69f1731bbb
* chore: bump chromium in DEPS to cbdeef954dfc34e94c8ca9cf72ad326b4a121158 * chore: bump chromium in DEPS to 29723f905baeab1d4228eef2c31cdb341ebeffe0 * chore: bump chromium in DEPS to 44d6d78e852137fff58c14ed26ab1e803e5bf822 * update patches * chore: bump chromium in DEPS to 8a3a0fccb39d6b8334c9a0496c0d5056e50cdb3f * chore: update patches * refactor: fix PrintBackend::CreateInstance() calls Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2354541 * chore: bump chromium in DEPS to b9ebec3bcb1cabdd1426f367636f54cc98e0500e * chore: remove patches to code that was deleted upstream CL: https://chromium-review.googlesource.com/c/chromium/src/+/2360314 * Remove uses of kCGColorSpaceITUR_2020_PQ_EOTF/HLG CL: https://chromium-review.googlesource.com/c/chromium/src/+/2363950 just garden variety code shear * chore: update patch indices * Move ColorModel to //printing/mojom/print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2355083 sync with printing ColorModel changes: moved to mojo, different naming scheme * chore: bump chromium in DEPS to 56c4b4d2ce5ba941acd2e0fdb5100e8a48847134 * chore: bump chromium in DEPS to 130501f220b684a79dc82c17e236e63ac1f2a093 * Convert PrintHostMsg_DidGetPrintedPagesCount to Mojo https://chromium-review.googlesource.com/c/chromium/src/+/2326857 Update argument list to Print() * chore: update patch indices * DumpAccTree: convert utf16 to utf8 in PropertyFilter https://chromium-review.googlesource.com/c/chromium/src/+/2360218 * chore: bump chromium in DEPS to 3058368c6646e0dc8be6f8ea838b0343428b7998 * chore: bump chromium in DEPS to f51b4e6555364363c61438dac7afd988c8347bfc * chore: bump chromium in DEPS to 2dcc6f8fc23ac41b2499eb69dee0b4017e9d1046 * update patches * chore: bump chromium in DEPS to 2d8e98ecedc7e4905540b053bc1c87e964715be5 * update patches * 2345900: Move content::RecordContentToVisibleTimeRequest struct to mojo https://chromium-review.googlesource.com/c/chromium/src/+/2345900 * update patches * 2345900: Move content::RecordContentToVisibleTimeRequest struct to mojo https://chromium-review.googlesource.com/c/chromium/src/+/2345900 * 2367394: Remove net::LOAD_DO_NOT_SEND_COOKIES and net::LOAD_DO_NOT_SEND_AUTH_DATA. https://chromium-review.googlesource.com/c/chromium/src/+/2367394 * 2373227: [XProto] Consolidate all <X11/*> includes to //ui/gfx/x/x11.h https://chromium-review.googlesource.com/c/chromium/src/+/2373227 * fixup! 2373227: [XProto] Consolidate all <X11/*> includes to //ui/gfx/x/x11.h * chore: bump chromium in DEPS to c090e3f960520cbd2328608b97f87238c76d6143 * update patches * chore: bump chromium in DEPS to 13a25e0a755de9a14271022c595f3d2e29829e1a * chore: bump chromium in DEPS to 6adbb767b012c41efaeab0d1bdbb3eefed0977bc * chore: bump chromium in DEPS to 339ec5455c5932ef1322ea9953a6349b0732199e * chore: bump chromium in DEPS to 20291807c33f7ef4ef4f57d62075e099b027bfe6 * chore: bump chromium in DEPS to 226fbd1b8b17d4ac84fdb9548ef3a1c646878d47 * update patches * fixup disable_color_correct_rendering patch * chore: bump chromium in DEPS to 577c45979cad4359f2e206d68efd9317d3d79315 * update patches * viz: Rename RenderPass to CompositorRenderPass (and related types). https://chromium-review.googlesource.com/c/chromium/src/+/2380730 * chore: bump chromium in DEPS to 37e2ad5303f2c03a1b5d8eda65341bf2561196cd * update patches * add kOmitCookies_Electron * update patch * chore: bump chromium in DEPS to 256e42409ea63a7e71016de07818a983a97db463 * update patches * fix worker script ready hook https://chromium-review.googlesource.com/c/chromium/src/+/2335713 * Fixup printing page ranges patch * [printing] Move PrintMsg_PrintPages_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2340854 * Add MIME sniffer overloads that take base::StringPieces https://chromium-review.googlesource.com/c/chromium/src/+/2382896 * [printing] Move PrintHostMsg_PreviewIds to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2379455 * fixup test due to new DCHECK https://chromium-review.googlesource.com/c/chromium/src/+/2333750 * stop sending cookies when useSessionCookies is false * chore: bump chromium in DEPS to dd429dbc556449951ee8160d8a4d61fd95a139d5 * update patches * chore: bump chromium in DEPS to 5202bde3f9f44c2065f5dacf27e7000dd19e4e4d * chore: bump chromium in DEPS to 099e8e07b89da65932431bb0fd51b6f7f5344c19 * chore: bump chromium in DEPS to 104e5da2a43b759732d5b94bfc750b3a9a639653 * chore: bump chromium in DEPS to a4519ce657af25834e355315fd7fefa77b13426a * update patches * Make FileURLLoaderFactory always owned by its |receivers_|. https://chromium-review.googlesource.com/c/chromium/src/+/2337411 * Make FileURLLoaderFactory always owned by its |receivers_|. https://chromium-review.googlesource.com/c/chromium/src/+/2337411 * chore: bump chromium in DEPS to 1b62e9e8c8eaf6b8e3a9c77ee67a4c1bfa6a4d6b * chore: update patches * fixup! Make FileURLLoaderFactory always owned by its |receivers_|. * chore: update patches - mac: Disable CoreServices _CSCheckFix. https://chromium-review.googlesource.com/c/chromium/src/+/2401334 - [XProto] Remove bad DCHECK in x11_error_tracker.cc https://chromium-review.googlesource.com/c/chromium/src/+/2402304 - Move content/browser/frame_host/* over to content/browser/renderer_host/ https://chromium-review.googlesource.com/c/chromium/src/+/2401303 * Refactor WebContentSettingsClient to dedupe AllowXYZ methods https://chromium-review.googlesource.com/c/chromium/src/+/2353552 * Introduce NonNetworkURLLoaderFactoryBase class. https://chromium-review.googlesource.com/c/chromium/src/+/2357559 * [XProto] Remove usage of all Xlib headers https://chromium-review.googlesource.com/c/chromium/src/+/2392140 * fixup! chore: update patches * chore: bump chromium in DEPS to c1df55fbeb8207d036a604f59e4ea4e8ee79930a * chore: update patches * Move content::WebPreferences struct to Blink https://chromium-review.googlesource.com/c/chromium/src/+/2397670 * chore: bump chromium in DEPS to 57a23ec4884fff6c2f8d9b8536131cdc9b551ec2 * Set appid on Pip windows. https://chromium-review.googlesource.com/c/chromium/src/+/2388274 * fixup! Set appid on Pip windows. * fix: add a patch to remove deprecated factory * chore: bump chromium in DEPS to 1a9ddb7ea43955877823d5c4dcbf241b64228635 * fix compilation on windows * chore: bump chromium in DEPS to 234e6c6a77f61ffad9335099d9b13892cf88fd44 * chore: update patches * chore: bump chromium in DEPS to 7631eb0a9f57a8a47d3c28e1d265961b3a4d6b2b * chore: update patches * chore: bump chromium in DEPS to f9c34cd485845b95c2d17a7f55fdf92cda9a1b3a * chore: update patches * chore: implement GetSurveyAPIKey Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2362182 * chore: replace CreateWebUIURLLoader with CreateWebUIURLLoaderFactory Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2358309 * chore: bump chromium in DEPS to 5bdbd2373da884adf41c087be1465fcc344d168c * chore: update node patches for common.gypi * chore: update patches * chore: non_network_url_loader_factory_base was moved Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2357431 * 2415752: Reland "Reland "OOR-CORS: Remove BlinkCORS supporting code outside Blink"" Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2415752 * chore: bump chromium in DEPS to b943d006a33ec5bc1743792d64724693eb357083 * fix: replace x11::None with x11::Window::None * chore: update patches * chore: update patches * fix: cast x11::Window to int * 2402123: Use end date when deleting http auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2402123 * 2320268: Migrate DragHostMsg_StartDragging to Mojo Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2320268 * 2401303: Move content/browser/frame_host/* over to content/browser/renderer_host/ https://chromium-review.googlesource.com/c/chromium/src/+/2401303 * chore: fix lint * chore: fix build * Update config.yml Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: Samuel Attard <sattard@slack-corp.com>
529 lines
19 KiB
C++
529 lines
19 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,
|
|
base::string16* out) {
|
|
if (val) {
|
|
auto* found = val->FindKeyOfType(path, base::Value::Type::STRING);
|
|
if (found) {
|
|
*out = base::UTF8ToUTF16(found->GetString());
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
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::web_pref::AutoplayPolicy* out) {
|
|
std::string policy_str;
|
|
if (GetAsString(val, path, &policy_str)) {
|
|
if (policy_str == "no-user-gesture-required") {
|
|
*out = blink::web_pref::AutoplayPolicy::kNoUserGestureRequired;
|
|
return true;
|
|
} else if (policy_str == "user-gesture-required") {
|
|
*out = blink::web_pref::AutoplayPolicy::kUserGestureRequired;
|
|
return true;
|
|
} else if (policy_str == "document-user-activation-required") {
|
|
*out = blink::web_pref::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);
|
|
if (IsUndefined(options::kContextIsolation)) {
|
|
node::Environment* env = node::Environment::GetCurrent(isolate);
|
|
EmitWarning(env,
|
|
"The default of contextIsolation is deprecated and will be "
|
|
"changing from false to true in a future release of Electron. "
|
|
"See https://github.com/electron/electron/issues/23506 for "
|
|
"more information",
|
|
"electron");
|
|
}
|
|
SetDefaultBoolIfUndefined(options::kContextIsolation, false);
|
|
SetDefaultBoolIfUndefined(options::kWorldSafeExecuteJavaScript, false);
|
|
SetDefaultBoolIfUndefined(options::kJavaScript, true);
|
|
SetDefaultBoolIfUndefined(options::kImages, true);
|
|
SetDefaultBoolIfUndefined(options::kTextAreasAreResizable, true);
|
|
SetDefaultBoolIfUndefined(options::kWebGL, true);
|
|
SetDefaultBoolIfUndefined(options::kEnableWebSQL, true);
|
|
bool webSecurity = true;
|
|
SetDefaultBoolIfUndefined(options::kWebSecurity, webSecurity);
|
|
// If webSecurity was explicity 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::StringType* path) const {
|
|
DCHECK(path);
|
|
base::FilePath::StringType preload;
|
|
if (GetAsString(&preference_, options::kPreloadScript, &preload)) {
|
|
if (base::FilePath(preload).IsAbsolute()) {
|
|
*path = std::move(preload);
|
|
return true;
|
|
} else {
|
|
LOG(ERROR) << "preload script must have absolute path.";
|
|
}
|
|
} else if (GetAsString(&preference_, options::kPreloadURL, &preload)) {
|
|
// Translate to file path if there is "preload-url" option.
|
|
base::FilePath preload_path;
|
|
if (net::FileURLToFilePath(GURL(preload), &preload_path)) {
|
|
*path = std::move(preload_path.value());
|
|
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) {
|
|
// Check if plugins are enabled.
|
|
if (IsEnabled(options::kPlugins))
|
|
command_line->AppendSwitch(switches::kEnablePlugins);
|
|
|
|
// Experimental flags.
|
|
if (IsEnabled(options::kExperimentalFeatures))
|
|
command_line->AppendSwitch(
|
|
::switches::kEnableExperimentalWebPlatformFeatures);
|
|
|
|
// Check if we have node integration specified.
|
|
if (IsEnabled(options::kNodeIntegration))
|
|
command_line->AppendSwitch(switches::kNodeIntegration);
|
|
|
|
// Whether to enable node integration in Worker.
|
|
if (IsEnabled(options::kNodeIntegrationInWorker))
|
|
command_line->AppendSwitch(switches::kNodeIntegrationInWorker);
|
|
|
|
// Check if webview tag creation is enabled, default to nodeIntegration value.
|
|
if (IsEnabled(options::kWebviewTag))
|
|
command_line->AppendSwitch(switches::kWebviewTag);
|
|
|
|
// 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 the `sandbox` option was passed to the BrowserWindow's webPreferences,
|
|
// pass `--enable-sandbox` to the renderer so it won't have any node.js
|
|
// integration. Otherwise disable Chromium sandbox, unless app.enableSandbox()
|
|
// was called.
|
|
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);
|
|
}
|
|
|
|
// Check if nativeWindowOpen is enabled.
|
|
if (IsEnabled(options::kNativeWindowOpen))
|
|
command_line->AppendSwitch(switches::kNativeWindowOpen);
|
|
|
|
// The preload script.
|
|
base::FilePath::StringType preload;
|
|
if (GetPreloadPath(&preload))
|
|
command_line->AppendSwitchNative(switches::kPreloadScript, preload);
|
|
|
|
// 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());
|
|
}
|
|
}
|
|
|
|
#if BUILDFLAG(ENABLE_REMOTE_MODULE)
|
|
// Whether to enable the remote module
|
|
if (IsEnabled(options::kEnableRemoteModule, false))
|
|
command_line->AppendSwitch(switches::kEnableRemoteModule);
|
|
#endif
|
|
|
|
// Run Electron APIs and preload script in isolated world
|
|
if (IsEnabled(options::kContextIsolation))
|
|
command_line->AppendSwitch(switches::kContextIsolation);
|
|
|
|
if (IsEnabled(options::kWorldSafeExecuteJavaScript))
|
|
command_line->AppendSwitch(switches::kWorldSafeExecuteJavaScript);
|
|
|
|
// --background-color.
|
|
std::string s;
|
|
if (GetAsString(&preference_, options::kBackgroundColor, &s)) {
|
|
command_line->AppendSwitchASCII(switches::kBackgroundColor, s);
|
|
} else if (!IsEnabled(options::kOffscreen)) {
|
|
// For non-OSR WebContents, we expect to have white background, see
|
|
// https://github.com/electron/electron/issues/13764 for more.
|
|
command_line->AppendSwitchASCII(switches::kBackgroundColor, "#fff");
|
|
}
|
|
|
|
// --offscreen
|
|
if (IsEnabled(options::kOffscreen)) {
|
|
command_line->AppendSwitch(options::kOffscreen);
|
|
}
|
|
|
|
// --guest-instance-id, which is used to identify guest WebContents.
|
|
int guest_instance_id = 0;
|
|
if (GetAsInteger(&preference_, options::kGuestInstanceID, &guest_instance_id))
|
|
command_line->AppendSwitchASCII(switches::kGuestInstanceID,
|
|
base::NumberToString(guest_instance_id));
|
|
|
|
// Pass the opener's window id.
|
|
int opener_id;
|
|
if (GetAsInteger(&preference_, options::kOpenerID, &opener_id))
|
|
command_line->AppendSwitchASCII(switches::kOpenerID,
|
|
base::NumberToString(opener_id));
|
|
|
|
#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);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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 (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) {
|
|
command_line->AppendSwitch(switches::kHiddenPage);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (IsEnabled(options::kNodeIntegrationInSubFrames))
|
|
command_line->AppendSwitch(switches::kNodeIntegrationInSubFrames);
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
if (IsEnabled(options::kSpellcheck)) {
|
|
command_line->AppendSwitch(switches::kEnableSpellcheck);
|
|
}
|
|
#endif
|
|
|
|
// Whether to allow the WebSQL api
|
|
if (IsEnabled(options::kEnableWebSQL))
|
|
command_line->AppendSwitch(switches::kEnableWebSQL);
|
|
|
|
// 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::web_pref::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) {
|
|
base::string16 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;
|
|
|
|
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
|