Bug 1374735 - use DevToolsShim to open browser console from extensions;r=bgrins,kmag

MozReview-Commit-ID: GJQ7fcw1L8i

--HG--
extra : source : da075933f7bcd9e3b7ff735879c521bb50f28b7a
This commit is contained in:
Julian Descottes 2017-07-24 12:12:47 +02:00
parent 721cd7ffa1
commit d148f3f8c0
3 changed files with 17 additions and 6 deletions

View File

@ -590,6 +590,15 @@ DevTools.prototype = {
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.
*

View File

@ -298,9 +298,10 @@ let addonSdkMethods = [
* therefore DevTools should always be available when they are called.
*/
let webExtensionsMethods = [
"createWebExtensionInspectedWindowFront",
"getTargetForTab",
"getTheme",
"createWebExtensionInspectedWindowFront",
"openBrowserConsole",
];
for (let method of [...addonSdkMethods, ...webExtensionsMethods]) {

View File

@ -2,6 +2,11 @@
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 */
@ -16,11 +21,7 @@ global.initializeBackgroundPage = (contentWindow) => {
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;