From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Andy Locascio Date: Wed, 6 May 2020 16:37:54 -0700 Subject: allow in-process windows to have different web prefs Allow earlier access to newly created WebContents so that we can change WebPreferences of in-process child windows, rather than relying on process-level command line switches, as before. diff --git a/third_party/blink/common/web_preferences/web_preferences.cc b/third_party/blink/common/web_preferences/web_preferences.cc index 758b0b1616ecf86b7dd090adce94395851d9baf2..55f20eb6266368c65fc0ec80d52caa332f85ecfb 100644 --- a/third_party/blink/common/web_preferences/web_preferences.cc +++ b/third_party/blink/common/web_preferences/web_preferences.cc @@ -146,6 +146,29 @@ WebPreferences::WebPreferences() navigate_on_drag_drop(true), v8_cache_options(blink::mojom::V8CacheOptions::kDefault), record_whole_document(false), + + // Begin Electron-specific WebPreferences. + disable_electron_site_instance_overrides(), + background_color(base::EmptyString()), + opener_id(0), + context_isolation(false), + enable_remote_module(false), + world_safe_execute_javascript(false), + guest_instance_id(0), + hidden_page(false), + offscreen(false), + preload(base::FilePath::StringType()), + native_window_open(false), + node_integration(false), + node_integration_in_worker(false), + node_leakage_in_renderers(false), + node_integration_in_sub_frames(false), + enable_spellcheck(false), + enable_plugins(false), + enable_websql(false), + webview_tag(false), + // End Electron-specific WebPreferences. + cookie_enabled(true), accelerated_video_decode_enabled(false), animation_policy( diff --git a/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc b/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc index ac2cb47de75eb3c3a695ff784c651ba3864ee6a0..e238c4e94fe6501bf7f89654d3b3eeef86eafb63 100644 --- a/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc +++ b/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc @@ -24,6 +24,11 @@ bool StructTraitscursive_font_family_map) || !data.ReadFantasyFontFamilyMap(&out->fantasy_font_family_map) || !data.ReadPictographFontFamilyMap(&out->pictograph_font_family_map) || + // Begin Electron-specific WebPreferences. + !data.ReadPreloads(&out->preloads) || + !data.ReadBackgroundColor(&out->background_color) || + !data.ReadPreload(&out->preload) || + // End Electron-specific WebPreferences. !data.ReadLazyFrameLoadingDistanceThresholdsPx( &out->lazy_frame_loading_distance_thresholds_px) || !data.ReadLazyImageLoadingDistanceThresholdsPx( @@ -150,6 +155,27 @@ bool StructTraitsnavigate_on_drag_drop = data.navigate_on_drag_drop(); out->v8_cache_options = data.v8_cache_options(); out->record_whole_document = data.record_whole_document(); + + // Begin Electron-specific WebPreferences. + out->disable_electron_site_instance_overrides = data.disable_electron_site_instance_overrides(); + out->opener_id = data.opener_id(); + out->context_isolation = data.context_isolation(); + out->enable_remote_module = data.enable_remote_module(); + out->world_safe_execute_javascript = data.world_safe_execute_javascript(); + out->guest_instance_id = data.guest_instance_id(); + out->hidden_page = data.hidden_page(); + out->offscreen = data.offscreen(); + out->native_window_open = data.native_window_open(); + out->node_integration = data.node_integration(); + out->node_integration_in_worker = data.node_integration_in_worker(); + out->node_leakage_in_renderers = data.node_leakage_in_renderers(); + out->node_integration_in_sub_frames = data.node_integration_in_sub_frames(); + out->enable_spellcheck = data.enable_spellcheck(); + out->enable_plugins = data.enable_plugins(); + out->enable_websql = data.enable_websql(); + out->webview_tag = data.webview_tag(); + // End Electron-specific WebPreferences. + out->cookie_enabled = data.cookie_enabled(); out->accelerated_video_decode_enabled = data.accelerated_video_decode_enabled(); diff --git a/third_party/blink/public/common/web_preferences/web_preferences.h b/third_party/blink/public/common/web_preferences/web_preferences.h index 64444803e75f95ad1a9b526521c5eee90ba5f925..f8b33c329988f269964783fb290721fc5208ae3d 100644 --- a/third_party/blink/public/common/web_preferences/web_preferences.h +++ b/third_party/blink/public/common/web_preferences/web_preferences.h @@ -9,6 +9,7 @@ #include #include +#include "base/files/file_path.h" #include "base/strings/string16.h" #include "base/time/time.h" #include "build/build_config.h" @@ -159,6 +160,29 @@ struct BLINK_COMMON_EXPORT WebPreferences { blink::mojom::V8CacheOptions v8_cache_options; bool record_whole_document; + // Begin Electron-specific WebPreferences. + std::vector preloads; + bool disable_electron_site_instance_overrides; + std::string background_color; + int opener_id; + bool context_isolation; + bool enable_remote_module; + bool world_safe_execute_javascript; + int guest_instance_id; + bool hidden_page; + bool offscreen; + base::FilePath preload; + bool native_window_open; + bool node_integration; + bool node_integration_in_worker; + bool node_leakage_in_renderers; + bool node_integration_in_sub_frames; + bool enable_spellcheck; + bool enable_plugins; + bool enable_websql; + bool webview_tag; + // End Electron-specific WebPreferences. + // This flags corresponds to a Page's Settings' setCookieEnabled state. It // only controls whether or not the "document.cookie" field is properly // connected to the backing store, for instance if you wanted to be able to diff --git a/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h b/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h index c071879cdc2e8c39f9eb9e95aa9f08d6d560fc58..9b4143fe461b35df5763e89991c00befd12a18d2 100644 --- a/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h +++ b/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h @@ -6,6 +6,7 @@ #define THIRD_PARTY_BLINK_PUBLIC_COMMON_WEB_PREFERENCES_WEB_PREFERENCES_MOJOM_TRAITS_H_ #include "build/build_config.h" +#include "mojo/public/cpp/base/file_path_mojom_traits.h" #include "mojo/public/cpp/bindings/struct_traits.h" #include "net/nqe/effective_connection_type.h" #include "third_party/blink/public/common/common_export.h" @@ -436,6 +437,88 @@ struct BLINK_COMMON_EXPORT StructTraits& preloads(const blink::web_pref::WebPreferences& r) { + return r.preloads; + } + + static bool disable_electron_site_instance_overrides(const blink::web_pref::WebPreferences& r) { + return r.disable_electron_site_instance_overrides; + } + + static const std::string& background_color(const blink::web_pref::WebPreferences& r) { + return r.background_color; + } + + static int opener_id(const blink::web_pref::WebPreferences& r) { + return r.opener_id; + } + + static bool context_isolation(const blink::web_pref::WebPreferences& r) { + return r.context_isolation; + } + + static bool enable_remote_module(const blink::web_pref::WebPreferences& r) { + return r.enable_remote_module; + } + + static bool world_safe_execute_javascript(const blink::web_pref::WebPreferences& r) { + return r.world_safe_execute_javascript; + } + + static int guest_instance_id(const blink::web_pref::WebPreferences& r) { + return r.guest_instance_id; + } + + static bool hidden_page(const blink::web_pref::WebPreferences& r) { + return r.hidden_page; + } + + static bool offscreen(const blink::web_pref::WebPreferences& r) { + return r.offscreen; + } + + static const base::FilePath& preload(const blink::web_pref::WebPreferences& r) { + return r.preload; + } + + static bool native_window_open(const blink::web_pref::WebPreferences& r) { + return r.native_window_open; + } + + static bool node_integration(const blink::web_pref::WebPreferences& r) { + return r.node_integration; + } + + static bool node_integration_in_worker(const blink::web_pref::WebPreferences& r) { + return r.node_integration_in_worker; + } + + static bool node_leakage_in_renderers(const blink::web_pref::WebPreferences& r) { + return r.node_leakage_in_renderers; + } + + static bool node_integration_in_sub_frames(const blink::web_pref::WebPreferences& r) { + return r.node_integration_in_sub_frames; + } + + static bool enable_spellcheck(const blink::web_pref::WebPreferences& r) { + return r.enable_spellcheck; + } + + static bool enable_plugins(const blink::web_pref::WebPreferences& r) { + return r.enable_plugins; + } + + static bool enable_websql(const blink::web_pref::WebPreferences& r) { + return r.enable_websql; + } + + static bool webview_tag(const blink::web_pref::WebPreferences& r) { + return r.webview_tag; + } + // End Electron-specific WebPreferences. + static bool cookie_enabled(const blink::web_pref::WebPreferences& r) { return r.cookie_enabled; } diff --git a/third_party/blink/public/mojom/webpreferences/web_preferences.mojom b/third_party/blink/public/mojom/webpreferences/web_preferences.mojom index 519b354f7a0e02e8bfeb9c33904f78898fce37c4..483712685b01a75ad26e9f45a08f2ae32b00d10f 100644 --- a/third_party/blink/public/mojom/webpreferences/web_preferences.mojom +++ b/third_party/blink/public/mojom/webpreferences/web_preferences.mojom @@ -9,6 +9,7 @@ import "third_party/blink/public/mojom/css/preferred_contrast.mojom"; import "third_party/blink/public/mojom/v8_cache_options.mojom"; import "url/mojom/url.mojom"; import "mojo/public/mojom/base/string16.mojom"; +import "mojo/public/mojom/base/file_path.mojom"; enum PointerType { kPointerNone = 1, // 1 << 0 @@ -210,6 +211,29 @@ struct WebPreferences { V8CacheOptions v8_cache_options; bool record_whole_document; + // Begin Electron-specific WebPreferences. + array preloads; + bool disable_electron_site_instance_overrides; + string background_color; + int32 opener_id; + bool context_isolation; + bool enable_remote_module; + bool world_safe_execute_javascript; + int32 guest_instance_id; + bool hidden_page; + bool offscreen; + mojo_base.mojom.FilePath preload; + bool native_window_open; + bool node_integration; + bool node_integration_in_worker; + bool node_leakage_in_renderers; + bool node_integration_in_sub_frames; + bool enable_spellcheck; + bool enable_plugins; + bool enable_websql; + bool webview_tag; + // End Electron-specific WebPreferences. + // This flags corresponds to a Page's Settings' setCookieEnabled state. It // only controls whether or not the "document.cookie" field is properly // connected to the backing store, for instance if you wanted to be able to