Bug 1697928 - Select process for about:reader based on article URI, r=annyG

Differential Revision: https://phabricator.services.mozilla.com/D108864
This commit is contained in:
Nika Layzell 2021-05-03 21:30:10 +00:00
Родитель 49eb472b16
Коммит 8e887cbfda
3 изменённых файлов: 126 добавлений и 0 удалений

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

@ -41,3 +41,6 @@ support-files =
readerModeArticle.html
readerModeArticleShort.html
readerModeArticleMedium.html
[browser_readerMode_remoteType.js]
support-files =
readerModeArticleShort.html

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

@ -0,0 +1,87 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const TEST_PATH = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://example.com"
);
const CROSS_SITE_TEST_PATH = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://example.org"
);
/**
* Test that switching an article into readermode doesn't change its' remoteType.
* Test that the reader mode correctly calculates and displays the
* estimated reading time for a short article
*/
add_task(async function() {
info("opening readermode normally to ensure process doesn't change");
let articleRemoteType;
let aboutReaderURL;
await BrowserTestUtils.withNewTab(
TEST_PATH + "readerModeArticleShort.html",
async function(browser) {
articleRemoteType = browser.remoteType;
// Click on the readermode button to switch into reader mode, and get the
// URL for that reader mode.
let pageShownPromise = BrowserTestUtils.waitForContentEvent(
browser,
"AboutReaderContentReady"
);
let readerButton = document.getElementById("reader-mode-button");
readerButton.click();
await pageShownPromise;
aboutReaderURL = browser.documentURI.spec;
ok(
aboutReaderURL.startsWith("about:reader"),
"about:reader should have been opened"
);
is(
browser.remoteType,
articleRemoteType,
"remote type should not have changed"
);
}
);
info(
"opening new tab directly with about reader URL into correct remote type"
);
await BrowserTestUtils.withNewTab(aboutReaderURL, async function(browser) {
is(
browser.remoteType,
articleRemoteType,
"Should have performed about:reader load in the correct remote type"
);
});
info("navigating process into correct remote type");
await BrowserTestUtils.withNewTab(
CROSS_SITE_TEST_PATH + "readerModeArticleShort.html",
async function(browser) {
if (SpecialPowers.useRemoteSubframes) {
isnot(
browser.remoteType,
articleRemoteType,
"Cross-site article should have different remote type with fission"
);
}
BrowserTestUtils.loadURI(browser, aboutReaderURL);
await BrowserTestUtils.browserLoaded(browser);
is(
browser.remoteType,
articleRemoteType,
"Should have switched into the correct remote type"
);
}
);
});

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

@ -82,6 +82,16 @@ function getAboutModule(aURL) {
}
}
function getOriginalReaderModeURI(aURI) {
try {
let searchParams = new URLSearchParams(aURI.query);
if (searchParams.has("url")) {
return Services.io.newURI(searchParams.get("url"));
}
} catch (e) {}
return null;
}
const NOT_REMOTE = null;
// These must match any similar ones in ContentParent.h and ProcInfo.h
@ -474,6 +484,32 @@ var E10SUtils = {
) {
return PRIVILEGEDABOUT_REMOTE_TYPE;
}
// When loading about:reader, try to display the document in the same
// web remote type as the document it's loading.
if (aURI.filePath == "reader") {
let readerModeURI = getOriginalReaderModeURI(aURI);
if (readerModeURI) {
let innerRemoteType = this.getRemoteTypeForURIObject(
readerModeURI,
aMultiProcess,
aRemoteSubframes,
aPreferredRemoteType,
aCurrentUri,
null, // aResultPrincipal
aIsSubframe,
aIsWorker,
aOriginAttributes
);
if (
innerRemoteType &&
innerRemoteType.startsWith(WEB_REMOTE_TYPE)
) {
return innerRemoteType;
}
}
}
return DEFAULT_REMOTE_TYPE;
}