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

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

Issue 1095393004: Refactor: Make MediaCaptureDevicesDispatcher have pluggable handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 5 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/extension_media_access_handler.h"
6
7 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
8 #include "chrome/browser/media/media_stream_capture_indicator.h"
9 #include "chrome/browser/media/media_stream_device_permissions.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/pref_names.h"
12 #include "content/public/browser/web_contents.h"
13 #include "extensions/common/extension.h"
14 #include "extensions/common/permissions/permissions_data.h"
15
16 ExtensionMediaAccessHandler::ExtensionMediaAccessHandler() {
17 }
18
19 ExtensionMediaAccessHandler::~ExtensionMediaAccessHandler() {
20 }
21
22 bool ExtensionMediaAccessHandler::SupportsRequest(
23 const content::MediaStreamRequest& request,
24 const extensions::Extension* extension) {
25 return extension && (extension->is_platform_app() ||
26 extension->is_media_request_white_listed());
27 }
28
29 void ExtensionMediaAccessHandler::HandleRequest(
30 content::WebContents* web_contents,
31 const content::MediaStreamRequest& request,
32 const content::MediaResponseCallback& callback,
33 const extensions::Extension* extension) {
34 // TODO(vrk): This code is largely duplicated in
35 // MediaStreamDevicesController::Accept(). Move this code into a shared method
36 // between the two classes.
37
38 Profile* profile =
39 Profile::FromBrowserContext(web_contents->GetBrowserContext());
40
41 bool audio_allowed =
42 request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE &&
43 extension->permissions_data()->HasAPIPermission(
44 extensions::APIPermission::kAudioCapture) &&
45 GetDevicePolicy(profile, extension->url(), prefs::kAudioCaptureAllowed,
46 prefs::kAudioCaptureAllowedUrls) != ALWAYS_DENY;
47 bool video_allowed =
48 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
49 extension->permissions_data()->HasAPIPermission(
50 extensions::APIPermission::kVideoCapture) &&
51 GetDevicePolicy(profile, extension->url(), prefs::kVideoCaptureAllowed,
52 prefs::kVideoCaptureAllowedUrls) != ALWAYS_DENY;
53
54 bool get_default_audio_device = audio_allowed;
55 bool get_default_video_device = video_allowed;
56
57 content::MediaStreamDevices devices;
58
59 // Set an initial error result. If neither audio or video is allowed, we'll
60 // never try to get any device below but will just create |ui| and return an
61 // empty list with "invalid state" result. If at least one is allowed, we'll
62 // try to get device(s), and if failure, we want to return "no hardware"
63 // result.
64 // TODO(grunell): The invalid state result should be changed to a new denied
65 // result + a dcheck to ensure at least one of audio or video types is
66 // capture.
67 content::MediaStreamRequestResult result =
68 (audio_allowed || video_allowed) ? content::MEDIA_DEVICE_NO_HARDWARE
69 : content::MEDIA_DEVICE_INVALID_STATE;
70
71 // Get the exact audio or video device if an id is specified.
72 // We only set any error result here and before running the callback change
73 // it to OK if we have any device.
74 if (audio_allowed && !request.requested_audio_device_id.empty()) {
75 const content::MediaStreamDevice* audio_device =
76 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedAudioDevice(
77 request.requested_audio_device_id);
78 if (audio_device) {
79 devices.push_back(*audio_device);
80 get_default_audio_device = false;
81 }
82 }
83 if (video_allowed && !request.requested_video_device_id.empty()) {
84 const content::MediaStreamDevice* video_device =
85 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedVideoDevice(
86 request.requested_video_device_id);
87 if (video_device) {
88 devices.push_back(*video_device);
89 get_default_video_device = false;
90 }
91 }
92
93 // If either or both audio and video devices were requested but not
94 // specified by id, get the default devices.
95 if (get_default_audio_device || get_default_video_device) {
96 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile(
97 profile, get_default_audio_device, get_default_video_device, &devices);
98 }
99
100 scoped_ptr<content::MediaStreamUI> ui;
101 if (!devices.empty()) {
102 result = content::MEDIA_DEVICE_OK;
103 ui = MediaCaptureDevicesDispatcher::GetInstance()
104 ->GetMediaStreamCaptureIndicator()
105 ->RegisterMediaStream(web_contents, devices);
106 }
107
108 callback.Run(devices, result, ui.Pass());
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698