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-12 01:46:58 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_browser_client.h"
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2015-08-04 09:13:05 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <shlobj.h>
|
|
|
|
#endif
|
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "base/base_switches.h"
|
2014-10-24 10:44:15 +00:00
|
|
|
#include "base/command_line.h"
|
2021-02-19 23:08:49 +00:00
|
|
|
#include "base/debug/crash_logging.h"
|
2018-03-16 02:05:51 +00:00
|
|
|
#include "base/environment.h"
|
2015-06-10 11:34:30 +00:00
|
|
|
#include "base/files/file_util.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "base/json/json_reader.h"
|
2018-10-23 08:45:41 +00:00
|
|
|
#include "base/lazy_instance.h"
|
2018-09-13 00:25:56 +00:00
|
|
|
#include "base/no_destructor.h"
|
2018-10-23 08:45:41 +00:00
|
|
|
#include "base/path_service.h"
|
2015-08-11 07:39:17 +00:00
|
|
|
#include "base/stl_util.h"
|
2015-06-26 02:48:36 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2016-08-24 00:16:54 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2018-07-31 21:38:37 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2019-01-12 01:00:43 +00:00
|
|
|
#include "base/task/post_task.h"
|
2018-11-07 13:23:09 +00:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2019-01-21 18:32:34 +00:00
|
|
|
#include "chrome/common/chrome_version.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "components/net_log/chrome_net_log.h"
|
2019-11-05 23:41:20 +00:00
|
|
|
#include "components/network_hints/common/network_hints.mojom.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "content/public/browser/browser_main_runner.h"
|
2015-04-28 15:45:58 +00:00
|
|
|
#include "content/public/browser/browser_ppapi_host.h"
|
2019-01-12 01:00:43 +00:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2015-06-03 20:57:06 +00:00
|
|
|
#include "content/public/browser/client_certificate_delegate.h"
|
2019-11-11 17:47:01 +00:00
|
|
|
#include "content/public/browser/login_delegate.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
#include "content/public/browser/overlay_window.h"
|
2018-03-06 06:24:54 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2014-01-30 13:57:01 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2014-03-06 03:07:04 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2014-01-31 02:30:16 +00:00
|
|
|
#include "content/public/browser/site_instance.h"
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "content/public/browser/tts_controller.h"
|
|
|
|
#include "content/public/browser/tts_platform.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "content/public/common/content_descriptors.h"
|
2018-01-22 22:49:30 +00:00
|
|
|
#include "content/public/common/content_paths.h"
|
2017-07-07 22:14:25 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2016-09-29 17:20:53 +00:00
|
|
|
#include "content/public/common/url_constants.h"
|
2018-10-01 20:00:53 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "electron/grit/electron_resources.h"
|
2020-12-14 18:57:36 +00:00
|
|
|
#include "electron/shell/common/api/api.mojom.h"
|
2020-05-26 20:06:26 +00:00
|
|
|
#include "mojo/public/cpp/bindings/binder_map.h"
|
2018-07-21 15:05:21 +00:00
|
|
|
#include "net/base/escape.h"
|
2015-06-03 20:57:06 +00:00
|
|
|
#include "net/ssl/ssl_cert_request_info.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "ppapi/buildflags/buildflags.h"
|
2015-04-28 15:45:58 +00:00
|
|
|
#include "ppapi/host/ppapi_host.h"
|
2018-10-13 01:57:04 +00:00
|
|
|
#include "printing/buildflags/buildflags.h"
|
2018-10-02 22:01:24 +00:00
|
|
|
#include "services/device/public/cpp/geolocation/location_provider.h"
|
2019-03-26 01:10:48 +00:00
|
|
|
#include "services/network/public/cpp/features.h"
|
2018-04-11 08:42:14 +00:00
|
|
|
#include "services/network/public/cpp/resource_request_body.h"
|
2021-03-04 17:27:05 +00:00
|
|
|
#include "services/network/public/cpp/self_deleting_url_loader_factory.h"
|
2020-07-30 00:45:02 +00:00
|
|
|
#include "shell/app/electron_crash_reporter_client.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_app.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "shell/browser/api/electron_api_crash_reporter.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_protocol.h"
|
|
|
|
#include "shell/browser/api/electron_api_session.h"
|
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
|
|
|
#include "shell/browser/api/electron_api_web_request.h"
|
2021-01-21 05:45:06 +00:00
|
|
|
#include "shell/browser/badging/badge_manager.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/child_web_contents_tracker.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_autofill_driver_factory.h"
|
|
|
|
#include "shell/browser/electron_browser_context.h"
|
2020-12-14 18:57:36 +00:00
|
|
|
#include "shell/browser/electron_browser_handler_impl.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_browser_main_parts.h"
|
|
|
|
#include "shell/browser/electron_navigation_throttle.h"
|
|
|
|
#include "shell/browser/electron_quota_permission_context.h"
|
|
|
|
#include "shell/browser/electron_speech_recognition_manager_delegate.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/font_defaults.h"
|
2020-06-22 16:35:24 +00:00
|
|
|
#include "shell/browser/javascript_environment.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/media/media_capture_devices_dispatcher.h"
|
|
|
|
#include "shell/browser/native_window.h"
|
|
|
|
#include "shell/browser/net/network_context_service.h"
|
|
|
|
#include "shell/browser/net/network_context_service_factory.h"
|
|
|
|
#include "shell/browser/net/proxying_url_loader_factory.h"
|
2020-02-11 05:56:09 +00:00
|
|
|
#include "shell/browser/net/proxying_websocket.h"
|
2019-08-07 15:04:09 +00:00
|
|
|
#include "shell/browser/net/system_network_context_manager.h"
|
2019-11-05 23:41:20 +00:00
|
|
|
#include "shell/browser/network_hints_handler_impl.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/notifications/notification_presenter.h"
|
|
|
|
#include "shell/browser/notifications/platform_notification_service.h"
|
2020-03-26 17:34:32 +00:00
|
|
|
#include "shell/browser/protocol_registry.h"
|
2020-09-28 16:22:03 +00:00
|
|
|
#include "shell/browser/serial/electron_serial_delegate.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/session_preferences.h"
|
|
|
|
#include "shell/browser/ui/devtools_manager_delegate.h"
|
|
|
|
#include "shell/browser/web_contents_permission_helper.h"
|
|
|
|
#include "shell/browser/web_contents_preferences.h"
|
|
|
|
#include "shell/browser/window_list.h"
|
2019-08-19 20:13:24 +00:00
|
|
|
#include "shell/common/api/api.mojom.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/application_info.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "shell/common/electron_paths.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
|
|
|
#include "shell/common/platform_util.h"
|
2020-04-29 06:16:10 +00:00
|
|
|
#include "third_party/blink/public/common/loader/url_loader_throttle.h"
|
2020-09-21 08:00:36 +00:00
|
|
|
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
|
2020-09-08 15:13:56 +00:00
|
|
|
#include "third_party/blink/public/mojom/badging/badging.mojom.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2019-07-15 08:22:25 +00:00
|
|
|
#include "ui/native_theme/native_theme.h"
|
2015-09-04 17:33:13 +00:00
|
|
|
#include "v8/include/v8.h"
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "sandbox/win/src/sandbox_policy.h"
|
|
|
|
#endif
|
|
|
|
|
2018-04-12 08:48:50 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
#include "net/ssl/client_cert_store_nss.h"
|
|
|
|
#elif defined(OS_WIN)
|
|
|
|
#include "net/ssl/client_cert_store_win.h"
|
2020-08-12 18:33:58 +00:00
|
|
|
#elif defined(OS_MAC)
|
2018-04-12 08:48:50 +00:00
|
|
|
#include "net/ssl/client_cert_store_mac.h"
|
|
|
|
#elif defined(USE_OPENSSL)
|
|
|
|
#include "net/ssl/client_cert_store.h"
|
|
|
|
#endif
|
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
#include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" // nogncheck
|
|
|
|
#include "components/spellcheck/common/spellcheck.mojom.h" // nogncheck
|
|
|
|
#endif
|
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
#if BUILDFLAG(OVERRIDE_LOCATION_PROVIDER)
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/fake_location_provider.h"
|
2018-10-01 20:00:53 +00:00
|
|
|
#endif // BUILDFLAG(OVERRIDE_LOCATION_PROVIDER)
|
2018-08-23 15:51:46 +00:00
|
|
|
|
2020-01-13 22:55:58 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "chrome/common/webui_url_constants.h"
|
|
|
|
#include "content/public/browser/child_process_security_policy.h"
|
|
|
|
#include "content/public/browser/file_url_loader.h"
|
|
|
|
#include "content/public/browser/web_ui_url_loader_factory.h"
|
|
|
|
#include "extensions/browser/api/mime_handler_private/mime_handler_private.h"
|
2020-12-18 23:11:43 +00:00
|
|
|
#include "extensions/browser/api/web_request/web_request_api.h"
|
2020-08-03 23:56:18 +00:00
|
|
|
#include "extensions/browser/browser_context_keyed_api_factory.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "extensions/browser/extension_host.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "extensions/browser/extension_message_filter.h"
|
|
|
|
#include "extensions/browser/extension_navigation_throttle.h"
|
2020-08-03 23:56:18 +00:00
|
|
|
#include "extensions/browser/extension_navigation_ui_data.h"
|
|
|
|
#include "extensions/browser/extension_protocols.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "extensions/browser/extension_registry.h"
|
2020-04-29 06:16:10 +00:00
|
|
|
#include "extensions/browser/extensions_browser_client.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "extensions/browser/guest_view/extensions_guest_view_message_filter.h"
|
|
|
|
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "extensions/browser/info_map.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "extensions/browser/process_manager.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "extensions/browser/process_map.h"
|
2020-08-03 23:56:18 +00:00
|
|
|
#include "extensions/browser/url_loader_factory_manager.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "extensions/common/api/mime_handler.mojom.h"
|
2020-08-03 23:56:18 +00:00
|
|
|
#include "extensions/common/constants.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "extensions/common/extension.h"
|
2020-08-03 23:56:18 +00:00
|
|
|
#include "extensions/common/switches.h"
|
2020-03-05 14:56:21 +00:00
|
|
|
#include "shell/browser/extensions/electron_extension_message_filter.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/browser/extensions/electron_extension_system.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "shell/browser/extensions/electron_extension_web_contents_observer.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS)
|
|
|
|
#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" // nogncheck
|
|
|
|
#include "shell/browser/plugins/plugin_utils.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#endif
|
|
|
|
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2019-07-03 01:22:09 +00:00
|
|
|
#include "content/common/mac_helpers.h"
|
|
|
|
#include "content/public/common/child_process_host.h"
|
|
|
|
#endif
|
|
|
|
|
2020-06-16 21:19:57 +00:00
|
|
|
#if defined(OS_LINUX) && !defined(MAS_BUILD)
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "base/debug/leak_annotations.h"
|
|
|
|
#include "components/crash/content/browser/crash_handler_host_linux.h"
|
2020-06-16 21:19:57 +00:00
|
|
|
#include "components/crash/core/app/breakpad_linux.h" // nogncheck
|
|
|
|
#include "components/crash/core/app/crash_switches.h" // nogncheck
|
|
|
|
#include "components/crash/core/app/crashpad.h" // nogncheck
|
2020-05-07 20:31:26 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-21 08:00:36 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PICTURE_IN_PICTURE) && defined(OS_WIN)
|
|
|
|
#include "chrome/browser/ui/views/overlay/overlay_window_views.h"
|
|
|
|
#include "shell/browser/browser.h"
|
|
|
|
#include "ui/aura/window.h"
|
|
|
|
#include "ui/aura/window_tree_host.h"
|
|
|
|
#include "ui/base/win/shell.h"
|
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
#endif
|
|
|
|
|
2018-03-14 07:55:59 +00:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2014-01-31 02:30:16 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-05-11 06:40:40 +00:00
|
|
|
// Next navigation should not restart renderer process.
|
|
|
|
bool g_suppress_renderer_process_restart = false;
|
|
|
|
|
2021-03-05 23:30:36 +00:00
|
|
|
// c.f. https://chromium-review.googlesource.com/c/chromium/src/+/2680274
|
2021-03-06 00:54:18 +00:00
|
|
|
content::SiteInfo GetSiteForURL(content::BrowserContext* browser_context,
|
|
|
|
const GURL& url) {
|
|
|
|
return content::SiteInfo::Create(
|
|
|
|
content::IsolationContext(browser_context), content::UrlInfo(url, false),
|
|
|
|
content::CoopCoepCrossOriginIsolatedInfo::CreateNonIsolated());
|
2021-03-05 23:30:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 07:22:52 +00:00
|
|
|
bool IsSameWebSite(content::BrowserContext* browser_context,
|
2019-01-22 15:10:36 +00:00
|
|
|
content::SiteInstance* site_instance,
|
2018-04-06 07:22:52 +00:00
|
|
|
const GURL& dest_url) {
|
2019-01-22 15:10:36 +00:00
|
|
|
return site_instance->IsSameSiteWithURL(dest_url) ||
|
|
|
|
// `IsSameSiteWithURL` doesn't seem to work for some URIs such as
|
|
|
|
// `file:`, handle these scenarios by comparing only the site as
|
|
|
|
// defined by `GetSiteForURL`.
|
2021-03-05 23:30:36 +00:00
|
|
|
(GetSiteForURL(browser_context, dest_url).site_url() ==
|
2019-01-22 15:10:36 +00:00
|
|
|
site_instance->GetSiteURL());
|
2016-05-23 03:57:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient* g_browser_client = nullptr;
|
2018-10-23 08:45:41 +00:00
|
|
|
|
|
|
|
base::LazyInstance<std::string>::DestructorAtExit
|
|
|
|
g_io_thread_application_locale = LAZY_INSTANCE_INITIALIZER;
|
|
|
|
|
|
|
|
base::NoDestructor<std::string> g_application_locale;
|
|
|
|
|
|
|
|
void SetApplicationLocaleOnIOThread(const std::string& locale) {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
|
g_io_thread_application_locale.Get() = locale;
|
|
|
|
}
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
void BindNetworkHintsHandler(
|
|
|
|
content::RenderFrameHost* frame_host,
|
|
|
|
mojo::PendingReceiver<network_hints::mojom::NetworkHintsHandler> receiver) {
|
|
|
|
NetworkHintsHandlerImpl::Create(frame_host, std::move(receiver));
|
|
|
|
}
|
|
|
|
|
2020-02-06 21:42:34 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
|
|
|
|
// below. Extension, and isolated apps require different privileges to be
|
|
|
|
// granted to their RenderProcessHosts. This classification allows us to make
|
|
|
|
// sure URLs are served by hosts with the right set of privileges.
|
2020-10-21 00:47:04 +00:00
|
|
|
enum class RenderProcessHostPrivilege {
|
2020-10-27 17:51:45 +00:00
|
|
|
kNormal,
|
|
|
|
kHosted,
|
|
|
|
kIsolated,
|
|
|
|
kExtension,
|
2020-02-06 21:42:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
|
|
|
|
const GURL& url,
|
|
|
|
extensions::ExtensionRegistry* registry) {
|
|
|
|
// Default to a normal renderer cause it is lower privileged. This should only
|
|
|
|
// occur if the URL on a site instance is either malformed, or uninitialized.
|
|
|
|
// If it is malformed, then there is no need for better privileges anyways.
|
|
|
|
// If it is uninitialized, but eventually settles on being an a scheme other
|
|
|
|
// than normal webrenderer, the navigation logic will correct us out of band
|
|
|
|
// anyways.
|
|
|
|
if (!url.is_valid())
|
2020-10-27 17:51:45 +00:00
|
|
|
return RenderProcessHostPrivilege::kNormal;
|
2020-02-06 21:42:34 +00:00
|
|
|
|
|
|
|
if (!url.SchemeIs(extensions::kExtensionScheme))
|
2020-10-27 17:51:45 +00:00
|
|
|
return RenderProcessHostPrivilege::kNormal;
|
2020-02-06 21:42:34 +00:00
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
return RenderProcessHostPrivilege::kExtension;
|
2020-02-06 21:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderProcessHostPrivilege GetProcessPrivilege(
|
|
|
|
content::RenderProcessHost* process_host,
|
|
|
|
extensions::ProcessMap* process_map,
|
|
|
|
extensions::ExtensionRegistry* registry) {
|
|
|
|
std::set<std::string> extension_ids =
|
|
|
|
process_map->GetExtensionsInProcess(process_host->GetID());
|
|
|
|
if (extension_ids.empty())
|
2020-10-27 17:51:45 +00:00
|
|
|
return RenderProcessHostPrivilege::kNormal;
|
2020-02-06 21:42:34 +00:00
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
return RenderProcessHostPrivilege::kExtension;
|
2020-02-06 21:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const extensions::Extension* GetEnabledExtensionFromEffectiveURL(
|
|
|
|
content::BrowserContext* context,
|
|
|
|
const GURL& effective_url) {
|
|
|
|
if (!effective_url.SchemeIs(extensions::kExtensionScheme))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
extensions::ExtensionRegistry* registry =
|
|
|
|
extensions::ExtensionRegistry::Get(context);
|
|
|
|
if (!registry)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return registry->enabled_extensions().GetByID(effective_url.host());
|
|
|
|
}
|
|
|
|
#endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
|
|
|
|
const std::string& process_type) {
|
|
|
|
base::FilePath dumps_path;
|
|
|
|
base::PathService::Get(electron::DIR_CRASH_DUMPS, &dumps_path);
|
|
|
|
{
|
|
|
|
ANNOTATE_SCOPED_MEMORY_LEAK;
|
2020-07-30 00:45:02 +00:00
|
|
|
bool upload = ElectronCrashReporterClient::Get()->GetCollectStatsConsent();
|
2020-05-07 20:31:26 +00:00
|
|
|
breakpad::CrashHandlerHostLinux* crash_handler =
|
2020-07-30 00:45:02 +00:00
|
|
|
new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload);
|
2020-05-07 20:31:26 +00:00
|
|
|
crash_handler->StartUploaderThread();
|
|
|
|
return crash_handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetCrashSignalFD(const base::CommandLine& command_line) {
|
|
|
|
// Extensions have the same process type as renderers.
|
|
|
|
if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost("extension");
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string process_type =
|
|
|
|
command_line.GetSwitchValueASCII(::switches::kProcessType);
|
|
|
|
|
|
|
|
if (process_type == ::switches::kRendererProcess) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost(process_type);
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process_type == ::switches::kPpapiPluginProcess) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost(process_type);
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process_type == ::switches::kGpuProcess) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost(process_type);
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process_type == ::switches::kUtilityProcess) {
|
|
|
|
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
|
|
|
|
if (!crash_handler)
|
|
|
|
crash_handler = CreateCrashHandlerHost(process_type);
|
|
|
|
return crash_handler->GetDeathSignalSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif // defined(OS_LINUX)
|
|
|
|
|
2014-01-31 02:30:16 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-05-11 06:40:40 +00:00
|
|
|
// static
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::SuppressRendererProcessRestartForOnce() {
|
2015-05-11 06:40:40 +00:00
|
|
|
g_suppress_renderer_process_restart = true;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient* ElectronBrowserClient::Get() {
|
2018-10-23 08:45:41 +00:00
|
|
|
return g_browser_client;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::SetApplicationLocale(const std::string& locale) {
|
2018-10-23 08:45:41 +00:00
|
|
|
if (!BrowserThread::IsThreadInitialized(BrowserThread::IO) ||
|
2019-09-18 19:58:00 +00:00
|
|
|
!base::PostTask(
|
2019-01-12 01:00:43 +00:00
|
|
|
FROM_HERE, {BrowserThread::IO},
|
2018-10-23 08:45:41 +00:00
|
|
|
base::BindOnce(&SetApplicationLocaleOnIOThread, locale))) {
|
|
|
|
g_io_thread_application_locale.Get() = locale;
|
|
|
|
}
|
|
|
|
*g_application_locale = locale;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::ElectronBrowserClient() {
|
2018-10-23 08:45:41 +00:00
|
|
|
DCHECK(!g_browser_client);
|
|
|
|
g_browser_client = this;
|
|
|
|
}
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::~ElectronBrowserClient() {
|
2018-10-23 08:45:41 +00:00
|
|
|
DCHECK(g_browser_client);
|
|
|
|
g_browser_client = nullptr;
|
|
|
|
}
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::WebContents* ElectronBrowserClient::GetWebContentsFromProcessID(
|
2016-05-27 00:20:46 +00:00
|
|
|
int process_id) {
|
2017-07-10 22:48:12 +00:00
|
|
|
// If the process is a pending process, we should use the web contents
|
2018-12-05 08:03:39 +00:00
|
|
|
// for the frame host passed into RegisterPendingProcess.
|
2019-08-28 14:39:21 +00:00
|
|
|
const auto iter = pending_processes_.find(process_id);
|
|
|
|
if (iter != std::end(pending_processes_))
|
|
|
|
return iter->second;
|
2016-05-27 00:20:46 +00:00
|
|
|
|
|
|
|
// Certain render process will be created with no associated render view,
|
|
|
|
// for example: ServiceWorker.
|
|
|
|
return WebContentsPreferences::GetWebContentsFromProcessID(process_id);
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::ShouldForceNewSiteInstance(
|
2018-12-05 08:03:39 +00:00
|
|
|
content::RenderFrameHost* current_rfh,
|
|
|
|
content::RenderFrameHost* speculative_rfh,
|
2016-08-15 10:59:08 +00:00
|
|
|
content::BrowserContext* browser_context,
|
2018-12-05 08:03:39 +00:00
|
|
|
const GURL& url,
|
|
|
|
bool has_response_started) const {
|
2016-08-15 10:59:08 +00:00
|
|
|
if (url.SchemeIs(url::kJavaScriptScheme))
|
2020-10-13 17:25:21 +00:00
|
|
|
// "javascript:" scheme should always use same SiteInstance
|
2016-08-15 10:59:08 +00:00
|
|
|
return false;
|
2020-01-13 22:55:58 +00:00
|
|
|
if (url.SchemeIs(extensions::kExtensionScheme))
|
|
|
|
return false;
|
2016-08-15 10:59:08 +00:00
|
|
|
|
2018-12-05 08:03:39 +00:00
|
|
|
content::SiteInstance* current_instance = current_rfh->GetSiteInstance();
|
|
|
|
content::SiteInstance* speculative_instance =
|
|
|
|
speculative_rfh ? speculative_rfh->GetSiteInstance() : nullptr;
|
2017-03-19 08:47:26 +00:00
|
|
|
int process_id = current_instance->GetProcess()->GetID();
|
2018-12-05 08:03:39 +00:00
|
|
|
if (NavigationWasRedirectedCrossSite(browser_context, current_instance,
|
|
|
|
speculative_instance, url,
|
|
|
|
has_response_started)) {
|
|
|
|
// Navigation was redirected. We can't force the current, speculative or a
|
|
|
|
// new unrelated site instance to be used. Delegate to the content layer.
|
|
|
|
return false;
|
|
|
|
} else if (IsRendererSandboxed(process_id)) {
|
|
|
|
// Renderer is sandboxed, delegate the decision to the content layer for all
|
|
|
|
// origins.
|
|
|
|
return false;
|
|
|
|
} else if (!RendererUsesNativeWindowOpen(process_id)) {
|
|
|
|
// non-sandboxed renderers without native window.open should always create
|
|
|
|
// a new SiteInstance
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
auto* web_contents = content::WebContents::FromRenderFrameHost(current_rfh);
|
2018-10-22 18:02:25 +00:00
|
|
|
if (!ChildWebContentsTracker::FromWebContents(web_contents)) {
|
2017-04-12 03:25:56 +00:00
|
|
|
// Root WebContents should always create new process to make sure
|
|
|
|
// native addons are loaded correctly after reload / navigation.
|
|
|
|
// (Non-root WebContents opened by window.open() should try to
|
|
|
|
// reuse process to allow synchronous cross-window scripting.)
|
2017-04-05 08:51:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-08-15 10:59:08 +00:00
|
|
|
|
|
|
|
// Create new a SiteInstance if navigating to a different site.
|
2019-01-22 15:10:36 +00:00
|
|
|
return !IsSameWebSite(browser_context, current_instance, url);
|
2016-08-15 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::NavigationWasRedirectedCrossSite(
|
2018-12-05 08:03:39 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
content::SiteInstance* current_instance,
|
|
|
|
content::SiteInstance* speculative_instance,
|
|
|
|
const GURL& dest_url,
|
|
|
|
bool has_response_started) const {
|
|
|
|
bool navigation_was_redirected = false;
|
|
|
|
if (has_response_started) {
|
2019-01-22 15:10:36 +00:00
|
|
|
navigation_was_redirected =
|
|
|
|
!IsSameWebSite(browser_context, current_instance, dest_url);
|
2018-12-05 08:03:39 +00:00
|
|
|
} else {
|
|
|
|
navigation_was_redirected =
|
|
|
|
speculative_instance &&
|
2019-01-22 15:10:36 +00:00
|
|
|
!IsSameWebSite(browser_context, speculative_instance, dest_url);
|
2018-12-05 08:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return navigation_was_redirected;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::AddProcessPreferences(
|
2018-04-18 01:55:30 +00:00
|
|
|
int process_id,
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::ProcessPreferences prefs) {
|
2017-03-19 08:25:45 +00:00
|
|
|
process_preferences_[process_id] = prefs;
|
2016-08-15 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RemoveProcessPreferences(int process_id) {
|
2017-03-19 08:25:45 +00:00
|
|
|
process_preferences_.erase(process_id);
|
2016-08-15 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::IsProcessObserved(int process_id) const {
|
2018-03-09 07:13:51 +00:00
|
|
|
return process_preferences_.find(process_id) != process_preferences_.end();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::IsRendererSandboxed(int process_id) const {
|
2017-03-19 08:25:45 +00:00
|
|
|
auto it = process_preferences_.find(process_id);
|
|
|
|
return it != process_preferences_.end() && it->second.sandbox;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::RendererUsesNativeWindowOpen(int process_id) const {
|
2017-03-19 08:25:45 +00:00
|
|
|
auto it = process_preferences_.find(process_id);
|
|
|
|
return it != process_preferences_.end() && it->second.native_window_open;
|
2016-08-15 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::RendererDisablesPopups(int process_id) const {
|
2017-05-23 22:59:17 +00:00
|
|
|
auto it = process_preferences_.find(process_id);
|
|
|
|
return it != process_preferences_.end() && it->second.disable_popups;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserClient::GetAffinityPreference(
|
2018-12-05 08:03:39 +00:00
|
|
|
content::RenderFrameHost* rfh) const {
|
|
|
|
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents);
|
|
|
|
std::string affinity;
|
|
|
|
if (web_preferences &&
|
|
|
|
web_preferences->GetPreference("affinity", &affinity) &&
|
|
|
|
!affinity.empty()) {
|
|
|
|
affinity = base::ToLowerASCII(affinity);
|
|
|
|
}
|
|
|
|
|
|
|
|
return affinity;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::SiteInstance* ElectronBrowserClient::GetSiteInstanceFromAffinity(
|
2018-12-05 08:03:39 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& url,
|
|
|
|
content::RenderFrameHost* rfh) const {
|
|
|
|
std::string affinity = GetAffinityPreference(rfh);
|
|
|
|
if (!affinity.empty()) {
|
|
|
|
auto iter = site_per_affinities_.find(affinity);
|
2021-03-05 23:30:36 +00:00
|
|
|
GURL dest_site = GetSiteForURL(browser_context, url).site_url();
|
2018-12-05 08:03:39 +00:00
|
|
|
if (iter != site_per_affinities_.end() &&
|
2019-01-22 15:10:36 +00:00
|
|
|
IsSameWebSite(browser_context, iter->second, dest_site)) {
|
2018-12-05 08:03:39 +00:00
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::ConsiderSiteInstanceForAffinity(
|
2018-12-05 08:03:39 +00:00
|
|
|
content::RenderFrameHost* rfh,
|
|
|
|
content::SiteInstance* site_instance) {
|
|
|
|
std::string affinity = GetAffinityPreference(rfh);
|
|
|
|
if (!affinity.empty()) {
|
|
|
|
site_per_affinities_[affinity] = site_instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::IsRendererSubFrame(int process_id) const {
|
2019-07-03 01:22:09 +00:00
|
|
|
return base::Contains(renderer_is_subframe_, process_id);
|
2019-06-20 10:10:56 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RenderProcessWillLaunch(
|
2019-08-15 20:50:58 +00:00
|
|
|
content::RenderProcessHost* host) {
|
2018-03-09 07:13:51 +00:00
|
|
|
// When a render process is crashed, it might be reused.
|
2015-06-26 02:48:36 +00:00
|
|
|
int process_id = host->GetID();
|
2018-03-09 07:13:51 +00:00
|
|
|
if (IsProcessObserved(process_id))
|
|
|
|
return;
|
|
|
|
|
2020-01-13 22:55:58 +00:00
|
|
|
auto* browser_context = host->GetBrowserContext();
|
2020-04-29 06:16:10 +00:00
|
|
|
ALLOW_UNUSED_LOCAL(browser_context);
|
2020-01-13 22:55:58 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
host->AddFilter(
|
|
|
|
new extensions::ExtensionMessageFilter(process_id, browser_context));
|
2020-02-13 00:39:12 +00:00
|
|
|
host->AddFilter(new extensions::ExtensionsGuestViewMessageFilter(
|
|
|
|
process_id, browser_context));
|
2020-03-05 14:56:21 +00:00
|
|
|
host->AddFilter(
|
|
|
|
new ElectronExtensionMessageFilter(process_id, browser_context));
|
2018-10-13 01:57:04 +00:00
|
|
|
#endif
|
2018-10-11 13:52:12 +00:00
|
|
|
|
2018-03-08 07:36:21 +00:00
|
|
|
ProcessPreferences prefs;
|
2018-04-18 01:55:30 +00:00
|
|
|
auto* web_preferences =
|
|
|
|
WebContentsPreferences::From(GetWebContentsFromProcessID(process_id));
|
2018-03-08 07:36:21 +00:00
|
|
|
if (web_preferences) {
|
2018-05-29 08:09:51 +00:00
|
|
|
prefs.sandbox = web_preferences->IsEnabled(options::kSandbox);
|
|
|
|
prefs.native_window_open =
|
|
|
|
web_preferences->IsEnabled(options::kNativeWindowOpen);
|
2018-03-08 07:36:21 +00:00
|
|
|
prefs.disable_popups = web_preferences->IsEnabled("disablePopups");
|
2018-11-21 20:10:05 +00:00
|
|
|
prefs.web_security = web_preferences->IsEnabled(options::kWebSecurity,
|
|
|
|
true /* default value */);
|
2019-12-11 00:22:35 +00:00
|
|
|
prefs.browser_context = host->GetBrowserContext();
|
2018-03-08 07:36:21 +00:00
|
|
|
}
|
2019-08-26 16:47:32 +00:00
|
|
|
|
2018-03-08 07:36:21 +00:00
|
|
|
AddProcessPreferences(host->GetID(), prefs);
|
2017-03-19 08:25:45 +00:00
|
|
|
// ensure the ProcessPreferences is removed later
|
|
|
|
host->AddObserver(this);
|
2014-08-21 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 03:55:14 +00:00
|
|
|
content::SpeechRecognitionManagerDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::CreateSpeechRecognitionManagerDelegate() {
|
|
|
|
return new ElectronSpeechRecognitionManagerDelegate;
|
2014-10-08 03:55:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
content::TtsPlatform* ElectronBrowserClient::GetTtsPlatform() {
|
2019-01-10 00:44:44 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::OverrideWebkitPrefs(
|
2021-02-09 20:16:21 +00:00
|
|
|
content::WebContents* web_contents,
|
2020-09-21 08:00:36 +00:00
|
|
|
blink::web_pref::WebPreferences* prefs) {
|
2013-04-12 12:48:02 +00:00
|
|
|
prefs->javascript_enabled = true;
|
2014-03-04 13:23:18 +00:00
|
|
|
prefs->web_security_enabled = true;
|
2014-10-26 06:05:54 +00:00
|
|
|
prefs->plugins_enabled = true;
|
2013-04-12 12:48:02 +00:00
|
|
|
prefs->dom_paste_enabled = true;
|
|
|
|
prefs->allow_scripts_to_close_windows = true;
|
|
|
|
prefs->javascript_can_access_clipboard = true;
|
|
|
|
prefs->local_storage_enabled = true;
|
|
|
|
prefs->databases_enabled = true;
|
|
|
|
prefs->application_cache_enabled = true;
|
|
|
|
prefs->allow_universal_access_from_file_urls = true;
|
|
|
|
prefs->allow_file_access_from_file_urls = true;
|
2017-12-18 01:47:10 +00:00
|
|
|
prefs->webgl1_enabled = true;
|
|
|
|
prefs->webgl2_enabled = true;
|
2015-01-07 04:53:25 +00:00
|
|
|
prefs->allow_running_insecure_content = false;
|
2018-04-26 15:27:35 +00:00
|
|
|
prefs->default_minimum_page_scale_factor = 1.f;
|
|
|
|
prefs->default_maximum_page_scale_factor = 1.f;
|
2018-04-26 15:23:27 +00:00
|
|
|
prefs->navigate_on_drag_drop = false;
|
2019-08-22 10:17:50 +00:00
|
|
|
#if !BUILDFLAG(ENABLE_PICTURE_IN_PICTURE)
|
|
|
|
prefs->picture_in_picture_enabled = false;
|
|
|
|
#endif
|
2014-03-06 03:07:04 +00:00
|
|
|
|
2020-03-30 22:39:50 +00:00
|
|
|
ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
|
2020-10-16 01:30:41 +00:00
|
|
|
prefs->preferred_color_scheme =
|
|
|
|
native_theme->ShouldUseDarkColors()
|
|
|
|
? blink::mojom::PreferredColorScheme::kDark
|
|
|
|
: blink::mojom::PreferredColorScheme::kLight;
|
2020-03-30 22:39:50 +00:00
|
|
|
|
2020-11-10 17:06:03 +00:00
|
|
|
auto preloads =
|
|
|
|
SessionPreferences::GetValidPreloads(web_contents->GetBrowserContext());
|
|
|
|
if (!preloads.empty())
|
|
|
|
prefs->preloads = preloads;
|
|
|
|
if (CanUseCustomSiteInstance())
|
|
|
|
prefs->disable_electron_site_instance_overrides = true;
|
|
|
|
|
2018-11-08 14:51:51 +00:00
|
|
|
SetFontDefaults(prefs);
|
|
|
|
|
2014-12-18 02:13:39 +00:00
|
|
|
// Custom preferences of guest page.
|
2018-03-08 08:01:54 +00:00
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents);
|
2020-11-10 17:06:03 +00:00
|
|
|
if (web_preferences) {
|
2018-03-08 08:01:54 +00:00
|
|
|
web_preferences->OverrideWebkitPrefs(prefs);
|
2020-11-10 17:06:03 +00:00
|
|
|
}
|
2013-04-12 12:48:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::SetCanUseCustomSiteInstance(bool should_disable) {
|
2019-05-31 22:47:18 +00:00
|
|
|
disable_process_restart_tricks_ = should_disable;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::CanUseCustomSiteInstance() {
|
2019-05-31 22:47:18 +00:00
|
|
|
return disable_process_restart_tricks_;
|
|
|
|
}
|
|
|
|
|
2018-12-05 08:03:39 +00:00
|
|
|
content::ContentBrowserClient::SiteInstanceForNavigationType
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::ShouldOverrideSiteInstanceForNavigation(
|
2018-12-05 08:03:39 +00:00
|
|
|
content::RenderFrameHost* current_rfh,
|
|
|
|
content::RenderFrameHost* speculative_rfh,
|
2015-04-26 04:28:27 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& url,
|
2019-08-08 18:48:33 +00:00
|
|
|
bool has_navigation_started,
|
2018-12-05 08:03:39 +00:00
|
|
|
bool has_response_started,
|
|
|
|
content::SiteInstance** affinity_site_instance) const {
|
2017-04-04 04:48:17 +00:00
|
|
|
if (g_suppress_renderer_process_restart) {
|
|
|
|
g_suppress_renderer_process_restart = false;
|
2018-12-05 08:03:39 +00:00
|
|
|
return SiteInstanceForNavigationType::ASK_CHROMIUM;
|
2018-11-12 21:01:43 +00:00
|
|
|
}
|
2017-12-13 10:57:41 +00:00
|
|
|
|
2018-11-20 20:28:26 +00:00
|
|
|
// Do we have an affinity site to manage ?
|
2018-12-05 08:03:39 +00:00
|
|
|
content::SiteInstance* site_instance_from_affinity =
|
|
|
|
GetSiteInstanceFromAffinity(browser_context, url, current_rfh);
|
|
|
|
if (site_instance_from_affinity) {
|
|
|
|
*affinity_site_instance = site_instance_from_affinity;
|
|
|
|
return SiteInstanceForNavigationType::FORCE_AFFINITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ShouldForceNewSiteInstance(current_rfh, speculative_rfh, browser_context,
|
|
|
|
url, has_response_started)) {
|
|
|
|
return SiteInstanceForNavigationType::ASK_CHROMIUM;
|
|
|
|
}
|
2018-11-20 20:28:26 +00:00
|
|
|
|
2018-12-05 08:03:39 +00:00
|
|
|
// ShouldOverrideSiteInstanceForNavigation will be called more than once
|
|
|
|
// during a navigation (currently twice, on request and when it's about
|
|
|
|
// to commit in the renderer), look at
|
|
|
|
// RenderFrameHostManager::GetFrameHostForNavigation.
|
|
|
|
// In the default mode we should reuse the same site instance until the
|
|
|
|
// request commits otherwise it will get destroyed. Currently there is no
|
|
|
|
// unique lifetime tracker for a navigation request during site instance
|
|
|
|
// creation. We check for the state of the request, which should be one of
|
|
|
|
// (WAITING_FOR_RENDERER_RESPONSE, STARTED, RESPONSE_STARTED, FAILED) along
|
|
|
|
// with the availability of a speculative render frame host.
|
|
|
|
if (has_response_started) {
|
|
|
|
return SiteInstanceForNavigationType::FORCE_CURRENT;
|
2018-11-20 20:28:26 +00:00
|
|
|
}
|
2018-12-05 08:03:39 +00:00
|
|
|
|
2019-08-08 18:48:33 +00:00
|
|
|
if (!has_navigation_started) {
|
|
|
|
// If the navigation didn't start yet, ignore any candidate site instance.
|
|
|
|
// If such instance exists, it belongs to a previous navigation still
|
|
|
|
// taking place. Fixes https://github.com/electron/electron/issues/17576.
|
|
|
|
return SiteInstanceForNavigationType::FORCE_NEW;
|
|
|
|
}
|
|
|
|
|
2018-12-05 08:03:39 +00:00
|
|
|
return SiteInstanceForNavigationType::FORCE_CANDIDATE_OR_NEW;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RegisterPendingSiteInstance(
|
2018-12-05 08:03:39 +00:00
|
|
|
content::RenderFrameHost* rfh,
|
|
|
|
content::SiteInstance* pending_site_instance) {
|
|
|
|
// Do we have an affinity site to manage?
|
|
|
|
ConsiderSiteInstanceForAffinity(rfh, pending_site_instance);
|
|
|
|
|
|
|
|
// Remember the original web contents for the pending renderer process.
|
|
|
|
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
|
|
|
auto* pending_process = pending_site_instance->GetProcess();
|
|
|
|
pending_processes_[pending_process->GetID()] = web_contents;
|
2019-06-20 10:10:56 +00:00
|
|
|
|
|
|
|
if (rfh->GetParent())
|
|
|
|
renderer_is_subframe_.insert(pending_process->GetID());
|
|
|
|
else
|
|
|
|
renderer_is_subframe_.erase(pending_process->GetID());
|
2017-12-13 10:57:41 +00:00
|
|
|
}
|
2016-05-23 03:57:46 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::AppendExtraCommandLineSwitches(
|
2014-06-28 14:33:00 +00:00
|
|
|
base::CommandLine* command_line,
|
2015-06-03 05:45:06 +00:00
|
|
|
int process_id) {
|
2018-01-22 22:49:30 +00:00
|
|
|
// Make sure we're about to launch a known executable
|
2018-01-23 15:25:01 +00:00
|
|
|
{
|
2019-07-24 22:58:51 +00:00
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
2018-01-23 15:25:01 +00:00
|
|
|
base::FilePath child_path;
|
2019-07-24 22:58:51 +00:00
|
|
|
base::FilePath program =
|
|
|
|
base::MakeAbsoluteFilePath(command_line->GetProgram());
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2019-07-24 22:58:51 +00:00
|
|
|
auto renderer_child_path = content::ChildProcessHost::GetChildPath(
|
|
|
|
content::ChildProcessHost::CHILD_RENDERER);
|
|
|
|
auto gpu_child_path = content::ChildProcessHost::GetChildPath(
|
|
|
|
content::ChildProcessHost::CHILD_GPU);
|
2020-09-21 02:08:15 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS)
|
2019-07-24 22:58:51 +00:00
|
|
|
auto plugin_child_path = content::ChildProcessHost::GetChildPath(
|
|
|
|
content::ChildProcessHost::CHILD_PLUGIN);
|
2020-09-21 02:08:15 +00:00
|
|
|
#endif
|
|
|
|
if (program != renderer_child_path && program != gpu_child_path
|
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS)
|
|
|
|
&& program != plugin_child_path
|
|
|
|
#endif
|
|
|
|
) {
|
2019-07-24 22:58:51 +00:00
|
|
|
child_path = content::ChildProcessHost::GetChildPath(
|
|
|
|
content::ChildProcessHost::CHILD_NORMAL);
|
|
|
|
CHECK_EQ(program, child_path)
|
|
|
|
<< "Aborted from launching unexpected helper executable";
|
2019-07-03 01:22:09 +00:00
|
|
|
}
|
|
|
|
#else
|
2021-02-19 23:08:49 +00:00
|
|
|
if (!base::PathService::Get(content::CHILD_PROCESS_EXE, &child_path)) {
|
|
|
|
CHECK(false) << "Unable to get child process binary name.";
|
|
|
|
}
|
|
|
|
SCOPED_CRASH_KEY_STRING256("ChildProcess", "child_process_exe",
|
|
|
|
child_path.AsUTF8Unsafe());
|
|
|
|
SCOPED_CRASH_KEY_STRING256("ChildProcess", "program",
|
|
|
|
program.AsUTF8Unsafe());
|
2019-07-24 22:58:51 +00:00
|
|
|
CHECK_EQ(program, child_path);
|
2019-07-03 01:22:09 +00:00
|
|
|
#endif
|
2018-01-23 15:25:01 +00:00
|
|
|
}
|
2018-01-22 22:49:30 +00:00
|
|
|
|
2017-07-07 22:14:25 +00:00
|
|
|
std::string process_type =
|
|
|
|
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
2015-04-26 09:26:25 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
bool enable_crash_reporter = false;
|
|
|
|
enable_crash_reporter = breakpad::IsCrashReporterEnabled();
|
|
|
|
if (enable_crash_reporter) {
|
2020-08-07 22:30:49 +00:00
|
|
|
std::string switch_value =
|
|
|
|
api::crash_reporter::GetClientId() + ",no_channel";
|
|
|
|
command_line->AppendSwitchASCII(::switches::kEnableCrashReporter,
|
|
|
|
switch_value);
|
2020-05-07 20:31:26 +00:00
|
|
|
for (const auto& pair : api::crash_reporter::GetGlobalCrashKeys()) {
|
|
|
|
if (!switch_value.empty())
|
|
|
|
switch_value += ",";
|
|
|
|
switch_value += pair.first;
|
|
|
|
switch_value += "=";
|
|
|
|
switch_value += pair.second;
|
|
|
|
}
|
|
|
|
command_line->AppendSwitchASCII(switches::kGlobalCrashKeys, switch_value);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
if (process_type == ::switches::kUtilityProcess ||
|
|
|
|
process_type == ::switches::kRendererProcess) {
|
|
|
|
// Copy following switches to child process.
|
|
|
|
static const char* const kCommonSwitchNames[] = {
|
|
|
|
switches::kStandardSchemes, switches::kEnableSandbox,
|
|
|
|
switches::kSecureSchemes, switches::kBypassCSPSchemes,
|
|
|
|
switches::kCORSSchemes, switches::kFetchSchemes,
|
2020-06-08 16:49:36 +00:00
|
|
|
switches::kServiceWorkerSchemes, switches::kEnableApiFilteringLogging,
|
|
|
|
switches::kStreamingSchemes};
|
2019-10-28 22:12:35 +00:00
|
|
|
command_line->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
|
|
|
|
kCommonSwitchNames,
|
|
|
|
base::size(kCommonSwitchNames));
|
|
|
|
}
|
2016-06-08 06:46:50 +00:00
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
if (process_type == ::switches::kRendererProcess) {
|
2015-08-04 09:13:05 +00:00
|
|
|
#if defined(OS_WIN)
|
2019-10-28 22:12:35 +00:00
|
|
|
// Append --app-user-model-id.
|
|
|
|
PWSTR current_app_id;
|
|
|
|
if (SUCCEEDED(GetCurrentProcessExplicitAppUserModelID(¤t_app_id))) {
|
|
|
|
command_line->AppendSwitchNative(switches::kAppUserModelId,
|
|
|
|
current_app_id);
|
|
|
|
CoTaskMemFree(current_app_id);
|
|
|
|
}
|
2015-08-04 09:13:05 +00:00
|
|
|
#endif
|
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
if (delegate_) {
|
|
|
|
auto app_path = static_cast<api::App*>(delegate_)->GetAppPath();
|
|
|
|
command_line->AppendSwitchPath(switches::kAppPath, app_path);
|
|
|
|
}
|
2017-04-04 00:36:01 +00:00
|
|
|
|
2020-06-01 23:08:34 +00:00
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
if (env->HasVar("ELECTRON_PROFILE_INIT_SCRIPTS")) {
|
|
|
|
command_line->AppendSwitch("profile-electron-init");
|
|
|
|
}
|
|
|
|
|
2020-08-19 00:41:47 +00:00
|
|
|
// Extension background pages don't have WebContentsPreferences, but they
|
|
|
|
// support WebSQL by default.
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
content::RenderProcessHost* process =
|
|
|
|
content::RenderProcessHost::FromID(process_id);
|
|
|
|
if (extensions::ProcessMap::Get(process->GetBrowserContext())
|
|
|
|
->Contains(process_id))
|
|
|
|
command_line->AppendSwitch(switches::kEnableWebSQL);
|
|
|
|
#endif
|
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
content::WebContents* web_contents =
|
|
|
|
GetWebContentsFromProcessID(process_id);
|
|
|
|
if (web_contents) {
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents);
|
|
|
|
if (web_preferences)
|
|
|
|
web_preferences->AppendCommandLineSwitches(
|
|
|
|
command_line, IsRendererSubFrame(process_id));
|
2019-05-31 22:47:18 +00:00
|
|
|
}
|
2017-12-05 06:59:15 +00:00
|
|
|
}
|
2014-01-30 13:57:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::DidCreatePpapiPlugin(
|
2020-10-16 01:30:41 +00:00
|
|
|
content::BrowserPpapiHost* host) {}
|
2015-04-28 15:45:58 +00:00
|
|
|
|
2018-10-31 14:49:44 +00:00
|
|
|
// attempt to get api key from env
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserClient::GetGeolocationApiKey() {
|
2018-03-14 07:55:59 +00:00
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
std::string api_key;
|
2018-10-31 14:49:44 +00:00
|
|
|
env->GetVar("GOOGLE_API_KEY", &api_key);
|
2018-03-14 07:55:59 +00:00
|
|
|
return api_key;
|
|
|
|
}
|
|
|
|
|
2019-04-20 17:20:37 +00:00
|
|
|
scoped_refptr<content::QuotaPermissionContext>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::CreateQuotaPermissionContext() {
|
|
|
|
return new ElectronQuotaPermissionContext;
|
2015-05-12 12:22:30 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 20:16:33 +00:00
|
|
|
content::GeneratedCodeCacheSettings
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::GetGeneratedCodeCacheSettings(
|
2019-01-09 20:16:33 +00:00
|
|
|
content::BrowserContext* context) {
|
|
|
|
// TODO(deepak1556): Use platform cache directory.
|
|
|
|
base::FilePath cache_path = context->GetPath();
|
|
|
|
// If we pass 0 for size, disk_cache will pick a default size using the
|
|
|
|
// heuristics based on available disk size. These are implemented in
|
|
|
|
// disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
|
|
|
|
return content::GeneratedCodeCacheSettings(true, 0, cache_path);
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::AllowCertificateError(
|
2016-03-08 14:28:53 +00:00
|
|
|
content::WebContents* web_contents,
|
2015-11-18 02:39:25 +00:00
|
|
|
int cert_error,
|
|
|
|
const net::SSLInfo& ssl_info,
|
|
|
|
const GURL& request_url,
|
2019-05-13 21:24:39 +00:00
|
|
|
bool is_main_frame_request,
|
2015-11-18 02:39:25 +00:00
|
|
|
bool strict_enforcement,
|
2019-12-11 00:22:35 +00:00
|
|
|
base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
|
2015-11-18 02:39:25 +00:00
|
|
|
if (delegate_) {
|
2019-08-15 20:50:58 +00:00
|
|
|
delegate_->AllowCertificateError(web_contents, cert_error, ssl_info,
|
|
|
|
request_url, is_main_frame_request,
|
2019-12-11 00:22:35 +00:00
|
|
|
strict_enforcement, std::move(callback));
|
2015-11-18 02:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
base::OnceClosure ElectronBrowserClient::SelectClientCertificate(
|
2015-06-03 20:57:06 +00:00
|
|
|
content::WebContents* web_contents,
|
|
|
|
net::SSLCertRequestInfo* cert_request_info,
|
2017-08-20 21:35:04 +00:00
|
|
|
net::ClientCertIdentityList client_certs,
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<content::ClientCertificateDelegate> delegate) {
|
2017-08-04 21:11:01 +00:00
|
|
|
if (!client_certs.empty() && delegate_) {
|
|
|
|
delegate_->SelectClientCertificate(web_contents, cert_request_info,
|
|
|
|
std::move(client_certs),
|
|
|
|
std::move(delegate));
|
2015-11-18 02:07:03 +00:00
|
|
|
}
|
2019-07-03 01:22:09 +00:00
|
|
|
return base::OnceClosure();
|
2015-06-03 20:57:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::CanCreateWindow(
|
2017-08-04 21:38:06 +00:00
|
|
|
content::RenderFrameHost* opener,
|
2016-03-31 00:58:23 +00:00
|
|
|
const GURL& opener_url,
|
|
|
|
const GURL& opener_top_level_frame_url,
|
2019-01-21 18:14:57 +00:00
|
|
|
const url::Origin& source_origin,
|
2017-04-04 04:50:44 +00:00
|
|
|
content::mojom::WindowContainerType container_type,
|
2016-03-31 00:58:23 +00:00
|
|
|
const GURL& target_url,
|
|
|
|
const content::Referrer& referrer,
|
2016-11-30 07:30:03 +00:00
|
|
|
const std::string& frame_name,
|
2016-03-31 00:58:23 +00:00
|
|
|
WindowOpenDisposition disposition,
|
2017-04-04 04:50:44 +00:00
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 18:05:45 +00:00
|
|
|
const std::string& raw_features,
|
2018-04-11 08:42:14 +00:00
|
|
|
const scoped_refptr<network::ResourceRequestBody>& body,
|
2016-03-31 00:58:23 +00:00
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) {
|
2018-03-14 07:55:59 +00:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
2016-03-31 14:21:18 +00:00
|
|
|
|
2017-08-04 21:38:06 +00:00
|
|
|
int opener_render_process_id = opener->GetProcess()->GetID();
|
|
|
|
|
2017-05-23 22:59:17 +00:00
|
|
|
if (RendererUsesNativeWindowOpen(opener_render_process_id)) {
|
|
|
|
if (RendererDisablesPopups(opener_render_process_id)) {
|
|
|
|
// <webview> without allowpopups attribute should return
|
|
|
|
// null from window.open calls
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
*no_javascript_access = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 00:58:23 +00:00
|
|
|
if (delegate_) {
|
2017-12-07 04:12:38 +00:00
|
|
|
return delegate_->CanCreateWindow(
|
|
|
|
opener, opener_url, opener_top_level_frame_url, source_origin,
|
|
|
|
container_type, target_url, referrer, frame_name, disposition, features,
|
2020-03-26 18:05:45 +00:00
|
|
|
raw_features, body, user_gesture, opener_suppressed,
|
2017-12-07 04:12:38 +00:00
|
|
|
no_javascript_access);
|
2016-03-31 00:58:23 +00:00
|
|
|
}
|
2016-03-31 14:21:18 +00:00
|
|
|
|
|
|
|
return false;
|
2016-03-31 00:58:23 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 10:17:50 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PICTURE_IN_PICTURE)
|
|
|
|
std::unique_ptr<content::OverlayWindow>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::CreateWindowForPictureInPicture(
|
2019-08-22 10:17:50 +00:00
|
|
|
content::PictureInPictureWindowController* controller) {
|
2020-09-21 08:00:36 +00:00
|
|
|
auto overlay_window = content::OverlayWindow::Create(controller);
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
base::string16 app_user_model_id = Browser::Get()->GetAppUserModelID();
|
|
|
|
if (!app_user_model_id.empty()) {
|
2020-10-26 18:56:31 +00:00
|
|
|
auto* overlay_window_view =
|
2020-09-21 08:00:36 +00:00
|
|
|
static_cast<OverlayWindowViews*>(overlay_window.get());
|
|
|
|
ui::win::SetAppIdForWindow(app_user_model_id,
|
|
|
|
overlay_window_view->GetNativeWindow()
|
|
|
|
->GetHost()
|
|
|
|
->GetAcceleratedWidget());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return overlay_window;
|
2019-08-22 10:17:50 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
|
2016-08-24 00:16:54 +00:00
|
|
|
std::vector<std::string>* additional_schemes) {
|
2016-08-24 14:52:35 +00:00
|
|
|
auto schemes_list = api::GetStandardSchemes();
|
|
|
|
if (!schemes_list.empty())
|
2018-04-18 01:55:30 +00:00
|
|
|
additional_schemes->insert(additional_schemes->end(), schemes_list.begin(),
|
2016-08-24 00:16:54 +00:00
|
|
|
schemes_list.end());
|
2016-09-29 17:20:53 +00:00
|
|
|
additional_schemes->push_back(content::kChromeDevToolsScheme);
|
2020-02-13 00:39:12 +00:00
|
|
|
additional_schemes->push_back(content::kChromeUIScheme);
|
2016-08-24 00:16:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::GetAdditionalWebUISchemes(
|
2018-10-19 13:50:30 +00:00
|
|
|
std::vector<std::string>* additional_schemes) {
|
|
|
|
additional_schemes->push_back(content::kChromeDevToolsScheme);
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::SiteInstanceGotProcess(
|
2020-01-13 22:55:58 +00:00
|
|
|
content::SiteInstance* site_instance) {
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
auto* browser_context =
|
2020-02-04 20:19:40 +00:00
|
|
|
static_cast<ElectronBrowserContext*>(site_instance->GetBrowserContext());
|
2020-05-08 18:17:28 +00:00
|
|
|
if (!browser_context->IsOffTheRecord()) {
|
|
|
|
extensions::ExtensionRegistry* registry =
|
|
|
|
extensions::ExtensionRegistry::Get(browser_context);
|
|
|
|
const extensions::Extension* extension =
|
|
|
|
registry->enabled_extensions().GetExtensionOrAppByURL(
|
|
|
|
site_instance->GetSiteURL());
|
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
|
|
|
|
extensions::ProcessMap::Get(browser_context)
|
|
|
|
->Insert(extension->id(), site_instance->GetProcess()->GetID(),
|
|
|
|
site_instance->GetId());
|
|
|
|
}
|
2020-01-13 22:55:58 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
}
|
|
|
|
|
2020-02-06 21:42:34 +00:00
|
|
|
bool ElectronBrowserClient::IsSuitableHost(
|
|
|
|
content::RenderProcessHost* process_host,
|
|
|
|
const GURL& site_url) {
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
auto* browser_context = process_host->GetBrowserContext();
|
|
|
|
extensions::ExtensionRegistry* registry =
|
|
|
|
extensions::ExtensionRegistry::Get(browser_context);
|
|
|
|
extensions::ProcessMap* process_map =
|
|
|
|
extensions::ProcessMap::Get(browser_context);
|
|
|
|
|
|
|
|
// Otherwise, just make sure the process privilege matches the privilege
|
|
|
|
// required by the site.
|
|
|
|
RenderProcessHostPrivilege privilege_required =
|
|
|
|
GetPrivilegeRequiredByUrl(site_url, registry);
|
|
|
|
return GetProcessPrivilege(process_host, process_map, registry) ==
|
|
|
|
privilege_required;
|
|
|
|
#else
|
|
|
|
return content::ContentBrowserClient::IsSuitableHost(process_host, site_url);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ElectronBrowserClient::ShouldUseProcessPerSite(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& effective_url) {
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
const extensions::Extension* extension =
|
|
|
|
GetEnabledExtensionFromEffectiveURL(browser_context, effective_url);
|
|
|
|
return extension != nullptr;
|
|
|
|
#else
|
|
|
|
return content::ContentBrowserClient::ShouldUseProcessPerSite(browser_context,
|
|
|
|
effective_url);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-02-27 00:03:55 +00:00
|
|
|
bool ElectronBrowserClient::ArePersistentMediaDeviceIDsAllowed(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& scope,
|
|
|
|
const GURL& site_for_cookies,
|
|
|
|
const base::Optional<url::Origin>& top_frame_origin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::SiteInstanceDeleting(
|
2018-02-13 06:57:54 +00:00
|
|
|
content::SiteInstance* site_instance) {
|
|
|
|
// We are storing weak_ptr, is it fundamental to maintain the map up-to-date
|
|
|
|
// when an instance is destroyed.
|
2018-12-05 08:03:39 +00:00
|
|
|
for (auto iter = site_per_affinities_.begin();
|
|
|
|
iter != site_per_affinities_.end(); ++iter) {
|
2018-02-13 06:57:54 +00:00
|
|
|
if (iter->second == site_instance) {
|
2018-12-05 08:03:39 +00:00
|
|
|
site_per_affinities_.erase(iter);
|
2018-02-13 06:57:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 22:55:58 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
// Don't do anything if we're shutting down.
|
|
|
|
if (content::BrowserMainRunner::ExitedMainMessageLoop())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto* browser_context =
|
2020-02-04 20:19:40 +00:00
|
|
|
static_cast<ElectronBrowserContext*>(site_instance->GetBrowserContext());
|
2020-05-08 18:17:28 +00:00
|
|
|
if (!browser_context->IsOffTheRecord()) {
|
|
|
|
// If this isn't an extension renderer there's nothing to do.
|
|
|
|
extensions::ExtensionRegistry* registry =
|
|
|
|
extensions::ExtensionRegistry::Get(browser_context);
|
|
|
|
const extensions::Extension* extension =
|
|
|
|
registry->enabled_extensions().GetExtensionOrAppByURL(
|
|
|
|
site_instance->GetSiteURL());
|
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
|
|
|
|
extensions::ProcessMap::Get(browser_context)
|
|
|
|
->Remove(extension->id(), site_instance->GetProcess()->GetID(),
|
|
|
|
site_instance->GetId());
|
|
|
|
}
|
2020-01-13 22:55:58 +00:00
|
|
|
#endif
|
2018-02-13 06:57:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::unique_ptr<net::ClientCertStore>
|
|
|
|
ElectronBrowserClient::CreateClientCertStore(
|
2019-12-11 00:22:35 +00:00
|
|
|
content::BrowserContext* browser_context) {
|
2018-04-12 08:48:50 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2018-06-19 08:15:54 +00:00
|
|
|
return std::make_unique<net::ClientCertStoreNSS>(
|
|
|
|
net::ClientCertStoreNSS::PasswordDelegateFactory());
|
2018-04-12 08:48:50 +00:00
|
|
|
#elif defined(OS_WIN)
|
2018-06-19 08:15:54 +00:00
|
|
|
return std::make_unique<net::ClientCertStoreWin>();
|
2020-08-12 18:33:58 +00:00
|
|
|
#elif defined(OS_MAC)
|
2018-06-19 08:15:54 +00:00
|
|
|
return std::make_unique<net::ClientCertStoreMac>();
|
2018-04-12 08:48:50 +00:00
|
|
|
#elif defined(USE_OPENSSL)
|
|
|
|
return std::unique_ptr<net::ClientCertStore>();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-08-23 15:51:46 +00:00
|
|
|
std::unique_ptr<device::LocationProvider>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::OverrideSystemLocationProvider() {
|
2018-10-01 20:00:53 +00:00
|
|
|
#if BUILDFLAG(OVERRIDE_LOCATION_PROVIDER)
|
2018-08-23 15:51:46 +00:00
|
|
|
return std::make_unique<FakeLocationProvider>();
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-05-26 20:06:26 +00:00
|
|
|
void ElectronBrowserClient::ConfigureNetworkContextParams(
|
2018-10-04 18:08:56 +00:00
|
|
|
content::BrowserContext* browser_context,
|
2020-05-26 20:06:26 +00:00
|
|
|
bool in_memory,
|
|
|
|
const base::FilePath& relative_partition_path,
|
|
|
|
network::mojom::NetworkContextParams* network_context_params,
|
2021-03-06 00:54:18 +00:00
|
|
|
cert_verifier::mojom::CertVerifierCreationParams*
|
|
|
|
cert_verifier_creation_params) {
|
2019-09-18 19:58:00 +00:00
|
|
|
DCHECK(browser_context);
|
2019-08-02 23:56:46 +00:00
|
|
|
return NetworkContextServiceFactory::GetForContext(browser_context)
|
2020-05-26 20:06:26 +00:00
|
|
|
->ConfigureNetworkContextParams(network_context_params,
|
|
|
|
cert_verifier_creation_params);
|
2019-03-26 01:10:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
network::mojom::NetworkContext*
|
|
|
|
ElectronBrowserClient::GetSystemNetworkContext() {
|
2019-03-26 01:10:48 +00:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
DCHECK(g_browser_process->system_network_context_manager());
|
|
|
|
return g_browser_process->system_network_context_manager()->GetContext();
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 03:44:12 +00:00
|
|
|
std::unique_ptr<content::BrowserMainParts>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::CreateBrowserMainParts(
|
2018-10-04 18:08:56 +00:00
|
|
|
const content::MainFunctionParams& params) {
|
2020-02-04 20:19:40 +00:00
|
|
|
return std::make_unique<ElectronBrowserMainParts>(params);
|
2013-04-12 01:46:58 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::WebNotificationAllowed(
|
2016-01-25 16:37:15 +00:00
|
|
|
int render_process_id,
|
2019-05-29 20:02:15 +00:00
|
|
|
base::OnceCallback<void(bool, bool)> callback) {
|
2016-03-13 22:23:39 +00:00
|
|
|
content::WebContents* web_contents =
|
|
|
|
WebContentsPreferences::GetWebContentsFromProcessID(render_process_id);
|
2016-01-23 13:29:47 +00:00
|
|
|
if (!web_contents) {
|
2019-05-29 20:02:15 +00:00
|
|
|
std::move(callback).Run(false, false);
|
2016-01-23 13:29:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* permission_helper =
|
2016-01-23 13:29:47 +00:00
|
|
|
WebContentsPermissionHelper::FromWebContents(web_contents);
|
|
|
|
if (!permission_helper) {
|
2019-05-29 20:02:15 +00:00
|
|
|
std::move(callback).Run(false, false);
|
2016-01-23 13:29:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-07-02 07:54:12 +00:00
|
|
|
permission_helper->RequestWebNotificationPermission(
|
2019-05-29 20:02:15 +00:00
|
|
|
base::BindOnce(std::move(callback), web_contents->IsAudioMuted()));
|
2016-01-23 13:29:47 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RenderProcessHostDestroyed(
|
2015-08-11 07:39:17 +00:00
|
|
|
content::RenderProcessHost* host) {
|
|
|
|
int process_id = host->GetID();
|
2017-07-10 22:48:12 +00:00
|
|
|
pending_processes_.erase(process_id);
|
2019-06-20 10:10:56 +00:00
|
|
|
renderer_is_subframe_.erase(process_id);
|
2017-03-19 08:25:45 +00:00
|
|
|
RemoveProcessPreferences(process_id);
|
2021-02-09 20:16:21 +00:00
|
|
|
host->RemoveObserver(this);
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RenderProcessReady(
|
|
|
|
content::RenderProcessHost* host) {
|
2017-05-16 00:41:45 +00:00
|
|
|
if (delegate_) {
|
|
|
|
static_cast<api::App*>(delegate_)->RenderProcessReady(host);
|
|
|
|
}
|
2015-08-11 07:39:17 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RenderProcessExited(
|
2018-09-15 00:11:49 +00:00
|
|
|
content::RenderProcessHost* host,
|
|
|
|
const content::ChildProcessTerminationInfo& info) {
|
2020-12-01 01:47:46 +00:00
|
|
|
if (delegate_) {
|
|
|
|
static_cast<api::App*>(delegate_)->RenderProcessExited(host);
|
2017-05-26 15:32:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 15:05:21 +00:00
|
|
|
void OnOpenExternal(const GURL& escaped_url, bool allowed) {
|
2019-05-03 20:53:45 +00:00
|
|
|
if (allowed) {
|
2018-07-21 15:05:21 +00:00
|
|
|
platform_util::OpenExternal(
|
2019-05-03 20:53:45 +00:00
|
|
|
escaped_url, platform_util::OpenExternalOptions(), base::DoNothing());
|
|
|
|
}
|
2018-07-21 15:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HandleExternalProtocolInUI(
|
|
|
|
const GURL& url,
|
2019-12-11 00:22:35 +00:00
|
|
|
content::WebContents::OnceGetter web_contents_getter,
|
2018-07-21 15:05:21 +00:00
|
|
|
bool has_user_gesture) {
|
2019-12-11 00:22:35 +00:00
|
|
|
content::WebContents* web_contents = std::move(web_contents_getter).Run();
|
2018-07-21 15:05:21 +00:00
|
|
|
if (!web_contents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto* permission_helper =
|
|
|
|
WebContentsPermissionHelper::FromWebContents(web_contents);
|
|
|
|
if (!permission_helper)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
|
2019-05-29 20:02:15 +00:00
|
|
|
auto callback = base::BindOnce(&OnOpenExternal, escaped_url);
|
|
|
|
permission_helper->RequestOpenExternalPermission(std::move(callback),
|
|
|
|
has_user_gesture, url);
|
2018-07-21 15:05:21 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::HandleExternalProtocol(
|
2018-07-21 15:05:21 +00:00
|
|
|
const GURL& url,
|
2019-12-11 00:22:35 +00:00
|
|
|
content::WebContents::OnceGetter web_contents_getter,
|
2018-07-21 15:05:21 +00:00
|
|
|
int child_id,
|
|
|
|
content::NavigationUIData* navigation_data,
|
|
|
|
bool is_main_frame,
|
|
|
|
ui::PageTransition page_transition,
|
2019-01-09 20:18:07 +00:00
|
|
|
bool has_user_gesture,
|
2019-10-28 22:12:35 +00:00
|
|
|
const base::Optional<url::Origin>& initiating_origin,
|
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) {
|
2019-12-11 00:22:35 +00:00
|
|
|
base::PostTask(
|
|
|
|
FROM_HERE, {BrowserThread::UI},
|
|
|
|
base::BindOnce(&HandleExternalProtocolInUI, url,
|
|
|
|
std::move(web_contents_getter), has_user_gesture));
|
2018-07-21 15:05:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-15 15:42:43 +00:00
|
|
|
std::vector<std::unique_ptr<content::NavigationThrottle>>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::CreateThrottlesForNavigation(
|
2018-09-15 15:42:43 +00:00
|
|
|
content::NavigationHandle* handle) {
|
|
|
|
std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
|
2020-02-04 20:19:40 +00:00
|
|
|
throttles.push_back(std::make_unique<ElectronNavigationThrottle>(handle));
|
2020-01-13 22:55:58 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
throttles.push_back(
|
|
|
|
std::make_unique<extensions::ExtensionNavigationThrottle>(handle));
|
|
|
|
#endif
|
|
|
|
|
2018-09-15 15:42:43 +00:00
|
|
|
return throttles;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::MediaObserver* ElectronBrowserClient::GetMediaObserver() {
|
2018-10-19 18:51:43 +00:00
|
|
|
return MediaCaptureDevicesDispatcher::GetInstance();
|
|
|
|
}
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
content::DevToolsManagerDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::GetDevToolsManagerDelegate() {
|
2018-10-19 13:50:30 +00:00
|
|
|
return new DevToolsManagerDelegate;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
NotificationPresenter* ElectronBrowserClient::GetNotificationPresenter() {
|
2018-10-17 18:01:11 +00:00
|
|
|
if (!notification_presenter_) {
|
|
|
|
notification_presenter_.reset(NotificationPresenter::Create());
|
|
|
|
}
|
|
|
|
return notification_presenter_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::PlatformNotificationService*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::GetPlatformNotificationService(
|
2019-04-20 17:20:37 +00:00
|
|
|
content::BrowserContext* browser_context) {
|
2018-10-17 18:01:11 +00:00
|
|
|
if (!notification_service_) {
|
2019-09-16 22:12:00 +00:00
|
|
|
notification_service_ = std::make_unique<PlatformNotificationService>(this);
|
2018-10-17 18:01:11 +00:00
|
|
|
}
|
|
|
|
return notification_service_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
base::FilePath ElectronBrowserClient::GetDefaultDownloadDirectory() {
|
2018-10-23 08:45:41 +00:00
|
|
|
// ~/Downloads
|
|
|
|
base::FilePath path;
|
|
|
|
if (base::PathService::Get(base::DIR_HOME, &path))
|
|
|
|
path = path.Append(FILE_PATH_LITERAL("Downloads"));
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-11-07 14:38:41 +00:00
|
|
|
scoped_refptr<network::SharedURLLoaderFactory>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::GetSystemSharedURLLoaderFactory() {
|
2018-11-07 14:38:41 +00:00
|
|
|
if (!g_browser_process)
|
|
|
|
return nullptr;
|
|
|
|
return g_browser_process->shared_url_loader_factory();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::OnNetworkServiceCreated(
|
2018-11-07 14:38:41 +00:00
|
|
|
network::mojom::NetworkService* network_service) {
|
2019-08-02 23:56:46 +00:00
|
|
|
if (!g_browser_process)
|
2018-11-07 14:38:41 +00:00
|
|
|
return;
|
2019-03-26 01:10:48 +00:00
|
|
|
|
2018-11-07 14:38:41 +00:00
|
|
|
g_browser_process->system_network_context_manager()->OnNetworkServiceCreated(
|
|
|
|
network_service);
|
|
|
|
}
|
|
|
|
|
2019-04-24 00:31:36 +00:00
|
|
|
std::vector<base::FilePath>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserClient::GetNetworkContextsParentDirectory() {
|
2019-04-24 00:31:36 +00:00
|
|
|
base::FilePath user_data_dir;
|
|
|
|
base::PathService::Get(DIR_USER_DATA, &user_data_dir);
|
|
|
|
DCHECK(!user_data_dir.empty());
|
|
|
|
|
|
|
|
return {user_data_dir};
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserClient::GetProduct() {
|
2019-01-21 18:32:34 +00:00
|
|
|
return "Chrome/" CHROME_VERSION_STRING;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserClient::GetUserAgent() {
|
2019-05-01 23:34:42 +00:00
|
|
|
if (user_agent_override_.empty())
|
|
|
|
return GetApplicationUserAgent();
|
|
|
|
return user_agent_override_;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::SetUserAgent(const std::string& user_agent) {
|
2019-05-01 23:34:42 +00:00
|
|
|
user_agent_override_ = user_agent;
|
2019-01-21 18:32:34 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
|
2019-04-23 21:39:21 +00:00
|
|
|
int frame_tree_node_id,
|
2020-10-28 00:33:04 +00:00
|
|
|
ukm::SourceIdObj ukm_source_id,
|
2019-04-23 21:39:21 +00:00
|
|
|
NonNetworkURLLoaderFactoryMap* factories) {
|
|
|
|
content::WebContents* web_contents =
|
|
|
|
content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
|
2020-03-26 17:34:32 +00:00
|
|
|
content::BrowserContext* context = web_contents->GetBrowserContext();
|
2020-01-15 00:20:30 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-10-16 01:30:41 +00:00
|
|
|
factories->emplace(
|
2020-01-15 00:20:30 +00:00
|
|
|
extensions::kExtensionScheme,
|
|
|
|
extensions::CreateExtensionNavigationURLLoaderFactory(
|
2020-08-12 18:33:58 +00:00
|
|
|
context, ukm_source_id,
|
|
|
|
false /* we don't support extensions::WebViewGuest */));
|
2020-01-15 00:20:30 +00:00
|
|
|
#endif
|
2020-03-26 17:34:32 +00:00
|
|
|
auto* protocol_registry = ProtocolRegistry::FromBrowserContext(context);
|
2020-04-01 07:38:40 +00:00
|
|
|
protocol_registry->RegisterURLLoaderFactories(
|
|
|
|
URLLoaderFactoryType::kNavigation, factories);
|
2019-04-23 21:39:21 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 01:48:37 +00:00
|
|
|
void ElectronBrowserClient::
|
|
|
|
RegisterNonNetworkWorkerMainResourceURLLoaderFactories(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
NonNetworkURLLoaderFactoryMap* factories) {
|
|
|
|
auto* protocol_registry =
|
|
|
|
ProtocolRegistry::FromBrowserContext(browser_context);
|
|
|
|
protocol_registry->RegisterURLLoaderFactories(
|
|
|
|
URLLoaderFactoryType::kWorkerMainResource, factories);
|
|
|
|
}
|
|
|
|
|
2020-02-13 00:39:12 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// The FileURLLoaderFactory provided to the extension background pages.
|
|
|
|
// Checks with the ChildProcessSecurityPolicy to validate the file access.
|
2021-03-04 17:27:05 +00:00
|
|
|
class FileURLLoaderFactory : public network::SelfDeletingURLLoaderFactory {
|
2020-02-13 00:39:12 +00:00
|
|
|
public:
|
2020-09-21 08:00:36 +00:00
|
|
|
static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create(
|
|
|
|
int child_id) {
|
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
|
|
|
|
|
|
|
|
// The FileURLLoaderFactory will delete itself when there are no more
|
|
|
|
// receivers - see the NonNetworkURLLoaderFactoryBase::OnDisconnect method.
|
|
|
|
new FileURLLoaderFactory(child_id,
|
|
|
|
pending_remote.InitWithNewPipeAndPassReceiver());
|
|
|
|
|
|
|
|
return pending_remote;
|
|
|
|
}
|
2020-02-13 00:39:12 +00:00
|
|
|
|
|
|
|
private:
|
2020-09-21 08:00:36 +00:00
|
|
|
explicit FileURLLoaderFactory(
|
|
|
|
int child_id,
|
|
|
|
mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver)
|
2021-03-04 17:27:05 +00:00
|
|
|
: network::SelfDeletingURLLoaderFactory(std::move(factory_receiver)),
|
2020-09-21 08:00:36 +00:00
|
|
|
child_id_(child_id) {}
|
|
|
|
~FileURLLoaderFactory() override = default;
|
|
|
|
|
2020-02-13 00:39:12 +00:00
|
|
|
// network::mojom::URLLoaderFactory:
|
|
|
|
void CreateLoaderAndStart(
|
|
|
|
mojo::PendingReceiver<network::mojom::URLLoader> loader,
|
|
|
|
int32_t routing_id,
|
|
|
|
int32_t request_id,
|
|
|
|
uint32_t options,
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderClient> client,
|
|
|
|
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
|
|
|
|
override {
|
|
|
|
if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL(
|
|
|
|
child_id_, request.url)) {
|
|
|
|
mojo::Remote<network::mojom::URLLoaderClient>(std::move(client))
|
|
|
|
->OnComplete(
|
|
|
|
network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
content::CreateFileURLLoaderBypassingSecurityChecks(
|
|
|
|
request, std::move(loader), std::move(client),
|
|
|
|
/*observer=*/nullptr,
|
|
|
|
/* allow_directory_listing */ true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int child_id_;
|
2020-09-21 08:00:36 +00:00
|
|
|
|
2020-02-13 00:39:12 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
#endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(
|
2019-05-07 02:33:05 +00:00
|
|
|
int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
NonNetworkURLLoaderFactoryMap* factories) {
|
|
|
|
content::RenderFrameHost* frame_host =
|
|
|
|
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
|
|
|
|
content::WebContents* web_contents =
|
|
|
|
content::WebContents::FromRenderFrameHost(frame_host);
|
2020-02-13 00:39:12 +00:00
|
|
|
|
2019-08-02 23:56:46 +00:00
|
|
|
if (web_contents) {
|
2020-03-26 17:34:32 +00:00
|
|
|
ProtocolRegistry::FromBrowserContext(web_contents->GetBrowserContext())
|
2020-04-01 07:38:40 +00:00
|
|
|
->RegisterURLLoaderFactories(URLLoaderFactoryType::kDocumentSubResource,
|
|
|
|
factories);
|
2019-08-02 23:56:46 +00:00
|
|
|
}
|
2020-02-13 00:39:12 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id,
|
|
|
|
render_frame_id);
|
|
|
|
if (factory)
|
2020-10-16 01:30:41 +00:00
|
|
|
factories->emplace(extensions::kExtensionScheme, std::move(factory));
|
2020-02-13 00:39:12 +00:00
|
|
|
|
|
|
|
if (!web_contents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
extensions::ElectronExtensionWebContentsObserver* web_observer =
|
|
|
|
extensions::ElectronExtensionWebContentsObserver::FromWebContents(
|
|
|
|
web_contents);
|
|
|
|
|
|
|
|
// There is nothing to do if no ElectronExtensionWebContentsObserver is
|
|
|
|
// attached to the |web_contents|.
|
|
|
|
if (!web_observer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const extensions::Extension* extension =
|
|
|
|
web_observer->GetExtensionFromFrame(frame_host, false);
|
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Support for chrome:// scheme if appropriate.
|
|
|
|
if (extension->is_extension() &&
|
|
|
|
extensions::Manifest::IsComponentLocation(extension->location())) {
|
|
|
|
// Components of chrome that are implemented as extensions or platform apps
|
|
|
|
// are allowed to use chrome://resources/ and chrome://theme/ URLs.
|
2020-09-21 08:00:36 +00:00
|
|
|
factories->emplace(content::kChromeUIScheme,
|
|
|
|
content::CreateWebUIURLLoaderFactory(
|
|
|
|
frame_host, content::kChromeUIScheme,
|
|
|
|
{content::kChromeUIResourcesHost}));
|
2020-02-13 00:39:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extension with a background page get file access that gets approval from
|
|
|
|
// ChildProcessSecurityPolicy.
|
|
|
|
extensions::ExtensionHost* host =
|
|
|
|
extensions::ProcessManager::Get(web_contents->GetBrowserContext())
|
|
|
|
->GetBackgroundHostForExtension(extension->id());
|
|
|
|
if (host) {
|
2020-09-21 08:00:36 +00:00
|
|
|
factories->emplace(url::kFileScheme,
|
|
|
|
FileURLLoaderFactory::Create(render_process_id));
|
2020-02-13 00:39:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ElectronBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
|
|
|
|
base::StringPiece scheme,
|
|
|
|
bool is_embedded_origin_secure) {
|
|
|
|
if (is_embedded_origin_secure && scheme == content::kChromeUIScheme)
|
|
|
|
return true;
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
return scheme == extensions::kExtensionScheme;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2019-05-07 02:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 05:56:09 +00:00
|
|
|
bool ElectronBrowserClient::WillInterceptWebSocket(
|
|
|
|
content::RenderFrameHost* frame) {
|
|
|
|
if (!frame)
|
|
|
|
return false;
|
|
|
|
|
2020-06-22 16:35:24 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
2020-03-11 01:16:58 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2020-02-11 05:56:09 +00:00
|
|
|
auto* browser_context = frame->GetProcess()->GetBrowserContext();
|
|
|
|
auto web_request = api::WebRequest::FromOrCreate(isolate, browser_context);
|
|
|
|
|
|
|
|
// NOTE: Some unit test environments do not initialize
|
|
|
|
// BrowserContextKeyedAPI factories for e.g. WebRequest.
|
|
|
|
if (!web_request.get())
|
|
|
|
return false;
|
|
|
|
|
2020-12-18 23:11:43 +00:00
|
|
|
bool has_listener = web_request->HasListener();
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
const auto* web_request_api =
|
|
|
|
extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get(
|
|
|
|
browser_context);
|
|
|
|
|
|
|
|
if (web_request_api)
|
|
|
|
has_listener |= web_request_api->MayHaveProxies();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return has_listener;
|
2020-02-11 05:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronBrowserClient::CreateWebSocket(
|
|
|
|
content::RenderFrameHost* frame,
|
|
|
|
WebSocketFactory factory,
|
|
|
|
const GURL& url,
|
|
|
|
const net::SiteForCookies& site_for_cookies,
|
|
|
|
const base::Optional<std::string>& user_agent,
|
|
|
|
mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
|
|
|
|
handshake_client) {
|
2020-06-22 16:35:24 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
2020-03-11 01:16:58 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2020-02-11 05:56:09 +00:00
|
|
|
auto* browser_context = frame->GetProcess()->GetBrowserContext();
|
2020-12-18 23:11:43 +00:00
|
|
|
|
2020-02-11 05:56:09 +00:00
|
|
|
auto web_request = api::WebRequest::FromOrCreate(isolate, browser_context);
|
|
|
|
DCHECK(web_request.get());
|
2020-12-18 23:11:43 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
if (!web_request->HasListener()) {
|
|
|
|
auto* web_request_api = extensions::BrowserContextKeyedAPIFactory<
|
|
|
|
extensions::WebRequestAPI>::Get(browser_context);
|
|
|
|
|
|
|
|
if (web_request_api && web_request_api->MayHaveProxies()) {
|
|
|
|
web_request_api->ProxyWebSocket(frame, std::move(factory), url,
|
|
|
|
site_for_cookies.RepresentativeUrl(),
|
|
|
|
user_agent, std::move(handshake_client));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-11 05:56:09 +00:00
|
|
|
ProxyingWebSocket::StartProxying(
|
|
|
|
web_request.get(), std::move(factory), url,
|
|
|
|
site_for_cookies.RepresentativeUrl(), user_agent,
|
|
|
|
std::move(handshake_client), true, frame->GetProcess()->GetID(),
|
|
|
|
frame->GetRoutingID(), frame->GetLastCommittedOrigin(), browser_context,
|
|
|
|
&next_id_);
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::WillCreateURLLoaderFactory(
|
2019-05-22 01:43:37 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
content::RenderFrameHost* frame_host,
|
|
|
|
int render_process_id,
|
2019-08-24 01:14:23 +00:00
|
|
|
URLLoaderFactoryType type,
|
2019-05-22 01:43:37 +00:00
|
|
|
const url::Origin& request_initiator,
|
2019-12-11 00:22:35 +00:00
|
|
|
base::Optional<int64_t> navigation_id,
|
2020-10-28 00:33:04 +00:00
|
|
|
ukm::SourceIdObj ukm_source_id,
|
2019-07-24 22:58:51 +00:00
|
|
|
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
|
2019-09-18 19:58:00 +00:00
|
|
|
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
|
|
|
|
header_client,
|
2019-12-11 00:22:35 +00:00
|
|
|
bool* bypass_redirect_checks,
|
2020-01-17 18:41:52 +00:00
|
|
|
bool* disable_secure_dns,
|
2019-12-11 00:22:35 +00:00
|
|
|
network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
|
2020-06-22 16:35:24 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
2020-03-11 01:16:58 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2019-10-24 00:51:06 +00:00
|
|
|
auto web_request = api::WebRequest::FromOrCreate(isolate, browser_context);
|
2019-08-13 05:47:35 +00:00
|
|
|
DCHECK(web_request.get());
|
2019-05-22 01:43:37 +00:00
|
|
|
|
2020-12-18 23:11:43 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
if (!web_request->HasListener()) {
|
|
|
|
auto* web_request_api = extensions::BrowserContextKeyedAPIFactory<
|
|
|
|
extensions::WebRequestAPI>::Get(browser_context);
|
|
|
|
|
|
|
|
DCHECK(web_request_api);
|
|
|
|
bool use_proxy_for_web_request =
|
|
|
|
web_request_api->MaybeProxyURLLoaderFactory(
|
|
|
|
browser_context, frame_host, render_process_id, type, navigation_id,
|
|
|
|
ukm_source_id, factory_receiver, header_client);
|
|
|
|
|
|
|
|
if (bypass_redirect_checks)
|
|
|
|
*bypass_redirect_checks = use_proxy_for_web_request;
|
|
|
|
if (use_proxy_for_web_request)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-24 22:58:51 +00:00
|
|
|
auto proxied_receiver = std::move(*factory_receiver);
|
2019-10-28 22:12:35 +00:00
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderFactory> target_factory_remote;
|
|
|
|
*factory_receiver = target_factory_remote.InitWithNewPipeAndPassReceiver();
|
2019-07-22 22:01:45 +00:00
|
|
|
|
2020-01-22 01:31:10 +00:00
|
|
|
// Required by WebRequestInfoInitParams.
|
|
|
|
//
|
|
|
|
// Note that in Electron we allow webRequest to capture requests sent from
|
|
|
|
// browser process, so creation of |navigation_ui_data| is different from
|
|
|
|
// Chromium which only does for renderer-initialized navigations.
|
|
|
|
std::unique_ptr<extensions::ExtensionNavigationUIData> navigation_ui_data;
|
|
|
|
if (navigation_id.has_value()) {
|
|
|
|
navigation_ui_data =
|
|
|
|
std::make_unique<extensions::ExtensionNavigationUIData>();
|
|
|
|
}
|
|
|
|
|
2019-09-18 19:58:00 +00:00
|
|
|
mojo::PendingReceiver<network::mojom::TrustedURLLoaderHeaderClient>
|
|
|
|
header_client_receiver;
|
2019-07-22 22:01:45 +00:00
|
|
|
if (header_client)
|
2019-09-18 19:58:00 +00:00
|
|
|
header_client_receiver = header_client->InitWithNewPipeAndPassReceiver();
|
2019-07-22 22:01:45 +00:00
|
|
|
|
2020-03-26 17:34:32 +00:00
|
|
|
auto* protocol_registry =
|
|
|
|
ProtocolRegistry::FromBrowserContext(browser_context);
|
2019-12-11 00:22:35 +00:00
|
|
|
new ProxyingURLLoaderFactory(
|
2020-03-26 17:34:32 +00:00
|
|
|
web_request.get(), protocol_registry->intercept_handlers(),
|
2020-09-21 08:00:36 +00:00
|
|
|
render_process_id, &next_id_, std::move(navigation_ui_data),
|
|
|
|
std::move(navigation_id), std::move(proxied_receiver),
|
|
|
|
std::move(target_factory_remote), std::move(header_client_receiver),
|
|
|
|
type);
|
2019-07-22 22:01:45 +00:00
|
|
|
|
2019-08-02 23:56:46 +00:00
|
|
|
if (bypass_redirect_checks)
|
|
|
|
*bypass_redirect_checks = true;
|
2020-08-03 23:56:18 +00:00
|
|
|
|
2019-05-22 01:43:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::OverrideURLLoaderFactoryParams(
|
2019-12-11 00:22:35 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const url::Origin& origin,
|
|
|
|
bool is_for_isolated_world,
|
|
|
|
network::mojom::URLLoaderFactoryParams* factory_params) {
|
2020-09-16 21:55:53 +00:00
|
|
|
// Bypass CORB and CORS when web security is disabled.
|
2020-08-28 01:43:08 +00:00
|
|
|
auto it = process_preferences_.find(factory_params->process_id);
|
|
|
|
if (it != process_preferences_.end() && !it->second.web_security) {
|
|
|
|
factory_params->is_corb_enabled = false;
|
2020-09-16 21:55:53 +00:00
|
|
|
factory_params->disable_web_security = true;
|
2019-08-02 23:56:46 +00:00
|
|
|
}
|
2020-08-03 23:56:18 +00:00
|
|
|
|
|
|
|
extensions::URLLoaderFactoryManager::OverrideURLLoaderFactoryParams(
|
|
|
|
browser_context, origin, is_for_isolated_world, factory_params);
|
2019-08-02 23:56:46 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
#if defined(OS_WIN)
|
2021-02-09 20:16:21 +00:00
|
|
|
bool ElectronBrowserClient::PreSpawnChild(
|
|
|
|
sandbox::TargetPolicy* policy,
|
|
|
|
sandbox::policy::SandboxType sandbox_type,
|
|
|
|
ChildSpawnFlags flags) {
|
2019-06-13 06:42:21 +00:00
|
|
|
// Allow crashpad to communicate via named pipe.
|
|
|
|
sandbox::ResultCode result = policy->AddRule(
|
|
|
|
sandbox::TargetPolicy::SUBSYS_FILES,
|
|
|
|
sandbox::TargetPolicy::FILES_ALLOW_ANY, L"\\??\\pipe\\crashpad_*");
|
|
|
|
if (result != sandbox::SBOX_ALL_OK)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::BindAssociatedReceiverFromFrame(
|
2019-08-19 20:13:24 +00:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const std::string& interface_name,
|
|
|
|
mojo::ScopedInterfaceEndpointHandle* handle) {
|
|
|
|
if (interface_name == mojom::ElectronAutofillDriver::Name_) {
|
|
|
|
AutofillDriverFactory::BindAutofillDriver(
|
|
|
|
mojom::ElectronAutofillDriverAssociatedRequest(std::move(*handle)),
|
|
|
|
render_frame_host);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserClient::GetApplicationLocale() {
|
2018-10-23 08:45:41 +00:00
|
|
|
if (BrowserThread::CurrentlyOn(BrowserThread::IO))
|
|
|
|
return g_io_thread_application_locale.Get();
|
|
|
|
return *g_application_locale;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
base::FilePath ElectronBrowserClient::GetFontLookupTableCacheDir() {
|
2019-08-24 01:14:23 +00:00
|
|
|
base::FilePath user_data_dir;
|
|
|
|
base::PathService::Get(DIR_USER_DATA, &user_data_dir);
|
|
|
|
DCHECK(!user_data_dir.empty());
|
|
|
|
return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache"));
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserClient::ShouldEnableStrictSiteIsolation() {
|
2018-12-05 08:03:39 +00:00
|
|
|
// Enable site isolation. It is off by default in Chromium <= 69.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::BindHostReceiverForRenderer(
|
2019-11-05 23:41:20 +00:00
|
|
|
content::RenderProcessHost* render_process_host,
|
|
|
|
mojo::GenericPendingReceiver receiver) {
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
if (auto host_receiver = receiver.As<spellcheck::mojom::SpellCheckHost>()) {
|
|
|
|
SpellCheckHostChromeImpl::Create(render_process_host->GetID(),
|
|
|
|
std::move(host_receiver));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-12-14 18:57:36 +00:00
|
|
|
void BindElectronBrowser(
|
|
|
|
content::RenderFrameHost* frame_host,
|
|
|
|
mojo::PendingReceiver<electron::mojom::ElectronBrowser> receiver) {
|
|
|
|
ElectronBrowserHandlerImpl::Create(frame_host, std::move(receiver));
|
|
|
|
}
|
|
|
|
|
2020-02-13 00:39:12 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
void BindMimeHandlerService(
|
|
|
|
content::RenderFrameHost* frame_host,
|
|
|
|
mojo::PendingReceiver<extensions::mime_handler::MimeHandlerService>
|
|
|
|
receiver) {
|
|
|
|
content::WebContents* contents =
|
|
|
|
content::WebContents::FromRenderFrameHost(frame_host);
|
|
|
|
auto* guest_view =
|
|
|
|
extensions::MimeHandlerViewGuest::FromWebContents(contents);
|
|
|
|
if (!guest_view)
|
|
|
|
return;
|
|
|
|
extensions::MimeHandlerServiceImpl::Create(guest_view->GetStreamWeakPtr(),
|
|
|
|
std::move(receiver));
|
|
|
|
}
|
2020-03-11 11:15:07 +00:00
|
|
|
|
|
|
|
void BindBeforeUnloadControl(
|
|
|
|
content::RenderFrameHost* frame_host,
|
|
|
|
mojo::PendingReceiver<extensions::mime_handler::BeforeUnloadControl>
|
|
|
|
receiver) {
|
|
|
|
auto* web_contents = content::WebContents::FromRenderFrameHost(frame_host);
|
|
|
|
if (!web_contents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto* guest_view =
|
|
|
|
extensions::MimeHandlerViewGuest::FromWebContents(web_contents);
|
|
|
|
if (!guest_view)
|
|
|
|
return;
|
|
|
|
guest_view->FuseBeforeUnloadControl(std::move(receiver));
|
|
|
|
}
|
2020-02-13 00:39:12 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserClient::RegisterBrowserInterfaceBindersForFrame(
|
2019-12-11 00:22:35 +00:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2020-05-26 20:06:26 +00:00
|
|
|
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) {
|
2019-12-11 00:22:35 +00:00
|
|
|
map->Add<network_hints::mojom::NetworkHintsHandler>(
|
|
|
|
base::BindRepeating(&BindNetworkHintsHandler));
|
2020-09-08 15:13:56 +00:00
|
|
|
map->Add<blink::mojom::BadgeService>(
|
2021-01-21 05:45:06 +00:00
|
|
|
base::BindRepeating(&badging::BadgeManager::BindFrameReceiver));
|
2020-12-14 18:57:36 +00:00
|
|
|
map->Add<electron::mojom::ElectronBrowser>(
|
|
|
|
base::BindRepeating(&BindElectronBrowser));
|
2020-02-13 00:39:12 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
map->Add<extensions::mime_handler::MimeHandlerService>(
|
|
|
|
base::BindRepeating(&BindMimeHandlerService));
|
2020-03-11 11:15:07 +00:00
|
|
|
map->Add<extensions::mime_handler::BeforeUnloadControl>(
|
|
|
|
base::BindRepeating(&BindBeforeUnloadControl));
|
|
|
|
|
|
|
|
content::WebContents* web_contents =
|
|
|
|
content::WebContents::FromRenderFrameHost(render_frame_host);
|
|
|
|
if (!web_contents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const GURL& site = render_frame_host->GetSiteInstance()->GetSiteURL();
|
|
|
|
if (!site.SchemeIs(extensions::kExtensionScheme))
|
|
|
|
return;
|
|
|
|
|
|
|
|
content::BrowserContext* browser_context =
|
|
|
|
render_frame_host->GetProcess()->GetBrowserContext();
|
|
|
|
auto* extension = extensions::ExtensionRegistry::Get(browser_context)
|
|
|
|
->enabled_extensions()
|
|
|
|
.GetByID(site.host());
|
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
extensions::ExtensionsBrowserClient::Get()
|
|
|
|
->RegisterBrowserInterfaceBindersForFrame(map, render_frame_host,
|
|
|
|
extension);
|
2020-02-13 00:39:12 +00:00
|
|
|
#endif
|
2019-12-11 00:22:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
void ElectronBrowserClient::GetAdditionalMappedFilesForChildProcess(
|
|
|
|
const base::CommandLine& command_line,
|
|
|
|
int child_process_id,
|
|
|
|
content::PosixFileDescriptorInfo* mappings) {
|
|
|
|
int crash_signal_fd = GetCrashSignalFD(command_line);
|
|
|
|
if (crash_signal_fd >= 0) {
|
2020-10-16 01:30:41 +00:00
|
|
|
mappings->Share(kCrashDumpSignal, crash_signal_fd);
|
2020-05-07 20:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::unique_ptr<content::LoginDelegate>
|
|
|
|
ElectronBrowserClient::CreateLoginDelegate(
|
2019-11-11 17:47:01 +00:00
|
|
|
const net::AuthChallengeInfo& auth_info,
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
const content::GlobalRequestID& request_id,
|
|
|
|
bool is_main_frame,
|
|
|
|
const GURL& url,
|
|
|
|
scoped_refptr<net::HttpResponseHeaders> response_headers,
|
|
|
|
bool first_auth_attempt,
|
|
|
|
LoginAuthRequiredCallback auth_required_callback) {
|
|
|
|
return std::make_unique<LoginHandler>(
|
|
|
|
auth_info, web_contents, is_main_frame, url, response_headers,
|
|
|
|
first_auth_attempt, std::move(auth_required_callback));
|
|
|
|
}
|
|
|
|
|
2020-02-13 00:39:12 +00:00
|
|
|
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
|
|
|
|
ElectronBrowserClient::CreateURLLoaderThrottles(
|
|
|
|
const network::ResourceRequest& request,
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
|
|
|
|
content::NavigationUIData* navigation_ui_data,
|
|
|
|
int frame_tree_node_id) {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
|
2021-02-09 20:16:21 +00:00
|
|
|
request.destination, frame_tree_node_id));
|
2020-02-13 00:39:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::flat_set<std::string>
|
|
|
|
ElectronBrowserClient::GetPluginMimeTypesWithExternalHandlers(
|
|
|
|
content::BrowserContext* browser_context) {
|
|
|
|
base::flat_set<std::string> mime_types;
|
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context);
|
|
|
|
for (const auto& pair : map)
|
|
|
|
mime_types.insert(pair.first);
|
|
|
|
#endif
|
|
|
|
return mime_types;
|
|
|
|
}
|
|
|
|
|
2020-09-28 16:22:03 +00:00
|
|
|
content::SerialDelegate* ElectronBrowserClient::GetSerialDelegate() {
|
|
|
|
if (!serial_delegate_)
|
|
|
|
serial_delegate_ = std::make_unique<ElectronSerialDelegate>();
|
|
|
|
return serial_delegate_.get();
|
|
|
|
}
|
|
|
|
|
2021-02-26 19:10:27 +00:00
|
|
|
content::BluetoothDelegate* ElectronBrowserClient::GetBluetoothDelegate() {
|
|
|
|
if (!bluetooth_delegate_)
|
|
|
|
bluetooth_delegate_ = std::make_unique<ElectronBluetoothDelegate>();
|
|
|
|
return bluetooth_delegate_.get();
|
|
|
|
}
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
void ElectronBrowserClient::BindBadgeServiceReceiverFromServiceWorker(
|
|
|
|
content::RenderProcessHost* service_worker_process_host,
|
|
|
|
const GURL& service_worker_scope,
|
|
|
|
mojo::PendingReceiver<blink::mojom::BadgeService> receiver) {
|
|
|
|
badging::BadgeManager::BindServiceWorkerReceiver(
|
|
|
|
service_worker_process_host, service_worker_scope, std::move(receiver));
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|