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

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

Issue 1095393004: Refactor: Make MediaCaptureDevicesDispatcher have pluggable handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address review comments of ps#2 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/tab_capture_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/profiles/profile.h"
10 #include "content/public/browser/web_contents.h"
11
12 #if defined(ENABLE_EXTENSIONS)
Sergey Ulanov 2015/06/01 23:39:18 This file doesn't need to be compiled when extensi
changbin 2015/06/02 14:20:09 Done.
13 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h"
14 #include "extensions/common/permissions/permissions_data.h"
15 #endif
16
17 TabCaptureAccessHandler::TabCaptureAccessHandler() {
18 }
19
20 TabCaptureAccessHandler::~TabCaptureAccessHandler() {
21 }
22
23 bool TabCaptureAccessHandler::SupportsStreamType(
24 const content::MediaStreamType type,
25 const extensions::Extension* extension) {
26 return type == content::MEDIA_TAB_VIDEO_CAPTURE ||
27 type == content::MEDIA_TAB_AUDIO_CAPTURE;
28 }
29
30 bool TabCaptureAccessHandler::CheckMediaAccessPermission(
31 content::WebContents* web_contents,
32 const GURL& security_origin,
33 content::MediaStreamType type,
34 const extensions::Extension* extension) {
35 return false;
36 }
37
38 void TabCaptureAccessHandler::HandleRequest(
39 content::WebContents* web_contents,
40 const content::MediaStreamRequest& request,
41 const content::MediaResponseCallback& callback,
42 const extensions::Extension* extension) {
43 content::MediaStreamDevices devices;
44 scoped_ptr<content::MediaStreamUI> ui;
45
46 #if defined(ENABLE_EXTENSIONS)
47 Profile* profile =
48 Profile::FromBrowserContext(web_contents->GetBrowserContext());
49 extensions::TabCaptureRegistry* tab_capture_registry =
50 extensions::TabCaptureRegistry::Get(profile);
51 if (!tab_capture_registry) {
52 NOTREACHED();
53 callback.Run(devices, content::MEDIA_DEVICE_INVALID_STATE, ui.Pass());
54 return;
55 }
56 const bool tab_capture_allowed = tab_capture_registry->VerifyRequest(
57 request.render_process_id, request.render_frame_id, extension->id());
58
59 if (request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE &&
60 tab_capture_allowed &&
61 extension->permissions_data()->HasAPIPermission(
62 extensions::APIPermission::kTabCapture)) {
63 devices.push_back(content::MediaStreamDevice(
64 content::MEDIA_TAB_AUDIO_CAPTURE, std::string(), std::string()));
65 }
66
67 if (request.video_type == content::MEDIA_TAB_VIDEO_CAPTURE &&
68 tab_capture_allowed &&
69 extension->permissions_data()->HasAPIPermission(
70 extensions::APIPermission::kTabCapture)) {
71 devices.push_back(content::MediaStreamDevice(
72 content::MEDIA_TAB_VIDEO_CAPTURE, std::string(), std::string()));
73 }
74
75 if (!devices.empty()) {
76 ui = MediaCaptureDevicesDispatcher::GetInstance()
77 ->GetMediaStreamCaptureIndicator()
78 ->RegisterMediaStream(web_contents, devices);
79 }
80 callback.Run(devices, devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE
81 : content::MEDIA_DEVICE_OK,
82 ui.Pass());
83 #else // defined(ENABLE_EXTENSIONS)
84 callback.Run(devices, content::MEDIA_DEVICE_TAB_CAPTURE_FAILURE, ui.Pass());
85 #endif // defined(ENABLE_EXTENSIONS)
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698