mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* chore: bump chromium in DEPS to 90.0.4430.19 * build: add 'use_rts' definition Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2694187 (cherry picked from commitb820b4078d) * chore: bump chromium in DEPS to 91.0.4441.0 * chore: update patches (cherry picked from commit55e50a0879) * chore: media_internal_resources becomes resources Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2699022 (cherry picked from commite715b9c921) * chore: update patches (cherry picked from commitc8148febfa) * refactor: extensions::ViewType moved to mojom Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710351 (cherry picked from commit87df2766ba) * chore: might_have_observers has been removed Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2667839 (cherry picked from commite900271bea) * refactor: CertVerifier is not in the network namespace anymore Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2689805 (cherry picked from commiteccfa516c5) * refactor: ExtensionUserScriptManager is now UserScriptManager Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2657617 (cherry picked from commit2fed02556d) * refactor: content::SiteInstance::GetSiteForURL was removed Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2680274 (cherry picked from commit0d94e0d1d9) * refactor: MenuItemType was moved to mojom Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2071443 (cherry picked from commit1a296e59c2) * refactor: extensions::ViewType was moved to mojom Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710351 (cherry picked from commitdc36e8e6fc) * refacotr: grit::ResourceMap replaced with webui::ResourcePath Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2685601 (cherry picked from commit59669e99cb) * refactor: blink::MenuItem::Type was moved to mojom Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2071443 (cherry picked from commitbe627568b2) * refactor: CreateDataPipe deprecated form was removed Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2698090 (cherry picked from commit77ad17b383) * refactor: DesktopMediaList::Type replaces content::DesktopMediaType_* Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2700637 (cherry picked from commit4e02d9407a) * chore: wire up activation_time in OSR Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2638372 (cherry picked from commitf51f427646) * chore: remove deleted file from chromium_src list (cherry picked from commit59432fe30a) * chore: fix lint (cherry picked from commit54cc68dd7a) * update patches (cherry picked from commite99e6a5a8a) * chore: update patches (cherry picked from commit1e16606524) * fixup gn check (cherry picked from commit8f4e362d8f) * update to xcode 12.4.0 Needed because of8008deb41c(cherry picked from commitfae4d87a5a) * 2752406: [LSC] Replace base::string16 with std::u16string in //ui https://chromium-review.googlesource.com/c/chromium/src/+/2752406 (cherry picked from commitd4bec23bde) * 2752406: [LSC] Replace base::string16 with std::u16string in //ui https://chromium-review.googlesource.com/c/chromium/src/+/2752406 (cherry picked from commit9e336f5d0c) * 2752932: Associate each AwProxyingURLLoaderFactory with a frame tree node id. https://chromium-review.googlesource.com/c/chromium/src/+/2752932 (cherry picked from commit08036802cb) * 2651385: Moving Profile::shared_cors_origin_access_list_ into //content layer. https://chromium-review.googlesource.com/c/chromium/src/+/2651385 (cherry picked from commit676f74f3dc) * 2734095: Introduce StoragePartitionId type to wrap current string representation. https://chromium-review.googlesource.com/c/chromium/src/+/2734095 (cherry picked from commit76538d2d38) * chore: bump chromium in DEPS to 90.0.4430.19 * chore: bump chromium in DEPS to 90.0.4430.30 * chore: bump chromium in DEPS to 90.0.4430.40 * chore: bump chromium in DEPS to 90.0.4430.51 * chore: bump chromium in DEPS to 91.0.4446.0 * chore: bump chromium in DEPS to 91.0.4448.0 (cherry picked from commit003dd6c16c) * Update patches (cherry picked from commit9f5e3f6685) * 2743594: Remove WebSize from blink. https://chromium-review.googlesource.com/c/chromium/src/+/2743594 (cherry picked from commitb15b820bca) * 2725403: Add URLLoaderClient::OnReceiveEarlyHints() https://chromium-review.googlesource.com/c/chromium/src/+/2725403 (cherry picked from commit185c343b22) * 2651385: Moving Profile::shared_cors_origin_access_list_ into //content layer. https://chromium-review.googlesource.com/c/chromium/src/+/2651385 (cherry picked from commit88bbe2a352) * 2721718: Move HostID to extensions::mojom::HostID https://chromium-review.googlesource.com/c/chromium/src/+/2721718 (cherry picked from commit3010dd93e3) * 2733070: Rename observer to URLLoaderNetworkServiceObserver https://chromium-review.googlesource.com/c/chromium/src/+/2733070 (cherry picked from commitd54bee03d0) * Use nogncheck for content/browser/site_instance_impl.h This is needed because //content/browser:browser is not a visible target (cherry picked from commit5fc298ee5f) * 2648046: Introduce alert notification helper .app https://chromium-review.googlesource.com/c/chromium/src/+/2648046 (cherry picked from commit2cd53eb46a) * 2752406: [LSC] Replace base::string16 with std::u16string in //ui https://chromium-review.googlesource.com/c/chromium/src/+/2752406 (cherry picked from commitf1bb6be4b9) * only include mac notifications on mac (cherry picked from commit3160e608e2) * add additional skipping of atk toolchain check (cherry picked from commit86d23cee40) * 2757472: Reland "Reland "[LSC] Remove base::string16 alias"" https://chromium-review.googlesource.com/c/chromium/src/+/2757472 (cherry picked from commit22d8f22cfb) * 2757472: Reland "Reland "[LSC] Remove base::string16 alias"" https://chromium-review.googlesource.com/c/chromium/src/+/2757472 (cherry picked from commitec893f8322) * 2720306: [api] Remove deprecated [Shared]ArrayBuffer API https://chromium-review.googlesource.com/c/v8/v8/+/2720306 (cherry picked from commitd0989802bd) * Fixup 2721718: Move HostID to extensions::mojom::HostID (cherry picked from commit29dfabadfd) * fixup 2651385: Moving Profile::shared_cors_origin_access_list_ into //content layer (cherry picked from commit97b6868e9c) * Fixup 2752406: [LSC] Replace base::string16 with std::u16string in //ui (cherry picked from commitb6d2ae0455) * Fixup 2725403: Add URLLoaderClient::OnReceiveEarlyHints() (cherry picked from commit7e961d8a37) * update node headers (cherry picked from commitc49bc282d5) * 2693008: Fix loading non-system cursors on Windows on browser_tests https://chromium-review.googlesource.com/c/chromium/src/+/2693008 (cherry picked from commit3b183854ff) * 2757472: Reland "Reland "[LSC] Remove base::string16 alias"" https://chromium-review.googlesource.com/c/chromium/src/+/2757472 (cherry picked from commit2d3c65beca) * undo changes to WebContentsPreferences::GetPreloadPath to fix mac build (cherry picked from commitdeeb2de14b) * fix StrCat issue (cherry picked from commit451e0931bf) * incantations for WebContentsPreferences::GetPreloadPath wide strings (cherry picked from commit205f572181) * bump nan (cherry picked from commit74318705c2) * fix GetAsString maybe? (cherry picked from commitea62ecd188) * windows build fixes (cherry picked from commit5b598037bb) * more windows build fix (cherry picked from commit61cf1abd4d) * SetAppUserModelID -> wstring (cherry picked from commit83d93bcbdc) * upgrade nan dep in tests (cherry picked from commit4f97b9303c) * update patch * wstrings are cross-platform (cherry picked from commit7f7b1f6c8a) * linter (cherry picked from commitaaf03765ed) * only bind setAppUserModelId on windows (cherry picked from commit640a145112) * well that was an odyssey (cherry picked from commitdd975328a0) * backport fcdf35e from v8 to fix nan crash (cherry picked from commit606fd87d1e) * disable typedarrays-test.js (cherry picked from commit01ca00ec82) * don't defer in NSWindow creation https://chromium-review.googlesource.com/c/chromium/src/+/2707696 (cherry picked from commit3122820e58) * use PartitionAllocator for ArrayBuffers in the main process (cherry picked from commit1f575ca3af) * fix patches (cherry picked from commit54e72fa8e3) * chore: omit some unnecessary conversions (cherry picked from commit0f3620099a) * refactor: make LoginItemSettings::path a wstring (cherry picked from commit9127cff58b) * refactor: make ShowTaskDialog take a wstr (cherry picked from commit1594c54933) * Revert "refactor: make LoginItemSettings::path a wstring" This reverts commit9127cff58b. (cherry picked from commit9684d85101) * fixup patches This reverts commit0cc08813a6. * update patches after merge Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Charles Kerr <charles@charleskerr.com>
532 lines
18 KiB
C++
532 lines
18 KiB
C++
// Copyright (c) 2015 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/web_contents_preferences.h"
|
|
|
|
#include <algorithm>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "base/command_line.h"
|
|
#include "base/memory/ptr_util.h"
|
|
#include "base/strings/string_number_conversions.h"
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "cc/base/switches.h"
|
|
#include "content/public/browser/render_frame_host.h"
|
|
#include "content/public/browser/render_process_host.h"
|
|
#include "content/public/common/content_switches.h"
|
|
#include "electron/buildflags/buildflags.h"
|
|
#include "net/base/filename_util.h"
|
|
#include "sandbox/policy/switches.h"
|
|
#include "shell/browser/native_window.h"
|
|
#include "shell/browser/web_view_manager.h"
|
|
#include "shell/common/gin_converters/value_converter.h"
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
#include "shell/common/options_switches.h"
|
|
#include "shell/common/process_util.h"
|
|
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
|
|
#include "third_party/blink/public/mojom/v8_cache_options.mojom.h"
|
|
|
|
#if defined(OS_WIN)
|
|
#include "ui/gfx/switches.h"
|
|
#endif
|
|
|
|
namespace {
|
|
|
|
bool GetAsString(const base::Value* val,
|
|
base::StringPiece path,
|
|
std::string* out) {
|
|
if (val) {
|
|
auto* found = val->FindKeyOfType(path, base::Value::Type::STRING);
|
|
if (found) {
|
|
*out = found->GetString();
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool GetAsString(const base::Value* val,
|
|
base::StringPiece path,
|
|
std::u16string* out) {
|
|
if (val) {
|
|
auto* found = val->FindKeyOfType(path, base::Value::Type::STRING);
|
|
if (found) {
|
|
*out = base::UTF8ToUTF16(found->GetString());
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
#if defined(OS_WIN)
|
|
bool GetAsString(const base::Value* val,
|
|
base::StringPiece path,
|
|
std::wstring* out) {
|
|
if (val) {
|
|
auto* found = val->FindKeyOfType(path, base::Value::Type::STRING);
|
|
if (found) {
|
|
*out = base::UTF8ToWide(found->GetString());
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
bool GetAsInteger(const base::Value* val, base::StringPiece path, int* out) {
|
|
if (val) {
|
|
auto* found = val->FindKey(path);
|
|
if (found && found->is_int()) {
|
|
*out = found->GetInt();
|
|
return true;
|
|
} else if (found && found->is_string()) {
|
|
return base::StringToInt(found->GetString(), out);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool GetAsAutoplayPolicy(const base::Value* val,
|
|
base::StringPiece path,
|
|
blink::mojom::AutoplayPolicy* out) {
|
|
std::string policy_str;
|
|
if (GetAsString(val, path, &policy_str)) {
|
|
if (policy_str == "no-user-gesture-required") {
|
|
*out = blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
|
|
return true;
|
|
} else if (policy_str == "user-gesture-required") {
|
|
*out = blink::mojom::AutoplayPolicy::kUserGestureRequired;
|
|
return true;
|
|
} else if (policy_str == "document-user-activation-required") {
|
|
*out = blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace electron {
|
|
|
|
// static
|
|
std::vector<WebContentsPreferences*> WebContentsPreferences::instances_;
|
|
|
|
WebContentsPreferences::WebContentsPreferences(
|
|
content::WebContents* web_contents,
|
|
const gin_helper::Dictionary& web_preferences)
|
|
: web_contents_(web_contents) {
|
|
v8::Isolate* isolate = web_preferences.isolate();
|
|
gin_helper::Dictionary copied(isolate, web_preferences.GetHandle()->Clone());
|
|
// Following fields should not be stored.
|
|
copied.Delete("embedder");
|
|
copied.Delete("session");
|
|
copied.Delete("type");
|
|
|
|
gin::ConvertFromV8(isolate, copied.GetHandle(), &preference_);
|
|
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
|
|
|
|
instances_.push_back(this);
|
|
|
|
// Set WebPreferences defaults onto the JS object
|
|
SetDefaultBoolIfUndefined(options::kPlugins, false);
|
|
SetDefaultBoolIfUndefined(options::kExperimentalFeatures, false);
|
|
SetDefaultBoolIfUndefined(options::kNodeIntegration, false);
|
|
SetDefaultBoolIfUndefined(options::kNodeIntegrationInSubFrames, false);
|
|
SetDefaultBoolIfUndefined(options::kNodeIntegrationInWorker, false);
|
|
SetDefaultBoolIfUndefined(options::kDisableHtmlFullscreenWindowResize, false);
|
|
SetDefaultBoolIfUndefined(options::kWebviewTag, false);
|
|
SetDefaultBoolIfUndefined(options::kSandbox, false);
|
|
SetDefaultBoolIfUndefined(options::kNativeWindowOpen, false);
|
|
SetDefaultBoolIfUndefined(options::kContextIsolation, true);
|
|
SetDefaultBoolIfUndefined(options::kWorldSafeExecuteJavaScript, true);
|
|
SetDefaultBoolIfUndefined(options::kJavaScript, true);
|
|
SetDefaultBoolIfUndefined(options::kImages, true);
|
|
SetDefaultBoolIfUndefined(options::kTextAreasAreResizable, true);
|
|
SetDefaultBoolIfUndefined(options::kWebGL, true);
|
|
SetDefaultBoolIfUndefined(options::kEnableWebSQL, true);
|
|
SetDefaultBoolIfUndefined(options::kEnablePreferredSizeMode, false);
|
|
bool webSecurity = true;
|
|
SetDefaultBoolIfUndefined(options::kWebSecurity, webSecurity);
|
|
// If webSecurity was explicitly set to false, let's inherit that into
|
|
// insecureContent
|
|
if (web_preferences.Get(options::kWebSecurity, &webSecurity) &&
|
|
!webSecurity) {
|
|
SetDefaultBoolIfUndefined(options::kAllowRunningInsecureContent, true);
|
|
} else {
|
|
SetDefaultBoolIfUndefined(options::kAllowRunningInsecureContent, false);
|
|
}
|
|
#if defined(OS_MAC)
|
|
SetDefaultBoolIfUndefined(options::kScrollBounce, false);
|
|
#endif
|
|
SetDefaultBoolIfUndefined(options::kOffscreen, false);
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
SetDefaultBoolIfUndefined(options::kSpellcheck, true);
|
|
#endif
|
|
|
|
// If this is a <webview> tag, and the embedder is offscreen-rendered, then
|
|
// this WebContents is also offscreen-rendered.
|
|
int guest_instance_id = 0;
|
|
if (web_preferences.Get(options::kGuestInstanceID, &guest_instance_id)) {
|
|
auto* manager = WebViewManager::GetWebViewManager(web_contents);
|
|
if (manager) {
|
|
auto* embedder = manager->GetEmbedder(guest_instance_id);
|
|
if (embedder) {
|
|
auto* embedder_preferences = WebContentsPreferences::From(embedder);
|
|
if (embedder_preferences &&
|
|
embedder_preferences->IsEnabled(options::kOffscreen)) {
|
|
preference_.SetKey(options::kOffscreen, base::Value(true));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
SetDefaults();
|
|
}
|
|
|
|
WebContentsPreferences::~WebContentsPreferences() {
|
|
instances_.erase(std::remove(instances_.begin(), instances_.end(), this),
|
|
instances_.end());
|
|
}
|
|
|
|
void WebContentsPreferences::SetDefaults() {
|
|
if (IsEnabled(options::kSandbox)) {
|
|
SetBool(options::kNativeWindowOpen, true);
|
|
}
|
|
|
|
last_preference_ = preference_.Clone();
|
|
}
|
|
|
|
bool WebContentsPreferences::IsUndefined(base::StringPiece key) {
|
|
return !preference_.FindKeyOfType(key, base::Value::Type::BOOLEAN);
|
|
}
|
|
|
|
bool WebContentsPreferences::SetDefaultBoolIfUndefined(base::StringPiece key,
|
|
bool val) {
|
|
auto* current_value =
|
|
preference_.FindKeyOfType(key, base::Value::Type::BOOLEAN);
|
|
if (current_value) {
|
|
return current_value->GetBool();
|
|
} else {
|
|
preference_.SetKey(key, base::Value(val));
|
|
return val;
|
|
}
|
|
}
|
|
|
|
void WebContentsPreferences::SetBool(base::StringPiece key, bool value) {
|
|
preference_.SetKey(key, base::Value(value));
|
|
}
|
|
|
|
bool WebContentsPreferences::IsEnabled(base::StringPiece name,
|
|
bool default_value) const {
|
|
auto* current_value =
|
|
preference_.FindKeyOfType(name, base::Value::Type::BOOLEAN);
|
|
if (current_value)
|
|
return current_value->GetBool();
|
|
return default_value;
|
|
}
|
|
|
|
void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
|
|
if (preference_.is_dict())
|
|
static_cast<base::DictionaryValue*>(&preference_)->MergeDictionary(&extend);
|
|
|
|
SetDefaults();
|
|
}
|
|
|
|
void WebContentsPreferences::Clear() {
|
|
if (preference_.is_dict())
|
|
static_cast<base::DictionaryValue*>(&preference_)->Clear();
|
|
}
|
|
|
|
bool WebContentsPreferences::GetPreference(base::StringPiece name,
|
|
std::string* value) const {
|
|
return GetAsString(&preference_, name, value);
|
|
}
|
|
|
|
bool WebContentsPreferences::GetPreloadPath(base::FilePath* path) const {
|
|
DCHECK(path);
|
|
base::FilePath::StringType preload_path;
|
|
if (GetAsString(&preference_, options::kPreloadScript, &preload_path)) {
|
|
base::FilePath preload(preload_path);
|
|
if (preload.IsAbsolute()) {
|
|
*path = std::move(preload);
|
|
return true;
|
|
} else {
|
|
LOG(ERROR) << "preload script must have absolute path.";
|
|
}
|
|
} else if (GetAsString(&preference_, options::kPreloadURL, &preload_path)) {
|
|
// Translate to file path if there is "preload-url" option.
|
|
base::FilePath preload;
|
|
GURL preload_url;
|
|
#if defined(OS_WIN)
|
|
preload_url = GURL(base::WideToUTF8(preload_path));
|
|
#else
|
|
preload_url = GURL(preload_path);
|
|
#endif
|
|
if (net::FileURLToFilePath(preload_url, &preload)) {
|
|
*path = std::move(preload);
|
|
return true;
|
|
} else {
|
|
LOG(ERROR) << "preload url must be file:// protocol.";
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// static
|
|
content::WebContents* WebContentsPreferences::GetWebContentsFromProcessID(
|
|
int process_id) {
|
|
for (WebContentsPreferences* preferences : instances_) {
|
|
content::WebContents* web_contents = preferences->web_contents_;
|
|
if (web_contents->GetMainFrame()->GetProcess()->GetID() == process_id)
|
|
return web_contents;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
// static
|
|
WebContentsPreferences* WebContentsPreferences::From(
|
|
content::WebContents* web_contents) {
|
|
if (!web_contents)
|
|
return nullptr;
|
|
return FromWebContents(web_contents);
|
|
}
|
|
|
|
void WebContentsPreferences::AppendCommandLineSwitches(
|
|
base::CommandLine* command_line,
|
|
bool is_subframe) {
|
|
// Experimental flags.
|
|
if (IsEnabled(options::kExperimentalFeatures))
|
|
command_line->AppendSwitch(
|
|
::switches::kEnableExperimentalWebPlatformFeatures);
|
|
|
|
// Sandbox can be enabled for renderer processes hosting cross-origin frames
|
|
// unless nodeIntegrationInSubFrames is enabled
|
|
bool can_sandbox_frame =
|
|
is_subframe && !IsEnabled(options::kNodeIntegrationInSubFrames);
|
|
|
|
if (IsEnabled(options::kSandbox) || can_sandbox_frame) {
|
|
command_line->AppendSwitch(switches::kEnableSandbox);
|
|
} else if (!command_line->HasSwitch(switches::kEnableSandbox)) {
|
|
command_line->AppendSwitch(sandbox::policy::switches::kNoSandbox);
|
|
command_line->AppendSwitch(::switches::kNoZygote);
|
|
}
|
|
|
|
// Custom args for renderer process
|
|
auto* customArgs =
|
|
preference_.FindKeyOfType(options::kCustomArgs, base::Value::Type::LIST);
|
|
if (customArgs) {
|
|
for (const auto& customArg : customArgs->GetList()) {
|
|
if (customArg.is_string())
|
|
command_line->AppendArg(customArg.GetString());
|
|
}
|
|
}
|
|
|
|
// --offscreen
|
|
// TODO(loc): Offscreen is duplicated in WebPreferences because it's needed
|
|
// earlier than we can get WebPreferences at the moment.
|
|
if (IsEnabled(options::kOffscreen)) {
|
|
command_line->AppendSwitch(options::kOffscreen);
|
|
}
|
|
|
|
#if defined(OS_MAC)
|
|
// Enable scroll bounce.
|
|
if (IsEnabled(options::kScrollBounce))
|
|
command_line->AppendSwitch(switches::kScrollBounce);
|
|
#endif
|
|
|
|
// Custom command line switches.
|
|
auto* args =
|
|
preference_.FindKeyOfType("commandLineSwitches", base::Value::Type::LIST);
|
|
if (args) {
|
|
for (const auto& arg : args->GetList()) {
|
|
if (arg.is_string()) {
|
|
const auto& arg_val = arg.GetString();
|
|
if (!arg_val.empty())
|
|
command_line->AppendSwitch(arg_val);
|
|
}
|
|
}
|
|
}
|
|
|
|
std::string s;
|
|
// Enable blink features.
|
|
if (GetAsString(&preference_, options::kEnableBlinkFeatures, &s))
|
|
command_line->AppendSwitchASCII(::switches::kEnableBlinkFeatures, s);
|
|
|
|
// Disable blink features.
|
|
if (GetAsString(&preference_, options::kDisableBlinkFeatures, &s))
|
|
command_line->AppendSwitchASCII(::switches::kDisableBlinkFeatures, s);
|
|
|
|
if (IsEnabled(options::kNodeIntegrationInWorker))
|
|
command_line->AppendSwitch(switches::kNodeIntegrationInWorker);
|
|
|
|
// 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
|
|
last_preference_ = preference_.Clone();
|
|
}
|
|
|
|
void WebContentsPreferences::OverrideWebkitPrefs(
|
|
blink::web_pref::WebPreferences* prefs) {
|
|
prefs->javascript_enabled =
|
|
IsEnabled(options::kJavaScript, true /* default_value */);
|
|
prefs->images_enabled = IsEnabled(options::kImages, true /* default_value */);
|
|
prefs->text_areas_are_resizable =
|
|
IsEnabled(options::kTextAreasAreResizable, true /* default_value */);
|
|
prefs->navigate_on_drag_drop =
|
|
IsEnabled(options::kNavigateOnDragDrop, false /* default_value */);
|
|
if (!GetAsAutoplayPolicy(&preference_, "autoplayPolicy",
|
|
&prefs->autoplay_policy)) {
|
|
prefs->autoplay_policy =
|
|
blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
|
|
}
|
|
|
|
// Check if webgl should be enabled.
|
|
bool is_webgl_enabled = IsEnabled(options::kWebGL, true /* default_value */);
|
|
prefs->webgl1_enabled = is_webgl_enabled;
|
|
prefs->webgl2_enabled = is_webgl_enabled;
|
|
|
|
// Check if web security should be enabled.
|
|
bool is_web_security_enabled =
|
|
IsEnabled(options::kWebSecurity, true /* default_value */);
|
|
prefs->web_security_enabled = is_web_security_enabled;
|
|
prefs->allow_running_insecure_content =
|
|
IsEnabled(options::kAllowRunningInsecureContent,
|
|
!is_web_security_enabled /* default_value */);
|
|
|
|
auto* fonts_dict = preference_.FindKeyOfType("defaultFontFamily",
|
|
base::Value::Type::DICTIONARY);
|
|
if (fonts_dict) {
|
|
std::u16string font;
|
|
if (GetAsString(fonts_dict, "standard", &font))
|
|
prefs->standard_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
if (GetAsString(fonts_dict, "serif", &font))
|
|
prefs->serif_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
if (GetAsString(fonts_dict, "sansSerif", &font))
|
|
prefs->sans_serif_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
if (GetAsString(fonts_dict, "monospace", &font))
|
|
prefs->fixed_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
if (GetAsString(fonts_dict, "cursive", &font))
|
|
prefs->cursive_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
if (GetAsString(fonts_dict, "fantasy", &font))
|
|
prefs->fantasy_font_family_map[blink::web_pref::kCommonScript] = font;
|
|
}
|
|
|
|
int size;
|
|
if (GetAsInteger(&preference_, "defaultFontSize", &size))
|
|
prefs->default_font_size = size;
|
|
if (GetAsInteger(&preference_, "defaultMonospaceFontSize", &size))
|
|
prefs->default_fixed_font_size = size;
|
|
if (GetAsInteger(&preference_, "minimumFontSize", &size))
|
|
prefs->minimum_font_size = size;
|
|
std::string encoding;
|
|
if (GetAsString(&preference_, "defaultEncoding", &encoding))
|
|
prefs->default_encoding = encoding;
|
|
|
|
// --background-color.
|
|
std::string color;
|
|
if (GetAsString(&preference_, options::kBackgroundColor, &color)) {
|
|
prefs->background_color = color;
|
|
} else if (!IsEnabled(options::kOffscreen)) {
|
|
prefs->background_color = "#fff";
|
|
}
|
|
|
|
// Pass the opener's window id.
|
|
int opener_id;
|
|
if (GetAsInteger(&preference_, options::kOpenerID, &opener_id))
|
|
prefs->opener_id = opener_id;
|
|
|
|
// Run Electron APIs and preload script in isolated world
|
|
prefs->context_isolation = IsEnabled(options::kContextIsolation, true);
|
|
|
|
#if BUILDFLAG(ENABLE_REMOTE_MODULE)
|
|
// Whether to enable the remote module
|
|
prefs->enable_remote_module = IsEnabled(options::kEnableRemoteModule, false);
|
|
#endif
|
|
|
|
prefs->world_safe_execute_javascript =
|
|
IsEnabled(options::kWorldSafeExecuteJavaScript, true);
|
|
|
|
int guest_instance_id = 0;
|
|
if (GetAsInteger(&preference_, options::kGuestInstanceID, &guest_instance_id))
|
|
prefs->guest_instance_id = guest_instance_id;
|
|
|
|
prefs->hidden_page = false;
|
|
if (guest_instance_id) {
|
|
// 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) {
|
|
auto* embedder = manager->GetEmbedder(guest_instance_id);
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
prefs->offscreen = IsEnabled(options::kOffscreen);
|
|
|
|
// The preload script.
|
|
GetPreloadPath(&prefs->preload);
|
|
|
|
// Check if nativeWindowOpen is enabled.
|
|
prefs->native_window_open = IsEnabled(options::kNativeWindowOpen);
|
|
|
|
// Check if we have node integration specified.
|
|
prefs->node_integration = IsEnabled(options::kNodeIntegration);
|
|
|
|
// Whether to enable node integration in Worker.
|
|
prefs->node_integration_in_worker =
|
|
IsEnabled(options::kNodeIntegrationInWorker);
|
|
|
|
prefs->node_integration_in_sub_frames =
|
|
IsEnabled(options::kNodeIntegrationInSubFrames);
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
prefs->enable_spellcheck = IsEnabled(options::kSpellcheck);
|
|
#endif
|
|
|
|
// Check if plugins are enabled.
|
|
prefs->enable_plugins = IsEnabled(options::kPlugins);
|
|
|
|
// Check if webview tag creation is enabled, default to nodeIntegration value.
|
|
prefs->webview_tag = IsEnabled(options::kWebviewTag);
|
|
|
|
// Whether to allow the WebSQL api
|
|
prefs->enable_websql = IsEnabled(options::kEnableWebSQL);
|
|
|
|
std::string v8_cache_options;
|
|
if (GetAsString(&preference_, "v8CacheOptions", &v8_cache_options)) {
|
|
if (v8_cache_options == "none") {
|
|
prefs->v8_cache_options = blink::mojom::V8CacheOptions::kNone;
|
|
} else if (v8_cache_options == "code") {
|
|
prefs->v8_cache_options = blink::mojom::V8CacheOptions::kCode;
|
|
} else if (v8_cache_options == "bypassHeatCheck") {
|
|
prefs->v8_cache_options =
|
|
blink::mojom::V8CacheOptions::kCodeWithoutHeatCheck;
|
|
} else if (v8_cache_options == "bypassHeatCheckAndEagerCompile") {
|
|
prefs->v8_cache_options =
|
|
blink::mojom::V8CacheOptions::kFullCodeWithoutHeatCheck;
|
|
} else {
|
|
prefs->v8_cache_options = blink::mojom::V8CacheOptions::kDefault;
|
|
}
|
|
}
|
|
}
|
|
|
|
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPreferences)
|
|
|
|
} // namespace electron
|