Пример #1
0
 internal void Reset()
 {
     this.document = null;
     this.DomEvents.Dispose();
     this.domEvents = null;
     this.documents.Clear();
 }
Пример #2
0
        public void OnStateChange(nsIWebProgress progress, nsIRequest request, Int32 status, UInt32 state)
        {
            if (!owner.created)
            {
                owner.created = true;
            }

#if debug
            //OnGeneric ("OnStateChange");

            System.Text.StringBuilder s = new System.Text.StringBuilder();
            if ((state & (uint)StateFlags.Start) != 0)
            {
                s.Append("Start\t");
            }
            if ((state & (uint)StateFlags.Redirecting) != 0)
            {
                s.Append("Redirecting\t");
            }
            if ((state & (uint)StateFlags.Transferring) != 0)
            {
                s.Append("Transferring\t");
            }
            if ((state & (uint)StateFlags.Negotiating) != 0)
            {
                s.Append("Negotiating\t");
            }
            if ((state & (uint)StateFlags.Stop) != 0)
            {
                s.Append("Stop\t");
            }
            if ((state & (uint)StateFlags.IsRequest) != 0)
            {
                s.Append("Request\t");
            }
            if ((state & (uint)StateFlags.IsDocument) != 0)
            {
                s.Append("Document\t");
            }
            if ((state & (uint)StateFlags.IsNetwork) != 0)
            {
                s.Append("Network\t");
            }
            if ((state & (uint)StateFlags.IsWindow) != 0)
            {
                s.Append("Window\t");
            }
            Console.Error.WriteLine(s.ToString());
#endif

            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 && _document && !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);
                    uri.getSpec(spec.Handle);
                    currentUri = spec.ToString();
                }

                calledLoadStarted = true;
                LoadStartedEventHandler eh = (LoadStartedEventHandler)(owner.Events [WebBrowser.LoadStartedEvent]);
                if (eh != null)
                {
                    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(2152398850);                          //NS_BINDING_ABORTED
                    }
                }
                return;
            }

            if (_document && _request && _transferring)
            {
                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);
                    uri.getSpec(spec.Handle);
                    currentUri = spec.ToString();
                }

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

                LoadCommitedEventHandler eh = (LoadCommitedEventHandler)(owner.Events[WebBrowser.LoadCommitedEvent]);
                if (eh != null)
                {
                    LoadCommitedEventArgs e = new LoadCommitedEventArgs(currentUri);
                    eh(this, e);
                }
                return;
            }

            if (_document && _request && _redirecting)
            {
                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);
                    uri.getSpec(spec.Handle);
                    currentUri = spec.ToString();
                }
                return;
            }

            if (_stop && !_request && !_document && _network && _window)
            {
                calledLoadStarted = false;
                LoadFinishedEventHandler eh1 = (LoadFinishedEventHandler)(owner.Events[WebBrowser.LoadFinishedEvent]);
                if (eh1 != null)
                {
                    nsIDOMWindow win;
                    progress.getDOMWindow(out win);
                    LoadFinishedEventArgs e = new LoadFinishedEventArgs(currentUri);
                    eh1(this, e);
                }
                return;
            }

            if (_stop && !_request && _document && !_network && !_window)
            {
                nsIDOMWindow win;
                progress.getDOMWindow(out win);
                nsIDOMDocument doc;
                win.getDocument(out doc);
                if (doc != null)
                {
                    int hash = doc.GetHashCode();
                    if (owner.documents.ContainsKey(hash))
                    {
                        DOM.Document document = owner.documents[hash] as DOM.Document;

                        EventHandler eh1 = (EventHandler)(document.Events[DOM.Document.LoadStoppedEvent]);
                        if (eh1 != null)
                        {
                            eh1(this, null);
                        }
                    }
                }
                calledLoadStarted = false;
                return;
            }
#if debug
            Console.Error.WriteLine("{0} completed", s.ToString());
#endif
        }
Пример #3
0
		internal void Reset ()
		{
			this.document = null;
			this.DomEvents.Dispose ();
			this.domEvents = null;
			this.documents.Clear ();
		}
		void Init (Document document, string mimeType, DocumentEncoderFlags flags)
		{
			UniString type = new UniString (mimeType);
			
			try {
				docEncoder.init ((nsIDOMDocument)document.nodeNoProxy, 
			    	             type.Handle, 
			        	         (uint)flags);
			} catch (System.Exception ex) {
				throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.DocumentEncoderService, ex);
			}
		}
		public io.Stream EncodeToStream (Document document) {
			Init (document, MimeType, Flags);
			Stream m = new Stream (new io.MemoryStream ());
			docEncoder.encodeToStream (m);
			return m.BaseStream;
		}
		public string EncodeToString (Document document) {
			Init (document, MimeType, Flags);
			docEncoder.encodeToString(storage);
			return Base.StringGet (storage);
		}