Bug 1735748 - [devtools] Disable all DevTools reload shortcuts in the Browser Toolbox, but replicate the local-build-only full reload shortcut. r=jdescottes,nchevobbe

This replicates the key shortcut implemented by browser-development-helpers.js.

Differential Revision: https://phabricator.services.mozilla.com/D128478
This commit is contained in:
Alexandre Poirot 2022-08-08 16:55:32 +00:00
Родитель 546a557cdd
Коммит a470d864c4
5 изменённых файлов: 91 добавлений и 38 удалений

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

@ -21,5 +21,46 @@ add_task(async function() {
});
ok(!hasCloseButton, "Browser toolbox doesn't have a close button");
info("Trigger F5 key shortcut and ensure nothing happens");
info(
"If F5 triggers a full reload, the mochitest will stop here as firefox instance will be restarted"
);
const previousInnerWindowId =
window.browsingContext.currentWindowGlobal.innerWindowId;
function onUnload() {
ok(false, "The top level window shouldn't be reloaded/closed");
}
window.addEventListener("unload", onUnload);
await ToolboxTask.spawn(null, async () => {
const isMacOS = Services.appinfo.OS === "Darwin";
const { win } = gToolbox;
// Simulate CmdOrCtrl+R
win.dispatchEvent(
new win.KeyboardEvent("keydown", {
bubbles: true,
ctrlKey: !isMacOS,
metaKey: isMacOS,
keyCode: "r".charCodeAt(0),
})
);
// Simulate F5
win.dispatchEvent(
new win.KeyboardEvent("keydown", {
bubbles: true,
keyCode: win.KeyEvent.DOM_VK_F5,
})
);
});
// Let a chance to trigger the regression where the top level document closes or reloads
await wait(1000);
is(
window.browsingContext.currentWindowGlobal.innerWindowId,
previousInnerWindowId,
"Check the browser.xhtml wasn't reloaded when pressing F5"
);
window.removeEventListener("unload", onUnload);
await ToolboxTask.destroy();
});

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

@ -147,6 +147,7 @@ window.addEventListener(
gShortcuts = new KeyShortcuts({ window });
gShortcuts.on("CmdOrCtrl+W", onCloseCommand);
gShortcuts.on("CmdOrCtrl+Alt+Shift+I", onDebugBrowserToolbox);
gShortcuts.on("CmdOrCtrl+Alt+R", onReloadBrowser);
const statusMessageContainer = document.getElementById(
"status-message-title"
@ -190,6 +191,13 @@ function onDebugBrowserToolbox() {
BrowserToolboxLauncher.init();
}
/**
* Replicate the local-build-only key shortcut to reload the browser
*/
function onReloadBrowser() {
gToolbox.commands.targetCommand.reloadTopLevelTarget();
}
async function openToolbox(descriptorFront) {
const form = descriptorFront._form;
appendStatusMessage(

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

@ -1179,21 +1179,23 @@ Toolbox.prototype = {
// List for Help/Settings key.
this.shortcuts.on(L10N.getStr("toolbox.help.key"), this.toggleOptions);
// Listen for Reload shortcuts
[
["reload", false],
["reload2", false],
["forceReload", true],
["forceReload2", true],
].forEach(([id, force]) => {
const key = L10N.getStr("toolbox." + id + ".key");
this.shortcuts.on(key, event => {
this.commands.targetCommand.reloadTopLevelTarget(force);
if (!this.isBrowserToolbox) {
// Listen for Reload shortcuts
[
["reload", false],
["reload2", false],
["forceReload", true],
["forceReload2", true],
].forEach(([id, force]) => {
const key = L10N.getStr("toolbox." + id + ".key");
this.shortcuts.on(key, event => {
this.commands.targetCommand.reloadTopLevelTarget(force);
// Prevent Firefox shortcuts from reloading the page
event.preventDefault();
// Prevent Firefox shortcuts from reloading the page
event.preventDefault();
});
});
});
}
// Add zoom-related shortcuts.
if (!this._hostOptions || this._hostOptions.zoom === true) {

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

@ -705,7 +705,14 @@ class WebConsoleUI {
);
ZoomKeys.register(this.window, shortcuts);
shortcuts.on("CmdOrCtrl+Alt+R", quickRestart);
/* This is the same as DevelopmentHelpers.quickRestart, but it runs in all
* builds (even official). This allows a user to do a restart + session restore
* with Ctrl+Shift+J (open Browser Console) and then Ctrl+Alt+R (restart).
*/
shortcuts.on("CmdOrCtrl+Alt+R", () => {
this.hud.commands.targetCommand.reloadTopLevelTarget();
});
} else if (Services.prefs.getBoolPref(PREF_SIDEBAR_ENABLED)) {
shortcuts.on("Esc", event => {
this.wrapper.dispatchSidebarClose();
@ -757,20 +764,4 @@ class WebConsoleUI {
}
}
/* This is the same as DevelopmentHelpers.quickRestart, but it runs in all
* builds (even official). This allows a user to do a restart + session restore
* with Ctrl+Shift+J (open Browser Console) and then Ctrl+Shift+R (restart).
*/
function quickRestart() {
const { Cc, Ci } = require("chrome");
Services.obs.notifyObservers(null, "startupcache-invalidate");
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("MOZ_DISABLE_SAFE_MODE_KEY", "1");
Services.startup.quit(
Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart
);
}
exports.WebConsoleUI = WebConsoleUI;

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

@ -196,19 +196,30 @@ const ProcessDescriptorActor = ActorClassWithSpec(processDescriptorSpec, {
};
},
async reloadDescriptor({ bypassCache }) {
async reloadDescriptor() {
if (!this.isParent || this.isWindowlessParent) {
throw new Error(
"reloadDescriptor is only available for parent process descriptors linked to a window"
"reloadDescriptor is only available for parent process descriptors"
);
}
// For parent process debugging, we only reload the current top level
// browser window.
this._windowGlobalTargetActor.browsingContext.reload(
bypassCache
? Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE
: Ci.nsIWebNavigation.LOAD_FLAGS_NONE
// Reload for the parent process will restart the whole browser
//
// This aims at replicate `DevelopmentHelpers.quickRestart`
// This allows a user to do a full firefox restart + session restore
// Via Ctrl+Alt+R on the Browser Console/Toolbox
// Maximize the chance of fetching new source content by clearing the cache
Services.obs.notifyObservers(null, "startupcache-invalidate");
// Avoid safemode popup from appearing on restart
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("MOZ_DISABLE_SAFE_MODE_KEY", "1");
Services.startup.quit(
Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart
);
},