Bug 1527151 - Reset securityUI.contentBlockingEvent on top level location changes. r=Ehsan a=lizzard
authorJohann Hofmann <jhofmann@mozilla.com>
Fri, 22 Feb 2019 19:44:03 +0000
changeset 516226 bdc420ea17d6f2688cc1de7f433b5b2330b11983
parent 516225 f50d84563bc574211361fca6fe90e67b0cdb8f14
child 516227 d53e3a3bef07479fff7243d33d13f6ac38554ebb
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan, lizzard
bugs1527151
milestone66.0
Bug 1527151 - Reset securityUI.contentBlockingEvent on top level location changes. r=Ehsan a=lizzard We had previously missed to call browser.updateSecurityUIForContentBlockingEvent on onLocationChange updates, to reset the contentBlockingEvent state. This would mean that on tab switch the contentBlockingEvent state for benign pages would still be what it was set to on the last tracker page. Differential Revision: https://phabricator.services.mozilla.com/D20328
browser/base/content/browser.js
browser/base/content/test/trackingUI/browser.ini
browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js
dom/interfaces/base/nsIBrowser.idl
dom/ipc/TabParent.cpp
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4918,16 +4918,17 @@ var XULBrowserWindow = {
     this._event = aEvent;
     this._lastLocationForEvent = spec;
 
     if (typeof(aIsSimulated) != "boolean" && typeof(aIsSimulated) != "undefined") {
       throw "onContentBlockingEvent: aIsSimulated receieved an unexpected type";
     }
 
     ContentBlocking.onContentBlockingEvent(this._event, aWebProgress, aIsSimulated);
+    gBrowser.selectedBrowser.updateSecurityUIForContentBlockingEvent(aEvent);
   },
 
   // This is called in multiple ways:
   //  1. Due to the nsIWebProgressListener.onSecurityChange notification.
   //  2. Called by tabbrowser.xml when updating the current browser.
   //  3. Called directly during this object's initializations.
   // aRequest will be null always in case 2 and 3, and sometimes in case 1.
   onSecurityChange(aWebProgress, aRequest, aState, aIsSimulated) {
--- a/browser/base/content/test/trackingUI/browser.ini
+++ b/browser/base/content/test/trackingUI/browser.ini
@@ -23,10 +23,11 @@ support-files =
   file_trackingUI_fetch.js
   file_trackingUI_fetch.js^headers^
 [browser_trackingUI_open_preferences.js]
 [browser_trackingUI_pbmode_exceptions.js]
 [browser_trackingUI_report_breakage.js]
 [browser_trackingUI_state.js]
 skip-if = serviceworker_e10s # see https://bugzilla.mozilla.org/show_bug.cgi?id=1511303#c1
 [browser_trackingUI_state_all_disabled.js]
+[browser_trackingUI_state_reset.js]
 [browser_trackingUI_telemetry.js]
 [browser_trackingUI_trackers_subview.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js
@@ -0,0 +1,47 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const TP_PREF = "privacy.trackingprotection.enabled";
+const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
+const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
+
+/* This asserts that the content blocking event state is correctly reset
+ * when navigating to a new location, and that the user is correctly
+ * reset when switching between tabs. */
+
+add_task(async function testResetOnLocationChange() {
+  Services.prefs.setBoolPref(TP_PREF, true);
+
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BENIGN_PAGE);
+  let browser = tab.linkedBrowser;
+
+  is(browser.securityUI.contentBlockingEvent, 0, "Benign page has no content blocking event");
+  ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
+
+  await Promise.all([promiseTabLoadEvent(tab, TRACKING_PAGE),
+                     waitForContentBlockingEvent(2)]);
+
+  is(browser.securityUI.contentBlockingEvent, Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, "Tracking page has a content blocking event");
+  ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
+
+  await promiseTabLoadEvent(tab, BENIGN_PAGE);
+
+  is(browser.securityUI.contentBlockingEvent, 0, "Benign page has no content blocking event");
+  ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
+
+  let contentBlockingEvent = waitForContentBlockingEvent(3);
+  let trackingTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TRACKING_PAGE);
+  await contentBlockingEvent;
+
+  is(trackingTab.linkedBrowser.securityUI.contentBlockingEvent, Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, "Tracking page has a content blocking event");
+  ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active");
+
+  gBrowser.selectedTab = tab;
+  is(browser.securityUI.contentBlockingEvent, 0, "Benign page has no content blocking event");
+  ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active");
+
+  gBrowser.removeTab(trackingTab);
+  gBrowser.removeTab(tab);
+
+  Services.prefs.clearUserPref(TP_PREF);
+});
--- a/dom/interfaces/base/nsIBrowser.idl
+++ b/dom/interfaces/base/nsIBrowser.idl
@@ -89,24 +89,16 @@ interface nsIBrowser : nsISupports
                                        in unsigned long enabledLength,
                                        [array, size_is(enabledLength)] in string enabledCommands,
                                        in unsigned long disabledLength,
                                        [array, size_is(disabledLength)] in string disabledCommands);
 
   readonly attribute nsIPrincipal contentPrincipal;
 
   /**
-   * Called by Gecko when a content blocking event needs to update the event
-   * state stored in the security UI object stored in the parent process.
-   * @param aEvent one of the content blocking event codes defined in
-   *               nsIWebProgressListener.idl.
-   */
-  void updateSecurityUIForContentBlockingEvent(in unsigned long aEvent);
-
-  /**
    * Called by Gecko when we need to call the web progress listeners on our
    * browser element in order to notify them about a content blocking event
    * which happened in the content process.
    * @param isWebProgressPassed whether we're passed a webProgress argument
    * @param isTopLevel whether we're in the top-level document
    * @param isLoadingDocument whether we're in the process of loading a document
    * @param loadType the type of load in progress
    * @param DOMWindowID the ID of the window receiving the notification
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -2119,19 +2119,16 @@ mozilla::ipc::IPCResult TabParent::RecvO
     MOZ_ASSERT(aWebProgressData.type() != OptionalWebProgressData::T__None);
 
     if (aWebProgressData.type() == OptionalWebProgressData::Tvoid_t) {
       Unused << browser->CallWebProgressContentBlockingEventListeners(
           false, false, false, 0, 0, aRequestData.requestURI(),
           aRequestData.originalRequestURI(), aRequestData.matchedList(),
           aEvent);
     } else {
-      if (aWebProgressData.get_WebProgressData().isTopLevel()) {
-        Unused << browser->UpdateSecurityUIForContentBlockingEvent(aEvent);
-      }
       Unused << browser->CallWebProgressContentBlockingEventListeners(
           true, aWebProgressData.get_WebProgressData().isTopLevel(),
           aWebProgressData.get_WebProgressData().isLoadingDocument(),
           aWebProgressData.get_WebProgressData().loadType(),
           aWebProgressData.get_WebProgressData().DOMWindowID(),
           aRequestData.requestURI(), aRequestData.originalRequestURI(),
           aRequestData.matchedList(), aEvent);
     }