Bug 1223116 P2 Make webconsole use new nsIServiceWorkerManager.shouldReportToWindow(). r=bgrins a=ritu
authorBen Kelly <ben@wanderview.com>
Wed, 18 Nov 2015 14:05:14 -0800
changeset 305556 4ddcaa564eb8ef998b8b123fec2582b935a047e2
parent 305555 a8babe14e557fdf216d9c65721b035efc2de5fba
child 305557 7e411051b2d699fd4f100059e17618e4508384b7
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins, ritu
bugs1223116
milestone44.0a2
Bug 1223116 P2 Make webconsole use new nsIServiceWorkerManager.shouldReportToWindow(). r=bgrins a=ritu
devtools/shared/webconsole/utils.js
--- a/devtools/shared/webconsole/utils.js
+++ b/devtools/shared/webconsole/utils.js
@@ -14,16 +14,21 @@ Cu.import("resource://gre/modules/XPCOMU
 loader.lazyImporter(this, "Services", "resource://gre/modules/Services.jsm");
 loader.lazyImporter(this, "Parser", "resource://devtools/shared/Parser.jsm");
 
 // TODO: Bug 842672 - browser/ imports modules from toolkit/.
 // Note that these are only used in WebConsoleCommands, see $0 and pprint().
 loader.lazyImporter(this, "VariablesView", "resource://devtools/client/shared/widgets/VariablesView.jsm");
 const DevToolsUtils = require("devtools/shared/DevToolsUtils");
 
+XPCOMUtils.defineLazyServiceGetter(this,
+                                   "swm",
+                                   "@mozilla.org/serviceworkers/manager;1",
+                                   "nsIServiceWorkerManager");
+
 // Match the function name from the result of toString() or toSource().
 //
 // Examples:
 // (function foobar(a, b) { ...
 // function foobar2(a) { ...
 // function() { ...
 const REGEX_MATCH_FUNCTION_NAME = /^\(?function\s+([^(\s]+)\s*\(/;
 
@@ -130,39 +135,16 @@ var WebConsoleUtils = {
     let style = win.getComputedStyle(aFrom);
     aTo.style.fontFamily = style.getPropertyCSSValue("font-family").cssText;
     aTo.style.fontSize = style.getPropertyCSSValue("font-size").cssText;
     aTo.style.fontWeight = style.getPropertyCSSValue("font-weight").cssText;
     aTo.style.fontStyle = style.getPropertyCSSValue("font-style").cssText;
   },
 
   /**
-   * Recursively gather a list of window locations given
-   * a top level window.
-   *
-   * @param nsIDOMWindow aWindow
-   * @return Array
-   *         list of window locations as strings
-   */
-  getLocationsForFrames: function(aWindow)
-  {
-    let location = aWindow.location.toString();
-    let locations = [location];
-
-    if (aWindow.frames) {
-      for (let i = 0; i < aWindow.frames.length; i++) {
-        let frame = aWindow.frames[i];
-        locations = locations.concat(this.getLocationsForFrames(frame));
-      }
-    }
-
-    return locations;
-  },
-
-  /**
    * Gets the ID of the inner window of this DOM window.
    *
    * @param nsIDOMWindow aWindow
    * @return integer
    *         Inner ID for the given aWindow.
    */
   getInnerWindowId: function WCU_getInnerWindowId(aWindow)
   {
@@ -1503,19 +1485,18 @@ ConsoleAPIListener.prototype =
   isMessageRelevant: function(message) {
     let workerType = WebConsoleUtils.getWorkerType(message);
 
     if (this.window && workerType === "ServiceWorker") {
       // For messages from Service Workers, message.ID is the
       // scope, which can be used to determine whether it's controlling
       // a window.
       let scope = message.ID;
-      let locations = WebConsoleUtils.getLocationsForFrames(this.window);
 
-      if (!locations.some(loc => loc.startsWith(scope))) {
+      if (!swm.shouldReportToWindow(this.window, scope)) {
         return false;
       }
     }
 
     if (this.window && !workerType) {
       let msgWindow = Services.wm.getCurrentInnerWindowWithId(message.innerID);
       if (!msgWindow || !isWindowIncluded(this.window, msgWindow)) {
         // Not the same window!