refactor: rename the atom directory to shell

This commit is contained in:
Samuel Attard 2019-06-19 13:43:10 -07:00 committed by Samuel Attard
parent 4575a4aae3
commit d7f07e8a80
631 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,145 @@
// Copyright (c) 2012 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-CHROMIUM file.
#include "atom/browser/media/media_capture_devices_dispatcher.h"
#include "base/logging.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/media_capture_devices.h"
using content::BrowserThread;
namespace atom {
namespace {
// Finds a device in |devices| that has |device_id|, or NULL if not found.
const blink::MediaStreamDevice* FindDeviceWithId(
const blink::MediaStreamDevices& devices,
const std::string& device_id) {
auto iter = devices.begin();
for (; iter != devices.end(); ++iter) {
if (iter->id == device_id) {
return &(*iter);
}
}
return nullptr;
}
} // namespace
MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
return base::Singleton<MediaCaptureDevicesDispatcher>::get();
}
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
: is_device_enumeration_disabled_(false) {
// MediaCaptureDevicesDispatcher is a singleton. It should be created on
// UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {}
const blink::MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (is_device_enumeration_disabled_)
return test_audio_devices_;
return content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
}
const blink::MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (is_device_enumeration_disabled_)
return test_video_devices_;
return content::MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
}
void MediaCaptureDevicesDispatcher::GetDefaultDevices(
bool audio,
bool video,
blink::MediaStreamDevices* devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(audio || video);
if (audio) {
const blink::MediaStreamDevice* device = GetFirstAvailableAudioDevice();
if (device)
devices->push_back(*device);
}
if (video) {
const blink::MediaStreamDevice* device = GetFirstAvailableVideoDevice();
if (device)
devices->push_back(*device);
}
}
const blink::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetRequestedAudioDevice(
const std::string& requested_audio_device_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const blink::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
const blink::MediaStreamDevice* const device =
FindDeviceWithId(audio_devices, requested_audio_device_id);
return device;
}
const blink::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const blink::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
if (audio_devices.empty())
return nullptr;
return &(*audio_devices.begin());
}
const blink::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetRequestedVideoDevice(
const std::string& requested_video_device_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const blink::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
const blink::MediaStreamDevice* const device =
FindDeviceWithId(video_devices, requested_video_device_id);
return device;
}
const blink::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const blink::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
if (video_devices.empty())
return nullptr;
return &(*video_devices.begin());
}
void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() {
is_device_enumeration_disabled_ = true;
}
void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() {}
void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() {}
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
int render_process_id,
int render_view_id,
int page_request_id,
const GURL& security_origin,
blink::MediaStreamType stream_type,
content::MediaRequestState state) {}
void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(int render_process_id,
int render_view_id) {}
void MediaCaptureDevicesDispatcher::OnSetCapturingLinkSecured(
int render_process_id,
int render_frame_id,
int page_request_id,
blink::MediaStreamType stream_type,
bool is_secure) {}
} // namespace atom

View file

@ -0,0 +1,90 @@
// Copyright (c) 2012 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-CHROMIUM file.
#ifndef ATOM_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
#define ATOM_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
#include <string>
#include "base/memory/singleton.h"
#include "content/public/browser/media_observer.h"
#include "content/public/browser/media_stream_request.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
namespace atom {
// This singleton is used to receive updates about media events from the content
// layer.
class MediaCaptureDevicesDispatcher : public content::MediaObserver {
public:
static MediaCaptureDevicesDispatcher* GetInstance();
// Methods for observers. Called on UI thread.
const blink::MediaStreamDevices& GetAudioCaptureDevices();
const blink::MediaStreamDevices& GetVideoCaptureDevices();
// 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.
// If the return list is empty, it means there is no available device on the
// OS.
// Called on the UI thread.
void GetDefaultDevices(bool audio,
bool video,
blink::MediaStreamDevices* devices);
// Helpers for picking particular requested devices, identified by raw id.
// If the device requested is not available it will return NULL.
const blink::MediaStreamDevice* GetRequestedAudioDevice(
const std::string& requested_audio_device_id);
const blink::MediaStreamDevice* GetRequestedVideoDevice(
const std::string& requested_video_device_id);
// Returns the first available audio or video device, or NULL if no devices
// are available.
const blink::MediaStreamDevice* GetFirstAvailableAudioDevice();
const blink::MediaStreamDevice* GetFirstAvailableVideoDevice();
// 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
// signleton.
void DisableDeviceEnumerationForTesting();
// Overridden from content::MediaObserver:
void OnAudioCaptureDevicesChanged() override;
void OnVideoCaptureDevicesChanged() override;
void OnMediaRequestStateChanged(int render_process_id,
int render_view_id,
int page_request_id,
const GURL& security_origin,
blink::MediaStreamType stream_type,
content::MediaRequestState state) override;
void OnCreatingAudioStream(int render_process_id,
int render_view_id) override;
void OnSetCapturingLinkSecured(int render_process_id,
int render_frame_id,
int page_request_id,
blink::MediaStreamType stream_type,
bool is_secure) override;
private:
friend struct base::DefaultSingletonTraits<MediaCaptureDevicesDispatcher>;
MediaCaptureDevicesDispatcher();
~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.
bool is_device_enumeration_disabled_;
DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher);
};
} // namespace atom
#endif // ATOM_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_

View file

@ -0,0 +1,54 @@
// Copyright 2013 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 "atom/browser/media/media_device_id_salt.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
namespace atom {
namespace {
const char kMediaDeviceIdSalt[] = "electron.media.device_id_salt";
} // namespace
MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
media_device_id_salt_.Init(kMediaDeviceIdSalt, pref_service);
if (media_device_id_salt_.GetValue().empty()) {
media_device_id_salt_.SetValue(
content::BrowserContext::CreateRandomMediaDeviceIDSalt());
}
}
MediaDeviceIDSalt::~MediaDeviceIDSalt() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
media_device_id_salt_.Destroy();
}
std::string MediaDeviceIDSalt::GetSalt() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return media_device_id_salt_.GetValue();
}
// static
void MediaDeviceIDSalt::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterStringPref(kMediaDeviceIdSalt, std::string());
}
// static
void MediaDeviceIDSalt::Reset(PrefService* pref_service) {
pref_service->SetString(
kMediaDeviceIdSalt,
content::BrowserContext::CreateRandomMediaDeviceIDSalt());
}
} // namespace atom

View file

@ -0,0 +1,39 @@
// Copyright 2013 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.
#ifndef ATOM_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_
#define ATOM_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_
#include <string>
#include "base/macros.h"
#include "components/prefs/pref_member.h"
class PrefRegistrySimple;
class PrefService;
namespace atom {
// MediaDeviceIDSalt is responsible for creating and retrieving a salt string
// that is used for creating MediaSource IDs that can be cached by a web
// service. If the cache is cleared, the MediaSourceIds are invalidated.
class MediaDeviceIDSalt {
public:
explicit MediaDeviceIDSalt(PrefService* pref_service);
~MediaDeviceIDSalt();
std::string GetSalt();
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
static void Reset(PrefService* pref_service);
private:
StringPrefMember media_device_id_salt_;
DISALLOW_COPY_AND_ASSIGN(MediaDeviceIDSalt);
};
} // namespace atom
#endif // ATOM_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_

View file

@ -0,0 +1,199 @@
// Copyright (c) 2012 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-CHROMIUM file.
#include "atom/browser/media/media_stream_devices_controller.h"
#include <memory>
#include <utility>
#include "atom/browser/media/media_capture_devices_dispatcher.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/media_stream_request.h"
namespace atom {
namespace {
bool HasAnyAvailableDevice() {
const blink::MediaStreamDevices& audio_devices =
MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices();
const blink::MediaStreamDevices& video_devices =
MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices();
return !audio_devices.empty() || !video_devices.empty();
}
} // namespace
MediaStreamDevicesController::MediaStreamDevicesController(
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback)
: request_(request),
callback_(std::move(callback)),
// For MEDIA_OPEN_DEVICE requests (Pepper) we always request both webcam
// and microphone to avoid popping two infobars.
microphone_requested_(
request.audio_type == blink::MEDIA_DEVICE_AUDIO_CAPTURE ||
request.request_type == blink::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
webcam_requested_(
request.video_type == blink::MEDIA_DEVICE_VIDEO_CAPTURE ||
request.request_type == blink::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {}
MediaStreamDevicesController::~MediaStreamDevicesController() {
if (!callback_.is_null()) {
std::move(callback_).Run(
blink::MediaStreamDevices(),
blink::mojom::MediaStreamRequestResult::FAILED_DUE_TO_SHUTDOWN,
std::unique_ptr<content::MediaStreamUI>());
}
}
bool MediaStreamDevicesController::TakeAction() {
// Do special handling of desktop screen cast.
if (request_.audio_type == blink::MEDIA_GUM_TAB_AUDIO_CAPTURE ||
request_.video_type == blink::MEDIA_GUM_TAB_VIDEO_CAPTURE ||
request_.audio_type == blink::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE ||
request_.video_type == blink::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE) {
HandleUserMediaRequest();
return true;
}
// Deny the request if there is no device attached to the OS.
if (!HasAnyAvailableDevice()) {
Deny(blink::mojom::MediaStreamRequestResult::NO_HARDWARE);
return true;
}
Accept();
return true;
}
void MediaStreamDevicesController::Accept() {
// Get the default devices for the request.
blink::MediaStreamDevices devices;
if (microphone_requested_ || webcam_requested_) {
switch (request_.request_type) {
case blink::MEDIA_OPEN_DEVICE_PEPPER_ONLY: {
const blink::MediaStreamDevice* device = nullptr;
// For open device request pick the desired device or fall back to the
// first available of the given type.
if (request_.audio_type == blink::MEDIA_DEVICE_AUDIO_CAPTURE) {
device =
MediaCaptureDevicesDispatcher::GetInstance()
->GetRequestedAudioDevice(request_.requested_audio_device_id);
// TODO(wjia): Confirm this is the intended behavior.
if (!device) {
device = MediaCaptureDevicesDispatcher::GetInstance()
->GetFirstAvailableAudioDevice();
}
} else if (request_.video_type == blink::MEDIA_DEVICE_VIDEO_CAPTURE) {
// Pepper API opens only one device at a time.
device =
MediaCaptureDevicesDispatcher::GetInstance()
->GetRequestedVideoDevice(request_.requested_video_device_id);
// TODO(wjia): Confirm this is the intended behavior.
if (!device) {
device = MediaCaptureDevicesDispatcher::GetInstance()
->GetFirstAvailableVideoDevice();
}
}
if (device)
devices.push_back(*device);
break;
}
case blink::MEDIA_GENERATE_STREAM: {
bool needs_audio_device = microphone_requested_;
bool needs_video_device = webcam_requested_;
// Get the exact audio or video device if an id is specified.
if (!request_.requested_audio_device_id.empty()) {
const blink::MediaStreamDevice* audio_device =
MediaCaptureDevicesDispatcher::GetInstance()
->GetRequestedAudioDevice(request_.requested_audio_device_id);
if (audio_device) {
devices.push_back(*audio_device);
needs_audio_device = false;
}
}
if (!request_.requested_video_device_id.empty()) {
const blink::MediaStreamDevice* video_device =
MediaCaptureDevicesDispatcher::GetInstance()
->GetRequestedVideoDevice(request_.requested_video_device_id);
if (video_device) {
devices.push_back(*video_device);
needs_video_device = false;
}
}
// If either or both audio and video devices were requested but not
// specified by id, get the default devices.
if (needs_audio_device || needs_video_device) {
MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevices(
needs_audio_device, needs_video_device, &devices);
}
break;
}
case blink::MEDIA_DEVICE_ACCESS: {
// Get the default devices for the request.
MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevices(
microphone_requested_, webcam_requested_, &devices);
break;
}
case blink::MEDIA_DEVICE_UPDATE: {
NOTREACHED();
break;
}
}
}
std::move(callback_).Run(devices, blink::mojom::MediaStreamRequestResult::OK,
std::unique_ptr<content::MediaStreamUI>());
}
void MediaStreamDevicesController::Deny(
blink::mojom::MediaStreamRequestResult result) {
std::move(callback_).Run(blink::MediaStreamDevices(), result,
std::unique_ptr<content::MediaStreamUI>());
}
void MediaStreamDevicesController::HandleUserMediaRequest() {
blink::MediaStreamDevices devices;
if (request_.audio_type == blink::MEDIA_GUM_TAB_AUDIO_CAPTURE) {
devices.push_back(
blink::MediaStreamDevice(blink::MEDIA_GUM_TAB_AUDIO_CAPTURE, "", ""));
}
if (request_.video_type == blink::MEDIA_GUM_TAB_VIDEO_CAPTURE) {
devices.push_back(
blink::MediaStreamDevice(blink::MEDIA_GUM_TAB_VIDEO_CAPTURE, "", ""));
}
if (request_.audio_type == blink::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE) {
devices.push_back(blink::MediaStreamDevice(
blink::MEDIA_GUM_DESKTOP_AUDIO_CAPTURE, "loopback", "System Audio"));
}
if (request_.video_type == blink::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE) {
content::DesktopMediaID screen_id;
// 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).
if (request_.requested_video_device_id.empty()) {
screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN,
-1 /* kFullDesktopScreenId */);
} else {
screen_id =
content::DesktopMediaID::Parse(request_.requested_video_device_id);
}
devices.push_back(
blink::MediaStreamDevice(blink::MEDIA_GUM_DESKTOP_VIDEO_CAPTURE,
screen_id.ToString(), "Screen"));
}
std::move(callback_).Run(
devices,
devices.empty() ? blink::mojom::MediaStreamRequestResult::NO_HARDWARE
: blink::mojom::MediaStreamRequestResult::OK,
std::unique_ptr<content::MediaStreamUI>());
}
} // namespace atom

View file

@ -0,0 +1,46 @@
// Copyright (c) 2012 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-CHROMIUM file.
#ifndef 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 "third_party/blink/public/common/mediastream/media_stream_request.h"
namespace atom {
class MediaStreamDevicesController {
public:
MediaStreamDevicesController(const content::MediaStreamRequest& request,
content::MediaResponseCallback callback);
virtual ~MediaStreamDevicesController();
// Accept or deny the request based on the default policy.
bool TakeAction();
// Explicitly accept or deny the request.
void Accept();
void Deny(blink::mojom::MediaStreamRequestResult result);
private:
// Handle the request of desktop or tab screen cast.
void HandleUserMediaRequest();
// The original request for access to devices.
const content::MediaStreamRequest request_;
// The callback that needs to be Run to notify WebRTC of whether access to
// audio/video devices was granted or not.
content::MediaResponseCallback callback_;
bool microphone_requested_;
bool webcam_requested_;
DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController);
};
} // namespace atom
#endif // ATOM_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_