Bug 1276117 - part 2: fix the URL bar state when loading about:home from a new tab page, r?mikedeboer
MozReview-Commit-ID: FADnX8bymNE
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -632,25 +632,32 @@
if (aStateFlags & nsIWebProgressListener.STATE_START &&
aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
if (aWebProgress.isTopLevel) {
// Need to use originalLocation rather than location because things
// like about:home and about:privatebrowsing arrive with nsIRequest
// pointing to their resolved jar: or file: URIs.
if (!(originalLocation && gInitialPages.includes(originalLocation.spec) &&
originalLocation != "about:blank" &&
+ this.mBrowser.initialPageLoadedFromURLBar != originalLocation.spec &&
this.mBrowser.currentURI && this.mBrowser.currentURI.spec == "about:blank")) {
- // This will trigger clearing the location bar. Don't do it if
- // we loaded off a blank browser and this is an initial page load
- // (e.g. about:privatebrowsing, about:newtab, etc.) so we avoid
- // clearing the location bar in case the user is typing in it.
- // loading about:blank shouldn't trigger this, either, because its
- // loads are "special".
+ // Indicating that we started a load will allow the location
+ // bar to be cleared when the load finishes.
+ // In order to not overwrite user-typed content, we avoid it
+ // (see if condition above) in a very specific case:
+ // If the load is of an 'initial' page (e.g. about:privatebrowsing,
+ // about:newtab, etc.), was not explicitly typed in the location
+ // bar by the user, is not about:blank (because about:blank can be
+ // loaded by websites under their principal), and the current
+ // page in the browser is about:blank (indicating it is a newly
+ // created or re-created browser, e.g. because it just switched
+ // remoteness or is a new tab/window).
this.mBrowser.urlbarChangeTracker.startedLoad();
}
+ delete this.mBrowser.initialPageLoadedFromURLBar;
// If the browser is loading it must not be crashed anymore
this.mTab.removeAttribute("crashed");
}
if (this._shouldShowProgress(aRequest)) {
if (!(aStateFlags & nsIWebProgressListener.STATE_RESTORING)) {
this.mTab.setAttribute("busy", "true");
--- a/browser/base/content/test/urlbar/browser_urlbarAboutHomeLoading.js
+++ b/browser/base/content/test/urlbar/browser_urlbarAboutHomeLoading.js
@@ -36,8 +36,31 @@ add_task(function* clearURLBarAfterParen
});
document.getElementById("home-button").click();
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
is(gURLBar.value, "", "URL bar should be empty");
is(tab.linkedBrowser.userTypedValue, null, "The browser should have no recorded userTypedValue");
yield BrowserTestUtils.removeTab(tab);
});
+/**
+ * Load about:home directly from an about:newtab page. Because it is an
+ * 'initial' page, we need to treat this specially if the user actually
+ * loads a page like this from the URL bar.
+ */
+add_task(function* clearURLBarAfterManuallyLoadingAboutHome() {
+ let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(gBrowser, () => {});
+ // This opens about:newtab:
+ BrowserOpenTab();
+ let tab = yield tabOpenedAndSwitchedTo;
+ is(gURLBar.value, "", "URL bar should be empty");
+ is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
+
+ gURLBar.value = "about:home";
+ gURLBar.select();
+ let aboutHomeLoaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, "about:home");
+ EventUtils.sendKey("return");
+ yield aboutHomeLoaded;
+
+ is(gURLBar.value, "", "URL bar should be empty");
+ is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
+ yield BrowserTestUtils.removeTab(tab);
+});
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -377,16 +377,19 @@ file, You can obtain one at http://mozil
}
});
}
function continueOperation()
{
this.value = url;
gBrowser.userTypedValue = url;
+ if (gInitialPages.includes(url)) {
+ gBrowser.selectedBrowser.initialPageLoadedFromURLBar = url;
+ }
try {
addToUrlbarHistory(url);
} catch (ex) {
// Things may go wrong when adding url to session history,
// but don't let that interfere with the loading of the url.
Cu.reportError(ex);
}