From 3864efe40caf5a76c21e72eac9396632ccff634f Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Tue, 2 Oct 2018 08:57:23 -0700 Subject: [PATCH] Merge pull request #538 from brave/webrtc_policy_setting Add WebRTC IP handling policy setting in the privacy page --- app/brave_generated_resources.grd | 19 ++++++ .../brave_personalization_options.html | 36 ++++++++++++ .../brave_personalization_options.js | 58 +++++++++++++++++++ .../brave_privacy_page_browser_proxy.html | 2 + .../brave_privacy_page_browser_proxy.js | 39 +++++++++++++ .../resources/settings/settings_resources.grd | 4 +- browser/ui/BUILD.gn | 4 ++ browser/ui/webui/brave_md_settings_ui.cc | 2 + .../webui/settings/brave_privacy_handler.cc | 50 ++++++++++++++++ .../ui/webui/settings/brave_privacy_handler.h | 31 ++++++++++ .../md_settings_localized_strings_provider.cc | 19 +++++- ...cy_page-personalization_options.html.patch | 23 ++++++-- script/chromium-rebase-l10n.py | 41 +++++++++++++ 13 files changed, 320 insertions(+), 8 deletions(-) create mode 100644 browser/resources/settings/brave_privacy_page/brave_personalization_options.html create mode 100644 browser/resources/settings/brave_privacy_page/brave_personalization_options.js create mode 100644 browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.html create mode 100644 browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.js create mode 100644 browser/ui/webui/settings/brave_privacy_handler.cc create mode 100644 browser/ui/webui/settings/brave_privacy_handler.h diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index dc2bdec955d6..66f8e7a207e8 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -211,6 +211,25 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U Block all fingerprinting + + + WebRTC IP Handling Policy + + + Learn more + + + Default + + + Default public and private interfaces + + + Default public interface only + + + Disable non-proxied UDP + diff --git a/browser/resources/settings/brave_privacy_page/brave_personalization_options.html b/browser/resources/settings/brave_privacy_page/brave_personalization_options.html new file mode 100644 index 000000000000..bd276c2f7d79 --- /dev/null +++ b/browser/resources/settings/brave_privacy_page/brave_personalization_options.html @@ -0,0 +1,36 @@ + + + + + + + + + + + + diff --git a/browser/resources/settings/brave_privacy_page/brave_personalization_options.js b/browser/resources/settings/brave_privacy_page/brave_personalization_options.js new file mode 100644 index 000000000000..5c769d8b0009 --- /dev/null +++ b/browser/resources/settings/brave_privacy_page/brave_personalization_options.js @@ -0,0 +1,58 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +(function() { +'use strict'; + +Polymer({ + is: 'settings-brave-personalization-options', + + properties: { + webRTCPolicies_: { + readOnly: true, + type: Array, + value: function() { + return [ + {value: 'default', name: loadTimeData.getString('webRTCDefault')}, + {value: 'default_public_and_private_interfaces', name: loadTimeData.getString('defaultPublicAndPrivateInterfaces')}, + {value: 'default_public_interface_only', name: loadTimeData.getString('defaultPublicInterfaceOnly')}, + {value: 'disable_non_proxied_udp', name: loadTimeData.getString('disableNonProxiedUdp')} + ] + }, + }, + + webRTCPolicy_: String, + }, + + /** @private {?settings.BravePrivacyBrowserProxy} */ + browserProxy_: null, + + /** @override */ + created: function() { + this.browserProxy_ = settings.BravePrivacyBrowserProxyImpl.getInstance(); + }, + + /** @override */ + ready: function() { + this.onWebRTCPolicyChange_ = this.onWebRTCPolicyChange_.bind(this) + this.browserProxy_.getWebRTCPolicy().then(policy => { + this.webRTCPolicy_ = policy; + }); + }, + + /** + * @param {string} policy1 + * @param {string} policy2 + * @return {boolean} + * @private + */ + webRTCPolicyEqual_: function(policy1, policy2) { + return policy1 === policy2; + }, + + onWebRTCPolicyChange_: function() { + this.browserProxy_.setWebRTCPolicy(this.$.webRTCPolicy.value); + }, +}); +})(); diff --git a/browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.html b/browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.html new file mode 100644 index 000000000000..6a67fcac1487 --- /dev/null +++ b/browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.html @@ -0,0 +1,2 @@ + + diff --git a/browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.js b/browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.js new file mode 100644 index 000000000000..3c448ac83bdb --- /dev/null +++ b/browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.js @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +cr.define('settings', function() { + /** @interface */ + class BravePrivacyBrowserProxy { + /** + * @return {!Promise} + */ + getWebRTCPolicy() {} + /** + * @param {string} policy name. + */ + setWebRTCPolicy(policy) {} + } + + /** + * @implements {settings.BravePrivacyBrowserProxy} + */ + class BravePrivacyBrowserProxyImpl { + /** @override */ + getWebRTCPolicy() { + return cr.sendWithPromise('getWebRTCPolicy'); + } + + /** @override */ + setWebRTCPolicy(policy) { + chrome.send('setWebRTCPolicy', [policy]); + } + } + + cr.addSingletonGetter(BravePrivacyBrowserProxyImpl); + + return { + BravePrivacyBrowserProxy: BravePrivacyBrowserProxy, + BravePrivacyBrowserProxyImpl: BravePrivacyBrowserProxyImpl, + }; +}); diff --git a/browser/resources/settings/settings_resources.grd b/browser/resources/settings/settings_resources.grd index a932e5592844..b799c684768d 100644 --- a/browser/resources/settings/settings_resources.grd +++ b/browser/resources/settings/settings_resources.grd @@ -320,11 +320,11 @@ - + - + diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index b00698c72bf7..0ee24f33bcdc 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -72,6 +72,8 @@ source_set("ui") { "webui/brave_welcome_ui.h", "webui/settings/brave_appearance_handler.cc", "webui/settings/brave_appearance_handler.h", + "webui/settings/brave_privacy_handler.cc", + "webui/settings/brave_privacy_handler.h", "webui/settings/default_brave_shields_handler.cc", "webui/settings/default_brave_shields_handler.h", ] @@ -108,7 +110,9 @@ source_set("ui") { "//brave/browser/tor", "//brave/components/resources:brave_components_resources_grit", "//chrome/app:command_ids", + "//chrome/common", "//content/public/browser", + "//content/public/common", "//skia", "//ui/accessibility", "//ui/base", diff --git a/browser/ui/webui/brave_md_settings_ui.cc b/browser/ui/webui/brave_md_settings_ui.cc index 38e259244a60..d3856869cc08 100644 --- a/browser/ui/webui/brave_md_settings_ui.cc +++ b/browser/ui/webui/brave_md_settings_ui.cc @@ -5,6 +5,7 @@ #include "brave/browser/ui/webui/brave_md_settings_ui.h" #include "brave/browser/ui/webui/settings/brave_appearance_handler.h" +#include "brave/browser/ui/webui/settings/brave_privacy_handler.h" #include "brave/browser/ui/webui/settings/default_brave_shields_handler.h" #include "chrome/browser/ui/webui/settings/metrics_reporting_handler.h" @@ -13,6 +14,7 @@ BraveMdSettingsUI::BraveMdSettingsUI(content::WebUI* web_ui, : MdSettingsUI(web_ui) { web_ui->AddMessageHandler(std::make_unique()); web_ui->AddMessageHandler(std::make_unique()); + web_ui->AddMessageHandler(std::make_unique()); web_ui->AddMessageHandler(std::make_unique()); } diff --git a/browser/ui/webui/settings/brave_privacy_handler.cc b/browser/ui/webui/settings/brave_privacy_handler.cc new file mode 100644 index 000000000000..73e37e523e1e --- /dev/null +++ b/browser/ui/webui/settings/brave_privacy_handler.cc @@ -0,0 +1,50 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/webui/settings/brave_privacy_handler.h" + +#include + +#include "base/bind.h" +#include "base/values.h" +#include "chrome/common/pref_names.h" +#include "chrome/browser/profiles/profile.h" +#include "components/prefs/pref_service.h" +#include "content/public/common/webrtc_ip_handling_policy.h" +#include "content/public/browser/web_ui.h" + +void BravePrivacyHandler::RegisterMessages() { + profile_ = Profile::FromWebUI(web_ui()); + + web_ui()->RegisterMessageCallback( + "getWebRTCPolicy", + base::BindRepeating(&BravePrivacyHandler::GetWebRTCPolicy, + base::Unretained(this))); + web_ui()->RegisterMessageCallback( + "setWebRTCPolicy", + base::BindRepeating(&BravePrivacyHandler::SetWebRTCPolicy, + base::Unretained(this))); +} + +void BravePrivacyHandler::SetWebRTCPolicy(const base::ListValue* args) { + CHECK_EQ(args->GetSize(), 1U); + CHECK(profile_); + + std::string policy; + args->GetString(0, &policy); + profile_->GetPrefs()->SetString(prefs::kWebRTCIPHandlingPolicy, policy); +} + +void BravePrivacyHandler::GetWebRTCPolicy(const base::ListValue* args) { + CHECK_EQ(args->GetSize(), 1U); + CHECK(profile_); + + std::string policy = + profile_->GetPrefs()->GetString(prefs::kWebRTCIPHandlingPolicy); + + AllowJavascript(); + ResolveJavascriptCallback( + args->GetList()[0].Clone(), + base::Value(policy)); +} diff --git a/browser/ui/webui/settings/brave_privacy_handler.h b/browser/ui/webui/settings/brave_privacy_handler.h new file mode 100644 index 000000000000..73809f54079c --- /dev/null +++ b/browser/ui/webui/settings/brave_privacy_handler.h @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_PRIVACY_HANDLER_H_ +#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_PRIVACY_HANDLER_H_ + +#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" + +class Profile; + +class BravePrivacyHandler : public settings::SettingsPageUIHandler { + public: + BravePrivacyHandler() = default; + ~BravePrivacyHandler() override = default; + + private: + // SettingsPageUIHandler overrides: + void RegisterMessages() override; + void OnJavascriptAllowed() override {} + void OnJavascriptDisallowed() override {} + + void SetWebRTCPolicy(const base::ListValue* args); + void GetWebRTCPolicy(const base::ListValue* args); + + Profile* profile_ = nullptr; + + DISALLOW_COPY_AND_ASSIGN(BravePrivacyHandler); +}; + +#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_PRIVACY_HANDLER_H_ diff --git a/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc b/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc index 1fb62d8a934a..ebdfd4a65867 100644 --- a/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc +++ b/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc @@ -17,6 +17,9 @@ void BraveAddImportDataStrings(content::WebUIDataSource* html_source) { } #endif +const char kWebRTCLearnMoreURL[] = + "https://github.com/brave/brave-browser/wiki/WebRTC-Custom-Settings"; + void BraveAddCommonStrings(content::WebUIDataSource* html_source, Profile* profile) { LocalizedString localized_strings[] = { {"siteSettingsAutoplay", @@ -58,10 +61,24 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source, Profile* profi {"allowAllFingerprinting", IDS_SETTINGS_ALLOW_FINGERPRINTING}, {"blockAllFingerprinting", - IDS_SETTINGS_BLOCK_FINGERPRINTING} + IDS_SETTINGS_BLOCK_FINGERPRINTING}, + {"webRTCPolicyLabel", + IDS_SETTINGS_WEBRTC_POLICY_LABEL}, + {"webRTCPolicySubLabel", + IDS_SETTINGS_WEBRTC_POLICY_SUB_LABEL}, + {"webRTCDefault", + IDS_SETTINGS_WEBRTC_POLICY_DEFAULT}, + {"defaultPublicAndPrivateInterfaces", + IDS_SETTINGS_WEBRTC_POLICY_DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES}, + {"defaultPublicInterfaceOnly", + IDS_SETTINGS_WEBRTC_POLICY_DEFAULT_PUBLIC_INTERFACE_ONLY}, + {"disableNonProxiedUdp", + IDS_SETTINGS_WEBRTC_POLICY_DISABLE_NON_PROXIED_UDP} }; AddLocalizedStringsBulk(html_source, localized_strings, arraysize(localized_strings)); + html_source->AddString("webRTCLearnMoreURL", + base::ASCIIToUTF16(kWebRTCLearnMoreURL)); } void BraveAddLocalizedStrings(content::WebUIDataSource* html_source, diff --git a/patches/chrome-browser-resources-settings-privacy_page-personalization_options.html.patch b/patches/chrome-browser-resources-settings-privacy_page-personalization_options.html.patch index 32e6f7686534..dad8c6865138 100644 --- a/patches/chrome-browser-resources-settings-privacy_page-personalization_options.html.patch +++ b/patches/chrome-browser-resources-settings-privacy_page-personalization_options.html.patch @@ -1,8 +1,18 @@ diff --git a/chrome/browser/resources/settings/privacy_page/personalization_options.html b/chrome/browser/resources/settings/privacy_page/personalization_options.html -index 843f10eeb1dbe04b45c28d947df1d28d43ea608a..7027cea31595eacb9a9f44cb7ca90e1510720212 100644 +index 843f10eeb1dbe04b45c28d947df1d28d43ea608a..23837485fa890d7f68a75a4e191a5fadeea73f5b 100644 --- a/chrome/browser/resources/settings/privacy_page/personalization_options.html +++ b/chrome/browser/resources/settings/privacy_page/personalization_options.html -@@ -35,16 +35,19 @@ +@@ -8,6 +8,9 @@ + + + ++ ++ ++ + + +