parent
92cfc4a62d
commit
a864167d46
8 changed files with 100 additions and 93 deletions
|
@ -712,7 +712,7 @@ void WebContents::FindReply(content::WebContents* web_contents,
|
||||||
bool WebContents::CheckMediaAccessPermission(
|
bool WebContents::CheckMediaAccessPermission(
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
const GURL& security_origin,
|
const GURL& security_origin,
|
||||||
content::MediaStreamType type) {
|
blink::MediaStreamType type) {
|
||||||
auto* web_contents =
|
auto* web_contents =
|
||||||
content::WebContents::FromRenderFrameHost(render_frame_host);
|
content::WebContents::FromRenderFrameHost(render_frame_host);
|
||||||
auto* permission_helper =
|
auto* permission_helper =
|
||||||
|
|
|
@ -387,7 +387,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
bool final_update) override;
|
bool final_update) override;
|
||||||
bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
|
bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
|
||||||
const GURL& security_origin,
|
const GURL& security_origin,
|
||||||
content::MediaStreamType type) override;
|
blink::MediaStreamType type) override;
|
||||||
void RequestMediaAccessPermission(
|
void RequestMediaAccessPermission(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
const content::MediaStreamRequest& request,
|
const content::MediaStreamRequest& request,
|
||||||
|
|
|
@ -7,18 +7,16 @@
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/media_capture_devices.h"
|
#include "content/public/browser/media_capture_devices.h"
|
||||||
#include "content/public/common/media_stream_request.h"
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
using content::MediaStreamDevices;
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Finds a device in |devices| that has |device_id|, or NULL if not found.
|
// Finds a device in |devices| that has |device_id|, or NULL if not found.
|
||||||
const content::MediaStreamDevice* FindDeviceWithId(
|
const blink::MediaStreamDevice* FindDeviceWithId(
|
||||||
const content::MediaStreamDevices& devices,
|
const blink::MediaStreamDevices& devices,
|
||||||
const std::string& device_id) {
|
const std::string& device_id) {
|
||||||
auto iter = devices.begin();
|
auto iter = devices.begin();
|
||||||
for (; iter != devices.end(); ++iter) {
|
for (; iter != devices.end(); ++iter) {
|
||||||
|
@ -29,11 +27,6 @@ const content::MediaStreamDevice* FindDeviceWithId(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MediaStreamDevices& EmptyDevices() {
|
|
||||||
static MediaStreamDevices* devices = new MediaStreamDevices;
|
|
||||||
return *devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
|
MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
|
||||||
|
@ -49,75 +42,75 @@ MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
|
||||||
|
|
||||||
MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {}
|
MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {}
|
||||||
|
|
||||||
const MediaStreamDevices&
|
const blink::MediaStreamDevices&
|
||||||
MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
|
MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
|
||||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
if (is_device_enumeration_disabled_)
|
if (is_device_enumeration_disabled_)
|
||||||
return EmptyDevices();
|
return test_audio_devices_;
|
||||||
return content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
|
return content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
const MediaStreamDevices&
|
const blink::MediaStreamDevices&
|
||||||
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
|
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
|
||||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
if (is_device_enumeration_disabled_)
|
if (is_device_enumeration_disabled_)
|
||||||
return EmptyDevices();
|
return test_video_devices_;
|
||||||
return content::MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
|
return content::MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaCaptureDevicesDispatcher::GetDefaultDevices(
|
void MediaCaptureDevicesDispatcher::GetDefaultDevices(
|
||||||
bool audio,
|
bool audio,
|
||||||
bool video,
|
bool video,
|
||||||
content::MediaStreamDevices* devices) {
|
blink::MediaStreamDevices* devices) {
|
||||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
DCHECK(audio || video);
|
DCHECK(audio || video);
|
||||||
|
|
||||||
if (audio) {
|
if (audio) {
|
||||||
const content::MediaStreamDevice* device = GetFirstAvailableAudioDevice();
|
const blink::MediaStreamDevice* device = GetFirstAvailableAudioDevice();
|
||||||
if (device)
|
if (device)
|
||||||
devices->push_back(*device);
|
devices->push_back(*device);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (video) {
|
if (video) {
|
||||||
const content::MediaStreamDevice* device = GetFirstAvailableVideoDevice();
|
const blink::MediaStreamDevice* device = GetFirstAvailableVideoDevice();
|
||||||
if (device)
|
if (device)
|
||||||
devices->push_back(*device);
|
devices->push_back(*device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const content::MediaStreamDevice*
|
const blink::MediaStreamDevice*
|
||||||
MediaCaptureDevicesDispatcher::GetRequestedAudioDevice(
|
MediaCaptureDevicesDispatcher::GetRequestedAudioDevice(
|
||||||
const std::string& requested_audio_device_id) {
|
const std::string& requested_audio_device_id) {
|
||||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
|
const blink::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
|
||||||
const content::MediaStreamDevice* const device =
|
const blink::MediaStreamDevice* const device =
|
||||||
FindDeviceWithId(audio_devices, requested_audio_device_id);
|
FindDeviceWithId(audio_devices, requested_audio_device_id);
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content::MediaStreamDevice*
|
const blink::MediaStreamDevice*
|
||||||
MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() {
|
MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() {
|
||||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
|
const blink::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
|
||||||
if (audio_devices.empty())
|
if (audio_devices.empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return &(*audio_devices.begin());
|
return &(*audio_devices.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
const content::MediaStreamDevice*
|
const blink::MediaStreamDevice*
|
||||||
MediaCaptureDevicesDispatcher::GetRequestedVideoDevice(
|
MediaCaptureDevicesDispatcher::GetRequestedVideoDevice(
|
||||||
const std::string& requested_video_device_id) {
|
const std::string& requested_video_device_id) {
|
||||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
|
const blink::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
|
||||||
const content::MediaStreamDevice* const device =
|
const blink::MediaStreamDevice* const device =
|
||||||
FindDeviceWithId(video_devices, requested_video_device_id);
|
FindDeviceWithId(video_devices, requested_video_device_id);
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content::MediaStreamDevice*
|
const blink::MediaStreamDevice*
|
||||||
MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() {
|
MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() {
|
||||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
|
const blink::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
|
||||||
if (video_devices.empty())
|
if (video_devices.empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return &(*video_devices.begin());
|
return &(*video_devices.begin());
|
||||||
|
@ -136,7 +129,7 @@ void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
|
||||||
int render_view_id,
|
int render_view_id,
|
||||||
int page_request_id,
|
int page_request_id,
|
||||||
const GURL& security_origin,
|
const GURL& security_origin,
|
||||||
content::MediaStreamType stream_type,
|
blink::MediaStreamType stream_type,
|
||||||
content::MediaRequestState state) {}
|
content::MediaRequestState state) {}
|
||||||
|
|
||||||
void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(int render_process_id,
|
void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(int render_process_id,
|
||||||
|
@ -146,7 +139,7 @@ void MediaCaptureDevicesDispatcher::OnSetCapturingLinkSecured(
|
||||||
int render_process_id,
|
int render_process_id,
|
||||||
int render_frame_id,
|
int render_frame_id,
|
||||||
int page_request_id,
|
int page_request_id,
|
||||||
content::MediaStreamType stream_type,
|
blink::MediaStreamType stream_type,
|
||||||
bool is_secure) {}
|
bool is_secure) {}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
|
|
||||||
#include "base/memory/singleton.h"
|
#include "base/memory/singleton.h"
|
||||||
#include "content/public/browser/media_observer.h"
|
#include "content/public/browser/media_observer.h"
|
||||||
#include "content/public/common/media_stream_request.h"
|
#include "content/public/browser/media_stream_request.h"
|
||||||
|
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -20,8 +21,8 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
|
||||||
static MediaCaptureDevicesDispatcher* GetInstance();
|
static MediaCaptureDevicesDispatcher* GetInstance();
|
||||||
|
|
||||||
// Methods for observers. Called on UI thread.
|
// Methods for observers. Called on UI thread.
|
||||||
const content::MediaStreamDevices& GetAudioCaptureDevices();
|
const blink::MediaStreamDevices& GetAudioCaptureDevices();
|
||||||
const content::MediaStreamDevices& GetVideoCaptureDevices();
|
const blink::MediaStreamDevices& GetVideoCaptureDevices();
|
||||||
|
|
||||||
// Helper to get the default devices which can be used by the media request.
|
// Helper to get the default devices which can be used by the media request.
|
||||||
// Uses the first available devices if the default devices are not available.
|
// Uses the first available devices if the default devices are not available.
|
||||||
|
@ -30,19 +31,19 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
|
||||||
// Called on the UI thread.
|
// Called on the UI thread.
|
||||||
void GetDefaultDevices(bool audio,
|
void GetDefaultDevices(bool audio,
|
||||||
bool video,
|
bool video,
|
||||||
content::MediaStreamDevices* devices);
|
blink::MediaStreamDevices* devices);
|
||||||
|
|
||||||
// Helpers for picking particular requested devices, identified by raw id.
|
// Helpers for picking particular requested devices, identified by raw id.
|
||||||
// If the device requested is not available it will return NULL.
|
// If the device requested is not available it will return NULL.
|
||||||
const content::MediaStreamDevice* GetRequestedAudioDevice(
|
const blink::MediaStreamDevice* GetRequestedAudioDevice(
|
||||||
const std::string& requested_audio_device_id);
|
const std::string& requested_audio_device_id);
|
||||||
const content::MediaStreamDevice* GetRequestedVideoDevice(
|
const blink::MediaStreamDevice* GetRequestedVideoDevice(
|
||||||
const std::string& requested_video_device_id);
|
const std::string& requested_video_device_id);
|
||||||
|
|
||||||
// Returns the first available audio or video device, or NULL if no devices
|
// Returns the first available audio or video device, or NULL if no devices
|
||||||
// are available.
|
// are available.
|
||||||
const content::MediaStreamDevice* GetFirstAvailableAudioDevice();
|
const blink::MediaStreamDevice* GetFirstAvailableAudioDevice();
|
||||||
const content::MediaStreamDevice* GetFirstAvailableVideoDevice();
|
const blink::MediaStreamDevice* GetFirstAvailableVideoDevice();
|
||||||
|
|
||||||
// Unittests that do not require actual device enumeration should call this
|
// Unittests that do not require actual device enumeration should call this
|
||||||
// API on the singleton. It is safe to call this multiple times on the
|
// API on the singleton. It is safe to call this multiple times on the
|
||||||
|
@ -56,14 +57,14 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
|
||||||
int render_view_id,
|
int render_view_id,
|
||||||
int page_request_id,
|
int page_request_id,
|
||||||
const GURL& security_origin,
|
const GURL& security_origin,
|
||||||
content::MediaStreamType stream_type,
|
blink::MediaStreamType stream_type,
|
||||||
content::MediaRequestState state) override;
|
content::MediaRequestState state) override;
|
||||||
void OnCreatingAudioStream(int render_process_id,
|
void OnCreatingAudioStream(int render_process_id,
|
||||||
int render_view_id) override;
|
int render_view_id) override;
|
||||||
void OnSetCapturingLinkSecured(int render_process_id,
|
void OnSetCapturingLinkSecured(int render_process_id,
|
||||||
int render_frame_id,
|
int render_frame_id,
|
||||||
int page_request_id,
|
int page_request_id,
|
||||||
content::MediaStreamType stream_type,
|
blink::MediaStreamType stream_type,
|
||||||
bool is_secure) override;
|
bool is_secure) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -72,6 +73,12 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
|
||||||
MediaCaptureDevicesDispatcher();
|
MediaCaptureDevicesDispatcher();
|
||||||
~MediaCaptureDevicesDispatcher() override;
|
~MediaCaptureDevicesDispatcher() override;
|
||||||
|
|
||||||
|
// Only for testing, a list of cached audio capture devices.
|
||||||
|
blink::MediaStreamDevices test_audio_devices_;
|
||||||
|
|
||||||
|
// Only for testing, a list of cached video capture devices.
|
||||||
|
blink::MediaStreamDevices test_video_devices_;
|
||||||
|
|
||||||
// Flag used by unittests to disable device enumeration.
|
// Flag used by unittests to disable device enumeration.
|
||||||
bool is_device_enumeration_disabled_;
|
bool is_device_enumeration_disabled_;
|
||||||
|
|
||||||
|
|
|
@ -9,16 +9,16 @@
|
||||||
|
|
||||||
#include "atom/browser/media/media_capture_devices_dispatcher.h"
|
#include "atom/browser/media/media_capture_devices_dispatcher.h"
|
||||||
#include "content/public/browser/desktop_media_id.h"
|
#include "content/public/browser/desktop_media_id.h"
|
||||||
#include "content/public/common/media_stream_request.h"
|
#include "content/public/browser/media_stream_request.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool HasAnyAvailableDevice() {
|
bool HasAnyAvailableDevice() {
|
||||||
const content::MediaStreamDevices& audio_devices =
|
const blink::MediaStreamDevices& audio_devices =
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices();
|
MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices();
|
||||||
const content::MediaStreamDevices& video_devices =
|
const blink::MediaStreamDevices& video_devices =
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices();
|
MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices();
|
||||||
|
|
||||||
return !audio_devices.empty() || !video_devices.empty();
|
return !audio_devices.empty() || !video_devices.empty();
|
||||||
|
@ -34,33 +34,33 @@ MediaStreamDevicesController::MediaStreamDevicesController(
|
||||||
// For MEDIA_OPEN_DEVICE requests (Pepper) we always request both webcam
|
// For MEDIA_OPEN_DEVICE requests (Pepper) we always request both webcam
|
||||||
// and microphone to avoid popping two infobars.
|
// and microphone to avoid popping two infobars.
|
||||||
microphone_requested_(
|
microphone_requested_(
|
||||||
request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
|
request.audio_type == blink::MEDIA_DEVICE_AUDIO_CAPTURE ||
|
||||||
request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
|
request.request_type == blink::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
|
||||||
webcam_requested_(
|
webcam_requested_(
|
||||||
request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
|
request.video_type == blink::MEDIA_DEVICE_VIDEO_CAPTURE ||
|
||||||
request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {}
|
request.request_type == blink::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {}
|
||||||
|
|
||||||
MediaStreamDevicesController::~MediaStreamDevicesController() {
|
MediaStreamDevicesController::~MediaStreamDevicesController() {
|
||||||
if (!callback_.is_null()) {
|
if (!callback_.is_null()) {
|
||||||
std::move(callback_).Run(content::MediaStreamDevices(),
|
std::move(callback_).Run(blink::MediaStreamDevices(),
|
||||||
content::MEDIA_DEVICE_INVALID_STATE,
|
blink::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
|
||||||
std::unique_ptr<content::MediaStreamUI>());
|
std::unique_ptr<content::MediaStreamUI>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MediaStreamDevicesController::TakeAction() {
|
bool MediaStreamDevicesController::TakeAction() {
|
||||||
// Do special handling of desktop screen cast.
|
// Do special handling of desktop screen cast.
|
||||||
if (request_.audio_type == content::MEDIA_GUM_TAB_AUDIO_CAPTURE ||
|
if (request_.audio_type == blink::MEDIA_GUM_TAB_AUDIO_CAPTURE ||
|
||||||
request_.video_type == content::MEDIA_GUM_TAB_VIDEO_CAPTURE ||
|
request_.video_type == blink::MEDIA_GUM_TAB_VIDEO_CAPTURE ||
|
||||||
request_.audio_type == content::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE ||
|
request_.audio_type == blink::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE ||
|
||||||
request_.video_type == content::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE) {
|
request_.video_type == blink::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE) {
|
||||||
HandleUserMediaRequest();
|
HandleUserMediaRequest();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deny the request if there is no device attached to the OS.
|
// Deny the request if there is no device attached to the OS.
|
||||||
if (!HasAnyAvailableDevice()) {
|
if (!HasAnyAvailableDevice()) {
|
||||||
Deny(content::MEDIA_DEVICE_NO_HARDWARE);
|
Deny(blink::MEDIA_DEVICE_NO_HARDWARE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,14 +70,14 @@ bool MediaStreamDevicesController::TakeAction() {
|
||||||
|
|
||||||
void MediaStreamDevicesController::Accept() {
|
void MediaStreamDevicesController::Accept() {
|
||||||
// Get the default devices for the request.
|
// Get the default devices for the request.
|
||||||
content::MediaStreamDevices devices;
|
blink::MediaStreamDevices devices;
|
||||||
if (microphone_requested_ || webcam_requested_) {
|
if (microphone_requested_ || webcam_requested_) {
|
||||||
switch (request_.request_type) {
|
switch (request_.request_type) {
|
||||||
case content::MEDIA_OPEN_DEVICE_PEPPER_ONLY: {
|
case blink::MEDIA_OPEN_DEVICE_PEPPER_ONLY: {
|
||||||
const content::MediaStreamDevice* device = nullptr;
|
const blink::MediaStreamDevice* device = nullptr;
|
||||||
// For open device request pick the desired device or fall back to the
|
// For open device request pick the desired device or fall back to the
|
||||||
// first available of the given type.
|
// first available of the given type.
|
||||||
if (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
|
if (request_.audio_type == blink::MEDIA_DEVICE_AUDIO_CAPTURE) {
|
||||||
device =
|
device =
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()
|
MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
->GetRequestedAudioDevice(request_.requested_audio_device_id);
|
->GetRequestedAudioDevice(request_.requested_audio_device_id);
|
||||||
|
@ -86,7 +86,7 @@ void MediaStreamDevicesController::Accept() {
|
||||||
device = MediaCaptureDevicesDispatcher::GetInstance()
|
device = MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
->GetFirstAvailableAudioDevice();
|
->GetFirstAvailableAudioDevice();
|
||||||
}
|
}
|
||||||
} else if (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
|
} else if (request_.video_type == blink::MEDIA_DEVICE_VIDEO_CAPTURE) {
|
||||||
// Pepper API opens only one device at a time.
|
// Pepper API opens only one device at a time.
|
||||||
device =
|
device =
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()
|
MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
|
@ -101,13 +101,13 @@ void MediaStreamDevicesController::Accept() {
|
||||||
devices.push_back(*device);
|
devices.push_back(*device);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case content::MEDIA_GENERATE_STREAM: {
|
case blink::MEDIA_GENERATE_STREAM: {
|
||||||
bool needs_audio_device = microphone_requested_;
|
bool needs_audio_device = microphone_requested_;
|
||||||
bool needs_video_device = webcam_requested_;
|
bool needs_video_device = webcam_requested_;
|
||||||
|
|
||||||
// Get the exact audio or video device if an id is specified.
|
// Get the exact audio or video device if an id is specified.
|
||||||
if (!request_.requested_audio_device_id.empty()) {
|
if (!request_.requested_audio_device_id.empty()) {
|
||||||
const content::MediaStreamDevice* audio_device =
|
const blink::MediaStreamDevice* audio_device =
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()
|
MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
->GetRequestedAudioDevice(request_.requested_audio_device_id);
|
->GetRequestedAudioDevice(request_.requested_audio_device_id);
|
||||||
if (audio_device) {
|
if (audio_device) {
|
||||||
|
@ -116,7 +116,7 @@ void MediaStreamDevicesController::Accept() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!request_.requested_video_device_id.empty()) {
|
if (!request_.requested_video_device_id.empty()) {
|
||||||
const content::MediaStreamDevice* video_device =
|
const blink::MediaStreamDevice* video_device =
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()
|
MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
->GetRequestedVideoDevice(request_.requested_video_device_id);
|
->GetRequestedVideoDevice(request_.requested_video_device_id);
|
||||||
if (video_device) {
|
if (video_device) {
|
||||||
|
@ -133,40 +133,45 @@ void MediaStreamDevicesController::Accept() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case content::MEDIA_DEVICE_ACCESS:
|
case blink::MEDIA_DEVICE_ACCESS: {
|
||||||
// Get the default devices for the request.
|
// Get the default devices for the request.
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevices(
|
MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevices(
|
||||||
microphone_requested_, webcam_requested_, &devices);
|
microphone_requested_, webcam_requested_, &devices);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case blink::MEDIA_DEVICE_UPDATE: {
|
||||||
|
NOTREACHED();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::move(callback_).Run(devices, content::MEDIA_DEVICE_OK,
|
std::move(callback_).Run(devices, blink::MEDIA_DEVICE_OK,
|
||||||
std::unique_ptr<content::MediaStreamUI>());
|
std::unique_ptr<content::MediaStreamUI>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaStreamDevicesController::Deny(
|
void MediaStreamDevicesController::Deny(
|
||||||
content::MediaStreamRequestResult result) {
|
blink::MediaStreamRequestResult result) {
|
||||||
std::move(callback_).Run(content::MediaStreamDevices(), result,
|
std::move(callback_).Run(blink::MediaStreamDevices(), result,
|
||||||
std::unique_ptr<content::MediaStreamUI>());
|
std::unique_ptr<content::MediaStreamUI>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaStreamDevicesController::HandleUserMediaRequest() {
|
void MediaStreamDevicesController::HandleUserMediaRequest() {
|
||||||
content::MediaStreamDevices devices;
|
blink::MediaStreamDevices devices;
|
||||||
|
|
||||||
if (request_.audio_type == content::MEDIA_GUM_TAB_AUDIO_CAPTURE) {
|
if (request_.audio_type == blink::MEDIA_GUM_TAB_AUDIO_CAPTURE) {
|
||||||
devices.push_back(content::MediaStreamDevice(
|
devices.push_back(
|
||||||
content::MEDIA_GUM_TAB_AUDIO_CAPTURE, "", ""));
|
blink::MediaStreamDevice(blink::MEDIA_GUM_TAB_AUDIO_CAPTURE, "", ""));
|
||||||
}
|
}
|
||||||
if (request_.video_type == content::MEDIA_GUM_TAB_VIDEO_CAPTURE) {
|
if (request_.video_type == blink::MEDIA_GUM_TAB_VIDEO_CAPTURE) {
|
||||||
devices.push_back(content::MediaStreamDevice(
|
devices.push_back(
|
||||||
content::MEDIA_GUM_TAB_VIDEO_CAPTURE, "", ""));
|
blink::MediaStreamDevice(blink::MEDIA_GUM_TAB_VIDEO_CAPTURE, "", ""));
|
||||||
}
|
}
|
||||||
if (request_.audio_type == content::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE) {
|
if (request_.audio_type == blink::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE) {
|
||||||
devices.push_back(content::MediaStreamDevice(
|
devices.push_back(blink::MediaStreamDevice(
|
||||||
content::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE, "loopback", "System Audio"));
|
blink::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE, "loopback", "System Audio"));
|
||||||
}
|
}
|
||||||
if (request_.video_type == content::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE) {
|
if (request_.video_type == blink::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE) {
|
||||||
content::DesktopMediaID screen_id;
|
content::DesktopMediaID screen_id;
|
||||||
// If the device id wasn't specified then this is a screen capture request
|
// If the device id wasn't specified then this is a screen capture request
|
||||||
// (i.e. chooseDesktopMedia() API wasn't used to generate device id).
|
// (i.e. chooseDesktopMedia() API wasn't used to generate device id).
|
||||||
|
@ -179,13 +184,13 @@ void MediaStreamDevicesController::HandleUserMediaRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
devices.push_back(
|
devices.push_back(
|
||||||
content::MediaStreamDevice(content::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE,
|
blink::MediaStreamDevice(blink::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE,
|
||||||
screen_id.ToString(), "Screen"));
|
screen_id.ToString(), "Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::move(callback_).Run(devices,
|
std::move(callback_).Run(devices,
|
||||||
devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE
|
devices.empty() ? blink::MEDIA_DEVICE_NO_HARDWARE
|
||||||
: content::MEDIA_DEVICE_OK,
|
: blink::MEDIA_DEVICE_OK,
|
||||||
std::unique_ptr<content::MediaStreamUI>());
|
std::unique_ptr<content::MediaStreamUI>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define ATOM_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
|
#define ATOM_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_
|
||||||
|
|
||||||
#include "content/public/browser/web_contents_delegate.h"
|
#include "content/public/browser/web_contents_delegate.h"
|
||||||
|
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ class MediaStreamDevicesController {
|
||||||
|
|
||||||
// Explicitly accept or deny the request.
|
// Explicitly accept or deny the request.
|
||||||
void Accept();
|
void Accept();
|
||||||
void Deny(content::MediaStreamRequestResult result);
|
void Deny(blink::MediaStreamRequestResult result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Handle the request of desktop or tab screen cast.
|
// Handle the request of desktop or tab screen cast.
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string MediaStreamTypeToString(content::MediaStreamType type) {
|
std::string MediaStreamTypeToString(blink::MediaStreamType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case content::MediaStreamType::MEDIA_DEVICE_AUDIO_CAPTURE:
|
case blink::MediaStreamType::MEDIA_DEVICE_AUDIO_CAPTURE:
|
||||||
return "audio";
|
return "audio";
|
||||||
case content::MediaStreamType::MEDIA_DEVICE_VIDEO_CAPTURE:
|
case blink::MediaStreamType::MEDIA_DEVICE_VIDEO_CAPTURE:
|
||||||
return "video";
|
return "video";
|
||||||
default:
|
default:
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
@ -40,7 +40,7 @@ void MediaAccessAllowed(const content::MediaStreamRequest& request,
|
||||||
if (allowed)
|
if (allowed)
|
||||||
controller.TakeAction();
|
controller.TakeAction();
|
||||||
else
|
else
|
||||||
controller.Deny(content::MEDIA_DEVICE_PERMISSION_DENIED);
|
controller.Deny(blink::MEDIA_DEVICE_PERMISSION_DENIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPointerLockResponse(content::WebContents* web_contents, bool allowed) {
|
void OnPointerLockResponse(content::WebContents* web_contents, bool allowed) {
|
||||||
|
@ -105,11 +105,11 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
|
||||||
base::DictionaryValue details;
|
base::DictionaryValue details;
|
||||||
std::unique_ptr<base::ListValue> media_types(new base::ListValue);
|
std::unique_ptr<base::ListValue> media_types(new base::ListValue);
|
||||||
if (request.audio_type ==
|
if (request.audio_type ==
|
||||||
content::MediaStreamType::MEDIA_DEVICE_AUDIO_CAPTURE) {
|
blink::MediaStreamType::MEDIA_DEVICE_AUDIO_CAPTURE) {
|
||||||
media_types->AppendString("audio");
|
media_types->AppendString("audio");
|
||||||
}
|
}
|
||||||
if (request.video_type ==
|
if (request.video_type ==
|
||||||
content::MediaStreamType::MEDIA_DEVICE_VIDEO_CAPTURE) {
|
blink::MediaStreamType::MEDIA_DEVICE_VIDEO_CAPTURE) {
|
||||||
media_types->AppendString("video");
|
media_types->AppendString("video");
|
||||||
}
|
}
|
||||||
details.SetList("mediaTypes", std::move(media_types));
|
details.SetList("mediaTypes", std::move(media_types));
|
||||||
|
@ -145,7 +145,7 @@ void WebContentsPermissionHelper::RequestOpenExternalPermission(
|
||||||
|
|
||||||
bool WebContentsPermissionHelper::CheckMediaAccessPermission(
|
bool WebContentsPermissionHelper::CheckMediaAccessPermission(
|
||||||
const GURL& security_origin,
|
const GURL& security_origin,
|
||||||
content::MediaStreamType type) const {
|
blink::MediaStreamType type) const {
|
||||||
base::DictionaryValue details;
|
base::DictionaryValue details;
|
||||||
details.SetString("securityOrigin", security_origin.spec());
|
details.SetString("securityOrigin", security_origin.spec());
|
||||||
details.SetString("mediaType", MediaStreamTypeToString(type));
|
details.SetString("mediaType", MediaStreamTypeToString(type));
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
#ifndef ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
#ifndef ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
||||||
#define ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
#define ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
|
||||||
|
|
||||||
|
#include "content/public/browser/media_stream_request.h"
|
||||||
#include "content/public/browser/permission_type.h"
|
#include "content/public/browser/permission_type.h"
|
||||||
#include "content/public/browser/web_contents_user_data.h"
|
#include "content/public/browser/web_contents_user_data.h"
|
||||||
#include "content/public/common/media_stream_request.h"
|
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ class WebContentsPermissionHelper
|
||||||
|
|
||||||
// Synchronous Checks
|
// Synchronous Checks
|
||||||
bool CheckMediaAccessPermission(const GURL& security_origin,
|
bool CheckMediaAccessPermission(const GURL& security_origin,
|
||||||
content::MediaStreamType type) const;
|
blink::MediaStreamType type) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit WebContentsPermissionHelper(content::WebContents* web_contents);
|
explicit WebContentsPermissionHelper(content::WebContents* web_contents);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue