From 9df9dc137ce952a2eaecd3051a493b4bee112689 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 30 Jan 2020 23:05:01 -0800 Subject: [PATCH] browser(webkit): introduce Browser.setLanguage --- browser_patches/webkit/BUILD_NUMBER | 2 +- browser_patches/webkit/patches/bootstrap.diff | 67 ++++++++++++++++--- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER index 3ff08f7287305..6f2c5fa6d9b97 100644 --- a/browser_patches/webkit/BUILD_NUMBER +++ b/browser_patches/webkit/BUILD_NUMBER @@ -1 +1 @@ -1128 +1129 diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diff index 31fb55b0bea5e..8ba55502cb7e2 100644 --- a/browser_patches/webkit/patches/bootstrap.diff +++ b/browser_patches/webkit/patches/bootstrap.diff @@ -359,10 +359,10 @@ index 1eb7abb2fa21d7a8ec0833160f53e5c523ec4317..7709bcc2ec69aab0589ca1b954db1fb2 FrontendChannel::ConnectionType connectionType() const; diff --git a/Source/JavaScriptCore/inspector/protocol/Browser.json b/Source/JavaScriptCore/inspector/protocol/Browser.json new file mode 100644 -index 0000000000000000000000000000000000000000..b9ac6ebfb1ba16f83663f3fbe29e619ba2befe13 +index 0000000000000000000000000000000000000000..efd406f0a6b7aa0e1e484665cbe863f1233524dd --- /dev/null +++ b/Source/JavaScriptCore/inspector/protocol/Browser.json -@@ -0,0 +1,202 @@ +@@ -0,0 +1,210 @@ +{ + "domain": "Browser", + "availability": ["web"], @@ -539,6 +539,14 @@ index 0000000000000000000000000000000000000000..b9ac6ebfb1ba16f83663f3fbe29e619b + { "name": "browserContextId", "$ref": "ContextID", "optional": true, "description": "Browser context id." } + ], + "description": "Clears permission overrides." ++ }, ++ { ++ "name": "setLanguage", ++ "description": "Allows to set locale language for context.", ++ "parameters": [ ++ { "name": "language", "type": "string" }, ++ { "name": "browserContextId", "$ref": "ContextID", "optional": true, "description": "Browser context id." } ++ ] + } + ], + "events": [ @@ -7371,10 +7379,10 @@ index 78caedf0c0ce83675569502d150fcc44e5f9868c..46b9901263286eab6de0bc4f899349d5 } // namespace WebKit diff --git a/Source/WebKit/UIProcess/InspectorBrowserAgent.cpp b/Source/WebKit/UIProcess/InspectorBrowserAgent.cpp new file mode 100644 -index 0000000000000000000000000000000000000000..d8dbb6391594955a23a5ed3cb34b05ca0b47acc1 +index 0000000000000000000000000000000000000000..3a945691c06155bdcfe8d6928447c3dcb047f686 --- /dev/null +++ b/Source/WebKit/UIProcess/InspectorBrowserAgent.cpp -@@ -0,0 +1,497 @@ +@@ -0,0 +1,505 @@ +/* + * Copyright (C) 2019 Microsoft Corporation. + * @@ -7812,6 +7820,14 @@ index 0000000000000000000000000000000000000000..d8dbb6391594955a23a5ed3cb34b05ca + } +} + ++void InspectorBrowserAgent::setLanguage(Inspector::ErrorString& errorString, const String& language, const String* browserContextID) ++{ ++ BrowserContext browserContext = lookupBrowserContext(errorString, browserContextID); ++ if (!errorString.isEmpty()) ++ return; ++ browserContext.processPool->setLanguageForAutomation(language); ++} ++ +void InspectorBrowserAgent::setGeolocationOverride(Inspector::ErrorString& errorString, const String* browserContextID, const JSON::Object* geolocation) +{ + BrowserContext browserContext = lookupBrowserContext(errorString, browserContextID); @@ -7874,10 +7890,10 @@ index 0000000000000000000000000000000000000000..d8dbb6391594955a23a5ed3cb34b05ca +#endif // ENABLE(REMOTE_INSPECTOR) diff --git a/Source/WebKit/UIProcess/InspectorBrowserAgent.h b/Source/WebKit/UIProcess/InspectorBrowserAgent.h new file mode 100644 -index 0000000000000000000000000000000000000000..8f224acabb5b2010368f25b9b6d5ca0a3b75cd0b +index 0000000000000000000000000000000000000000..87951616c1ad9afbaf645a7ef164df4c93c53f27 --- /dev/null +++ b/Source/WebKit/UIProcess/InspectorBrowserAgent.h -@@ -0,0 +1,113 @@ +@@ -0,0 +1,114 @@ +/* + * Copyright (C) 2019 Microsoft Corporation. + * @@ -7970,6 +7986,7 @@ index 0000000000000000000000000000000000000000..8f224acabb5b2010368f25b9b6d5ca0a + void grantPermissions(Inspector::ErrorString&, const String* browserContextID, const String& origin, const JSON::Array& permissions) override; + void resetPermissions(Inspector::ErrorString&, const String* browserContextID) override; + void setGeolocationOverride(Inspector::ErrorString&, const String* browserContextID, const JSON::Object* geolocation) override; ++ void setLanguage(Inspector::ErrorString&, const String& language, const String* browserContextID) override; + + static String toBrowserContextIDProtocolString(const PAL::SessionID&); + static String toPageProxyIDProtocolString(const WebPageProxy&); @@ -9357,8 +9374,25 @@ index a6d4c6173b0fd75a5f507e44f60f7dfd14f433b4..d2721d8356841fd5b3b16c808c35522d #if ENABLE(NETSCAPE_PLUGIN_API) UnavailablePluginButtonClicked(uint32_t pluginUnavailabilityReason, String mimeType, String pluginURLString, String pluginspageAttributeURLString, String frameURLString, String pageURLString) +diff --git a/Source/WebKit/UIProcess/WebProcessPool.cpp b/Source/WebKit/UIProcess/WebProcessPool.cpp +index e1ce3a17d5c6d38a12e54cc1f45f951c16b290d6..de49f636874949990ffba16fc8c8bc8e8b9e7efb 100644 +--- a/Source/WebKit/UIProcess/WebProcessPool.cpp ++++ b/Source/WebKit/UIProcess/WebProcessPool.cpp +@@ -987,7 +987,11 @@ void WebProcessPool::initializeNewWebProcess(WebProcessProxy& process, WebsiteDa + #endif + + parameters.cacheModel = LegacyGlobalSettings::singleton().cacheModel(); +- parameters.languages = configuration().overrideLanguages().isEmpty() ? userPreferredLanguages() : configuration().overrideLanguages(); ++ if (m_languageForAutomation.isNull()) { ++ parameters.languages = configuration().overrideLanguages().isEmpty() ? userPreferredLanguages() : configuration().overrideLanguages(); ++ } else { ++ parameters.languages.append(m_languageForAutomation); ++ } + + parameters.urlSchemesRegisteredAsEmptyDocument = copyToVector(m_schemesToRegisterAsEmptyDocument); + parameters.urlSchemesRegisteredAsSecure = copyToVector(LegacyGlobalSettings::singleton().schemesToRegisterAsSecure()); diff --git a/Source/WebKit/UIProcess/WebProcessPool.h b/Source/WebKit/UIProcess/WebProcessPool.h -index 64b1dbce4c907536999b1c2a5eb314670f423e1e..e86d634f64fdaa0fd4a9338ffba566bf7209e02d 100644 +index 64b1dbce4c907536999b1c2a5eb314670f423e1e..b9297305dab1d5001ee184747d58bd8b4999ac84 100644 --- a/Source/WebKit/UIProcess/WebProcessPool.h +++ b/Source/WebKit/UIProcess/WebProcessPool.h @@ -416,7 +416,7 @@ public: @@ -9370,7 +9404,24 @@ index 64b1dbce4c907536999b1c2a5eb314670f423e1e..e86d634f64fdaa0fd4a9338ffba566bf void setIgnoreTLSErrors(bool); bool ignoreTLSErrors() const { return m_ignoreTLSErrors; } #endif -@@ -711,8 +711,8 @@ private: +@@ -537,6 +537,8 @@ public: + + PlugInAutoStartProvider& plugInAutoStartProvider() { return m_plugInAutoStartProvider; } + ++ void setLanguageForAutomation(const String& language) { m_languageForAutomation = language; } ++ + void setUseSeparateServiceWorkerProcess(bool); + bool useSeparateServiceWorkerProcess() const { return m_useSeparateServiceWorkerProcess; } + +@@ -642,6 +644,7 @@ private: + std::unique_ptr m_customProtocolManagerClient; + + RefPtr m_automationSession; ++ String m_languageForAutomation; + + #if ENABLE(NETSCAPE_PLUGIN_API) + PluginInfoStore m_pluginInfoStore; +@@ -711,8 +714,8 @@ private: HashMap> m_dictionaryCallbacks; HashMap> m_statisticsRequests;