Skip to content

Commit

Permalink
Merge pull request #538 from brave/webrtc_policy_setting
Browse files Browse the repository at this point in the history
Add WebRTC IP handling policy setting in the privacy page
  • Loading branch information
yrliou committed Oct 2, 2018
1 parent 9453ad1 commit 3864efe
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 8 deletions.
19 changes: 19 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_BLOCK_FINGERPRINTING" desc="Select value">
Block all fingerprinting
</message>
<!-- WebRTC Policy Setting -->
<message name="IDS_SETTINGS_WEBRTC_POLICY_LABEL" desc="WebRTC policy setting label">
WebRTC IP Handling Policy
</message>
<message name="IDS_SETTINGS_WEBRTC_POLICY_SUB_LABEL" desc="WebRTC policy setting sub-label">
Learn more
</message>
<message name="IDS_SETTINGS_WEBRTC_POLICY_DEFAULT" desc="Select value">
Default
</message>
<message name="IDS_SETTINGS_WEBRTC_POLICY_DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES" desc="Select value">
Default public and private interfaces
</message>
<message name="IDS_SETTINGS_WEBRTC_POLICY_DEFAULT_PUBLIC_INTERFACE_ONLY" desc="Select value">
Default public interface only
</message>
<message name="IDS_SETTINGS_WEBRTC_POLICY_DISABLE_NON_PROXIED_UDP" desc="Select value">
Disable non-proxied UDP
</message>
</messages>
<includes>
<include name="IDR_BRAVE_TAG_SERVICES_POLYFILL" file="resources/js/tag_services_polyfill.js" type="BINDATA" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<link rel="import" href="chrome://resources/html/polymer.html">

<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/html/md_select_css.html">
<link rel="import" href="brave_privacy_page_browser_proxy.html">
<link rel="import" href="../settings_shared_css.html">
<link rel="import" href="../settings_vars_css.html">

<dom-module id="settings-brave-personalization-options">
<template>
<style include="settings-shared md-select iron-flex">
.settings-box {
display: flex;
justify-content: space-between;
}
</style>
<div class="settings-box">
<div calss="start" id="labelWrapper">
<div class="label">$i18n{webRTCPolicyLabel}</div>
<a id="learnMore" href="$i18n{webRTCLearnMoreURL}" target="_blank">
$i18n{webRTCPolicySubLabel}
</a>
</div>
<select id="webRTCPolicy" class="md-select"
on-change="onWebRTCPolicyChange_">
<template is="dom-repeat" items="[[webRTCPolicies_]]">
<option value="[[item.value]]"
selected="[[webRTCPolicyEqual_(item.value, webRTCPolicy_)]]">
[[item.name]]
</option>
</template>
</select>
</div>
</template>
<script src="brave_personalization_options.js"></script>
</dom-module>
Original file line number Diff line number Diff line change
@@ -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);
},
});
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="href" src="chrome://resources/html/cr.html">
<script src="brave_privacy_page_browser_proxy.js"></script>
Original file line number Diff line number Diff line change
@@ -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<string>}
*/
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,
};
});
4 changes: 2 additions & 2 deletions browser/resources/settings/settings_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@
<structure name="IDR_SETTINGS_PDF_DOCUMENTS_HTML" file="site_settings/pdf_documents.html" type="chrome_html" />
<structure name="IDR_SETTINGS_PDF_DOCUMENTS_JS" file="site_settings/pdf_documents.js" type="chrome_html" />
<structure name="IDR_SETTINGS_PERSONALIZATION_OPTIONS_HTML" file="privacy_page/personalization_options.html" type="chrome_html" preprocess="true" allowexternalscript="true" />
<structure name="IDR_SETTINGS_PERSONALIZATION_OPTIONS_JS" file="privacy_page/personalization_options.js" preprocess="true" type="chrome_html" />
<structure name="IDR_SETTINGS_PERSONALIZATION_OPTIONS_JS" file="privacy_page/personalization_options.js" preprocess="true" type="chrome_html" /><structure name="IDR_SETTINGS_BRAVE_PERSONALIZATION_OPTIONS_HTML" file="brave_privacy_page/brave_personalization_options.html" type="chrome_html" preprocess="true" allowexternalscript="true" /><structure name="IDR_SETTINGS_BRAVE_PERSONALIZATION_OPTIONS_JS" file="brave_privacy_page/brave_personalization_options.js" type="chrome_html" preprocess="true" />
<structure name="IDR_SETTINGS_PRIVACY_PAGE_HTML" file="privacy_page/privacy_page.html" type="chrome_html" flattenhtml="true" allowexternalscript="true" />
<structure name="IDR_SETTINGS_PRIVACY_PAGE_JS" file="privacy_page/privacy_page.js" preprocess="true" type="chrome_html" />
<structure name="IDR_SETTINGS_PRIVACY_PAGE_BROWSER_PROXY_HTML" file="privacy_page/privacy_page_browser_proxy.html" type="chrome_html" />
<structure name="IDR_SETTINGS_PRIVACY_PAGE_BROWSER_PROXY_JS" file="privacy_page/privacy_page_browser_proxy.js" preprocess="true" type="chrome_html" />
<structure name="IDR_SETTINGS_PRIVACY_PAGE_BROWSER_PROXY_JS" file="privacy_page/privacy_page_browser_proxy.js" preprocess="true" type="chrome_html" /><structure name="IDR_SETTINGS_BRAVE_PRIVACY_PAGE_BROWSER_PROXY_HTML" file="brave_privacy_page/brave_privacy_page_browser_proxy.html" type="chrome_html" /><structure name="IDR_SETTINGS_BRAVE_PRIVACY_PAGE_BROWSER_PROXY_JS" file="brave_privacy_page/brave_privacy_page_browser_proxy.js" type="chrome_html" preprocess="true" />
<structure name="IDR_SETTINGS_PROTOCOL_HANDLERS_HTML" file="site_settings/protocol_handlers.html" preprocess="true" type="chrome_html" />
<structure name="IDR_SETTINGS_PROTOCOL_HANDLERS_JS" file="site_settings/protocol_handlers.js" preprocess="true" type="chrome_html" />
<structure name="IDR_SETTINGS_ROUTE_HTML" file="route.html" type="chrome_html" />
Expand Down
4 changes: 4 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/webui/brave_md_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -13,6 +14,7 @@ BraveMdSettingsUI::BraveMdSettingsUI(content::WebUI* web_ui,
: MdSettingsUI(web_ui) {
web_ui->AddMessageHandler(std::make_unique<settings::MetricsReportingHandler>());
web_ui->AddMessageHandler(std::make_unique<BraveAppearanceHandler>());
web_ui->AddMessageHandler(std::make_unique<BravePrivacyHandler>());
web_ui->AddMessageHandler(std::make_unique<DefaultBraveShieldsHandler>());
}

Expand Down
50 changes: 50 additions & 0 deletions browser/ui/webui/settings/brave_privacy_handler.cc
Original file line number Diff line number Diff line change
@@ -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 <string>

#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));
}
31 changes: 31 additions & 0 deletions browser/ui/webui/settings/brave_privacy_handler.h
Original file line number Diff line number Diff line change
@@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 @@
<link rel="import" href="../route.html">
<link rel="import" href="../settings_shared_css.html">
<link rel="import" href="privacy_page_browser_proxy.html">
+<if expr="not _google_chrome">
+<link rel="import" href="../brave_privacy_page/brave_personalization_options.html">
+</if>

<dom-module id="settings-personalization-options">
<template>
@@ -35,16 +38,22 @@
numeric-unchecked-value="[[networkPredictionEnum_.NEVER]]"
disabled="[[unifiedConsentGiven]]">
</settings-toggle-button>
Expand All @@ -18,19 +28,22 @@ index 843f10eeb1dbe04b45c28d947df1d28d43ea608a..7027cea31595eacb9a9f44cb7ca90e15
sub-label="$i18n{safeBrowsingEnableProtectionDesc}"
disabled="[[unifiedConsentGiven]]">
</settings-toggle-button>
+ <if expr="not _google_chrome">
+ <settings-brave-personalization-options></settings-brave-personalization-options>
+ </if>
+ <if expr="_google_chrome">
<settings-toggle-button id="safeBrowsingExtendedReportingControl"
pref="[[safeBrowsingExtendedReportingPref_]]"
label="$i18n{safeBrowsingEnableExtendedReporting}"
@@ -53,6 +56,7 @@
@@ -53,6 +62,7 @@
no-set-pref
disabled="[[unifiedConsentGiven]]">
</settings-toggle-button>
+ </if>
<if expr="_google_chrome">
<if expr="chromeos">
<settings-toggle-button pref="{{prefs.cros.metrics.reportingEnabled}}"
@@ -61,6 +65,8 @@
@@ -61,6 +71,8 @@
disabled="[[unifiedConsentGiven]]">
</settings-toggle-button>
</if><!-- chromeos -->
Expand All @@ -39,7 +52,7 @@ index 843f10eeb1dbe04b45c28d947df1d28d43ea608a..7027cea31595eacb9a9f44cb7ca90e15
<if expr="not chromeos">
<settings-toggle-button id="metricsReportingControl"
pref="[[metricsReportingPref_]]" label="$i18n{enableLogging}"
@@ -75,7 +81,7 @@
@@ -75,7 +87,7 @@
</template>
</settings-toggle-button>
</if><!-- not chromeos -->
Expand Down
Loading

0 comments on commit 3864efe

Please sign in to comment.