Bug 1374735 - use DevToolsShim to open browser console from extensions;r=bgrins,kmag
MozReview-Commit-ID: GJQ7fcw1L8i
--- a/devtools/client/framework/devtools.js
+++ b/devtools/client/framework/devtools.js
@@ -586,16 +586,25 @@ DevTools.prototype = {
* Compatibility layer for web-extensions. Used by DevToolsShim for
* browser/components/extensions/ext-devtools-inspectedWindow.js
*/
createWebExtensionInspectedWindowFront: function (tabTarget) {
return new WebExtensionInspectedWindowFront(tabTarget.client, tabTarget.form);
},
/**
+ * Compatibility layer for web-extensions. Used by DevToolsShim for
+ * toolkit/components/extensions/ext-c-toolkit.js
+ */
+ openBrowserConsole: function () {
+ let {HUDService} = require("devtools/client/webconsole/hudservice");
+ HUDService.openBrowserConsoleOrFocus();
+ },
+
+ /**
* Called from the DevToolsShim, used by nsContextMenu.js.
*
* @param {XULTab} tab
* The browser tab on which inspect node was used.
* @param {Array} selectors
* An array of CSS selectors to find the target node. Several selectors can be
* needed if the element is nested in frames and not directly in the root
* document.
--- a/devtools/shim/DevToolsShim.jsm
+++ b/devtools/shim/DevToolsShim.jsm
@@ -293,18 +293,19 @@ let addonSdkMethods = [
/**
* Compatibility layer for webextensions.
*
* Those methods are called only after a DevTools webextension was loaded in DevTools,
* therefore DevTools should always be available when they are called.
*/
let webExtensionsMethods = [
+ "createWebExtensionInspectedWindowFront",
"getTargetForTab",
"getTheme",
- "createWebExtensionInspectedWindowFront",
+ "openBrowserConsole",
];
for (let method of [...addonSdkMethods, ...webExtensionsMethods]) {
this.DevToolsShim[method] = function () {
return this.gDevTools[method].apply(this.gDevTools, arguments);
};
}
--- a/toolkit/components/extensions/ext-c-toolkit.js
+++ b/toolkit/components/extensions/ext-c-toolkit.js
@@ -1,31 +1,32 @@
"use strict";
Cu.import("resource://gre/modules/ExtensionCommon.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Services",
+ "resource://gre/modules/Services.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "DevToolsShim",
+ "chrome://devtools-shim/content/DevToolsShim.jsm");
+
// These are defined on "global" which is used for the same scopes as the other
// ext-c-*.js files.
/* exported EventManager */
/* global EventManager: false */
global.EventManager = ExtensionCommon.EventManager;
global.initializeBackgroundPage = (contentWindow) => {
// Override the `alert()` method inside background windows;
// we alias it to console.log().
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1203394
let alertDisplayedWarning = false;
let alertOverwrite = text => {
if (!alertDisplayedWarning) {
- require("devtools/client/framework/devtools-browser");
-
- let {HUDService} = require("devtools/client/webconsole/hudservice");
- HUDService.openBrowserConsoleOrFocus();
-
+ DevToolsShim.openBrowserConsole();
contentWindow.console.warn("alert() is not supported in background windows; please use console.log instead.");
alertDisplayedWarning = true;
}
contentWindow.console.log(text);
};
Cu.exportFunction(alertOverwrite, contentWindow, {defineAs: "alert"});