| 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..650ca95bdd364310cbcef7a1662d335bd5a7f22c
|
| --- /dev/null
|
| +++ b/chrome/browser/media/tab_capture_access_handler.cc
|
| @@ -0,0 +1,70 @@
|
| +// Copyright (c) 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_stream_capture_indicator.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +
|
| +#if defined(ENABLE_EXTENSIONS)
|
| +#include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h"
|
| +#include "extensions/common/permissions/permissions_data.h"
|
| +#endif
|
| +
|
| +TabCaptureAccessHandler::TabCaptureAccessHandler(
|
| + scoped_refptr<MediaStreamCaptureIndicator> capture_indicator)
|
| + : media_stream_capture_indicator_(capture_indicator) {
|
| +}
|
| +
|
| +TabCaptureAccessHandler::~TabCaptureAccessHandler() {
|
| +}
|
| +
|
| +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 = media_stream_capture_indicator_->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)
|
| +}
|
|
|