зеркало из https://github.com/electron/electron.git
chore: move more constants to options_switches.h/cc (#13093)
* Add options::kNativeWindowOpen * Add options::kSandbox * Add options::kPlugins * Add options::kWebSecurity * Add options::kAllowRunningInsecureContent * Add options::kOffscreen
This commit is contained in:
Родитель
ec44fb79d8
Коммит
45e78728bd
|
@ -84,7 +84,7 @@ TopLevelWindow::TopLevelWindow(v8::Isolate* isolate,
|
|||
mate::Dictionary web_preferences;
|
||||
bool offscreen;
|
||||
if (options.Get(options::kWebPreferences, &web_preferences) &&
|
||||
web_preferences.Get("offscreen", &offscreen) && offscreen) {
|
||||
web_preferences.Get(options::kOffscreen, &offscreen) && offscreen) {
|
||||
const_cast<mate::Dictionary&>(options).Set(options::kFrame, false);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -368,7 +368,7 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
else if (options.Get("isBrowserView", &b) && b)
|
||||
type_ = BROWSER_VIEW;
|
||||
#if defined(ENABLE_OSR)
|
||||
else if (options.Get("offscreen", &b) && b)
|
||||
else if (options.Get(options::kOffscreen, &b) && b)
|
||||
type_ = OFF_SCREEN;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -181,8 +181,9 @@ void AtomBrowserClient::RenderProcessWillLaunch(
|
|||
auto* web_preferences =
|
||||
WebContentsPreferences::From(GetWebContentsFromProcessID(process_id));
|
||||
if (web_preferences) {
|
||||
prefs.sandbox = web_preferences->IsEnabled("sandbox");
|
||||
prefs.native_window_open = web_preferences->IsEnabled("nativeWindowOpen");
|
||||
prefs.sandbox = web_preferences->IsEnabled(options::kSandbox);
|
||||
prefs.native_window_open =
|
||||
web_preferences->IsEnabled(options::kNativeWindowOpen);
|
||||
prefs.disable_popups = web_preferences->IsEnabled("disablePopups");
|
||||
}
|
||||
AddProcessPreferences(host->GetID(), prefs);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
|
@ -90,7 +91,8 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
|||
window = relay->window.get();
|
||||
|
||||
auto* web_preferences = WebContentsPreferences::From(web_contents);
|
||||
bool offscreen = !web_preferences || web_preferences->IsEnabled("offscreen");
|
||||
bool offscreen =
|
||||
!web_preferences || web_preferences->IsEnabled(options::kOffscreen);
|
||||
|
||||
base::FilePath path;
|
||||
GetItemSavePath(item, &path);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/ui/message_box.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
|
@ -66,7 +67,7 @@ void AtomJavaScriptDialogManager::RunJavaScriptDialog(
|
|||
|
||||
// Don't set parent for offscreen window.
|
||||
NativeWindow* window = nullptr;
|
||||
if (web_preferences && !web_preferences->IsEnabled("offscreen")) {
|
||||
if (web_preferences && !web_preferences->IsEnabled(options::kOffscreen)) {
|
||||
auto* relay = NativeWindowRelay::FromWebContents(web_contents);
|
||||
if (relay)
|
||||
window = relay->window.get();
|
||||
|
|
|
@ -80,7 +80,7 @@ void OnPdfResourceIntercepted(
|
|||
return;
|
||||
|
||||
auto* web_preferences = WebContentsPreferences::From(web_contents);
|
||||
if (!web_preferences || !web_preferences->IsEnabled("plugins")) {
|
||||
if (!web_preferences || !web_preferences->IsEnabled(options::kPlugins)) {
|
||||
auto* browser_context = web_contents->GetBrowserContext();
|
||||
auto* download_manager =
|
||||
content::BrowserContext::GetDownloadManager(browser_context);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "atom/browser/web_dialog_helper.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "chrome/browser/printing/print_preview_message_handler.h"
|
||||
#include "chrome/browser/printing/print_view_manager_basic.h"
|
||||
|
@ -156,7 +157,8 @@ void CommonWebContentsDelegate::InitWithWebContents(
|
|||
|
||||
// Determien whether the WebContents is offscreen.
|
||||
auto* web_preferences = WebContentsPreferences::From(web_contents);
|
||||
offscreen_ = !web_preferences || web_preferences->IsEnabled("offscreen");
|
||||
offscreen_ =
|
||||
!web_preferences || web_preferences->IsEnabled(options::kOffscreen);
|
||||
|
||||
// Create InspectableWebContents.
|
||||
web_contents_.reset(brightray::InspectableWebContents::Create(web_contents));
|
||||
|
|
|
@ -51,32 +51,33 @@ WebContentsPreferences::WebContentsPreferences(
|
|||
instances_.push_back(this);
|
||||
|
||||
// Set WebPreferences defaults onto the JS object
|
||||
SetDefaultBoolIfUndefined("plugins", false);
|
||||
SetDefaultBoolIfUndefined(options::kPlugins, false);
|
||||
SetDefaultBoolIfUndefined(options::kExperimentalFeatures, false);
|
||||
SetDefaultBoolIfUndefined(options::kExperimentalCanvasFeatures, false);
|
||||
bool node = SetDefaultBoolIfUndefined(options::kNodeIntegration, true);
|
||||
SetDefaultBoolIfUndefined(options::kNodeIntegrationInWorker, false);
|
||||
SetDefaultBoolIfUndefined(options::kWebviewTag, node);
|
||||
SetDefaultBoolIfUndefined("sandbox", false);
|
||||
SetDefaultBoolIfUndefined("nativeWindowOpen", false);
|
||||
SetDefaultBoolIfUndefined(options::kSandbox, false);
|
||||
SetDefaultBoolIfUndefined(options::kNativeWindowOpen, false);
|
||||
SetDefaultBoolIfUndefined(options::kContextIsolation, false);
|
||||
SetDefaultBoolIfUndefined("javascript", true);
|
||||
SetDefaultBoolIfUndefined("images", true);
|
||||
SetDefaultBoolIfUndefined("textAreasAreResizable", true);
|
||||
SetDefaultBoolIfUndefined("webgl", true);
|
||||
bool webSecurity = true;
|
||||
SetDefaultBoolIfUndefined("webSecurity", webSecurity);
|
||||
SetDefaultBoolIfUndefined(options::kWebSecurity, webSecurity);
|
||||
// If webSecurity was explicity set to false, let's inherit that into
|
||||
// insecureContent
|
||||
if (web_preferences.Get("webSecurity", &webSecurity) && !webSecurity) {
|
||||
SetDefaultBoolIfUndefined("allowRunningInsecureContent", true);
|
||||
if (web_preferences.Get(options::kWebSecurity, &webSecurity) &&
|
||||
!webSecurity) {
|
||||
SetDefaultBoolIfUndefined(options::kAllowRunningInsecureContent, true);
|
||||
} else {
|
||||
SetDefaultBoolIfUndefined("allowRunningInsecureContent", false);
|
||||
SetDefaultBoolIfUndefined(options::kAllowRunningInsecureContent, false);
|
||||
}
|
||||
#if defined(OS_MACOSX)
|
||||
SetDefaultBoolIfUndefined(options::kScrollBounce, false);
|
||||
#endif
|
||||
SetDefaultBoolIfUndefined("offscreen", false);
|
||||
SetDefaultBoolIfUndefined(options::kOffscreen, false);
|
||||
|
||||
last_dict_ = std::move(*dict_.CreateDeepCopy());
|
||||
}
|
||||
|
@ -131,7 +132,7 @@ void WebContentsPreferences::AppendCommandLineSwitches(
|
|||
base::CommandLine* command_line) {
|
||||
bool b;
|
||||
// Check if plugins are enabled.
|
||||
if (dict_.GetBoolean("plugins", &b) && b)
|
||||
if (dict_.GetBoolean(options::kPlugins, &b) && b)
|
||||
command_line->AppendSwitch(switches::kEnablePlugins);
|
||||
|
||||
// Experimental flags.
|
||||
|
@ -161,11 +162,11 @@ void WebContentsPreferences::AppendCommandLineSwitches(
|
|||
// 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.
|
||||
if (dict_.GetBoolean("sandbox", &b) && b)
|
||||
if (dict_.GetBoolean(options::kSandbox, &b) && b)
|
||||
command_line->AppendSwitch(switches::kEnableSandbox);
|
||||
else if (!command_line->HasSwitch(switches::kEnableSandbox))
|
||||
command_line->AppendSwitch(::switches::kNoSandbox);
|
||||
if (dict_.GetBoolean("nativeWindowOpen", &b) && b)
|
||||
if (dict_.GetBoolean(options::kNativeWindowOpen, &b) && b)
|
||||
command_line->AppendSwitch(switches::kNativeWindowOpen);
|
||||
|
||||
// The preload script.
|
||||
|
@ -278,11 +279,11 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
|||
prefs->webgl1_enabled = b;
|
||||
prefs->webgl2_enabled = b;
|
||||
}
|
||||
if (dict_.GetBoolean("webSecurity", &b)) {
|
||||
if (dict_.GetBoolean(options::kWebSecurity, &b)) {
|
||||
prefs->web_security_enabled = b;
|
||||
prefs->allow_running_insecure_content = !b;
|
||||
}
|
||||
if (dict_.GetBoolean("allowRunningInsecureContent", &b))
|
||||
if (dict_.GetBoolean(options::kAllowRunningInsecureContent, &b))
|
||||
prefs->allow_running_insecure_content = b;
|
||||
if (dict_.GetBoolean("navigateOnDragDrop", &b))
|
||||
prefs->navigate_on_drag_drop = b;
|
||||
|
|
|
@ -139,8 +139,20 @@ const char kNodeIntegrationInWorker[] = "nodeIntegrationInWorker";
|
|||
// Enable the web view tag.
|
||||
const char kWebviewTag[] = "webviewTag";
|
||||
|
||||
const char kNativeWindowOpen[] = "nativeWindowOpen";
|
||||
|
||||
const char kCustomArgs[] = "additionalArguments";
|
||||
|
||||
const char kPlugins[] = "plugins";
|
||||
|
||||
const char kSandbox[] = "sandbox";
|
||||
|
||||
const char kWebSecurity[] = "webSecurity";
|
||||
|
||||
const char kAllowRunningInsecureContent[] = "allowRunningInsecureContent";
|
||||
|
||||
const char kOffscreen[] = "offscreen";
|
||||
|
||||
} // namespace options
|
||||
|
||||
namespace switches {
|
||||
|
|
|
@ -68,7 +68,13 @@ extern const char kBlinkFeatures[];
|
|||
extern const char kDisableBlinkFeatures[];
|
||||
extern const char kNodeIntegrationInWorker[];
|
||||
extern const char kWebviewTag[];
|
||||
extern const char kNativeWindowOpen[];
|
||||
extern const char kCustomArgs[];
|
||||
extern const char kPlugins[];
|
||||
extern const char kSandbox[];
|
||||
extern const char kWebSecurity[];
|
||||
extern const char kAllowRunningInsecureContent[];
|
||||
extern const char kOffscreen[];
|
||||
|
||||
} // namespace options
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ void AtomRendererClient::SetupMainWorldOverrides(
|
|||
dict.Set(options::kOpenerID,
|
||||
command_line->GetSwitchValueASCII(switches::kOpenerID));
|
||||
dict.Set("hiddenPage", command_line->HasSwitch(switches::kHiddenPage));
|
||||
dict.Set("nativeWindowOpen",
|
||||
dict.Set(options::kNativeWindowOpen,
|
||||
command_line->HasSwitch(switches::kNativeWindowOpen));
|
||||
|
||||
v8::Local<v8::Value> args[] = {binding};
|
||||
|
|
Загрузка…
Ссылка в новой задаче