public void NavigateComplete2(object pDisp, ref object url)
 {
     UnsafeNativeMethods.IWebBrowser2 webBrowser = (UnsafeNativeMethods.IWebBrowser2)pDisp;
     if (this._parent.AxIWebBrowser2 == webBrowser)
     {
         if (this._parent.DocumentStream != null)
         {
             Invariant.Assert(this._parent.NavigatingToAboutBlank && string.Compare((string)url, "about:blank", StringComparison.OrdinalIgnoreCase) == 0);
             try
             {
                 UnsafeNativeMethods.IHTMLDocument nativeHTMLDocument = this._parent.NativeHTMLDocument;
                 if (nativeHTMLDocument != null)
                 {
                     UnsafeNativeMethods.IPersistStreamInit          persistStreamInit = nativeHTMLDocument as UnsafeNativeMethods.IPersistStreamInit;
                     System.Runtime.InteropServices.ComTypes.IStream pstm = new ManagedIStream(this._parent.DocumentStream);
                     persistStreamInit.Load(pstm);
                 }
                 return;
             }
             finally
             {
                 this._parent.DocumentStream = null;
             }
         }
         string text = (string)url;
         if (this._parent.NavigatingToAboutBlank)
         {
             Invariant.Assert(string.Compare(text, "about:blank", StringComparison.OrdinalIgnoreCase) == 0);
             text = null;
         }
         Uri uri = string.IsNullOrEmpty(text) ? null : new Uri(text);
         NavigationEventArgs e = new NavigationEventArgs(uri, null, null, null, null, true);
         this._parent.OnNavigated(e);
     }
 }
Exemple #2
0
        public void NavigateComplete2(object pDisp, ref object url)
        {
            Debug.Assert(url == null || url is string, "invalid url type");

            // Events only fired for top level navigation.
            UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp;
            if (_parent.AxIWebBrowser2 == axIWebBrowser2)
            {
                // If we are loading from stream.
                if (_parent.DocumentStream != null)
                {
                    Invariant.Assert(_parent.NavigatingToAboutBlank &&
                                     (String.Compare((string)url, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0));

                    try
                    {
                        UnsafeNativeMethods.IHTMLDocument nativeHTMLDocument = _parent.NativeHTMLDocument;
                        if (nativeHTMLDocument != null)
                        {
                            UnsafeNativeMethods.IPersistStreamInit psi = nativeHTMLDocument as UnsafeNativeMethods.IPersistStreamInit;
                            Debug.Assert(psi != null, "The Document does not implement IPersistStreamInit");

                            System.Runtime.InteropServices.ComTypes.IStream iStream =
                                new MS.Internal.IO.Packaging.ManagedIStream(_parent.DocumentStream);

                            psi.Load(iStream);
                        }
                    }
                    finally
                    {
                        _parent.DocumentStream = null;
                    }
                }
                else
                {
                    string urlString = (string)url;
                    // When source set to null or navigating to stream/string, we navigate to "about:blank"
                    // internally. Make sure we pass null in the event args.
                    if (_parent.NavigatingToAboutBlank)
                    {
                        Invariant.Assert(String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0);
                        urlString = null;
                    }
                    Uri source            = (String.IsNullOrEmpty(urlString) ? null : new Uri(urlString));
                    NavigationEventArgs e = new NavigationEventArgs(source, null, null, null, null, true);

                    _parent.OnNavigated(e);
                }
            }
        }
 public void DocumentComplete(object pDisp, ref object url)
 {
     UnsafeNativeMethods.IWebBrowser2 webBrowser = (UnsafeNativeMethods.IWebBrowser2)pDisp;
     if (this._parent.AxIWebBrowser2 == webBrowser)
     {
         string text = (string)url;
         if (this._parent.NavigatingToAboutBlank)
         {
             Invariant.Assert(string.Compare(text, "about:blank", StringComparison.OrdinalIgnoreCase) == 0);
             text = null;
         }
         Uri uri = string.IsNullOrEmpty(text) ? null : new Uri(text);
         NavigationEventArgs e = new NavigationEventArgs(uri, null, null, null, null, true);
         this._parent.OnLoadCompleted(e);
     }
 }
Exemple #4
0
        public void DocumentComplete(object pDisp, ref object url)
        {
            Debug.Assert(url == null || url is string, "invalid url type");

            // Events only fired for top level navigation.
            UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp;
            if (_parent.AxIWebBrowser2 == axIWebBrowser2)
            {
                string urlString = (string)url;
                // When source set to null or navigating to stream/string, we navigate to "about:blank"
                // internally. Make sure we pass null in the event args.
                if (_parent.NavigatingToAboutBlank)
                {
                    Invariant.Assert(String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0);
                    urlString = null;
                }
                Uri source            = (String.IsNullOrEmpty(urlString) ? null : new Uri(urlString));
                NavigationEventArgs e = new NavigationEventArgs(source, null, null, null, null, true);

                _parent.OnLoadCompleted(e);
            }
        }
 protected override void DetachInterfaces()
 {
   this.axIWebBrowser2 = null;
   base.DetachInterfaces();
 }
 protected override void AttachInterfaces(object nativeActiveXObject)
 {
   this.axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)nativeActiveXObject;
   base.AttachInterfaces(nativeActiveXObject);
 }
Exemple #7
0
 protected override void DetachInterfaces()
 {
     this.axIWebBrowser2 = null;
     base.DetachInterfaces();
 }
Exemple #8
0
 protected override void AttachInterfaces(object nativeActiveXObject)
 {
     this.axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)nativeActiveXObject;
     base.AttachInterfaces(nativeActiveXObject);
 }
Exemple #9
0
        public void BeforeNavigate2(object pDisp, ref object url, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel)
        {
            bool newNavigationInitiated = false;
            bool cancelRequested        = false;

            try
            {
                Debug.Assert(url == null || url is string, "invalid url type");
                Debug.Assert(targetFrameName == null || targetFrameName is string, "invalid targetFrameName type");
                Debug.Assert(headers == null || headers is string, "invalid headers type");
                //
                // Due to a


                if (targetFrameName == null)
                {
                    targetFrameName = "";
                }
                if (headers == null)
                {
                    headers = "";
                }

                string urlString = (string)url;
                Uri    source    = String.IsNullOrEmpty(urlString) ? null : new Uri(urlString);

                UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp;
                // If _parent.AxIWebBrowser2 != axIWebBrowser2, navigation happens in a nested [i]frame.
                // in that case we do not want to enforce site locking as we want the default IE behavior to take
                // over.
                if (_parent.AxIWebBrowser2 == axIWebBrowser2)
                {
                    // The NavigatingToAboutBlank property indicates whether we are navigating to "about:blank"
                    // as a result of navigating to null or stream/string navigation.
                    // We set the NavigatingToAboutBlank bit to true in the WebBrowser DoNavigate method. When the above
                    // conditions occur, the NavigatingToAboutBlank is true and the source must be "about:blank".
                    //
                    // But when end user navigates away from the current about:blank page (by clicking
                    // on a hyperlink, Goback/Forward), or programmatically call GoBack and Forward,
                    // When we get the navigating event, NavigatingToAboutBlank is true, but the source is not "about:blank".
                    // Clear the NavigatingToAboutBlank bit in that case.
                    if ((_parent.NavigatingToAboutBlank) &&
                        String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        _parent.NavigatingToAboutBlank = false;
                    }

                    // Site locking for top level WebOC navigation
                    // "about:blank is not enabled in partial trust publicly.
                    // We enable it internally to navigate to null.
                    if ((!_parent.NavigatingToAboutBlank) &&
                        !SecurityHelper.CallerHasWebPermission(source) &&
                        !IsAllowedScriptScheme(source))
                    {
                        cancelRequested = true;
                    }
                    else
                    {
                        // When source set to null or navigating to stream/string, we navigate to "about:blank"
                        // internally. Make sure we pass null in the event args.
                        if (_parent.NavigatingToAboutBlank)
                        {
                            source = null;
                        }

                        NavigatingCancelEventArgs e = new NavigatingCancelEventArgs(source,
                                                                                    null, null, null, NavigationMode.New, null, null, true);

                        // TFS Dev10 520954 - Launching a navigation from the Navigating event handler causes reentrancy.
                        // For more info, see WebBrowser.LastNavigation. This is a point of possible reentrancy. Whenever
                        // a new navigation is started during the call to the Navigating event handler, we need to cancel
                        // out the current navigation.
                        Guid lastNavigation = _parent.LastNavigation;

                        // Fire navigating event. Events are only fired for top level navigation.
                        _parent.OnNavigating(e);

                        // TFS Dev10 520954 - Launching a navigation from the Navigating event handler causes reentrancy.
                        // For more info, see WebBrowser.LastNavigation. If _lastNavigation has changed during the call to
                        // the event handlers for Navigating, we know a new navigation has been initialized.
                        if (_parent.LastNavigation != lastNavigation)
                        {
                            newNavigationInitiated = true;
                        }

                        cancelRequested = e.Cancel;
                    }
                }
            }
            // We disable this to suppress FXCop warning since in this case we really want to catch all exceptions
            // please refer to comment below
#pragma warning disable 6502
            catch
            {
                // This is an interesting pattern of putting a try catch block around this that catches everything,
                // The reason I do this is based on a conversation with Microsoft. What happens here is if there is
                // an exception in any of the code above then navigation still continues since COM interop eats up
                // the exception. But what we want is for this navigation to fail.
                // There fore I catch all exceptions and cancel navigation
                cancelRequested = true;
            }
#pragma warning restore 6502
            finally
            {
                // Clean the WebBrowser control state if navigation cancelled.
                //
                // TFS Dev10 520954 - Launching a navigation from the Navigating event handler causes reentrancy.
                // For more info, see WebBrowser.LastNavigation. A new navigation started during event handling for
                // the Navigating event will have touched the control's global state. In case the navigation was
                // cancelled in order to start a new navigation, we shouldn't tamper with that new state.
                if (cancelRequested && !newNavigationInitiated)
                {
                    _parent.CleanInternalState();
                }

                // TFS Dev10 520954 - Launching a navigation from the Navigating event handler causes reentrancy.
                // For more info, see WebBrowser.LastNavigation. Whenever a new navigation is started during the
                // call to the Navigating event handler, we need to cancel out the current navigation.
                if (cancelRequested || newNavigationInitiated)
                {
                    cancel = true;
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WebBrowser"/> class.
 /// </summary>
 /// <param name="activeXWebBrowser">The ActiveX Web Browser.</param>
 internal WebBrowser(UnsafeNativeMethods.IWebBrowser2 activeXWebBrowser)
 {
     this.ActiveXWebBrowser = activeXWebBrowser;
     this.Properties        = new WebBrowserPropertyAccessor(this);
 }
Exemple #11
0
 protected override void AttachInterfaces(object nativeActiveXObject)
 {
     this.axIWebBrowser2        = (UnsafeNativeMethods.IWebBrowser2)nativeActiveXObject;
     this.axIWebBrowser2.Silent = true;//不弹脚本错误框
     base.AttachInterfaces(nativeActiveXObject);
 }
        public void BeforeNavigate2(object pDisp, ref object url, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel)
        {
            bool flag  = false;
            bool flag2 = false;

            try
            {
                if (targetFrameName == null)
                {
                    targetFrameName = "";
                }
                if (headers == null)
                {
                    headers = "";
                }
                string text = (string)url;
                Uri    uri  = string.IsNullOrEmpty(text) ? null : new Uri(text);
                UnsafeNativeMethods.IWebBrowser2 webBrowser = (UnsafeNativeMethods.IWebBrowser2)pDisp;
                if (this._parent.AxIWebBrowser2 == webBrowser)
                {
                    if (this._parent.NavigatingToAboutBlank && string.Compare(text, "about:blank", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        this._parent.NavigatingToAboutBlank = false;
                    }
                    if (!this._parent.NavigatingToAboutBlank && !SecurityHelper.CallerHasWebPermission(uri) && !WebBrowserEvent.IsAllowedScriptScheme(uri))
                    {
                        flag2 = true;
                    }
                    else
                    {
                        if (this._parent.NavigatingToAboutBlank)
                        {
                            uri = null;
                        }
                        NavigatingCancelEventArgs navigatingCancelEventArgs = new NavigatingCancelEventArgs(uri, null, null, null, NavigationMode.New, null, null, true);
                        Guid lastNavigation = this._parent.LastNavigation;
                        this._parent.OnNavigating(navigatingCancelEventArgs);
                        if (this._parent.LastNavigation != lastNavigation)
                        {
                            flag = true;
                        }
                        flag2 = navigatingCancelEventArgs.Cancel;
                    }
                }
            }
            catch
            {
                flag2 = true;
            }
            finally
            {
                if (flag2 && !flag)
                {
                    this._parent.CleanInternalState();
                }
                if (flag2 || flag)
                {
                    cancel = true;
                }
            }
        }