Chromium Code Reviews| Index: chrome/browser/media/tab_capture_access_handler.cc |
| diff --git a/chrome/browser/media/tab_capture_access_handler.cc b/chrome/browser/media/tab_capture_access_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8139a8092f6fdaffa3647bd2df727772b7c59324 |
| --- /dev/null |
| +++ b/chrome/browser/media/tab_capture_access_handler.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/media/tab_capture_access_handler.h" |
| + |
| +#include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| +#include "chrome/browser/media/media_stream_capture_indicator.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +#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.
|
| +#include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
| +#include "extensions/common/permissions/permissions_data.h" |
| +#endif |
| + |
| +TabCaptureAccessHandler::TabCaptureAccessHandler() { |
| +} |
| + |
| +TabCaptureAccessHandler::~TabCaptureAccessHandler() { |
| +} |
| + |
| +bool TabCaptureAccessHandler::SupportsStreamType( |
| + const content::MediaStreamType type, |
| + const extensions::Extension* extension) { |
| + return type == content::MEDIA_TAB_VIDEO_CAPTURE || |
| + type == content::MEDIA_TAB_AUDIO_CAPTURE; |
| +} |
| + |
| +bool TabCaptureAccessHandler::CheckMediaAccessPermission( |
| + content::WebContents* web_contents, |
| + const GURL& security_origin, |
| + content::MediaStreamType type, |
| + const extensions::Extension* extension) { |
| + return false; |
| +} |
| + |
| +void TabCaptureAccessHandler::HandleRequest( |
| + content::WebContents* web_contents, |
| + const content::MediaStreamRequest& request, |
| + const content::MediaResponseCallback& callback, |
| + const extensions::Extension* extension) { |
| + content::MediaStreamDevices devices; |
| + scoped_ptr<content::MediaStreamUI> ui; |
| + |
| +#if defined(ENABLE_EXTENSIONS) |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + extensions::TabCaptureRegistry* tab_capture_registry = |
| + extensions::TabCaptureRegistry::Get(profile); |
| + if (!tab_capture_registry) { |
| + NOTREACHED(); |
| + callback.Run(devices, content::MEDIA_DEVICE_INVALID_STATE, ui.Pass()); |
| + return; |
| + } |
| + const bool tab_capture_allowed = tab_capture_registry->VerifyRequest( |
| + request.render_process_id, request.render_frame_id, extension->id()); |
| + |
| + if (request.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE && |
| + tab_capture_allowed && |
| + extension->permissions_data()->HasAPIPermission( |
| + extensions::APIPermission::kTabCapture)) { |
| + devices.push_back(content::MediaStreamDevice( |
| + content::MEDIA_TAB_AUDIO_CAPTURE, std::string(), std::string())); |
| + } |
| + |
| + if (request.video_type == content::MEDIA_TAB_VIDEO_CAPTURE && |
| + tab_capture_allowed && |
| + extension->permissions_data()->HasAPIPermission( |
| + extensions::APIPermission::kTabCapture)) { |
| + devices.push_back(content::MediaStreamDevice( |
| + content::MEDIA_TAB_VIDEO_CAPTURE, std::string(), std::string())); |
| + } |
| + |
| + if (!devices.empty()) { |
| + ui = MediaCaptureDevicesDispatcher::GetInstance() |
| + ->GetMediaStreamCaptureIndicator() |
| + ->RegisterMediaStream(web_contents, devices); |
| + } |
| + callback.Run(devices, devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE |
| + : content::MEDIA_DEVICE_OK, |
| + ui.Pass()); |
| +#else // defined(ENABLE_EXTENSIONS) |
| + callback.Run(devices, content::MEDIA_DEVICE_TAB_CAPTURE_FAILURE, ui.Pass()); |
| +#endif // defined(ENABLE_EXTENSIONS) |
| +} |