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
{
WebBrowser owner;
string currentUri;
+ bool calledLoadStarted;
public Callback (WebBrowser owner)
{
public void OnStateChange (nsIWebProgress progress, nsIRequest request, Int32 status, UInt32 state)
- {
+ {
+ if (!owner.created)
+ owner.created = true;
+
#if debug
//OnGeneric ("OnStateChange");
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) {
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;
eh1 (this, null);
}
}
+ calledLoadStarted = false;
+ return;
}
#if debug
Console.Error.WriteLine ("{0} completed", s.ToString ());
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);
{
// 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);
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);
+ }
}
}
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;
this.document = null;
this.DomEvents.Dispose ();
this.domEvents = null;
+ this.documents.Clear ();
}
public bool Initialized {
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);
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);
}
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;
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,