diff --git a/toolkit/devtools/LayoutHelpers.jsm b/toolkit/devtools/LayoutHelpers.jsm index dea31c0cff0b..3c48631fbcb1 100644 --- a/toolkit/devtools/LayoutHelpers.jsm +++ b/toolkit/devtools/LayoutHelpers.jsm @@ -344,6 +344,22 @@ LayoutHelpers.prototype = { 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. */ diff --git a/toolkit/devtools/webconsole/utils.js b/toolkit/devtools/webconsole/utils.js index 607787a2d75a..7720e9505ede 100644 --- a/toolkit/devtools/webconsole/utils.js +++ b/toolkit/devtools/webconsole/utils.js @@ -15,6 +15,7 @@ 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"); @@ -1072,6 +1073,9 @@ function ConsoleServiceListener(aWindow, aListener) { this.window = aWindow; this.listener = aListener; + if (this.window) { + this.layoutHelpers = new LayoutHelpers(this.window); + } } exports.ConsoleServiceListener = ConsoleServiceListener; @@ -1121,7 +1125,7 @@ ConsoleServiceListener.prototype = } let errorWindow = Services.wm.getOuterWindowWithId(aMessage.outerWindowID); - if (!errorWindow || errorWindow.top != this.window) { + if (!errorWindow || !this.layoutHelpers.isIncludedInTopLevelWindow(errorWindow)) { return; } } @@ -1243,6 +1247,9 @@ function ConsoleAPIListener(aWindow, aOwner) { this.window = aWindow; this.owner = aOwner; + if (this.window) { + this.layoutHelpers = new LayoutHelpers(this.window); + } } exports.ConsoleAPIListener = ConsoleAPIListener; @@ -1294,7 +1301,7 @@ ConsoleAPIListener.prototype = 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; }