Skip to content

Commit

Permalink
Bug 1846500 - Inherit color scheme override from opener. r=pbz
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Aug 8, 2023
1 parent 37b4c74 commit 4742795
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 47 deletions.
14 changes: 0 additions & 14 deletions browser/base/content/pageinfo/pageInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ ChromeUtils.defineESModuleGetters(this, {
E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs",
});

// 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
Expand Down
23 changes: 23 additions & 0 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
MOZ_DIAGNOSTIC_ASSERT(aOpener->mType == aType);
fields.Get<IDX_OpenerId>() = aOpener->Id();
fields.Get<IDX_HadOriginalOpener>() = true;

if (aType == Type::Chrome && !aParent) {
// See SetOpener for why we do this inheritance.
fields.Get<IDX_PrefersColorSchemeOverride>() =
aOpener->Top()->GetPrefersColorSchemeOverride();
}
}

if (aParent) {
Expand Down Expand Up @@ -1076,6 +1082,23 @@ bool BrowsingContext::IsTargetable() const {
return !GetClosed() && AncestorsAreCurrent();
}

void BrowsingContext::SetOpener(BrowsingContext* aOpener) {
MOZ_DIAGNOSTIC_ASSERT(!aOpener || aOpener->Group() == Group());
MOZ_DIAGNOSTIC_ASSERT(!aOpener || aOpener->mType == mType);

MOZ_ALWAYS_SUCCEEDS(SetOpenerId(aOpener ? aOpener->Id() : 0));

if (IsChrome() && IsTop() && aOpener) {
// Inherit color scheme overrides from parent window. This is to inherit the
// color scheme of dark themed PBM windows in dialogs opened by such
// windows.
auto openerOverride = aOpener->Top()->PrefersColorSchemeOverride();
if (openerOverride != PrefersColorSchemeOverride()) {
MOZ_ALWAYS_SUCCEEDS(SetPrefersColorSchemeOverride(openerOverride));
}
}
}

bool BrowsingContext::HasOpener() const {
return sBrowsingContexts->Contains(GetOpenerId());
}
Expand Down
8 changes: 1 addition & 7 deletions docshell/base/BrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
}
return nullptr;
}
void SetOpener(BrowsingContext* aOpener) {
MOZ_DIAGNOSTIC_ASSERT(!aOpener || aOpener->Group() == Group());
MOZ_DIAGNOSTIC_ASSERT(!aOpener || aOpener->mType == mType);

MOZ_ALWAYS_SUCCEEDS(SetOpenerId(aOpener ? aOpener->Id() : 0));
}

void SetOpener(BrowsingContext* aOpener);
bool HasOpener() const;

bool HadOriginalOpener() const { return GetHadOriginalOpener(); }
Expand Down
14 changes: 0 additions & 14 deletions toolkit/components/prompts/content/commonDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@ const { CommonDialog } = ChromeUtils.importESModule(

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)
Expand Down
12 changes: 0 additions & 12 deletions toolkit/profile/content/createProfileWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ var gProfileDisplay;

// Called once when the wizard is opened.
function initWizard() {
// 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;
}

try {
gProfileService = C[ToolkitProfileService].getService(
I.nsIToolkitProfileService
Expand Down

0 comments on commit 4742795

Please sign in to comment.