* Mono.Mozilla/DOM/DOMHTMLDocument.cs,
authorAndreia Gaita <avidigal@novell.com>
Tue, 25 Dec 2007 05:01:57 +0000 (05:01 -0000)
committerAndreia Gaita <avidigal@novell.com>
Tue, 25 Dec 2007 05:01:57 +0000 (05:01 -0000)
  Mono.Mozilla/DOM/DOMObject.cs
  Mono.Mozilla/DOM/Navigation.cs:

Properly dispose unmanaged resources.
Use native mozilla dom interfaces through com directly instead
of going through the glue, as they are now proxies that invoke
the methods on the main mozilla ui properly (avoiding threading problems).
Check if library was properly initialized.
Add Go method - implements navigation
directly through COM instead of going through the glue.

* Mono.Mozilla/interfaces/nsIWebNavigation.cs: Use typed flags instead of
generic uint32. Remove comments about threading (as it is now safe to use
this interface)

* Mono.Mozilla/Base.cs: Return bool on initialization so I can track if
library was properly initialized from the interfaces that go directly
through COM and not through the glue

* Mono.Mozilla/WebBrowser.cs: Save initialization result so interfaces
don't get called if the library was not initialized.

2007-12-25  Andreia Gaita  <avidigal@novell.com>

svn path=/trunk/mcs/; revision=91870

mcs/class/Mono.Mozilla/ChangeLog
mcs/class/Mono.Mozilla/Mono.Mozilla/Base.cs
mcs/class/Mono.Mozilla/Mono.Mozilla/DOM/DOMHTMLDocument.cs
mcs/class/Mono.Mozilla/Mono.Mozilla/DOM/DOMObject.cs
mcs/class/Mono.Mozilla/Mono.Mozilla/DOM/Navigation.cs
mcs/class/Mono.Mozilla/Mono.Mozilla/WebBrowser.cs
mcs/class/Mono.Mozilla/Mono.Mozilla/interfaces/nsIWebNavigation.cs
mcs/class/Mono.Mozilla/Mono.WebBrowser/DOM/INavigation.cs
mcs/class/Mono.Mozilla/Mono.WebBrowser/IWebBrowser.cs

index e90f368d3f5f44dd1d9e450bf002854bc7f78fcf..a559a05fae8e4205750e58f2089a1eaaee4593a0 100644 (file)
@@ -1,3 +1,28 @@
+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
index d6d0ee5c3a1af696da8bbf460f4f190569427fd1..51ebf95dde4466006ed73e2fcf114f86c73c9e44 100644 (file)
@@ -72,7 +72,7 @@ namespace Mono.Mozilla
                        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
@@ -94,11 +94,12 @@ namespace Mono.Mozilla
                                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
@@ -259,8 +260,17 @@ namespace Mono.Mozilla
                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
@@ -316,6 +326,10 @@ namespace Mono.Mozilla
                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
index 59e276427d7b0f50c5881c268769ccbf8683ab2e..9525c575630f17f8809decca9266fe3aa9697a0c 100644 (file)
@@ -33,12 +33,26 @@ namespace Mono.Mozilla.DOM
 {\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
@@ -47,8 +61,16 @@ namespace Mono.Mozilla.DOM
                                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
index 09ed4e172ef349d488210fb9f3258b86875b61ec..5fea61b2aaa87aa6304754cf057ee072e68974a3 100644 (file)
@@ -31,7 +31,8 @@ namespace Mono.Mozilla.DOM
 {\r
        internal class DOMObject : IDisposable\r
        {\r
-               internal HandleRef storage;\r
+               internal HandleRef storage;
+               private bool disposed = false;\r
 \r
                internal DOMObject ()\r
                {\r
@@ -40,15 +41,26 @@ namespace Mono.Mozilla.DOM
                }\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
index 187ca2a7ce942326be594862ada6b0c729d333e5..75e4ba57d38c30e8e49817d4ff6df0965e270449 100755 (executable)
@@ -31,43 +31,73 @@ using Mono.WebBrowser.DOM;
 \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
@@ -77,17 +107,37 @@ namespace Mono.Mozilla.DOM
 \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
index 99466f8fa5894b3843353c4b86ddd5b2ae78a278..ad8d6f7eddc1dad816f93542e64205404038dbf2 100644 (file)
@@ -40,18 +40,18 @@ namespace Mono.Mozilla
        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
@@ -67,7 +67,7 @@ namespace Mono.Mozilla
                                        nsIDOMHTMLDocument doc = Base.GetDOMDocument (this);\r
                                        document = new DOM.DOMHTMLDocument (doc);\r
                                }\r
-                               return document;\r
+                               return document as IDOMHTMLDocument;\r
                        }\r
                }\r
 \r
@@ -75,11 +75,12 @@ namespace Mono.Mozilla
                {\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
@@ -108,8 +109,8 @@ namespace Mono.Mozilla
                }\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
index cd30f02f321ce18da7b6288e865430a90178ccf1..33862e53a37c37d9558c2f995974b1c6dd5ac03d 100755 (executable)
@@ -43,52 +43,33 @@ namespace Mono.Mozilla
                [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
@@ -110,5 +91,12 @@ namespace Mono.Mozilla
                [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
index 217d336f7410e53369d389c1e63e341d3f64b813..ec55d19452494c4447d85e7389632579405b79a6 100755 (executable)
@@ -37,6 +37,7 @@ namespace Mono.WebBrowser.DOM
                void Home ();\r
                void Reload ();\r
                void Reload (ReloadOption option);\r
-               void Stop ();\r
+               void Stop ();
+               void Go (string url);\r
        }\r
 }\r
index 29b1a2ff070b378874d1a1951e82e8b8830c7075..736f0d841b6cd6cd2623a06c1baa85285c6c6818 100644 (file)
@@ -34,7 +34,7 @@ namespace Mono.WebBrowser
 {\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
@@ -62,7 +62,7 @@ namespace Mono.WebBrowser
                event EventHandler Navigated;\r
        }
 
-       public enum ReloadOption\r
+       public enum ReloadOption : uint\r
        {\r
                None = 0,\r
                Proxy = 1,\r