Chromium Code Reviews| Index: chrome/browser/media/webrtc/media_permission.cc |
| diff --git a/chrome/browser/media/webrtc/media_permission.cc b/chrome/browser/media/webrtc/media_permission.cc |
| index 278f7ede84e1516f4762c17d115d7703751e68a8..5cdd933d95f0b76907bb490c83e4f7df09aa22d4 100644 |
| --- a/chrome/browser/media/webrtc/media_permission.cc |
| +++ b/chrome/browser/media/webrtc/media_permission.cc |
| @@ -11,18 +11,32 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/public/browser/permission_manager.h" |
| +#include "content/public/browser/web_contents.h" |
| #include "content/public/common/url_constants.h" |
| #include "extensions/common/constants.h" |
| #include "third_party/WebKit/public/platform/modules/permissions/permission_status.mojom.h" |
| +#if defined(OS_CHROMEOS) |
| +#include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| +#include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
| +#include "chrome/browser/chromeos/settings/cros_settings.h" |
| +#include "chromeos/settings/cros_settings_names.h" |
| +#endif |
| + |
| MediaPermission::MediaPermission(ContentSettingsType content_type, |
| const GURL& requesting_origin, |
| const GURL& embedding_origin, |
| - Profile* profile) |
| + Profile* profile, |
| + content::WebContents* web_contents) |
| : content_type_(content_type), |
| requesting_origin_(requesting_origin), |
| embedding_origin_(embedding_origin), |
| - profile_(profile) {} |
| + profile_(profile), |
| + web_contents_(web_contents) { |
| + // Currently |web_contents_| is only used on ChromeOS but it's not worth |
| + // #ifdef'ing out all its usage, so just mark it used here. |
| + (void)web_contents_; |
| +} |
| ContentSetting MediaPermission::GetPermissionStatus( |
| content::MediaStreamRequestResult* denial_reason) const { |
| @@ -41,6 +55,53 @@ ContentSetting MediaPermission::GetPermissionStatus( |
| return CONTENT_SETTING_BLOCK; |
| } |
| +#if defined(OS_CHROMEOS) |
| + // Special permissions if the request is coming from a ChromeOS login page. |
| + if (web_contents_ == |
| + chromeos::LoginDisplayHost::default_host() |
| + ->GetWebUILoginView() |
| + ->GetWebContents()) { |
| + if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| + *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| + return CONTENT_SETTING_BLOCK; |
| + } |
| + |
| + const chromeos::CrosSettings* const settings = |
| + chromeos::CrosSettings::Get(); |
| + if (!settings) { |
| + *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| + return CONTENT_SETTING_BLOCK; |
| + } |
| + |
| + const base::Value* const raw_list_value = |
| + settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls); |
| + if (!raw_list_value) { |
| + *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| + return CONTENT_SETTING_BLOCK; |
| + } |
| + |
| + const base::ListValue* list_value; |
| + bool is_list = raw_list_value->GetAsList(&list_value); |
|
achuithb
2017/02/21 13:54:37
nit const
raymes
2017/02/22 02:33:07
Done.
|
| + DCHECK(is_list); |
| + for (const auto& base_value : *list_value) { |
| + std::string value; |
| + if (base_value->GetAsString(&value)) { |
| + const ContentSettingsPattern pattern = |
| + ContentSettingsPattern::FromString(value); |
| + if (pattern == ContentSettingsPattern::Wildcard()) { |
| + LOG(WARNING) << "Ignoring wildcard URL pattern: " << value; |
| + continue; |
| + } |
| + if (pattern.IsValid() && pattern.Matches(requesting_origin_)) |
| + return CONTENT_SETTING_ALLOW; |
| + } |
| + } |
| + |
| + *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| + return CONTENT_SETTING_BLOCK; |
| + } |
| +#endif // defined(OS_CHROMEOS) |
| + |
| // Check policy and content settings. |
| blink::mojom::PermissionStatus status = |
| permission_manager->GetPermissionStatus( |