Skip to content

Commit

Permalink
Bug 1818604 - unbreak loading files using 'open file' in the layout d…
Browse files Browse the repository at this point in the history
…ebugger, r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D174240
  • Loading branch information
gijsk committed Mar 31, 2023
1 parent ff14122 commit 473e2d3
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions layout/tools/layout-debug/ui/content/layoutdebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ function OnLDBLoad() {
if (gArgs.url) {
// Switch to the right kind of content process, and wait a bit so that
// the profiler has had a chance to attach to it.
updateBrowserRemotenessByURL(gArgs.url);
setTimeout(() => fixupAndLoadURIString(gArgs.url), 3000);
loadStringURI(gArgs.url, { delayLoad: 3000 });
return;
}
} else {
Expand All @@ -369,7 +368,7 @@ function OnLDBLoad() {
gDebugger._pagedMode = gArgs.paged;

if (gArgs.url) {
fixupAndLoadURIString(gArgs.url);
loadStringURI(gArgs.url);
}

// Some command line arguments may toggle menu items. Call this after
Expand Down Expand Up @@ -452,22 +451,21 @@ function openFile() {
fp.fileURL.spec &&
fp.fileURL.spec.length > 0
) {
gBrowser.loadURI(fp.fileURL);
loadURIObject(fp.fileURL);
}
});
}

// A simplified version of the function with the same name in tabbrowser.js.
function updateBrowserRemotenessByURL(aURL) {
let oa = E10SUtils.predictOriginAttributes({ browser: gBrowser });
let remoteType = E10SUtils.getRemoteTypeForURI(
aURL,
gMultiProcessBrowser,
gFissionBrowser,
gBrowser.remoteType,
gBrowser.currentURI,
oa
);
let remoteType = E10SUtils.getRemoteTypeForURIObject(aURL, {
multiProcess: gMultiProcessBrowser,
remoteSubFrames: gFissionBrowser,
preferredRemoteType: gBrowser.remoteType,
currentURI: gBrowser.currentURI,
originAttributes: oa,
});
if (gBrowser.remoteType != remoteType) {
gDebugger.detachBrowser();
if (remoteType == E10SUtils.NOT_REMOTE) {
Expand All @@ -483,11 +481,30 @@ function updateBrowserRemotenessByURL(aURL) {
}
}

function fixupAndLoadURIString(aURL) {
function loadStringURI(aURLString, aOptions) {
let realURL;
try {
realURL = Services.uriFixup.getFixupURIInfo(aURLString).preferredURI;
} catch (ex) {
alert(
"Couldn't work out how to create a URL from input: " +
aURLString.substring(0, 100)
);
return;
}
return loadURIObject(realURL, aOptions);
}

async function loadURIObject(aURL, { delayLoad } = {}) {
// We don't bother trying to handle navigations within the browser to new URLs
// that should be loaded in a different process.
updateBrowserRemotenessByURL(aURL);
gBrowser.fixupAndLoadURIString(aURL, {
// When attaching the profiler we may want to delay the actual load a bit
// after switching remoteness.
if (delayLoad) {
await new Promise(r => setTimeout(r, delayLoad));
}
gBrowser.loadURI(aURL, {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
}
Expand All @@ -498,6 +515,6 @@ function focusURLBar() {
}

function go() {
fixupAndLoadURIString(gURLBar.value);
loadStringURI(gURLBar.value);
gBrowser.focus();
}

0 comments on commit 473e2d3

Please sign in to comment.