From 2204e9bb15c9e8895bfa0896867ac91be5766094 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 22 May 2014 22:54:09 +0800 Subject: [PATCH 1/5] Add 'web-preferences' options in BrowserWindow. --- atom/browser/native_window.cc | 27 +++++++++++++++++++++++++++ atom/browser/native_window.h | 3 +++ atom/common/options_switches.cc | 3 +++ atom/common/options_switches.h | 1 + 4 files changed, 34 insertions(+) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 558778029e5b..2c8635b91b08 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -76,6 +76,11 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, // Read iframe security before any navigation. options->GetString(switches::kNodeIntegration, &node_integration_); + // Read the web preferences. + base::DictionaryValue* web_preferences; + if (options->GetDictionary(switches::kWebPreferences, &web_preferences)) + web_preferences_.reset(web_preferences->DeepCopy()); + web_contents->SetDelegate(this); inspectable_web_contents()->SetDelegate(this); @@ -348,6 +353,28 @@ void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) { // FIXME Disable accelerated composition in frameless window. if (!has_frame_) prefs->accelerated_compositing_enabled = false; + + bool b; + if (!web_preferences_) + return; + else if (web_preferences_->GetBoolean("javascript", &b)) + prefs->javascript_enabled = b; + else if (web_preferences_->GetBoolean("web-security", &b)) + prefs->web_security_enabled = b; + else if (web_preferences_->GetBoolean("images", &b)) + prefs->images_enabled = b; + else if (web_preferences_->GetBoolean("plugins", &b)) + prefs->plugins_enabled = b; + else if (web_preferences_->GetBoolean("java", &b)) + prefs->java_enabled = b; + else if (web_preferences_->GetBoolean("text-areas-are-resizable", &b)) + prefs->text_areas_are_resizable = b; + else if (web_preferences_->GetBoolean("webgl", &b)) + prefs->experimental_webgl_enabled = b; + else if (web_preferences_->GetBoolean("webaudio", &b)) + prefs->webaudio_enabled = b; + else if (web_preferences_->GetBoolean("accelerated-compositing", &b)) + prefs->accelerated_compositing_enabled = b; } void NativeWindow::NotifyWindowClosed() { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 7c2b60806713..e9bce8139705 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -290,6 +290,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // it should be cancelled when we can prove that the window is responsive. base::CancelableClosure window_unresposive_closure_; + // web preferences. + scoped_ptr web_preferences_; + base::WeakPtrFactory weak_factory_; base::WeakPtr devtools_window_; diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 270fc1f48315..05fc8b0f3591 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -39,6 +39,9 @@ const char kAcceptFirstMouse[] = "accept-first-mouse"; // Whether window size should include window frame. const char kUseContentSize[] = "use-content-size"; +// The WebPreferences. +const char kWebPreferences[] = "web-preferences"; + } // namespace switches } // namespace atom diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 8fa105684dc2..31463e64d9f3 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -29,6 +29,7 @@ extern const char kAlwaysOnTop[]; extern const char kNodeIntegration[]; extern const char kAcceptFirstMouse[]; extern const char kUseContentSize[]; +extern const char kWebPreferences[]; } // namespace switches From 1fbebb0da76d22be72ebf944bef135d6360f723b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 22 May 2014 23:48:00 +0800 Subject: [PATCH 2/5] Add 'extra-plugin-dirs' option. --- atom/browser/native_window.cc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 2c8635b91b08..dbd57d0b59be 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -31,6 +31,7 @@ #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" +#include "content/public/browser/plugin_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host_view.h" @@ -355,26 +356,35 @@ void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) { prefs->accelerated_compositing_enabled = false; bool b; + base::ListValue* list; if (!web_preferences_) return; - else if (web_preferences_->GetBoolean("javascript", &b)) + if (web_preferences_->GetBoolean("javascript", &b)) prefs->javascript_enabled = b; - else if (web_preferences_->GetBoolean("web-security", &b)) + if (web_preferences_->GetBoolean("web-security", &b)) prefs->web_security_enabled = b; - else if (web_preferences_->GetBoolean("images", &b)) + if (web_preferences_->GetBoolean("images", &b)) prefs->images_enabled = b; - else if (web_preferences_->GetBoolean("plugins", &b)) - prefs->plugins_enabled = b; - else if (web_preferences_->GetBoolean("java", &b)) + if (web_preferences_->GetBoolean("java", &b)) prefs->java_enabled = b; - else if (web_preferences_->GetBoolean("text-areas-are-resizable", &b)) + if (web_preferences_->GetBoolean("text-areas-are-resizable", &b)) prefs->text_areas_are_resizable = b; - else if (web_preferences_->GetBoolean("webgl", &b)) + if (web_preferences_->GetBoolean("webgl", &b)) prefs->experimental_webgl_enabled = b; - else if (web_preferences_->GetBoolean("webaudio", &b)) + if (web_preferences_->GetBoolean("webaudio", &b)) prefs->webaudio_enabled = b; - else if (web_preferences_->GetBoolean("accelerated-compositing", &b)) + if (web_preferences_->GetBoolean("accelerated-compositing", &b)) prefs->accelerated_compositing_enabled = b; + if (web_preferences_->GetBoolean("plugins", &b)) + prefs->plugins_enabled = b; + if (web_preferences_->GetList("extra-plugin-dirs", &list)) + for (size_t i = 0; i < list->GetSize(); ++i) { + base::FilePath::StringType path_string; + if (list->GetString(i, &path_string)) { + base::FilePath path(path_string); + content::PluginService::GetInstance()->AddExtraPluginDir(path); + } + } } void NativeWindow::NotifyWindowClosed() { From 23d2dc5007e565a32b451bb0d4f6f4b438219af3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 22 May 2014 23:58:02 +0800 Subject: [PATCH 3/5] :memo: Document the 'web-preferences' option. --- docs/api/browser-window.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 384b6e2a7129..0d6b1af3df33 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -51,6 +51,18 @@ You can also create a window without chrome by using `manual-enable-iframe` or `disable`. * `accept-first-mouse` Boolean - Whether the web view accepts a single mouse-down event that simultaneously activates the window + * `web-preferences` Object - Settings of web page's features + * `javascript` Boolean + * `web-security` Boolean + * `images` Boolean + * `java` Boolean + * `text-areas-are-resizable` Boolean + * `webgl` Boolean + * `webaudio` Boolean + * `accelerated-compositing` Boolean + * `plugins` Boolean + * `extra-plugin-dirs` Array - Array of paths that would be searched for + plugins. Creates a new `BrowserWindow` with native properties set by the `options`. Usually you only need to set the `width` and `height`, other properties will From 542e795fe0b5f6ac8cc79ece4e639be57150f97f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 23 May 2014 22:56:56 +0800 Subject: [PATCH 4/5] :memo: Mention atom-shell's changes to the process object. --- docs/README.md | 1 + docs/api/process.md | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 docs/api/process.md diff --git a/docs/README.md b/docs/README.md index 99ad1a5f2a22..82ab7c5228b8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,6 +7,7 @@ ## API references * [Synopsis](api/synopsis.md) +* [Process object](api/process.md) Modules for browser side: diff --git a/docs/api/process.md b/docs/api/process.md new file mode 100644 index 000000000000..31fb95ce3523 --- /dev/null +++ b/docs/api/process.md @@ -0,0 +1,8 @@ +# Process object + +The `process` object in atom-shell has following differences between the one in +upstream node: + +* `process.type` String - Process's type, can be `browser` or `renderer`. +* `process.versions['atom-shell']` String - Version of atom-shell. +* `process.resourcesPath` String - Path to JavaScript source codes. From 2984c0d521edc19a2b36f9dae798d86e8469b8e2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 23 May 2014 23:07:38 +0800 Subject: [PATCH 5/5] :memo: Add details on plugins support. --- docs/api/browser-window.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 0d6b1af3df33..51c2e82d776d 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -60,9 +60,13 @@ You can also create a window without chrome by using * `webgl` Boolean * `webaudio` Boolean * `accelerated-compositing` Boolean - * `plugins` Boolean + * `plugins` Boolean - Whether plugins should be enabled, currently only + `NPAPI` plugins are supported. * `extra-plugin-dirs` Array - Array of paths that would be searched for - plugins. + plugins. Note that if you want to add a directory under your app, you + should use `__dirname` or `process.resourcesPath` to join the paths to + make them absolute, using relative paths would make atom-shell search + under current working directory. Creates a new `BrowserWindow` with native properties set by the `options`. Usually you only need to set the `width` and `height`, other properties will