+2007-12-25 Andreia Gaita <avidigal@novell.com>\r
+\r
+ * Mono.Mozilla/DOM/DOMHTMLDocument.cs,\r
+ Mono.Mozilla/DOM/DOMObject.cs\r
+ Mono.Mozilla/DOM/Navigation.cs:\r
+ \r
+ Properly dispose unmanaged resources.\r
+ Use native mozilla dom interfaces through com directly instead\r
+ of going through the glue, as they are now proxies that invoke\r
+ the methods on the main mozilla ui properly (avoiding threading problems).\r
+ Check if library was properly initialized.\r
+ Add Go method - implements navigation\r
+ directly through COM instead of going through the glue.\r
+ \r
+ * Mono.Mozilla/interfaces/nsIWebNavigation.cs: Use typed flags instead of\r
+ generic uint32. Remove comments about threading (as it is now safe to use\r
+ this interface)\r
+\r
+ * Mono.Mozilla/Base.cs: Return bool on initialization so I can track if\r
+ library was properly initialized from the interfaces that go directly \r
+ through COM and not through the glue\r
+\r
+ * Mono.Mozilla/WebBrowser.cs: Save initialization result so interfaces\r
+ don't get called if the library was not initialized.\r
+\r
2007-11-08 Andreia Gaita <avidigal@novell.com>\r
\r
* Mono.Mozilla.csproj, Mono.Mozilla2K5.csproj: Synch with .sources\r
Trace.AutoFlush = true;\r
}\r
\r
- public static void Init (WebBrowser control)\r
+ public static bool Init (WebBrowser control)\r
{\r
BindingInfo info = new BindingInfo ();\r
info.callback = new CallbackBinder (control);\r
Console.WriteLine ("libgluezilla not found. To have webbrowser support, you need libgluezilla installed");\r
Marshal.FreeHGlobal (ptrCallback);\r
gluezillaInstalled = false;\r
- return;\r
+ return false;\r
}\r
gluezillaInstalled = true;\r
boundControls.Add (control as IWebBrowser, info);\r
- DebugStartup ();\r
+ DebugStartup ();
+ return true;\r
}\r
\r
public static void Shutdown (IWebBrowser control)\r
public static void StringSet (HandleRef str, string text)\r
{\r
gluezilla_stringSet (str, text);\r
- }\r
+ }
+/*
+ public static nsIServiceManager GetServiceManager (IWebBrowser control)\r
+ {\r
+ if (!isInitialized ())\r
+ return null;\r
+ BindingInfo info = getBinding (control);\r
\r
+ return gluezilla_getServiceManager (info.gluezilla);\r
+ }\r
+*/\r
#region pinvokes\r
[DllImport("gluezilla")]\r
private static extern void gluezilla_debug_startup();\r
private static extern IntPtr gluezilla_stringGet (HandleRef str);\r
[DllImport ("gluezilla")]\r
private static extern void gluezilla_stringSet (HandleRef str, [MarshalAs (UnmanagedType.LPWStr)] string text);\r
+
+
+// [DllImport ("gluezilla")]
+// private static extern nsIServiceManager gluezilla_getServiceManager (IntPtr instance);
#endregion\r
}\r
}\r
{\r
internal class DOMHTMLDocument: DOMObject, IDOMHTMLDocument\r
{\r
- private nsIDOMHTMLDocument document;\r
+ private nsIDOMHTMLDocument document;
+ private bool disposed = false;\r
\r
public DOMHTMLDocument (nsIDOMHTMLDocument document)\r
{\r
this.document = document;\r
- }\r
+ }
+
+ #region IDisposable Members\r
+ protected override void Dispose (bool disposing)
+ {
+ if (!disposed) {
+ if (disposing) {
+ this.document = null;
+ }
+ disposed = true;
+ }
+ base.Dispose(disposing);
+ } \r
+ #endregion
\r
#region IDOMDocument Members\r
\r
nsIDOMHTMLElement body;\r
this.document.getBody (out body);\r
return new DOMHTMLElement (body);\r
- }\r
+ }
}\r
+
+ public string Text {
+ set {
+ nsIDOMElement element;
+ this.document.getDocumentElement (out element);
+
+ }
+ }
\r
public string Title {\r
get {\r
{\r
internal class DOMObject : IDisposable\r
{\r
- internal HandleRef storage;\r
+ internal HandleRef storage;
+ private bool disposed = false;\r
\r
internal DOMObject ()\r
{\r
}\r
\r
~DOMObject ()\r
- {\r
- this.Dispose ();\r
+ {
+ Dispose (false);\r
}\r
\r
#region IDisposable Members\r
+
+ protected virtual void Dispose (bool disposing)
+ {
+ if (!disposed) {
+ if (disposing) {
+ Base.StringFinish (storage);
+ }
+ disposed = true;
+ }
+ }
\r
public void Dispose ()\r
{\r
- Base.StringFinish (storage);\r
+ Dispose (true);
+ GC.SuppressFinalize (this);\r
}\r
\r
#endregion\r
\r
namespace Mono.Mozilla.DOM\r
{\r
- internal class Navigation: INavigation\r
+ internal class Navigation: DOMObject, INavigation\r
{\r
\r
- private nsIWebNavigation webNav;\r
- private IWebBrowser control;\r
+ private nsIWebNavigation navigation;\r
+ private IWebBrowser control;
+ private bool disposed = false;
+ \r
public Navigation (IWebBrowser control, nsIWebNavigation webNav)\r
{\r
- this.webNav = webNav;\r
+ this.navigation = webNav;\r
this.control = control;\r
}\r
+
+
+ #region IDisposable Members\r
+ protected override void Dispose (bool disposing)
+ {
+ if (!disposed) {
+ if (disposing) {
+ this.navigation = null;
+ }
+ disposed = true;
+ }
+ base.Dispose(disposing);
+ } \r
+ #endregion
\r
#region INavigation Members\r
\r
public bool CanGoBack {\r
- get {\r
+ get {
+ if (navigation == null)
+ return false;
+ \r
bool canGoBack;\r
- webNav.CanGoBack (out canGoBack);\r
+ navigation.CanGoBack (out canGoBack);\r
return canGoBack;\r
}\r
}\r
\r
public bool CanGoForward {\r
get {\r
+ if (navigation == null)
+ return false;
+
bool canGoForward;\r
- webNav.CanGoForward (out canGoForward);\r
+ navigation.CanGoForward (out canGoForward);\r
return canGoForward;\r
}\r
}\r
\r
public bool Back ()\r
{\r
- return Base.Back (control);\r
+ if (navigation == null)
+ return false;
+
+ //return Base.Back (control);
+ return navigation.GoBack () == 0;\r
}\r
\r
public bool Forward ()\r
{\r
- return Base.Forward (control);\r
+ if (navigation == null)
+ return false;
+
+ //return Base.Forward (control);
+ return navigation.GoForward () == 0;\r
}\r
\r
public void Home ()\r
\r
public void Reload ()\r
{\r
- Base.Reload (control, ReloadOption.None);\r
+ if (navigation == null)
+ return;
+
+ //Base.Reload (control, ReloadOption.None);
+ navigation.Reload (ReloadOption.None);\r
}\r
\r
public void Reload (ReloadOption option)\r
{\r
- Base.Reload (control, option);\r
+ if (navigation == null)
+ return;
+
+ //Base.Reload (control, option);
+ navigation.Reload (option);\r
}\r
\r
public void Stop ()\r
{\r
- Base.Stop (control);\r
+ if (navigation == null)
+ return;
+
+ //Base.Stop (control);
+ navigation.Stop (StopOption.All);\r
+ }
+
+ public void Go (string url)
+ {
+ if (navigation == null)
+ return;
+
+ navigation.LoadURI (url, ReloadOption.None, null, null, null);
}\r
\r
#endregion\r
public class WebBrowser : Component, IWebBrowser, ICallback\r
{\r
private bool loaded;\r
- private IDOMHTMLDocument document;\r
- private INavigation navigation;\r
+ private DOM.DOMHTMLDocument document;\r
+ private DOM.Navigation navigation;\r
\r
public WebBrowser ()\r
{\r
- loaded = false;\r
- Base.Init (this);\r
+ loaded = Base.Init (this);\r
}\r
\r
- public void Load (IntPtr handle, int width, int height)\r
- {\r
- Base.Bind (this, handle, width, height);\r
+ public bool Load (IntPtr handle, int width, int height)\r
+ {
+ Base.Bind (this, handle, width, height);
+ return loaded;\r
}\r
\r
public void Shutdown ()\r
nsIDOMHTMLDocument doc = Base.GetDOMDocument (this);\r
document = new DOM.DOMHTMLDocument (doc);\r
}\r
- return document;\r
+ return document as IDOMHTMLDocument;\r
}\r
}\r
\r
{\r
get\r
{\r
- if (navigation == null) {\r
+ if (navigation == null) {
+
nsIWebNavigation webNav = Base.GetWebNavigation (this);\r
navigation = new DOM.Navigation (this, webNav);\r
}\r
- return navigation;\r
+ return navigation as INavigation;\r
}\r
}\r
\r
}\r
\r
public void Navigate (string url)\r
- {\r
- this.document = null;\r
+ {
+ this.document = null;
this.navigation = null;\r
Base.Navigate (this, url);\r
}\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
int CanGoForward (out bool canGoForward);\r
\r
- /// <summary>\r
- /// Do not use on non-windows platforms due to threading problems\r
- /// </summary>\r
- /// <returns></returns>\r
[PreserveSigAttribute]\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
int GoBack ();\r
\r
- /// <summary>\r
- /// Do not use on non-windows platforms due to threading problems\r
- /// </summary>\r
- /// <returns></returns>\r
[PreserveSigAttribute]\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
int GoForward ();\r
\r
- /// <summary>\r
- /// Do not use on non-windows platforms due to threading problems\r
- /// </summary>\r
- /// <returns></returns>\r
[PreserveSigAttribute]\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
int GotoIndex (Int32 index);\r
\r
- /// <summary>\r
- /// Do not use on non-windows platforms due to threading problems\r
- /// </summary>\r
- /// <returns></returns>\r
[PreserveSigAttribute]\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
- int LoadURI (string uri, UInt32 loadFlags,\r
+ int LoadURI ([MarshalAs(UnmanagedType.LPWStr)] string uri,
+ Mono.WebBrowser.ReloadOption loadFlags,\r
[MarshalAs (UnmanagedType.Interface)] nsIURI referrer,\r
[MarshalAs (UnmanagedType.Interface)] nsIInputStream postData,\r
[MarshalAs (UnmanagedType.Interface)] nsIInputStream headers);\r
\r
- /// <summary>\r
- /// Do not use on non-windows platforms due to threading problems\r
- /// </summary>\r
- /// <returns></returns>\r
[PreserveSigAttribute]\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
- int Reload (UInt32 reloadFlags);\r
+ int Reload (Mono.WebBrowser.ReloadOption reloadFlags);\r
\r
[PreserveSigAttribute]\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
- int Stop (UInt32 stopFlags);\r
+ int Stop (StopOption stopFlags);\r
\r
[PreserveSigAttribute]\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
[MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]\r
int SetSessionHistory ([MarshalAs (UnmanagedType.Interface)] nsISHistory sessionHistory);\r
\r
- }\r
+ }
+
+ internal enum StopOption : uint\r
+ {\r
+ Network = 1,\r
+ Content = 2,\r
+ All = 3\r
+ }\r\r
}\r
void Home ();\r
void Reload ();\r
void Reload (ReloadOption option);\r
- void Stop ();\r
+ void Stop ();
+ void Go (string url);\r
}\r
}\r
{\r
public interface IWebBrowser\r
{\r
- void Load (IntPtr handle, int width, int height);\r
+ bool Load (IntPtr handle, int width, int height);\r
void Shutdown ();\r
void FocusIn (FocusOption focus);\r
void FocusOut ();\r
event EventHandler Navigated;\r
}
- public enum ReloadOption\r
+ public enum ReloadOption : uint\r
{\r
None = 0,\r
Proxy = 1,\r