commit 4a726fc8a675c0882cbfba2514deb32b53ade2ab Author: Kathy Brade brade@pearlcrescent.com Date: Wed Nov 25 11:36:20 2015 -0500
Bug 16940: After update, load local change notes.
Add an about:tbupdate page that displays the first section from TorBrowser/Docs/ChangeLog.txt and includes a link to the remote post-update page (typically our blog entry for the release). --- .../base/content/abouttbupdate/aboutTBUpdate.css | 34 +++++++++++ .../base/content/abouttbupdate/aboutTBUpdate.js | 10 +++ .../base/content/abouttbupdate/aboutTBUpdate.xhtml | 34 +++++++++++ .../content/abouttbupdate/aboutTBUpdateLogo.png | Bin 0 -> 23266 bytes browser/base/content/browser.js | 14 ++++- browser/base/content/content.js | 64 ++++++++++++++++++++ browser/base/jar.mn | 8 ++- browser/components/about/AboutRedirector.cpp | 8 +++ browser/components/build/nsModule.cpp | 3 + browser/components/nsBrowserContentHandler.js | 12 ++++ .../locales/en-US/chrome/browser/aboutTBUpdate.dtd | 6 ++ browser/locales/jar.mn | 3 + 12 files changed, 194 insertions(+), 2 deletions(-)
diff --git a/browser/base/content/abouttbupdate/aboutTBUpdate.css b/browser/base/content/abouttbupdate/aboutTBUpdate.css new file mode 100644 index 0000000..489c9d2 --- /dev/null +++ b/browser/base/content/abouttbupdate/aboutTBUpdate.css @@ -0,0 +1,34 @@ +body { + font-family: sans-serif; + font-size: 110%; + background-image: -moz-linear-gradient(top, #ffffff, #ffffff 10%, #d5ffd5 50%, #d5ffd5); + background-attachment: fixed; + background-size: 100% 100%; +} + +#logo { + background-image: url("chrome://browser/content/abouttbupdate/aboutTBUpdateLogo.png"); + height: 128px; + width: 128px; + margin: 20px; + float: left; +} + +#msg { + margin-top: 50px; + float: left; +} + +#msg-updated { + font-size: 120%; + margin-bottom: 20px; +} + +#changelog-container { + margin: 0px 20px 20px 20px; +} + +#changelog { + margin-left: 20px; + white-space: pre; +} diff --git a/browser/base/content/abouttbupdate/aboutTBUpdate.js b/browser/base/content/abouttbupdate/aboutTBUpdate.js new file mode 100644 index 0000000..8243647 --- /dev/null +++ b/browser/base/content/abouttbupdate/aboutTBUpdate.js @@ -0,0 +1,10 @@ +// Copyright (c) 2015, The Tor Project, Inc. +// See LICENSE for licensing information. +// +// vim: set sw=2 sts=2 ts=8 et syntax=javascript: + +function init() +{ + let event = new CustomEvent("AboutTBUpdateLoad", { bubbles: true }); + document.dispatchEvent(event); +} diff --git a/browser/base/content/abouttbupdate/aboutTBUpdate.xhtml b/browser/base/content/abouttbupdate/aboutTBUpdate.xhtml new file mode 100644 index 0000000..3a29e0c --- /dev/null +++ b/browser/base/content/abouttbupdate/aboutTBUpdate.xhtml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!DOCTYPE html [ + <!ENTITY % htmlDTD + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "DTD/xhtml1-strict.dtd"> + %htmlDTD; + <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd"> + %globalDTD; + <!ENTITY % tbUpdateDTD SYSTEM "chrome://browser/locale/aboutTBUpdate.dtd"> + %tbUpdateDTD; +]> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <title>&aboutTBUpdate.title;</title> + <link rel="stylesheet" type="text/css" + href="chrome://browser/content/abouttbupdate/aboutTBUpdate.css"/> + <script src="chrome://browser/content/abouttbupdate/aboutTBUpdate.js" + type="text/javascript;version=1.7"/> +</head> +<body dir="&locale.dir;" onload="init()"> +<div id="logo"/> +<div id="msg"> +<div id="msg-updated">&aboutTBUpdate.updated;</div> +<div>&aboutTBUpdate.linkPrefix;<a id="infolink">&aboutTBUpdate.linkLabel;</a>&aboutTBUpdate.linkSuffix; +</div> +</div> +<br clear="all"/> +<div id="changelog-container">&aboutTBUpdate.changeLogHeading; +<div id="changelog"></div> +</div> +</body> +</html> diff --git a/browser/base/content/abouttbupdate/aboutTBUpdateLogo.png b/browser/base/content/abouttbupdate/aboutTBUpdateLogo.png new file mode 100644 index 0000000..be5cae9 Binary files /dev/null and b/browser/base/content/abouttbupdate/aboutTBUpdateLogo.png differ diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index baddc59..815f018 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -216,6 +216,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "ReaderParent",
let gInitialPages = [ "about:tor", +#ifdef TOR_BROWSER_UPDATE + "about:tbupdate", +#endif "about:blank", "about:newtab", "about:home", @@ -2354,7 +2357,11 @@ function URLBarSetURI(aURI) { // Replace initial page URIs with an empty string // only if there's no opener (bug 370555). // Bug 863515 - Make content.opener checks work in electrolysis. +#ifdef TOR_BROWSER_UPDATE + if (gInitialPages.indexOf(uri.spec.split('?')[0]) != -1) +#else if (gInitialPages.indexOf(uri.spec) != -1) +#endif value = !gMultiProcessBrowser && content.opener ? uri.spec : ""; else value = losslessDecodeURI(uri); @@ -6951,8 +6958,13 @@ var gIdentityHandler = {
// Chrome URIs however get special treatment. Some chrome URIs are // whitelisted to provide a positive security signal to the user. - let whitelist = /^about:(accounts|addons|app-manager|config|crashes|customizing|downloads|healthreport|home|license|newaddon|permissions|preferences|privatebrowsing|rights|sessionrestore|support|welcomeback)/i; +#ifdef TOR_BROWSER_UPDATE + let whitelist = /^about:(accounts|addons|app-manager|config|crashes|customizing|downloads|healthreport|home|license|newaddon|permissions|preferences|privatebrowsing|rights|sessionrestore|support|welcomeback|tor|tbupdate)/i; + let isChromeUI = uri.schemeIs("about") && whitelist.test(uri.spec.split('?')[0]); +#else + let whitelist = /^about:(accounts|addons|app-manager|config|crashes|customizing|downloads|healthreport|home|license|newaddon|permissions|preferences|privatebrowsing|rights|sessionrestore|support|welcomeback|tor)/i; let isChromeUI = uri.schemeIs("about") && whitelist.test(uri.spec); +#endif if (isChromeUI) { this.setMode(this.IDENTITY_MODE_CHROMEUI); } else if (unknown) { diff --git a/browser/base/content/content.js b/browser/base/content/content.js index 14f21fc..fd87352 100644 --- a/browser/base/content/content.js +++ b/browser/base/content/content.js @@ -11,6 +11,9 @@ Cu.import("resource:///modules/ContentWebRTC.jsm"); Cu.import("resource:///modules/ContentObservers.jsm"); Cu.import("resource://gre/modules/InlineSpellChecker.jsm"); Cu.import("resource://gre/modules/InlineSpellCheckerContent.jsm"); +#ifdef TOR_BROWSER_UPDATE +Cu.import("resource://gre/modules/NetUtil.jsm"); +#endif
XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils", "resource:///modules/E10SUtils.jsm"); @@ -560,6 +563,67 @@ let AboutReaderListener = { }; AboutReaderListener.init();
+#ifdef TOR_BROWSER_UPDATE +let AboutTBUpdateListener = { + init: function(chromeGlobal) { + chromeGlobal.addEventListener('AboutTBUpdateLoad', this, false, true); + }, + + get isAboutTBUpdate() { + return content.document.documentURI.split('?')[0].toLowerCase() + == "about:tbupdate"; + }, + + handleEvent: function(aEvent) { + if (this.isAboutTBUpdate && (aEvent.type == "AboutTBUpdateLoad")) + this.onPageLoad(); + }, + + onPageLoad: function() { + let doc = content.document; + doc.getElementById("infolink").setAttribute("href", this.getPostUpdateURL()); + doc.getElementById("changelog").textContent = this.getChangeLogText(); + }, + + // Extract the post update URL from this page's query string. + getPostUpdateURL: function() { + let idx = content.document.documentURI.indexOf('?'); + if (idx > 0) + return decodeURIComponent(content.document.documentURI.substring(idx+1)); + + // No query string: use the default URL. + return Services.urlFormatter.formatURLPref("startup.homepage_override_url"); + }, + + // Read and return the text from the beginning of the changelog file that is + // located at TorBrowser/Docs/ChangeLog.txt. + // When electrolysis is enabled we will need to adopt an architecture that is + // more similar to the one that is used for about:home (see AboutHomeListener + // in this file and browser/modules/AboutHome.jsm). + getChangeLogText: function() { + try { + // "DefProfRt" is .../TorBrowser/Data/Browser + let f = Cc["@mozilla.org/file/directory_service;1"] + .getService(Ci.nsIProperties).get("DefProfRt", Ci.nsIFile); + f = f.parent.parent; // Remove "Data/Browser" + f.appendRelativePath("Docs/ChangeLog.txt"); + + let fs = Cc["@mozilla.org/network/file-input-stream;1"] + .createInstance(Ci.nsIFileInputStream); + fs.init(f, -1, 0, 0); + let s = NetUtil.readInputStreamToString(fs, fs.available()); + fs.close(); + + // Truncate at the first empty line. + return s.replace(/[\r\n][\r\n][\s\S]*$/m, ""); + } catch (e) {} + + return ""; + }, +}; +AboutTBUpdateListener.init(this); +#endif + // An event listener for custom "WebChannelMessageToChrome" events on pages addEventListener("WebChannelMessageToChrome", function (e) { // if target is window then we want the document principal, otherwise fallback to target itself. diff --git a/browser/base/jar.mn b/browser/base/jar.mn index 00f0c8a..73f370a 100644 --- a/browser/base/jar.mn +++ b/browser/base/jar.mn @@ -72,12 +72,18 @@ browser.jar: content/browser/aboutTabCrashed.css (content/aboutTabCrashed.css) content/browser/aboutTabCrashed.js (content/aboutTabCrashed.js) content/browser/aboutTabCrashed.xhtml (content/aboutTabCrashed.xhtml) +#ifdef TOR_BROWSER_UPDATE + content/browser/abouttbupdate/aboutTBUpdate.xhtml (content/abouttbupdate/aboutTBUpdate.xhtml) + content/browser/abouttbupdate/aboutTBUpdate.js (content/abouttbupdate/aboutTBUpdate.js) + content/browser/abouttbupdate/aboutTBUpdate.css (content/abouttbupdate/aboutTBUpdate.css) + content/browser/abouttbupdate/aboutTBUpdateLogo.png (content/abouttbupdate/aboutTBUpdateLogo.png) +#endif * content/browser/browser.css (content/browser.css) * content/browser/browser.js (content/browser.js) * content/browser/browser.xul (content/browser.xul) * content/browser/browser-tabPreviews.xml (content/browser-tabPreviews.xml) * content/browser/chatWindow.xul (content/chatWindow.xul) - content/browser/content.js (content/content.js) +* content/browser/content.js (content/content.js) content/browser/defaultthemes/1.footer.jpg (content/defaultthemes/1.footer.jpg) content/browser/defaultthemes/1.header.jpg (content/defaultthemes/1.header.jpg) content/browser/defaultthemes/1.icon.jpg (content/defaultthemes/1.icon.jpg) diff --git a/browser/components/about/AboutRedirector.cpp b/browser/components/about/AboutRedirector.cpp index 4805c2c..a4f1c4a 100644 --- a/browser/components/about/AboutRedirector.cpp +++ b/browser/components/about/AboutRedirector.cpp @@ -123,6 +123,14 @@ static RedirEntry kRedirMap[] = { nsIAboutModule::URI_MUST_LOAD_IN_CHILD | nsIAboutModule::MAKE_UNLINKABLE | nsIAboutModule::HIDE_FROM_ABOUTABOUT }, +#ifdef TOR_BROWSER_UPDATE + { "tbupdate", "chrome://browser/content/abouttbupdate/aboutTBUpdate.xhtml", + nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | + nsIAboutModule::ALLOW_SCRIPT | + nsIAboutModule::MAKE_UNLINKABLE | + nsIAboutModule::HIDE_FROM_ABOUTABOUT + }, +#endif }; static const int kRedirTotal = ArrayLength(kRedirMap);
diff --git a/browser/components/build/nsModule.cpp b/browser/components/build/nsModule.cpp index 553dfcf..8761b7d 100644 --- a/browser/components/build/nsModule.cpp +++ b/browser/components/build/nsModule.cpp @@ -116,6 +116,9 @@ static const mozilla::Module::ContractIDEntry kBrowserContracts[] = { { NS_ABOUT_MODULE_CONTRACTID_PREFIX "looppanel", &kNS_BROWSER_ABOUT_REDIRECTOR_CID }, { NS_ABOUT_MODULE_CONTRACTID_PREFIX "loopconversation", &kNS_BROWSER_ABOUT_REDIRECTOR_CID }, { NS_ABOUT_MODULE_CONTRACTID_PREFIX "reader", &kNS_BROWSER_ABOUT_REDIRECTOR_CID }, +#ifdef TOR_BROWSER_UPDATE + { NS_ABOUT_MODULE_CONTRACTID_PREFIX "tbupdate", &kNS_BROWSER_ABOUT_REDIRECTOR_CID }, +#endif #if defined(XP_WIN) { NS_IEHISTORYENUMERATOR_CONTRACTID, &kNS_WINIEHISTORYENUMERATOR_CID }, #elif defined(XP_MACOSX) diff --git a/browser/components/nsBrowserContentHandler.js b/browser/components/nsBrowserContentHandler.js index a3465a0..9d7d110 100644 --- a/browser/components/nsBrowserContentHandler.js +++ b/browser/components/nsBrowserContentHandler.js @@ -629,6 +629,13 @@ nsBrowserContentHandler.prototype = { // into account because that requires waiting for the session file // to be read. If a crash occurs after updating, before restarting, // we may open the startPage in addition to restoring the session. + // + // Tor Browser: Instead of opening the post-update "override page" + // directly, an about:tbupdate page is opened that includes a link + // to the override page as well as text from the first part of the + // local ChangeLog.txt file. The override page URL comes from the + // openURL attribute within the updates.xml file or, if no showURL + // action is present, from the startup.homepage_override_url pref. var ss = Components.classes["@mozilla.org/browser/sessionstartup;1"] .getService(Components.interfaces.nsISessionStartup); willRestoreSession = ss.isAutomaticRestoreEnabled(); @@ -642,6 +649,11 @@ nsBrowserContentHandler.prototype = { overridePage = overridePage.replace("%OLD_TOR_BROWSER_VERSION%", old_tbversion); #endif + +#ifdef TOR_BROWSER_UPDATE + if (overridePage) + overridePage = "about:tbupdate?" + encodeURIComponent(overridePage); +#endif break; } } diff --git a/browser/locales/en-US/chrome/browser/aboutTBUpdate.dtd b/browser/locales/en-US/chrome/browser/aboutTBUpdate.dtd new file mode 100644 index 0000000..37567bd --- /dev/null +++ b/browser/locales/en-US/chrome/browser/aboutTBUpdate.dtd @@ -0,0 +1,6 @@ +<!ENTITY aboutTBUpdate.title "Tor Browser Update"> +<!ENTITY aboutTBUpdate.updated "Tor Browser has been updated."> +<!ENTITY aboutTBUpdate.linkPrefix "For the most up-to-date information about this release, "> +<!ENTITY aboutTBUpdate.linkLabel "visit our website"> +<!ENTITY aboutTBUpdate.linkSuffix "."> +<!ENTITY aboutTBUpdate.changeLogHeading "Changelog:"> diff --git a/browser/locales/jar.mn b/browser/locales/jar.mn index 03a8cdf..510ce40 100644 --- a/browser/locales/jar.mn +++ b/browser/locales/jar.mn @@ -24,6 +24,9 @@ locale/browser/syncCustomize.dtd (%chrome/browser/syncCustomize.dtd) locale/browser/aboutSyncTabs.dtd (%chrome/browser/aboutSyncTabs.dtd) #endif +#ifdef TOR_BROWSER_UPDATE + locale/browser/aboutTBUpdate.dtd (%chrome/browser/aboutTBUpdate.dtd) +#endif locale/browser/browser.dtd (%chrome/browser/browser.dtd) locale/browser/baseMenuOverlay.dtd (%chrome/browser/baseMenuOverlay.dtd) locale/browser/browser.properties (%chrome/browser/browser.properties)