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