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 cb402eb77994b4377b41784e4346c3593969fb6c..f5afa1ecc469ebaac44289d0e2a3530e870cefd9 100644 |
--- a/chrome/browser/media/media_stream_devices_controller.cc |
+++ b/chrome/browser/media/media_stream_devices_controller.cc |
@@ -4,9 +4,7 @@ |
#include "chrome/browser/media/media_stream_devices_controller.h" |
-#include "base/command_line.h" |
#include "base/metrics/histogram.h" |
-#include "base/prefs/pref_service.h" |
#include "base/prefs/scoped_user_pref_update.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/values.h" |
@@ -15,6 +13,7 @@ |
#include "chrome/browser/content_settings/tab_specific_content_settings.h" |
#include "chrome/browser/media/media_capture_devices_dispatcher.h" |
#include "chrome/browser/media/media_stream_capture_indicator.h" |
+#include "chrome/browser/media/media_stream_devices_util.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/common/chrome_switches.h" |
@@ -30,10 +29,6 @@ |
#include "grit/theme_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
-#if defined(OS_CHROMEOS) |
-#include "components/user_manager/user_manager.h" |
-#endif |
- |
using content::BrowserThread; |
namespace { |
@@ -81,19 +76,6 @@ bool HasAvailableDevicesForRequest(const content::MediaStreamRequest& request) { |
return true; |
} |
-bool IsInKioskMode() { |
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
- return true; |
- |
-#if defined(OS_CHROMEOS) |
- const user_manager::UserManager* user_manager = |
- user_manager::UserManager::Get(); |
- return user_manager && user_manager->IsLoggedInAsKioskApp(); |
-#else |
- return false; |
-#endif |
-} |
- |
enum DevicePermissionActions { |
kAllowHttps = 0, |
kAllowHttp, |
@@ -134,7 +116,9 @@ MediaStreamDevicesController::MediaStreamDevicesController( |
// case take a ride on the MEDIA_DEVICE_*_CAPTURE permission. Should be fixed. |
if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
request.request_type == content::MEDIA_OPEN_DEVICE) { |
- if (GetDevicePolicy(prefs::kAudioCaptureAllowed, |
+ if (GetDevicePolicy(profile_, |
+ request_.security_origin, |
+ prefs::kAudioCaptureAllowed, |
prefs::kAudioCaptureAllowedUrls) == ALWAYS_DENY) { |
request_permissions_.insert(std::make_pair( |
content::MEDIA_DEVICE_AUDIO_CAPTURE, |
@@ -149,7 +133,9 @@ MediaStreamDevicesController::MediaStreamDevicesController( |
} |
if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE || |
request.request_type == content::MEDIA_OPEN_DEVICE) { |
- if (GetDevicePolicy(prefs::kVideoCaptureAllowed, |
+ if (GetDevicePolicy(profile_, |
+ request_.security_origin, |
+ prefs::kVideoCaptureAllowed, |
prefs::kVideoCaptureAllowedUrls) == ALWAYS_DENY) { |
request_permissions_.insert(std::make_pair( |
content::MEDIA_DEVICE_VIDEO_CAPTURE, |
@@ -456,51 +442,9 @@ void MediaStreamDevicesController::RequestFinished() { |
delete this; |
} |
-MediaStreamDevicesController::DevicePolicy |
-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(); |
- |
- // TODO(tommi): Remove the kiosk mode check when the whitelist below |
- // is visible in the media exceptions UI. |
- // See discussion here: https://codereview.chromium.org/15738004/ |
- if (IsInKioskMode()) { |
- 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)) { |
- ContentSettingsPattern pattern = |
- ContentSettingsPattern::FromString(value); |
- if (pattern == ContentSettingsPattern::Wildcard()) { |
- DLOG(WARNING) << "Ignoring wildcard URL pattern: " << value; |
- continue; |
- } |
- DLOG_IF(ERROR, !pattern.IsValid()) << "Invalid URL pattern: " << value; |
- if (pattern.IsValid() && pattern.Matches(request_.security_origin)) |
- 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->GetBoolean(policy_name)) |
- return ALWAYS_DENY; |
- |
- return POLICY_NOT_SET; |
-} |
- |
bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { |
// The request from internal objects like chrome://URLs is always allowed. |
- if (ShouldAlwaysAllowOrigin()) |
+ if (ShouldAlwaysAllowOrigin(profile_, request_.security_origin)) |
return true; |
struct { |
@@ -520,8 +464,11 @@ bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { |
if (!device_checks[i].has_capability) |
continue; |
- DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name, |
- device_checks[i].list_policy_name); |
+ MediaStreamDevicePolicy policy = |
+ GetDevicePolicy(profile_, |
+ request_.security_origin, |
+ device_checks[i].policy_name, |
+ device_checks[i].list_policy_name); |
if (policy == ALWAYS_DENY) |
return false; |
@@ -595,15 +542,6 @@ bool MediaStreamDevicesController::IsSchemeSecure() const { |
request_.security_origin.SchemeIs(extensions::kExtensionScheme); |
} |
-bool MediaStreamDevicesController::ShouldAlwaysAllowOrigin() const { |
- // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the |
- // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and |
- // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA. |
- return profile_->GetHostContentSettingsMap()->ShouldAllowAllContent( |
- request_.security_origin, request_.security_origin, |
- CONTENT_SETTINGS_TYPE_MEDIASTREAM); |
-} |
- |
void MediaStreamDevicesController::SetPermission(bool allowed) const { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
ContentSettingsPattern primary_pattern = |