Skip to content

Commit 549a37b

Browse files
browser(firefox): fix color scheme not updating until reload (#3157)
1 parent 415e94f commit 549a37b

File tree

3 files changed

+35
-61
lines changed

3 files changed

+35
-61
lines changed

browser_patches/firefox/BUILD_NUMBER

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1140
2-
Changed: [email protected] Thu Jul 23 17:44:30 PDT 2020
1+
1141
2+
Changed: [email protected] Fri 24 Jul 2020 03:10:49 PM PDT

browser_patches/firefox/juggler/content/FrameTree.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,29 @@ class FrameTree {
142142
}
143143

144144
setColorScheme(colorScheme) {
145-
const docShell = this._mainFrame._docShell;
145+
if (this._emulatedColorScheme === colorScheme) {
146+
return;
147+
}
148+
149+
let internalColorScheme;
146150
switch (colorScheme) {
147-
case 'light': docShell.colorSchemeOverride = Ci.nsIDocShell.COLOR_SCHEME_OVERRIDE_LIGHT; break;
148-
case 'dark': docShell.colorSchemeOverride = Ci.nsIDocShell.COLOR_SCHEME_OVERRIDE_DARK; break;
149-
case 'no-preference': docShell.colorSchemeOverride = Ci.nsIDocShell.COLOR_SCHEME_OVERRIDE_NO_PREFERENCE; break;
150-
default: docShell.colorSchemeOverride = Ci.nsIDocShell.COLOR_SCHEME_OVERRIDE_NONE; break;
151+
case "light":
152+
internalColorScheme = Ci.nsIContentViewer.PREFERS_COLOR_SCHEME_LIGHT;
153+
break;
154+
case "dark":
155+
internalColorScheme = Ci.nsIContentViewer.PREFERS_COLOR_SCHEME_DARK;
156+
break;
157+
case "no-preference":
158+
internalColorScheme =
159+
Ci.nsIContentViewer.PREFERS_COLOR_SCHEME_NO_PREFERENCE;
160+
break;
161+
default:
162+
internalColorScheme = Ci.nsIContentViewer.PREFERS_COLOR_SCHEME_NONE;
151163
}
164+
165+
this._emulatedColorScheme = colorScheme;
166+
const docShell = this._mainFrame._docShell;
167+
docShell.contentViewer.emulatePrefersColorScheme(internalColorScheme);
152168
}
153169

154170
frameForDocShell(docShell) {

browser_patches/firefox/patches/bootstrap.diff

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ index 040c7b124dec6bb254563bbe74fe50012cb077a3..b4e6b8132786af70e8ad0dce88b67c28
139139
const transportProvider = {
140140
setListener(upgradeListener) {
141141
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
142-
index 2424029f2783fe2af012f033c75c497b3c493bd6..56b0aa8f51798666f80cdfce5ace18260185c6ee 100644
142+
index 2424029f2783fe2af012f033c75c497b3c493bd6..3960ade9382cf43fe542ed52668f70ffcf3ba974 100644
143143
--- a/docshell/base/nsDocShell.cpp
144144
+++ b/docshell/base/nsDocShell.cpp
145145
@@ -15,6 +15,12 @@
@@ -187,27 +187,26 @@ index 2424029f2783fe2af012f033c75c497b3c493bd6..56b0aa8f51798666f80cdfce5ace1826
187187
#include "nsNetCID.h"
188188
#include "nsNetUtil.h"
189189
#include "nsObjectLoadingContent.h"
190-
@@ -379,6 +389,11 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
190+
@@ -379,6 +389,10 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
191191
mAllowWindowControl(true),
192192
mUseErrorPages(true),
193193
mCSSErrorReportingEnabled(false),
194194
+ mFileInputInterceptionEnabled(false),
195195
+ mOverrideHasFocus(false),
196196
+ mBypassCSPEnabled(false),
197197
+ mOnlineOverride(nsIDocShell::ONLINE_OVERRIDE_NONE),
198-
+ mColorSchemeOverride(COLOR_SCHEME_OVERRIDE_NONE),
199198
mAllowAuth(mItemType == typeContent),
200199
mAllowKeywordFixup(false),
201200
mIsOffScreenBrowser(false),
202-
@@ -1249,6 +1264,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
201+
@@ -1249,6 +1263,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
203202
isSubFrame = mLSHE->GetIsSubFrame();
204203
}
205204

206205
+ FireOnFrameLocationChange(this, aRequest, aURI, aLocationFlags);
207206
if (!isSubFrame && !isRoot) {
208207
/*
209208
* We don't want to send OnLocationChange notifications when
210-
@@ -3079,6 +3095,184 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
209+
@@ -3079,6 +3094,172 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
211210
return NS_OK;
212211
}
213212

@@ -375,24 +374,12 @@ index 2424029f2783fe2af012f033c75c497b3c493bd6..56b0aa8f51798666f80cdfce5ace1826
375374
+ return NS_OK;
376375
+}
377376
+
378-
+NS_IMETHODIMP
379-
+nsDocShell::GetColorSchemeOverride(ColorSchemeOverride* aColorSchemeOverride) {
380-
+ *aColorSchemeOverride = GetRootDocShell()->mColorSchemeOverride;
381-
+ return NS_OK;
382-
+}
383-
+
384-
+NS_IMETHODIMP
385-
+nsDocShell::SetColorSchemeOverride(ColorSchemeOverride aColorSchemeOverride) {
386-
+ mColorSchemeOverride = aColorSchemeOverride;
387-
+ return NS_OK;
388-
+}
389-
+
390377
+// =============== Juggler End =======================
391378
+
392379
NS_IMETHODIMP
393380
nsDocShell::GetIsNavigating(bool* aOut) {
394381
*aOut = mIsNavigating;
395-
@@ -8195,6 +8389,12 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState,
382+
@@ -8195,6 +8376,12 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState,
396383
true, // aForceNoOpener
397384
getter_AddRefs(newBC));
398385
MOZ_ASSERT(!newBC);
@@ -405,7 +392,7 @@ index 2424029f2783fe2af012f033c75c497b3c493bd6..56b0aa8f51798666f80cdfce5ace1826
405392
return rv;
406393
}
407394

408-
@@ -11698,6 +11898,9 @@ class OnLinkClickEvent : public Runnable {
395+
@@ -11698,6 +11885,9 @@ class OnLinkClickEvent : public Runnable {
409396
mNoOpenerImplied, nullptr, nullptr,
410397
mIsUserTriggered, mTriggeringPrincipal, mCsp);
411398
}
@@ -415,7 +402,7 @@ index 2424029f2783fe2af012f033c75c497b3c493bd6..56b0aa8f51798666f80cdfce5ace1826
415402
return NS_OK;
416403
}
417404

418-
@@ -11787,6 +11990,8 @@ nsresult nsDocShell::OnLinkClick(
405+
@@ -11787,6 +11977,8 @@ nsresult nsDocShell::OnLinkClick(
419406
this, aContent, aURI, target, aFileName, aPostDataStream,
420407
aHeadersDataStream, noOpenerImplied, aIsUserTriggered, aIsTrusted,
421408
aTriggeringPrincipal, aCsp);
@@ -425,7 +412,7 @@ index 2424029f2783fe2af012f033c75c497b3c493bd6..56b0aa8f51798666f80cdfce5ace1826
425412
}
426413

427414
diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h
428-
index dcffed8e55371a4f0aeae408de3a94e4e3a9ab95..5f6b2243ac054f414573736fc23b75509b2a8f5b 100644
415+
index dcffed8e55371a4f0aeae408de3a94e4e3a9ab95..d680dc0c0bd7ccc20ab37760e9b5e5d8450498a1 100644
429416
--- a/docshell/base/nsDocShell.h
430417
+++ b/docshell/base/nsDocShell.h
431418
@@ -13,6 +13,7 @@
@@ -469,7 +456,7 @@ index dcffed8e55371a4f0aeae408de3a94e4e3a9ab95..5f6b2243ac054f414573736fc23b7550
469456
// Handles retrieval of subframe session history for nsDocShell::LoadURI. If a
470457
// load is requested in a subframe of the current DocShell, the subframe
471458
// loadType may need to reflect the loadType of the parent document, or in
472-
@@ -1262,6 +1275,14 @@ class nsDocShell final : public nsDocLoader,
459+
@@ -1262,6 +1275,13 @@ class nsDocShell final : public nsDocLoader,
473460
bool mAllowWindowControl : 1;
474461
bool mUseErrorPages : 1;
475462
bool mCSSErrorReportingEnabled : 1;
@@ -479,13 +466,12 @@ index dcffed8e55371a4f0aeae408de3a94e4e3a9ab95..5f6b2243ac054f414573736fc23b7550
479466
+ nsString mLanguageOverride;
480467
+ RefPtr<nsGeolocationService> mGeolocationServiceOverride;
481468
+ OnlineOverride mOnlineOverride;
482-
+ ColorSchemeOverride mColorSchemeOverride;
483469
+
484470
bool mAllowAuth : 1;
485471
bool mAllowKeywordFixup : 1;
486472
bool mIsOffScreenBrowser : 1;
487473
diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl
488-
index 01dc4734eb191adf6572b9b628b4682eda017e19..0929fa0c324d5bc6e09a9d71ac4d8f4fbacca946 100644
474+
index 01dc4734eb191adf6572b9b628b4682eda017e19..85e83db8cb45356b86e83f0edf9ff680cb9abc4e 100644
489475
--- a/docshell/base/nsIDocShell.idl
490476
+++ b/docshell/base/nsIDocShell.idl
491477
@@ -44,6 +44,7 @@ interface nsIURI;
@@ -496,7 +482,7 @@ index 01dc4734eb191adf6572b9b628b4682eda017e19..0929fa0c324d5bc6e09a9d71ac4d8f4f
496482
interface nsIDocShellLoadInfo;
497483
interface nsIEditor;
498484
interface nsIEditingSession;
499-
@@ -1010,6 +1011,33 @@ interface nsIDocShell : nsIDocShellTreeItem
485+
@@ -1010,6 +1011,25 @@ interface nsIDocShell : nsIDocShellTreeItem
500486
*/
501487
void synchronizeLayoutHistoryState();
502488

@@ -517,21 +503,13 @@ index 01dc4734eb191adf6572b9b628b4682eda017e19..0929fa0c324d5bc6e09a9d71ac4d8f4f
517503
+ };
518504
+ [infallible] attribute nsIDocShell_OnlineOverride onlineOverride;
519505
+
520-
+ cenum ColorSchemeOverride : 8 {
521-
+ COLOR_SCHEME_OVERRIDE_LIGHT,
522-
+ COLOR_SCHEME_OVERRIDE_DARK,
523-
+ COLOR_SCHEME_OVERRIDE_NO_PREFERENCE,
524-
+ COLOR_SCHEME_OVERRIDE_NONE, /* This clears the override. */
525-
+ };
526-
+ [infallible] attribute nsIDocShell_ColorSchemeOverride colorSchemeOverride;
527-
+
528506
+ void setGeolocationOverride(in nsIDOMGeoPosition position);
529507
+
530508
/**
531509
* This attempts to save any applicable layout history state (like
532510
* scroll position) in the nsISHEntry. This is normally done
533511
diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp
534-
index 3ea8d9829cbfb59e7095a21ff53993cb7716e9f2..b882a58f17a701cbced7b38f959a40e9e964b96a 100644
512+
index 3ea8d9829cbfb59e7095a21ff53993cb7716e9f2..61e83179c27c715a1dcf9d70a76f1710fd884a00 100644
535513
--- a/dom/base/Document.cpp
536514
+++ b/dom/base/Document.cpp
537515
@@ -3216,6 +3216,9 @@ void Document::SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages) {
@@ -567,26 +545,6 @@ index 3ea8d9829cbfb59e7095a21ff53993cb7716e9f2..b882a58f17a701cbced7b38f959a40e9
567545
// Is there a focused DOMWindow?
568546
nsCOMPtr<mozIDOMWindowProxy> focusedWindow;
569547
fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
570-
@@ -16322,6 +16334,19 @@ void Document::RemoveToplevelLoadingDocument(Document* aDoc) {
571-
572-
StylePrefersColorScheme Document::PrefersColorScheme(
573-
IgnoreRFP aIgnoreRFP) const {
574-
+ auto* docShell = static_cast<nsDocShell*>(GetDocShell());
575-
+ nsIDocShell::ColorSchemeOverride colorScheme;
576-
+ if (docShell->GetColorSchemeOverride(&colorScheme) == NS_OK &&
577-
+ colorScheme != nsIDocShell::COLOR_SCHEME_OVERRIDE_NONE) {
578-
+ switch (colorScheme) {
579-
+ case nsIDocShell::COLOR_SCHEME_OVERRIDE_LIGHT:
580-
+ return StylePrefersColorScheme::Light;
581-
+ case nsIDocShell::COLOR_SCHEME_OVERRIDE_DARK:
582-
+ return StylePrefersColorScheme::Dark;
583-
+ case nsIDocShell::COLOR_SCHEME_OVERRIDE_NO_PREFERENCE:
584-
+ return StylePrefersColorScheme::NoPreference;
585-
+ };
586-
+ }
587-
if (aIgnoreRFP == IgnoreRFP::No &&
588-
nsContentUtils::ShouldResistFingerprinting(this)) {
589-
return StylePrefersColorScheme::Light;
590548
diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp
591549
index aa3fa6719f05a1aeb45f03f85a7e169d42f96bb8..4f3131229fe053a2b125327839fc64178fc15b62 100644
592550
--- a/dom/base/Navigator.cpp

0 commit comments

Comments
 (0)