OLD | NEW |
| (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 <utility> | |
8 | |
9 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | |
10 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | |
11 #include "chrome/browser/media/media_stream_capture_indicator.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "content/public/browser/web_contents.h" | |
14 #include "extensions/common/permissions/permissions_data.h" | |
15 | |
16 TabCaptureAccessHandler::TabCaptureAccessHandler() { | |
17 } | |
18 | |
19 TabCaptureAccessHandler::~TabCaptureAccessHandler() { | |
20 } | |
21 | |
22 bool TabCaptureAccessHandler::SupportsStreamType( | |
23 const content::MediaStreamType type, | |
24 const extensions::Extension* extension) { | |
25 return type == content::MEDIA_TAB_VIDEO_CAPTURE || | |
26 type == content::MEDIA_TAB_AUDIO_CAPTURE; | |
27 } | |
28 | |
29 bool TabCaptureAccessHandler::CheckMediaAccessPermission( | |
30 content::WebContents* web_contents, | |
31 const GURL& security_origin, | |
32 content::MediaStreamType type, | |
33 const extensions::Extension* extension) { | |
34 return false; | |
35 } | |
36 | |
37 void TabCaptureAccessHandler::HandleRequest( | |
38 content::WebContents* web_contents, | |
39 const content::MediaStreamRequest& request, | |
40 const content::MediaResponseCallback& callback, | |
41 const extensions::Extension* extension) { | |
42 content::MediaStreamDevices devices; | |
43 std::unique_ptr<content::MediaStreamUI> ui; | |
44 | |
45 if (!extension) | |
46 callback.Run(devices, content::MEDIA_DEVICE_TAB_CAPTURE_FAILURE, | |
47 std::move(ui)); | |
48 | |
49 Profile* profile = | |
50 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
51 extensions::TabCaptureRegistry* tab_capture_registry = | |
52 extensions::TabCaptureRegistry::Get(profile); | |
53 if (!tab_capture_registry) { | |
54 NOTREACHED(); | |
55 callback.Run(devices, content::MEDIA_DEVICE_INVALID_STATE, std::move(ui)); | |
56 return; | |
57 } | |
58 const bool tab_capture_allowed = tab_capture_registry->VerifyRequest( | |
59 request.render_process_id, request.render_frame_id, extension->id()); | |
60 | |
61 if (request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE && | |
62 tab_capture_allowed && | |
63 extension->permissions_data()->HasAPIPermission( | |
64 extensions::APIPermission::kTabCapture)) { | |
65 devices.push_back(content::MediaStreamDevice( | |
66 content::MEDIA_TAB_AUDIO_CAPTURE, std::string(), std::string())); | |
67 } | |
68 | |
69 if (request.video_type == content::MEDIA_TAB_VIDEO_CAPTURE && | |
70 tab_capture_allowed && | |
71 extension->permissions_data()->HasAPIPermission( | |
72 extensions::APIPermission::kTabCapture)) { | |
73 devices.push_back(content::MediaStreamDevice( | |
74 content::MEDIA_TAB_VIDEO_CAPTURE, std::string(), std::string())); | |
75 } | |
76 | |
77 if (!devices.empty()) { | |
78 ui = MediaCaptureDevicesDispatcher::GetInstance() | |
79 ->GetMediaStreamCaptureIndicator() | |
80 ->RegisterMediaStream(web_contents, devices); | |
81 } | |
82 UpdateExtensionTrusted(request, extension); | |
83 callback.Run(devices, devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE | |
84 : content::MEDIA_DEVICE_OK, | |
85 std::move(ui)); | |
86 } | |
OLD | NEW |