Bug 1427186 - stop ever showing 'new tab' as a title for about:privatebrowsing in private windows, r?dao draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 07 Mar 2018 20:13:54 +0000
changeset 766397 b0b9588300b0219924a1958b4957b4a4839d6d7a
parent 766212 d6957f004e9cc3d7408ac3a8f2b49ff97556e27f
child 766398 5fe1129f445a11db1fa6f003215ecd0c282213da
push id102318
push usergijskruitbosch@gmail.com
push dateMon, 12 Mar 2018 20:45:36 +0000
reviewersdao
bugs1427186
milestone61.0a1
Bug 1427186 - stop ever showing 'new tab' as a title for about:privatebrowsing in private windows, r?dao There are 3 issues here: - the runtime changing of the title causes issues where the content title is not set. This is fixed by setting it to the private title by default; there is very little (if any) UI that allows users to even open about:privatebrowsing in 'normal' windows so we care a lot less about flicker there. To be able to include this title in the markup, we switched to a dtd. - the 'empty tab' title we set on the tab initially is set when the tab is created. This has been updated to check for private windows, and default to 'Private Browsing' instead. This will obviously also affect other new tabs in private browsing, but that seems desirable/consistent. - Likewise, we use this title when updating a tab's title that we don't yet have a content title for (which can still happen while about:privatebrowsing is loading because e10s), and so that is updated, too. MozReview-Commit-ID: nVfXD2M6UZ
browser/base/content/tabbrowser.js
browser/base/content/tabbrowser.xml
browser/components/privatebrowsing/content/aboutPrivateBrowsing.js
browser/components/privatebrowsing/content/aboutPrivateBrowsing.xhtml
browser/locales/en-US/chrome/browser/aboutPrivateBrowsing.dtd
browser/locales/en-US/chrome/browser/aboutPrivateBrowsing.properties
browser/locales/en-US/chrome/browser/tabbrowser.properties
browser/locales/jar.mn
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -1333,17 +1333,17 @@ window._gBrowser = {
             title = title.substring(0, 500) + "\u2026";
           } else {
             var characterSet = browser.characterSet;
             title = Services.textToSubURI.unEscapeNonAsciiURI(characterSet, title);
           }
         } catch (ex) { /* Do nothing. */ }
       } else {
         // Still no title? Fall back to our untitled string.
-        title = gTabBrowserBundle.GetStringFromName("tabs.emptyTabTitle");
+        title = this.tabContainer.emptyTabTitle;
       }
     }
 
     return this._setTabLabel(aTab, title, { isContentTitle });
   },
 
   _setTabLabel(aTab, aLabel, aOptions) {
     if (!aLabel) {
@@ -2265,17 +2265,17 @@ window._gBrowser = {
       lazyBrowserURI = aURIObject;
       aURI = "about:blank";
     }
 
     var uriIsAboutBlank = aURI == "about:blank";
 
     if (!aNoInitialLabel) {
       if (isBlankPageURL(aURI)) {
-        t.setAttribute("label", gTabBrowserBundle.GetStringFromName("tabs.emptyTabTitle"));
+        t.setAttribute("label", this.tabContainer.emptyTabTitle);
       } else {
         // Set URL as label so that the tab isn't empty initially.
         this.setInitialTabTitle(t, aURI, { beforeTabOpen: true });
       }
     }
 
     // Related tab inherits current tab's user context unless a different
     // usercontextid is specified
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -110,18 +110,22 @@
     <implementation implements="nsIDOMEventListener, nsIObserver">
       <constructor>
         <![CDATA[
           this._tabClipWidth = Services.prefs.getIntPref("browser.tabs.tabClipWidth");
 
           let { restoreTabsButton } = this;
           restoreTabsButton.setAttribute("label", gTabBrowserBundle.GetStringFromName("tabs.restoreLastTabs"));
 
+          let strId = PrivateBrowsingUtils.isWindowPrivate(window) ?
+              "emptyPrivateTabTitle" : "emptyTabTitle";
+          this.emptyTabTitle = gTabBrowserBundle.GetStringFromName("tabs." + strId);
+
           var tab = this.firstChild;
-          tab.label = gTabBrowserBundle.GetStringFromName("tabs.emptyTabTitle");
+          tab.label = this.emptyTabTitle;
           tab.setAttribute("onerror", "this.removeAttribute('image');");
 
           window.addEventListener("resize", this);
           window.addEventListener("DOMContentLoaded", this);
 
           Services.prefs.addObserver("privacy.userContext", this);
           this.observe(null, "nsPref:changed", "privacy.userContext.enabled");
 
--- a/browser/components/privatebrowsing/content/aboutPrivateBrowsing.js
+++ b/browser/components/privatebrowsing/content/aboutPrivateBrowsing.js
@@ -28,25 +28,24 @@ function updateTPInfo() {
   tpSubHeader.classList.toggle("tp-off", !trackingEnabled);
 }
 
 document.addEventListener("DOMContentLoaded", function() {
   let aboutCapabilities = document.aboutCapabilities;
   if (!aboutCapabilities.isWindowPrivate()) {
     document.documentElement.classList.remove("private");
     document.documentElement.classList.add("normal");
-    document.title = aboutCapabilities.getStringFromBundle(STRING_BUNDLE, "title.normal");
+    document.title = document.querySelector("title").getAttribute("notprivatetitle");
     document.getElementById("favicon").setAttribute("href", FAVICON_QUESTION);
     document.getElementById("startPrivateBrowsing").addEventListener("click", function() {
       aboutCapabilities.sendAsyncMessage("OpenPrivateWindow", null);
     });
     return;
   }
 
-  document.title = aboutCapabilities.getStringFromBundle(STRING_BUNDLE, "title.head");
   document.getElementById("startTour").addEventListener("click", function() {
     aboutCapabilities.sendAsyncMessage("DontShowIntroPanelAgain", null);
   });
   document.getElementById("startTour").setAttribute("href",
     aboutCapabilities.formatURLPref("privacy.trackingprotection.introURL"));
   document.getElementById("learnMore").setAttribute("href",
     aboutCapabilities.formatURLPref("app.support.baseURL") + "private-browsing");
 
--- a/browser/components/privatebrowsing/content/aboutPrivateBrowsing.xhtml
+++ b/browser/components/privatebrowsing/content/aboutPrivateBrowsing.xhtml
@@ -18,16 +18,17 @@
 ]>
 
 <html xmlns="http://www.w3.org/1999/xhtml" class="private">
   <head>
     <meta http-equiv="Content-Security-Policy" content="default-src chrome:"/>
     <link id="favicon" rel="icon" type="image/png" href="chrome://browser/skin/privatebrowsing/favicon.svg"/>
     <link rel="stylesheet" href="chrome://browser/content/aboutPrivateBrowsing.css" type="text/css" media="all"/>
     <link rel="stylesheet" href="chrome://browser/skin/privatebrowsing/aboutPrivateBrowsing.css" type="text/css" media="all"/>
+    <title notprivatetitle="&aboutPrivateBrowsing.notPrivate.title;">&aboutPrivateBrowsing.title;</title>
     <script type="application/javascript" src="chrome://browser/content/aboutPrivateBrowsing.js"></script>
   </head>
 
   <body dir="&locale.dir;">
     <p class="showNormal">&aboutPrivateBrowsing.notPrivate;</p>
     <button id="startPrivateBrowsing"
             class="showNormal"
             accesskey="&privatebrowsingpage.openPrivateWindow.accesskey;">&privatebrowsingpage.openPrivateWindow.label;</button>
--- a/browser/locales/en-US/chrome/browser/aboutPrivateBrowsing.dtd
+++ b/browser/locales/en-US/chrome/browser/aboutPrivateBrowsing.dtd
@@ -1,12 +1,17 @@
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
+<!-- LOCALIZATION NOTE (aboutPrivateBrowsing.title):
+     Please ensure this exactly matches tabs.emptyPrivateTabTitle in tabbrowser.properties -->
+<!ENTITY aboutPrivateBrowsing.title                      "Private Browsing">
+<!ENTITY aboutPrivateBrowsing.notPrivate.title           "Open a private window?">
+
 <!ENTITY aboutPrivateBrowsing.notPrivate                 "You are currently not in a private window.">
 <!ENTITY privatebrowsingpage.openPrivateWindow.label     "Open a Private Window">
 <!ENTITY privatebrowsingpage.openPrivateWindow.accesskey "P">
 
 <!ENTITY privateBrowsing.title                           "Private Browsing">
 <!ENTITY privateBrowsing.title.tracking                  "Private Browsing with Tracking Protection">
 <!ENTITY aboutPrivateBrowsing.info.notsaved.before       "When you browse in a Private Window, Firefox ">
 <!ENTITY aboutPrivateBrowsing.info.notsaved.emphasize    "does not save">
deleted file mode 100644
--- a/browser/locales/en-US/chrome/browser/aboutPrivateBrowsing.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-title.head=Private Browsing
-title.normal=Open a private window?
--- a/browser/locales/en-US/chrome/browser/tabbrowser.properties
+++ b/browser/locales/en-US/chrome/browser/tabbrowser.properties
@@ -1,14 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 tabs.restoreLastTabs=Restore Tabs From Last Time
 tabs.emptyTabTitle=New Tab
+# LOCALIZATION NOTE (tabs.emptyPrivateTabTitle)
+# Please ensure this exactly matches aboutPrivateBrowsing.dtd's window title (aboutPrivateBrowsing.title).
+tabs.emptyPrivateTabTitle=Private Browsing
 tabs.closeTab=Close Tab
 tabs.close=Close
 tabs.closeWarningTitle=Confirm close
 # LOCALIZATION NOTE (tabs.closeWarningMultiple):
 # Semicolon-separated list of plural forms. See:
 # http://developer.mozilla.org/en/docs/Localization_and_Plurals
 # The singular form is not considered since this string is used only for
 # multiple tabs.
--- a/browser/locales/jar.mn
+++ b/browser/locales/jar.mn
@@ -10,17 +10,16 @@
 [localization] @AB_CD@.jar:
   browser                                          (%browser/**/*.ftl)
 
 @AB_CD@.jar:
 % locale browser @AB_CD@ %locale/browser/
 *   locale/browser/bookmarks.html                  (generic/profile/bookmarks.html.in)
     locale/browser/aboutDialog.dtd                 (%chrome/browser/aboutDialog.dtd)
     locale/browser/aboutPrivateBrowsing.dtd        (%chrome/browser/aboutPrivateBrowsing.dtd)
-    locale/browser/aboutPrivateBrowsing.properties (%chrome/browser/aboutPrivateBrowsing.properties)
     locale/browser/aboutRobots.dtd                 (%chrome/browser/aboutRobots.dtd)
     locale/browser/aboutHome.dtd                   (%chrome/browser/aboutHome.dtd)
     locale/browser/accounts.properties             (%chrome/browser/accounts.properties)
     locale/browser/aboutSearchReset.dtd            (%chrome/browser/aboutSearchReset.dtd)
     locale/browser/aboutSessionRestore.dtd         (%chrome/browser/aboutSessionRestore.dtd)
     locale/browser/aboutTabCrashed.dtd             (%chrome/browser/aboutTabCrashed.dtd)
     locale/browser/browser.dtd                     (%chrome/browser/browser.dtd)
     locale/browser/baseMenuOverlay.dtd             (%chrome/browser/baseMenuOverlay.dtd)