Bug 1472491: Part 5j - Add BlockedSiteChild actor. r=johannh f=felipe
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 20:53:09 -0700
changeset 431464 17440776f078aa0219f72e97ce88f0b7a1217b30
parent 431463 0fbc93e84af5cfc0ce57f3c0bf3189bfcf20af74
child 431465 0196bac4114b13c869f57cad22d922920a5b8180
push id34443
push usercsabou@mozilla.com
push dateWed, 15 Aug 2018 00:53:32 +0000
treeherdermozilla-central@b80906e2fbc9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1472491
milestone63.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 1472491: Part 5j - Add BlockedSiteChild actor. r=johannh f=felipe MozReview-Commit-ID: JnEBCvtQu7E
browser/actors/BlockedSiteChild.jsm
browser/actors/ClickHandlerChild.jsm
browser/actors/moz.build
browser/base/content/content.js
browser/components/nsBrowserGlue.js
browser/modules/BlockedSiteContent.jsm
browser/modules/moz.build
rename from browser/modules/BlockedSiteContent.jsm
rename to browser/actors/BlockedSiteChild.jsm
--- a/browser/modules/BlockedSiteContent.jsm
+++ b/browser/actors/BlockedSiteChild.jsm
@@ -1,16 +1,18 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* 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/. */
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-var EXPORTED_SYMBOLS = ["BlockedSiteContent"];
+var EXPORTED_SYMBOLS = ["BlockedSiteChild"];
+
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
 
 ChromeUtils.defineModuleGetter(this, "SafeBrowsing",
                                "resource://gre/modules/SafeBrowsing.jsm");
 
 function getSiteBlockedErrorDetails(docShell) {
   let blockedInfo = {};
   if (docShell.failedChannel) {
     let classifiedChannel = docShell.failedChannel.
@@ -30,31 +32,36 @@ function getSiteBlockedErrorDetails(docS
       blockedInfo = { list: classifiedChannel.matchedList,
                       provider: classifiedChannel.matchedProvider,
                       uri: reportUri.asciiSpec };
     }
   }
   return blockedInfo;
 }
 
-var BlockedSiteContent = {
-  receiveMessage(global, msg) {
+class BlockedSiteChild extends ActorChild {
+  receiveMessage(msg) {
     if (msg.name == "DeceptiveBlockedDetails") {
-      global.sendAsyncMessage("DeceptiveBlockedDetails:Result", {
-        blockedInfo: getSiteBlockedErrorDetails(global.docShell),
+      this.mm.sendAsyncMessage("DeceptiveBlockedDetails:Result", {
+        blockedInfo: getSiteBlockedErrorDetails(this.mm.docShell),
       });
     }
-  },
+  }
 
-  handleEvent(global, aEvent) {
-    if (aEvent.type != "AboutBlockedLoaded") {
-      return;
+  handleEvent(event) {
+    if (event.type == "AboutBlockedLoaded") {
+      this.onAboutBlockedLoaded(event);
+    } else if (event.type == "click" && event.button == 0) {
+      this.onClick(event);
     }
+  }
 
-    let {content} = global;
+  onAboutBlockedLoaded(aEvent) {
+    let global = this.mm;
+    let content = aEvent.target.ownerGlobal;
 
     let blockedInfo = getSiteBlockedErrorDetails(global.docShell);
     let provider = blockedInfo.provider || "";
 
     let doc = content.document;
 
     /**
     * Set error description link in error details.
@@ -115,31 +122,34 @@ var BlockedSiteContent = {
       let el = content.document.getElementById("advisoryDesc");
       el.remove();
       return;
     }
 
     let anchorEl = content.document.getElementById("advisory_provider");
     anchorEl.setAttribute("href", advisoryUrl);
     anchorEl.textContent = advisoryLinkText;
-  },
+  }
 
-  onAboutBlocked(global, targetElement, ownerDoc) {
+  onClick(event) {
+    let ownerDoc = event.target.ownerDocument;
+    if (!ownerDoc) {
+      return;
+    }
+
     var reason = "phishing";
     if (/e=malwareBlocked/.test(ownerDoc.documentURI)) {
       reason = "malware";
     } else if (/e=unwantedBlocked/.test(ownerDoc.documentURI)) {
       reason = "unwanted";
     } else if (/e=harmfulBlocked/.test(ownerDoc.documentURI)) {
       reason = "harmful";
     }
 
-    let docShell = ownerDoc.defaultView.docShell;
-
-    global.sendAsyncMessage("Browser:SiteBlockedError", {
+    this.mm.sendAsyncMessage("Browser:SiteBlockedError", {
       location: ownerDoc.location.href,
       reason,
-      elementId: targetElement.getAttribute("id"),
+      elementId: event.target.getAttribute("id"),
       isTopFrame: (ownerDoc.defaultView.parent === ownerDoc.defaultView),
-      blockedInfo: getSiteBlockedErrorDetails(docShell),
+      blockedInfo: getSiteBlockedErrorDetails(ownerDoc.defaultView.docShell),
     });
-  },
-};
+  }
+}
--- a/browser/actors/ClickHandlerChild.jsm
+++ b/browser/actors/ClickHandlerChild.jsm
@@ -3,18 +3,16 @@
  * 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/. */
 
 var EXPORTED_SYMBOLS = ["ClickHandlerChild"];
 
 ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-ChromeUtils.defineModuleGetter(this, "BlockedSiteContent",
-                               "resource:///modules/BlockedSiteContent.jsm");
 ChromeUtils.defineModuleGetter(this, "BrowserUtils",
                                "resource://gre/modules/BrowserUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "NetErrorContent",
                                "resource:///modules/NetErrorContent.jsm");
 ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
                                "resource://gre/modules/PrivateBrowsingUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "WebNavigationFrames",
                                "resource://gre/modules/WebNavigationFrames.jsm");
@@ -32,17 +30,16 @@ class ClickHandlerChild extends ActorChi
     }
 
     // Handle click events from about pages
     if (event.button == 0) {
       if (this.mm.AboutNetAndCertErrorListener.isAboutCertError(ownerDoc)) {
         NetErrorContent.onCertError(this.mm, originalTarget, ownerDoc.defaultView);
         return;
       } else if (ownerDoc.documentURI.startsWith("about:blocked")) {
-        BlockedSiteContent.onAboutBlocked(this.mm, originalTarget, ownerDoc);
         return;
       } else if (this.mm.AboutNetAndCertErrorListener.isAboutNetError(ownerDoc)) {
         NetErrorContent.onAboutNetError(this.mm, event, ownerDoc.documentURI);
         return;
       }
     }
 
     let [href, node, principal] = this._hrefAndLinkNodeForClickEvent(event);
--- a/browser/actors/moz.build
+++ b/browser/actors/moz.build
@@ -13,16 +13,17 @@ with Files("PageInfoChild.jsm"):
 with Files("PageStyleChild.jsm"):
     BUG_COMPONENT = ("Firefox", "Menus")
 
 with Files("PluginChild.jsm"):
     BUG_COMPONENT = ("Core", "Plug-ins")
 
 FINAL_TARGET_FILES.actors += [
     'AboutReaderChild.jsm',
+    'BlockedSiteChild.jsm',
     'BrowserTabChild.jsm',
     'ClickHandlerChild.jsm',
     'ContentSearchChild.jsm',
     'ContextMenuChild.jsm',
     'LightWeightThemeInstallChild.jsm',
     'PageInfoChild.jsm',
     'PageStyleChild.jsm',
     'PluginChild.jsm',
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -11,17 +11,16 @@
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 // TabChildGlobal
 var global = this;
 
 XPCOMUtils.defineLazyModuleGetters(this, {
-  BlockedSiteContent: "resource:///modules/BlockedSiteContent.jsm",
   ContentLinkHandler: "resource:///modules/ContentLinkHandler.jsm",
   ContentMetaHandler: "resource:///modules/ContentMetaHandler.jsm",
   ContentWebRTC: "resource:///modules/ContentWebRTC.jsm",
   LoginFormFactory: "resource://gre/modules/LoginManagerContent.jsm",
   InsecurePasswordUtils: "resource://gre/modules/InsecurePasswordUtils.jsm",
   FormSubmitObserver: "resource:///modules/FormSubmitObserver.jsm",
   NetErrorContent: "resource:///modules/NetErrorContent.jsm",
   PageMetadata: "resource://gre/modules/PageMetadata.jsm",
@@ -60,49 +59,16 @@ addEventListener("DOMInputPasswordAdded"
   LoginManagerContent.onDOMInputPasswordAdded(event, content);
   let formLike = LoginFormFactory.createFromField(event.originalTarget);
   InsecurePasswordUtils.reportInsecurePasswords(formLike);
 });
 addEventListener("DOMAutoComplete", function(event) {
   LoginManagerContent.onUsernameInput(event);
 });
 
-var AboutBlockedSiteListener = {
-  init(chromeGlobal) {
-    addMessageListener("DeceptiveBlockedDetails", this);
-    chromeGlobal.addEventListener("AboutBlockedLoaded", this, false, true);
-    this.init = null;
-  },
-
-  get isBlockedSite() {
-    return content.document.documentURI.startsWith("about:blocked");
-  },
-
-  receiveMessage(msg) {
-    if (!this.isBlockedSite) {
-      return;
-    }
-
-    BlockedSiteContent.receiveMessage(global, msg);
-  },
-
-  handleEvent(aEvent) {
-    if (!this.isBlockedSite) {
-      return;
-    }
-
-    if (aEvent.type != "AboutBlockedLoaded") {
-      return;
-    }
-
-    BlockedSiteContent.handleEvent(global, aEvent);
-  },
-};
-AboutBlockedSiteListener.init(this);
-
 this.AboutNetAndCertErrorListener = {
   init(chromeGlobal) {
     addMessageListener("CertErrorDetails", this);
     addMessageListener("Browser:CaptivePortalFreed", this);
     chromeGlobal.addEventListener("AboutNetErrorLoad", this, false, true);
     chromeGlobal.addEventListener("AboutNetErrorOpenCaptivePortal", this, false, true);
     chromeGlobal.addEventListener("AboutNetErrorSetAutomatic", this, false, true);
     chromeGlobal.addEventListener("AboutNetErrorResetPreferences", this, false, true);
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -24,16 +24,31 @@ let ACTORS = {
       },
       messages: [
         "Reader:ToggleReaderMode",
         "Reader:PushState",
       ],
     },
   },
 
+  BlockedSite: {
+    child: {
+      module: "resource:///actors/BlockedSiteChild.jsm",
+      events: {
+        "AboutBlockedLoaded": {wantUntrusted: true},
+        "click": {},
+      },
+      matches: ["about:blocked?*"],
+      allFrames: true,
+      messages: [
+        "DeceptiveBlockedDetails",
+      ],
+    },
+  },
+
   BrowserTab: {
     child: {
       module: "resource:///actors/BrowserTabChild.jsm",
       group: "browsers",
 
       events: {
         "DOMWindowCreated": {once: true},
         "MozAfterPaint": {once: true},
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -117,17 +117,16 @@ BROWSER_CHROME_MANIFESTS += [
     'test/browser/browser.ini',
     'test/browser/formValidation/browser.ini',
 ]
 XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
 
 EXTRA_JS_MODULES += [
     'AboutNewTab.jsm',
     'AsyncTabSwitcher.jsm',
-    'BlockedSiteContent.jsm',
     'BrowserErrorReporter.jsm',
     'BrowserUsageTelemetry.jsm',
     'BrowserWindowTracker.jsm',
     'ContentClick.jsm',
     'ContentCrashHandlers.jsm',
     'ContentLinkHandler.jsm',
     'ContentMetaHandler.jsm',
     'ContentObservers.js',