From a160cc3e5841560214340a6aec0cb090a1232d98 Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Thu, 23 Jul 2015 20:37:17 -0700 Subject: [PATCH] Bug 1187022 - Add hover tooltip for tracking protection shield icon;r=MattN --HG-- extra : commitid : KxZ3gqOI83Z --- .../content/browser-trackingprotection.js | 37 ++++++++++++------- .../test/general/browser_trackingUI_1.js | 5 +++ .../en-US/chrome/browser/browser.properties | 3 ++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/browser/base/content/browser-trackingprotection.js b/browser/base/content/browser-trackingprotection.js index 933c60dd73c0..2d97dc858869 100644 --- a/browser/base/content/browser-trackingprotection.js +++ b/browser/base/content/browser-trackingprotection.js @@ -8,6 +8,11 @@ let TrackingProtection = { PREF_ENABLED_IN_PRIVATE_WINDOWS: "privacy.trackingprotection.pbmode.enabled", enabledGlobally: false, enabledInPrivateWindows: false, + container: null, + content: null, + icon: null, + activeTooltipText: null, + disabledTooltipText: null, init() { let $ = selector => document.querySelector(selector); @@ -19,6 +24,11 @@ let TrackingProtection = { Services.prefs.addObserver(this.PREF_ENABLED_GLOBALLY, this, false); Services.prefs.addObserver(this.PREF_ENABLED_IN_PRIVATE_WINDOWS, this, false); + this.activeTooltipText = + gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"); + this.disabledTooltipText = + gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"); + this.enabledHistogram.add(this.enabledGlobally); }, @@ -66,21 +76,14 @@ let TrackingProtection = { this.icon.setAttribute("animate", "true"); } - let { - STATE_BLOCKED_TRACKING_CONTENT, STATE_LOADED_TRACKING_CONTENT - } = Ci.nsIWebProgressListener; + let isBlocking = state & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT; + let isAllowing = state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT; - for (let element of [this.icon, this.content]) { - if (state & STATE_BLOCKED_TRACKING_CONTENT) { - element.setAttribute("state", "blocked-tracking-content"); - } else if (state & STATE_LOADED_TRACKING_CONTENT) { - element.setAttribute("state", "loaded-tracking-content"); - } else { - element.removeAttribute("state"); - } - } + if (isBlocking) { + this.icon.setAttribute("tooltiptext", this.activeTooltipText); + this.icon.setAttribute("state", "blocked-tracking-content"); + this.content.setAttribute("state", "blocked-tracking-content"); - if (state & STATE_BLOCKED_TRACKING_CONTENT) { // Open the tracking protection introduction panel, if applicable. let introCount = gPrefService.getIntPref("privacy.trackingprotection.introCount"); if (introCount < TrackingProtection.MAX_INTROS) { @@ -88,6 +91,14 @@ let TrackingProtection = { gPrefService.savePrefFile(null); this.showIntroPanel(); } + } else if (isAllowing) { + this.icon.setAttribute("tooltiptext", this.disabledTooltipText); + this.icon.setAttribute("state", "loaded-tracking-content"); + this.content.setAttribute("state", "loaded-tracking-content"); + } else { + this.icon.removeAttribute("tooltiptext"); + this.icon.removeAttribute("state"); + this.content.removeAttribute("state"); } // Telemetry for state change. diff --git a/browser/base/content/test/general/browser_trackingUI_1.js b/browser/base/content/test/general/browser_trackingUI_1.js index 370ac1e51591..d17f2733e785 100644 --- a/browser/base/content/test/general/browser_trackingUI_1.js +++ b/browser/base/content/test/general/browser_trackingUI_1.js @@ -46,6 +46,7 @@ function testBenignPage() { ok(!TrackingProtection.container.hidden, "The container is visible"); ok(!TrackingProtection.content.hasAttribute("state"), "content: no state"); ok(!TrackingProtection.icon.hasAttribute("state"), "icon: no state"); + ok(!TrackingProtection.icon.hasAttribute("tooltiptext"), "icon: no tooltip"); ok(hidden("#tracking-protection-icon"), "icon is hidden"); ok(hidden("#tracking-action-block"), "blockButton is hidden"); @@ -64,6 +65,8 @@ function testTrackingPage(window) { 'content: state="blocked-tracking-content"'); is(TrackingProtection.icon.getAttribute("state"), "blocked-tracking-content", 'icon: state="blocked-tracking-content"'); + is(TrackingProtection.icon.getAttribute("tooltiptext"), + gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), "correct tooltip"); ok(!hidden("#tracking-protection-icon"), "icon is visible"); ok(hidden("#tracking-action-block"), "blockButton is hidden"); @@ -90,6 +93,8 @@ function testTrackingPageUnblocked() { 'content: state="loaded-tracking-content"'); is(TrackingProtection.icon.getAttribute("state"), "loaded-tracking-content", 'icon: state="loaded-tracking-content"'); + is(TrackingProtection.icon.getAttribute("tooltiptext"), + gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), "correct tooltip"); ok(!hidden("#tracking-protection-icon"), "icon is visible"); ok(!hidden("#tracking-action-block"), "blockButton is visible"); diff --git a/browser/locales/en-US/chrome/browser/browser.properties b/browser/locales/en-US/chrome/browser/browser.properties index 766446fac755..1c27c2f8e6c3 100644 --- a/browser/locales/en-US/chrome/browser/browser.properties +++ b/browser/locales/en-US/chrome/browser/browser.properties @@ -343,6 +343,9 @@ trackingProtection.intro.description=When the shield is visible, that means Fire trackingProtection.intro.step1of3=1 of 3 trackingProtection.intro.nextButton.label=Next +trackingProtection.icon.activeTooltip=Tracking attempts blocked +trackingProtection.icon.disabledTooltip=Tracking content detected + # Edit Bookmark UI editBookmarkPanel.pageBookmarkedTitle=Page Bookmarked editBookmarkPanel.pageBookmarkedDescription=%S will always remember this page for you.