2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-15 16:25:08 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_browser_context.h"
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
#include <memory>
|
2024-06-07 21:18:35 +00:00
|
|
|
#include <optional>
|
2019-09-16 22:12:00 +00:00
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
#include "base/barrier_closure.h"
|
2021-06-17 21:17:25 +00:00
|
|
|
#include "base/base_paths.h"
|
2015-01-05 21:40:38 +00:00
|
|
|
#include "base/command_line.h"
|
2015-07-26 08:17:55 +00:00
|
|
|
#include "base/files/file_path.h"
|
2020-08-17 20:21:53 +00:00
|
|
|
#include "base/no_destructor.h"
|
2016-01-21 08:21:37 +00:00
|
|
|
#include "base/path_service.h"
|
2022-05-17 16:48:40 +00:00
|
|
|
#include "base/strings/escape.h"
|
2024-01-24 22:43:31 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2016-01-21 08:21:37 +00:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2015-07-26 08:17:55 +00:00
|
|
|
#include "chrome/common/pref_names.h"
|
2018-10-11 13:52:12 +00:00
|
|
|
#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "components/prefs/json_pref_store.h"
|
2016-06-15 11:31:29 +00:00
|
|
|
#include "components/prefs/pref_registry_simple.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "components/prefs/pref_service.h"
|
|
|
|
#include "components/prefs/pref_service_factory.h"
|
|
|
|
#include "components/prefs/value_map_pref_store.h"
|
|
|
|
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
|
|
|
|
#include "components/proxy_config/proxy_config_pref_names.h"
|
2019-03-05 05:08:55 +00:00
|
|
|
#include "content/browser/blob_storage/chrome_blob_storage_context.h" // nogncheck
|
2019-01-22 19:50:25 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2021-02-09 20:16:21 +00:00
|
|
|
#include "content/public/browser/cors_origin_pattern_setter.h"
|
2024-01-25 17:46:30 +00:00
|
|
|
#include "content/public/browser/host_zoom_map.h"
|
2022-08-22 21:15:32 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2021-02-09 20:16:21 +00:00
|
|
|
#include "content/public/browser/shared_cors_origin_access_list.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "content/public/browser/storage_partition.h"
|
2022-08-22 21:15:32 +00:00
|
|
|
#include "content/public/browser/web_contents_media_capture_id.h"
|
|
|
|
#include "media/audio/audio_device_description.h"
|
2019-03-26 01:10:48 +00:00
|
|
|
#include "services/network/public/cpp/features.h"
|
2024-01-31 23:04:13 +00:00
|
|
|
#include "services/network/public/cpp/url_loader_factory_builder.h"
|
2019-08-29 06:07:46 +00:00
|
|
|
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
#include "services/network/public/mojom/network_context.mojom.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/cookie_change_notifier.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_browser_client.h"
|
|
|
|
#include "shell/browser/electron_browser_main_parts.h"
|
|
|
|
#include "shell/browser/electron_download_manager_delegate.h"
|
|
|
|
#include "shell/browser/electron_permission_manager.h"
|
2024-04-10 20:06:47 +00:00
|
|
|
#include "shell/browser/file_system_access/file_system_access_permission_context_factory.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/net/resolve_proxy_helper.h"
|
2020-03-26 17:34:32 +00:00
|
|
|
#include "shell/browser/protocol_registry.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/special_storage_policy.h"
|
2020-07-15 18:27:42 +00:00
|
|
|
#include "shell/browser/ui/inspectable_web_contents.h"
|
2024-04-23 15:30:47 +00:00
|
|
|
#include "shell/browser/ui/webui/accessibility_ui.h"
|
2022-06-27 20:50:08 +00:00
|
|
|
#include "shell/browser/web_contents_permission_helper.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/web_view_manager.h"
|
|
|
|
#include "shell/browser/zoom_level_delegate.h"
|
|
|
|
#include "shell/common/application_info.h"
|
2022-11-22 21:50:32 +00:00
|
|
|
#include "shell/common/electron_constants.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "shell/common/electron_paths.h"
|
2022-08-22 21:15:32 +00:00
|
|
|
#include "shell/common/gin_converters/frame_converter.h"
|
|
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
2022-11-17 19:59:23 +00:00
|
|
|
#include "shell/common/thread_restrictions.h"
|
2024-01-25 17:46:30 +00:00
|
|
|
#include "third_party/blink/public/common/page/page_zoom.h"
|
2023-05-24 15:17:08 +00:00
|
|
|
#include "third_party/blink/public/mojom/media/capture_handle_config.mojom.h"
|
2022-08-22 21:15:32 +00:00
|
|
|
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
#include "extensions/browser/browser_context_keyed_service_factories.h"
|
|
|
|
#include "extensions/browser/extension_pref_store.h"
|
|
|
|
#include "extensions/browser/extension_pref_value_map_factory.h"
|
|
|
|
#include "extensions/browser/extension_prefs.h"
|
2023-11-15 14:30:47 +00:00
|
|
|
#include "extensions/browser/permissions_manager.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "extensions/browser/pref_names.h"
|
|
|
|
#include "extensions/common/extension_api.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/browser/extensions/electron_browser_context_keyed_service_factories.h"
|
|
|
|
#include "shell/browser/extensions/electron_extension_system.h"
|
|
|
|
#include "shell/browser/extensions/electron_extension_system_factory.h"
|
|
|
|
#include "shell/browser/extensions/electron_extensions_browser_client.h"
|
|
|
|
#include "shell/common/extensions/electron_extensions_client.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) || \
|
|
|
|
BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
#include "components/pref_registry/pref_registry_syncable.h"
|
|
|
|
#include "components/user_prefs/user_prefs.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
#include "base/i18n/rtl.h"
|
|
|
|
#include "components/language/core/browser/language_prefs.h"
|
|
|
|
#include "components/spellcheck/browser/pref_names.h"
|
|
|
|
#include "components/spellcheck/common/spellcheck_common.h"
|
|
|
|
#endif
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
using content::BrowserThread;
|
2013-09-20 08:47:47 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-09-20 08:47:47 +00:00
|
|
|
|
2014-09-23 04:13:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2023-05-24 15:17:08 +00:00
|
|
|
// Copied from chrome/browser/media/webrtc/desktop_capture_devices_util.cc.
|
|
|
|
media::mojom::CaptureHandlePtr CreateCaptureHandle(
|
|
|
|
content::WebContents* capturer,
|
|
|
|
const url::Origin& capturer_origin,
|
|
|
|
const content::DesktopMediaID& captured_id) {
|
|
|
|
if (capturer_origin.opaque()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::RenderFrameHost* const captured_rfh =
|
|
|
|
content::RenderFrameHost::FromID(
|
|
|
|
captured_id.web_contents_id.render_process_id,
|
|
|
|
captured_id.web_contents_id.main_render_frame_id);
|
|
|
|
if (!captured_rfh || !captured_rfh->IsActive()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::WebContents* const captured =
|
|
|
|
content::WebContents::FromRenderFrameHost(captured_rfh);
|
|
|
|
if (!captured) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& captured_config = captured->GetCaptureHandleConfig();
|
|
|
|
if (!captured_config.all_origins_permitted &&
|
|
|
|
base::ranges::none_of(
|
|
|
|
captured_config.permitted_origins,
|
|
|
|
[capturer_origin](const url::Origin& permitted_origin) {
|
|
|
|
return capturer_origin.IsSameOriginWith(permitted_origin);
|
|
|
|
})) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Observing CaptureHandle when either the capturing or the captured party
|
|
|
|
// is incognito is disallowed, except for self-capture.
|
|
|
|
if (capturer->GetPrimaryMainFrame() != captured->GetPrimaryMainFrame()) {
|
|
|
|
if (capturer->GetBrowserContext()->IsOffTheRecord() ||
|
|
|
|
captured->GetBrowserContext()->IsOffTheRecord()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!captured_config.expose_origin &&
|
|
|
|
captured_config.capture_handle.empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = media::mojom::CaptureHandle::New();
|
|
|
|
if (captured_config.expose_origin) {
|
|
|
|
result->origin = captured->GetPrimaryMainFrame()->GetLastCommittedOrigin();
|
|
|
|
}
|
|
|
|
result->capture_handle = captured_config.capture_handle;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-01-25 17:46:30 +00:00
|
|
|
// Copied from chrome/browser/media/webrtc/desktop_capture_devices_util.cc.
|
2024-06-07 21:18:35 +00:00
|
|
|
std::optional<int> GetZoomLevel(content::WebContents* capturer,
|
|
|
|
const url::Origin& capturer_origin,
|
|
|
|
const content::DesktopMediaID& captured_id) {
|
2024-01-25 17:46:30 +00:00
|
|
|
content::RenderFrameHost* const captured_rfh =
|
|
|
|
content::RenderFrameHost::FromID(
|
|
|
|
captured_id.web_contents_id.render_process_id,
|
|
|
|
captured_id.web_contents_id.main_render_frame_id);
|
|
|
|
if (!captured_rfh || !captured_rfh->IsActive()) {
|
2024-06-07 21:18:35 +00:00
|
|
|
return std::nullopt;
|
2024-01-25 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
content::WebContents* const captured_wc =
|
|
|
|
content::WebContents::FromRenderFrameHost(captured_rfh);
|
|
|
|
if (!captured_wc) {
|
2024-06-07 21:18:35 +00:00
|
|
|
return std::nullopt;
|
2024-01-25 17:46:30 +00:00
|
|
|
}
|
|
|
|
|
2024-07-02 07:51:33 +00:00
|
|
|
double zoom_level = blink::ZoomLevelToZoomFactor(
|
2024-01-25 17:46:30 +00:00
|
|
|
content::HostZoomMap::GetZoomLevel(captured_wc));
|
|
|
|
return std::round(100 * zoom_level);
|
|
|
|
}
|
|
|
|
|
2023-05-24 15:17:08 +00:00
|
|
|
// Copied from chrome/browser/media/webrtc/desktop_capture_devices_util.cc.
|
|
|
|
media::mojom::DisplayMediaInformationPtr
|
|
|
|
DesktopMediaIDToDisplayMediaInformation(
|
|
|
|
content::WebContents* capturer,
|
|
|
|
const url::Origin& capturer_origin,
|
|
|
|
const content::DesktopMediaID& media_id) {
|
|
|
|
media::mojom::DisplayCaptureSurfaceType display_surface =
|
|
|
|
media::mojom::DisplayCaptureSurfaceType::MONITOR;
|
|
|
|
bool logical_surface = true;
|
|
|
|
media::mojom::CursorCaptureType cursor =
|
|
|
|
media::mojom::CursorCaptureType::NEVER;
|
|
|
|
#if defined(USE_AURA)
|
|
|
|
const bool uses_aura =
|
|
|
|
media_id.window_id != content::DesktopMediaID::kNullId ? true : false;
|
|
|
|
#else
|
|
|
|
const bool uses_aura = false;
|
|
|
|
#endif // defined(USE_AURA)
|
|
|
|
|
|
|
|
media::mojom::CaptureHandlePtr capture_handle;
|
2024-01-25 17:46:30 +00:00
|
|
|
int zoom_level = 100;
|
2023-05-24 15:17:08 +00:00
|
|
|
switch (media_id.type) {
|
|
|
|
case content::DesktopMediaID::TYPE_SCREEN:
|
|
|
|
display_surface = media::mojom::DisplayCaptureSurfaceType::MONITOR;
|
|
|
|
cursor = uses_aura ? media::mojom::CursorCaptureType::MOTION
|
|
|
|
: media::mojom::CursorCaptureType::ALWAYS;
|
|
|
|
break;
|
|
|
|
case content::DesktopMediaID::TYPE_WINDOW:
|
|
|
|
display_surface = media::mojom::DisplayCaptureSurfaceType::WINDOW;
|
|
|
|
cursor = uses_aura ? media::mojom::CursorCaptureType::MOTION
|
|
|
|
: media::mojom::CursorCaptureType::ALWAYS;
|
|
|
|
break;
|
|
|
|
case content::DesktopMediaID::TYPE_WEB_CONTENTS:
|
|
|
|
display_surface = media::mojom::DisplayCaptureSurfaceType::BROWSER;
|
|
|
|
cursor = media::mojom::CursorCaptureType::MOTION;
|
|
|
|
capture_handle = CreateCaptureHandle(capturer, capturer_origin, media_id);
|
2024-01-25 17:46:30 +00:00
|
|
|
zoom_level =
|
|
|
|
GetZoomLevel(capturer, capturer_origin, media_id).value_or(100);
|
2023-05-24 15:17:08 +00:00
|
|
|
break;
|
|
|
|
case content::DesktopMediaID::TYPE_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return media::mojom::DisplayMediaInformation::New(
|
2024-01-25 17:46:30 +00:00
|
|
|
display_surface, logical_surface, cursor, std::move(capture_handle),
|
|
|
|
zoom_level);
|
2023-05-24 15:17:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
// Convert string to lower case and escape it.
|
|
|
|
std::string MakePartitionName(const std::string& input) {
|
2022-05-17 16:48:40 +00:00
|
|
|
return base::EscapePath(base::ToLowerASCII(input));
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 17:33:32 +00:00
|
|
|
[[nodiscard]] content::DesktopMediaID GetAudioDesktopMediaId(
|
|
|
|
const std::vector<std::string>& audio_device_ids) {
|
|
|
|
// content::MediaStreamRequest provides a vector of ids
|
|
|
|
// to allow user preference to influence which stream is
|
|
|
|
// returned. This is a WIP upstream, so for now just use
|
|
|
|
// the first device in the list.
|
|
|
|
// Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5132210
|
|
|
|
if (!audio_device_ids.empty())
|
|
|
|
return content::DesktopMediaID::Parse(audio_device_ids.front());
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2024-04-19 15:55:59 +00:00
|
|
|
bool DoesDeviceMatch(const base::Value& device,
|
|
|
|
const base::Value& device_to_compare,
|
|
|
|
const blink::PermissionType permission_type) {
|
|
|
|
if (permission_type ==
|
|
|
|
static_cast<blink::PermissionType>(
|
|
|
|
WebContentsPermissionHelper::PermissionType::HID) ||
|
|
|
|
permission_type ==
|
|
|
|
static_cast<blink::PermissionType>(
|
|
|
|
WebContentsPermissionHelper::PermissionType::USB)) {
|
|
|
|
if (device.GetDict().FindInt(kDeviceVendorIdKey) !=
|
|
|
|
device_to_compare.GetDict().FindInt(kDeviceVendorIdKey) ||
|
|
|
|
device.GetDict().FindInt(kDeviceProductIdKey) !=
|
|
|
|
device_to_compare.GetDict().FindInt(kDeviceProductIdKey)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto* serial_number =
|
|
|
|
device_to_compare.GetDict().FindString(kDeviceSerialNumberKey);
|
|
|
|
const auto* device_serial_number =
|
|
|
|
device.GetDict().FindString(kDeviceSerialNumberKey);
|
|
|
|
|
|
|
|
if (serial_number && device_serial_number &&
|
|
|
|
*device_serial_number == *serial_number)
|
|
|
|
return true;
|
|
|
|
} else if (permission_type ==
|
|
|
|
static_cast<blink::PermissionType>(
|
|
|
|
WebContentsPermissionHelper::PermissionType::SERIAL)) {
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
const auto* instance_id = device.GetDict().FindString(kDeviceInstanceIdKey);
|
|
|
|
const auto* port_instance_id =
|
|
|
|
device_to_compare.GetDict().FindString(kDeviceInstanceIdKey);
|
|
|
|
if (instance_id && port_instance_id && *instance_id == *port_instance_id)
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
const auto* serial_number = device.GetDict().FindString(kSerialNumberKey);
|
|
|
|
const auto* port_serial_number =
|
|
|
|
device_to_compare.GetDict().FindString(kSerialNumberKey);
|
|
|
|
if (device.GetDict().FindInt(kVendorIdKey) !=
|
|
|
|
device_to_compare.GetDict().FindInt(kVendorIdKey) ||
|
|
|
|
device.GetDict().FindInt(kProductIdKey) !=
|
|
|
|
device_to_compare.GetDict().FindInt(kProductIdKey) ||
|
|
|
|
(serial_number && port_serial_number &&
|
|
|
|
*port_serial_number != *serial_number)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
|
|
const auto* usb_driver_key = device.GetDict().FindString(kUsbDriverKey);
|
|
|
|
const auto* port_usb_driver_key =
|
|
|
|
device_to_compare.GetDict().FindString(kUsbDriverKey);
|
|
|
|
if (usb_driver_key && port_usb_driver_key &&
|
|
|
|
*usb_driver_key != *port_usb_driver_key) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // BUILDFLAG(IS_MAC)
|
|
|
|
return true;
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-23 04:13:46 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
// static
|
2020-08-17 20:21:53 +00:00
|
|
|
ElectronBrowserContext::BrowserContextMap&
|
|
|
|
ElectronBrowserContext::browser_context_map() {
|
|
|
|
static base::NoDestructor<ElectronBrowserContext::BrowserContextMap>
|
|
|
|
browser_context_map;
|
|
|
|
return *browser_context_map;
|
|
|
|
}
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2023-03-20 14:34:49 +00:00
|
|
|
ElectronBrowserContext::ElectronBrowserContext(
|
|
|
|
const PartitionOrPath partition_location,
|
|
|
|
bool in_memory,
|
|
|
|
base::Value::Dict options)
|
2022-09-08 23:23:08 +00:00
|
|
|
: in_memory_pref_store_(new ValueMapPrefStore),
|
|
|
|
storage_policy_(base::MakeRefCounted<SpecialStoragePolicy>()),
|
2021-06-15 00:37:55 +00:00
|
|
|
protocol_registry_(base::WrapUnique(new ProtocolRegistry)),
|
2018-10-04 18:08:56 +00:00
|
|
|
in_memory_(in_memory),
|
2021-03-16 19:43:09 +00:00
|
|
|
ssl_config_(network::mojom::SSLConfig::New()) {
|
2016-07-12 13:05:07 +00:00
|
|
|
// Read options.
|
2018-08-14 21:07:53 +00:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
2018-10-04 18:08:56 +00:00
|
|
|
use_cache_ = !command_line->HasSwitch(switches::kDisableHttpCache);
|
2022-07-05 15:25:18 +00:00
|
|
|
if (auto use_cache_opt = options.FindBool("cache")) {
|
2022-01-10 22:31:39 +00:00
|
|
|
use_cache_ = use_cache_opt.value();
|
|
|
|
}
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
base::StringToInt(command_line->GetSwitchValueASCII(switches::kDiskCacheSize),
|
|
|
|
&max_cache_size_);
|
|
|
|
|
2023-03-20 14:34:49 +00:00
|
|
|
if (auto* path_value = std::get_if<std::reference_wrapper<const std::string>>(
|
|
|
|
&partition_location)) {
|
|
|
|
base::PathService::Get(DIR_SESSION_DATA, &path_);
|
|
|
|
const std::string& partition_loc = path_value->get();
|
|
|
|
if (!in_memory && !partition_loc.empty()) {
|
|
|
|
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
|
|
|
.Append(base::FilePath::FromUTF8Unsafe(
|
|
|
|
MakePartitionName(partition_loc)));
|
|
|
|
}
|
|
|
|
} else if (auto* filepath_partition =
|
|
|
|
std::get_if<std::reference_wrapper<const base::FilePath>>(
|
|
|
|
&partition_location)) {
|
|
|
|
const base::FilePath& partition_path = filepath_partition->get();
|
|
|
|
path_ = std::move(partition_path);
|
|
|
|
}
|
2016-07-26 11:04:04 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(this);
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
// Initialize Pref Registry.
|
2016-07-26 11:04:04 +00:00
|
|
|
InitPrefs();
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
cookie_change_notifier_ = std::make_unique<CookieChangeNotifier>(this);
|
2018-10-11 13:52:12 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-05-08 18:17:28 +00:00
|
|
|
if (!in_memory_) {
|
|
|
|
BrowserContextDependencyManager::GetInstance()
|
|
|
|
->CreateBrowserContextServices(this);
|
|
|
|
|
|
|
|
extension_system_ = static_cast<extensions::ElectronExtensionSystem*>(
|
|
|
|
extensions::ExtensionSystem::Get(this));
|
|
|
|
extension_system_->InitForRegularProfile(true /* extensions_enabled */);
|
|
|
|
extension_system_->FinishInitialization();
|
|
|
|
}
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
2016-06-22 06:46:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::~ElectronBrowserContext() {
|
2018-10-04 18:08:56 +00:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
2021-06-03 08:05:04 +00:00
|
|
|
NotifyWillBeDestroyed();
|
2024-07-08 10:56:03 +00:00
|
|
|
|
|
|
|
// the DestroyBrowserContextServices() call below frees this.
|
|
|
|
extension_system_ = nullptr;
|
|
|
|
|
2020-01-13 22:55:58 +00:00
|
|
|
// Notify any keyed services of browser context destruction.
|
|
|
|
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
|
|
|
|
this);
|
2018-10-04 18:08:56 +00:00
|
|
|
ShutdownStoragePartitions();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserContext::InitPrefs() {
|
2018-10-04 18:08:56 +00:00
|
|
|
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
|
2022-11-17 19:59:23 +00:00
|
|
|
ScopedAllowBlockingForElectron allow_blocking;
|
2018-10-04 18:08:56 +00:00
|
|
|
PrefServiceFactory prefs_factory;
|
|
|
|
scoped_refptr<JsonPrefStore> pref_store =
|
|
|
|
base::MakeRefCounted<JsonPrefStore>(prefs_path);
|
|
|
|
pref_store->ReadPrefs(); // Synchronous.
|
|
|
|
prefs_factory.set_user_prefs(pref_store);
|
2022-09-08 23:23:08 +00:00
|
|
|
prefs_factory.set_command_line_prefs(in_memory_pref_store());
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-05-08 18:17:28 +00:00
|
|
|
if (!in_memory_) {
|
|
|
|
auto* ext_pref_store = new ExtensionPrefStore(
|
|
|
|
ExtensionPrefValueMapFactory::GetForBrowserContext(this),
|
|
|
|
IsOffTheRecord());
|
|
|
|
prefs_factory.set_extension_prefs(ext_pref_store);
|
|
|
|
}
|
2019-10-31 20:11:51 +00:00
|
|
|
#endif
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) || \
|
|
|
|
BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2021-06-08 02:00:05 +00:00
|
|
|
auto registry = base::MakeRefCounted<user_prefs::PrefRegistrySyncable>();
|
2019-07-24 23:01:08 +00:00
|
|
|
#else
|
2021-06-08 02:00:05 +00:00
|
|
|
auto registry = base::MakeRefCounted<PrefRegistrySimple>();
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory,
|
|
|
|
base::FilePath());
|
|
|
|
base::FilePath download_dir;
|
|
|
|
base::PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &download_dir);
|
|
|
|
registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
|
|
|
|
download_dir);
|
|
|
|
registry->RegisterDictionaryPref(prefs::kDevToolsFileSystemPaths);
|
2020-07-15 18:27:42 +00:00
|
|
|
InspectableWebContents::RegisterPrefs(registry.get());
|
2018-10-19 18:51:43 +00:00
|
|
|
MediaDeviceIDSalt::RegisterPrefs(registry.get());
|
|
|
|
ZoomLevelDelegate::RegisterPrefs(registry.get());
|
2018-10-04 18:08:56 +00:00
|
|
|
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
|
2024-04-23 15:30:47 +00:00
|
|
|
ElectronAccessibilityUIMessageHandler::RegisterPrefs(registry.get());
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-05-08 18:17:28 +00:00
|
|
|
if (!in_memory_)
|
|
|
|
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
|
2023-11-15 14:30:47 +00:00
|
|
|
extensions::PermissionsManager::RegisterProfilePrefs(registry.get());
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
BrowserContextDependencyManager::GetInstance()
|
|
|
|
->RegisterProfilePrefsForServices(registry.get());
|
|
|
|
|
|
|
|
language::LanguagePrefs::RegisterProfilePrefs(registry.get());
|
|
|
|
#endif
|
|
|
|
|
2022-09-08 23:23:08 +00:00
|
|
|
prefs_ = prefs_factory.Create(registry.get());
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) || \
|
|
|
|
BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2019-07-24 23:01:08 +00:00
|
|
|
user_prefs::UserPrefs::Set(this, prefs_.get());
|
|
|
|
#endif
|
2019-10-31 20:11:51 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
// No configured dictionaries, the default will be en-US
|
2023-06-02 13:38:29 +00:00
|
|
|
if (prefs()->GetList(spellcheck::prefs::kSpellCheckDictionaries).empty()) {
|
2019-10-31 20:11:51 +00:00
|
|
|
std::string default_code = spellcheck::GetCorrespondingSpellCheckLanguage(
|
|
|
|
base::i18n::GetConfiguredLocale());
|
|
|
|
if (!default_code.empty()) {
|
2022-06-22 08:14:35 +00:00
|
|
|
base::Value::List language_codes;
|
2021-10-06 02:21:00 +00:00
|
|
|
language_codes.Append(default_code);
|
2022-06-22 08:14:35 +00:00
|
|
|
prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries,
|
|
|
|
base::Value(std::move(language_codes)));
|
2019-10-31 20:11:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2018-08-14 21:07:53 +00:00
|
|
|
}
|
2016-06-22 06:46:46 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserContext::SetUserAgent(const std::string& user_agent) {
|
2016-06-22 06:57:51 +00:00
|
|
|
user_agent_ = user_agent;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
base::FilePath ElectronBrowserContext::GetPath() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return path_;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserContext::IsOffTheRecord() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return in_memory_;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserContext::GetMediaDeviceIDSalt() {
|
2024-07-08 14:49:41 +00:00
|
|
|
if (!media_device_id_salt_)
|
2019-09-16 22:12:00 +00:00
|
|
|
media_device_id_salt_ = std::make_unique<MediaDeviceIDSalt>(prefs_.get());
|
2018-10-04 18:08:56 +00:00
|
|
|
return media_device_id_salt_->GetSalt();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<content::ZoomLevelDelegate>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::CreateZoomLevelDelegate(
|
2018-10-04 18:08:56 +00:00
|
|
|
const base::FilePath& partition_path) {
|
|
|
|
if (!IsOffTheRecord()) {
|
2018-10-19 18:51:43 +00:00
|
|
|
return std::make_unique<ZoomLevelDelegate>(prefs(), partition_path);
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
return std::unique_ptr<content::ZoomLevelDelegate>();
|
|
|
|
}
|
|
|
|
|
2015-06-22 11:43:49 +00:00
|
|
|
content::DownloadManagerDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetDownloadManagerDelegate() {
|
2024-07-08 14:49:41 +00:00
|
|
|
if (!download_manager_delegate_) {
|
2019-09-16 22:12:00 +00:00
|
|
|
download_manager_delegate_ =
|
2024-07-08 14:49:41 +00:00
|
|
|
std::make_unique<ElectronDownloadManagerDelegate>(GetDownloadManager());
|
2015-06-22 11:43:49 +00:00
|
|
|
}
|
|
|
|
return download_manager_delegate_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::BrowserPluginGuestManager* ElectronBrowserContext::GetGuestManager() {
|
2014-10-22 14:55:13 +00:00
|
|
|
if (!guest_manager_)
|
2019-09-16 22:12:00 +00:00
|
|
|
guest_manager_ = std::make_unique<WebViewManager>();
|
2014-10-22 14:55:13 +00:00
|
|
|
return guest_manager_.get();
|
|
|
|
}
|
|
|
|
|
2021-10-06 02:21:00 +00:00
|
|
|
content::PlatformNotificationService*
|
|
|
|
ElectronBrowserContext::GetPlatformNotificationService() {
|
|
|
|
return ElectronBrowserClient::Get()->GetPlatformNotificationService();
|
|
|
|
}
|
|
|
|
|
2018-10-02 21:53:10 +00:00
|
|
|
content::PermissionControllerDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetPermissionControllerDelegate() {
|
2024-07-08 14:49:41 +00:00
|
|
|
if (!permission_manager_)
|
2020-02-04 20:19:40 +00:00
|
|
|
permission_manager_ = std::make_unique<ElectronPermissionManager>();
|
2016-01-30 11:19:18 +00:00
|
|
|
return permission_manager_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
storage::SpecialStoragePolicy*
|
|
|
|
ElectronBrowserContext::GetSpecialStoragePolicy() {
|
2018-08-21 15:51:04 +00:00
|
|
|
return storage_policy_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserContext::GetUserAgent() const {
|
2022-06-13 16:35:42 +00:00
|
|
|
return user_agent_.value_or(ElectronBrowserClient::Get()->GetUserAgent());
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
predictors::PreconnectManager* ElectronBrowserContext::GetPreconnectManager() {
|
2024-07-08 14:49:41 +00:00
|
|
|
if (!preconnect_manager_) {
|
2019-09-16 22:12:00 +00:00
|
|
|
preconnect_manager_ =
|
|
|
|
std::make_unique<predictors::PreconnectManager>(nullptr, this);
|
2019-08-26 16:47:32 +00:00
|
|
|
}
|
|
|
|
return preconnect_manager_.get();
|
|
|
|
}
|
|
|
|
|
2019-08-29 06:07:46 +00:00
|
|
|
scoped_refptr<network::SharedURLLoaderFactory>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetURLLoaderFactory() {
|
2019-08-29 06:07:46 +00:00
|
|
|
if (url_loader_factory_)
|
|
|
|
return url_loader_factory_;
|
|
|
|
|
2024-01-31 23:04:13 +00:00
|
|
|
network::URLLoaderFactoryBuilder factory_builder;
|
2019-08-29 06:07:46 +00:00
|
|
|
|
|
|
|
// Consult the embedder.
|
2019-09-18 19:58:00 +00:00
|
|
|
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>
|
|
|
|
header_client;
|
2020-02-04 20:19:40 +00:00
|
|
|
static_cast<content::ContentBrowserClient*>(ElectronBrowserClient::Get())
|
2019-08-29 06:07:46 +00:00
|
|
|
->WillCreateURLLoaderFactory(
|
|
|
|
this, nullptr, -1,
|
|
|
|
content::ContentBrowserClient::URLLoaderFactoryType::kNavigation,
|
2024-05-10 15:21:10 +00:00
|
|
|
url::Origin(), net::IsolationInfo(), std::nullopt,
|
|
|
|
ukm::kInvalidSourceIdObj, factory_builder, &header_client, nullptr,
|
|
|
|
nullptr, nullptr, nullptr);
|
2019-08-29 06:07:46 +00:00
|
|
|
|
|
|
|
network::mojom::URLLoaderFactoryParamsPtr params =
|
|
|
|
network::mojom::URLLoaderFactoryParams::New();
|
|
|
|
params->header_client = std::move(header_client);
|
|
|
|
params->process_id = network::mojom::kBrowserProcessId;
|
|
|
|
params->is_trusted = true;
|
2024-02-21 20:27:05 +00:00
|
|
|
params->is_orb_enabled = false;
|
2019-08-29 06:07:46 +00:00
|
|
|
// The tests of net module would fail if this setting is true, it seems that
|
|
|
|
// the non-NetworkService implementation always has web security enabled.
|
|
|
|
params->disable_web_security = false;
|
|
|
|
|
2021-05-04 03:13:46 +00:00
|
|
|
auto* storage_partition = GetDefaultStoragePartition();
|
2019-08-29 06:07:46 +00:00
|
|
|
url_loader_factory_ =
|
2024-01-31 23:04:13 +00:00
|
|
|
std::move(factory_builder)
|
|
|
|
.Finish(storage_partition->GetNetworkContext(), std::move(params));
|
2019-08-29 06:07:46 +00:00
|
|
|
return url_loader_factory_;
|
2019-11-14 18:01:18 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::PushMessagingService*
|
|
|
|
ElectronBrowserContext::GetPushMessagingService() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::SSLHostStateDelegate*
|
|
|
|
ElectronBrowserContext::GetSSLHostStateDelegate() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BackgroundFetchDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetBackgroundFetchDelegate() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BackgroundSyncController*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetBackgroundSyncController() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BrowsingDataRemoverDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetBrowsingDataRemoverDelegate() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-22 19:50:25 +00:00
|
|
|
content::ClientHintsControllerDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetClientHintsControllerDelegate() {
|
2019-01-22 19:50:25 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
content::StorageNotificationService*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetStorageNotificationService() {
|
2019-10-28 22:12:35 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-09-07 07:46:37 +00:00
|
|
|
content::ReduceAcceptLanguageControllerDelegate*
|
|
|
|
ElectronBrowserContext::GetReduceAcceptLanguageControllerDelegate() {
|
|
|
|
// Needs implementation
|
|
|
|
// Refs https://chromium-review.googlesource.com/c/chromium/src/+/3687391
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-04-10 20:06:47 +00:00
|
|
|
content::FileSystemAccessPermissionContext*
|
|
|
|
ElectronBrowserContext::GetFileSystemAccessPermissionContext() {
|
|
|
|
return FileSystemAccessPermissionContextFactory::GetForBrowserContext(this);
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ResolveProxyHelper* ElectronBrowserContext::GetResolveProxyHelper() {
|
2018-10-04 18:08:56 +00:00
|
|
|
if (!resolve_proxy_helper_) {
|
2024-02-22 17:08:25 +00:00
|
|
|
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(
|
|
|
|
GetDefaultStoragePartition()->GetNetworkContext());
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
return resolve_proxy_helper_.get();
|
|
|
|
}
|
|
|
|
|
2020-09-23 20:22:10 +00:00
|
|
|
network::mojom::SSLConfigPtr ElectronBrowserContext::GetSSLConfig() {
|
|
|
|
return ssl_config_.Clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronBrowserContext::SetSSLConfig(network::mojom::SSLConfigPtr config) {
|
|
|
|
ssl_config_ = std::move(config);
|
|
|
|
if (ssl_config_client_) {
|
|
|
|
ssl_config_client_->OnSSLConfigUpdated(ssl_config_.Clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronBrowserContext::SetSSLConfigClient(
|
|
|
|
mojo::Remote<network::mojom::SSLConfigClient> client) {
|
|
|
|
ssl_config_client_ = std::move(client);
|
|
|
|
}
|
|
|
|
|
2022-08-22 21:15:32 +00:00
|
|
|
void ElectronBrowserContext::SetDisplayMediaRequestHandler(
|
|
|
|
DisplayMediaRequestHandler handler) {
|
|
|
|
display_media_request_handler_ = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronBrowserContext::DisplayMediaDeviceChosen(
|
|
|
|
const content::MediaStreamRequest& request,
|
|
|
|
content::MediaResponseCallback callback,
|
|
|
|
gin::Arguments* args) {
|
|
|
|
blink::mojom::StreamDevicesSetPtr stream_devices_set =
|
|
|
|
blink::mojom::StreamDevicesSet::New();
|
|
|
|
v8::Local<v8::Value> result;
|
|
|
|
if (!args->GetNext(&result) || result->IsNullOrUndefined()) {
|
|
|
|
std::move(callback).Run(
|
|
|
|
blink::mojom::StreamDevicesSet(),
|
|
|
|
blink::mojom::MediaStreamRequestResult::CAPTURE_FAILURE, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gin_helper::Dictionary result_dict;
|
|
|
|
if (!gin::ConvertFromV8(args->isolate(), result, &result_dict)) {
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
.ThrowTypeError(
|
|
|
|
"Display Media Request streams callback must be called with null "
|
|
|
|
"or a valid object");
|
|
|
|
std::move(callback).Run(
|
|
|
|
blink::mojom::StreamDevicesSet(),
|
|
|
|
blink::mojom::MediaStreamRequestResult::CAPTURE_FAILURE, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stream_devices_set->stream_devices.emplace_back(
|
|
|
|
blink::mojom::StreamDevices::New());
|
|
|
|
blink::mojom::StreamDevices& devices = *stream_devices_set->stream_devices[0];
|
|
|
|
bool video_requested =
|
|
|
|
request.video_type != blink::mojom::MediaStreamType::NO_SERVICE;
|
|
|
|
bool audio_requested =
|
|
|
|
request.audio_type != blink::mojom::MediaStreamType::NO_SERVICE;
|
|
|
|
bool has_video = false;
|
|
|
|
if (video_requested && result_dict.Has("video")) {
|
|
|
|
gin_helper::Dictionary video_dict;
|
|
|
|
std::string id;
|
|
|
|
std::string name;
|
|
|
|
content::RenderFrameHost* rfh;
|
|
|
|
if (result_dict.Get("video", &video_dict) && video_dict.Get("id", &id) &&
|
|
|
|
video_dict.Get("name", &name)) {
|
2023-05-24 15:17:08 +00:00
|
|
|
blink::MediaStreamDevice video_device(request.video_type, id, name);
|
|
|
|
video_device.display_media_info = DesktopMediaIDToDisplayMediaInformation(
|
|
|
|
nullptr, url::Origin::Create(request.security_origin),
|
2023-08-23 08:49:24 +00:00
|
|
|
content::DesktopMediaID::Parse(video_device.id));
|
2023-05-24 15:17:08 +00:00
|
|
|
devices.video_device = video_device;
|
2022-08-22 21:15:32 +00:00
|
|
|
} else if (result_dict.Get("video", &rfh)) {
|
2023-05-24 15:17:08 +00:00
|
|
|
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
|
|
|
blink::MediaStreamDevice video_device(
|
2022-08-22 21:15:32 +00:00
|
|
|
request.video_type,
|
|
|
|
content::WebContentsMediaCaptureId(rfh->GetProcess()->GetID(),
|
|
|
|
rfh->GetRoutingID())
|
|
|
|
.ToString(),
|
2023-05-24 15:17:08 +00:00
|
|
|
base::UTF16ToUTF8(web_contents->GetTitle()));
|
|
|
|
video_device.display_media_info = DesktopMediaIDToDisplayMediaInformation(
|
|
|
|
web_contents, url::Origin::Create(request.security_origin),
|
2023-08-23 08:49:24 +00:00
|
|
|
content::DesktopMediaID::Parse(video_device.id));
|
2023-05-24 15:17:08 +00:00
|
|
|
devices.video_device = video_device;
|
2022-08-22 21:15:32 +00:00
|
|
|
} else {
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
.ThrowTypeError(
|
|
|
|
"video must be a WebFrameMain or DesktopCapturerSource");
|
|
|
|
std::move(callback).Run(
|
|
|
|
blink::mojom::StreamDevicesSet(),
|
|
|
|
blink::mojom::MediaStreamRequestResult::CAPTURE_FAILURE, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
has_video = true;
|
|
|
|
}
|
|
|
|
if (audio_requested && result_dict.Has("audio")) {
|
|
|
|
gin_helper::Dictionary audio_dict;
|
|
|
|
std::string id;
|
|
|
|
std::string name;
|
|
|
|
content::RenderFrameHost* rfh;
|
|
|
|
// NB. this is not permitted by the documentation, but is left here as an
|
|
|
|
// "escape hatch" for providing an arbitrary name/id if needed in the
|
|
|
|
// future.
|
|
|
|
if (result_dict.Get("audio", &audio_dict) && audio_dict.Get("id", &id) &&
|
|
|
|
audio_dict.Get("name", &name)) {
|
2023-05-24 15:17:08 +00:00
|
|
|
blink::MediaStreamDevice audio_device(request.audio_type, id, name);
|
|
|
|
audio_device.display_media_info = DesktopMediaIDToDisplayMediaInformation(
|
|
|
|
nullptr, url::Origin::Create(request.security_origin),
|
2024-02-14 17:33:32 +00:00
|
|
|
GetAudioDesktopMediaId(request.requested_audio_device_ids));
|
2023-05-24 15:17:08 +00:00
|
|
|
devices.audio_device = audio_device;
|
2022-08-22 21:15:32 +00:00
|
|
|
} else if (result_dict.Get("audio", &rfh)) {
|
2023-03-01 10:37:19 +00:00
|
|
|
bool enable_local_echo = false;
|
|
|
|
result_dict.Get("enableLocalEcho", &enable_local_echo);
|
|
|
|
bool disable_local_echo = !enable_local_echo;
|
2023-05-24 15:17:08 +00:00
|
|
|
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
|
|
|
blink::MediaStreamDevice audio_device(
|
|
|
|
request.audio_type,
|
|
|
|
content::WebContentsMediaCaptureId(rfh->GetProcess()->GetID(),
|
|
|
|
rfh->GetRoutingID(),
|
|
|
|
disable_local_echo)
|
|
|
|
.ToString(),
|
|
|
|
"Tab audio");
|
|
|
|
audio_device.display_media_info = DesktopMediaIDToDisplayMediaInformation(
|
|
|
|
web_contents, url::Origin::Create(request.security_origin),
|
2024-02-14 17:33:32 +00:00
|
|
|
GetAudioDesktopMediaId(request.requested_audio_device_ids));
|
2023-05-24 15:17:08 +00:00
|
|
|
devices.audio_device = audio_device;
|
2022-08-22 21:15:32 +00:00
|
|
|
} else if (result_dict.Get("audio", &id)) {
|
2023-05-24 15:17:08 +00:00
|
|
|
blink::MediaStreamDevice audio_device(request.audio_type, id,
|
|
|
|
"System audio");
|
|
|
|
audio_device.display_media_info = DesktopMediaIDToDisplayMediaInformation(
|
|
|
|
nullptr, url::Origin::Create(request.security_origin),
|
2024-02-14 17:33:32 +00:00
|
|
|
GetAudioDesktopMediaId(request.requested_audio_device_ids));
|
2023-05-24 15:17:08 +00:00
|
|
|
devices.audio_device = audio_device;
|
2022-08-22 21:15:32 +00:00
|
|
|
} else {
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
.ThrowTypeError(
|
|
|
|
"audio must be a WebFrameMain, \"loopback\" or "
|
|
|
|
"\"loopbackWithMute\"");
|
|
|
|
std::move(callback).Run(
|
|
|
|
blink::mojom::StreamDevicesSet(),
|
|
|
|
blink::mojom::MediaStreamRequestResult::CAPTURE_FAILURE, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((video_requested && !has_video)) {
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
.ThrowTypeError(
|
|
|
|
"Video was requested, but no video stream was provided");
|
|
|
|
std::move(callback).Run(
|
|
|
|
blink::mojom::StreamDevicesSet(),
|
|
|
|
blink::mojom::MediaStreamRequestResult::CAPTURE_FAILURE, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::move(callback).Run(*stream_devices_set,
|
|
|
|
blink::mojom::MediaStreamRequestResult::OK, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ElectronBrowserContext::ChooseDisplayMediaDevice(
|
|
|
|
const content::MediaStreamRequest& request,
|
|
|
|
content::MediaResponseCallback callback) {
|
|
|
|
if (!display_media_request_handler_)
|
|
|
|
return false;
|
|
|
|
DisplayMediaResponseCallbackJs callbackJs =
|
|
|
|
base::BindOnce(&DisplayMediaDeviceChosen, request, std::move(callback));
|
|
|
|
display_media_request_handler_.Run(request, std::move(callbackJs));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-27 20:50:08 +00:00
|
|
|
void ElectronBrowserContext::GrantDevicePermission(
|
|
|
|
const url::Origin& origin,
|
|
|
|
const base::Value& device,
|
|
|
|
blink::PermissionType permission_type) {
|
|
|
|
granted_devices_[permission_type][origin].push_back(
|
|
|
|
std::make_unique<base::Value>(device.Clone()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronBrowserContext::RevokeDevicePermission(
|
|
|
|
const url::Origin& origin,
|
|
|
|
const base::Value& device,
|
2024-04-19 15:55:59 +00:00
|
|
|
const blink::PermissionType permission_type) {
|
2022-06-27 20:50:08 +00:00
|
|
|
const auto& current_devices_it = granted_devices_.find(permission_type);
|
|
|
|
if (current_devices_it == granted_devices_.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto& origin_devices_it = current_devices_it->second.find(origin);
|
|
|
|
if (origin_devices_it == current_devices_it->second.end())
|
|
|
|
return;
|
|
|
|
|
2024-04-19 15:55:59 +00:00
|
|
|
std::erase_if(origin_devices_it->second,
|
|
|
|
[&device, &permission_type](auto const& val) {
|
|
|
|
return DoesDeviceMatch(device, *val, permission_type);
|
|
|
|
});
|
2022-06-27 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ElectronBrowserContext::CheckDevicePermission(
|
|
|
|
const url::Origin& origin,
|
|
|
|
const base::Value& device,
|
|
|
|
blink::PermissionType permission_type) {
|
|
|
|
const auto& current_devices_it = granted_devices_.find(permission_type);
|
|
|
|
if (current_devices_it == granted_devices_.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto& origin_devices_it = current_devices_it->second.find(origin);
|
|
|
|
if (origin_devices_it == current_devices_it->second.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (const auto& device_to_compare : origin_devices_it->second) {
|
2024-04-19 15:55:59 +00:00
|
|
|
if (DoesDeviceMatch(device, *device_to_compare, permission_type))
|
2022-06-27 20:50:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-05 12:54:36 +00:00
|
|
|
// static
|
2020-08-17 20:21:53 +00:00
|
|
|
ElectronBrowserContext* ElectronBrowserContext::From(
|
2018-04-18 01:55:30 +00:00
|
|
|
const std::string& partition,
|
|
|
|
bool in_memory,
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict options) {
|
2018-10-04 18:08:56 +00:00
|
|
|
PartitionKey key(partition, in_memory);
|
2020-08-17 20:21:53 +00:00
|
|
|
ElectronBrowserContext* browser_context = browser_context_map()[key].get();
|
|
|
|
if (browser_context) {
|
|
|
|
return browser_context;
|
|
|
|
}
|
2016-07-12 12:39:54 +00:00
|
|
|
|
2023-03-20 14:34:49 +00:00
|
|
|
auto* new_context = new ElectronBrowserContext(std::cref(partition),
|
|
|
|
in_memory, std::move(options));
|
|
|
|
browser_context_map()[key] =
|
|
|
|
std::unique_ptr<ElectronBrowserContext>(new_context);
|
|
|
|
return new_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
ElectronBrowserContext* ElectronBrowserContext::FromPath(
|
|
|
|
const base::FilePath& path,
|
|
|
|
base::Value::Dict options) {
|
|
|
|
PartitionKey key(path);
|
|
|
|
|
|
|
|
ElectronBrowserContext* browser_context = browser_context_map()[key].get();
|
|
|
|
if (browser_context) {
|
|
|
|
return browser_context;
|
|
|
|
}
|
|
|
|
|
2019-10-30 05:30:59 +00:00
|
|
|
auto* new_context =
|
2023-03-20 14:34:49 +00:00
|
|
|
new ElectronBrowserContext(std::cref(path), false, std::move(options));
|
2020-08-17 20:21:53 +00:00
|
|
|
browser_context_map()[key] =
|
|
|
|
std::unique_ptr<ElectronBrowserContext>(new_context);
|
|
|
|
return new_context;
|
2015-09-05 12:54:36 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|