Skip to content

Commit

Permalink
browser(firefox): implelemt timezone overrides (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Mar 30, 2020
1 parent d130479 commit 43b91e6
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 20 deletions.
2 changes: 1 addition & 1 deletion browser_patches/firefox/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1063
1064
97 changes: 78 additions & 19 deletions browser_patches/firefox/patches/bootstrap.diff
Original file line number Diff line number Diff line change
Expand Up @@ -138,47 +138,57 @@ index 040c7b124dec6bb254563bbe74fe50012cb077a3..b4e6b8132786af70e8ad0dce88b67c28
const transportProvider = {
setListener(upgradeListener) {
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890b657c675 100644
index 514a4f2890a20558afe0d9c1aec697612fc8e873..4be480a4ec0e397c6c9a1d695a1faf381af414d1 100644
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -15,6 +15,12 @@
@@ -15,6 +15,14 @@
# include <unistd.h> // for getpid()
#endif

+#if JS_HAS_INTL_API && !MOZ_SYSTEM_ICU
+# include "unicode/locid.h"
+# include "unicode/timezone.h"
+# include "unicode/unistr.h"
+#endif /* JS_HAS_INTL_API && !MOZ_SYSTEM_ICU */
+
+#include "js/LocaleSensitive.h"
+
#include "mozilla/ArrayUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/AutoRestore.h"
@@ -53,6 +59,7 @@
@@ -53,6 +61,7 @@
#include "mozilla/dom/ContentFrameMessageManager.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/Element.h"
+#include "mozilla/dom/Geolocation.h"
#include "mozilla/dom/HTMLAnchorElement.h"
#include "mozilla/dom/PerformanceNavigation.h"
#include "mozilla/dom/PermissionMessageUtils.h"
@@ -71,6 +78,7 @@
@@ -71,6 +80,7 @@
#include "mozilla/dom/nsCSPContext.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/dom/JSWindowActorChild.h"
+#include "mozilla/dom/WorkerCommon.h"

#include "mozilla/net/DocumentChannel.h"
#include "mozilla/net/DocumentChannelChild.h"
@@ -96,6 +104,7 @@
@@ -96,6 +106,7 @@
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
#include "mozilla/dom/Document.h"
+#include "mozilla/dom/Element.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIDOMWindow.h"
#include "nsIEditingSession.h"
@@ -350,6 +359,9 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
@@ -183,6 +194,7 @@
#include "nsGlobalWindow.h"
#include "nsISearchService.h"
#include "nsJSEnvironment.h"
+#include "nsJSUtils.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsObjectLoadingContent.h"
@@ -350,6 +362,9 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
mUseErrorPages(false),
mObserveErrorPages(true),
mCSSErrorReportingEnabled(false),
Expand All @@ -188,15 +198,15 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890
mAllowAuth(mItemType == typeContent),
mAllowKeywordFixup(false),
mIsOffScreenBrowser(false),
@@ -1219,6 +1231,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
@@ -1219,6 +1234,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
isSubFrame = mLSHE->GetIsSubFrame();
}

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

Expand Down Expand Up @@ -262,6 +272,37 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890
+}
+
+NS_IMETHODIMP
+nsDocShell::OverrideTimezone(const nsAString& aTimezoneOverride, bool* aSuccess) {
+ NS_ENSURE_ARG(aSuccess);
+
+ // Validate timezone id.
+ UniquePtr<icu::TimeZone> timezone(icu::TimeZone::createTimeZone(
+ icu::UnicodeString(NS_LossyConvertUTF16toASCII(aTimezoneOverride).get(), -1, US_INV)));
+ if (!timezone || *timezone == icu::TimeZone::getUnknown()) {
+ fprintf(stderr, "Invalid timezone id: %s\n", NS_LossyConvertUTF16toASCII(aTimezoneOverride).get());
+ *aSuccess = false;
+ return NS_OK;
+ }
+
+ // The env variable is read by js::DateTimeInfo::internalResyncICUDefaultTimeZone()
+ auto setTimeZoneEnv = [](const char* value) {
+#if defined(_WIN32)
+ return _putenv_s("TZ", value) == 0;
+#else
+ return setenv("TZ", value, true) == 0;
+#endif /* _WIN32 */
+ };
+
+ *aSuccess = setTimeZoneEnv(NS_LossyConvertUTF16toASCII(aTimezoneOverride).get());
+ if (*aSuccess) {
+ nsJSUtils::ResetTimeZone();
+ } else {
+ fprintf(stderr, "Failed to change timezone to '%s'\n", NS_LossyConvertUTF16toASCII(aTimezoneOverride).get());
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDocShell::GetFileInputInterceptionEnabled(bool* aEnabled) {
+ MOZ_ASSERT(aEnabled);
+ *aEnabled = GetRootDocShell()->mFileInputInterceptionEnabled;
Expand Down Expand Up @@ -328,7 +369,7 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890
NS_IMETHODIMP
nsDocShell::GetIsNavigating(bool* aOut) {
*aOut = mIsNavigating;
@@ -12137,6 +12275,9 @@ class OnLinkClickEvent : public Runnable {
@@ -12137,6 +12309,9 @@ class OnLinkClickEvent : public Runnable {
mNoOpenerImplied, nullptr, nullptr,
mIsUserTriggered, mTriggeringPrincipal, mCsp);
}
Expand All @@ -338,7 +379,7 @@ index 514a4f2890a20558afe0d9c1aec697612fc8e873..44b48f306cb6c67264edbb2eaa49c890
return NS_OK;
}

@@ -12226,6 +12367,9 @@ nsresult nsDocShell::OnLinkClick(
@@ -12226,6 +12401,9 @@ nsresult nsDocShell::OnLinkClick(
this, aContent, aURI, target, aFileName, aPostDataStream,
aHeadersDataStream, noOpenerImplied, aIsUserTriggered, aIsTrusted,
aTriggeringPrincipal, aCsp);
Expand Down Expand Up @@ -405,7 +446,7 @@ index cc88045201371eb2195a28c60fcd3b6d940e8b72..7fad3529cc7a22b0b2aa8d8cb5ebbb58
bool mAllowKeywordFixup : 1;
bool mIsOffScreenBrowser : 1;
diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl
index ee89208c3ada6da09ecda6147e1a372ee0562810..83a70dd59a22abd391f9b2db99837e3e5851db31 100644
index ee89208c3ada6da09ecda6147e1a372ee0562810..ce8d31365b5190ac2c974100a6ec6408c53681d5 100644
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -44,6 +44,7 @@ interface nsIURI;
Expand All @@ -416,7 +457,7 @@ index ee89208c3ada6da09ecda6147e1a372ee0562810..83a70dd59a22abd391f9b2db99837e3e
interface nsIDocShellLoadInfo;
interface nsIEditor;
interface nsIEditingSession;
@@ -1129,4 +1130,19 @@ interface nsIDocShell : nsIDocShellTreeItem
@@ -1129,4 +1130,21 @@ interface nsIDocShell : nsIDocShellTreeItem
* @see nsISHEntry synchronizeLayoutHistoryState().
*/
void synchronizeLayoutHistoryState();
Expand All @@ -427,6 +468,8 @@ index ee89208c3ada6da09ecda6147e1a372ee0562810..83a70dd59a22abd391f9b2db99837e3e
+
+ attribute AString languageOverride;
+
+ boolean overrideTimezone(in AString timezoneId);
+
+ cenum OnlineOverride: 8 {
+ ONLINE_OVERRIDE_NONE = 0,
+ ONLINE_OVERRIDE_ONLINE = 1,
Expand Down Expand Up @@ -1953,10 +1996,10 @@ index 0000000000000000000000000000000000000000..ba34976ad05e7f5f1a99777f76ac08b1
+this.SimpleChannel = SimpleChannel;
diff --git a/juggler/TargetRegistry.js b/juggler/TargetRegistry.js
new file mode 100644
index 0000000000000000000000000000000000000000..98d00f70a61787e31c5ae58310fd86312f3d0dcf
index 0000000000000000000000000000000000000000..dcf03385589acc29c7fe0f02f912d40ab7efb76f
--- /dev/null
+++ b/juggler/TargetRegistry.js
@@ -0,0 +1,471 @@
@@ -0,0 +1,479 @@
+const {EventEmitter} = ChromeUtils.import('resource://gre/modules/EventEmitter.jsm');
+const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
+const {SimpleChannel} = ChromeUtils.import('chrome://juggler/content/SimpleChannel.js');
Expand Down Expand Up @@ -2048,6 +2091,10 @@ index 0000000000000000000000000000000000000000..98d00f70a61787e31c5ae58310fd8631
+ this._mainWindow.gBrowser.selectedTab = tab;
+ const target = this._tabToTarget.get(tab);
+ await target._contentReadyPromise;
+ if (browserContext.options.timezoneId) {
+ if (await target.hasFailedToOverrideTimezone())
+ throw new Error('Failed to override timezone');
+ }
+ return target.id();
+ }
+
Expand Down Expand Up @@ -2249,6 +2296,10 @@ index 0000000000000000000000000000000000000000..98d00f70a61787e31c5ae58310fd8631
+ await this._channel.connect('').send('setOnlineOverride', override).catch(e => void e);
+ }
+
+ async hasFailedToOverrideTimezone() {
+ return await this._channel.connect('').send('hasFailedToOverrideTimezone').catch(e => true);
+ }
+
+ dispose() {
+ this._disposed = true;
+ if (this._browserContext)
Expand Down Expand Up @@ -4840,10 +4891,10 @@ index 0000000000000000000000000000000000000000..3a386425d3796d0a6786dea193b3402d
+
diff --git a/juggler/content/main.js b/juggler/content/main.js
new file mode 100644
index 0000000000000000000000000000000000000000..b1f66264a97a0ca24fe29fb8a04e3ea2f5ec9eeb
index 0000000000000000000000000000000000000000..1864328a47107621309c9b3726bb84535b780c2f
--- /dev/null
+++ b/juggler/content/main.js
@@ -0,0 +1,146 @@
@@ -0,0 +1,153 @@
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
+const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');
+const {FrameTree} = ChromeUtils.import('chrome://juggler/content/content/FrameTree.js');
Expand Down Expand Up @@ -4908,8 +4959,11 @@ index 0000000000000000000000000000000000000000..b1f66264a97a0ca24fe29fb8a04e3ea2
+ response = { sessionIds: [], browserContextOptions: {}, waitForInitialNavigation: false };
+
+ const { sessionIds, browserContextOptions, waitForInitialNavigation } = response;
+ const { userAgent, bypassCSP, javaScriptDisabled, viewport, scriptsToEvaluateOnNewDocument, bindings, locale, geolocation, onlineOverride } = browserContextOptions;
+ const { userAgent, bypassCSP, javaScriptDisabled, viewport, scriptsToEvaluateOnNewDocument, bindings, locale, timezoneId, geolocation, onlineOverride } = browserContextOptions;
+
+ let failedToOverrideTimezone = false;
+ if (timezoneId)
+ failedToOverrideTimezone = !docShell.overrideTimezone(timezoneId);
+ if (userAgent !== undefined)
+ docShell.browsingContext.customUserAgent = userAgent;
+ if (bypassCSP !== undefined)
Expand Down Expand Up @@ -4970,6 +5024,10 @@ index 0000000000000000000000000000000000000000..b1f66264a97a0ca24fe29fb8a04e3ea2
+ // noop, just a rountrip.
+ },
+
+ hasFailedToOverrideTimezone() {
+ return failedToOverrideTimezone;
+ },
+
+ dispose() {
+ },
+ });
Expand Down Expand Up @@ -6075,10 +6133,10 @@ index 0000000000000000000000000000000000000000..78b6601b91d0b7fcda61114e6846aa07
+this.EXPORTED_SYMBOLS = ['t', 'checkScheme'];
diff --git a/juggler/protocol/Protocol.js b/juggler/protocol/Protocol.js
new file mode 100644
index 0000000000000000000000000000000000000000..67df4d5592d66e0db3c7c120ad12f9b360b9c45d
index 0000000000000000000000000000000000000000..4028ed2f4c87e869da15103e936f85e887d769a1
--- /dev/null
+++ b/juggler/protocol/Protocol.js
@@ -0,0 +1,778 @@
@@ -0,0 +1,779 @@
+const {t, checkScheme} = ChromeUtils.import('chrome://juggler/content/protocol/PrimitiveTypes.js');
+
+// Protocol-specific types.
Expand Down Expand Up @@ -6294,6 +6352,7 @@ index 0000000000000000000000000000000000000000..67df4d5592d66e0db3c7c120ad12f9b3
+ javaScriptDisabled: t.Optional(t.Boolean),
+ viewport: t.Optional(pageTypes.Viewport),
+ locale: t.Optional(t.String),
+ timezoneId: t.Optional(t.String),
+ },
+ returns: {
+ browserContextId: t.String,
Expand Down

0 comments on commit 43b91e6

Please sign in to comment.