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"
|
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"
|
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"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/native_window.h"
|
|
|
|
#include "shell/browser/web_view_manager.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
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#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) {
|
|
|
|
std::string policy_str;
|
|
|
|
if (!ConvertFromV8(isolate, val, &policy_str))
|
|
|
|
return false;
|
2019-01-15 19:30:34 +00:00
|
|
|
if (policy_str == "no-user-gesture-required") {
|
2020-10-16 01:30:41 +00:00
|
|
|
*out = blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
|
2019-01-15 19:30:34 +00:00
|
|
|
return true;
|
|
|
|
} else if (policy_str == "user-gesture-required") {
|
2020-10-16 01:30:41 +00:00
|
|
|
*out = blink::mojom::AutoplayPolicy::kUserGestureRequired;
|
2019-01-15 19:30:34 +00:00
|
|
|
return true;
|
|
|
|
} else if (policy_str == "document-user-activation-required") {
|
2020-10-16 01:30:41 +00:00
|
|
|
*out = blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired;
|
2019-01-15 19:30:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
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) {
|
|
|
|
std::string v8_cache_options;
|
|
|
|
if (!ConvertFromV8(isolate, val, &v8_cache_options))
|
|
|
|
return false;
|
|
|
|
if (v8_cache_options == "none") {
|
|
|
|
*out = blink::mojom::V8CacheOptions::kNone;
|
|
|
|
return true;
|
|
|
|
} else if (v8_cache_options == "code") {
|
|
|
|
*out = blink::mojom::V8CacheOptions::kCode;
|
2021-06-08 02:00:22 +00:00
|
|
|
return true;
|
2021-07-26 16:04:09 +00:00
|
|
|
} else if (v8_cache_options == "bypassHeatCheck") {
|
|
|
|
*out = blink::mojom::V8CacheOptions::kCodeWithoutHeatCheck;
|
2021-06-08 02:00:22 +00:00
|
|
|
return true;
|
2021-07-26 16:04:09 +00:00
|
|
|
} else if (v8_cache_options == "bypassHeatCheckAndEagerCompile") {
|
|
|
|
*out = blink::mojom::V8CacheOptions::kFullCodeWithoutHeatCheck;
|
2021-06-08 02:00:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-07-26 16:04:09 +00:00
|
|
|
return false;
|
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
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-09-04 16:44:22 +00:00
|
|
|
|
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)
|
2016-03-09 12:34:51 +00:00
|
|
|
: 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-26 16:04:09 +00:00
|
|
|
if (guest_instance_id_) {
|
2019-04-19 19:55:20 +00:00
|
|
|
auto* manager = WebViewManager::GetWebViewManager(web_contents);
|
|
|
|
if (manager) {
|
2021-07-26 16:04:09 +00:00
|
|
|
auto* embedder = manager->GetEmbedder(guest_instance_id_);
|
2019-04-19 19:55:20 +00:00
|
|
|
if (embedder) {
|
|
|
|
auto* embedder_preferences = WebContentsPreferences::From(embedder);
|
2021-07-26 16:04:09 +00:00
|
|
|
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;
|
|
|
|
sandbox_ = false;
|
|
|
|
native_window_open_ = true;
|
|
|
|
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();
|
|
|
|
default_font_size_ = absl::nullopt;
|
|
|
|
default_monospace_font_size_ = absl::nullopt;
|
|
|
|
minimum_font_size_ = absl::nullopt;
|
|
|
|
default_encoding_ = absl::nullopt;
|
|
|
|
opener_id_ = 0;
|
|
|
|
guest_instance_id_ = 0;
|
|
|
|
custom_args_.clear();
|
|
|
|
custom_switches_.clear();
|
|
|
|
enable_blink_features_ = absl::nullopt;
|
|
|
|
disable_blink_features_ = absl::nullopt;
|
|
|
|
disable_popups_ = false;
|
|
|
|
disable_dialogs_ = false;
|
|
|
|
safe_dialogs_ = false;
|
|
|
|
safe_dialogs_message_ = absl::nullopt;
|
|
|
|
ignore_menu_shortcuts_ = false;
|
|
|
|
background_color_ = SK_ColorTRANSPARENT;
|
|
|
|
image_animation_policy_ =
|
|
|
|
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
|
|
|
|
preload_path_ = absl::nullopt;
|
|
|
|
v8_cache_options_ = blink::mojom::V8CacheOptions::kDefault;
|
2019-05-27 00:44:54 +00:00
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
#if defined(OS_MAC)
|
|
|
|
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();
|
|
|
|
Merge(web_preferences);
|
2018-08-03 21:23:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
void WebContentsPreferences::Merge(
|
|
|
|
const gin_helper::Dictionary& web_preferences) {
|
|
|
|
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_);
|
|
|
|
web_preferences.Get(options::kSandbox, &sandbox_);
|
|
|
|
web_preferences.Get(options::kNativeWindowOpen, &native_window_open_);
|
|
|
|
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::kOpenerID, &opener_id_);
|
|
|
|
web_preferences.Get(options::kGuestInstanceID, &guest_instance_id_);
|
|
|
|
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_);
|
|
|
|
web_preferences.Get(options::kBackgroundColor, &background_color_);
|
|
|
|
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
|
|
|
std::string preload_url_str;
|
|
|
|
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
|
|
|
} else if (web_preferences.Get(options::kPreloadURL, &preload_url_str)) {
|
2018-08-10 22:19:49 +00:00
|
|
|
// Translate to file path if there is "preload-url" option.
|
2020-11-10 17:06:03 +00:00
|
|
|
base::FilePath preload;
|
2021-07-26 16:04:09 +00:00
|
|
|
GURL preload_url(preload_url_str);
|
2021-03-22 22:49:43 +00:00
|
|
|
if (net::FileURLToFilePath(preload_url, &preload)) {
|
2021-07-26 16:04:09 +00:00
|
|
|
preload_path_ = preload;
|
2018-08-10 22:19:49 +00:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "preload url must be file:// protocol.";
|
|
|
|
}
|
|
|
|
}
|
2021-07-26 16:04:09 +00:00
|
|
|
|
|
|
|
web_preferences.Get("v8CacheOptions", &v8_cache_options_);
|
|
|
|
|
|
|
|
#if defined(OS_MAC)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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_;
|
2017-12-18 02:46:23 +00:00
|
|
|
if (web_contents->GetMainFrame()->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-07-26 16:04:09 +00:00
|
|
|
if (sandbox_ || 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
|
|
|
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_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
|
|
|
|
// we can fetch the options used to initally configure the WebContents
|
2021-07-26 16:04:09 +00:00
|
|
|
// last_preference_ = preference_.Clone();
|
|
|
|
SaveLastPreferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContentsPreferences::SaveLastPreferences() {
|
|
|
|
last_web_preferences_ = base::Value(base::Value::Type::DICTIONARY);
|
|
|
|
last_web_preferences_.SetKey(options::kOpenerID, base::Value(opener_id_));
|
|
|
|
last_web_preferences_.SetKey(options::kNodeIntegration,
|
|
|
|
base::Value(node_integration_));
|
|
|
|
last_web_preferences_.SetKey(options::kNodeIntegrationInSubFrames,
|
|
|
|
base::Value(node_integration_in_sub_frames_));
|
|
|
|
last_web_preferences_.SetKey(options::kNativeWindowOpen,
|
|
|
|
base::Value(native_window_open_));
|
|
|
|
last_web_preferences_.SetKey(options::kSandbox, base::Value(sandbox_));
|
|
|
|
last_web_preferences_.SetKey(options::kContextIsolation,
|
|
|
|
base::Value(context_isolation_));
|
|
|
|
last_web_preferences_.SetKey(options::kJavaScript, base::Value(javascript_));
|
|
|
|
last_web_preferences_.SetKey(options::kEnableWebSQL,
|
|
|
|
base::Value(enable_websql_));
|
|
|
|
last_web_preferences_.SetKey(options::kWebviewTag, base::Value(webview_tag_));
|
|
|
|
last_web_preferences_.SetKey("disablePopups", base::Value(disable_popups_));
|
|
|
|
last_web_preferences_.SetKey(options::kWebSecurity,
|
|
|
|
base::Value(web_security_));
|
|
|
|
last_web_preferences_.SetKey(options::kAllowRunningInsecureContent,
|
|
|
|
base::Value(allow_running_insecure_content_));
|
|
|
|
last_web_preferences_.SetKey(options::kExperimentalFeatures,
|
|
|
|
base::Value(experimental_features_));
|
|
|
|
last_web_preferences_.SetKey(
|
|
|
|
options::kEnableBlinkFeatures,
|
|
|
|
base::Value(enable_blink_features_.value_or("")));
|
2015-09-04 17:04:09 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 17:12:32 +00:00
|
|
|
void WebContentsPreferences::OverrideWebkitPrefs(
|
2020-09-21 08:00:36 +00:00
|
|
|
blink::web_pref::WebPreferences* prefs) {
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->javascript_enabled = javascript_;
|
|
|
|
prefs->images_enabled = images_;
|
|
|
|
// GetImageAnimationPolicy(&preference_, &prefs->animation_policy);
|
|
|
|
prefs->text_areas_are_resizable = text_areas_are_resizable_;
|
|
|
|
prefs->navigate_on_drag_drop = navigate_on_drag_drop_;
|
|
|
|
prefs->autoplay_policy = autoplay_policy_;
|
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_;
|
|
|
|
|
|
|
|
if (auto font =
|
|
|
|
default_font_family_.find("standard") != default_font_family_.end())
|
|
|
|
prefs->standard_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
|
|
if (auto font =
|
|
|
|
default_font_family_.find("serif") != default_font_family_.end())
|
|
|
|
prefs->serif_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
|
|
if (auto font =
|
|
|
|
default_font_family_.find("sansSerif") != default_font_family_.end())
|
|
|
|
prefs->sans_serif_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
|
|
if (auto font =
|
|
|
|
default_font_family_.find("monospace") != default_font_family_.end())
|
|
|
|
prefs->fixed_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
|
|
if (auto font =
|
|
|
|
default_font_family_.find("cursive") != default_font_family_.end())
|
|
|
|
prefs->cursive_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
|
|
if (auto font =
|
|
|
|
default_font_family_.find("fantasy") != default_font_family_.end())
|
|
|
|
prefs->fantasy_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
|
|
|
|
|
|
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
|
|
|
// Pass the opener's window id.
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->opener_id = opener_id_;
|
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_;
|
|
|
|
prefs->guest_instance_id = guest_instance_id_;
|
2020-11-10 17:06:03 +00:00
|
|
|
|
|
|
|
prefs->hidden_page = false;
|
2021-07-26 16:04:09 +00:00
|
|
|
if (guest_instance_id_) {
|
2020-11-10 17:06:03 +00:00
|
|
|
// Webview `document.visibilityState` tracks window visibility so we need
|
|
|
|
// to let it know if the window happens to be hidden right now.
|
|
|
|
auto* manager = WebViewManager::GetWebViewManager(web_contents_);
|
|
|
|
if (manager) {
|
2021-07-26 16:04:09 +00:00
|
|
|
auto* embedder = manager->GetEmbedder(guest_instance_id_);
|
2020-11-10 17:06:03 +00:00
|
|
|
if (embedder) {
|
|
|
|
auto* relay = NativeWindowRelay::FromWebContents(embedder);
|
|
|
|
if (relay) {
|
|
|
|
auto* window = relay->GetNativeWindow();
|
|
|
|
if (window) {
|
|
|
|
const bool visible = window->IsVisible() && !window->IsMinimized();
|
|
|
|
if (!visible) {
|
|
|
|
prefs->hidden_page = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->offscreen = offscreen_;
|
2020-11-10 17:06:03 +00:00
|
|
|
|
|
|
|
// The preload script.
|
2021-07-26 16:04:09 +00:00
|
|
|
if (preload_path_)
|
|
|
|
prefs->preload = *preload_path_;
|
2020-11-10 17:06:03 +00:00
|
|
|
|
2021-07-26 16:04:09 +00:00
|
|
|
prefs->native_window_open = native_window_open_;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-01-21 16:56:54 +00:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPreferences)
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|