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..d0cc06a06b6a25192bab131f638072028b3c2363 |
--- /dev/null |
+++ b/chrome/browser/media/tab_capture_access_handler.cc |
@@ -0,0 +1,82 @@ |
+// 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/extensions/api/tab_capture/tab_capture_registry.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" |
+#include "extensions/common/permissions/permissions_data.h" |
+ |
+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 (!extension) |
+ callback.Run(devices, content::MEDIA_DEVICE_TAB_CAPTURE_FAILURE, ui.Pass()); |
+ |
+ 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()); |
+} |