Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5164)

Unified Diff: chrome/browser/media/tab_capture_access_handler.cc

Issue 1095393004: Refactor: Make MediaCaptureDevicesDispatcher have pluggable handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tryjob error. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media/tab_capture_access_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« no previous file with comments | « chrome/browser/media/tab_capture_access_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698