Bug 1382661 - Stop injecting DeveloperToolbar on top level windows. r=jdescottes

MozReview-Commit-ID: L6k7SPf8czd

--HG--
extra : rebase_source : 8bece0542a4ad3d3c360745096975efd8906c587
This commit is contained in:
Alexandre Poirot 2017-07-20 13:52:57 +02:00
Родитель 1ff63c03a8
Коммит b6c47816da
9 изменённых файлов: 84 добавлений и 58 удалений

Просмотреть файл

@ -24,6 +24,7 @@ var { helpers, assert } = (function () {
var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
var { TargetFactory } = require("devtools/client/framework/target");
var { gDevToolsBrowser } = require("devtools/client/framework/devtools-browser");
var Services = require("Services");
var assert = { ok: ok, is: is, log: info };
@ -211,8 +212,8 @@ var { helpers, assert } = (function () {
options = options || {};
options.chromeWindow = options.chromeWindow || window;
return options.chromeWindow.DeveloperToolbar.show(true).then(function () {
var toolbar = options.chromeWindow.DeveloperToolbar;
var toolbar = gDevToolsBrowser.getDeveloperToolbar(options.chromeWindow);
return toolbar.show(true).then(function () {
options.automator = createDeveloperToolbarAutomator(toolbar);
options.requisition = toolbar.requisition;
return options;
@ -243,7 +244,8 @@ var { helpers, assert } = (function () {
* @return A promise resolved (with undefined) when the toolbar is closed
*/
helpers.closeToolbar = function (options) {
return options.chromeWindow.DeveloperToolbar.hide().then(function () {
var toolbar = gDevToolsBrowser.getDeveloperToolbar(options.chromeWindow).hide();
return toolbar.then(function () {
delete options.automator;
delete options.requisition;
});
@ -323,8 +325,8 @@ var { helpers, assert } = (function () {
return helpers.addTab(url, function (innerOptions) {
var win = innerOptions.chromeWindow;
return win.DeveloperToolbar.show(true).then(function () {
var toolbar = win.DeveloperToolbar;
var toolbar = gDevToolsBrowser.getDeveloperToolbar(win);
return toolbar.show(true).then(function () {
innerOptions.automator = createDeveloperToolbarAutomator(toolbar);
innerOptions.requisition = toolbar.requisition;
@ -334,7 +336,7 @@ var { helpers, assert } = (function () {
ok(false, error);
console.error(error);
}).then(function () {
win.DeveloperToolbar.hide().then(function () {
toolbar.hide().then(function () {
delete innerOptions.automator;
});
});

Просмотреть файл

@ -24,6 +24,7 @@ loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main", true);
loader.lazyRequireGetter(this, "BrowserMenus", "devtools/client/framework/browser-menus");
loader.lazyRequireGetter(this, "appendStyleSheet", "devtools/client/shared/stylesheet-utils", true);
loader.lazyRequireGetter(this, "DeveloperToolbar", "devtools/client/shared/developer-toolbar", true);
loader.lazyImporter(this, "CustomizableUI", "resource:///modules/CustomizableUI.jsm");
loader.lazyImporter(this, "CustomizableWidgets", "resource:///modules/CustomizableWidgets.jsm");
@ -55,6 +56,11 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
*/
_browserStyleSheets: new WeakMap(),
/**
* WeakMap keeping track of DeveloperToolbar instances for each firefox window.
*/
_toolbars: new WeakMap(),
_tabStats: {
peakOpen: 0,
peakPinned: 0,
@ -108,7 +114,7 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
focusEl.setAttribute("disabled", "true");
}
if (devToolbarEnabled && Services.prefs.getBoolPref("devtools.toolbar.visible")) {
win.DeveloperToolbar.show(false).catch(console.error);
this.getDeveloperToolbar(win).show(false).catch(console.error);
}
// Enable WebIDE?
@ -499,12 +505,6 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
// only once menus are registered as it depends on it.
gDevToolsBrowser.installDeveloperWidget();
// Inject lazily DeveloperToolbar on the chrome window
loader.lazyGetter(win, "DeveloperToolbar", function () {
let { DeveloperToolbar } = require("devtools/client/shared/developer-toolbar");
return new DeveloperToolbar(win);
});
this.updateCommandAvailability(win);
this.updateDevtoolsThemeAttribute(win);
this.ensurePrefObserver();
@ -518,6 +518,22 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
tabContainer.addEventListener("TabUnpinned", this);
},
/**
* Create singleton instance of the developer toolbar for a given top level window.
*
* @param {Window} win
* The window to which the toolbar should be created.
*/
getDeveloperToolbar(win) {
let toolbar = this._toolbars.get(win);
if (toolbar) {
return toolbar;
}
toolbar = new DeveloperToolbar(win);
this._toolbars.set(win, toolbar);
return toolbar;
},
/**
* Hook the JS debugger tool to the "Debug Script" button of the slow script
* dialog.
@ -727,11 +743,7 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
this._browserStyleSheets.delete(win);
}
// Destroy the Developer toolbar if it has been accessed
let desc = Object.getOwnPropertyDescriptor(win, "DeveloperToolbar");
if (desc && !desc.get) {
win.DeveloperToolbar.destroy();
}
this._toolbars.delete(win);
let tabContainer = win.gBrowser.tabContainer;
tabContainer.removeEventListener("TabSelect", this);

Просмотреть файл

@ -75,9 +75,9 @@ exports.menuitems = [
// or close the toolbar and when hitting the key shortcut where we just
// focus the toolbar if it doesn't already has it.
if (event.target.tagName.toLowerCase() == "menuitem") {
window.DeveloperToolbar.toggle();
gDevToolsBrowser.getDeveloperToolbar(window).toggle();
} else {
window.DeveloperToolbar.focusToggle();
gDevToolsBrowser.getDeveloperToolbar(window).focusToggle();
}
},
key: {

Просмотреть файл

@ -230,7 +230,9 @@ DeveloperToolbar.prototype.createToolbar = function () {
let close = this._doc.createElement("toolbarbutton");
close.setAttribute("id", "developer-toolbar-closebutton");
close.setAttribute("class", "close-icon");
close.setAttribute("oncommand", "DeveloperToolbar.hide();");
close.addEventListener("command", (event) => {
this.hide();
});
let closeTooltip = L10N.getStr("toolbar.closeButton.tooltip");
close.setAttribute("tooltiptext", closeTooltip);

Просмотреть файл

@ -3,7 +3,4 @@
module.exports = {
// Extend from the shared list of defined globals for mochitests.
"extends": "../../../.eslintrc.mochitests.js",
"globals": {
"DeveloperToolbar": true
}
};

Просмотреть файл

@ -5,18 +5,21 @@
// Tests that the developer toolbar works properly
const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
const TEST_URI = TEST_URI_ROOT + "doc_toolbar_basic.html";
add_task(function* () {
info("Starting browser_toolbar_basic.js");
yield addTab(TEST_URI);
ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible in to start");
let toolbar = gDevToolsBrowser.getDeveloperToolbar(window);
ok(!toolbar.visible, "DeveloperToolbar is not visible in to start");
let shown = oneTimeObserve(DeveloperToolbar.NOTIFICATIONS.SHOW);
let shown = oneTimeObserve(toolbar.NOTIFICATIONS.SHOW);
document.getElementById("menu_devToolbar").doCommand();
yield shown;
ok(DeveloperToolbar.visible, "DeveloperToolbar is visible in checkOpen");
ok(toolbar.visible, "DeveloperToolbar is visible in checkOpen");
let close = document.getElementById("developer-toolbar-closebutton");
ok(close, "Close button exists");
@ -36,23 +39,23 @@ add_task(function* () {
gBrowser.removeCurrentTab();
let hidden = oneTimeObserve(DeveloperToolbar.NOTIFICATIONS.HIDE);
let hidden = oneTimeObserve(toolbar.NOTIFICATIONS.HIDE);
document.getElementById("menu_devToolbar").doCommand();
yield hidden;
ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible in hidden");
ok(!toolbar.visible, "DeveloperToolbar is not visible in hidden");
shown = oneTimeObserve(DeveloperToolbar.NOTIFICATIONS.SHOW);
shown = oneTimeObserve(toolbar.NOTIFICATIONS.SHOW);
document.getElementById("menu_devToolbar").doCommand();
yield shown;
ok(DeveloperToolbar.visible, "DeveloperToolbar is visible in after open");
ok(toolbar.visible, "DeveloperToolbar is visible in after open");
ok(isChecked(toggleToolbox), "toggle toolbox button is checked");
hidden = oneTimeObserve(DeveloperToolbar.NOTIFICATIONS.HIDE);
hidden = oneTimeObserve(toolbar.NOTIFICATIONS.HIDE);
document.getElementById("developer-toolbar-closebutton").doCommand();
yield hidden;
ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible after re-close");
ok(!toolbar.visible, "DeveloperToolbar is not visible after re-close");
});
function isChecked(b) {

Просмотреть файл

@ -5,6 +5,8 @@
// Tests that the developer toolbar works properly
const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
const TEST_URI = "data:text/html;charset=utf-8,<p>Tooltip Tests</p>";
const PREF_DEVTOOLS_THEME = "devtools.theme";
@ -13,82 +15,84 @@ registerCleanupFunction(() => {
Services.prefs.clearUserPref(PREF_DEVTOOLS_THEME);
});
let toolbar = gDevToolsBrowser.getDeveloperToolbar(window);
add_task(function* showToolbar() {
yield addTab(TEST_URI);
info("Starting browser_toolbar_tooltip.js");
ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible in runTest");
ok(!toolbar.visible, "DeveloperToolbar is not visible in runTest");
let showPromise = observeOnce(DeveloperToolbar.NOTIFICATIONS.SHOW);
let showPromise = observeOnce(toolbar.NOTIFICATIONS.SHOW);
document.getElementById("menu_devToolbar").doCommand();
yield showPromise;
});
add_task(function* testDimensions() {
let tooltipPanel = DeveloperToolbar.tooltipPanel;
let tooltipPanel = toolbar.tooltipPanel;
DeveloperToolbar.focusManager.helpRequest();
yield DeveloperToolbar.inputter.setInput("help help");
toolbar.focusManager.helpRequest();
yield toolbar.inputter.setInput("help help");
DeveloperToolbar.inputter.setCursor({ start: "help help".length });
toolbar.inputter.setCursor({ start: "help help".length });
is(tooltipPanel._dimensions.start, "help ".length,
"search param start, when cursor at end");
ok(getLeftMargin() > 30, "tooltip offset, when cursor at end");
DeveloperToolbar.inputter.setCursor({ start: "help".length });
toolbar.inputter.setCursor({ start: "help".length });
is(tooltipPanel._dimensions.start, 0,
"search param start, when cursor at end of command");
ok(getLeftMargin() > 9, "tooltip offset, when cursor at end of command");
DeveloperToolbar.inputter.setCursor({ start: "help help".length - 1 });
toolbar.inputter.setCursor({ start: "help help".length - 1 });
is(tooltipPanel._dimensions.start, "help ".length,
"search param start, when cursor at penultimate position");
ok(getLeftMargin() > 30, "tooltip offset, when cursor at penultimate position");
DeveloperToolbar.inputter.setCursor({ start: 0 });
toolbar.inputter.setCursor({ start: 0 });
is(tooltipPanel._dimensions.start, 0,
"search param start, when cursor at start");
ok(getLeftMargin() > 9, "tooltip offset, when cursor at start");
});
add_task(function* testThemes() {
let tooltipPanel = DeveloperToolbar.tooltipPanel;
let tooltipPanel = toolbar.tooltipPanel;
ok(tooltipPanel.document, "Tooltip panel is initialized");
Services.prefs.setCharPref(PREF_DEVTOOLS_THEME, "dark");
yield DeveloperToolbar.inputter.setInput("");
yield DeveloperToolbar.inputter.setInput("help help");
yield toolbar.inputter.setInput("");
yield toolbar.inputter.setInput("help help");
is(tooltipPanel.document.documentElement.getAttribute("devtoolstheme"),
"dark", "Tooltip panel has correct theme");
Services.prefs.setCharPref(PREF_DEVTOOLS_THEME, "light");
yield DeveloperToolbar.inputter.setInput("");
yield DeveloperToolbar.inputter.setInput("help help");
yield toolbar.inputter.setInput("");
yield toolbar.inputter.setInput("help help");
is(tooltipPanel.document.documentElement.getAttribute("devtoolstheme"),
"light", "Tooltip panel has correct theme");
});
add_task(function* hideToolbar() {
info("Ending browser_toolbar_tooltip.js");
yield DeveloperToolbar.inputter.setInput("");
yield toolbar.inputter.setInput("");
ok(DeveloperToolbar.visible, "DeveloperToolbar is visible in hideToolbar");
ok(toolbar.visible, "DeveloperToolbar is visible in hideToolbar");
info("Hide toolbar");
let hidePromise = observeOnce(DeveloperToolbar.NOTIFICATIONS.HIDE);
let hidePromise = observeOnce(toolbar.NOTIFICATIONS.HIDE);
document.getElementById("menu_devToolbar").doCommand();
yield hidePromise;
ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible in hideToolbar");
ok(!toolbar.visible, "DeveloperToolbar is not visible in hideToolbar");
info("Done test");
});
function getLeftMargin() {
let style = DeveloperToolbar.tooltipPanel._panel.style.marginLeft;
let style = toolbar.tooltipPanel._panel.style.marginLeft;
return parseInt(style.slice(0, -2), 10);
}

Просмотреть файл

@ -7,6 +7,8 @@
// Tests that the developer toolbar errors count works properly.
const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
// Use the old webconsole since this is directly accessing old DOM, and
// the error count isn't reset when pressing the clear button in new one
// See Bug 1304794.
@ -15,6 +17,8 @@ registerCleanupFunction(function* () {
Services.prefs.clearUserPref("devtools.webconsole.new-frontend-enabled");
});
let toolbar = gDevToolsBrowser.getDeveloperToolbar(window);
function test() {
const TEST_URI = TEST_URI_ROOT + "doc_toolbar_webconsole_errors_count.html";
@ -35,15 +39,15 @@ function test() {
expectUncaughtException();
if (!DeveloperToolbar.visible) {
DeveloperToolbar.show(true).then(onOpenToolbar);
if (!toolbar.visible) {
toolbar.show(true).then(onOpenToolbar);
} else {
onOpenToolbar();
}
}
function onOpenToolbar() {
ok(DeveloperToolbar.visible, "DeveloperToolbar is visible");
ok(toolbar.visible, "DeveloperToolbar is visible");
webconsole = document.getElementById("developer-toolbar-toolbox-button");
waitForButtonUpdate({
@ -240,9 +244,9 @@ function test() {
if (!check()) {
info("wait for: " + options.name);
DeveloperToolbar.on("errors-counter-updated", function onUpdate(event) {
toolbar.on("errors-counter-updated", function onUpdate(event) {
if (check()) {
DeveloperToolbar.off(event, onUpdate);
toolbar.off(event, onUpdate);
}
});
}

Просмотреть файл

@ -7,6 +7,7 @@
var WebConsoleUtils = require("devtools/client/webconsole/utils").Utils;
const {extend} = require("devtools/shared/extend");
var {TargetFactory} = require("devtools/client/framework/target");
var {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
var {Tools} = require("devtools/client/definitions");
const { Task } = require("devtools/shared/task");
var promise = require("promise");
@ -389,7 +390,8 @@ WebConsole.prototype = {
_onClearButton: function WC__onClearButton()
{
if (this.target.isLocalTab) {
this.browserWindow.DeveloperToolbar.resetErrorsCount(this.target.tab);
gDevToolsBrowser.getDeveloperToolbar(this.browserWindow)
.resetErrorsCount(this.target.tab);
}
},