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

Side by Side Diff: chrome/browser/media/webrtc/media_permission.cc

Issue 2696703006: Move media permission checking logic for ChromeOS login pages (Closed)
Patch Set: Move media permission checking logic for ChromeOS login pages Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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/permission_type.h" 14 #include "content/public/browser/permission_type.h"
15 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/url_constants.h" 16 #include "content/public/common/url_constants.h"
16 #include "extensions/common/constants.h" 17 #include "extensions/common/constants.h"
17 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 18 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
18 19
20 #if defined(OS_CHROMEOS)
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
19 namespace { 26 namespace {
20 27
21 content::PermissionType ContentSettingsTypeToPermission( 28 content::PermissionType ContentSettingsTypeToPermission(
22 ContentSettingsType content_setting) { 29 ContentSettingsType content_setting) {
23 if (content_setting == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 30 if (content_setting == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
24 return content::PermissionType::AUDIO_CAPTURE; 31 return content::PermissionType::AUDIO_CAPTURE;
25 } else { 32 } else {
26 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, content_setting); 33 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, content_setting);
27 return content::PermissionType::VIDEO_CAPTURE; 34 return content::PermissionType::VIDEO_CAPTURE;
28 } 35 }
29 } 36 }
30 37
31 } // namespace 38 } // namespace
32 39
33 MediaPermission::MediaPermission(ContentSettingsType content_type, 40 MediaPermission::MediaPermission(ContentSettingsType content_type,
34 const GURL& requesting_origin, 41 const GURL& requesting_origin,
35 const GURL& embedding_origin, 42 const GURL& embedding_origin,
36 Profile* profile) 43 Profile* profile,
44 content::WebContents* web_contents)
37 : content_type_(content_type), 45 : content_type_(content_type),
38 requesting_origin_(requesting_origin), 46 requesting_origin_(requesting_origin),
39 embedding_origin_(embedding_origin), 47 embedding_origin_(embedding_origin),
40 profile_(profile) {} 48 profile_(profile),
49 web_contents_(web_contents) {
50 // Currently |web_contents_| is only used on ChromeOS but it's not worth
51 // #ifdef'ing out all its usage, so just mark it used here.
52 (void)web_contents_;
achuithb 2017/02/16 09:05:38 This seems pretty sketchy. Are there any other pla
raymes 2017/02/16 10:36:14 +jyasskin (C++ expert): Jeffrey does this seem lik
Sergey Ulanov 2017/02/16 19:26:17 ALLOW_UNUSED_LOCAL()?
Jeffrey Yasskin 2017/02/17 17:34:32 That seems misleading for a non-local variable, bu
raymes 2017/02/21 01:29:55 I'd like to stick with this for now as I think it'
achuithb 2017/02/21 13:54:37 Acknowledged.
53 }
41 54
42 ContentSetting MediaPermission::GetPermissionStatus( 55 ContentSetting MediaPermission::GetPermissionStatus(
43 content::MediaStreamRequestResult* denial_reason) const { 56 content::MediaStreamRequestResult* denial_reason) const {
44 // Deny the request if the security origin is empty, this happens with 57 // Deny the request if the security origin is empty, this happens with
45 // file access without |--allow-file-access-from-files| flag. 58 // file access without |--allow-file-access-from-files| flag.
46 if (requesting_origin_.is_empty()) { 59 if (requesting_origin_.is_empty()) {
47 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN; 60 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN;
48 return CONTENT_SETTING_BLOCK; 61 return CONTENT_SETTING_BLOCK;
49 } 62 }
50 63
51 content::PermissionType permission_type = 64 content::PermissionType permission_type =
52 ContentSettingsTypeToPermission(content_type_); 65 ContentSettingsTypeToPermission(content_type_);
53 PermissionManager* permission_manager = PermissionManager::Get(profile_); 66 PermissionManager* permission_manager = PermissionManager::Get(profile_);
54 67
55 // Find out if the kill switch is on. Set the denial reason to kill switch. 68 // Find out if the kill switch is on. Set the denial reason to kill switch.
56 if (permission_manager->IsPermissionKillSwitchOn(permission_type)) { 69 if (permission_manager->IsPermissionKillSwitchOn(permission_type)) {
57 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; 70 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON;
58 return CONTENT_SETTING_BLOCK; 71 return CONTENT_SETTING_BLOCK;
59 } 72 }
60 73
74 #if defined(OS_CHROMEOS)
75 // Special permissions if the request is coming from a ChromeOS login page.
76 if (chromeos::WebUILoginView::IsWebUILoginView(
77 web_contents_->GetDelegate())) {
78 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
79 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
80 return CONTENT_SETTING_BLOCK;
81 }
82
83 const chromeos::CrosSettings* const settings =
84 chromeos::CrosSettings::Get();
85 if (!settings) {
86 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
87 return CONTENT_SETTING_BLOCK;
88 }
89
90 const base::Value* const raw_list_value =
91 settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls);
92 if (!raw_list_value) {
93 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
94 return CONTENT_SETTING_BLOCK;
95 }
96
97 const base::ListValue* list_value;
98 CHECK(raw_list_value->GetAsList(&list_value));
Sergey Ulanov 2017/02/16 19:26:17 It's best to avoid side-effects in CHECK() stateme
raymes 2017/02/21 01:29:55 Agreed - I just copied this code over from the oth
99 for (const auto& base_value : *list_value) {
100 std::string value;
101 if (base_value->GetAsString(&value)) {
102 ContentSettingsPattern pattern =
achuithb 2017/02/16 09:05:38 nit const
raymes 2017/02/21 01:29:55 Done.
103 ContentSettingsPattern::FromString(value);
104 if (pattern == ContentSettingsPattern::Wildcard()) {
105 LOG(WARNING) << "Ignoring wildcard URL pattern: " << value;
106 continue;
107 }
108 if (pattern.IsValid() && pattern.Matches(requesting_origin_))
109 return CONTENT_SETTING_ALLOW;
110 }
111 }
112 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
113 return CONTENT_SETTING_BLOCK;
achuithb 2017/02/16 09:05:38 Wonder if there's a way to avoid the 4x repetition
raymes 2017/02/21 01:29:55 I don't think there's a simple way right now but i
114 }
115 #endif
Sergey Ulanov 2017/02/16 19:26:17 // defined(OS_CHROMEOS)
raymes 2017/02/21 01:29:55 Done.
116
61 // Check policy and content settings. 117 // Check policy and content settings.
62 blink::mojom::PermissionStatus status = 118 blink::mojom::PermissionStatus status =
63 permission_manager->GetPermissionStatus( 119 permission_manager->GetPermissionStatus(
64 permission_type, requesting_origin_, embedding_origin_); 120 permission_type, requesting_origin_, embedding_origin_);
65 switch (status) { 121 switch (status) {
66 case blink::mojom::PermissionStatus::DENIED: 122 case blink::mojom::PermissionStatus::DENIED:
67 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; 123 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
68 return CONTENT_SETTING_BLOCK; 124 return CONTENT_SETTING_BLOCK;
69 case blink::mojom::PermissionStatus::ASK: 125 case blink::mojom::PermissionStatus::ASK:
70 return CONTENT_SETTING_ASK; 126 return CONTENT_SETTING_ASK;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return false; 166 return false;
111 167
112 // Note: we check device_id before dereferencing devices. If the requested 168 // Note: we check device_id before dereferencing devices. If the requested
113 // device id is non-empty, then the corresponding device list must not be 169 // device id is non-empty, then the corresponding device list must not be
114 // NULL. 170 // NULL.
115 if (!device_id.empty() && !devices->FindById(device_id)) 171 if (!device_id.empty() && !devices->FindById(device_id))
116 return false; 172 return false;
117 173
118 return true; 174 return true;
119 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698