Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2699)

Unified Diff: chrome/browser/media/media_stream_devices_controller.cc

Issue 15738004: Add a policy list for access to capture devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change capture policy values to be per-profile. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/media_stream_devices_controller.cc
diff --git a/chrome/browser/media/media_stream_devices_controller.cc b/chrome/browser/media/media_stream_devices_controller.cc
index 7b8634830200f17e3583d1f004eeae2065a5a7fe..5d0039e69bfdd7b2d0536c24e9b2a98b98fa48e8 100644
--- a/chrome/browser/media/media_stream_devices_controller.cc
+++ b/chrome/browser/media/media_stream_devices_controller.cc
@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
+#include "base/string_util.h"
#include "base/values.h"
#include "chrome/browser/content_settings/content_settings_provider.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
@@ -54,12 +55,14 @@ MediaStreamDevicesController::MediaStreamDevicesController(
// Don't call GetDevicePolicy from the initializer list since the
// implementation depends on member variables.
if (microphone_requested_ &&
- GetDevicePolicy(prefs::kAudioCaptureAllowed) == ALWAYS_DENY) {
+ GetDevicePolicy(prefs::kAudioCaptureAllowed,
+ prefs::kAudioCaptureAllowedUrls) == ALWAYS_DENY) {
microphone_requested_ = false;
}
if (webcam_requested_ &&
- GetDevicePolicy(prefs::kVideoCaptureAllowed) == ALWAYS_DENY) {
+ GetDevicePolicy(prefs::kVideoCaptureAllowed,
+ prefs::kVideoCaptureAllowedUrls) == ALWAYS_DENY) {
webcam_requested_ = false;
}
}
@@ -75,6 +78,10 @@ void MediaStreamDevicesController::RegisterUserPrefs(
prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed,
true,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+ prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+ prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
@@ -192,14 +199,36 @@ void MediaStreamDevicesController::Deny(bool update_content_setting) {
}
MediaStreamDevicesController::DevicePolicy
-MediaStreamDevicesController::GetDevicePolicy(const char* policy_name) const {
+MediaStreamDevicesController::GetDevicePolicy(
+ const char* policy_name,
+ const char* whitelist_policy_name) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // If the security origin policy matches a value in the whitelist, allow it.
+ // Otherwise, check the |policy_name| master switch for the default behavior.
+
PrefService* prefs = profile_->GetPrefs();
- if (!prefs->IsManagedPreference(policy_name))
+ if (prefs->IsManagedPreference(whitelist_policy_name)) {
+ const base::ListValue* list = prefs->GetList(whitelist_policy_name);
+ std::string value;
+ for (size_t i = 0; i < list->GetSize(); ++i) {
+ if (list->GetString(i, &value) &&
+ MatchPattern(request_.security_origin.spec(), value)) {
Joao da Silva 2013/05/23 13:28:36 MatchPattern() accepts "*", do we want to enable t
tommi (sloooow) - chröme 2013/05/23 13:50:39 Yes, that's a conscious decision. I don't think i
+ return ALWAYS_ALLOW;
+ }
+ }
+ }
+
+ // If a match was not found, check if audio capture is otherwise disallowed
+ // or if the user should be prompted. Setting the policy value to "true"
+ // is equal to not setting it at all, so from hereon out, we will return
+ // either POLICY_NOT_SET (prompt) or ALWAYS_DENY (no prompt, no access).
+ if (!prefs->IsManagedPreference(policy_name) ||
+ prefs->GetBoolean(policy_name)) {
return POLICY_NOT_SET;
+ }
- return prefs->GetBoolean(policy_name) ? ALWAYS_ALLOW : ALWAYS_DENY;
+ return ALWAYS_DENY;
}
bool MediaStreamDevicesController::IsRequestAllowedByDefault() const {
@@ -210,11 +239,13 @@ bool MediaStreamDevicesController::IsRequestAllowedByDefault() const {
struct {
bool has_capability;
const char* policy_name;
+ const char* list_policy_name;
ContentSettingsType settings_type;
} device_checks[] = {
{ microphone_requested_, prefs::kAudioCaptureAllowed,
- CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC },
+ prefs::kAudioCaptureAllowedUrls, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC },
{ webcam_requested_, prefs::kVideoCaptureAllowed,
+ prefs::kVideoCaptureAllowedUrls,
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA },
};
@@ -222,7 +253,8 @@ bool MediaStreamDevicesController::IsRequestAllowedByDefault() const {
if (!device_checks[i].has_capability)
continue;
- DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name);
+ DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name,
+ device_checks[i].list_policy_name);
if (policy == ALWAYS_DENY ||
(policy == POLICY_NOT_SET &&
profile_->GetHostContentSettingsMap()->GetContentSetting(
« no previous file with comments | « chrome/browser/media/media_stream_devices_controller.h ('k') | chrome/browser/policy/configuration_policy_handler_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698