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

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

Issue 2746873004: Move ChromeOS login media access logic into a MediaAccessHandler (Closed)
Patch Set: Move ChromeOS login media access logic into a MediaAccessHandler Created 3 years, 8 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"
8 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h"
9 #include "chrome/browser/permissions/permission_context_base.h" 7 #include "chrome/browser/permissions/permission_context_base.h"
10 #include "chrome/browser/permissions/permission_manager.h" 8 #include "chrome/browser/permissions/permission_manager.h"
11 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/permission_manager.h" 11 #include "content/public/browser/permission_manager.h"
15 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/url_constants.h" 13 #include "content/public/common/url_constants.h"
17 #include "extensions/common/constants.h" 14 #include "extensions/common/constants.h"
18 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
19
20 #if defined(OS_CHROMEOS)
21 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
22 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
23 #include "chrome/browser/chromeos/settings/cros_settings.h"
24 #include "chromeos/settings/cros_settings_names.h"
25 #endif
26 15
27 MediaPermission::MediaPermission(ContentSettingsType content_type, 16 MediaPermission::MediaPermission(ContentSettingsType content_type,
28 const GURL& requesting_origin, 17 const GURL& requesting_origin,
29 const GURL& embedding_origin, 18 const GURL& embedding_origin,
30 Profile* profile, 19 Profile* profile,
31 content::WebContents* web_contents) 20 content::WebContents* web_contents)
32 : content_type_(content_type), 21 : content_type_(content_type),
33 requesting_origin_(requesting_origin), 22 requesting_origin_(requesting_origin),
34 embedding_origin_(embedding_origin), 23 embedding_origin_(embedding_origin),
35 profile_(profile), 24 profile_(profile),
36 web_contents_(web_contents) { 25 web_contents_(web_contents) {
37 // Currently |web_contents_| is only used on ChromeOS but it's not worth 26 // Currently |web_contents_| is only used on ChromeOS but it's not worth
38 // #ifdef'ing out all its usage, so just mark it used here. 27 // #ifdef'ing out all its usage, so just mark it used here.
39 (void)web_contents_; 28 (void)web_contents_;
40 } 29 }
41 30
42 ContentSetting MediaPermission::GetPermissionStatus( 31 ContentSetting MediaPermission::GetPermissionStatus(
43 content::MediaStreamRequestResult* denial_reason) const { 32 content::MediaStreamRequestResult* denial_reason) const {
44 DCHECK(!requesting_origin_.is_empty()); 33 DCHECK(!requesting_origin_.is_empty());
45 34
46 PermissionManager* permission_manager = PermissionManager::Get(profile_); 35 PermissionManager* permission_manager = PermissionManager::Get(profile_);
47 36
48 // Find out if the kill switch is on. Set the denial reason to kill switch. 37 // Find out if the kill switch is on. Set the denial reason to kill switch.
49 if (permission_manager->IsPermissionKillSwitchOn(content_type_)) { 38 if (permission_manager->IsPermissionKillSwitchOn(content_type_)) {
50 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; 39 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON;
51 return CONTENT_SETTING_BLOCK; 40 return CONTENT_SETTING_BLOCK;
52 } 41 }
53 42
54 #if defined(OS_CHROMEOS)
55 // Special permissions if the request is coming from a ChromeOS login page.
56 chromeos::LoginDisplayHost* login_display_host =
57 chromeos::LoginDisplayHost::default_host();
58 chromeos::WebUILoginView* webui_login_view =
59 login_display_host ? login_display_host->GetWebUILoginView() : nullptr;
60 content::WebContents* login_web_contents =
61 webui_login_view ? webui_login_view->GetWebContents() : nullptr;
62 if (web_contents_ == login_web_contents) {
63 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
64 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
65 return CONTENT_SETTING_BLOCK;
66 }
67
68 // When creating new user (including supervised user), we must
69 // be able to use photo for user image.
70 if (requesting_origin_.spec() == chrome::kChromeUIOobeURL) {
71 return CONTENT_SETTING_ALLOW;
72 }
73
74 const chromeos::CrosSettings* const settings =
75 chromeos::CrosSettings::Get();
76 if (!settings) {
77 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
78 return CONTENT_SETTING_BLOCK;
79 }
80
81 const base::Value* const raw_list_value =
82 settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls);
83 if (!raw_list_value) {
84 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
85 return CONTENT_SETTING_BLOCK;
86 }
87
88 const base::ListValue* list_value;
89 const bool is_list = raw_list_value->GetAsList(&list_value);
90 DCHECK(is_list);
91 for (const auto& base_value : *list_value) {
92 std::string value;
93 if (base_value->GetAsString(&value)) {
94 const ContentSettingsPattern pattern =
95 ContentSettingsPattern::FromString(value);
96 if (pattern == ContentSettingsPattern::Wildcard()) {
97 LOG(WARNING) << "Ignoring wildcard URL pattern: " << value;
98 continue;
99 }
100 if (pattern.IsValid() && pattern.Matches(requesting_origin_))
101 return CONTENT_SETTING_ALLOW;
102 }
103 }
104
105 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
106 return CONTENT_SETTING_BLOCK;
107 }
108 #endif // defined(OS_CHROMEOS)
109
110 // Check policy and content settings. 43 // Check policy and content settings.
111 ContentSetting content_setting = 44 ContentSetting content_setting =
112 permission_manager 45 permission_manager
113 ->GetPermissionStatus(content_type_, requesting_origin_, 46 ->GetPermissionStatus(content_type_, requesting_origin_,
114 embedding_origin_) 47 embedding_origin_)
115 .content_setting; 48 .content_setting;
116 if (content_setting == CONTENT_SETTING_BLOCK) 49 if (content_setting == CONTENT_SETTING_BLOCK)
117 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; 50 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
118 return content_setting; 51 return content_setting;
119 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698