| Index: extensions/shell/browser/media_capture_util.cc
|
| diff --git a/extensions/shell/browser/media_capture_util.cc b/extensions/shell/browser/media_capture_util.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fad550bc3902afb3e1d9fea6c9f3f8412bfbc895
|
| --- /dev/null
|
| +++ b/extensions/shell/browser/media_capture_util.cc
|
| @@ -0,0 +1,70 @@
|
| +// Copyright 2014 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 "extensions/shell/browser/media_capture_util.h"
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/logging.h"
|
| +#include "content/public/browser/media_capture_devices.h"
|
| +#include "extensions/common/permissions/permissions_data.h"
|
| +using content::MediaCaptureDevices;
|
| +using content::MediaStreamDevices;
|
| +using content::MediaStreamUI;
|
| +
|
| +namespace extensions {
|
| +namespace media_capture_util {
|
| +
|
| +// See also Chrome's MediaCaptureDevicesDispatcher.
|
| +void GrantMediaStreamRequestWithFirstDevice(
|
| + content::WebContents* web_contents,
|
| + const content::MediaStreamRequest& request,
|
| + const content::MediaResponseCallback& callback,
|
| + const Extension* extension) {
|
| + // app_shell only supports audio and video capture, not tab or screen capture.
|
| + DCHECK(request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
|
| + request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE);
|
| +
|
| + // app_shell does not support requesting a specific device ID.
|
| + DCHECK(request.requested_audio_device_id.empty() &&
|
| + request.requested_video_device_id.empty());
|
| +
|
| + MediaStreamDevices devices;
|
| + const PermissionsData* permissions_data = extension->permissions_data();
|
| +
|
| + if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
|
| + if (permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) {
|
| + const MediaStreamDevices& audio_devices =
|
| + MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
|
| + // Use first available audio capture device.
|
| + if (!audio_devices.empty())
|
| + devices.push_back(audio_devices[0]);
|
| + } else {
|
| + // app_shell has no UI surface to show the error, so log it.
|
| + LOG(WARNING) << "Audio capture request but no audioCapture permission.";
|
| + }
|
| + }
|
| +
|
| + if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
|
| + if (permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) {
|
| + const MediaStreamDevices& video_devices =
|
| + MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
|
| + // Use first available video capture device.
|
| + if (!video_devices.empty())
|
| + devices.push_back(video_devices[0]);
|
| + } else {
|
| + // app_shell has no UI surface to show the error, so log it.
|
| + LOG(WARNING) << "Video capture request but no videoCapture permission.";
|
| + }
|
| + }
|
| +
|
| + // Don't show UI.
|
| + scoped_ptr<MediaStreamUI> ui;
|
| + callback.Run(devices,
|
| + devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE
|
| + : content::MEDIA_DEVICE_OK,
|
| + ui.Pass());
|
| +}
|
| +
|
| +} // namespace media_capture_util
|
| +} // namespace extensions
|
|
|