-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from brave/webrtc_policy_setting
Add WebRTC IP handling policy setting in the privacy page
- Loading branch information
Showing
13 changed files
with
320 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
browser/resources/settings/brave_privacy_page/brave_personalization_options.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
58 changes: 58 additions & 0 deletions
58
browser/resources/settings/brave_privacy_page/brave_personalization_options.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}); | ||
})(); |
2 changes: 2 additions & 0 deletions
2
browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
39 changes: 39 additions & 0 deletions
39
browser/resources/settings/brave_privacy_page/brave_privacy_page_browser_proxy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.