Exemple #1
0
            public void BeforeNavigate2(object pDisp, ref object urlObject, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel)
            {
                Debug.Assert(_parent != null, "Parent should have been set");
                //Note: we want to allow navigation if we haven't already navigated.
                if (AllowNavigation || !_haveNavigated)
                {
                    Debug.Assert(urlObject is null || urlObject is string, "invalid url type");
                    Debug.Assert(targetFrameName is null || targetFrameName is string, "invalid targetFrameName type");
                    Debug.Assert(headers is null || headers is string, "invalid headers type");
                    //
                    // If during running interop code, the variant.bstr value gets set
                    // to -1 on return back to native code, if the original value was null, we
                    // have to set targetFrameName and headers to string.Empty.
                    if (targetFrameName is null)
                    {
                        targetFrameName = string.Empty;
                    }
                    if (headers is null)
                    {
                        headers = string.Empty;
                    }

                    string urlString = urlObject is null ? string.Empty : (string)urlObject;
                    WebBrowserNavigatingEventArgs e = new WebBrowserNavigatingEventArgs(
                        new Uri(urlString), targetFrameName is null ? string.Empty : (string)targetFrameName);
                    _parent.OnNavigating(e);
                    cancel = e.Cancel;
                }
                else
                {
                    cancel = true;
                }
            }