/// <summary>
            /// Notifies the <see cref="P:Parent"/> that a document has been completely loaded and initialized.
            /// </summary>
            /// <param name="webBrowser">The top-level or frame <see cref="T:WebBrowser"/> corresponding to the loaded document.</param>
            /// <param name="url">The URL, Universal Naming Convention (UNC) file name, or pointer to an item identifier list (PIDL) of the loaded document.</param>
            public override void DocumentCompleted(WebBrowser webBrowser, string url)
            {
                this.hasNavigated = true;

                /* //TODO: Implementar carregamento inicial
                 * if ((this.parent.documentStreamToSetOnLoad != null) && (((string)urlObject) == "about:blank"))
                 * {
                 *  HtmlDocument document = this.parent.Document;
                 *  if (document != null)
                 *  {
                 *      UnsafeNativeMethods.IPersistStreamInit domDocument = document.DomDocument as UnsafeNativeMethods.IPersistStreamInit;
                 *      UnsafeNativeMethods.IStream pstm = new UnsafeNativeMethods.ComStreamFromDataStream(this.parent.documentStreamToSetOnLoad);
                 *      domDocument.Load(pstm);
                 *      document.Encoding = "unicode";
                 *  }
                 *  this.parent.documentStreamToSetOnLoad = null;
                 * }
                 * else
                 */
                {
                    Uri uri = new Uri(url ?? string.Empty);
                    WebBrowserDocumentCompletedEventArgs e = new WebBrowserDocumentCompletedEventArgs(webBrowser, uri);
                    this.Parent.OnDocumentCompleted(e);
                }
            }
            /// <summary>
            /// Notifies the <see cref="P:Parent"/> that a navigation is occurring.
            /// </summary>
            /// <param name="webBrowser">The top-level or frame <see cref="T:WebBrowser"/> corresponding to the navigation.</param>
            /// <param name="url">The URL to which the browser is navigating.</param>
            /// <param name="targetFrameName">The frame in which the resource will be displayed, or <see langword="null"/> if no named frame is targeted for the resource.</param>
            /// <param name="postData">Data to send to the server if the HTTP POST transaction is being used.</param>
            /// <param name="headers">Specifies the additional HTTP headers to send to the server (HTTP URLs only). The headers can specify such things as the action required of the server, the type of data being passed to the server, or a status code.</param>
            /// <returns>
            /// <see langword="true"/> to cancel the navigation operation, or to <see langword="false"/> to allow it to proceed.
            /// </returns>
            public override bool Navigating(WebBrowser webBrowser, string url, string targetFrameName, byte[] postData, string headers)
            {
                if (this.Parent.AllowNavigation || !this.hasNavigated)
                {
                    if (targetFrameName == null)
                    {
                        targetFrameName = string.Empty;
                    }

                    if (headers == null)
                    {
                        headers = string.Empty;
                    }

                    Uri uri = new Uri(url ?? string.Empty);

                    var e = new WebBrowserNavigatingEventArgs(webBrowser, uri, targetFrameName ?? string.Empty, postData, headers);

                    this.Parent.OnNavigating(e);

                    return(e.Cancel);
                }
                else
                {
                    return(true);
                }
            }
            /// <summary>
            /// Notifies the <see cref="P:Parent"/> that a navigation has been completed on a window or frameSet element.
            /// </summary>
            /// <param name="webBrowser">The top-level or frame <see cref="T:WebBrowser"/> corresponding to the navigation.</param>
            /// <param name="url">The URL, UNC file name, or PIDL that was navigated to.</param>
            /// <remarks>
            /// Note that the URL can be different from the URL that the browser was told to navigate to.
            /// One reason is that this URL is the canonicalized and qualified URL; for example, if an application specified a URL of "www.microsoft.com" in a call to the <see cref="M:WebBrowser.Navigate"/> method, the URL passed by Navigate2 will be "http://www.microsoft.com/".
            /// Also, if the server has redirected the browser to a different URL, the redirected URL will be reflected here.
            /// </remarks>
            public override void Navigated(WebBrowser webBrowser, string url)
            {
                Uri uri = new Uri(url ?? string.Empty);

                var e = new WebBrowserNavigatedEventArgs(webBrowser, uri);

                this.Parent.OnNavigated(e);
            }
            /// <summary>
            /// Notifies the <see cref="P:Parent"/> that an error occured during navigation.
            /// </summary>
            /// <param name="webBrowser">The top-level or frame <see cref="T:WebBrowser"/> corresponding to the navigation.</param>
            /// <param name="url">The URL for which navigation failed.</param>
            /// <param name="frame">The name of the frame in which to display the resource, or <see langword="null"/> if no named frame was targeted for the resource.</param>
            /// <param name="status">The <see cref="T:WebBrowserNavigateErrorStatus">error status code</see>, if available.</param>
            /// <param name="cancel"><see langword="true"/> if the navigation should be canceled; otherwise <see langword="false"/>.</param>
            /// <returns>
            /// <see langword="true"/> to cancel the navigation; otherwise <see langword="false"/>.
            /// </returns>
            public override bool NavigateError(WebBrowser webBrowser, string url, string frame, WebBrowserNavigateErrorStatus status, bool cancel)
            {
                Uri uri = new Uri(url ?? string.Empty);

                var e = new WebBrowserNavigateErrorEventArgs(webBrowser, uri, frame, status, cancel);

                this.Parent.OnNavigateError(e);

                return(e.Cancel);
            }
            /// <summary>
            /// Notifies the <see cref="P:Parent"/> that a new window is to be created.
            /// </summary>
            /// <param name="webBrowser">The <see cref="T:WebBrowser"/> where the navigation should occur.</param>
            /// <param name="cancel"><see langword="true"/> if the navigation should be canceled; otherwise <see langword="false"/>.</param>
            /// <param name="flags">The <see cref="T:WebBrowserNewWindowFlags">flags</see> that pertain to the new window.</param>
            /// <param name="urlContext">The URL of the page that is opening the new window.</param>
            /// <param name="url">The URL that is opened in the new window.</param>
            /// <returns>
            /// <see langword="true"/> to cancel the navigation; otherwise <see langword="false"/>.
            /// </returns>
            public override bool NewWindow(ref WebBrowser webBrowser, bool cancel, WebBrowserNewWindowFlags flags, string urlContext, string url)
            {
                var uriContext = new Uri(urlContext ?? string.Empty);
                var uri        = new Uri(url ?? string.Empty);
                var e          = new WebBrowserNewWindowEventArgs(webBrowser, uriContext, uri, flags, cancel);

                this.Parent.OnNewWindow(e);

                webBrowser = e.WebBrowser;
                return(e.Cancel);
            }
Exemple #6
0
        /// <summary>
        /// Called by the control when the underlying ActiveX control is created.
        /// </summary>
        /// <param name="nativeActiveXObject">An object that represents the underlying ActiveX control.</param>
        protected override void AttachInterfaces(object nativeActiveXObject)
        {
            base.AttachInterfaces(nativeActiveXObject);

            this.WebBrowser = WebBrowser.Create(nativeActiveXObject as UnsafeNativeMethods.IWebBrowser2);
        }
            /// <summary>
            /// Notifies the <see cref="P:Parent"/> that a print template is being destroyed.
            /// </summary>
            /// <param name="webBrowser">The top-level or frame <see cref="T:WebBrowser"/> that represents the window or frame.</param>
            public override void PrintTemplateDestroyed(WebBrowser webBrowser)
            {
                var e = new WebBrowserPrintTemplateEventArgs(webBrowser);

                this.Parent.OnPrintTemplateDestroyed(e);
            }
            /// <summary>
            /// Notifies the <see cref="P:Parent"/> that a print template is being instantiated.
            /// </summary>
            /// <param name="webBrowser">The top-level or frame <see cref="T:WebBrowser"/> that represents the window or frame.</param>
            public override void PrintTemplateInstantiated(WebBrowser webBrowser)
            {
                var e = new WebBrowserPrintTemplateEventArgs(webBrowser);

                this.Parent.OnPrintTemplateCreated(e);
            }