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

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: ChromeOSLoginMediaAccessHandler 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),
(...skipping 13 matching lines...) Expand all
49 } 38 }
50 39
51 PermissionManager* permission_manager = PermissionManager::Get(profile_); 40 PermissionManager* permission_manager = PermissionManager::Get(profile_);
52 41
53 // Find out if the kill switch is on. Set the denial reason to kill switch. 42 // Find out if the kill switch is on. Set the denial reason to kill switch.
54 if (permission_manager->IsPermissionKillSwitchOn(content_type_)) { 43 if (permission_manager->IsPermissionKillSwitchOn(content_type_)) {
55 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; 44 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON;
56 return CONTENT_SETTING_BLOCK; 45 return CONTENT_SETTING_BLOCK;
57 } 46 }
58 47
59 #if defined(OS_CHROMEOS)
60 // Special permissions if the request is coming from a ChromeOS login page.
61 chromeos::LoginDisplayHost* login_display_host =
62 chromeos::LoginDisplayHost::default_host();
63 chromeos::WebUILoginView* webui_login_view =
64 login_display_host ? login_display_host->GetWebUILoginView() : nullptr;
65 content::WebContents* login_web_contents =
66 webui_login_view ? webui_login_view->GetWebContents() : nullptr;
67 if (web_contents_ == login_web_contents) {
68 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
69 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
70 return CONTENT_SETTING_BLOCK;
71 }
72
73 // When creating new user (including supervised user), we must
74 // be able to use photo for user image.
75 if (requesting_origin_.spec() == chrome::kChromeUIOobeURL) {
76 return CONTENT_SETTING_ALLOW;
77 }
78
79 const chromeos::CrosSettings* const settings =
80 chromeos::CrosSettings::Get();
81 if (!settings) {
82 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
83 return CONTENT_SETTING_BLOCK;
84 }
85
86 const base::Value* const raw_list_value =
87 settings->GetPref(chromeos::kLoginVideoCaptureAllowedUrls);
88 if (!raw_list_value) {
89 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
90 return CONTENT_SETTING_BLOCK;
91 }
92
93 const base::ListValue* list_value;
94 const bool is_list = raw_list_value->GetAsList(&list_value);
95 DCHECK(is_list);
96 for (const auto& base_value : *list_value) {
97 std::string value;
98 if (base_value->GetAsString(&value)) {
99 const ContentSettingsPattern pattern =
100 ContentSettingsPattern::FromString(value);
101 if (pattern == ContentSettingsPattern::Wildcard()) {
102 LOG(WARNING) << "Ignoring wildcard URL pattern: " << value;
103 continue;
104 }
105 if (pattern.IsValid() && pattern.Matches(requesting_origin_))
106 return CONTENT_SETTING_ALLOW;
107 }
108 }
109
110 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
111 return CONTENT_SETTING_BLOCK;
112 }
113 #endif // defined(OS_CHROMEOS)
114
115 // Check policy and content settings. 48 // Check policy and content settings.
116 ContentSetting content_setting = 49 ContentSetting content_setting =
117 permission_manager 50 permission_manager
118 ->GetPermissionStatus(content_type_, requesting_origin_, 51 ->GetPermissionStatus(content_type_, requesting_origin_,
119 embedding_origin_) 52 embedding_origin_)
120 .content_setting; 53 .content_setting;
121 if (content_setting == CONTENT_SETTING_BLOCK) 54 if (content_setting == CONTENT_SETTING_BLOCK)
122 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; 55 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED;
123 return content_setting; 56 return content_setting;
124 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698