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

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/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 chromeos::LoginDisplayHost* login_display_host =
61 chromeos::LoginDisplayHost::default_host();
62 chromeos::WebUILoginView* webui_login_view =
63 login_display_host ? login_display_host->GetWebUILoginView() : nullptr;
64 content::WebContents* login_web_contents =
65 webui_login_view ? webui_login_view->GetWebContents() : nullptr;
66 if (web_contents_ == login_web_contents) {
67 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
68 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
69 return CONTENT_SETTING_BLOCK;
70 }
71
72 const chromeos::CrosSettings* const settings =
73 chromeos::CrosSettings::Get();
74 if (!settings) {
75 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
76 return CONTENT_SETTING_BLOCK;
77 }
78
79 const base::Value* const raw_list_value =
80 settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls);
81 if (!raw_list_value) {
82 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
83 return CONTENT_SETTING_BLOCK;
84 }
85
86 const base::ListValue* list_value;
87 const bool is_list = raw_list_value->GetAsList(&list_value);
88 DCHECK(is_list);
89 for (const auto& base_value : *list_value) {
90 std::string value;
91 if (base_value->GetAsString(&value)) {
92 const ContentSettingsPattern pattern =
93 ContentSettingsPattern::FromString(value);
94 if (pattern == ContentSettingsPattern::Wildcard()) {
95 LOG(WARNING) << "Ignoring wildcard URL pattern: " << value;
96 continue;
97 }
98 if (pattern.IsValid() && pattern.Matches(requesting_origin_))
99 return CONTENT_SETTING_ALLOW;
100 }
101 }
102
103 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
104 return CONTENT_SETTING_BLOCK;
105 }
106 #endif // defined(OS_CHROMEOS)
107
44 // Check policy and content settings. 108 // Check policy and content settings.
45 blink::mojom::PermissionStatus status = 109 blink::mojom::PermissionStatus status =
46 permission_manager->GetPermissionStatus( 110 permission_manager->GetPermissionStatus(
47 content_type_, requesting_origin_, embedding_origin_); 111 content_type_, requesting_origin_, embedding_origin_);
48 switch (status) { 112 switch (status) {
49 case blink::mojom::PermissionStatus::DENIED: 113 case blink::mojom::PermissionStatus::DENIED:
50 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; 114 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
51 return CONTENT_SETTING_BLOCK; 115 return CONTENT_SETTING_BLOCK;
52 case blink::mojom::PermissionStatus::ASK: 116 case blink::mojom::PermissionStatus::ASK:
53 return CONTENT_SETTING_ASK; 117 return CONTENT_SETTING_ASK;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return false; 157 return false;
94 158
95 // Note: we check device_id before dereferencing devices. If the requested 159 // 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 160 // device id is non-empty, then the corresponding device list must not be
97 // NULL. 161 // NULL.
98 if (!device_id.empty() && !devices->FindById(device_id)) 162 if (!device_id.empty() && !devices->FindById(device_id))
99 return false; 163 return false;
100 164
101 return true; 165 return true;
102 } 166 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc/media_permission.h ('k') | chrome/browser/media/webrtc/media_stream_devices_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698