From 0a8c1f9a496b71e516e84114bd872c0564c9542b Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 12 Nov 2014 13:59:00 +0100 Subject: [PATCH] Bug 956482 - Move inline script about:privatebrowsing out to an external file. r=jaws --- .../content/aboutPrivateBrowsing.js | 58 +++++++++++++++++++ .../content/aboutPrivateBrowsing.xhtml | 55 +----------------- browser/components/privatebrowsing/jar.mn | 3 +- .../browser_privatebrowsing_windowtitle.js | 2 +- .../browser/aboutPrivateBrowsing.properties | 2 + browser/locales/jar.mn | 1 + 6 files changed, 67 insertions(+), 54 deletions(-) create mode 100644 browser/components/privatebrowsing/content/aboutPrivateBrowsing.js create mode 100644 browser/locales/en-US/chrome/browser/aboutPrivateBrowsing.properties diff --git a/browser/components/privatebrowsing/content/aboutPrivateBrowsing.js b/browser/components/privatebrowsing/content/aboutPrivateBrowsing.js new file mode 100644 index 00000000000..3da766b7158 --- /dev/null +++ b/browser/components/privatebrowsing/content/aboutPrivateBrowsing.js @@ -0,0 +1,58 @@ +/* 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/. */ + +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; + +Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); + +var stringBundle = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService) + .createBundle("chrome://browser/locale/aboutPrivateBrowsing.properties"); + +if (!PrivateBrowsingUtils.isWindowPrivate(window)) { + document.title = stringBundle.GetStringFromName("title.normal"); + setFavIcon("chrome://global/skin/icons/question-16.png"); +} else { + document.title = stringBundle.GetStringFromName("title"); + setFavIcon("chrome://browser/skin/Privacy-16.png"); +} + +var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindow); + +function setFavIcon(url) { + var icon = document.createElement("link"); + icon.setAttribute("rel", "icon"); + icon.setAttribute("type", "image/png"); + icon.setAttribute("href", url); + var head = document.getElementsByTagName("head")[0]; + head.insertBefore(icon, head.firstChild); +} + +document.addEventListener("DOMContentLoaded", function () { + if (!PrivateBrowsingUtils.isWindowPrivate(window)) { + document.body.setAttribute("class", "normal"); + } + + // Set up the help link + let learnMoreURL = Cc["@mozilla.org/toolkit/URLFormatterService;1"] + .getService(Ci.nsIURLFormatter) + .formatURLPref("app.support.baseURL"); + let learnMore = document.getElementById("learnMore"); + if (learnMore) { + learnMore.setAttribute("href", learnMoreURL + "private-browsing"); + } + + let startPrivateBrowsing = document.getElementById("startPrivateBrowsing"); + if (startPrivateBrowsing) { + startPrivateBrowsing.addEventListener("command", openPrivateWindow); + } +}, false); + +function openPrivateWindow() { + mainWindow.OpenBrowserWindow({private: true}); +} diff --git a/browser/components/privatebrowsing/content/aboutPrivateBrowsing.xhtml b/browser/components/privatebrowsing/content/aboutPrivateBrowsing.xhtml index 8f4cf41785e..1e465d6707f 100644 --- a/browser/components/privatebrowsing/content/aboutPrivateBrowsing.xhtml +++ b/browser/components/privatebrowsing/content/aboutPrivateBrowsing.xhtml @@ -20,56 +20,7 @@ - + @@ -85,10 +36,10 @@

&aboutPrivateBrowsing.notPrivate;