mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1880914 - Move all reload functions. r=Gijs,devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D205527
This commit is contained in:
parent
263337e229
commit
955c9df070
@ -7,6 +7,10 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var kSkipCacheFlags =
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY |
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
||||
|
||||
var BrowserCommands = {
|
||||
back(aEvent) {
|
||||
const where = BrowserUtils.whereToOpenLink(aEvent, false, true);
|
||||
@ -80,4 +84,115 @@ var BrowserCommands = {
|
||||
duplicateTabIn(gBrowser.selectedTab, where, Number(historyindex));
|
||||
return true;
|
||||
},
|
||||
|
||||
reloadOrDuplicate(aEvent) {
|
||||
aEvent = BrowserUtils.getRootEvent(aEvent);
|
||||
const accelKeyPressed =
|
||||
AppConstants.platform == "macosx" ? aEvent.metaKey : aEvent.ctrlKey;
|
||||
const backgroundTabModifier = aEvent.button == 1 || accelKeyPressed;
|
||||
|
||||
if (aEvent.shiftKey && !backgroundTabModifier) {
|
||||
this.reloadSkipCache();
|
||||
return;
|
||||
}
|
||||
|
||||
const where = BrowserUtils.whereToOpenLink(aEvent, false, true);
|
||||
if (where == "current") {
|
||||
this.reload();
|
||||
} else {
|
||||
duplicateTabIn(gBrowser.selectedTab, where);
|
||||
}
|
||||
},
|
||||
|
||||
reload() {
|
||||
if (gBrowser.currentURI.schemeIs("view-source")) {
|
||||
// Bug 1167797: For view source, we always skip the cache
|
||||
this.reloadSkipCache();
|
||||
return;
|
||||
}
|
||||
this.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_NONE);
|
||||
},
|
||||
|
||||
reloadSkipCache() {
|
||||
// Bypass proxy and cache.
|
||||
this.reloadWithFlags(kSkipCacheFlags);
|
||||
},
|
||||
|
||||
reloadWithFlags(reloadFlags) {
|
||||
const unchangedRemoteness = [];
|
||||
|
||||
for (const tab of gBrowser.selectedTabs) {
|
||||
const browser = tab.linkedBrowser;
|
||||
const url = browser.currentURI;
|
||||
const urlSpec = url.spec;
|
||||
// We need to cache the content principal here because the browser will be
|
||||
// reconstructed when the remoteness changes and the content prinicpal will
|
||||
// be cleared after reconstruction.
|
||||
const principal = tab.linkedBrowser.contentPrincipal;
|
||||
if (gBrowser.updateBrowserRemotenessByURL(browser, urlSpec)) {
|
||||
// If the remoteness has changed, the new browser doesn't have any
|
||||
// information of what was loaded before, so we need to load the previous
|
||||
// URL again.
|
||||
if (tab.linkedPanel) {
|
||||
loadBrowserURI(browser, url, principal);
|
||||
} else {
|
||||
// Shift to fully loaded browser and make
|
||||
// sure load handler is instantiated.
|
||||
tab.addEventListener(
|
||||
"SSTabRestoring",
|
||||
() => loadBrowserURI(browser, url, principal),
|
||||
{ once: true }
|
||||
);
|
||||
gBrowser._insertBrowser(tab);
|
||||
}
|
||||
} else {
|
||||
unchangedRemoteness.push(tab);
|
||||
}
|
||||
}
|
||||
|
||||
if (!unchangedRemoteness.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset temporary permissions on the remaining tabs to reload.
|
||||
// This is done here because we only want to reset
|
||||
// permissions on user reload.
|
||||
for (const tab of unchangedRemoteness) {
|
||||
SitePermissions.clearTemporaryBlockPermissions(tab.linkedBrowser);
|
||||
// Also reset DOS mitigations for the basic auth prompt on reload.
|
||||
delete tab.linkedBrowser.authPromptAbuseCounter;
|
||||
}
|
||||
gIdentityHandler.hidePopup();
|
||||
gPermissionPanel.hidePopup();
|
||||
|
||||
const handlingUserInput = document.hasValidTransientUserGestureActivation;
|
||||
|
||||
for (const tab of unchangedRemoteness) {
|
||||
if (tab.linkedPanel) {
|
||||
sendReloadMessage(tab);
|
||||
} else {
|
||||
// Shift to fully loaded browser and make
|
||||
// sure load handler is instantiated.
|
||||
tab.addEventListener("SSTabRestoring", () => sendReloadMessage(tab), {
|
||||
once: true,
|
||||
});
|
||||
gBrowser._insertBrowser(tab);
|
||||
}
|
||||
}
|
||||
|
||||
function loadBrowserURI(browser, url, principal) {
|
||||
browser.loadURI(url, {
|
||||
flags: reloadFlags,
|
||||
triggeringPrincipal: principal,
|
||||
});
|
||||
}
|
||||
|
||||
function sendReloadMessage(tab) {
|
||||
tab.linkedBrowser.sendMessageToActor(
|
||||
"Browser:Reload",
|
||||
{ flags: reloadFlags, handlingUserInput },
|
||||
"BrowserTab"
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -69,11 +69,11 @@
|
||||
<observes element="Browser:Forward" attribute="disabled"/>
|
||||
</command>
|
||||
<command id="Browser:Stop" oncommand="BrowserStop();" disabled="true"/>
|
||||
<command id="Browser:Reload" oncommand="if (event.shiftKey) BrowserReloadSkipCache(); else BrowserReload()" disabled="true"/>
|
||||
<command id="Browser:ReloadOrDuplicate" oncommand="BrowserReloadOrDuplicate(event)" disabled="true">
|
||||
<command id="Browser:Reload" oncommand="if (event.shiftKey) BrowserCommands.reloadSkipCache(); else BrowserCommands.reload()" disabled="true"/>
|
||||
<command id="Browser:ReloadOrDuplicate" oncommand="BrowserCommands.reloadOrDuplicate(event)" disabled="true">
|
||||
<observes element="Browser:Reload" attribute="disabled"/>
|
||||
</command>
|
||||
<command id="Browser:ReloadSkipCache" oncommand="BrowserReloadSkipCache()" disabled="true">
|
||||
<command id="Browser:ReloadSkipCache" oncommand="BrowserCommands.reloadSkipCache()" disabled="true">
|
||||
<observes element="Browser:Reload" attribute="disabled"/>
|
||||
</command>
|
||||
<command id="Browser:NextTab" oncommand="gBrowser.tabContainer.advanceSelectedTab(1, true);"/>
|
||||
|
@ -456,7 +456,9 @@ var gIdentityHandler = {
|
||||
);
|
||||
|
||||
// Reload the page with the content unblocked
|
||||
BrowserReloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE);
|
||||
BrowserCommands.reloadWithFlags(
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE
|
||||
);
|
||||
if (this._popupInitialized) {
|
||||
PanelMultiView.hidePopup(this._identityPopup);
|
||||
}
|
||||
@ -475,7 +477,7 @@ var gIdentityHandler = {
|
||||
"mixed-content"
|
||||
);
|
||||
if (reload) {
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
}
|
||||
if (this._popupInitialized) {
|
||||
PanelMultiView.hidePopup(this._identityPopup);
|
||||
@ -496,7 +498,7 @@ var gIdentityHandler = {
|
||||
port,
|
||||
gBrowser.contentPrincipal.originAttributes
|
||||
);
|
||||
BrowserReloadSkipCache();
|
||||
BrowserCommands.reloadSkipCache();
|
||||
if (this._popupInitialized) {
|
||||
PanelMultiView.hidePopup(this._identityPopup);
|
||||
}
|
||||
@ -611,7 +613,7 @@ var gIdentityHandler = {
|
||||
// Because "off" is 1 and "off temporarily" is 2, we can just check if the
|
||||
// sum of newValue and oldValue is 3.
|
||||
if (newValue + oldValue !== 3) {
|
||||
BrowserReloadSkipCache();
|
||||
BrowserCommands.reloadSkipCache();
|
||||
if (this._popupInitialized) {
|
||||
PanelMultiView.hidePopup(this._identityPopup);
|
||||
}
|
||||
|
@ -2190,7 +2190,7 @@ var gProtectionsHandler = {
|
||||
ContentBlockingAllowList.add(gBrowser.selectedBrowser);
|
||||
if (shouldReload) {
|
||||
this._hidePopup();
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
}
|
||||
},
|
||||
|
||||
@ -2198,7 +2198,7 @@ var gProtectionsHandler = {
|
||||
ContentBlockingAllowList.remove(gBrowser.selectedBrowser);
|
||||
if (shouldReload) {
|
||||
this._hidePopup();
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -108,7 +108,7 @@ ChromeUtils.defineLazyGetter(this, "fxAccounts", () => {
|
||||
|
||||
XPCOMUtils.defineLazyScriptGetter(
|
||||
this,
|
||||
"BrowserCommands",
|
||||
["BrowserCommands", "kSkipCacheFlags"],
|
||||
"chrome://browser/content/browser-commands.js"
|
||||
);
|
||||
|
||||
@ -2630,7 +2630,7 @@ function HandleAppCommandEvent(evt) {
|
||||
BrowserCommands.forward();
|
||||
break;
|
||||
case "Reload":
|
||||
BrowserReloadSkipCache();
|
||||
BrowserCommands.reloadSkipCache();
|
||||
break;
|
||||
case "Stop":
|
||||
if (XULBrowserWindow.stopCommand.getAttribute("disabled") != "true") {
|
||||
@ -2681,42 +2681,6 @@ function BrowserStop() {
|
||||
gBrowser.webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL);
|
||||
}
|
||||
|
||||
function BrowserReloadOrDuplicate(aEvent) {
|
||||
aEvent = getRootEvent(aEvent);
|
||||
let accelKeyPressed =
|
||||
AppConstants.platform == "macosx" ? aEvent.metaKey : aEvent.ctrlKey;
|
||||
var backgroundTabModifier = aEvent.button == 1 || accelKeyPressed;
|
||||
|
||||
if (aEvent.shiftKey && !backgroundTabModifier) {
|
||||
BrowserReloadSkipCache();
|
||||
return;
|
||||
}
|
||||
|
||||
let where = whereToOpenLink(aEvent, false, true);
|
||||
if (where == "current") {
|
||||
BrowserReload();
|
||||
} else {
|
||||
duplicateTabIn(gBrowser.selectedTab, where);
|
||||
}
|
||||
}
|
||||
|
||||
function BrowserReload() {
|
||||
if (gBrowser.currentURI.schemeIs("view-source")) {
|
||||
// Bug 1167797: For view source, we always skip the cache
|
||||
return BrowserReloadSkipCache();
|
||||
}
|
||||
const reloadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
BrowserReloadWithFlags(reloadFlags);
|
||||
}
|
||||
|
||||
const kSkipCacheFlags =
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY |
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
||||
function BrowserReloadSkipCache() {
|
||||
// Bypass proxy and cache.
|
||||
BrowserReloadWithFlags(kSkipCacheFlags);
|
||||
}
|
||||
|
||||
function BrowserHome(aEvent) {
|
||||
if (aEvent && "button" in aEvent && aEvent.button == 2) {
|
||||
// right-click: do nothing
|
||||
@ -3415,84 +3379,6 @@ function BrowserFullScreen() {
|
||||
window.fullScreen = !window.fullScreen || BrowserHandler.kiosk;
|
||||
}
|
||||
|
||||
function BrowserReloadWithFlags(reloadFlags) {
|
||||
let unchangedRemoteness = [];
|
||||
|
||||
for (let tab of gBrowser.selectedTabs) {
|
||||
let browser = tab.linkedBrowser;
|
||||
let url = browser.currentURI;
|
||||
let urlSpec = url.spec;
|
||||
// We need to cache the content principal here because the browser will be
|
||||
// reconstructed when the remoteness changes and the content prinicpal will
|
||||
// be cleared after reconstruction.
|
||||
let principal = tab.linkedBrowser.contentPrincipal;
|
||||
if (gBrowser.updateBrowserRemotenessByURL(browser, urlSpec)) {
|
||||
// If the remoteness has changed, the new browser doesn't have any
|
||||
// information of what was loaded before, so we need to load the previous
|
||||
// URL again.
|
||||
if (tab.linkedPanel) {
|
||||
loadBrowserURI(browser, url, principal);
|
||||
} else {
|
||||
// Shift to fully loaded browser and make
|
||||
// sure load handler is instantiated.
|
||||
tab.addEventListener(
|
||||
"SSTabRestoring",
|
||||
() => loadBrowserURI(browser, url, principal),
|
||||
{ once: true }
|
||||
);
|
||||
gBrowser._insertBrowser(tab);
|
||||
}
|
||||
} else {
|
||||
unchangedRemoteness.push(tab);
|
||||
}
|
||||
}
|
||||
|
||||
if (!unchangedRemoteness.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset temporary permissions on the remaining tabs to reload.
|
||||
// This is done here because we only want to reset
|
||||
// permissions on user reload.
|
||||
for (let tab of unchangedRemoteness) {
|
||||
SitePermissions.clearTemporaryBlockPermissions(tab.linkedBrowser);
|
||||
// Also reset DOS mitigations for the basic auth prompt on reload.
|
||||
delete tab.linkedBrowser.authPromptAbuseCounter;
|
||||
}
|
||||
gIdentityHandler.hidePopup();
|
||||
gPermissionPanel.hidePopup();
|
||||
|
||||
let handlingUserInput = document.hasValidTransientUserGestureActivation;
|
||||
|
||||
for (let tab of unchangedRemoteness) {
|
||||
if (tab.linkedPanel) {
|
||||
sendReloadMessage(tab);
|
||||
} else {
|
||||
// Shift to fully loaded browser and make
|
||||
// sure load handler is instantiated.
|
||||
tab.addEventListener("SSTabRestoring", () => sendReloadMessage(tab), {
|
||||
once: true,
|
||||
});
|
||||
gBrowser._insertBrowser(tab);
|
||||
}
|
||||
}
|
||||
|
||||
function loadBrowserURI(browser, url, principal) {
|
||||
browser.loadURI(url, {
|
||||
flags: reloadFlags,
|
||||
triggeringPrincipal: principal,
|
||||
});
|
||||
}
|
||||
|
||||
function sendReloadMessage(tab) {
|
||||
tab.linkedBrowser.sendMessageToActor(
|
||||
"Browser:Reload",
|
||||
{ flags: reloadFlags, handlingUserInput },
|
||||
"BrowserTab"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: can we pull getPEMString in from pippki.js instead of
|
||||
// duplicating them here?
|
||||
function getPEMString(cert) {
|
||||
@ -7224,7 +7110,9 @@ function handleDroppedLink(
|
||||
|
||||
function BrowserForceEncodingDetection() {
|
||||
gBrowser.selectedBrowser.forceEncodingDetection();
|
||||
BrowserReloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
|
||||
BrowserCommands.reloadWithFlags(
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE
|
||||
);
|
||||
}
|
||||
|
||||
var ToolbarContextMenu = {
|
||||
|
@ -34,10 +34,7 @@
|
||||
"HandleAppCommandEvent",
|
||||
"BrowserCommands",
|
||||
"BrowserStop",
|
||||
"BrowserReloadOrDuplicate",
|
||||
"BrowserReload",
|
||||
"kSkipCacheFlags",
|
||||
"BrowserReloadSkipCache",
|
||||
"BrowserHome",
|
||||
"loadOneOrMoreURIs",
|
||||
"openLocation",
|
||||
@ -58,7 +55,6 @@
|
||||
"getMeOutOfHere",
|
||||
"getDefaultHomePage",
|
||||
"BrowserFullScreen",
|
||||
"BrowserReloadWithFlags",
|
||||
"getPEMString",
|
||||
"browserDragAndDrop",
|
||||
"homeButtonObserver",
|
||||
|
@ -544,7 +544,7 @@ add_task(async function checkViewSource() {
|
||||
certOverrideService.clearValidityOverride("expired.example.com", -1, {});
|
||||
|
||||
loaded = BrowserTestUtils.waitForErrorPage(browser);
|
||||
BrowserReloadSkipCache();
|
||||
BrowserCommands.reloadSkipCache();
|
||||
await loaded;
|
||||
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
|
@ -41,7 +41,7 @@ add_task(async function testTempPermissionOnReload() {
|
||||
reloaded = BrowserTestUtils.browserLoaded(browser, false, origin);
|
||||
|
||||
// Reload as a user (should remove the temp permission).
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
|
||||
await reloaded;
|
||||
|
||||
|
@ -159,7 +159,7 @@ add_task(async function process_switching_through_navigation_features() {
|
||||
assertIsPrivilegedProcess(browser, "new tab opened from about:newtab");
|
||||
|
||||
// Check that reload does not break the privileged about: content process affinity.
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
await BrowserTestUtils.browserLoaded(browser, false, ABOUT_NEWTAB);
|
||||
assertIsPrivilegedProcess(browser, "about:newtab after reload");
|
||||
|
||||
|
@ -140,7 +140,7 @@ add_task(async function process_switching_through_navigation_features() {
|
||||
);
|
||||
|
||||
// Check that reload does not break the privileged mozilla content process affinity.
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
await BrowserTestUtils.browserLoaded(browser, false, TEST_HIGH1);
|
||||
is(
|
||||
browser.frameLoader.remoteTab.osPid,
|
||||
|
@ -515,7 +515,7 @@ add_task(async function () {
|
||||
gInvalidFormPopup,
|
||||
"popuphidden"
|
||||
);
|
||||
BrowserReloadSkipCache();
|
||||
BrowserCommands.reloadSkipCache();
|
||||
await popupHiddenPromise;
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
|
@ -17,7 +17,7 @@ add_task(async function () {
|
||||
ok(true, "The initial message is displayed in the console");
|
||||
// Create a promise for the message logged after the reload.
|
||||
const onMessage = waitForMessageByType(hud, loggedString, ".console-api");
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
await onMessage;
|
||||
ok(true, "The message is also displayed after a page reload");
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ add_task(async function test_backAndReload() {
|
||||
await BrowserTestUtils.browserStopped(browser);
|
||||
|
||||
info("Reload.");
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
await BrowserTestUtils.waitForLocationChange(gBrowser);
|
||||
|
||||
is(browser.documentURI.spec, DUMMY);
|
||||
|
@ -20,7 +20,7 @@ add_task(async function test_beforeUnload_and_replaceState() {
|
||||
browser,
|
||||
"pageshow"
|
||||
);
|
||||
BrowserReload();
|
||||
BrowserCommands.reload();
|
||||
await awaitPageShow;
|
||||
|
||||
let updatedState = await SpecialPowers.spawn(browser, [], () => {
|
||||
|
@ -162,7 +162,7 @@ async function loadPageAndReload(testCase) {
|
||||
}
|
||||
);
|
||||
is(true, hasInteractedWith, "Simulated successfully user interaction");
|
||||
BrowserReloadWithFlags(testCase.reloadFlag);
|
||||
BrowserCommands.reloadWithFlags(testCase.reloadFlag);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
is(true, true, `reload with flag ${testCase.name} was successful`);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ async function reloadBrowser(browser, url) {
|
||||
let reloaded = BrowserTestUtils.browserLoaded(browser, false, url);
|
||||
|
||||
// Reload as a user.
|
||||
window.BrowserReload();
|
||||
window.BrowserCommands.reload();
|
||||
|
||||
await reloaded;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user