Skip to content

Commit 43b91e6

Browse files
authored
browser(firefox): implelemt timezone overrides (#1577)
1 parent d130479 commit 43b91e6

File tree

2 files changed

+79
-20
lines changed

2 files changed

+79
-20
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1063
1+
1064

browser_patches/firefox/patches/bootstrap.diff

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,47 +138,57 @@ index 040c7b124dec6bb254563bbe74fe50012cb077a3..b4e6b8132786af70e8ad0dce88b67c28
138138
const transportProvider = {
139139
setListener(upgradeListener) {
140140
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
141-
index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890b657c675 100644
141+
index 514a4f2890a20558afe0d9c1aec697612fc8e873..4be480a4ec0e397c6c9a1d695a1faf381af414d1 100644
142142
--- a/docshell/base/nsDocShell.cpp
143143
+++ b/docshell/base/nsDocShell.cpp
144-
@@ -15,6 +15,12 @@
144+
@@ -15,6 +15,14 @@
145145
# include <unistd.h> // for getpid()
146146
#endif
147147

148148
+#if JS_HAS_INTL_API && !MOZ_SYSTEM_ICU
149149
+# include "unicode/locid.h"
150+
+# include "unicode/timezone.h"
151+
+# include "unicode/unistr.h"
150152
+#endif /* JS_HAS_INTL_API && !MOZ_SYSTEM_ICU */
151153
+
152154
+#include "js/LocaleSensitive.h"
153155
+
154156
#include "mozilla/ArrayUtils.h"
155157
#include "mozilla/Attributes.h"
156158
#include "mozilla/AutoRestore.h"
157-
@@ -53,6 +59,7 @@
159+
@@ -53,6 +61,7 @@
158160
#include "mozilla/dom/ContentFrameMessageManager.h"
159161
#include "mozilla/dom/DocGroup.h"
160162
#include "mozilla/dom/Element.h"
161163
+#include "mozilla/dom/Geolocation.h"
162164
#include "mozilla/dom/HTMLAnchorElement.h"
163165
#include "mozilla/dom/PerformanceNavigation.h"
164166
#include "mozilla/dom/PermissionMessageUtils.h"
165-
@@ -71,6 +78,7 @@
167+
@@ -71,6 +80,7 @@
166168
#include "mozilla/dom/nsCSPContext.h"
167169
#include "mozilla/dom/LoadURIOptionsBinding.h"
168170
#include "mozilla/dom/JSWindowActorChild.h"
169171
+#include "mozilla/dom/WorkerCommon.h"
170172

171173
#include "mozilla/net/DocumentChannel.h"
172174
#include "mozilla/net/DocumentChannelChild.h"
173-
@@ -96,6 +104,7 @@
175+
@@ -96,6 +106,7 @@
174176
#include "nsIDocShellTreeItem.h"
175177
#include "nsIDocShellTreeOwner.h"
176178
#include "mozilla/dom/Document.h"
177179
+#include "mozilla/dom/Element.h"
178180
#include "nsIDocumentLoaderFactory.h"
179181
#include "nsIDOMWindow.h"
180182
#include "nsIEditingSession.h"
181-
@@ -350,6 +359,9 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
183+
@@ -183,6 +194,7 @@
184+
#include "nsGlobalWindow.h"
185+
#include "nsISearchService.h"
186+
#include "nsJSEnvironment.h"
187+
+#include "nsJSUtils.h"
188+
#include "nsNetCID.h"
189+
#include "nsNetUtil.h"
190+
#include "nsObjectLoadingContent.h"
191+
@@ -350,6 +362,9 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
182192
mUseErrorPages(false),
183193
mObserveErrorPages(true),
184194
mCSSErrorReportingEnabled(false),
@@ -188,15 +198,15 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890
188198
mAllowAuth(mItemType == typeContent),
189199
mAllowKeywordFixup(false),
190200
mIsOffScreenBrowser(false),
191-
@@ -1219,6 +1231,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
201+
@@ -1219,6 +1234,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
192202
isSubFrame = mLSHE->GetIsSubFrame();
193203
}
194204

195205
+ FireOnFrameLocationChange(this, aRequest, aURI, aLocationFlags);
196206
if (!isSubFrame && !isRoot) {
197207
/*
198208
* We don't want to send OnLocationChange notifications when
199-
@@ -3340,6 +3353,131 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
209+
@@ -3340,6 +3356,162 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
200210
return NS_OK;
201211
}
202212

@@ -262,6 +272,37 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890
262272
+}
263273
+
264274
+NS_IMETHODIMP
275+
+nsDocShell::OverrideTimezone(const nsAString& aTimezoneOverride, bool* aSuccess) {
276+
+ NS_ENSURE_ARG(aSuccess);
277+
+
278+
+ // Validate timezone id.
279+
+ UniquePtr<icu::TimeZone> timezone(icu::TimeZone::createTimeZone(
280+
+ icu::UnicodeString(NS_LossyConvertUTF16toASCII(aTimezoneOverride).get(), -1, US_INV)));
281+
+ if (!timezone || *timezone == icu::TimeZone::getUnknown()) {
282+
+ fprintf(stderr, "Invalid timezone id: %s\n", NS_LossyConvertUTF16toASCII(aTimezoneOverride).get());
283+
+ *aSuccess = false;
284+
+ return NS_OK;
285+
+ }
286+
+
287+
+ // The env variable is read by js::DateTimeInfo::internalResyncICUDefaultTimeZone()
288+
+ auto setTimeZoneEnv = [](const char* value) {
289+
+#if defined(_WIN32)
290+
+ return _putenv_s("TZ", value) == 0;
291+
+#else
292+
+ return setenv("TZ", value, true) == 0;
293+
+#endif /* _WIN32 */
294+
+ };
295+
+
296+
+ *aSuccess = setTimeZoneEnv(NS_LossyConvertUTF16toASCII(aTimezoneOverride).get());
297+
+ if (*aSuccess) {
298+
+ nsJSUtils::ResetTimeZone();
299+
+ } else {
300+
+ fprintf(stderr, "Failed to change timezone to '%s'\n", NS_LossyConvertUTF16toASCII(aTimezoneOverride).get());
301+
+ }
302+
+ return NS_OK;
303+
+}
304+
+
305+
+NS_IMETHODIMP
265306
+nsDocShell::GetFileInputInterceptionEnabled(bool* aEnabled) {
266307
+ MOZ_ASSERT(aEnabled);
267308
+ *aEnabled = GetRootDocShell()->mFileInputInterceptionEnabled;
@@ -328,7 +369,7 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890
328369
NS_IMETHODIMP
329370
nsDocShell::GetIsNavigating(bool* aOut) {
330371
*aOut = mIsNavigating;
331-
@@ -12137,6 +12275,9 @@ class OnLinkClickEvent : public Runnable {
372+
@@ -12137,6 +12309,9 @@ class OnLinkClickEvent : public Runnable {
332373
mNoOpenerImplied, nullptr, nullptr,
333374
mIsUserTriggered, mTriggeringPrincipal, mCsp);
334375
}
@@ -338,7 +379,7 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890
338379
return NS_OK;
339380
}
340381

341-
@@ -12226,6 +12367,9 @@ nsresult nsDocShell::OnLinkClick(
382+
@@ -12226,6 +12401,9 @@ nsresult nsDocShell::OnLinkClick(
342383
this, aContent, aURI, target, aFileName, aPostDataStream,
343384
aHeadersDataStream, noOpenerImplied, aIsUserTriggered, aIsTrusted,
344385
aTriggeringPrincipal, aCsp);
@@ -405,7 +446,7 @@ index cc88045201371eb2195a28c60fcd3b6d940e8b72..7fad3529cc7a22b0b2aa8d8cb5ebbb58
405446
bool mAllowKeywordFixup : 1;
406447
bool mIsOffScreenBrowser : 1;
407448
diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl
408-
index ee89208c3ada6da09ecda6147e1a372ee0562810..83a70dd59a22abd391f9b2db99837e3e5851db31 100644
449+
index ee89208c3ada6da09ecda6147e1a372ee0562810..ce8d31365b5190ac2c974100a6ec6408c53681d5 100644
409450
--- a/docshell/base/nsIDocShell.idl
410451
+++ b/docshell/base/nsIDocShell.idl
411452
@@ -44,6 +44,7 @@ interface nsIURI;
@@ -416,7 +457,7 @@ index ee89208c3ada6da09ecda6147e1a372ee0562810..83a70dd59a22abd391f9b2db99837e3e
416457
interface nsIDocShellLoadInfo;
417458
interface nsIEditor;
418459
interface nsIEditingSession;
419-
@@ -1129,4 +1130,19 @@ interface nsIDocShell : nsIDocShellTreeItem
460+
@@ -1129,4 +1130,21 @@ interface nsIDocShell : nsIDocShellTreeItem
420461
* @see nsISHEntry synchronizeLayoutHistoryState().
421462
*/
422463
void synchronizeLayoutHistoryState();
@@ -427,6 +468,8 @@ index ee89208c3ada6da09ecda6147e1a372ee0562810..83a70dd59a22abd391f9b2db99837e3e
427468
+
428469
+ attribute AString languageOverride;
429470
+
471+
+ boolean overrideTimezone(in AString timezoneId);
472+
+
430473
+ cenum OnlineOverride: 8 {
431474
+ ONLINE_OVERRIDE_NONE = 0,
432475
+ ONLINE_OVERRIDE_ONLINE = 1,
@@ -1953,10 +1996,10 @@ index 0000000000000000000000000000000000000000..ba34976ad05e7f5f1a99777f76ac08b1
19531996
+this.SimpleChannel = SimpleChannel;
19541997
diff --git a/juggler/TargetRegistry.js b/juggler/TargetRegistry.js
19551998
new file mode 100644
1956-
index 0000000000000000000000000000000000000000..98d00f70a61787e31c5ae58310fd86312f3d0dcf
1999+
index 0000000000000000000000000000000000000000..dcf03385589acc29c7fe0f02f912d40ab7efb76f
19572000
--- /dev/null
19582001
+++ b/juggler/TargetRegistry.js
1959-
@@ -0,0 +1,471 @@
2002+
@@ -0,0 +1,479 @@
19602003
+const {EventEmitter} = ChromeUtils.import('resource://gre/modules/EventEmitter.jsm');
19612004
+const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
19622005
+const {SimpleChannel} = ChromeUtils.import('chrome://juggler/content/SimpleChannel.js');
@@ -2048,6 +2091,10 @@ index 0000000000000000000000000000000000000000..98d00f70a61787e31c5ae58310fd8631
20482091
+ this._mainWindow.gBrowser.selectedTab = tab;
20492092
+ const target = this._tabToTarget.get(tab);
20502093
+ await target._contentReadyPromise;
2094+
+ if (browserContext.options.timezoneId) {
2095+
+ if (await target.hasFailedToOverrideTimezone())
2096+
+ throw new Error('Failed to override timezone');
2097+
+ }
20512098
+ return target.id();
20522099
+ }
20532100
+
@@ -2249,6 +2296,10 @@ index 0000000000000000000000000000000000000000..98d00f70a61787e31c5ae58310fd8631
22492296
+ await this._channel.connect('').send('setOnlineOverride', override).catch(e => void e);
22502297
+ }
22512298
+
2299+
+ async hasFailedToOverrideTimezone() {
2300+
+ return await this._channel.connect('').send('hasFailedToOverrideTimezone').catch(e => true);
2301+
+ }
2302+
+
22522303
+ dispose() {
22532304
+ this._disposed = true;
22542305
+ if (this._browserContext)
@@ -4840,10 +4891,10 @@ index 0000000000000000000000000000000000000000..3a386425d3796d0a6786dea193b3402d
48404891
+
48414892
diff --git a/juggler/content/main.js b/juggler/content/main.js
48424893
new file mode 100644
4843-
index 0000000000000000000000000000000000000000..b1f66264a97a0ca24fe29fb8a04e3ea2f5ec9eeb
4894+
index 0000000000000000000000000000000000000000..1864328a47107621309c9b3726bb84535b780c2f
48444895
--- /dev/null
48454896
+++ b/juggler/content/main.js
4846-
@@ -0,0 +1,146 @@
4897+
@@ -0,0 +1,153 @@
48474898
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
48484899
+const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
48494900
+const {FrameTree} = ChromeUtils.import('chrome://juggler/content/content/FrameTree.js');
@@ -4908,8 +4959,11 @@ index 0000000000000000000000000000000000000000..b1f66264a97a0ca24fe29fb8a04e3ea2
49084959
+ response = { sessionIds: [], browserContextOptions: {}, waitForInitialNavigation: false };
49094960
+
49104961
+ const { sessionIds, browserContextOptions, waitForInitialNavigation } = response;
4911-
+ const { userAgent, bypassCSP, javaScriptDisabled, viewport, scriptsToEvaluateOnNewDocument, bindings, locale, geolocation, onlineOverride } = browserContextOptions;
4962+
+ const { userAgent, bypassCSP, javaScriptDisabled, viewport, scriptsToEvaluateOnNewDocument, bindings, locale, timezoneId, geolocation, onlineOverride } = browserContextOptions;
49124963
+
4964+
+ let failedToOverrideTimezone = false;
4965+
+ if (timezoneId)
4966+
+ failedToOverrideTimezone = !docShell.overrideTimezone(timezoneId);
49134967
+ if (userAgent !== undefined)
49144968
+ docShell.browsingContext.customUserAgent = userAgent;
49154969
+ if (bypassCSP !== undefined)
@@ -4970,6 +5024,10 @@ index 0000000000000000000000000000000000000000..b1f66264a97a0ca24fe29fb8a04e3ea2
49705024
+ // noop, just a rountrip.
49715025
+ },
49725026
+
5027+
+ hasFailedToOverrideTimezone() {
5028+
+ return failedToOverrideTimezone;
5029+
+ },
5030+
+
49735031
+ dispose() {
49745032
+ },
49755033
+ });
@@ -6075,10 +6133,10 @@ index 0000000000000000000000000000000000000000..78b6601b91d0b7fcda61114e6846aa07
60756133
+this.EXPORTED_SYMBOLS = ['t', 'checkScheme'];
60766134
diff --git a/juggler/protocol/Protocol.js b/juggler/protocol/Protocol.js
60776135
new file mode 100644
6078-
index 0000000000000000000000000000000000000000..67df4d5592d66e0db3c7c120ad12f9b360b9c45d
6136+
index 0000000000000000000000000000000000000000..4028ed2f4c87e869da15103e936f85e887d769a1
60796137
--- /dev/null
60806138
+++ b/juggler/protocol/Protocol.js
6081-
@@ -0,0 +1,778 @@
6139+
@@ -0,0 +1,779 @@
60826140
+const {t, checkScheme} = ChromeUtils.import('chrome://juggler/content/protocol/PrimitiveTypes.js');
60836141
+
60846142
+// Protocol-specific types.
@@ -6294,6 +6352,7 @@ index 0000000000000000000000000000000000000000..67df4d5592d66e0db3c7c120ad12f9b3
62946352
+ javaScriptDisabled: t.Optional(t.Boolean),
62956353
+ viewport: t.Optional(pageTypes.Viewport),
62966354
+ locale: t.Optional(t.String),
6355+
+ timezoneId: t.Optional(t.String),
62976356
+ },
62986357
+ returns: {
62996358
+ browserContextId: t.String,

0 commit comments

Comments
 (0)