* Mono.Mozilla/Callback.cs,
authorAndreia Gaita <avidigal@novell.com>
Sun, 23 Nov 2008 06:19:16 +0000 (06:19 -0000)
committerAndreia Gaita <avidigal@novell.com>
Sun, 23 Nov 2008 06:19:16 +0000 (06:19 -0000)
  Mono.Mozilla/DOM/DocumentEncoder.cs,
  Mono.Mozilla/DOM/HTMLElement.cs,
  Mono.Mozilla/WebBrowser.cs,
  Mono.Mozilla/interfaces/nsIServiceManager.cs:
  Fix ContentStream for xulrunner 1.8.
  Fix Document and Uri setting when loading new pages

2008-11-23  Andreia Gaita <shana@jitted.com>

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

mcs/class/Mono.WebBrowser/ChangeLog
mcs/class/Mono.WebBrowser/Mono.Mozilla/Callback.cs
mcs/class/Mono.WebBrowser/Mono.Mozilla/DOM/DocumentEncoder.cs
mcs/class/Mono.WebBrowser/Mono.Mozilla/DOM/HTMLElement.cs
mcs/class/Mono.WebBrowser/Mono.Mozilla/WebBrowser.cs
mcs/class/Mono.WebBrowser/Mono.Mozilla/interfaces/nsIServiceManager.cs

index 38da68eb0a703a697faed8d8b34244e71c5eba31..beaf16c7fc4b87638386f76dc7a5d68bbda1a0a1 100644 (file)
@@ -1,5 +1,15 @@
 2008-11-23  Andreia Gaita <shana@jitted.com> 
 
+       * Mono.Mozilla/Callback.cs,
+         Mono.Mozilla/DOM/DocumentEncoder.cs,
+         Mono.Mozilla/DOM/HTMLElement.cs,
+         Mono.Mozilla/WebBrowser.cs,
+         Mono.Mozilla/interfaces/nsIServiceManager.cs:
+         Fix ContentStream for xulrunner 1.8.
+         Fix Document and Uri setting when loading new pages
+
+2008-11-23  Andreia Gaita <shana@jitted.com>
+
        * Mono.Mozilla/Base.cs, Mono.Mozilla/WebBrowser.cs: Separate initialization 
        in 3 stages so events can be registered before the window is actually created. 
        The creation of the window is now done only when a user requests something
index a6ba1e62970d81bafda8613b94daed94a0153324..821173aabead6baf892e32fb7d300197f288ba89 100644 (file)
@@ -39,6 +39,7 @@ namespace Mono.Mozilla {
        {
                WebBrowser owner;
                string currentUri;
+               bool calledLoadStarted;
                
                public Callback (WebBrowser owner) 
                {
@@ -57,7 +58,10 @@ namespace Mono.Mozilla {
 
 
                public void OnStateChange (nsIWebProgress progress, nsIRequest request, Int32 status, UInt32 state)
-               {                       
+               {
+                       if (!owner.created)
+                               owner.created = true;
+
 #if debug
                        //OnGeneric ("OnStateChange");
 
@@ -92,45 +96,61 @@ namespace Mono.Mozilla {
                        Console.Error.WriteLine (s.ToString ());
 #endif
 
-               
-                       if ((state & (uint) StateFlags.Start) != 0 && 
-                               (state & (uint) StateFlags.IsRequest) != 0 &&
-                               (state & (uint) StateFlags.IsDocument) != 0 &&
-                           (state & (uint) StateFlags.IsNetwork) != 0 && 
-                           (state & (uint) StateFlags.IsWindow) != 0 
-                           )
-                       {
-                               owner.documents.Clear ();
+                       bool _start = (state & (uint) StateFlags.Start) != 0;
+                       bool _negotiating = (state & (uint) StateFlags.Negotiating) != 0;
+                       bool _transferring = (state & (uint) StateFlags.Transferring) != 0;
+                       bool _redirecting = (state & (uint) StateFlags.Redirecting) != 0;
+                       bool _stop = (state & (uint) StateFlags.Stop) != 0;
+                       bool _request = (state & (uint) StateFlags.IsRequest) != 0;
+                       bool _document = (state & (uint) StateFlags.IsDocument) != 0;
+                       bool _network = (state & (uint) StateFlags.IsNetwork) != 0;
+                       bool _window = (state & (uint) StateFlags.IsWindow) != 0;
+
+                       if (_start && _request && !calledLoadStarted) {
+                               nsIDOMWindow win;
+                               progress.getDOMWindow (out win);
                                nsIChannel channel = (nsIChannel) request;
                                nsIURI uri;
                                channel.getURI (out uri);
                                if (uri == null)
                                        currentUri = "about:blank";
                                else {
-                                       AsciiString spec = new AsciiString(String.Empty);
+                                       AsciiString spec = new AsciiString (String.Empty);
                                        uri.getSpec (spec.Handle);
                                        currentUri = spec.ToString ();
                                }
-                               
-                               LoadStartedEventHandler eh = (LoadStartedEventHandler) (owner.Events[WebBrowser.LoadStartedEvent]);
+
+                               calledLoadStarted = true;
+                               LoadStartedEventHandler eh = (LoadStartedEventHandler) (owner.Events [WebBrowser.LoadStartedEvent]);
                                if (eh != null) {
-                                       nsIDOMWindow win;
-                                       progress.getDOMWindow (out win);
+
                                        AsciiString name = new AsciiString (String.Empty);
                                        win.getName (name.Handle);
-                                       
+
                                        LoadStartedEventArgs e = new LoadStartedEventArgs (currentUri, name.ToString ());
                                        eh (this, e);
                                        if (e.Cancel)
                                                request.cancel (0);
                                }
+                               return;
+
+                       }
+
+                       if (_document && _request && _transferring) {
+                               nsIDOMWindow win;
+                               progress.getDOMWindow (out win);
+                               nsIDOMWindow topWin;
+                               win.getTop (out topWin);
+                               if (topWin == null || topWin.GetHashCode () == win.GetHashCode ()) {
+                                       owner.Reset ();
+                                       nsIDOMDocument doc;
+                                       win.getDocument (out doc);
+                                       if (doc != null)
+                                               owner.document = new Mono.Mozilla.DOM.Document (owner, doc);
+                               }
                        }
-                               
-                       if ((state & (uint) StateFlags.Stop) != 0 && 
-                               (state & (uint) StateFlags.IsNetwork) != 0 &&
-                               (state & (uint) StateFlags.IsWindow) != 0
-                               )
-                       {
+
+                       if (_stop && !_request && !_document && _network && _window) {
                            LoadFinishedEventHandler eh1 = (LoadFinishedEventHandler) (owner.Events[WebBrowser.LoadFinishedEvent]);
                            if (eh1 != null) {
 
@@ -140,10 +160,10 @@ namespace Mono.Mozilla {
                                eh1 (this, e);
 
                            }
+                               return;
                        }
-                       else if ((state & (uint) StateFlags.Stop) != 0 && 
-                               (state & (uint) StateFlags.IsDocument) != 0)
-                       {
+
+                       if (_stop && !_request && _document && !_network && !_window) {
                                nsIDOMWindow win;
                                progress.getDOMWindow (out win);
                                nsIDOMDocument doc;
@@ -158,6 +178,8 @@ namespace Mono.Mozilla {
                                                        eh1 (this, null);
                                    }
                                }
+                               calledLoadStarted = false;
+                               return;
                        } 
 #if debug
                        Console.Error.WriteLine ("{0} completed", s.ToString ());
index 09abdfe7b80743cbaa56d42bd7c7d319417cd639..0faccc527f95b86c4b0fc1e9e65b0601dbd60a6d 100644 (file)
@@ -39,9 +39,10 @@ namespace Mono.Mozilla {
                public DocumentEncoder (WebBrowser control) : base (control) {          
                        IntPtr docEncoderServicePtr = IntPtr.Zero;
 
-                       docEncoderServicePtr = this.control.ServiceManager.getServiceByContractID (
-                                                               "@mozilla.org/layout/documentEncoder;1?type=text/html",
-                                       typeof (nsIDocumentEncoder).GUID);
+                       this.control.ServiceManager.getServiceByContractID (
+                                                       "@mozilla.org/layout/documentEncoder;1?type=text/html",
+                                                       typeof (nsIDocumentEncoder).GUID,
+                                                       out docEncoderServicePtr);
                        if (docEncoderServicePtr == IntPtr.Zero)
                                throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.DocumentEncoderService);
 
index 5fa793cfdeb4b28f1734d95e1f1fcf7ee4466a12..3dbb37a76a6cf716a3706287885c50c7153fa68f 100644 (file)
@@ -79,13 +79,24 @@ namespace Mono.Mozilla.DOM
                {
                        // bad emulation of outerHTML since gecko doesn't support it :P
                        get {
-                               control.DocEncoder.Flags = DocumentEncoderFlags.OutputRaw;
-                               if (this.Equals (Owner.DocumentElement))
-                                       return control.DocEncoder.EncodeToString ((Document)Owner);
-                               return control.DocEncoder.EncodeToString (this);                                        
+                               try {
+                                       control.DocEncoder.Flags = DocumentEncoderFlags.OutputRaw;
+                                       if (this.Equals (Owner.DocumentElement))
+                                               return control.DocEncoder.EncodeToString ((Document) Owner);
+                                       return control.DocEncoder.EncodeToString (this);
+                               } catch {
+                                       string tag = this.TagName;
+                                       string str = "<" + tag;
+                                       foreach (IAttribute att in this.Attributes) {
+                                               str += " " + att.Name + "=\"" + att.Value + "\"";
+                                       }
+                                       nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
+                                       nsElem.getInnerHTML (storage);
+                                       str += ">" + Base.StringGet (storage) + "</" + tag + ">";
+                                       return str;
+                               }
                        }
                        set {
-                               /*
                                nsIDOMDocumentRange docRange = ((Document) control.Document).XPComObject as nsIDOMDocumentRange;
                                nsIDOMRange range;
                                docRange.createRange (out range);
@@ -100,16 +111,28 @@ namespace Mono.Mozilla.DOM
                                nsIDOMNode newNode;
                                parent.replaceChild (fragment as nsIDOMNode, this.node as nsIDOMNode, out newNode);
                                this.node = newNode as Mono.Mozilla.nsIDOMHTMLElement;
-                               */
                        }
                }
 
                public override io.Stream ContentStream {
-                       get { 
-                               control.DocEncoder.Flags = DocumentEncoderFlags.OutputRaw;
-                               if (this.Equals (Owner.DocumentElement))
-                                       return control.DocEncoder.EncodeToStream ((Document)Owner);
-                               return control.DocEncoder.EncodeToStream (this);
+                       get {
+                               try {
+                                       control.DocEncoder.Flags = DocumentEncoderFlags.OutputRaw;
+                                       if (this.Equals (Owner.DocumentElement))
+                                               return control.DocEncoder.EncodeToStream ((Document) Owner);
+                                       return control.DocEncoder.EncodeToStream (this);
+                               } catch {
+                                       string tag = this.TagName;
+                                       string str = "<" + tag;
+                                       foreach (IAttribute att in this.Attributes) {
+                                               str += " " + att.Name + "=\"" + att.Value + "\"";
+                                       }
+                                       nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
+                                       nsElem.getInnerHTML (storage);
+                                       str += ">" + Base.StringGet (storage) + "</" + tag + ">";
+                                       byte[] bytes = System.Text.ASCIIEncoding.UTF8.GetBytes (str);
+                                       return new io.MemoryStream (bytes);
+                               }
                        }
                }
 
index ef08685675d862c18fe6d174475c9f2661e5604c..6683342cdaf41d68d032c64685b4ab285ecec24e 100644 (file)
@@ -39,10 +39,10 @@ namespace Mono.Mozilla
        internal class WebBrowser : IWebBrowser
        {
                bool loaded;
-               bool created = false;
+               internal bool created = false;
                bool creating = false;
 
-               DOM.Document document;
+               internal DOM.Document document;
                
                internal DOM.Navigation navigation;
                internal Platform platform;
@@ -91,6 +91,7 @@ namespace Mono.Mozilla
                        this.document = null;
                        this.DomEvents.Dispose ();
                        this.domEvents = null;
+                       this.documents.Clear ();
                }
 
                public bool Initialized {
@@ -191,7 +192,8 @@ namespace Mono.Mozilla
                                if (ioService == null) {
                                        IntPtr ioServicePtr = IntPtr.Zero;
 
-                                       ioServicePtr = ServiceManager.getServiceByContractID ("@mozilla.org/network/io-service;1", typeof (nsIIOService).GUID);
+                                       ServiceManager.getServiceByContractID ("@mozilla.org/network/io-service;1", typeof (nsIIOService).GUID,
+                                               out ioServicePtr);
                                        if (ioServicePtr == IntPtr.Zero)
                                                throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.IOService);
 
@@ -210,7 +212,8 @@ namespace Mono.Mozilla
                        get {
                                if (accessibilityService == null) {
                                        IntPtr accessibilityServicePtr = IntPtr.Zero;
-                                       accessibilityServicePtr = ServiceManager.getServiceByContractID ("@mozilla.org/accessibilityService;1", typeof (nsIAccessibilityService).GUID);
+                                       ServiceManager.getServiceByContractID ("@mozilla.org/accessibilityService;1", typeof (nsIAccessibilityService).GUID,
+                                               out accessibilityServicePtr);
                                        if (accessibilityServicePtr == IntPtr.Zero) {
                                                throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.AccessibilityService);
                                        }
@@ -231,7 +234,8 @@ namespace Mono.Mozilla
                                if (errorService == null) {
                                        IntPtr errorServicePtr = IntPtr.Zero;
 
-                                       errorServicePtr = ServiceManager.getServiceByContractID ("@mozilla.org/xpcom/error-service;1", typeof (nsIErrorService).GUID);
+                                       ServiceManager.getServiceByContractID ("@mozilla.org/xpcom/error-service;1", typeof (nsIErrorService).GUID,
+                                               out errorServicePtr);
                                        if (errorServicePtr == IntPtr.Zero)
                                                return null;
 
index 212d28d1d1388dd8b9c3c39d582c8073de7f0ae6..ba3d35aea10da35094e940352926e33a826155ed 100644 (file)
@@ -42,9 +42,12 @@ namespace Mono.Mozilla {
                IntPtr getService ([MarshalAs (UnmanagedType.LPStruct)]  Guid aClass,
                                [MarshalAs (UnmanagedType.LPStruct)]  Guid aIID);
 
+
+               [PreserveSigAttribute]
                [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
-               IntPtr getServiceByContractID ([MarshalAs (UnmanagedType.LPStr)]  string aContractID,
-                               [MarshalAs (UnmanagedType.LPStruct)]  Guid aIID);
+               int getServiceByContractID ([MarshalAs (UnmanagedType.LPStr)]  string aContractID,
+                               [MarshalAs (UnmanagedType.LPStruct)]  Guid aIID, 
+                               out IntPtr ret);
 
                [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
                bool isServiceInstantiated ([MarshalAs (UnmanagedType.LPStruct)]  Guid aClass,