Bug 896523 - In Firefox, Console.log does not work from apps launched within the system app. r=msucan
authorPaul Rouget <paul@mozilla.com>
Fri, 24 Jan 2014 08:33:31 -0500
changeset 165052 4852d88cc2aee7ace4d8bda463ca08893e54444d
parent 165051 41143dba70eb8c00da3a96088366280be93d60be
child 165053 670741cc94a53157038f91324c6ce67988540ec6
push id4552
push userryanvm@gmail.com
push dateFri, 24 Jan 2014 13:38:45 +0000
treeherderfx-team@670741cc94a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmsucan
bugs896523
milestone29.0a1
Bug 896523 - In Firefox, Console.log does not work from apps launched within the system app. r=msucan
toolkit/devtools/LayoutHelpers.jsm
toolkit/devtools/webconsole/utils.js
--- a/toolkit/devtools/LayoutHelpers.jsm
+++ b/toolkit/devtools/LayoutHelpers.jsm
@@ -340,16 +340,32 @@ LayoutHelpers.prototype = {
     let docShell = win.QueryInterface(Ci.nsIInterfaceRequestor)
                    .getInterface(Ci.nsIWebNavigation)
                    .QueryInterface(Ci.nsIDocShell);
 
     return docShell === this._topDocShell;
   },
 
   /**
+   * Check a window is part of the top level window.
+   */
+  isIncludedInTopLevelWindow: function LH_isIncludedInTopLevelWindow(win) {
+    if (this.isTopLevelWindow(win)) {
+      return true;
+    }
+
+    let parent = this.getParentWindow(win);
+    if (!parent || parent === win) {
+      return false;
+    }
+
+    return this.isIncludedInTopLevelWindow(parent);
+  },
+
+  /**
    * like win.parent, but goes through mozbrowsers and mozapps iframes.
    */
   getParentWindow: function LH_getParentWindow(win) {
     if (this.isTopLevelWindow(win)) {
       return null;
     }
 
     let docShell = win.QueryInterface(Ci.nsIInterfaceRequestor)
--- a/toolkit/devtools/webconsole/utils.js
+++ b/toolkit/devtools/webconsole/utils.js
@@ -10,16 +10,17 @@ const {Cc, Ci, Cu, components} = require
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 loader.lazyGetter(this, "NetworkHelper", () => require("devtools/toolkit/webconsole/network-helper"));
 loader.lazyImporter(this, "Services", "resource://gre/modules/Services.jsm");
 loader.lazyImporter(this, "ConsoleAPIStorage", "resource://gre/modules/ConsoleAPIStorage.jsm");
 loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
 loader.lazyImporter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm");
+loader.lazyImporter(this, "LayoutHelpers", "resource://gre/modules/devtools/LayoutHelpers.jsm");
 loader.lazyServiceGetter(this, "gActivityDistributor",
                          "@mozilla.org/network/http-activity-distributor;1",
                          "nsIHttpActivityDistributor");
 
 // TODO: Bug 842672 - toolkit/ imports modules from browser/.
 // Note that these are only used in JSTermHelpers, see $0 and pprint().
 loader.lazyImporter(this, "gDevTools", "resource:///modules/devtools/gDevTools.jsm");
 loader.lazyImporter(this, "devtools", "resource://gre/modules/devtools/Loader.jsm");
@@ -1067,16 +1068,19 @@ exports.JSPropertyProvider = JSPropertyP
  *        The listener object must have one method:
  *        - onConsoleServiceMessage(). This method is invoked with one argument,
  *        the nsIConsoleMessage, whenever a relevant message is received.
  */
 function ConsoleServiceListener(aWindow, aListener)
 {
   this.window = aWindow;
   this.listener = aListener;
+  if (this.window) {
+    this.layoutHelpers = new LayoutHelpers(this.window);
+  }
 }
 exports.ConsoleServiceListener = ConsoleServiceListener;
 
 ConsoleServiceListener.prototype =
 {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIConsoleListener]),
 
   /**
@@ -1116,17 +1120,17 @@ ConsoleServiceListener.prototype =
     if (this.window) {
       if (!(aMessage instanceof Ci.nsIScriptError) ||
           !aMessage.outerWindowID ||
           !this.isCategoryAllowed(aMessage.category)) {
         return;
       }
 
       let errorWindow = Services.wm.getOuterWindowWithId(aMessage.outerWindowID);
-      if (!errorWindow || errorWindow.top != this.window) {
+      if (!errorWindow || !this.layoutHelpers.isIncludedInTopLevelWindow(errorWindow)) {
         return;
       }
     }
 
     this.listener.onConsoleServiceMessage(aMessage);
   },
 
   /**
@@ -1238,16 +1242,19 @@ ConsoleServiceListener.prototype =
  *        - onConsoleAPICall(). This method is invoked with one argument, the
  *        Console API message that comes from the observer service, whenever
  *        a relevant console API call is received.
  */
 function ConsoleAPIListener(aWindow, aOwner)
 {
   this.window = aWindow;
   this.owner = aOwner;
+  if (this.window) {
+    this.layoutHelpers = new LayoutHelpers(this.window);
+  }
 }
 exports.ConsoleAPIListener = ConsoleAPIListener;
 
 ConsoleAPIListener.prototype =
 {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   /**
@@ -1289,17 +1296,17 @@ ConsoleAPIListener.prototype =
   {
     if (!this.owner) {
       return;
     }
 
     let apiMessage = aMessage.wrappedJSObject;
     if (this.window) {
       let msgWindow = Services.wm.getOuterWindowWithId(apiMessage.ID);
-      if (!msgWindow || msgWindow.top != this.window) {
+      if (!msgWindow || !this.layoutHelpers.isIncludedInTopLevelWindow(msgWindow)) {
         // Not the same window!
         return;
       }
     }
 
     this.owner.onConsoleAPICall(apiMessage);
   },