Skip to content

Commit

Permalink
* Mono.Mozilla/WebBrowser.cs: Update the loaded flag so users can now
Browse files Browse the repository at this point in the history
  if the engine is actually running properly.
* Mono.Mozilla/Base.cs: Create cache directory with a version specific
  name so there's no conflict when the user has both xulrunner
  runtime 1.8 and 1.9 installed. Get rid of gluezillaInstalled flag,
  redundant. Bind now returns bool so I can check if the engine is
  actually running properly after initialization. Check the return
  value of createBrowserWindow and bail out if no valid pointer is
  returned. Protect the string functions with a check so they don't
  get called if the engine is not initialized.

Fixes: segfaults when two xulrunner engines are installed. 
segfaults when engine gets initialized but doesn't load properly afterwards

2008-09-10  Andreia Gaita <avidigal@novell.com>

svn path=/branches/mono-2-0/mcs/; revision=112640
  • Loading branch information
shana committed Sep 10, 2008
1 parent 85432ce commit 13f9cb3
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 63 deletions.
16 changes: 16 additions & 0 deletions mcs/class/Mono.WebBrowser/ChangeLog
@@ -1,3 +1,19 @@
2008-09-10 Andreia Gaita <avidigal@novell.com>

* Mono.Mozilla/WebBrowser.cs: Update the loaded flag so users can now
if the engine is actually running properly.
* Mono.Mozilla/Base.cs: Create cache directory with a version specific
name so there's no conflict when the user has both xulrunner
runtime 1.8 and 1.9 installed. Get rid of gluezillaInstalled flag,
redundant. Bind now returns bool so I can check if the engine is
actually running properly after initialization. Check the return
value of createBrowserWindow and bail out if no valid pointer is
returned. Protect the string functions with a check so they don't
get called if the engine is not initialized.

Fixes: segfaults when two xulrunner engines are installed.
segfaults when engine gets initialized but doesn't load properly afterwards

2008-06-11 Andreia Gaita <avidigal@novell.com>

* Mono.Mozilla/DOM/Attribute.cs: Fix missing setter
Expand Down
144 changes: 82 additions & 62 deletions mcs/class/Mono.WebBrowser/Mono.Mozilla/Base.cs
Expand Up @@ -35,8 +35,9 @@ namespace Mono.Mozilla
internal class Base
{
private static Hashtable boundControls;
internal static bool gluezillaInstalled;
internal static bool initialized;
private static object initLock = new object ();
private static string monoMozDir;

private class BindingInfo
{
Expand All @@ -46,7 +47,7 @@ private class BindingInfo

private static bool isInitialized ()
{
if (!gluezillaInstalled)
if (!initialized)
return false;
return true;
}
Expand All @@ -73,60 +74,72 @@ public static void Debug (int signal)

public static bool Init (WebBrowser control, Platform platform)
{
if (!initialized) {

string monoMozDir = System.IO.Path.Combine (
System.IO.Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData),
".mono"), "mozilla");

if (!System.IO.Directory.Exists (monoMozDir))
System.IO.Directory.CreateDirectory (monoMozDir);

Platform mozPlatform;
try {
gluezilla_init (platform, out mozPlatform);
}
catch (DllNotFoundException) {
Console.WriteLine ("libgluezilla not found. To have webbrowser support, you need libgluezilla installed");
gluezillaInstalled = false;
initialized = false;
return false;
}
control.enginePlatform = mozPlatform;
gluezillaInstalled = true;
initialized = true;
}
return initialized;
lock (initLock) {
if (!initialized) {

Platform mozPlatform;
try {
short version = gluezilla_init (platform, out mozPlatform);

monoMozDir = System.IO.Path.Combine (
System.IO.Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData),
".mono"), "mozilla-" + version);

if (!System.IO.Directory.Exists (monoMozDir))
System.IO.Directory.CreateDirectory (monoMozDir);

}
catch (DllNotFoundException) {
Console.WriteLine ("libgluezilla not found. To have webbrowser support, you need libgluezilla installed");
initialized = false;
return false;
}
control.enginePlatform = mozPlatform;
initialized = true;
}
}
return initialized;
}

public static void Bind (WebBrowser control, IntPtr handle, int width, int height)
public static bool Bind (WebBrowser control, IntPtr handle, int width, int height)
{
if (!isInitialized ())
return;
return false;

BindingInfo info = new BindingInfo ();
info.callback = new CallbackBinder (control.callbacks);
IntPtr ptrCallback = Marshal.AllocHGlobal (Marshal.SizeOf (info.callback));
Marshal.StructureToPtr (info.callback, ptrCallback, true);

string monoMozDir = System.IO.Path.Combine (
System.IO.Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData),
".mono"), "mozilla");
info.gluezilla = gluezilla_createBrowserWindow (ptrCallback, handle, width, height, Environment.CurrentDirectory, monoMozDir, control.platform);

info.gluezilla = gluezilla_createBrowserWindow (ptrCallback, handle, width, height, Environment.CurrentDirectory, monoMozDir, control.platform);
lock (initLock) {
if (info.gluezilla == IntPtr.Zero) {
Marshal.FreeHGlobal (ptrCallback);
info = null;
initialized = false;
return false;
}
}
boundControls.Add (control as IWebBrowser, info);

return true;
}

public static void Shutdown (IWebBrowser control)
{
if (!isInitialized ())
return;
BindingInfo info = getBinding (control);

gluezilla_shutdown (info.gluezilla);
lock (initLock) {
if (!initialized)
return;

BindingInfo info = getBinding (control);

gluezilla_shutdown (info.gluezilla);
boundControls.Remove (control);
if (boundControls.Count == 0) {
info = null;
initialized = false;
}
}
}

// layout
Expand Down Expand Up @@ -195,28 +208,35 @@ public static nsIWebNavigation GetWebNavigation (IWebBrowser control)
return gluezilla_getWebNavigation (info.gluezilla);
}

public static IntPtr StringInit ()
{
return gluezilla_stringInit ();
}

public static void StringFinish (HandleRef str)
{
gluezilla_stringFinish (str);
}

public static string StringGet (HandleRef str)
{
IntPtr p = gluezilla_stringGet (str);
return Marshal.PtrToStringUni (p);
}

public static void StringSet (HandleRef str, string text)
{
gluezilla_stringSet (str, text);
public static IntPtr StringInit ()
{
if (!isInitialized ())
return IntPtr.Zero;
return gluezilla_stringInit ();
}

public static void StringFinish (HandleRef str)
{
if (!isInitialized ())
return;
gluezilla_stringFinish (str);
}

public static string StringGet (HandleRef str)
{
if (!isInitialized ())
return String.Empty;
IntPtr p = gluezilla_stringGet (str);
return Marshal.PtrToStringUni (p);
}

public static void StringSet (HandleRef str, string text)
{
if (!isInitialized ())
return;
gluezilla_stringSet (str, text);
}


public static object GetProxyForObject (IWebBrowser control, Guid iid, object obj)
{
if (!isInitialized ())
Expand Down Expand Up @@ -245,7 +265,7 @@ public static string EvalScript (IWebBrowser control, string script)
private static extern void gluezilla_debug(int signal);

[DllImport("gluezilla")]
private static extern IntPtr gluezilla_init (Platform platform, out Platform mozPlatform);
private static extern short gluezilla_init (Platform platform, out Platform mozPlatform);

[DllImport ("gluezilla")]
private static extern IntPtr gluezilla_shutdown (IntPtr instance);
Expand Down
2 changes: 1 addition & 1 deletion mcs/class/Mono.WebBrowser/Mono.Mozilla/WebBrowser.cs
Expand Up @@ -64,7 +64,7 @@ public WebBrowser (Platform platform)

public bool Load (IntPtr handle, int width, int height)
{
Base.Bind (this, handle, width, height);
loaded = Base.Bind (this, handle, width, height);
return loaded;
}

Expand Down

0 comments on commit 13f9cb3

Please sign in to comment.