OLD | NEW |
(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/tab_capture_access_handler.h" |
| 6 |
| 7 #include "chrome/browser/media/media_stream_capture_indicator.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 |
| 10 #if defined(ENABLE_EXTENSIONS) |
| 11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
| 12 #include "extensions/common/permissions/permissions_data.h" |
| 13 #endif |
| 14 |
| 15 TabCaptureAccessHandler::TabCaptureAccessHandler( |
| 16 scoped_refptr<MediaStreamCaptureIndicator> capture_indicator) |
| 17 : media_stream_capture_indicator_(capture_indicator) { |
| 18 } |
| 19 |
| 20 TabCaptureAccessHandler::~TabCaptureAccessHandler() { |
| 21 } |
| 22 |
| 23 void TabCaptureAccessHandler::HandleRequest( |
| 24 content::WebContents* web_contents, |
| 25 const content::MediaStreamRequest& request, |
| 26 const content::MediaResponseCallback& callback, |
| 27 const extensions::Extension* extension) { |
| 28 content::MediaStreamDevices devices; |
| 29 scoped_ptr<content::MediaStreamUI> ui; |
| 30 |
| 31 #if defined(ENABLE_EXTENSIONS) |
| 32 Profile* profile = |
| 33 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 34 extensions::TabCaptureRegistry* tab_capture_registry = |
| 35 extensions::TabCaptureRegistry::Get(profile); |
| 36 if (!tab_capture_registry) { |
| 37 NOTREACHED(); |
| 38 callback.Run(devices, content::MEDIA_DEVICE_INVALID_STATE, ui.Pass()); |
| 39 return; |
| 40 } |
| 41 const bool tab_capture_allowed = tab_capture_registry->VerifyRequest( |
| 42 request.render_process_id, request.render_frame_id, extension->id()); |
| 43 |
| 44 if (request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE && |
| 45 tab_capture_allowed && |
| 46 extension->permissions_data()->HasAPIPermission( |
| 47 extensions::APIPermission::kTabCapture)) { |
| 48 devices.push_back(content::MediaStreamDevice( |
| 49 content::MEDIA_TAB_AUDIO_CAPTURE, std::string(), std::string())); |
| 50 } |
| 51 |
| 52 if (request.video_type == content::MEDIA_TAB_VIDEO_CAPTURE && |
| 53 tab_capture_allowed && |
| 54 extension->permissions_data()->HasAPIPermission( |
| 55 extensions::APIPermission::kTabCapture)) { |
| 56 devices.push_back(content::MediaStreamDevice( |
| 57 content::MEDIA_TAB_VIDEO_CAPTURE, std::string(), std::string())); |
| 58 } |
| 59 |
| 60 if (!devices.empty()) { |
| 61 ui = media_stream_capture_indicator_->RegisterMediaStream(web_contents, |
| 62 devices); |
| 63 } |
| 64 callback.Run(devices, devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE |
| 65 : content::MEDIA_DEVICE_OK, |
| 66 ui.Pass()); |
| 67 #else // defined(ENABLE_EXTENSIONS) |
| 68 callback.Run(devices, content::MEDIA_DEVICE_TAB_CAPTURE_FAILURE, ui.Pass()); |
| 69 #endif // defined(ENABLE_EXTENSIONS) |
| 70 } |
OLD | NEW |