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 "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) |
| 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::SupportsRequest( |
| 24 const content::MediaStreamRequest& request, |
| 25 const extensions::Extension* extension) { |
| 26 return request.video_type == content::MEDIA_TAB_VIDEO_CAPTURE || |
| 27 request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE; |
| 28 } |
| 29 |
| 30 void TabCaptureAccessHandler::HandleRequest( |
| 31 content::WebContents* web_contents, |
| 32 const content::MediaStreamRequest& request, |
| 33 const content::MediaResponseCallback& callback, |
| 34 const extensions::Extension* extension) { |
| 35 content::MediaStreamDevices devices; |
| 36 scoped_ptr<content::MediaStreamUI> ui; |
| 37 |
| 38 #if defined(ENABLE_EXTENSIONS) |
| 39 Profile* profile = |
| 40 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 41 extensions::TabCaptureRegistry* tab_capture_registry = |
| 42 extensions::TabCaptureRegistry::Get(profile); |
| 43 if (!tab_capture_registry) { |
| 44 NOTREACHED(); |
| 45 callback.Run(devices, content::MEDIA_DEVICE_INVALID_STATE, ui.Pass()); |
| 46 return; |
| 47 } |
| 48 const bool tab_capture_allowed = tab_capture_registry->VerifyRequest( |
| 49 request.render_process_id, request.render_frame_id, extension->id()); |
| 50 |
| 51 if (request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE && |
| 52 tab_capture_allowed && |
| 53 extension->permissions_data()->HasAPIPermission( |
| 54 extensions::APIPermission::kTabCapture)) { |
| 55 devices.push_back(content::MediaStreamDevice( |
| 56 content::MEDIA_TAB_AUDIO_CAPTURE, std::string(), std::string())); |
| 57 } |
| 58 |
| 59 if (request.video_type == content::MEDIA_TAB_VIDEO_CAPTURE && |
| 60 tab_capture_allowed && |
| 61 extension->permissions_data()->HasAPIPermission( |
| 62 extensions::APIPermission::kTabCapture)) { |
| 63 devices.push_back(content::MediaStreamDevice( |
| 64 content::MEDIA_TAB_VIDEO_CAPTURE, std::string(), std::string())); |
| 65 } |
| 66 |
| 67 if (!devices.empty()) { |
| 68 ui = MediaCaptureDevicesDispatcher::GetInstance() |
| 69 ->GetMediaStreamCaptureIndicator() |
| 70 ->RegisterMediaStream(web_contents, devices); |
| 71 } |
| 72 callback.Run(devices, devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE |
| 73 : content::MEDIA_DEVICE_OK, |
| 74 ui.Pass()); |
| 75 #else // defined(ENABLE_EXTENSIONS) |
| 76 callback.Run(devices, content::MEDIA_DEVICE_TAB_CAPTURE_FAILURE, ui.Pass()); |
| 77 #endif // defined(ENABLE_EXTENSIONS) |
| 78 } |
OLD | NEW |