Bug 1600878 - P2. Use contentBlockingEvents in WindowGlobalParent instead of contentBlockingEvent in RemoteSecurityUI r=timhuang,Ehsan
authorDimi Lee <dlee@mozilla.com>
Tue, 17 Dec 2019 11:25:23 +0000
changeset 510090 bd432376ef0d60c6f77a251ce6ed56285f5464a6
parent 510089 7535e00d33e9c5201a27720ae735830dbdc146fb
child 510091 89dcc457c42f9f3a78cb5bf9ecbc18835ff7192a
push id37014
push usercbrindusan@mozilla.com
push dateTue, 14 Jan 2020 21:43:07 +0000
treeherdermozilla-central@12d8255184b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstimhuang, Ehsan
bugs1600878
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1600878 - P2. Use contentBlockingEvents in WindowGlobalParent instead of contentBlockingEvent in RemoteSecurityUI r=timhuang,Ehsan ContentBlockingEvent in RemoteSecurityUI is updated after receiving a notification from a child process. Since contentBlockingEvent will be removed from the child, this patch removes the use of contentBlockingEvent in RemoteSecurityUI and uses the API defined in WindowGlobalActor. Depends on D55621 Differential Revision: https://phabricator.services.mozilla.com/D55622
browser/base/content/browser-siteProtections.js
browser/base/content/browser.js
browser/base/content/tabbrowser.js
browser/base/content/test/trackingUI/browser_trackingUI_background_tabs.js
browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js
toolkit/content/widgets/browser-custom-element.js
--- a/browser/base/content/browser-siteProtections.js
+++ b/browser/base/content/browser-siteProtections.js
@@ -1667,23 +1667,22 @@ var gProtectionsHandler = {
   onStateChange(aWebProgress, stateFlags) {
     if (!aWebProgress.isTopLevel) {
       return;
     }
 
     this._isStoppedState = !!(
       stateFlags & Ci.nsIWebProgressListener.STATE_STOP
     );
-
-    this.notifyContentBlockingEvent(gBrowser.securityUI.contentBlockingEvent);
+    this.notifyContentBlockingEvent(
+      gBrowser.selectedBrowser.getContentBlockingEvents()
+    );
   },
 
-  onContentBlockingEvent(event, webProgress, isSimulated) {
-    let previousState = gBrowser.securityUI.contentBlockingEvent;
-
+  onContentBlockingEvent(event, webProgress, isSimulated, previousState) {
     // Don't deal with about:, file: etc.
     if (!ContentBlockingAllowList.canHandle(gBrowser.selectedBrowser)) {
       this.iconBox.removeAttribute("animate");
       this.iconBox.removeAttribute("active");
       this.iconBox.removeAttribute("hasException");
       return;
     }
 
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -5571,33 +5571,38 @@ var XULBrowserWindow = {
   onContentBlockingEvent(aWebProgress, aRequest, aEvent, aIsSimulated) {
     // Don't need to do anything if the data we use to update the UI hasn't
     // changed
     let uri = gBrowser.currentURI;
     let spec = uri.spec;
     if (this._event == aEvent && this._lastLocationForEvent == spec) {
       return;
     }
-    this._event = aEvent;
     this._lastLocationForEvent = spec;
 
     if (
       typeof aIsSimulated != "boolean" &&
       typeof aIsSimulated != "undefined"
     ) {
       throw new Error(
         "onContentBlockingEvent: aIsSimulated receieved an unexpected type"
       );
     }
 
     gProtectionsHandler.onContentBlockingEvent(
-      this._event,
+      aEvent,
       aWebProgress,
-      aIsSimulated
+      aIsSimulated,
+      this._event // previous content blocking event
     );
+
+    // We need the state of the previous content blocking event, so update
+    // event after onContentBlockingEvent is called.
+    this._event = aEvent;
+
     // Because this function will only receive content blocking event updates
     // for the currently selected tab, we handle updates to background tabs in
     // TabsProgressListener.onContentBlockingEvent.
     gBrowser.selectedBrowser.updateSecurityUIForContentBlockingEvent(aEvent);
   },
 
   // This is called in multiple ways:
   //  1. Due to the nsIWebProgressListener.onSecurityChange notification.
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -1083,17 +1083,17 @@
           true,
           false
         );
         // Include the true final argument to indicate that this event is
         // simulated (instead of being observed by the webProgressListener).
         this._callProgressListeners(
           null,
           "onContentBlockingEvent",
-          [webProgress, null, securityUI.contentBlockingEvent, true],
+          [webProgress, null, newBrowser.getContentBlockingEvents(), true],
           true,
           false
         );
       }
 
       let listener = this._tabListeners.get(newTab);
       if (listener && listener.mStateFlags) {
         this._callProgressListeners(
@@ -1990,17 +1990,17 @@
         : Ci.nsIWebProgressListener.STATE_IS_INSECURE;
       this._callProgressListeners(
         aBrowser,
         "onSecurityChange",
         [aBrowser.webProgress, null, state],
         true,
         false
       );
-      let event = securityUI ? securityUI.contentBlockingEvent : 0;
+      let event = aBrowser.getContentBlockingEvents();
       // Include the true final argument to indicate that this event is
       // simulated (instead of being observed by the webProgressListener).
       this._callProgressListeners(
         aBrowser,
         "onContentBlockingEvent",
         [aBrowser.webProgress, null, event, true],
         true,
         false
--- a/browser/base/content/test/trackingUI/browser_trackingUI_background_tabs.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_background_tabs.js
@@ -24,48 +24,48 @@ add_task(async function testBackgroundTa
     UrlClassifierTestUtils.cleanupTestTrackers();
   });
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BENIGN_PAGE);
 
   let backgroundTab = BrowserTestUtils.addTab(gBrowser);
   let browser = backgroundTab.linkedBrowser;
   let hasContentBlockingEvent = TestUtils.waitForCondition(
-    () => browser.securityUI.contentBlockingEvent != 0
+    () => browser.getContentBlockingEvents() != 0
   );
   await promiseTabLoadEvent(backgroundTab, TRACKING_PAGE);
   await hasContentBlockingEvent;
 
   is(
-    browser.securityUI.contentBlockingEvent,
+    browser.getContentBlockingEvents(),
     Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
     "Background tab has the correct content blocking event."
   );
 
   is(
-    tab.linkedBrowser.securityUI.contentBlockingEvent,
+    tab.linkedBrowser.getContentBlockingEvents(),
     0,
     "Foreground tab has the correct content blocking event."
   );
 
   ok(
     !gProtectionsHandler.iconBox.hasAttribute("active"),
     "shield is not active"
   );
 
   await BrowserTestUtils.switchTab(gBrowser, backgroundTab);
 
   is(
-    browser.securityUI.contentBlockingEvent,
+    browser.getContentBlockingEvents(),
     Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
     "Background tab still has the correct content blocking event."
   );
 
   is(
-    tab.linkedBrowser.securityUI.contentBlockingEvent,
+    tab.linkedBrowser.getContentBlockingEvents(),
     0,
     "Foreground tab still has the correct content blocking event."
   );
 
   ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
 
   gBrowser.removeTab(backgroundTab);
   gBrowser.removeTab(tab);
--- a/browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js
@@ -14,66 +14,66 @@ const ABOUT_PAGE = "about:preferences";
 
 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,
+    browser.getContentBlockingEvents(),
     0,
     "Benign page has no content blocking event"
   );
   ok(
     !gProtectionsHandler.iconBox.hasAttribute("active"),
     "shield is not active"
   );
 
   await Promise.all([
     promiseTabLoadEvent(tab, TRACKING_PAGE),
     waitForContentBlockingEvent(2),
   ]);
 
   is(
-    browser.securityUI.contentBlockingEvent,
+    browser.getContentBlockingEvents(),
     Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
     "Tracking page has a content blocking event"
   );
   ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
 
   await promiseTabLoadEvent(tab, BENIGN_PAGE);
 
   is(
-    browser.securityUI.contentBlockingEvent,
+    browser.getContentBlockingEvents(),
     0,
     "Benign page has no content blocking event"
   );
   ok(
     !gProtectionsHandler.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,
+    trackingTab.linkedBrowser.getContentBlockingEvents(),
     Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
     "Tracking page has a content blocking event"
   );
   ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
 
   gBrowser.selectedTab = tab;
   is(
-    browser.securityUI.contentBlockingEvent,
+    browser.getContentBlockingEvents(),
     0,
     "Benign page has no content blocking event"
   );
   ok(
     !gProtectionsHandler.iconBox.hasAttribute("active"),
     "shield is not active"
   );
 
--- a/toolkit/content/widgets/browser-custom-element.js
+++ b/toolkit/content/widgets/browser-custom-element.js
@@ -2084,16 +2084,24 @@
       if (this.isRemoteBrowser) {
         return this.frameLoader.remoteTab.getContentBlockingLog();
       }
       return this.docShell
         ? this.docShell.getContentBlockingLog()
         : Promise.reject("docshell isn't available");
     }
 
+    getContentBlockingEvents() {
+      let windowGlobal = this.browsingContext.currentWindowGlobal;
+      if (!windowGlobal) {
+        return 0;
+      }
+      return windowGlobal.contentBlockingEvents;
+    }
+
     // Send an asynchronous message to the remote child via an actor.
     // Note: use this only for messages through an actor. For old-style
     // messages, use the message manager. If 'all' is true, then send
     // a message to all descendant processes.
     sendMessageToActor(messageName, args, actorName, all) {
       if (!this.frameLoader) {
         return;
       }