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

Side by Side Diff: chrome/browser/media/media_access_handler.cc

Issue 2746873004: Move ChromeOS login media access logic into a MediaAccessHandler (Closed)
Patch Set: Move SAML access logic into MediaAccessHandler Created 3 years, 9 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 2017 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/extension_media_access_handler.h" 5 #include "chrome/browser/media/saml_media_access_handler.h"
6
7 #include <utility>
8 6
9 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 7 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
10 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" 8 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
11 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h"
12 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/pref_names.h"
14 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
15 #include "extensions/common/extension.h"
16 #include "extensions/common/permissions/permissions_data.h"
17 11
18 namespace { 12 // static
19 13 void MediaAccessHandler::CheckDevicesAndRunCallback(
20 // This is a short-term solution to grant camera and/or microphone access to
21 // extensions:
22 // 1. Virtual keyboard extension.
23 // 2. Flutter gesture recognition extension.
24 // 3. TODO(smus): Airbender experiment 1.
25 // 4. TODO(smus): Airbender experiment 2.
26 // 5. Hotwording component extension.
27 // 6. XKB input method component extension.
28 // 7. M17n/T13n/CJK input method component extension.
29 // Once http://crbug.com/292856 is fixed, remove this whitelist.
30 bool IsMediaRequestWhitelistedForExtension(
31 const extensions::Extension* extension) {
32 return extension->id() == "mppnpdlheglhdfmldimlhpnegondlapf" ||
33 extension->id() == "jokbpnebhdcladagohdnfgjcpejggllo" ||
34 extension->id() == "clffjmdilanldobdnedchkdbofoimcgb" ||
35 extension->id() == "nnckehldicaciogcbchegobnafnjkcne" ||
36 extension->id() == "nbpagnldghgfoolbancepceaanlmhfmd" ||
37 extension->id() == "jkghodnilhceideoidjikpgommlajknk" ||
38 extension->id() == "gjaehgfemfahhmlgpdfknkhdnemmolop";
39 }
40
41 } // namespace
42
43 ExtensionMediaAccessHandler::ExtensionMediaAccessHandler() {
44 }
45
46 ExtensionMediaAccessHandler::~ExtensionMediaAccessHandler() {
47 }
48
49 bool ExtensionMediaAccessHandler::SupportsStreamType(
50 const content::MediaStreamType type,
51 const extensions::Extension* extension) {
52 return extension && (extension->is_platform_app() ||
53 IsMediaRequestWhitelistedForExtension(extension)) &&
54 (type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
55 type == content::MEDIA_DEVICE_VIDEO_CAPTURE);
56 }
57
58 bool ExtensionMediaAccessHandler::CheckMediaAccessPermission(
59 content::WebContents* web_contents,
60 const GURL& security_origin,
61 content::MediaStreamType type,
62 const extensions::Extension* extension) {
63 return extension->permissions_data()->HasAPIPermission(
64 type == content::MEDIA_DEVICE_AUDIO_CAPTURE
65 ? extensions::APIPermission::kAudioCapture
66 : extensions::APIPermission::kVideoCapture);
67 }
68
69 void ExtensionMediaAccessHandler::HandleRequest(
70 content::WebContents* web_contents, 14 content::WebContents* web_contents,
71 const content::MediaStreamRequest& request, 15 const content::MediaStreamRequest& request,
72 const content::MediaResponseCallback& callback, 16 const content::MediaResponseCallback& callback,
73 const extensions::Extension* extension) { 17 bool audio_allowed,
18 bool video_allowed) {
74 // TODO(vrk): This code is largely duplicated in 19 // TODO(vrk): This code is largely duplicated in
75 // MediaStreamDevicesController::Accept(). Move this code into a shared method 20 // MediaStreamDevicesController::Accept(). Move this code into a shared method
Sergey Ulanov 2017/03/15 22:48:30 That code is in MediaStreamDevicesController::GetD
raymes 2017/03/16 02:30:37 Done.
76 // between the two classes. 21 // between the two classes.
77
78 Profile* profile =
79 Profile::FromBrowserContext(web_contents->GetBrowserContext());
80
81 bool audio_allowed =
82 request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE &&
83 extension->permissions_data()->HasAPIPermission(
84 extensions::APIPermission::kAudioCapture) &&
85 GetDevicePolicy(profile, extension->url(), prefs::kAudioCaptureAllowed,
86 prefs::kAudioCaptureAllowedUrls) != ALWAYS_DENY;
87 bool video_allowed =
88 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
89 extension->permissions_data()->HasAPIPermission(
90 extensions::APIPermission::kVideoCapture) &&
91 GetDevicePolicy(profile, extension->url(), prefs::kVideoCaptureAllowed,
92 prefs::kVideoCaptureAllowedUrls) != ALWAYS_DENY;
93
94 bool get_default_audio_device = audio_allowed; 22 bool get_default_audio_device = audio_allowed;
95 bool get_default_video_device = video_allowed; 23 bool get_default_video_device = video_allowed;
96 24
97 content::MediaStreamDevices devices; 25 content::MediaStreamDevices devices;
98 26
99 // Set an initial error result. If neither audio or video is allowed, we'll 27 // Set an initial error result. If neither audio or video is allowed, we'll
100 // never try to get any device below but will just create |ui| and return an 28 // never try to get any device below but will just create |ui| and return an
101 // empty list with "invalid state" result. If at least one is allowed, we'll 29 // empty list with "invalid state" result. If at least one is allowed, we'll
102 // try to get device(s), and if failure, we want to return "no hardware" 30 // try to get device(s), and if failure, we want to return "no hardware"
103 // result. 31 // result.
(...skipping 19 matching lines...) Expand all
123 if (video_allowed && !request.requested_video_device_id.empty()) { 51 if (video_allowed && !request.requested_video_device_id.empty()) {
124 const content::MediaStreamDevice* video_device = 52 const content::MediaStreamDevice* video_device =
125 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedVideoDevice( 53 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedVideoDevice(
126 request.requested_video_device_id); 54 request.requested_video_device_id);
127 if (video_device) { 55 if (video_device) {
128 devices.push_back(*video_device); 56 devices.push_back(*video_device);
129 get_default_video_device = false; 57 get_default_video_device = false;
130 } 58 }
131 } 59 }
132 60
61 Profile* profile =
62 Profile::FromBrowserContext(web_contents->GetBrowserContext());
63
133 // If either or both audio and video devices were requested but not 64 // If either or both audio and video devices were requested but not
134 // specified by id, get the default devices. 65 // specified by id, get the default devices.
135 if (get_default_audio_device || get_default_video_device) { 66 if (get_default_audio_device || get_default_video_device) {
136 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile( 67 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile(
137 profile, get_default_audio_device, get_default_video_device, &devices); 68 profile, get_default_audio_device, get_default_video_device, &devices);
138 } 69 }
139 70
140 std::unique_ptr<content::MediaStreamUI> ui; 71 std::unique_ptr<content::MediaStreamUI> ui;
141 if (!devices.empty()) { 72 if (!devices.empty()) {
142 result = content::MEDIA_DEVICE_OK; 73 result = content::MEDIA_DEVICE_OK;
143 ui = MediaCaptureDevicesDispatcher::GetInstance() 74 ui = MediaCaptureDevicesDispatcher::GetInstance()
144 ->GetMediaStreamCaptureIndicator() 75 ->GetMediaStreamCaptureIndicator()
145 ->RegisterMediaStream(web_contents, devices); 76 ->RegisterMediaStream(web_contents, devices);
146 } 77 }
147 78
148 callback.Run(devices, result, std::move(ui)); 79 callback.Run(devices, result, std::move(ui));
149 } 80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698