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

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

Powered by Google App Engine
This is Rietveld 408576698