refactor: move media/net from brightray to atom (#15288)

This commit is contained in:
Milan Burda 2018-10-19 20:51:43 +02:00 committed by John Kleinschmidt
parent 6f3c46cc7e
commit 6d844a0b67
32 changed files with 108 additions and 152 deletions

View file

@ -19,6 +19,7 @@
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/atom_permission_manager.h"
#include "atom/browser/browser.h"
#include "atom/browser/media/media_device_id_salt.h"
#include "atom/browser/net/atom_cert_verifier.h"
#include "atom/browser/session_preferences.h"
#include "atom/common/native_mate_converters/callback.h"
@ -31,7 +32,6 @@
#include "base/guid.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "brightray/browser/media/media_device_id_salt.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/pref_names.h"
#include "components/download/public/common/download_danger_type.h"
@ -440,7 +440,7 @@ void Session::ClearStorageData(mate::Arguments* args) {
if (options.storage_types & StoragePartition::REMOVE_DATA_MASK_COOKIES) {
// Reset media device id salt when cookies are cleared.
// https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid
brightray::MediaDeviceIDSalt::Reset(browser_context()->prefs());
MediaDeviceIDSalt::Reset(browser_context()->prefs());
}
storage_partition->ClearData(
options.storage_types, options.quota_types, options.origin,

View file

@ -22,6 +22,7 @@
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
#include "atom/browser/child_web_contents_tracker.h"
#include "atom/browser/io_thread.h"
#include "atom/browser/media/media_capture_devices_dispatcher.h"
#include "atom/browser/native_window.h"
#include "atom/browser/notifications/notification_presenter.h"
#include "atom/browser/notifications/platform_notification_service.h"
@ -683,6 +684,10 @@ AtomBrowserClient::CreateThrottlesForNavigation(
return throttles;
}
content::MediaObserver* AtomBrowserClient::GetMediaObserver() {
return MediaCaptureDevicesDispatcher::GetInstance();
}
content::DevToolsManagerDelegate*
AtomBrowserClient::GetDevToolsManagerDelegate() {
return new DevToolsManagerDelegate;

View file

@ -127,6 +127,7 @@ class AtomBrowserClient : public brightray::BrowserClient,
std::unique_ptr<base::Value> GetServiceManifestOverlay(
base::StringPiece name) override;
net::NetLog* GetNetLog() override;
content::MediaObserver* GetMediaObserver() override;
content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override;
content::PlatformNotificationService* GetPlatformNotificationService()
override;

View file

@ -17,6 +17,7 @@
#include "atom/browser/special_storage_policy.h"
#include "atom/browser/ui/inspectable_web_contents_impl.h"
#include "atom/browser/web_view_manager.h"
#include "atom/browser/zoom_level_delegate.h"
#include "atom/common/atom_version.h"
#include "atom/common/chrome_version.h"
#include "atom/common/options_switches.h"
@ -28,7 +29,6 @@
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_restrictions.h"
#include "brightray/browser/brightray_paths.h"
#include "brightray/browser/zoom_level_delegate.h"
#include "brightray/common/application_info.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
@ -153,8 +153,8 @@ void AtomBrowserContext::InitPrefs() {
download_dir);
registry->RegisterDictionaryPref(prefs::kDevToolsFileSystemPaths);
InspectableWebContentsImpl::RegisterPrefs(registry.get());
brightray::MediaDeviceIDSalt::RegisterPrefs(registry.get());
brightray::ZoomLevelDelegate::RegisterPrefs(registry.get());
MediaDeviceIDSalt::RegisterPrefs(registry.get());
ZoomLevelDelegate::RegisterPrefs(registry.get());
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
prefs_ = prefs_factory.Create(
@ -210,7 +210,7 @@ content::ResourceContext* AtomBrowserContext::GetResourceContext() {
std::string AtomBrowserContext::GetMediaDeviceIDSalt() {
if (!media_device_id_salt_.get())
media_device_id_salt_.reset(new brightray::MediaDeviceIDSalt(prefs_.get()));
media_device_id_salt_.reset(new MediaDeviceIDSalt(prefs_.get()));
return media_device_id_salt_->GetSalt();
}
@ -218,8 +218,7 @@ std::unique_ptr<content::ZoomLevelDelegate>
AtomBrowserContext::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
if (!IsOffTheRecord()) {
return std::make_unique<brightray::ZoomLevelDelegate>(prefs(),
partition_path);
return std::make_unique<ZoomLevelDelegate>(prefs(), partition_path);
}
return std::unique_ptr<content::ZoomLevelDelegate>();
}

View file

@ -10,10 +10,10 @@
#include <string>
#include <vector>
#include "atom/browser/media/media_device_id_salt.h"
#include "atom/browser/net/url_request_context_getter.h"
#include "base/memory/ref_counted_delete_on_sequence.h"
#include "base/memory/weak_ptr.h"
#include "brightray/browser/media/media_device_id_salt.h"
#include "chrome/browser/net/proxy_config_monitor.h"
#include "content/public/browser/browser_context.h"
@ -152,7 +152,7 @@ class AtomBrowserContext
std::unique_ptr<WebViewManager> guest_manager_;
std::unique_ptr<AtomPermissionManager> permission_manager_;
std::unique_ptr<AtomBlobReader> blob_reader_;
std::unique_ptr<brightray::MediaDeviceIDSalt> media_device_id_salt_;
std::unique_ptr<MediaDeviceIDSalt> media_device_id_salt_;
scoped_refptr<ResolveProxyHelper> resolve_proxy_helper_;
scoped_refptr<storage::SpecialStoragePolicy> storage_policy_;

View file

@ -14,6 +14,7 @@
#include "atom/browser/browser.h"
#include "atom/browser/io_thread.h"
#include "atom/browser/javascript_environment.h"
#include "atom/browser/media/media_capture_devices_dispatcher.h"
#include "atom/browser/node_debugger.h"
#include "atom/browser/ui/devtools_manager_delegate.h"
#include "atom/common/api/atom_bindings.h"
@ -177,6 +178,9 @@ int AtomBrowserMainParts::PreCreateThreads() {
brightray::BrowserClient::Get()->GetApplicationLocale());
}
// Force MediaCaptureDevicesDispatcher to be created on UI thread.
MediaCaptureDevicesDispatcher::GetInstance();
#if defined(OS_MACOSX)
ui::InitIdleMonitor();
#endif

View file

@ -0,0 +1,152 @@
// 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"
#include "content/public/common/media_stream_request.h"
namespace atom {
using content::BrowserThread;
using content::MediaStreamDevices;
namespace {
// Finds a device in |devices| that has |device_id|, or NULL if not found.
const content::MediaStreamDevice* FindDeviceWithId(
const content::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;
}
const MediaStreamDevices& EmptyDevices() {
static MediaStreamDevices* devices = new MediaStreamDevices;
return *devices;
}
} // 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 MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (is_device_enumeration_disabled_)
return EmptyDevices();
return content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
}
const MediaStreamDevices&
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (is_device_enumeration_disabled_)
return EmptyDevices();
return content::MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
}
void MediaCaptureDevicesDispatcher::GetDefaultDevices(
bool audio,
bool video,
content::MediaStreamDevices* devices) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(audio || video);
if (audio) {
const content::MediaStreamDevice* device = GetFirstAvailableAudioDevice();
if (device)
devices->push_back(*device);
}
if (video) {
const content::MediaStreamDevice* device = GetFirstAvailableVideoDevice();
if (device)
devices->push_back(*device);
}
}
const content::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetRequestedAudioDevice(
const std::string& requested_audio_device_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
const content::MediaStreamDevice* const device =
FindDeviceWithId(audio_devices, requested_audio_device_id);
return device;
}
const content::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
if (audio_devices.empty())
return nullptr;
return &(*audio_devices.begin());
}
const content::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetRequestedVideoDevice(
const std::string& requested_video_device_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
const content::MediaStreamDevice* const device =
FindDeviceWithId(video_devices, requested_video_device_id);
return device;
}
const content::MediaStreamDevice*
MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const content::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,
content::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,
content::MediaStreamType stream_type,
bool is_secure) {}
} // namespace atom

View file

@ -0,0 +1,83 @@
// 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/common/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 content::MediaStreamDevices& GetAudioCaptureDevices();
const content::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,
content::MediaStreamDevices* devices);
// Helpers for picking particular requested devices, identified by raw id.
// If the device requested is not available it will return NULL.
const content::MediaStreamDevice* GetRequestedAudioDevice(
const std::string& requested_audio_device_id);
const content::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 content::MediaStreamDevice* GetFirstAvailableAudioDevice();
const content::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,
content::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,
content::MediaStreamType stream_type,
bool is_secure) override;
private:
friend struct base::DefaultSingletonTraits<MediaCaptureDevicesDispatcher>;
MediaCaptureDevicesDispatcher();
~MediaCaptureDevicesDispatcher() override;
// 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[] = "brightray.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,191 @@
// 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/common/media_stream_request.h"
namespace atom {
namespace {
bool HasAnyAvailableDevice() {
const content::MediaStreamDevices& audio_devices =
MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices();
const content::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 == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
webcam_requested_(
request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {}
MediaStreamDevicesController::~MediaStreamDevicesController() {
if (!callback_.is_null()) {
std::move(callback_).Run(content::MediaStreamDevices(),
content::MEDIA_DEVICE_INVALID_STATE,
std::unique_ptr<content::MediaStreamUI>());
}
}
bool MediaStreamDevicesController::TakeAction() {
// Do special handling of desktop screen cast.
if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE ||
request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE ||
request_.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE ||
request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) {
HandleUserMediaRequest();
return true;
}
// Deny the request if there is no device attached to the OS.
if (!HasAnyAvailableDevice()) {
Deny(content::MEDIA_DEVICE_NO_HARDWARE);
return true;
}
Accept();
return true;
}
void MediaStreamDevicesController::Accept() {
// Get the default devices for the request.
content::MediaStreamDevices devices;
if (microphone_requested_ || webcam_requested_) {
switch (request_.request_type) {
case content::MEDIA_OPEN_DEVICE_PEPPER_ONLY: {
const content::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 == content::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 == content::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 content::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 content::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 content::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 content::MEDIA_DEVICE_ACCESS:
// Get the default devices for the request.
MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevices(
microphone_requested_, webcam_requested_, &devices);
break;
}
}
std::move(callback_).Run(devices, content::MEDIA_DEVICE_OK,
std::unique_ptr<content::MediaStreamUI>());
}
void MediaStreamDevicesController::Deny(
content::MediaStreamRequestResult result) {
std::move(callback_).Run(content::MediaStreamDevices(), result,
std::unique_ptr<content::MediaStreamUI>());
}
void MediaStreamDevicesController::HandleUserMediaRequest() {
content::MediaStreamDevices devices;
if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) {
devices.push_back(
content::MediaStreamDevice(content::MEDIA_TAB_AUDIO_CAPTURE, "", ""));
}
if (request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) {
devices.push_back(
content::MediaStreamDevice(content::MEDIA_TAB_VIDEO_CAPTURE, "", ""));
}
if (request_.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE) {
devices.push_back(content::MediaStreamDevice(
content::MEDIA_DESKTOP_AUDIO_CAPTURE, "loopback", "System Audio"));
}
if (request_.video_type == content::MEDIA_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(content::MediaStreamDevice(
content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen"));
}
std::move(callback_).Run(devices,
devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE
: content::MEDIA_DEVICE_OK,
std::unique_ptr<content::MediaStreamUI>());
}
} // namespace atom

View file

@ -0,0 +1,45 @@
// 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"
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(content::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_

View file

@ -7,10 +7,10 @@
#include <utility>
#include "atom/browser/browser.h"
#include "atom/browser/net/require_ct_delegate.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "base/containers/linked_list.h"
#include "base/memory/weak_ptr.h"
#include "brightray/browser/net/require_ct_delegate.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/net_errors.h"
#include "net/cert/cert_verify_result.h"
@ -150,7 +150,7 @@ class CertVerifierRequest : public AtomCertVerifier::Request {
base::WeakPtrFactory<CertVerifierRequest> weak_ptr_factory_;
};
AtomCertVerifier::AtomCertVerifier(brightray::RequireCTDelegate* ct_delegate)
AtomCertVerifier::AtomCertVerifier(RequireCTDelegate* ct_delegate)
: default_cert_verifier_(net::CertVerifier::CreateDefault()),
ct_delegate_(ct_delegate) {}

View file

@ -11,15 +11,10 @@
#include "net/cert/cert_verifier.h"
namespace brightray {
class RequireCTDelegate;
} // namespace brightray
namespace atom {
class CertVerifierRequest;
class RequireCTDelegate;
struct VerifyRequestParams {
std::string hostname;
@ -34,7 +29,7 @@ struct VerifyRequestParams {
class AtomCertVerifier : public net::CertVerifier {
public:
explicit AtomCertVerifier(brightray::RequireCTDelegate* ct_delegate);
explicit AtomCertVerifier(RequireCTDelegate* ct_delegate);
~AtomCertVerifier() override;
using VerifyProc = base::Callback<void(const VerifyRequestParams& request,
@ -43,7 +38,7 @@ class AtomCertVerifier : public net::CertVerifier {
void SetVerifyProc(const VerifyProc& proc);
const VerifyProc verify_proc() const { return verify_proc_; }
brightray::RequireCTDelegate* ct_delegate() const { return ct_delegate_; }
RequireCTDelegate* ct_delegate() const { return ct_delegate_; }
net::CertVerifier* default_verifier() const {
return default_cert_verifier_.get();
}
@ -66,7 +61,7 @@ class AtomCertVerifier : public net::CertVerifier {
std::map<RequestParams, CertVerifierRequest*> inflight_requests_;
VerifyProc verify_proc_;
std::unique_ptr<net::CertVerifier> default_cert_verifier_;
brightray::RequireCTDelegate* ct_delegate_;
RequireCTDelegate* ct_delegate_;
DISALLOW_COPY_AND_ASSIGN(AtomCertVerifier);
};

View file

@ -0,0 +1,36 @@
// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/net/require_ct_delegate.h"
#include "content/public/browser/browser_thread.h"
namespace atom {
RequireCTDelegate::RequireCTDelegate() {}
RequireCTDelegate::~RequireCTDelegate() {}
void RequireCTDelegate::AddCTExcludedHost(const std::string& host) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
ct_excluded_hosts_.insert(host);
}
void RequireCTDelegate::ClearCTExcludedHostsList() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
ct_excluded_hosts_.clear();
}
RequireCTDelegate::CTRequirementLevel RequireCTDelegate::IsCTRequiredForHost(
const std::string& host,
const net::X509Certificate* chain,
const net::HashValueVector& hashes) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (!ct_excluded_hosts_.empty() &&
(ct_excluded_hosts_.find(host) != ct_excluded_hosts_.end()))
return CTRequirementLevel::NOT_REQUIRED;
return CTRequirementLevel::DEFAULT;
}
} // namespace atom

View file

@ -0,0 +1,37 @@
// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_NET_REQUIRE_CT_DELEGATE_H_
#define ATOM_BROWSER_NET_REQUIRE_CT_DELEGATE_H_
#include <set>
#include <string>
#include "net/http/transport_security_state.h"
namespace atom {
class RequireCTDelegate
: public net::TransportSecurityState::RequireCTDelegate {
public:
RequireCTDelegate();
~RequireCTDelegate() override;
void AddCTExcludedHost(const std::string& host);
void ClearCTExcludedHostsList();
// net::TransportSecurityState::RequireCTDelegate:
CTRequirementLevel IsCTRequiredForHost(
const std::string& host,
const net::X509Certificate* chain,
const net::HashValueVector& hashes) override;
private:
std::set<std::string> ct_excluded_hosts_;
DISALLOW_COPY_AND_ASSIGN(RequireCTDelegate);
};
} // namespace atom
#endif // ATOM_BROWSER_NET_REQUIRE_CT_DELEGATE_H_

View file

@ -17,10 +17,10 @@
#include "atom/browser/net/atom_network_delegate.h"
#include "atom/browser/net/atom_url_request_job_factory.h"
#include "atom/browser/net/http_protocol_handler.h"
#include "atom/browser/net/require_ct_delegate.h"
#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "base/task_scheduler/post_task.h"
#include "brightray/browser/net/require_ct_delegate.h"
#include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
@ -317,7 +317,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
network_delegate_ = network_delegate.get();
builder->set_network_delegate(std::move(network_delegate));
ct_delegate_.reset(new brightray::RequireCTDelegate);
ct_delegate_.reset(new RequireCTDelegate);
auto cert_verifier = std::make_unique<AtomCertVerifier>(ct_delegate_.get());
builder->SetCertVerifier(std::move(cert_verifier));

View file

@ -19,15 +19,12 @@
#include "base/debug/leak_tracker.h"
#endif
namespace brightray {
class RequireCTDelegate;
} // namespace brightray
namespace atom {
class AtomBrowserContext;
class AtomNetworkDelegate;
class AtomURLRequestJobFactory;
class RequireCTDelegate;
class ResourceContext;
class URLRequestContextGetter : public net::URLRequestContextGetter {
@ -96,7 +93,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
base::debug::LeakTracker<URLRequestContextGetter> leak_tracker_;
#endif
std::unique_ptr<brightray::RequireCTDelegate> ct_delegate_;
std::unique_ptr<RequireCTDelegate> ct_delegate_;
std::unique_ptr<AtomURLRequestJobFactory> top_job_factory_;
std::unique_ptr<network::mojom::NetworkContext> network_context_;

View file

@ -9,12 +9,12 @@
#include <vector>
#include "atom/browser/notifications/notification_delegate.h"
#include "atom/common/platform_util.h"
#include "base/files/file_enumerator.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "brightray/common/application_info.h"
#include "brightray/common/platform_util.h"
#include "chrome/browser/ui/libgtkui/gtk_util.h"
#include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
#include "third_party/skia/include/core/SkBitmap.h"
@ -127,7 +127,7 @@ void LibnotifyNotification::Show(const NotificationOptions& options) {
// Send the desktop name to identify the application
// The desktop-entry is the part before the .desktop
std::string desktop_id;
if (brightray::platform_util::GetDesktopName(&desktop_id)) {
if (platform_util::GetDesktopName(&desktop_id)) {
const std::string suffix{".desktop"};
if (base::EndsWith(desktop_id, suffix,
base::CompareCase::INSENSITIVE_ASCII)) {

View file

@ -9,8 +9,8 @@
#include <utility>
#include "atom/browser/atom_permission_manager.h"
#include "atom/browser/media/media_stream_devices_controller.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "brightray/browser/media/media_stream_devices_controller.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_process_host.h"
@ -38,8 +38,7 @@ namespace {
void MediaAccessAllowed(const content::MediaStreamRequest& request,
content::MediaResponseCallback callback,
bool allowed) {
brightray::MediaStreamDevicesController controller(request,
std::move(callback));
MediaStreamDevicesController controller(request, std::move(callback));
if (allowed)
controller.TakeAction();
else

View file

@ -0,0 +1,167 @@
// 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 "atom/browser/zoom_level_delegate.h"
#include <functional>
#include <memory>
#include <vector>
#include "base/bind.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_filter.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service_factory.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/page_zoom.h"
namespace atom {
namespace {
// Double that indicates the default zoom level.
const char kPartitionDefaultZoomLevel[] = "partition.default_zoom_level";
// Dictionary that maps hostnames to zoom levels. Hosts not in this pref will
// be displayed at the default zoom level.
const char kPartitionPerHostZoomLevels[] = "partition.per_host_zoom_levels";
std::string GetHash(const base::FilePath& partition_path) {
size_t int_key = std::hash<base::FilePath>()(partition_path);
return base::NumberToString(int_key);
}
} // namespace
// static
void ZoomLevelDelegate::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(kPartitionDefaultZoomLevel);
registry->RegisterDictionaryPref(kPartitionPerHostZoomLevels);
}
ZoomLevelDelegate::ZoomLevelDelegate(PrefService* pref_service,
const base::FilePath& partition_path)
: pref_service_(pref_service), host_zoom_map_(nullptr) {
DCHECK(pref_service_);
partition_key_ = GetHash(partition_path);
}
ZoomLevelDelegate::~ZoomLevelDelegate() {}
void ZoomLevelDelegate::SetDefaultZoomLevelPref(double level) {
if (content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel()))
return;
DictionaryPrefUpdate update(pref_service_, kPartitionDefaultZoomLevel);
update->SetDouble(partition_key_, level);
host_zoom_map_->SetDefaultZoomLevel(level);
}
double ZoomLevelDelegate::GetDefaultZoomLevelPref() const {
double default_zoom_level = 0.0;
const base::DictionaryValue* default_zoom_level_dictionary =
pref_service_->GetDictionary(kPartitionDefaultZoomLevel);
// If no default has been previously set, the default returned is the
// value used to initialize default_zoom_level in this function.
default_zoom_level_dictionary->GetDouble(partition_key_, &default_zoom_level);
return default_zoom_level;
}
void ZoomLevelDelegate::OnZoomLevelChanged(
const content::HostZoomMap::ZoomLevelChange& change) {
if (change.mode != content::HostZoomMap::ZOOM_CHANGED_FOR_HOST)
return;
double level = change.zoom_level;
DictionaryPrefUpdate update(pref_service_, kPartitionPerHostZoomLevels);
base::DictionaryValue* host_zoom_dictionaries = update.Get();
DCHECK(host_zoom_dictionaries);
bool modification_is_removal =
content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel());
base::DictionaryValue* host_zoom_dictionary = nullptr;
if (!host_zoom_dictionaries->GetDictionary(partition_key_,
&host_zoom_dictionary)) {
host_zoom_dictionary = host_zoom_dictionaries->SetDictionary(
partition_key_, std::make_unique<base::DictionaryValue>());
}
if (modification_is_removal)
host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, nullptr);
else
host_zoom_dictionary->SetKey(change.host, base::Value(level));
}
void ZoomLevelDelegate::ExtractPerHostZoomLevels(
const base::DictionaryValue* host_zoom_dictionary) {
std::vector<std::string> keys_to_remove;
std::unique_ptr<base::DictionaryValue> host_zoom_dictionary_copy =
host_zoom_dictionary->DeepCopyWithoutEmptyChildren();
for (base::DictionaryValue::Iterator i(*host_zoom_dictionary_copy);
!i.IsAtEnd(); i.Advance()) {
const std::string& host(i.key());
double zoom_level = 0;
bool has_valid_zoom_level = i.value().GetAsDouble(&zoom_level);
// Filter out A) the empty host, B) zoom levels equal to the default; and
// remember them, so that we can later erase them from Prefs.
// Values of type B could further have been stored before the default zoom
// level was set to its current value. In either case, SetZoomLevelForHost
// will ignore type B values, thus, to have consistency with HostZoomMap's
// internal state, these values must also be removed from Prefs.
if (host.empty() || !has_valid_zoom_level ||
content::ZoomValuesEqual(zoom_level,
host_zoom_map_->GetDefaultZoomLevel())) {
keys_to_remove.push_back(host);
continue;
}
host_zoom_map_->SetZoomLevelForHost(host, zoom_level);
}
// Sanitize prefs to remove entries that match the default zoom level and/or
// have an empty host.
{
DictionaryPrefUpdate update(pref_service_, kPartitionPerHostZoomLevels);
base::DictionaryValue* host_zoom_dictionaries = update.Get();
base::DictionaryValue* sanitized_host_zoom_dictionary = nullptr;
host_zoom_dictionaries->GetDictionary(partition_key_,
&sanitized_host_zoom_dictionary);
for (const std::string& s : keys_to_remove)
sanitized_host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr);
}
}
void ZoomLevelDelegate::InitHostZoomMap(content::HostZoomMap* host_zoom_map) {
// This init function must be called only once.
DCHECK(!host_zoom_map_);
DCHECK(host_zoom_map);
host_zoom_map_ = host_zoom_map;
// Initialize the default zoom level.
host_zoom_map_->SetDefaultZoomLevel(GetDefaultZoomLevelPref());
// Initialize the HostZoomMap with per-host zoom levels from the persisted
// zoom-level preference values.
const base::DictionaryValue* host_zoom_dictionaries =
pref_service_->GetDictionary(kPartitionPerHostZoomLevels);
const base::DictionaryValue* host_zoom_dictionary = nullptr;
if (host_zoom_dictionaries->GetDictionary(partition_key_,
&host_zoom_dictionary)) {
// Since we're calling this before setting up zoom_subscription_ below we
// don't need to worry that host_zoom_dictionary is indirectly affected
// by calls to HostZoomMap::SetZoomLevelForHost().
ExtractPerHostZoomLevels(host_zoom_dictionary);
}
zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind(
&ZoomLevelDelegate::OnZoomLevelChanged, base::Unretained(this)));
}
} // namespace atom

View file

@ -0,0 +1,64 @@
// 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.
#ifndef ATOM_BROWSER_ZOOM_LEVEL_DELEGATE_H_
#define ATOM_BROWSER_ZOOM_LEVEL_DELEGATE_H_
#include <memory>
#include <string>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/zoom_level_delegate.h"
namespace base {
class DictionaryValue;
}
class PrefRegistrySimple;
namespace atom {
// A class to manage per-partition default and per-host zoom levels.
// It implements an interface between the content/ zoom
// levels in HostZoomMap and preference system. All changes
// to the per-partition default zoom levels flow through this
// class. Any changes to per-host levels are updated when HostZoomMap calls
// OnZoomLevelChanged.
class ZoomLevelDelegate : public content::ZoomLevelDelegate {
public:
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
ZoomLevelDelegate(PrefService* pref_service,
const base::FilePath& partition_path);
~ZoomLevelDelegate() override;
void SetDefaultZoomLevelPref(double level);
double GetDefaultZoomLevelPref() const;
// content::ZoomLevelDelegate:
void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override;
private:
void ExtractPerHostZoomLevels(
const base::DictionaryValue* host_zoom_dictionary);
// This is a callback function that receives notifications from HostZoomMap
// when per-host zoom levels change. It is used to update the per-host
// zoom levels (if any) managed by this class (for its associated partition).
void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
PrefService* pref_service_;
content::HostZoomMap* host_zoom_map_;
std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
std::string partition_key_;
DISALLOW_COPY_AND_ASSIGN(ZoomLevelDelegate);
};
} // namespace atom
#endif // ATOM_BROWSER_ZOOM_LEVEL_DELEGATE_H_