Bug 1372996 - Clear the URL bar when on ext newtab r?mixedpuppy draft
authorMark Striemer <mstriemer@mozilla.com>
Fri, 01 Sep 2017 09:39:24 -0500
changeset 662426 d05ec1caebe30eb66faff24cc41e1f2c330d26a5
parent 662425 b7f103d256b97191fe58277fbb14028a9f5f8819
child 730859 c227f0f4badb39d6fa2c7eb6ce944cdb180e530f
push id79074
push userbmo:mstriemer@mozilla.com
push dateMon, 11 Sep 2017 17:17:14 +0000
reviewersmixedpuppy
bugs1372996
milestone57.0a1
Bug 1372996 - Clear the URL bar when on ext newtab r?mixedpuppy MozReview-Commit-ID: 2NNOK2kRPgl
browser/base/content/browser.js
browser/components/extensions/test/browser/browser_ext_identity_indication.js
browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -296,16 +296,20 @@ var gInitialPages = [
   "about:blank",
   "about:newtab",
   "about:home",
   "about:privatebrowsing",
   "about:welcomeback",
   "about:sessionrestore"
 ];
 
+function isInitialPage(url) {
+  return gInitialPages.includes(url) || url == BROWSER_NEW_TAB_URL;
+}
+
 function* browserWindows() {
   let windows = Services.wm.getEnumerator("navigator:browser");
   while (windows.hasMoreElements())
     yield windows.getNext();
 }
 
 /**
 * We can avoid adding multiple load event listeners and save some time by adding
@@ -2744,29 +2748,33 @@ function URLBarSetURI(aURI) {
     let uri = aURI || gBrowser.currentURI;
     // Strip off "wyciwyg://" and passwords for the location bar
     try {
       uri = Services.uriFixup.createExposableURI(uri);
     } catch (e) {}
 
     // Replace initial page URIs with an empty string
     // only if there's no opener (bug 370555).
-    if (gInitialPages.includes(uri.spec) &&
+    if (isInitialPage(uri.spec) &&
         checkEmptyPageOrigin(gBrowser.selectedBrowser, uri)) {
       value = "";
     } else {
       // We should deal with losslessDecodeURI throwing for exotic URIs
       try {
         value = losslessDecodeURI(uri);
       } catch (ex) {
         value = "about:blank";
       }
     }
 
     valid = !isBlankPageURL(uri.spec) || uri.schemeIs("moz-extension");
+  } else if (isInitialPage(value) &&
+             checkEmptyPageOrigin(gBrowser.selectedBrowser, value)) {
+    value = "";
+    valid = true;
   }
 
   let isDifferentValidValue = valid && value != gURLBar.value;
   gURLBar.value = value;
   gURLBar.valueIsTyped = !valid;
   gURLBar.removeAttribute("usertyping");
   if (isDifferentValidValue) {
     gURLBar.selectionStart = gURLBar.selectionEnd = 0;
--- a/browser/components/extensions/test/browser/browser_ext_identity_indication.js
+++ b/browser/components/extensions/test/browser/browser_ext_identity_indication.js
@@ -84,14 +84,15 @@ add_task(async function testIdentityIndi
 
   await extension.startup();
 
   confirmDefaults();
 
   let url = await extension.awaitMessage("url");
   await BrowserTestUtils.withNewTab({gBrowser, url}, async function() {
     confirmExtensionPage();
+    is(gURLBar.value, "", "The URL bar is blank");
   });
 
   await extension.unload();
 
   confirmDefaults();
 });
--- a/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
+++ b/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
@@ -40,8 +40,57 @@ add_task(async function test_sending_mes
 
   let url = await extension.awaitMessage("from-newtab-page");
   ok(url.endsWith(NEWTAB_URI_1),
      "Newtab url is overriden by the extension.");
 
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
   await extension.unload();
 });
+
+/**
+ * Ensure we don't show the extension URL in the URL bar temporarily in new tabs
+ * while we're switching remoteness (when the URL we're loading and the
+ * default content principal are different).
+ */
+add_task(async function dontTemporarilyShowAboutExtensionPath() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      name: "Test Extension",
+      applications: {
+        gecko: {
+          id: "newtab@mochi.test",
+        },
+      },
+      chrome_url_overrides: {
+        newtab: "newtab.html",
+      },
+    },
+    background() {
+      browser.test.sendMessage("url", browser.runtime.getURL("newtab.html"));
+    },
+    files: {
+      "newtab.html": "<h1>New tab!</h1>",
+    },
+    useAddonManager: "temporary",
+  });
+
+  await extension.startup();
+  let url = await extension.awaitMessage("url");
+
+  let wpl = {
+    onLocationChange() {
+      is(gURLBar.value, "", "URL bar value should stay empty.");
+    },
+  };
+  gBrowser.addProgressListener(wpl);
+
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser, url});
+
+  gBrowser.removeProgressListener(wpl);
+  is(gURLBar.value, "", "URL bar value should be empty.");
+  ContentTask.spawn(tab.linkedBrowser, null, function() {
+    is(content.document.body.textContent, "New tab!", "New tab page is loaded.");
+  });
+
+  await extension.unload();
+  await BrowserTestUtils.removeTab(tab);
+});