Move a few options in NativeWindow to web-preferences
This commit is contained in:
parent
880dce950d
commit
0b97d58a6f
5 changed files with 42 additions and 57 deletions
|
@ -69,6 +69,16 @@ Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
|
|||
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
||||
options.Get(switches::kWebPreferences, &web_preferences);
|
||||
|
||||
// Be compatible with old options which are now in web_preferences.
|
||||
std::string str;
|
||||
double d;
|
||||
if (options.Get(switches::kNodeIntegration, &str))
|
||||
web_preferences.Set(switches::kNodeIntegration, str);
|
||||
if (options.Get(switches::kPreloadScript, &str))
|
||||
web_preferences.Set(switches::kPreloadScript, str);
|
||||
if (options.Get(switches::kZoomFactor, &d))
|
||||
web_preferences.Set(switches::kZoomFactor, d);
|
||||
|
||||
// Creates the WebContents used by BrowserWindow.
|
||||
auto web_contents = WebContents::Create(isolate, web_preferences);
|
||||
web_contents_.Reset(isolate, web_contents.ToV8());
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "net/ssl/ssl_cert_request_info.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -231,7 +232,6 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
|||
ProcessOwner owner = GetProcessOwner(process_id, &window, &info);
|
||||
|
||||
if (owner == OWNER_NATIVE_WINDOW) {
|
||||
window->AppendExtraCommandLineSwitches(command_line);
|
||||
WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||
window->web_contents(), command_line);
|
||||
} else if (owner == OWNER_GUEST_WEB_CONTENTS) {
|
||||
|
|
|
@ -15,12 +15,10 @@
|
|||
#include "atom/common/native_mate_converters/image_converter.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/prefs/pref_service.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "brightray/browser/inspectable_web_contents.h"
|
||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||
|
@ -77,9 +75,7 @@ NativeWindow::NativeWindow(
|
|||
transparent_(false),
|
||||
enable_larger_than_screen_(false),
|
||||
is_closed_(false),
|
||||
node_integration_(true),
|
||||
has_dialog_attached_(false),
|
||||
zoom_factor_(1.0),
|
||||
aspect_ratio_(0.0),
|
||||
inspectable_web_contents_(inspectable_web_contents),
|
||||
weak_factory_(this) {
|
||||
|
@ -88,7 +84,6 @@ NativeWindow::NativeWindow(
|
|||
options.Get(switches::kFrame, &has_frame_);
|
||||
options.Get(switches::kTransparent, &transparent_);
|
||||
options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
|
||||
options.Get(switches::kNodeIntegration, &node_integration_);
|
||||
|
||||
// Tell the content module to initialize renderer widget with transparent
|
||||
// mode.
|
||||
|
@ -97,25 +92,6 @@ NativeWindow::NativeWindow(
|
|||
// Read icon before window is created.
|
||||
options.Get(switches::kIcon, &icon_);
|
||||
|
||||
// The "preload" option must be absolute path.
|
||||
if (options.Get(switches::kPreloadScript, &preload_script_) &&
|
||||
!preload_script_.IsAbsolute()) {
|
||||
LOG(ERROR) << "Path of \"preload\" script must be absolute.";
|
||||
preload_script_.clear();
|
||||
}
|
||||
|
||||
// Be compatible with old API of "node-integration" option.
|
||||
std::string old_string_token;
|
||||
if (options.Get(switches::kNodeIntegration, &old_string_token) &&
|
||||
old_string_token != "disable")
|
||||
node_integration_ = true;
|
||||
|
||||
// Read the web preferences.
|
||||
options.Get(switches::kWebPreferences, &web_preferences_);
|
||||
|
||||
// Read the zoom factor before any navigation.
|
||||
options.Get(switches::kZoomFactor, &zoom_factor_);
|
||||
|
||||
WindowList::AddWindow(this);
|
||||
}
|
||||
|
||||
|
@ -364,22 +340,6 @@ void NativeWindow::RendererResponsive(content::WebContents* source) {
|
|||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
||||
}
|
||||
|
||||
void NativeWindow::AppendExtraCommandLineSwitches(
|
||||
base::CommandLine* command_line) {
|
||||
// Append --node-integration to renderer process.
|
||||
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
||||
node_integration_ ? "true" : "false");
|
||||
|
||||
// Append --preload.
|
||||
if (!preload_script_.empty())
|
||||
command_line->AppendSwitchPath(switches::kPreloadScript, preload_script_);
|
||||
|
||||
// Append --zoom-factor.
|
||||
if (zoom_factor_ != 1.0)
|
||||
command_line->AppendSwitchASCII(switches::kZoomFactor,
|
||||
base::DoubleToString(zoom_factor_));
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowClosed() {
|
||||
if (is_closed_)
|
||||
return;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "content/public/browser/readback_types.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
#include "native_mate/persistent_dictionary.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
|
||||
|
@ -280,9 +279,6 @@ class NativeWindow : public content::WebContentsObserver,
|
|||
// The windows has been closed.
|
||||
bool is_closed_;
|
||||
|
||||
// Whether node integration is enabled.
|
||||
bool node_integration_;
|
||||
|
||||
// There is a dialog that has been attached to window.
|
||||
bool has_dialog_attached_;
|
||||
|
||||
|
@ -290,15 +286,6 @@ class NativeWindow : public content::WebContentsObserver,
|
|||
// it should be cancelled when we can prove that the window is responsive.
|
||||
base::CancelableClosure window_unresposive_closure_;
|
||||
|
||||
// Web preferences.
|
||||
mate::PersistentDictionary web_preferences_;
|
||||
|
||||
// The script to load before page's JavaScript starts to run.
|
||||
base::FilePath preload_script_;
|
||||
|
||||
// Page's default zoom factor.
|
||||
double zoom_factor_;
|
||||
|
||||
// Used to maintain the aspect ratio of a view which is inside of the
|
||||
// content view.
|
||||
double aspect_ratio_;
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "storage/common/fileapi/file_system_util.h" // IsAbsolute
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "ui/gfx/switches.h"
|
||||
|
@ -54,25 +56,51 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
|||
content::WebContents* web_contents, base::CommandLine* command_line) {
|
||||
WebContentsPreferences* self = From(web_contents);
|
||||
CHECK(self);
|
||||
base::DictionaryValue& web_preferences = self->web_preferences_;
|
||||
|
||||
bool b;
|
||||
#if defined(OS_WIN)
|
||||
// Check if DirectWrite is disabled.
|
||||
if (self->web_preferences_.GetBoolean(switches::kDirectWrite, &b) && !b)
|
||||
if (web_preferences.GetBoolean(switches::kDirectWrite, &b) && !b)
|
||||
command_line->AppendSwitch(::switches::kDisableDirectWrite);
|
||||
#endif
|
||||
|
||||
// Check if plugins are enabled.
|
||||
if (self->web_preferences_.GetBoolean("plugins", &b) && b)
|
||||
if (web_preferences.GetBoolean("plugins", &b) && b)
|
||||
command_line->AppendSwitch(switches::kEnablePlugins);
|
||||
|
||||
// This set of options are not availabe in WebPreferences, so we have to pass
|
||||
// them via command line and enable them in renderer procss.
|
||||
for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) {
|
||||
const char* feature = kWebRuntimeFeatures[i];
|
||||
if (self->web_preferences_.GetBoolean(feature, &b))
|
||||
if (web_preferences.GetBoolean(feature, &b))
|
||||
command_line->AppendSwitchASCII(feature, b ? "true" : "false");
|
||||
}
|
||||
|
||||
// Check if we have node integration specified.
|
||||
bool node_integration = true;
|
||||
web_preferences.GetBoolean(switches::kNodeIntegration, &node_integration);
|
||||
// Be compatible with old API of "node-integration" option.
|
||||
std::string old_token;
|
||||
if (web_preferences.GetString(switches::kNodeIntegration, &old_token) &&
|
||||
old_token != "disable")
|
||||
node_integration = true;
|
||||
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
||||
node_integration ? "true" : "false");
|
||||
|
||||
// The preload script.
|
||||
base::FilePath::StringType preload;
|
||||
if (web_preferences.GetString(switches::kPreloadScript, &preload) &&
|
||||
!preload.empty() &&
|
||||
base::FilePath(preload).IsAbsolute())
|
||||
command_line->AppendSwitchNative(switches::kPreloadScript, preload);
|
||||
|
||||
// The zoom factor.
|
||||
double zoom_factor = 1.0;
|
||||
if (web_preferences.GetDouble(switches::kZoomFactor, &zoom_factor) &&
|
||||
zoom_factor != 1.0)
|
||||
command_line->AppendSwitchASCII(switches::kZoomFactor,
|
||||
base::DoubleToString(zoom_factor));
|
||||
}
|
||||
|
||||
void WebContentsPreferences::OverrideWebkitPrefs(
|
||||
|
|
Loading…
Reference in a new issue