Merge autoland to mozilla-central. a=merge

This commit is contained in:
Marian-Vasile Laza 2022-01-29 23:40:50 +02:00
commit 8a08700a03
9 changed files with 211 additions and 28 deletions

View File

@ -13,6 +13,19 @@ XPCOMUtils.defineLazyModuleGetters(this, {
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
});
// Inherit color scheme overrides from parent window. This is to inherit the
// color scheme of dark themed PBM windows.
{
let openerColorSchemeOverride =
window.opener?.browsingContext?.top.prefersColorSchemeOverride;
if (
openerColorSchemeOverride &&
window.browsingContext == window.browsingContext.top
) {
window.browsingContext.prefersColorSchemeOverride = openerColorSchemeOverride;
}
}
// define a js object to implement nsITreeView
function pageInfoTreeView(treeid, copycol) {
// copycol is the index number for the column that we want to add to

View File

@ -5927,7 +5927,9 @@ nsresult ContentParent::AboutToLoadHttpFtpDocumentForChild(
}
nsCOMPtr<nsIPrincipal> principal;
rv = ssm->GetChannelResultPrincipal(aChannel, getter_AddRefs(principal));
nsCOMPtr<nsIPrincipal> partitionedPrincipal;
rv = ssm->GetChannelResultPrincipals(aChannel, getter_AddRefs(principal),
getter_AddRefs(partitionedPrincipal));
NS_ENSURE_SUCCESS(rv, rv);
// Let the caller know we're going to send main thread IPC for updating
@ -5938,9 +5940,15 @@ nsresult ContentParent::AboutToLoadHttpFtpDocumentForChild(
TransmitBlobURLsForPrincipal(principal);
// Tranmit permissions for both regular and partitioned principal so that the
// content process can get permissions for the partitioned principal. For
// example, the desk-notification permission for a partitioned service worker.
rv = TransmitPermissionsForPrincipal(principal);
NS_ENSURE_SUCCESS(rv, rv);
rv = TransmitPermissionsForPrincipal(partitionedPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
nsLoadFlags newLoadFlags;
aChannel->GetLoadFlags(&newLoadFlags);
if (newLoadFlags & nsIRequest::LOAD_DOCUMENT_NEEDS_COOKIE) {

View File

@ -43,7 +43,8 @@ namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(ReadableByteStreamController)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ReadableByteStreamController,
ReadableStreamController)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mByobRequest, mStream)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mByobRequest, mCancelAlgorithm,
mPullAlgorithm, mStream)
tmp->ClearPendingPullIntos();
tmp->ClearQueue();
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
@ -51,7 +52,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ReadableByteStreamController,
ReadableStreamController)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mByobRequest, mStream)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mByobRequest, mCancelAlgorithm,
mPullAlgorithm, mStream)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(ReadableByteStreamController,

View File

@ -22,9 +22,9 @@
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED(ReadableStreamBYOBReader,
ReadableStreamGenericReader,
mReadIntoRequests)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_INHERITED(ReadableStreamBYOBReader,
ReadableStreamGenericReader,
mReadIntoRequests)
NS_IMPL_ADDREF_INHERITED(ReadableStreamBYOBReader, ReadableStreamGenericReader)
NS_IMPL_RELEASE_INHERITED(ReadableStreamBYOBReader, ReadableStreamGenericReader)
@ -32,11 +32,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ReadableStreamBYOBReader)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_END_INHERITING(ReadableStreamGenericReader)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(ReadableStreamBYOBReader,
ReadableStreamGenericReader)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
JSObject* ReadableStreamBYOBReader::WrapObject(
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
return ReadableStreamBYOBReader_Binding::Wrap(aCx, this, aGivenProto);

View File

@ -30,7 +30,16 @@ ReadableStreamBYOBRequest::~ReadableStreamBYOBRequest() {
mozilla::DropJSObjects(this);
}
NS_IMPL_CYCLE_COLLECTION(ReadableStreamBYOBRequest)
NS_IMPL_CYCLE_COLLECTION_CLASS(ReadableStreamBYOBRequest)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ReadableStreamBYOBRequest)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal, mController)
tmp->mView = nullptr;
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ReadableStreamBYOBRequest)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal, mController)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(ReadableStreamBYOBRequest)
NS_IMPL_CYCLE_COLLECTING_RELEASE(ReadableStreamBYOBRequest)

View File

@ -777,6 +777,11 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
nsCOMPtr<nsIWidget> viewWidget = aView->GetWidget();
viewWidget->SetTransparencyMode(mode);
windowWidget->SetWindowShadowStyle(shadow);
// For macOS, apply color scheme overrides to the top level window widget.
if (auto scheme = aPresContext->GetOverriddenColorScheme()) {
windowWidget->SetColorScheme(scheme);
}
}
if (!aRC) return;

View File

@ -9,12 +9,18 @@
const { BuiltInThemes } = ChromeUtils.import(
"resource:///modules/BuiltInThemes.jsm"
);
const { PromptTestUtils } = ChromeUtils.import(
"resource://testing-common/PromptTestUtils.jsm"
);
const IS_LINUX = AppConstants.platform == "linux";
const LIGHT_THEME_ID = "firefox-compact-light@mozilla.org";
const DARK_THEME_ID = "firefox-compact-dark@mozilla.org";
// This tests opens many chrome windows which is slow on debug builds.
requestLongerTimeout(2);
/**
* Test a window's theme color scheme.
* @param {*} options - Test options.
@ -58,6 +64,40 @@ async function testWindowColorScheme({
}
}
/**
* Match the prefers-color-scheme media query and return the results.
* @param {Object} options
* @param {Window} options.win - If chrome=true, window to test, otherwise
* parent window of the content window to test.
* @param {boolean} options.chrome - If true the media queries will be matched
* against the supplied chrome window. Otherwise they will be matched against
* the content window.
* @returns {Promise<{light: boolean, dark: boolean}>} - Resolves with an
* object of the media query results.
*/
function getPrefersColorSchemeInfo({ win, chrome = false }) {
let fn = async windowObj => {
// If called in the parent, we use the supplied win object. Otherwise use
// the content window global.
let win = windowObj || content;
// LookAndFeel updates are async.
await new Promise(resolve => {
win.requestAnimationFrame(() => win.requestAnimationFrame(resolve));
});
return {
light: win.matchMedia("(prefers-color-scheme: light)").matches,
dark: win.matchMedia("(prefers-color-scheme: dark)").matches,
};
};
if (chrome) {
return fn(win);
}
return SpecialPowers.spawn(win.gBrowser.selectedBrowser, [], fn);
}
add_task(async function setup() {
// Set system theme to light to ensure consistency across test machines.
await SpecialPowers.pushPrefEnv({
@ -113,22 +153,7 @@ add_task(async function test_default_theme_light() {
expectDefaultDarkAttribute: true,
});
let prefersColorScheme = await SpecialPowers.spawn(
pbmWindowA.gBrowser.selectedBrowser,
[],
async () => {
// LookAndFeel updates are async.
await new Promise(resolve => {
content.requestAnimationFrame(() =>
content.requestAnimationFrame(resolve)
);
});
return {
light: content.matchMedia("(prefers-color-scheme: light)").matches,
dark: content.matchMedia("(prefers-color-scheme: dark)").matches,
};
}
);
let prefersColorScheme = await getPrefersColorSchemeInfo({ win: pbmWindowA });
ok(
prefersColorScheme.light && !prefersColorScheme.dark,
"Content of dark themed PBM window should still be themed light"
@ -312,3 +337,101 @@ add_task(async function test_theme_switch_updates_existing_pbm_win() {
await BrowserTestUtils.closeWindow(windowB);
await BrowserTestUtils.closeWindow(pbmWindow);
});
// pageInfo windows should inherit the PBM window dark theme.
add_task(async function test_pbm_dark_page_info() {
for (let isPBM of [false, true]) {
let win = await BrowserTestUtils.openNewBrowserWindow({
private: isPBM,
});
let windowTypeStr = isPBM ? "private" : "normal";
info(`Opening pageInfo from ${windowTypeStr} browsing.`);
await BrowserTestUtils.withNewTab(
{ gBrowser: win.gBrowser, url: "https://example.com" },
async () => {
let pageInfo = win.BrowserPageInfo(null, "securityTab");
await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
let prefersColorScheme = await getPrefersColorSchemeInfo({
win: pageInfo,
chrome: true,
});
if (isPBM) {
ok(
!prefersColorScheme.light && prefersColorScheme.dark,
"pageInfo from private window should be themed dark."
);
} else {
ok(
prefersColorScheme.light && !prefersColorScheme.dark,
"pageInfo from normal window should be themed light."
);
}
pageInfo.close();
}
);
await BrowserTestUtils.closeWindow(win);
}
});
// Prompts should inherit the PBM window dark theme.
add_task(async function test_pbm_dark_prompts() {
const { MODAL_TYPE_TAB, MODAL_TYPE_CONTENT } = Services.prompt;
for (let isPBM of [false, true]) {
let win = await BrowserTestUtils.openNewBrowserWindow({
private: isPBM,
});
// TODO: Once Bug 1751953 has been fixed, we can also test MODAL_TYPE_WINDOW
// here.
for (let modalType of [MODAL_TYPE_TAB, MODAL_TYPE_CONTENT]) {
let windowTypeStr = isPBM ? "private" : "normal";
let modalTypeStr = modalType == MODAL_TYPE_TAB ? "tab" : "content";
info(`Opening ${modalTypeStr} prompt from ${windowTypeStr} browsing.`);
let openPromise = PromptTestUtils.waitForPrompt(
win.gBrowser.selectedBrowser,
{
modalType,
promptType: "alert",
}
);
let promptPromise = Services.prompt.asyncAlert(
win.gBrowser.selectedBrowser.browsingContext,
modalType,
"Hello",
"Hello, world!"
);
let dialog = await openPromise;
let prefersColorScheme = await getPrefersColorSchemeInfo({
win: dialog.ui.prompt,
chrome: true,
});
if (isPBM) {
ok(
!prefersColorScheme.light && prefersColorScheme.dark,
"Prompt from private window should be themed dark."
);
} else {
ok(
prefersColorScheme.light && !prefersColorScheme.dark,
"Prompt from normal window should be themed light."
);
}
await PromptTestUtils.handlePrompt(dialog);
await promptPromise;
}
await BrowserTestUtils.closeWindow(win);
}
});

View File

@ -13,6 +13,19 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var propBag, args, Dialog;
// Inherit color scheme overrides from parent window. This is to inherit the
// color scheme of dark themed PBM windows.
{
let openerColorSchemeOverride =
window.opener?.browsingContext?.top.prefersColorSchemeOverride;
if (
openerColorSchemeOverride &&
window.browsingContext == window.browsingContext.top
) {
window.browsingContext.prefersColorSchemeOverride = openerColorSchemeOverride;
}
}
function commonDialogOnLoad() {
propBag = window.arguments[0]
.QueryInterface(Ci.nsIWritablePropertyBag2)

View File

@ -270,6 +270,21 @@ LightweightThemeConsumer.prototype = {
return true;
})();
// If this is a per-window dark theme, set the color scheme override so
// child BrowsingContexts, such as embedded prompts, get themed
// appropriately.
// If not, reset the color scheme override field. This is required to reset
// the color scheme on theme switch.
if (
useDarkTheme &&
!updateGlobalThemeData &&
this._win.browsingContext == this._win.browsingContext.top
) {
this._win.browsingContext.prefersColorSchemeOverride = "dark";
} else {
this._win.browsingContext.prefersColorSchemeOverride = "none";
}
let theme = useDarkTheme ? themeData.darkTheme : themeData.theme;
if (!theme) {
theme = { id: DEFAULT_THEME_ID };