2015-09-04 16:44:22 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/web_contents_preferences.h"
|
2015-09-04 16:44:22 +00:00
|
|
|
|
2016-03-09 12:34:51 +00:00
|
|
|
#include <algorithm>
|
2015-09-05 11:47:44 +00:00
|
|
|
#include <string>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <utility>
|
2016-03-09 12:34:51 +00:00
|
|
|
#include <vector>
|
2015-09-05 11:47:44 +00:00
|
|
|
|
2015-09-04 17:04:09 +00:00
|
|
|
#include "base/command_line.h"
|
2023-06-22 12:33:44 +00:00
|
|
|
#include "base/containers/fixed_flat_map.h"
|
2017-08-07 20:30:03 +00:00
|
|
|
#include "base/memory/ptr_util.h"
|
2015-09-04 17:33:13 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2018-08-03 21:23:07 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "cc/base/switches.h"
|
2018-03-12 08:27:43 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2016-03-09 12:34:51 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2022-01-10 22:31:39 +00:00
|
|
|
#include "content/public/browser/web_contents_user_data.h"
|
2016-01-07 04:49:00 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2015-09-05 01:57:39 +00:00
|
|
|
#include "net/base/filename_util.h"
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "sandbox/policy/switches.h"
|
2021-07-28 22:32:53 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/native_window.h"
|
2021-08-03 22:07:03 +00:00
|
|
|
#include "shell/browser/session_preferences.h"
|
2021-09-06 07:59:09 +00:00
|
|
|
#include "shell/common/color_util.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
2020-06-25 17:55:17 +00:00
|
|
|
#include "shell/common/process_util.h"
|
2020-09-21 08:00:36 +00:00
|
|
|
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
|
2020-06-01 03:09:23 +00:00
|
|
|
#include "third_party/blink/public/mojom/v8_cache_options.mojom.h"
|
2021-07-26 16:04:09 +00:00
|
|
|
#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom.h"
|
2015-09-04 17:04:09 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2015-09-04 17:04:09 +00:00
|
|
|
#include "ui/gfx/switches.h"
|
|
|
|
#endif
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
namespace gin {
|
2018-08-03 21:23:07 +00:00
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
template <>
|
|
|
|
struct Converter<blink::mojom::AutoplayPolicy> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
blink::mojom::AutoplayPolicy* out) {
|
2023-06-22 12:33:44 +00:00
|
|
|
using Val = blink::mojom::AutoplayPolicy;
|
|
|
|
static constexpr auto Lookup =
|
2023-11-28 21:40:12 +00:00
|
|
|
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
2023-06-22 12:33:44 +00:00
|
|
|
{"document-user-activation-required",
|
|
|
|
Val::kDocumentUserActivationRequired},
|
|
|
|
{"no-user-gesture-required", Val::kNoUserGestureRequired},
|
|
|
|
{"user-gesture-required", Val::kUserGestureRequired},
|
|
|
|
});
|
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2019-01-15 19:30:34 +00:00
|
|
|
}
|
2021-07-26 16:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct Converter<blink::mojom::V8CacheOptions> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
blink::mojom::V8CacheOptions* out) {
|
2023-06-22 12:33:44 +00:00
|
|
|
using Val = blink::mojom::V8CacheOptions;
|
|
|
|
static constexpr auto Lookup =
|
2023-11-28 21:40:12 +00:00
|
|
|
base::MakeFixedFlatMap<base::StringPiece, Val>({
|
2023-06-22 12:33:44 +00:00
|
|
|
{"bypassHeatCheck", Val::kCodeWithoutHeatCheck},
|
|
|
|
{"bypassHeatCheckAndEagerCompile", Val::kFullCodeWithoutHeatCheck},
|
|
|
|
{"code", Val::kCode},
|
|
|
|
{"none", Val::kNone},
|
|
|
|
});
|
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2021-06-08 02:00:22 +00:00
|
|
|
}
|
2021-07-26 16:04:09 +00:00
|
|
|
};
|
2021-06-08 02:00:22 +00:00
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
} // namespace gin
|
2018-08-03 21:23:07 +00:00
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
namespace {
|
|
|
|
std::vector<WebContentsPreferences*>& Instances() {
|
|
|
|
static base::NoDestructor<std::vector<WebContentsPreferences*>> g_instances;
|
|
|
|
return *g_instances;
|
|
|
|
}
|
|
|
|
} // namespace
|
2016-03-09 12:34:51 +00:00
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
WebContentsPreferences::WebContentsPreferences(
|
|
|
|
content::WebContents* web_contents,
|
2019-10-25 13:03:28 +00:00
|
|
|
const gin_helper::Dictionary& web_preferences)
|
2022-01-10 22:31:39 +00:00
|
|
|
: content::WebContentsUserData<WebContentsPreferences>(*web_contents),
|
|
|
|
web_contents_(web_contents) {
|
2017-08-07 20:30:03 +00:00
|
|
|
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
|
2021-07-26 16:04:09 +00:00
|
|
|
Instances().push_back(this);
|
|
|
|
SetFromDictionary(web_preferences);
|
2018-03-08 07:05:12 +00:00
|
|
|
|
2019-04-19 19:55:20 +00:00
|
|
|
// If this is a <webview> tag, and the embedder is offscreen-rendered, then
|
|
|
|
// this WebContents is also offscreen-rendered.
|
2021-07-28 22:32:53 +00:00
|
|
|
if (auto* api_web_contents = api::WebContents::From(web_contents_)) {
|
|
|
|
if (electron::api::WebContents* embedder = api_web_contents->embedder()) {
|
|
|
|
auto* embedder_preferences =
|
|
|
|
WebContentsPreferences::From(embedder->web_contents());
|
|
|
|
if (embedder_preferences && embedder_preferences->IsOffscreen()) {
|
|
|
|
offscreen_ = true;
|
2019-04-19 19:55:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-04 16:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WebContentsPreferences::~WebContentsPreferences() {
|
2021-07-26 16:04:09 +00:00
|
|
|
Instances().erase(std::remove(Instances().begin(), Instances().end(), this),
|
|
|
|
Instances().end());
|
2015-09-04 16:44:22 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
void WebContentsPreferences::Clear() {
|
|
|
|
plugins_ = false;
|
|
|
|
experimental_features_ = false;
|
|
|
|
node_integration_ = false;
|
|
|
|
node_integration_in_sub_frames_ = false;
|
|
|
|
node_integration_in_worker_ = false;
|
|
|
|
disable_html_fullscreen_window_resize_ = false;
|
|
|
|
webview_tag_ = false;
|
2024-01-10 22:23:35 +00:00
|
|
|
sandbox_ = std::nullopt;
|
2021-07-26 16:04:09 +00:00
|
|
|
context_isolation_ = true;
|
|
|
|
javascript_ = true;
|
|
|
|
images_ = true;
|
|
|
|
text_areas_are_resizable_ = true;
|
|
|
|
webgl_ = true;
|
|
|
|
enable_websql_ = true;
|
|
|
|
enable_preferred_size_mode_ = false;
|
|
|
|
web_security_ = true;
|
|
|
|
allow_running_insecure_content_ = false;
|
|
|
|
offscreen_ = false;
|
|
|
|
navigate_on_drag_drop_ = false;
|
|
|
|
autoplay_policy_ = blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
|
|
|
|
default_font_family_.clear();
|
2024-01-10 22:23:35 +00:00
|
|
|
default_font_size_ = std::nullopt;
|
|
|
|
default_monospace_font_size_ = std::nullopt;
|
|
|
|
minimum_font_size_ = std::nullopt;
|
|
|
|
default_encoding_ = std::nullopt;
|
2021-07-28 22:32:53 +00:00
|
|
|
is_webview_ = false;
|
2021-07-26 16:04:09 +00:00
|
|
|
custom_args_.clear();
|
|
|
|
custom_switches_.clear();
|
2024-01-10 22:23:35 +00:00
|
|
|
enable_blink_features_ = std::nullopt;
|
|
|
|
disable_blink_features_ = std::nullopt;
|
2021-07-26 16:04:09 +00:00
|
|
|
disable_popups_ = false;
|
|
|
|
disable_dialogs_ = false;
|
|
|
|
safe_dialogs_ = false;
|
2024-01-10 22:23:35 +00:00
|
|
|
safe_dialogs_message_ = std::nullopt;
|
2021-07-26 16:04:09 +00:00
|
|
|
ignore_menu_shortcuts_ = false;
|
2024-01-10 22:23:35 +00:00
|
|
|
background_color_ = std::nullopt;
|
2021-07-26 16:04:09 +00:00
|
|
|
image_animation_policy_ =
|
|
|
|
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
|
2024-01-10 22:23:35 +00:00
|
|
|
preload_path_ = std::nullopt;
|
2021-07-26 16:04:09 +00:00
|
|
|
v8_cache_options_ = blink::mojom::V8CacheOptions::kDefault;
|
2019-05-27 00:44:54 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2021-07-26 16:04:09 +00:00
|
|
|
scroll_bounce_ = false;
|
|
|
|
#endif
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
spellcheck_ = true;
|
|
|
|
#endif
|
2018-08-03 21:23:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
void WebContentsPreferences::SetFromDictionary(
|
|
|
|
const gin_helper::Dictionary& web_preferences) {
|
|
|
|
Clear();
|
2018-08-03 21:23:07 +00:00
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
web_preferences.Get(options::kPlugins, &plugins_);
|
|
|
|
web_preferences.Get(options::kExperimentalFeatures, &experimental_features_);
|
|
|
|
web_preferences.Get(options::kNodeIntegration, &node_integration_);
|
|
|
|
web_preferences.Get(options::kNodeIntegrationInSubFrames,
|
|
|
|
&node_integration_in_sub_frames_);
|
|
|
|
web_preferences.Get(options::kNodeIntegrationInWorker,
|
|
|
|
&node_integration_in_worker_);
|
|
|
|
web_preferences.Get(options::kDisableHtmlFullscreenWindowResize,
|
|
|
|
&disable_html_fullscreen_window_resize_);
|
|
|
|
web_preferences.Get(options::kWebviewTag, &webview_tag_);
|
2021-08-03 22:07:03 +00:00
|
|
|
bool sandbox;
|
|
|
|
if (web_preferences.Get(options::kSandbox, &sandbox))
|
|
|
|
sandbox_ = sandbox;
|
2021-07-26 16:04:09 +00:00
|
|
|
web_preferences.Get(options::kContextIsolation, &context_isolation_);
|
|
|
|
web_preferences.Get(options::kJavaScript, &javascript_);
|
|
|
|
web_preferences.Get(options::kImages, &images_);
|
|
|
|
web_preferences.Get(options::kTextAreasAreResizable,
|
|
|
|
&text_areas_are_resizable_);
|
|
|
|
web_preferences.Get(options::kWebGL, &webgl_);
|
|
|
|
web_preferences.Get(options::kEnableWebSQL, &enable_websql_);
|
|
|
|
web_preferences.Get(options::kEnablePreferredSizeMode,
|
|
|
|
&enable_preferred_size_mode_);
|
|
|
|
web_preferences.Get(options::kWebSecurity, &web_security_);
|
|
|
|
if (!web_preferences.Get(options::kAllowRunningInsecureContent,
|
|
|
|
&allow_running_insecure_content_) &&
|
|
|
|
!web_security_)
|
|
|
|
allow_running_insecure_content_ = true;
|
|
|
|
web_preferences.Get(options::kOffscreen, &offscreen_);
|
|
|
|
web_preferences.Get(options::kNavigateOnDragDrop, &navigate_on_drag_drop_);
|
|
|
|
web_preferences.Get("autoplayPolicy", &autoplay_policy_);
|
|
|
|
web_preferences.Get("defaultFontFamily", &default_font_family_);
|
|
|
|
int size;
|
|
|
|
if (web_preferences.Get("defaultFontSize", &size))
|
|
|
|
default_font_size_ = size;
|
|
|
|
if (web_preferences.Get("defaultMonospaceFontSize", &size))
|
|
|
|
default_monospace_font_size_ = size;
|
|
|
|
if (web_preferences.Get("minimumFontSize", &size))
|
|
|
|
minimum_font_size_ = size;
|
|
|
|
std::string encoding;
|
|
|
|
if (web_preferences.Get("defaultEncoding", &encoding))
|
|
|
|
default_encoding_ = encoding;
|
|
|
|
web_preferences.Get(options::kCustomArgs, &custom_args_);
|
|
|
|
web_preferences.Get("commandLineSwitches", &custom_switches_);
|
|
|
|
web_preferences.Get("disablePopups", &disable_popups_);
|
|
|
|
web_preferences.Get("disableDialogs", &disable_dialogs_);
|
|
|
|
web_preferences.Get("safeDialogs", &safe_dialogs_);
|
2021-11-03 18:16:18 +00:00
|
|
|
// preferences don't save a transparency option,
|
|
|
|
// apply any existing transparency setting to background_color_
|
|
|
|
bool transparent;
|
2023-05-02 21:44:34 +00:00
|
|
|
if (web_preferences.Get(options::kTransparent, &transparent) && transparent) {
|
2021-11-03 18:16:18 +00:00
|
|
|
background_color_ = SK_ColorTRANSPARENT;
|
|
|
|
}
|
2021-09-06 07:59:09 +00:00
|
|
|
std::string background_color;
|
|
|
|
if (web_preferences.GetHidden(options::kBackgroundColor, &background_color))
|
2022-03-21 17:35:54 +00:00
|
|
|
background_color_ = ParseCSSColor(background_color);
|
2021-07-26 16:04:09 +00:00
|
|
|
std::string safe_dialogs_message;
|
|
|
|
if (web_preferences.Get("safeDialogsMessage", &safe_dialogs_message))
|
|
|
|
safe_dialogs_message_ = safe_dialogs_message;
|
|
|
|
web_preferences.Get("ignoreMenuShortcuts", &ignore_menu_shortcuts_);
|
|
|
|
std::string enable_blink_features;
|
|
|
|
if (web_preferences.Get(options::kEnableBlinkFeatures,
|
|
|
|
&enable_blink_features))
|
|
|
|
enable_blink_features_ = enable_blink_features;
|
|
|
|
std::string disable_blink_features;
|
|
|
|
if (web_preferences.Get(options::kDisableBlinkFeatures,
|
|
|
|
&disable_blink_features))
|
|
|
|
disable_blink_features_ = disable_blink_features;
|
2015-09-05 02:43:30 +00:00
|
|
|
|
2020-11-10 17:06:03 +00:00
|
|
|
base::FilePath::StringType preload_path;
|
2021-07-26 16:04:09 +00:00
|
|
|
if (web_preferences.Get(options::kPreloadScript, &preload_path)) {
|
2021-03-22 17:35:11 +00:00
|
|
|
base::FilePath preload(preload_path);
|
2020-11-10 17:06:03 +00:00
|
|
|
if (preload.IsAbsolute()) {
|
2021-07-26 16:04:09 +00:00
|
|
|
preload_path_ = preload;
|
2018-08-10 22:19:49 +00:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "preload script must have absolute path.";
|
|
|
|
}
|
|
|
|
}
|
2021-07-26 16:04:09 +00:00
|
|
|
|
2021-07-28 22:32:53 +00:00
|
|
|
std::string type;
|
|
|
|
if (web_preferences.Get(options::kType, &type)) {
|
|
|
|
is_webview_ = type == "webview";
|
|
|
|
}
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
web_preferences.Get("v8CacheOptions", &v8_cache_options_);
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2021-07-26 16:04:09 +00:00
|
|
|
web_preferences.Get(options::kScrollBounce, &scroll_bounce_);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
web_preferences.Get(options::kSpellcheck, &spellcheck_);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SaveLastPreferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebContentsPreferences::GetSafeDialogsMessage(std::string* message) const {
|
|
|
|
if (safe_dialogs_message_) {
|
|
|
|
*message = *safe_dialogs_message_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebContentsPreferences::SetImageAnimationPolicy(std::string policy) {
|
|
|
|
if (policy == "animate") {
|
|
|
|
image_animation_policy_ =
|
|
|
|
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
|
|
|
|
return true;
|
|
|
|
} else if (policy == "animateOnce") {
|
|
|
|
image_animation_policy_ =
|
|
|
|
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
|
|
|
|
return true;
|
|
|
|
} else if (policy == "noAnimation") {
|
|
|
|
image_animation_policy_ =
|
|
|
|
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebContentsPreferences::GetPreloadPath(base::FilePath* path) const {
|
|
|
|
DCHECK(path);
|
|
|
|
if (preload_path_) {
|
|
|
|
*path = *preload_path_;
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-10 22:19:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-03 22:07:03 +00:00
|
|
|
bool WebContentsPreferences::IsSandboxed() const {
|
|
|
|
if (sandbox_)
|
|
|
|
return *sandbox_;
|
|
|
|
bool sandbox_disabled_by_default =
|
2022-07-11 23:28:09 +00:00
|
|
|
node_integration_ || node_integration_in_worker_;
|
2021-08-03 22:07:03 +00:00
|
|
|
return !sandbox_disabled_by_default;
|
|
|
|
}
|
|
|
|
|
2016-03-09 12:34:51 +00:00
|
|
|
// static
|
|
|
|
content::WebContents* WebContentsPreferences::GetWebContentsFromProcessID(
|
|
|
|
int process_id) {
|
2021-07-26 16:04:09 +00:00
|
|
|
for (WebContentsPreferences* preferences : Instances()) {
|
2016-03-09 12:34:51 +00:00
|
|
|
content::WebContents* web_contents = preferences->web_contents_;
|
2022-06-27 20:50:08 +00:00
|
|
|
if (web_contents->GetPrimaryMainFrame()->GetProcess()->GetID() ==
|
|
|
|
process_id)
|
2016-03-09 12:34:51 +00:00
|
|
|
return web_contents;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-08 07:12:45 +00:00
|
|
|
// static
|
|
|
|
WebContentsPreferences* WebContentsPreferences::From(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
if (!web_contents)
|
|
|
|
return nullptr;
|
|
|
|
return FromWebContents(web_contents);
|
|
|
|
}
|
|
|
|
|
2018-03-08 08:01:54 +00:00
|
|
|
void WebContentsPreferences::AppendCommandLineSwitches(
|
2019-06-20 10:10:56 +00:00
|
|
|
base::CommandLine* command_line,
|
|
|
|
bool is_subframe) {
|
2016-01-07 04:49:00 +00:00
|
|
|
// Experimental flags.
|
2021-07-26 16:04:09 +00:00
|
|
|
if (experimental_features_)
|
2016-01-07 04:49:00 +00:00
|
|
|
command_line->AppendSwitch(
|
|
|
|
::switches::kEnableExperimentalWebPlatformFeatures);
|
2015-09-04 17:33:13 +00:00
|
|
|
|
2019-06-20 10:10:56 +00:00
|
|
|
// Sandbox can be enabled for renderer processes hosting cross-origin frames
|
|
|
|
// unless nodeIntegrationInSubFrames is enabled
|
2021-07-26 16:04:09 +00:00
|
|
|
bool can_sandbox_frame = is_subframe && !node_integration_in_sub_frames_;
|
2019-06-20 10:10:56 +00:00
|
|
|
|
2021-08-03 22:07:03 +00:00
|
|
|
if (IsSandboxed() || can_sandbox_frame) {
|
2016-08-15 10:59:08 +00:00
|
|
|
command_line->AppendSwitch(switches::kEnableSandbox);
|
2018-12-06 01:42:12 +00:00
|
|
|
} else if (!command_line->HasSwitch(switches::kEnableSandbox)) {
|
2020-07-14 01:13:34 +00:00
|
|
|
command_line->AppendSwitch(sandbox::policy::switches::kNoSandbox);
|
2018-12-06 01:42:12 +00:00
|
|
|
command_line->AppendSwitch(::switches::kNoZygote);
|
|
|
|
}
|
2018-08-03 21:23:07 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2016-05-06 05:57:43 +00:00
|
|
|
// Enable scroll bounce.
|
2021-07-26 16:04:09 +00:00
|
|
|
if (scroll_bounce_)
|
2016-05-06 05:57:43 +00:00
|
|
|
command_line->AppendSwitch(switches::kScrollBounce);
|
|
|
|
#endif
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
// Custom args for renderer process
|
|
|
|
for (const auto& arg : custom_args_)
|
|
|
|
if (!arg.empty())
|
|
|
|
command_line->AppendArg(arg);
|
2016-06-07 20:42:42 +00:00
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
// Custom command line switches.
|
|
|
|
for (const auto& arg : custom_switches_)
|
|
|
|
if (!arg.empty())
|
|
|
|
command_line->AppendSwitch(arg);
|
|
|
|
|
|
|
|
if (enable_blink_features_)
|
|
|
|
command_line->AppendSwitchASCII(::switches::kEnableBlinkFeatures,
|
|
|
|
*enable_blink_features_);
|
|
|
|
if (disable_blink_features_)
|
|
|
|
command_line->AppendSwitchASCII(::switches::kDisableBlinkFeatures,
|
|
|
|
*disable_blink_features_);
|
|
|
|
|
|
|
|
if (node_integration_in_worker_)
|
2020-11-10 17:06:03 +00:00
|
|
|
command_line->AppendSwitch(switches::kNodeIntegrationInWorker);
|
2020-05-06 19:52:59 +00:00
|
|
|
|
2018-03-08 08:01:54 +00:00
|
|
|
// We are appending args to a webContents so let's save the current state
|
|
|
|
// of our preferences object so that during the lifetime of the WebContents
|
2022-06-16 07:46:11 +00:00
|
|
|
// we can fetch the options used to initially configure the WebContents
|
2021-07-26 16:04:09 +00:00
|
|
|
// last_preference_ = preference_.Clone();
|
|
|
|
SaveLastPreferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContentsPreferences::SaveLastPreferences() {
|
2023-03-15 13:07:51 +00:00
|
|
|
base::Value::Dict dict;
|
|
|
|
dict.Set(options::kNodeIntegration, node_integration_);
|
|
|
|
dict.Set(options::kNodeIntegrationInSubFrames,
|
|
|
|
node_integration_in_sub_frames_);
|
|
|
|
dict.Set(options::kSandbox, IsSandboxed());
|
|
|
|
dict.Set(options::kContextIsolation, context_isolation_);
|
|
|
|
dict.Set(options::kJavaScript, javascript_);
|
|
|
|
dict.Set(options::kEnableWebSQL, enable_websql_);
|
|
|
|
dict.Set(options::kWebviewTag, webview_tag_);
|
|
|
|
dict.Set("disablePopups", disable_popups_);
|
|
|
|
dict.Set(options::kWebSecurity, web_security_);
|
|
|
|
dict.Set(options::kAllowRunningInsecureContent,
|
|
|
|
allow_running_insecure_content_);
|
|
|
|
dict.Set(options::kExperimentalFeatures, experimental_features_);
|
|
|
|
dict.Set(options::kEnableBlinkFeatures, enable_blink_features_.value_or(""));
|
2023-12-06 01:36:23 +00:00
|
|
|
dict.Set("disableDialogs", disable_dialogs_);
|
|
|
|
dict.Set("safeDialogs", safe_dialogs_);
|
|
|
|
dict.Set("safeDialogsMessage", safe_dialogs_message_.value_or(""));
|
2023-03-15 13:07:51 +00:00
|
|
|
|
|
|
|
last_web_preferences_ = base::Value(std::move(dict));
|
2015-09-04 17:04:09 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 17:12:32 +00:00
|
|
|
void WebContentsPreferences::OverrideWebkitPrefs(
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
blink::web_pref::WebPreferences* prefs,
|
|
|
|
blink::RendererPreferences* renderer_prefs) {
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->javascript_enabled = javascript_;
|
|
|
|
prefs->images_enabled = images_;
|
2021-08-09 16:58:03 +00:00
|
|
|
prefs->animation_policy = image_animation_policy_;
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->text_areas_are_resizable = text_areas_are_resizable_;
|
|
|
|
prefs->autoplay_policy = autoplay_policy_;
|
2018-08-03 21:23:07 +00:00
|
|
|
|
chore: bump chromium to 118.0.5975.0 (main) (#39531)
* chore: bump chromium in DEPS to 118.0.5951.0
* chore: update printing.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4727894
No logic changes, but patch needed to be manually re-applied due to upstream code shear
* chore: update port_autofill_colors_to_the_color_pipeline.patch
No manual changes; patch applied with fuzz
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5953.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5955.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5957.0
* chore: update patches
* chore: include path of native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
* chore: remove reference to eextensions/browser/notification-types.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4771627
* chore: update references to renamed upstream field NativeWebKeyboardEvent.skip_if_unhandled (formerly known as skip_in_browser
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4758689
Need a second pair of eyes on this commit. In particular the reference in content_converter.cc, skipInBrowser, seems to not be set or documented anywhere? Is this unused/vestigal code?
* chore: sync signature of ElectronExtensionsBrowserClient::IsValidContext() to upstream change
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4784198
* chore: add auto_pip_setting_helper.[cc,h] to chromium_src build
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4688277
Exiting upstream code used by chromium_src now depends on this new upstream class
* chore: bump chromium in DEPS to 118.0.5959.0
* chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
Xref: add_maximized_parameter_to_linuxui_getwindowframeprovider.patch
manually adjust patch to minor upstream chagnes
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5961.0
* chore: bump chromium in DEPS to 118.0.5963.0
* chore: update patches
* 4780994: Rename various base files to "apple" since iOS uses them too
https://chromium-review.googlesource.com/c/chromium/src/+/4780994
* Many files moved from `mac` -> `apple`
This commit follows a handful of CLs that simply rename files/symbols to change `mac`
to `apple`
to signify their use across both macOS and iOS:
- 4784010: Move scoped_nsautorelease_pool to base/apple, leave a forwarding header
- 4790744: Move foundation_util to base/apple, leave a forwarding header
- 4790741: Move scoped_cftypreref to base/apple, leave a forwarding header
- 4787627: Move and rename macOS+iOS base/ files in PA to "apple"
- 4780399: Move OSStatus logging to base/apple
- 4787387: Remove forwarding headers
- 4781113: Rename message_pump_mac to "apple" because iOS uses it too
* fixup minor patch update error
A function param got dropped from this patch somewhere earlier
* chore: bump chromium in DEPS to 118.0.5965.2
* chore: update patches
* 4799213: Move ScopedTypeRef and ScopedCFTypeRef into base::apple::
https://chromium-review.googlesource.com/c/chromium/src/+/4799213
* Fix removed include to BrowserContext
In crrev.com/c/4767962 an include to BrowserContext was removed,
which was necessary for compilation. This broke only for us because
"chrome/browser/profiles/profile.h" includes that class, but we remove
all references to profiles.
* chore: bump chromium in DEPS to 118.0.5967.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5969.0
* chore: update patches
* chore: bump chromium in DEPS to 118.0.5971.0
* chore: bump chromium in DEPS to 118.0.5973.0
* chore: update patches
* 4772121: [OOPIF PDF] Replace PDFWebContentsHelper with PDFDocumentHelper
https://chromium-review.googlesource.com/c/chromium/src/+/4772121
* 4811164: [Extensions] Do some cleanup in ChromeManagementAPIDelegate.
https://chromium-review.googlesource.com/c/chromium/src/+/4811164
* 4809488: Remove duplicate dnd functionality between Web and Renderer prefs
https://chromium-review.googlesource.com/c/chromium/src/+/4809488
Given that this is no longer an option of web preferences, we should
consider deprecating this option and then removing it.
* chore: bump chromium in DEPS to 118.0.5975.0
* chore: update patches
* fixup! chore: add auto_pip_settings_helper.{cc|h} to chromium_src build
* Reland "[windows] Remove RegKey::DeleteEmptyKey"
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4813255
* Ensure StrCat means StrCat
Refs https://chromium-review.googlesource.com/c/chromium/src/+/1117180
* fixup! Remove RegKey::DeleteEmptyKey
* Consistently reject large p and large q in DH
Refs https://boringssl-review.googlesource.com/c/boringssl/+/62226
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2023-09-01 06:54:59 +00:00
|
|
|
// TODO: navigate_on_drag_drop was removed from web prefs in favor of the
|
|
|
|
// equivalent option in renderer prefs. this option should be deprecated from
|
|
|
|
// our API and then removed here.
|
|
|
|
renderer_prefs->can_accept_load_drops = navigate_on_drag_drop_;
|
|
|
|
|
2018-08-03 21:23:07 +00:00
|
|
|
// Check if webgl should be enabled.
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->webgl1_enabled = webgl_;
|
|
|
|
prefs->webgl2_enabled = webgl_;
|
2018-08-03 21:23:07 +00:00
|
|
|
|
|
|
|
// Check if web security should be enabled.
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->web_security_enabled = web_security_;
|
|
|
|
prefs->allow_running_insecure_content = allow_running_insecure_content_;
|
|
|
|
|
2023-04-13 09:30:25 +00:00
|
|
|
if (!default_font_family_.empty()) {
|
|
|
|
if (auto iter = default_font_family_.find("standard");
|
|
|
|
iter != default_font_family_.end())
|
|
|
|
prefs->standard_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
iter->second;
|
|
|
|
if (auto iter = default_font_family_.find("serif");
|
|
|
|
iter != default_font_family_.end())
|
2023-04-13 13:54:41 +00:00
|
|
|
prefs->serif_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
iter->second;
|
2023-04-13 09:30:25 +00:00
|
|
|
if (auto iter = default_font_family_.find("sansSerif");
|
|
|
|
iter != default_font_family_.end())
|
|
|
|
prefs->sans_serif_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
iter->second;
|
|
|
|
if (auto iter = default_font_family_.find("monospace");
|
|
|
|
iter != default_font_family_.end())
|
2023-04-13 13:54:41 +00:00
|
|
|
prefs->fixed_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
iter->second;
|
2023-04-13 09:30:25 +00:00
|
|
|
if (auto iter = default_font_family_.find("cursive");
|
|
|
|
iter != default_font_family_.end())
|
|
|
|
prefs->cursive_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
iter->second;
|
|
|
|
if (auto iter = default_font_family_.find("fantasy");
|
|
|
|
iter != default_font_family_.end())
|
|
|
|
prefs->fantasy_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
iter->second;
|
2023-06-06 21:26:32 +00:00
|
|
|
if (auto iter = default_font_family_.find("math");
|
|
|
|
iter != default_font_family_.end())
|
|
|
|
prefs->math_font_family_map[blink::web_pref::kCommonScript] =
|
|
|
|
iter->second;
|
2023-04-13 09:30:25 +00:00
|
|
|
}
|
2021-07-26 16:04:09 +00:00
|
|
|
|
|
|
|
if (default_font_size_)
|
|
|
|
prefs->default_font_size = *default_font_size_;
|
|
|
|
if (default_monospace_font_size_)
|
|
|
|
prefs->default_fixed_font_size = *default_monospace_font_size_;
|
|
|
|
if (minimum_font_size_)
|
|
|
|
prefs->minimum_font_size = *minimum_font_size_;
|
|
|
|
if (default_encoding_)
|
|
|
|
prefs->default_encoding = *default_encoding_;
|
2020-06-01 03:09:23 +00:00
|
|
|
|
2020-11-10 17:06:03 +00:00
|
|
|
// Run Electron APIs and preload script in isolated world
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->context_isolation = context_isolation_;
|
2021-07-28 22:32:53 +00:00
|
|
|
prefs->is_webview = is_webview_;
|
2020-11-10 17:06:03 +00:00
|
|
|
|
|
|
|
prefs->hidden_page = false;
|
2021-07-28 22:32:53 +00:00
|
|
|
// Webview `document.visibilityState` tracks window visibility so we need
|
|
|
|
// to let it know if the window happens to be hidden right now.
|
|
|
|
if (auto* api_web_contents = api::WebContents::From(web_contents_)) {
|
|
|
|
if (electron::api::WebContents* embedder = api_web_contents->embedder()) {
|
|
|
|
if (auto* relay =
|
|
|
|
NativeWindowRelay::FromWebContents(embedder->web_contents())) {
|
|
|
|
if (auto* window = relay->GetNativeWindow()) {
|
|
|
|
const bool visible = window->IsVisible() && !window->IsMinimized();
|
|
|
|
if (!visible) {
|
|
|
|
prefs->hidden_page = true;
|
2020-11-10 17:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->offscreen = offscreen_;
|
2020-11-10 17:06:03 +00:00
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->node_integration = node_integration_;
|
|
|
|
prefs->node_integration_in_worker = node_integration_in_worker_;
|
|
|
|
prefs->node_integration_in_sub_frames = node_integration_in_sub_frames_;
|
2020-11-10 17:06:03 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->enable_spellcheck = spellcheck_;
|
2020-11-10 17:06:03 +00:00
|
|
|
#endif
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->enable_plugins = plugins_;
|
|
|
|
prefs->webview_tag = webview_tag_;
|
|
|
|
prefs->enable_websql = enable_websql_;
|
2020-11-10 17:06:03 +00:00
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->v8_cache_options = v8_cache_options_;
|
2015-09-04 17:12:32 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 18:51:36 +00:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPreferences);
|
2019-01-21 16:56:54 +00:00
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
} // namespace electron
|