@@ -138,7 +138,7 @@ index 040c7b124dec6bb254563bbe74fe50012cb077a3..b4e6b8132786af70e8ad0dce88b67c28
138
138
const transportProvider = {
139
139
setListener(upgradeListener) {
140
140
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
141
- index 514a4f2890a20558afe0d9c1aec697612fc8e873..a013080177ee2c49342db2cda869b10a698482f4 100644
141
+ index 514a4f2890a20558afe0d9c1aec697612fc8e873..8d16217833c15ee3611be913646c77fc440473e5 100644
142
142
--- a/docshell/base/nsDocShell.cpp
143
143
+++ b/docshell/base/nsDocShell.cpp
144
144
@@ -15,6 +15,12 @@
@@ -186,25 +186,26 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..a013080177ee2c49342db2cda869b10a
186
186
#include "nsNetCID.h"
187
187
#include "nsNetUtil.h"
188
188
#include "nsObjectLoadingContent.h"
189
- @@ -350,6 +360,9 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
189
+ @@ -350,6 +360,10 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
190
190
mUseErrorPages(false),
191
191
mObserveErrorPages(true),
192
192
mCSSErrorReportingEnabled(false),
193
193
+ mFileInputInterceptionEnabled(false),
194
194
+ mBypassCSPEnabled(false),
195
195
+ mOnlineOverride(nsIDocShell::ONLINE_OVERRIDE_NONE),
196
+ + mColorSchemeOverride(COLOR_SCHEME_OVERRIDE_NONE),
196
197
mAllowAuth(mItemType == typeContent),
197
198
mAllowKeywordFixup(false),
198
199
mIsOffScreenBrowser(false),
199
- @@ -1219,6 +1232 ,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
200
+ @@ -1219,6 +1233 ,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
200
201
isSubFrame = mLSHE->GetIsSubFrame();
201
202
}
202
203
203
204
+ FireOnFrameLocationChange(this, aRequest, aURI, aLocationFlags);
204
205
if (!isSubFrame && !isRoot) {
205
206
/*
206
207
* We don't want to send OnLocationChange notifications when
207
- @@ -3340,6 +3354,155 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
208
+ @@ -3340,6 +3355,167 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
208
209
return NS_OK;
209
210
}
210
211
@@ -355,12 +356,24 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..a013080177ee2c49342db2cda869b10a
355
356
+ return NS_OK;
356
357
+ }
357
358
+
359
+ + NS_IMETHODIMP
360
+ + nsDocShell::GetColorSchemeOverride(ColorSchemeOverride* aColorSchemeOverride) {
361
+ + *aColorSchemeOverride = GetRootDocShell()->mColorSchemeOverride;
362
+ + return NS_OK;
363
+ + }
364
+ +
365
+ + NS_IMETHODIMP
366
+ + nsDocShell::SetColorSchemeOverride(ColorSchemeOverride aColorSchemeOverride) {
367
+ + mColorSchemeOverride = aColorSchemeOverride;
368
+ + return NS_OK;
369
+ + }
370
+ +
358
371
+ // =============== Juggler End =======================
359
372
+
360
373
NS_IMETHODIMP
361
374
nsDocShell::GetIsNavigating(bool* aOut) {
362
375
*aOut = mIsNavigating;
363
- @@ -12137,6 +12300 ,9 @@ class OnLinkClickEvent : public Runnable {
376
+ @@ -12137,6 +12313 ,9 @@ class OnLinkClickEvent : public Runnable {
364
377
mNoOpenerImplied, nullptr, nullptr,
365
378
mIsUserTriggered, mTriggeringPrincipal, mCsp);
366
379
}
@@ -370,7 +383,7 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..a013080177ee2c49342db2cda869b10a
370
383
return NS_OK;
371
384
}
372
385
373
- @@ -12226,6 +12392 ,9 @@ nsresult nsDocShell::OnLinkClick(
386
+ @@ -12226,6 +12405 ,9 @@ nsresult nsDocShell::OnLinkClick(
374
387
this, aContent, aURI, target, aFileName, aPostDataStream,
375
388
aHeadersDataStream, noOpenerImplied, aIsUserTriggered, aIsTrusted,
376
389
aTriggeringPrincipal, aCsp);
@@ -381,7 +394,7 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..a013080177ee2c49342db2cda869b10a
381
394
}
382
395
383
396
diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h
384
- index cc88045201371eb2195a28c60fcd3b6d940e8b72..7fad3529cc7a22b0b2aa8d8cb5ebbb5814aa2490 100644
397
+ index cc88045201371eb2195a28c60fcd3b6d940e8b72..2ea1e4825849c3bf42d0ab2c06a73ce79363922a 100644
385
398
--- a/docshell/base/nsDocShell.h
386
399
+++ b/docshell/base/nsDocShell.h
387
400
@@ -13,6 +13,7 @@
@@ -423,7 +436,7 @@ index cc88045201371eb2195a28c60fcd3b6d940e8b72..7fad3529cc7a22b0b2aa8d8cb5ebbb58
423
436
// Handles retrieval of subframe session history for nsDocShell::LoadURI. If a
424
437
// load is requested in a subframe of the current DocShell, the subframe
425
438
// loadType may need to reflect the loadType of the parent document, or in
426
- @@ -1292,6 +1303,12 @@ class nsDocShell final : public nsDocLoader,
439
+ @@ -1292,6 +1303,13 @@ class nsDocShell final : public nsDocLoader,
427
440
bool mUseErrorPages : 1;
428
441
bool mObserveErrorPages : 1;
429
442
bool mCSSErrorReportingEnabled : 1;
@@ -432,12 +445,13 @@ index cc88045201371eb2195a28c60fcd3b6d940e8b72..7fad3529cc7a22b0b2aa8d8cb5ebbb58
432
445
+ nsString mLanguageOverride;
433
446
+ RefPtr<nsGeolocationService> mGeolocationServiceOverride;
434
447
+ OnlineOverride mOnlineOverride;
448
+ + ColorSchemeOverride mColorSchemeOverride;
435
449
+
436
450
bool mAllowAuth : 1;
437
451
bool mAllowKeywordFixup : 1;
438
452
bool mIsOffScreenBrowser : 1;
439
453
diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl
440
- index ee89208c3ada6da09ecda6147e1a372ee0562810..ce8d31365b5190ac2c974100a6ec6408c53681d5 100644
454
+ index ee89208c3ada6da09ecda6147e1a372ee0562810..1d3156f00f193bd9c1173a1326a1cb140efcf7b5 100644
441
455
--- a/docshell/base/nsIDocShell.idl
442
456
+++ b/docshell/base/nsIDocShell.idl
443
457
@@ -44,6 +44,7 @@ interface nsIURI;
@@ -448,7 +462,7 @@ index ee89208c3ada6da09ecda6147e1a372ee0562810..ce8d31365b5190ac2c974100a6ec6408
448
462
interface nsIDocShellLoadInfo;
449
463
interface nsIEditor;
450
464
interface nsIEditingSession;
451
- @@ -1129,4 +1130,21 @@ interface nsIDocShell : nsIDocShellTreeItem
465
+ @@ -1129,4 +1130,29 @@ interface nsIDocShell : nsIDocShellTreeItem
452
466
* @see nsISHEntry synchronizeLayoutHistoryState().
453
467
*/
454
468
void synchronizeLayoutHistoryState();
@@ -468,10 +482,18 @@ index ee89208c3ada6da09ecda6147e1a372ee0562810..ce8d31365b5190ac2c974100a6ec6408
468
482
+ };
469
483
+ [infallible] attribute nsIDocShell_OnlineOverride onlineOverride;
470
484
+
485
+ + cenum ColorSchemeOverride : 8 {
486
+ + COLOR_SCHEME_OVERRIDE_LIGHT,
487
+ + COLOR_SCHEME_OVERRIDE_DARK,
488
+ + COLOR_SCHEME_OVERRIDE_NO_PREFERENCE,
489
+ + COLOR_SCHEME_OVERRIDE_NONE, /* This clears the override. */
490
+ + };
491
+ + [infallible] attribute nsIDocShell_ColorSchemeOverride colorSchemeOverride;
492
+ +
471
493
+ void setGeolocationOverride(in nsIDOMGeoPosition position);
472
494
};
473
495
diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp
474
- index bc0aeaefb9ca6d7cd15fc5ad189d2d260d519997..e948a5c20308ad8a9f43b3a53c532ee0cf62950c 100644
496
+ index bc0aeaefb9ca6d7cd15fc5ad189d2d260d519997..c5f649f2b0508028955be4fa9562cfc1370b0a00 100644
475
497
--- a/dom/base/Document.cpp
476
498
+++ b/dom/base/Document.cpp
477
499
@@ -3269,6 +3269,9 @@ void Document::SendToConsole(nsCOMArray<nsISecurityConsoleMessage>& aMessages) {
@@ -496,6 +518,27 @@ index bc0aeaefb9ca6d7cd15fc5ad189d2d260d519997..e948a5c20308ad8a9f43b3a53c532ee0
496
518
// If this is a data document - no need to set CSP.
497
519
if (mLoadedAsData) {
498
520
return NS_OK;
521
+ @@ -16114,6 +16122,20 @@ void Document::RemoveToplevelLoadingDocument(Document* aDoc) {
522
+ }
523
+
524
+ StylePrefersColorScheme Document::PrefersColorScheme() const {
525
+ + auto* docShell = static_cast<nsDocShell*>(GetDocShell());
526
+ + nsIDocShell::ColorSchemeOverride colorScheme;
527
+ + if (docShell->GetColorSchemeOverride(&colorScheme) == NS_OK &&
528
+ + colorScheme != nsIDocShell::COLOR_SCHEME_OVERRIDE_NONE) {
529
+ + switch (colorScheme) {
530
+ + case nsIDocShell::COLOR_SCHEME_OVERRIDE_LIGHT:
531
+ + return StylePrefersColorScheme::Light;
532
+ + case nsIDocShell::COLOR_SCHEME_OVERRIDE_DARK:
533
+ + return StylePrefersColorScheme::Dark;
534
+ + case nsIDocShell::COLOR_SCHEME_OVERRIDE_NO_PREFERENCE:
535
+ + return StylePrefersColorScheme::NoPreference;
536
+ + };
537
+ + }
538
+ +
539
+ if (nsContentUtils::ShouldResistFingerprinting(this)) {
540
+ return StylePrefersColorScheme::Light;
541
+ }
499
542
diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp
500
543
index 1388a20edd594c6799e47ed567edb1f7d9cc9224..549026512c86e1e7e81a200d1c45f2cb58b3fc67 100644
501
544
--- a/dom/base/Navigator.cpp
@@ -2123,10 +2166,10 @@ index 0000000000000000000000000000000000000000..ba34976ad05e7f5f1a99777f76ac08b1
2123
2166
+ this.SimpleChannel = SimpleChannel;
2124
2167
diff --git a/juggler/TargetRegistry.js b/juggler/TargetRegistry.js
2125
2168
new file mode 100644
2126
- index 0000000000000000000000000000000000000000..836b5c537aa322663de78cd35b64f215c4c91abc
2169
+ index 0000000000000000000000000000000000000000..345aa8b0ebbd9d1e8c9c79913bd7ec3fbb1cc768
2127
2170
--- /dev/null
2128
2171
+++ b/juggler/TargetRegistry.js
2129
- @@ -0,0 +1,552 @@
2172
+ @@ -0,0 +1,561 @@
2130
2173
+ const {EventEmitter} = ChromeUtils.import('resource://gre/modules/EventEmitter.jsm');
2131
2174
+ const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
2132
2175
+ const {SimpleChannel} = ChromeUtils.import('chrome://juggler/content/SimpleChannel.js');
@@ -2456,6 +2499,10 @@ index 0000000000000000000000000000000000000000..836b5c537aa322663de78cd35b64f215
2456
2499
+ await this._channel.connect('').send('setOnlineOverride', override).catch(e => void e);
2457
2500
+ }
2458
2501
+
2502
+ + async setColorScheme(colorScheme) {
2503
+ + await this._channel.connect('').send('setColorScheme', colorScheme).catch(e => void e);
2504
+ + }
2505
+ +
2459
2506
+ async hasFailedToOverrideTimezone() {
2460
2507
+ return await this._channel.connect('').send('hasFailedToOverrideTimezone').catch(e => true);
2461
2508
+ }
@@ -2542,6 +2589,11 @@ index 0000000000000000000000000000000000000000..836b5c537aa322663de78cd35b64f215
2542
2589
+ await Promise.all(Array.from(this.pages).map(page => page.setOnlineOverride(override)));
2543
2590
+ }
2544
2591
+
2592
+ + async setColorScheme(colorScheme) {
2593
+ + this.options.colorScheme = colorScheme;
2594
+ + await Promise.all(Array.from(this.pages).map(page => page.setColorScheme(colorScheme)));
2595
+ + }
2596
+ +
2545
2597
+ async grantPermissions(origin, permissions) {
2546
2598
+ this._permissions.set(origin, permissions);
2547
2599
+ const promises = [];
@@ -2796,10 +2848,10 @@ index 0000000000000000000000000000000000000000..268fbc361d8053182bb6c27f626e853d
2796
2848
+
2797
2849
diff --git a/juggler/content/FrameTree.js b/juggler/content/FrameTree.js
2798
2850
new file mode 100644
2799
- index 0000000000000000000000000000000000000000..255d1a842e9646eccc7c7bf8902baf94ef094c0e
2851
+ index 0000000000000000000000000000000000000000..5a1df2837d70531a670163b7c860108895bc9106
2800
2852
--- /dev/null
2801
2853
+++ b/juggler/content/FrameTree.js
2802
- @@ -0,0 +1,452 @@
2854
+ @@ -0,0 +1,462 @@
2803
2855
+ "use strict";
2804
2856
+ const Ci = Components.interfaces;
2805
2857
+ const Cr = Components.results;
@@ -2936,6 +2988,16 @@ index 0000000000000000000000000000000000000000..255d1a842e9646eccc7c7bf8902baf94
2936
2988
+ frame._addBinding(name, script);
2937
2989
+ }
2938
2990
+
2991
+ + setColorScheme(colorScheme) {
2992
+ + const docShell = this._mainFrame._docShell;
2993
+ + switch (colorScheme) {
2994
+ + case 'light': docShell.colorSchemeOverride = Ci.nsIDocShell.COLOR_SCHEME_OVERRIDE_LIGHT; break;
2995
+ + case 'dark': docShell.colorSchemeOverride = Ci.nsIDocShell.COLOR_SCHEME_OVERRIDE_DARK; break;
2996
+ + case 'no-preference': docShell.colorSchemeOverride = Ci.nsIDocShell.COLOR_SCHEME_OVERRIDE_NO_PREFERENCE; break;
2997
+ + default: docShell.colorSchemeOverride = Ci.nsIDocShell.COLOR_SCHEME_OVERRIDE_NONE; break;
2998
+ + }
2999
+ + }
3000
+ +
2939
3001
+ frameForDocShell(docShell) {
2940
3002
+ return this._docShellToFrame.get(docShell) || null;
2941
3003
+ }
@@ -3322,10 +3384,10 @@ index 0000000000000000000000000000000000000000..be70ea364f9534bb3b344f64970366c3
3322
3384
+
3323
3385
diff --git a/juggler/content/PageAgent.js b/juggler/content/PageAgent.js
3324
3386
new file mode 100644
3325
- index 0000000000000000000000000000000000000000..643fcfeb7d1084c2a5eb99031d0f626ebee725f9
3387
+ index 0000000000000000000000000000000000000000..7f1958121f24c5f5360f24d7580ebf1132f91e83
3326
3388
--- /dev/null
3327
3389
+++ b/juggler/content/PageAgent.js
3328
- @@ -0,0 +1,936 @@
3390
+ @@ -0,0 +1,932 @@
3329
3391
+ "use strict";
3330
3392
+ const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
3331
3393
+ const Ci = Components.interfaces;
@@ -3512,11 +3574,7 @@ index 0000000000000000000000000000000000000000..643fcfeb7d1084c2a5eb99031d0f626e
3512
3574
+ cv.stopEmulatingMedium();
3513
3575
+ else if (type)
3514
3576
+ cv.emulateMedium(type);
3515
- + switch (colorScheme) {
3516
- + case 'light': cv.emulatePrefersColorScheme(cv.PREFERS_COLOR_SCHEME_LIGHT); break;
3517
- + case 'dark': cv.emulatePrefersColorScheme(cv.PREFERS_COLOR_SCHEME_DARK); break;
3518
- + case 'no-preference': cv.emulatePrefersColorScheme(cv.PREFERS_COLOR_SCHEME_NO_PREFERENCE); break;
3519
- + }
3577
+ + this._frameTree.setColorScheme(colorScheme);
3520
3578
+ }
3521
3579
+
3522
3580
+ _addScriptToEvaluateOnNewDocument({script, worldName}) {
@@ -5059,10 +5117,10 @@ index 0000000000000000000000000000000000000000..3a386425d3796d0a6786dea193b3402d
5059
5117
+
5060
5118
diff --git a/juggler/content/main.js b/juggler/content/main.js
5061
5119
new file mode 100644
5062
- index 0000000000000000000000000000000000000000..0060f625a8ad10d7f0df121bdc5fcfa8d5d7b336
5120
+ index 0000000000000000000000000000000000000000..40eb01dfb672fdb3e31d03fef83ae3210698b17c
5063
5121
--- /dev/null
5064
5122
+++ b/juggler/content/main.js
5065
- @@ -0,0 +1,156 @@
5123
+ @@ -0,0 +1,162 @@
5066
5124
+ const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
5067
5125
+ const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
5068
5126
+ const {FrameTree} = ChromeUtils.import('chrome://juggler/content/content/FrameTree.js');
@@ -5130,7 +5188,7 @@ index 0000000000000000000000000000000000000000..0060f625a8ad10d7f0df121bdc5fcfa8
5130
5188
+ response = { sessionIds: [], browserContextOptions: {} };
5131
5189
+
5132
5190
+ const { sessionIds, browserContextOptions } = response;
5133
- + const { userAgent, bypassCSP, javaScriptDisabled, viewport, scriptsToEvaluateOnNewDocument, bindings, locale, timezoneId, geolocation, onlineOverride } = browserContextOptions;
5191
+ + const { userAgent, bypassCSP, javaScriptDisabled, viewport, scriptsToEvaluateOnNewDocument, bindings, locale, timezoneId, geolocation, onlineOverride, colorScheme } = browserContextOptions;
5134
5192
+
5135
5193
+ let failedToOverrideTimezone = false;
5136
5194
+ if (timezoneId)
@@ -5155,6 +5213,8 @@ index 0000000000000000000000000000000000000000..0060f625a8ad10d7f0df121bdc5fcfa8
5155
5213
+ }
5156
5214
+
5157
5215
+ frameTree = new FrameTree(docShell);
5216
+ + if (colorScheme !== undefined)
5217
+ + frameTree.setColorScheme(colorScheme);
5158
5218
+ for (const script of scriptsToEvaluateOnNewDocument || [])
5159
5219
+ frameTree.addScriptToEvaluateOnNewDocument(script);
5160
5220
+ for (const { name, script } of bindings || [])
@@ -5191,6 +5251,10 @@ index 0000000000000000000000000000000000000000..0060f625a8ad10d7f0df121bdc5fcfa8
5191
5251
+ setOnlineOverrideInDocShell(override);
5192
5252
+ },
5193
5253
+
5254
+ + setColorScheme(colorScheme) {
5255
+ + frameTree.setColorScheme(colorScheme);
5256
+ + },
5257
+ +
5194
5258
+ ensurePermissions() {
5195
5259
+ // noop, just a rountrip.
5196
5260
+ },
@@ -5298,10 +5362,10 @@ index 0000000000000000000000000000000000000000..bf37558bccc48f4d90eadc971c1eb3e4
5298
5362
+ this.AccessibilityHandler = AccessibilityHandler;
5299
5363
diff --git a/juggler/protocol/BrowserHandler.js b/juggler/protocol/BrowserHandler.js
5300
5364
new file mode 100644
5301
- index 0000000000000000000000000000000000000000..da90d080ac091afa6c75cfc993d8850231e0d41a
5365
+ index 0000000000000000000000000000000000000000..97e88dd582090971d122064b8a131096a317b6be
5302
5366
--- /dev/null
5303
5367
+++ b/juggler/protocol/BrowserHandler.js
5304
- @@ -0,0 +1,185 @@
5368
+ @@ -0,0 +1,189 @@
5305
5369
+ "use strict";
5306
5370
+
5307
5371
+ const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
@@ -5453,6 +5517,10 @@ index 0000000000000000000000000000000000000000..da90d080ac091afa6c75cfc993d88502
5453
5517
+ await this._targetRegistry.browserContextForId(browserContextId).setOnlineOverride(override);
5454
5518
+ }
5455
5519
+
5520
+ + async setColorScheme({browserContextId, colorScheme}) {
5521
+ + await this._targetRegistry.browserContextForId(browserContextId).setColorScheme(colorScheme);
5522
+ + }
5523
+ +
5456
5524
+ async addScriptToEvaluateOnNewDocument({browserContextId, script}) {
5457
5525
+ await this._targetRegistry.browserContextForId(browserContextId).addScriptToEvaluateOnNewDocument(script);
5458
5526
+ }
@@ -6293,10 +6361,10 @@ index 0000000000000000000000000000000000000000..78b6601b91d0b7fcda61114e6846aa07
6293
6361
+ this.EXPORTED_SYMBOLS = ['t', 'checkScheme'];
6294
6362
diff --git a/juggler/protocol/Protocol.js b/juggler/protocol/Protocol.js
6295
6363
new file mode 100644
6296
- index 0000000000000000000000000000000000000000..e5482da00da11c88b278164b148f44c724cb0c89
6364
+ index 0000000000000000000000000000000000000000..6e187212618130bc716a0fd0121ed0dd23d35770
6297
6365
--- /dev/null
6298
6366
+++ b/juggler/protocol/Protocol.js
6299
- @@ -0,0 +1,775 @@
6367
+ @@ -0,0 +1,781 @@
6300
6368
+ const {t, checkScheme} = ChromeUtils.import('chrome://juggler/content/protocol/PrimitiveTypes.js');
6301
6369
+
6302
6370
+ // Protocol-specific types.
@@ -6613,6 +6681,12 @@ index 0000000000000000000000000000000000000000..e5482da00da11c88b278164b148f44c7
6613
6681
+ override: t.Optional(t.Enum(['online', 'offline'])),
6614
6682
+ }
6615
6683
+ },
6684
+ + 'setColorScheme': {
6685
+ + params: {
6686
+ + browserContextId: t.Optional(t.String),
6687
+ + colorScheme: t.Optional(t.Enum(['dark', 'light', 'no-preference'])),
6688
+ + },
6689
+ + },
6616
6690
+ },
6617
6691
+ };
6618
6692
+
0 commit comments