From 17e22dafd86ecf1d37defec0a01f0312fb77933f Mon Sep 17 00:00:00 2001 From: Mike de Boer Date: Tue, 9 Apr 2013 16:48:30 -0700 Subject: [PATCH] Bug 819493: the Know Your Rights notification box has moved to be shown as default snippet on first startup. r=gavin --HG-- extra : rebase_source : f16a45e155e1a151c010ceaaab0d2878ea4a5da4 --- browser/base/content/abouthome/aboutHome.css | 13 +++- browser/base/content/abouthome/aboutHome.js | 14 +++- .../base/content/abouthome/aboutHome.xhtml | 1 + browser/base/content/browser.js | 8 ++ .../base/content/test/browser_aboutHome.js | 59 ++++++++++++-- browser/components/Makefile.in | 4 - browser/components/nsBrowserGlue.js | 77 ------------------- .../en-US/chrome/browser/aboutHome.dtd | 2 + browser/modules/AboutHomeUtils.jsm | 42 +++++++++- browser/modules/Makefile.in | 6 +- .../chrome/global/aboutRights.properties | 7 -- toolkit/locales/jar.mn | 1 - 12 files changed, 133 insertions(+), 101 deletions(-) delete mode 100644 toolkit/locales/en-US/chrome/global/aboutRights.properties diff --git a/browser/base/content/abouthome/aboutHome.css b/browser/base/content/abouthome/aboutHome.css index fd5bf348d294..46902acee74c 100644 --- a/browser/base/content/abouthome/aboutHome.css +++ b/browser/base/content/abouthome/aboutHome.css @@ -140,7 +140,8 @@ a { } #defaultSnippet1, -#defaultSnippet2 { +#defaultSnippet2, +#rightsSnippet { display: block; min-height: 38px; background: 30px center no-repeat; @@ -148,8 +149,13 @@ a { -moz-padding-start: 79px; } +#rightsSnippet[hidden] { + display: none; +} + #defaultSnippet1:-moz-dir(rtl), -#defaultSnippet2:-moz-dir(rtl) { +#defaultSnippet2:-moz-dir(rtl), +#rightsSnippet:-moz-dir(rtl) { background-position: right 30px center; } @@ -351,7 +357,8 @@ body[narrow] #restorePreviousSession::before { */ @media not all and (max-resolution: 1dppx) { #defaultSnippet1, - #defaultSnippet2 { + #defaultSnippet2, + #rightsSnippet { background-size: 40px; } diff --git a/browser/base/content/abouthome/aboutHome.js b/browser/base/content/abouthome/aboutHome.js index 6d3a3dd2b3c0..603b8c2b2ffe 100644 --- a/browser/base/content/abouthome/aboutHome.js +++ b/browser/base/content/abouthome/aboutHome.js @@ -340,6 +340,19 @@ function loadSnippets() let _snippetsShown = false; function showSnippets() { + let snippetsElt = document.getElementById("snippets"); + + // Show about:rights notification, if needed. + let showRights = document.documentElement.getAttribute("showKnowYourRights"); + if (showRights) { + let rightsElt = document.getElementById("rightsSnippet"); + let anchor = rightsElt.getElementsByTagName("a")[0]; + anchor.href = "about:rights"; + snippetsElt.appendChild(rightsElt); + rightsElt.removeAttribute("hidden"); + return; + } + if (!gSnippetsMap) throw new Error("Snippets map has not properly been initialized"); if (_snippetsShown) { @@ -350,7 +363,6 @@ function showSnippets() } _snippetsShown = true; - let snippetsElt = document.getElementById("snippets"); let snippets = gSnippetsMap.get("snippets"); // If there are remotely fetched snippets, try to to show them. if (snippets) { diff --git a/browser/base/content/abouthome/aboutHome.xhtml b/browser/base/content/abouthome/aboutHome.xhtml index 3a2d6546657a..a10627e22e43 100644 --- a/browser/base/content/abouthome/aboutHome.xhtml +++ b/browser/base/content/abouthome/aboutHome.xhtml @@ -49,6 +49,7 @@ &abouthome.defaultSnippet1.v1; &abouthome.defaultSnippet2.v1; +
diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 481d77a7ae75..be1abad75379 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2276,7 +2276,15 @@ function BrowserOnAboutPageLoad(doc) { // Inject search engine and snippets URL. let docElt = doc.documentElement; + // set the following attributes BEFORE searchEngineURL, which triggers to + // show the snippets when it's set. docElt.setAttribute("snippetsURL", AboutHomeUtils.snippetsURL); + if (AboutHomeUtils.showKnowYourRights) { + docElt.setAttribute("showKnowYourRights", "true"); + // Set pref to indicate we've shown the notification. + let currentVersion = Services.prefs.getIntPref("browser.rights.version"); + Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true); + } docElt.setAttribute("snippetsVersion", AboutHomeUtils.snippetsVersion); docElt.setAttribute("searchEngineName", AboutHomeUtils.defaultSearchEngine.name); diff --git a/browser/base/content/test/browser_aboutHome.js b/browser/base/content/test/browser_aboutHome.js index 1020c1e8a5aa..ec73a6d0d1f2 100644 --- a/browser/base/content/test/browser_aboutHome.js +++ b/browser/base/content/test/browser_aboutHome.js @@ -9,14 +9,14 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task", XPCOMUtils.defineLazyModuleGetter(this, "AboutHomeUtils", "resource:///modules/AboutHomeUtils.jsm"); +let gRightsVersion = Services.prefs.getIntPref("browser.rights.version"); + registerCleanupFunction(function() { // Ensure we don't pollute prefs for next tests. - try { - Services.prefs.clearUserPref("network.cookies.cookieBehavior"); - } catch (ex) {} - try { - Services.prefs.clearUserPref("network.cookie.lifetimePolicy"); - } catch (ex) {} + Services.prefs.clearUserPref("network.cookies.cookieBehavior"); + Services.prefs.clearUserPref("network.cookie.lifetimePolicy"); + Services.prefs.clearUserPref("browser.rights.override"); + Services.prefs.clearUserPref("browser.rights." + gRightsVersion + ".shown"); }); let gTests = [ @@ -200,6 +200,50 @@ let gTests = [ } }, +{ + desc: "Check if the 'Know Your Rights default snippet is shown when 'browser.rights.override' pref is set", + beforeRun: function () + { + Services.prefs.setBoolPref("browser.rights.override", false); + }, + setup: function () { }, + run: function (aSnippetsMap) + { + let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; + let showRights = AboutHomeUtils.showKnowYourRights; + + ok(showRights, "AboutHomeUtils.showKnowYourRights should be TRUE"); + + let snippetsElt = doc.getElementById("snippets"); + ok(snippetsElt, "Found snippets element"); + is(snippetsElt.getElementsByTagName("a")[0].href, "about:rights", "Snippet link is present."); + + Services.prefs.clearUserPref("browser.rights.override"); + } +}, + +{ + desc: "Check if the 'Know Your Rights default snippet is NOT shown when 'browser.rights.override' pref is NOT set", + beforeRun: function () + { + Services.prefs.setBoolPref("browser.rights.override", true); + }, + setup: function () { }, + run: function (aSnippetsMap) + { + let doc = gBrowser.selectedTab.linkedBrowser.contentDocument; + let rightsData = AboutHomeUtils.knowYourRightsData; + + ok(!rightsData, "AboutHomeUtils.knowYourRightsData should be FALSE"); + + let snippetsElt = doc.getElementById("snippets"); + ok(snippetsElt, "Found snippets element"); + ok(snippetsElt.getElementsByTagName("a")[0].href != "about:rights", "Snippet link should not point to about:rights."); + + Services.prefs.clearUserPref("browser.rights.override"); + } +} + ]; function test() @@ -210,6 +254,9 @@ function test() for (let test of gTests) { info(test.desc); + if (test.beforeRun) + yield test.beforeRun(); + let tab = yield promiseNewTabLoadEvent("about:home", "DOMContentLoaded"); // Must wait for both the snippets map and the browser attributes, since diff --git a/browser/components/Makefile.in b/browser/components/Makefile.in index a779dc37a580..b68c86993671 100644 --- a/browser/components/Makefile.in +++ b/browser/components/Makefile.in @@ -20,8 +20,4 @@ EXTRA_PP_COMPONENTS = \ EXTRA_JS_MODULES = distribution.js -ifdef MOZILLA_OFFICIAL -DEFINES += -DOFFICIAL_BUILD=1 -endif - include $(topsrcdir)/config/rules.mk diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 07bb928f91f7..6da3f75f853b 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -528,11 +528,6 @@ BrowserGlue.prototype = { // All initial windows have opened. _onWindowsRestored: function BG__onWindowsRestored() { - // Show about:rights notification, if needed. - if (this._shouldShowRights()) { - this._showRightsNotification(); - } - // Show update notification, if needed. if (Services.prefs.prefHasUserValue("app.update.postupdate")) this._showUpdateNotification(); @@ -761,78 +756,6 @@ BrowserGlue.prototype = { } }, - /* - * _shouldShowRights - Determines if the user should be shown the - * about:rights notification. The notification should *not* be shown if - * we've already shown the current version, or if the override pref says to - * never show it. The notification *should* be shown if it's never been seen - * before, if a newer version is available, or if the override pref says to - * always show it. - */ - _shouldShowRights: function BG__shouldShowRights() { - // Look for an unconditional override pref. If set, do what it says. - // (true --> never show, false --> always show) - try { - return !Services.prefs.getBoolPref("browser.rights.override"); - } catch (e) { } - // Ditto, for the legacy EULA pref. - try { - return !Services.prefs.getBoolPref("browser.EULA.override"); - } catch (e) { } - -#ifndef OFFICIAL_BUILD - // Non-official builds shouldn't shouldn't show the notification. - return false; -#endif - - // Look to see if the user has seen the current version or not. - var currentVersion = Services.prefs.getIntPref("browser.rights.version"); - try { - return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown"); - } catch (e) { } - - // Legacy: If the user accepted a EULA, we won't annoy them with the - // equivalent about:rights page until the version changes. - try { - return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted"); - } catch (e) { } - - // We haven't shown the notification before, so do so now. - return true; - }, - - _showRightsNotification: function BG__showRightsNotification() { - // Stick the notification onto the selected tab of the active browser window. - var win = this.getMostRecentBrowserWindow(); - var notifyBox = win.gBrowser.getNotificationBox(); - - var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties"); - var rightsBundle = Services.strings.createBundle("chrome://global/locale/aboutRights.properties"); - - var buttonLabel = rightsBundle.GetStringFromName("buttonLabel"); - var buttonAccessKey = rightsBundle.GetStringFromName("buttonAccessKey"); - var productName = brandBundle.GetStringFromName("brandFullName"); - var notifyRightsText = rightsBundle.formatStringFromName("notifyRightsText", [productName], 1); - - var buttons = [ - { - label: buttonLabel, - accessKey: buttonAccessKey, - popup: null, - callback: function(aNotificationBar, aButton) { - win.openUILinkIn("about:rights", "tab"); - } - } - ]; - - // Set pref to indicate we've shown the notification. - var currentVersion = Services.prefs.getIntPref("browser.rights.version"); - Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true); - - var notification = notifyBox.appendNotification(notifyRightsText, "about-rights", null, notifyBox.PRIORITY_INFO_LOW, buttons); - notification.persistence = -1; // Until user closes it - }, - _showUpdateNotification: function BG__showUpdateNotification() { Services.prefs.clearUserPref("app.update.postupdate"); diff --git a/browser/locales/en-US/chrome/browser/aboutHome.dtd b/browser/locales/en-US/chrome/browser/aboutHome.dtd index 693021cf0af8..e84341f54008 100644 --- a/browser/locales/en-US/chrome/browser/aboutHome.dtd +++ b/browser/locales/en-US/chrome/browser/aboutHome.dtd @@ -21,6 +21,8 @@ text in will be linked to the featured add-ons on addons.mozilla.org --> Choose from thousands of add-ons."> + +Know your rights…"> diff --git a/browser/modules/AboutHomeUtils.jsm b/browser/modules/AboutHomeUtils.jsm index 43b793e70345..341ee39c367c 100644 --- a/browser/modules/AboutHomeUtils.jsm +++ b/browser/modules/AboutHomeUtils.jsm @@ -16,7 +16,47 @@ const SNIPPETS_URL_PREF = "browser.aboutHomeSnippets.updateUrl"; const STARTPAGE_VERSION = 4; this.AboutHomeUtils = { - get snippetsVersion() STARTPAGE_VERSION + get snippetsVersion() STARTPAGE_VERSION, + + /* + * showKnowYourRights - Determines if the user should be shown the + * about:rights notification. The notification should *not* be shown if + * we've already shown the current version, or if the override pref says to + * never show it. The notification *should* be shown if it's never been seen + * before, if a newer version is available, or if the override pref says to + * always show it. + */ + get showKnowYourRights() { + // Look for an unconditional override pref. If set, do what it says. + // (true --> never show, false --> always show) + try { + return !Services.prefs.getBoolPref("browser.rights.override"); + } catch (e) { } + // Ditto, for the legacy EULA pref. + try { + return !Services.prefs.getBoolPref("browser.EULA.override"); + } catch (e) { } + +#ifndef MOZILLA_OFFICIAL + // Non-official builds shouldn't show the notification. + return false; +#endif + + // Look to see if the user has seen the current version or not. + var currentVersion = Services.prefs.getIntPref("browser.rights.version"); + try { + return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown"); + } catch (e) { } + + // Legacy: If the user accepted a EULA, we won't annoy them with the + // equivalent about:rights page until the version changes. + try { + return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted"); + } catch (e) { } + + // We haven't shown the notification before, so do so now. + return true; + } }; /** diff --git a/browser/modules/Makefile.in b/browser/modules/Makefile.in index 6c1c1a554014..6ab3ad1806c1 100644 --- a/browser/modules/Makefile.in +++ b/browser/modules/Makefile.in @@ -12,7 +12,6 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/config.mk EXTRA_JS_MODULES = \ - AboutHomeUtils.jsm \ BrowserNewTabPreloader.jsm \ openLocationLastURL.jsm \ NetworkPrioritizer.jsm \ @@ -26,6 +25,7 @@ EXTRA_JS_MODULES = \ $(NULL) EXTRA_PP_JS_MODULES = \ + AboutHomeUtils.jsm \ RecentWindow.jsm \ $(NULL) @@ -37,4 +37,8 @@ EXTRA_JS_MODULES += \ $(NULL) endif +ifdef MOZILLA_OFFICIAL +DEFINES += -DMOZILLA_OFFICIAL=1 +endif + include $(topsrcdir)/config/rules.mk diff --git a/toolkit/locales/en-US/chrome/global/aboutRights.properties b/toolkit/locales/en-US/chrome/global/aboutRights.properties deleted file mode 100644 index 377bf7a8ffbe..000000000000 --- a/toolkit/locales/en-US/chrome/global/aboutRights.properties +++ /dev/null @@ -1,7 +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/. - -buttonLabel = Know your rights… -buttonAccessKey = K -notifyRightsText = %S is free and open source software from the non-profit Mozilla Foundation. diff --git a/toolkit/locales/jar.mn b/toolkit/locales/jar.mn index f87978da3a4e..86dd35f4fb35 100644 --- a/toolkit/locales/jar.mn +++ b/toolkit/locales/jar.mn @@ -9,7 +9,6 @@ locale/@AB_CD@/global/about.dtd (%chrome/global/about.dtd) locale/@AB_CD@/global/aboutAbout.dtd (%chrome/global/aboutAbout.dtd) locale/@AB_CD@/global/aboutRights.dtd (%chrome/global/aboutRights.dtd) - locale/@AB_CD@/global/aboutRights.properties (%chrome/global/aboutRights.properties) locale/@AB_CD@/global/aboutSupport.dtd (%chrome/global/aboutSupport.dtd) locale/@AB_CD@/global/aboutSupport.properties (%chrome/global/aboutSupport.properties) locale/@AB_CD@/global/aboutTelemetry.dtd (%chrome/global/aboutTelemetry.dtd)