Quellcode durchsuchen

* 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 <[email protected]>

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

Andreia Gaita vor 17 Jahren
Ursprung
Commit
f69e6db55f

+ 10 - 0
mcs/class/Mono.WebBrowser/ChangeLog

@@ -1,5 +1,15 @@
 2008-11-23  Andreia Gaita <[email protected]> 
 
+	* 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 <[email protected]>
+
 	* 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

+ 47 - 25
mcs/class/Mono.WebBrowser/Mono.Mozilla/Callback.cs

@@ -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 ());

+ 4 - 3
mcs/class/Mono.WebBrowser/Mono.Mozilla/DOM/DocumentEncoder.cs

@@ -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);
 

+ 34 - 11
mcs/class/Mono.WebBrowser/Mono.Mozilla/DOM/HTMLElement.cs

@@ -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);
+				}
 			}
 		}
 

+ 9 - 5
mcs/class/Mono.WebBrowser/Mono.Mozilla/WebBrowser.cs

@@ -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;
 

+ 5 - 2
mcs/class/Mono.WebBrowser/Mono.Mozilla/interfaces/nsIServiceManager.cs

@@ -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,