Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
using MS.Internal.AppModel;
using MS.Internal.Interop;

//In order to avoid generating warnings about unknown message numbers and
//unknown pragmas when compiling your C# source code with the actual C# compiler,
//In order to avoid generating warnings about unknown message numbers and
//unknown pragmas when compiling your C# source code with the actual C# compiler,
//you need to disable warnings 1634 and 1691. (Presharp Documentation)
#pragma warning disable 1634, 1691

Expand Down Expand Up @@ -72,15 +72,15 @@ public void BeforeNavigate2(object pDisp, ref object url, ref object flags, ref

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.
// 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".
//
// 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".
Expand Down Expand Up @@ -174,11 +174,11 @@ 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.
// Events only fired for top level navigation.
UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp;
if (_parent.AxIWebBrowser2 == axIWebBrowser2)
if (_parent.AxIWebBrowser2 == axIWebBrowser2 && !ShouldIgnoreCompletionEvent(ref url))
{
// If we are loading from stream.
// If we are loading from stream.
if (_parent.DocumentStream != null)
{
Invariant.Assert(_parent.NavigatingToAboutBlank &&
Expand Down Expand Up @@ -207,7 +207,7 @@ public void NavigateComplete2(object pDisp, ref object url)
{
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.
// internally. Make sure we pass null in the event args.
if (_parent.NavigatingToAboutBlank)
{
Invariant.Assert(String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0);
Expand All @@ -229,13 +229,13 @@ 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.
// Events only fired for top level navigation.
UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp;
if (_parent.AxIWebBrowser2 == axIWebBrowser2)
if (_parent.AxIWebBrowser2 == axIWebBrowser2 && !ShouldIgnoreCompletionEvent(ref url))
{
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.
// internally. Make sure we pass null in the event args.
if (_parent.NavigatingToAboutBlank)
{
Invariant.Assert(String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0);
Expand All @@ -248,6 +248,17 @@ public void DocumentComplete(object pDisp, ref object url)
}
}

// if we are navigating to "about:blank", ignore completion events
// for any other url. These can happen despite our attempt to cancel
// outstanding navigations (see WebBrowser.DoNavigate), due to race
// conditions between the browser and us.
private bool ShouldIgnoreCompletionEvent(ref object url)
{
string urlString = url as string;
return (_parent.NavigatingToAboutBlank &&
String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) != 0);
}

public void CommandStateChange(long command, bool enable)
{
if (command == NativeMethods.CSC_NAVIGATEBACK)
Expand Down