Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media/webrtc/media_permission.h" | 5 #include "chrome/browser/media/webrtc/media_permission.h" |
| 6 | 6 |
| 7 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 7 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 8 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" | 8 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" |
| 9 #include "chrome/browser/permissions/permission_context_base.h" | 9 #include "chrome/browser/permissions/permission_context_base.h" |
| 10 #include "chrome/browser/permissions/permission_manager.h" | 10 #include "chrome/browser/permissions/permission_manager.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "content/public/browser/permission_manager.h" | 13 #include "content/public/browser/permission_manager.h" |
| 14 #include "content/public/browser/web_contents.h" | |
| 14 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
| 15 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 16 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" | 17 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" |
| 17 | 18 |
| 19 #if defined(OS_CHROMEOS) | |
| 20 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 21 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" | |
| 22 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 23 #include "chromeos/settings/cros_settings_names.h" | |
| 24 #endif | |
| 25 | |
| 18 MediaPermission::MediaPermission(ContentSettingsType content_type, | 26 MediaPermission::MediaPermission(ContentSettingsType content_type, |
| 19 const GURL& requesting_origin, | 27 const GURL& requesting_origin, |
| 20 const GURL& embedding_origin, | 28 const GURL& embedding_origin, |
| 21 Profile* profile) | 29 Profile* profile, |
| 30 content::WebContents* web_contents) | |
| 22 : content_type_(content_type), | 31 : content_type_(content_type), |
| 23 requesting_origin_(requesting_origin), | 32 requesting_origin_(requesting_origin), |
| 24 embedding_origin_(embedding_origin), | 33 embedding_origin_(embedding_origin), |
| 25 profile_(profile) {} | 34 profile_(profile), |
| 35 web_contents_(web_contents) { | |
| 36 // Currently |web_contents_| is only used on ChromeOS but it's not worth | |
| 37 // #ifdef'ing out all its usage, so just mark it used here. | |
| 38 (void)web_contents_; | |
| 39 } | |
| 26 | 40 |
| 27 ContentSetting MediaPermission::GetPermissionStatus( | 41 ContentSetting MediaPermission::GetPermissionStatus( |
| 28 content::MediaStreamRequestResult* denial_reason) const { | 42 content::MediaStreamRequestResult* denial_reason) const { |
| 29 // Deny the request if the security origin is empty, this happens with | 43 // Deny the request if the security origin is empty, this happens with |
| 30 // file access without |--allow-file-access-from-files| flag. | 44 // file access without |--allow-file-access-from-files| flag. |
| 31 if (requesting_origin_.is_empty()) { | 45 if (requesting_origin_.is_empty()) { |
| 32 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN; | 46 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN; |
| 33 return CONTENT_SETTING_BLOCK; | 47 return CONTENT_SETTING_BLOCK; |
| 34 } | 48 } |
| 35 | 49 |
| 36 PermissionManager* permission_manager = PermissionManager::Get(profile_); | 50 PermissionManager* permission_manager = PermissionManager::Get(profile_); |
| 37 | 51 |
| 38 // Find out if the kill switch is on. Set the denial reason to kill switch. | 52 // Find out if the kill switch is on. Set the denial reason to kill switch. |
| 39 if (permission_manager->IsPermissionKillSwitchOn(content_type_)) { | 53 if (permission_manager->IsPermissionKillSwitchOn(content_type_)) { |
| 40 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; | 54 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; |
| 41 return CONTENT_SETTING_BLOCK; | 55 return CONTENT_SETTING_BLOCK; |
| 42 } | 56 } |
| 43 | 57 |
| 58 #if defined(OS_CHROMEOS) | |
| 59 // Special permissions if the request is coming from a ChromeOS login page. | |
| 60 if (web_contents_ == | |
| 61 chromeos::LoginDisplayHost::default_host() | |
| 62 ->GetWebUILoginView() | |
| 63 ->GetWebContents()) { | |
| 64 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | |
| 65 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | |
| 66 return CONTENT_SETTING_BLOCK; | |
| 67 } | |
| 68 | |
| 69 const chromeos::CrosSettings* const settings = | |
| 70 chromeos::CrosSettings::Get(); | |
| 71 if (!settings) { | |
| 72 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | |
| 73 return CONTENT_SETTING_BLOCK; | |
| 74 } | |
| 75 | |
| 76 const base::Value* const raw_list_value = | |
| 77 settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls); | |
| 78 if (!raw_list_value) { | |
| 79 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | |
| 80 return CONTENT_SETTING_BLOCK; | |
| 81 } | |
| 82 | |
| 83 const base::ListValue* list_value; | |
| 84 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.
| |
| 85 DCHECK(is_list); | |
| 86 for (const auto& base_value : *list_value) { | |
| 87 std::string value; | |
| 88 if (base_value->GetAsString(&value)) { | |
| 89 const ContentSettingsPattern pattern = | |
| 90 ContentSettingsPattern::FromString(value); | |
| 91 if (pattern == ContentSettingsPattern::Wildcard()) { | |
| 92 LOG(WARNING) << "Ignoring wildcard URL pattern: " << value; | |
| 93 continue; | |
| 94 } | |
| 95 if (pattern.IsValid() && pattern.Matches(requesting_origin_)) | |
| 96 return CONTENT_SETTING_ALLOW; | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | |
| 101 return CONTENT_SETTING_BLOCK; | |
| 102 } | |
| 103 #endif // defined(OS_CHROMEOS) | |
| 104 | |
| 44 // Check policy and content settings. | 105 // Check policy and content settings. |
| 45 blink::mojom::PermissionStatus status = | 106 blink::mojom::PermissionStatus status = |
| 46 permission_manager->GetPermissionStatus( | 107 permission_manager->GetPermissionStatus( |
| 47 content_type_, requesting_origin_, embedding_origin_); | 108 content_type_, requesting_origin_, embedding_origin_); |
| 48 switch (status) { | 109 switch (status) { |
| 49 case blink::mojom::PermissionStatus::DENIED: | 110 case blink::mojom::PermissionStatus::DENIED: |
| 50 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 111 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| 51 return CONTENT_SETTING_BLOCK; | 112 return CONTENT_SETTING_BLOCK; |
| 52 case blink::mojom::PermissionStatus::ASK: | 113 case blink::mojom::PermissionStatus::ASK: |
| 53 return CONTENT_SETTING_ASK; | 114 return CONTENT_SETTING_ASK; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 return false; | 154 return false; |
| 94 | 155 |
| 95 // Note: we check device_id before dereferencing devices. If the requested | 156 // Note: we check device_id before dereferencing devices. If the requested |
| 96 // device id is non-empty, then the corresponding device list must not be | 157 // device id is non-empty, then the corresponding device list must not be |
| 97 // NULL. | 158 // NULL. |
| 98 if (!device_id.empty() && !devices->FindById(device_id)) | 159 if (!device_id.empty() && !devices->FindById(device_id)) |
| 99 return false; | 160 return false; |
| 100 | 161 |
| 101 return true; | 162 return true; |
| 102 } | 163 } |
| OLD | NEW |