Bug 562649 - set and correctly handle userTypedValue when loading external URIs. r=gavin,neil

--HG--
extra : rebase_source : f147fcde568bc15e25be804591518b694d605a95
This commit is contained in:
Dão Gottwald 2010-06-08 22:13:55 +02:00
parent 425f7b166a
commit 1dafa1b1fb
5 changed files with 44 additions and 25 deletions

View File

@ -4288,17 +4288,6 @@ var XULBrowserWindow = {
gBrowser.selectedBrowser.engines = null;
var uri = aRequest.QueryInterface(Ci.nsIChannel).URI;
// Set the URI now if it isn't already set, so that the user can tell which
// site is loading. Only do this if the content window has no opener, though
// (i.e. the load wasn't triggered by a content-controlled link), to
// minimize spoofing risk.
if (gURLBar &&
gURLBar.value == "" &&
!content.opener &&
getWebNavigation().currentURI.spec == "about:blank")
URLBarSetURI(uri);
try {
Services.obs.notifyObservers(content, "StartDocumentLoad", uri.spec);
} catch (e) {
@ -4486,9 +4475,6 @@ nsBrowserAccess.prototype = {
return null;
}
var loadflags = isExternal ?
Ci.nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL :
Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW)
aWhere = gPrefService.getIntPref("browser.link.open_newwindow");
switch (aWhere) {
@ -4528,17 +4514,12 @@ nsBrowserAccess.prototype = {
let loadInBackground = gPrefService.getBoolPref("browser.tabs.loadDivertedInBackground");
let referrer = aOpener ? makeURI(aOpener.location.href) : null;
// If this is an external load, we need to load a blank tab first,
// because loadflags can't be passed to loadOneTab.
let loadBlankFirst = !aURI || isExternal;
let tab = win.gBrowser.loadOneTab(loadBlankFirst ? "about:blank" : aURI.spec, {
let tab = win.gBrowser.loadOneTab(aURI ? aURI.spec : "about:blank", {
referrerURI: referrer,
fromExternal: isExternal,
inBackground: loadInBackground});
let browser = win.gBrowser.getBrowserForTab(tab);
if (loadBlankFirst && aURI)
browser.loadURIWithFlags(aURI.spec, loadflags, referrer, null, null);
newWindow = browser.contentWindow;
if (needToFocusWin || (!loadInBackground && isExternal))
newWindow.focus();
@ -4547,6 +4528,9 @@ nsBrowserAccess.prototype = {
newWindow = content;
if (aURI) {
let referrer = aOpener ? makeURI(aOpener.location.href) : null;
let loadflags = isExternal ?
Ci.nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL :
Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
gBrowser.loadURIWithFlags(aURI.spec, loadflags, referrer, null, null);
}
if (!gPrefService.getBoolPref("browser.tabs.loadDivertedInBackground"))

View File

@ -1044,6 +1044,7 @@
<parameter name="aAllowThirdPartyFixup"/>
<body>
<![CDATA[
var aFromExternal;
var aRelatedToCurrent;
if (arguments.length == 2 &&
typeof arguments[1] == "object" &&
@ -1054,6 +1055,7 @@
aPostData = params.postData;
aLoadInBackground = params.inBackground;
aAllowThirdPartyFixup = params.allowThirdPartyFixup;
aFromExternal = params.fromExternal;
aRelatedToCurrent = params.relatedToCurrent;
}
@ -1066,6 +1068,7 @@
postData: aPostData,
ownerTab: owner,
allowThirdPartyFixup: aAllowThirdPartyFixup,
fromExternal: aFromExternal,
relatedToCurrent: aRelatedToCurrent});
if (!bgLoad)
this.selectedTab = tab;
@ -1135,6 +1138,7 @@
<parameter name="aAllowThirdPartyFixup"/>
<body>
<![CDATA[
var aFromExternal;
var aRelatedToCurrent;
if (arguments.length == 2 &&
typeof arguments[1] == "object" &&
@ -1145,6 +1149,7 @@
aPostData = params.postData;
aOwner = params.ownerTab;
aAllowThirdPartyFixup = params.allowThirdPartyFixup;
aFromExternal = params.fromExternal;
aRelatedToCurrent = params.relatedToCurrent;
}
@ -1270,9 +1275,11 @@
// the document successfully loads
b.userTypedValue = aURI;
let flags = aAllowThirdPartyFixup ?
Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP :
Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
if (aAllowThirdPartyFixup)
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
if (aFromExternal)
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL;
try {
b.loadURIWithFlags(aURI, flags, aReferrerURI, aCharset, aPostData);
}

View File

@ -122,6 +122,7 @@ _BROWSER_FILES = \
browser_bug550565.js \
browser_bug555224.js \
browser_bug556061.js \
browser_bug562649.js \
browser_bug563588.js \
browser_contextSearchTabPosition.js \
browser_ctrlTab.js \

View File

@ -0,0 +1,24 @@
function test() {
const URI = "data:text/plain,bug562649";
browserDOMWindow.openURI(makeURI(URI),
null,
Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
ok(XULBrowserWindow.isBusy, "window is busy loading a page");
is(gBrowser.userTypedValue, URI, "userTypedValue matches test URI");
is(gURLBar.value, URI, "location bar value matches test URI");
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.removeCurrentTab();
is(gBrowser.userTypedValue, URI, "userTypedValue matches test URI after switching tabs");
is(gURLBar.value, URI, "location bar value matches test URI after switching tabs");
waitForExplicitFinish();
gBrowser.selectedBrowser.addEventListener("load", function () {
is(gBrowser.userTypedValue, null, "userTypedValue is null as the page has loaded");
is(gURLBar.value, URI, "location bar value matches test URI as the page has loaded");
gBrowser.removeCurrentTab();
finish();
}, true);
}

View File

@ -182,8 +182,11 @@
catch (e) {
}
}
try {
if (!(aFlags & this.webNavigation.LOAD_FLAGS_FROM_EXTERNAL))
this.userTypedClear++;
try {
this.webNavigation.loadURI(aURI, aFlags, aReferrerURI, aPostData, null);
} finally {
if (this.userTypedClear)