Merge pull request #4014 from atom/blink-features

Add blinkFeatures option
This commit is contained in:
Cheng Zhao 2016-01-07 14:58:10 +08:00
commit ae6c2d46b8
7 changed files with 150 additions and 199 deletions

View file

@ -10,6 +10,7 @@
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/web_preferences.h"
#include "native_mate/dictionary.h"
#include "net/base/filename_util.h"
@ -22,28 +23,6 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::WebContentsPreferences);
namespace atom {
namespace {
// Array of available web runtime features.
struct FeaturePair {
const char* name;
const char* cmd;
};
FeaturePair kWebRuntimeFeatures[] = {
{ options::kExperimentalFeatures,
switches::kExperimentalFeatures },
{ options::kExperimentalCanvasFeatures,
switches::kExperimentalCanvasFeatures },
{ options::kOverlayScrollbars,
switches::kOverlayScrollbars },
{ options::kSharedWorker,
switches::kSharedWorker },
{ options::kPageVisibility,
switches::kPageVisibility },
};
} // namespace
WebContentsPreferences::WebContentsPreferences(
content::WebContents* web_contents,
const mate::Dictionary& web_preferences) {
@ -85,13 +64,12 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
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 auto& feature = kWebRuntimeFeatures[i];
if (web_preferences.GetBoolean(feature.name, &b))
command_line->AppendSwitchASCII(feature.cmd, b ? "true" : "false");
}
// Experimental flags.
if (web_preferences.GetBoolean(options::kExperimentalFeatures, &b) && b)
command_line->AppendSwitch(
::switches::kEnableExperimentalWebPlatformFeatures);
if (web_preferences.GetBoolean(options::kExperimentalCanvasFeatures, &b) && b)
command_line->AppendSwitch(::switches::kEnableExperimentalCanvasFeatures);
// Check if we have node integration specified.
bool node_integration = true;
@ -138,6 +116,12 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
if (web_preferences.GetInteger(options::kOpenerID, &opener_id))
command_line->AppendSwitchASCII(switches::kOpenerID,
base::IntToString(opener_id));
// Enable blink features.
std::string blink_features;
if (web_preferences.GetString(options::kBlinkFeatures, &blink_features))
command_line->AppendSwitchASCII(::switches::kEnableBlinkFeatures,
blink_features);
}
// static

View file

@ -85,20 +85,18 @@ const char kNodeIntegration[] = "nodeIntegration";
// Instancd ID of guest WebContents.
const char kGuestInstanceID[] = "guestInstanceId";
// Set page visiblity to always visible.
const char kPageVisibility[] = "pageVisibility";
// Enable DirectWrite on Windows.
const char kDirectWrite[] = "directWrite";
// Opener window's ID.
const char kOpenerID[] = "openerId";
// Web runtime features.
const char kExperimentalFeatures[] = "experimentalFeatures";
const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures";
const char kOverlayScrollbars[] = "overlayScrollbars";
const char kSharedWorker[] = "sharedWorker";
// Opener window's ID.
const char kOpenerID[] = "openerId";
// Enable blink features.
const char kBlinkFeatures[] = "blinkFeatures";
} // namespace options
@ -141,11 +139,6 @@ const char kPreloadScript[] = "preload";
const char kPreloadURL[] = "preload-url";
const char kNodeIntegration[] = "node-integration";
const char kGuestInstanceID[] = "guest-instance-id";
const char kExperimentalFeatures[] = "experimental-features";
const char kExperimentalCanvasFeatures[] = "experimental-canvas-features";
const char kOverlayScrollbars[] = "overlay-scrollbars";
const char kSharedWorker[] = "shared-worker";
const char kPageVisibility[] = "page-visiblity";
const char kOpenerID[] = "opener-id";
// Widevine options

View file

@ -49,10 +49,8 @@ extern const char kNodeIntegration[];
extern const char kGuestInstanceID[];
extern const char kExperimentalFeatures[];
extern const char kExperimentalCanvasFeatures[];
extern const char kOverlayScrollbars[];
extern const char kSharedWorker[];
extern const char kPageVisibility[];
extern const char kOpenerID[];
extern const char kBlinkFeatures[];
} // namespace options
@ -77,11 +75,6 @@ extern const char kPreloadScript[];
extern const char kPreloadURL[];
extern const char kNodeIntegration[];
extern const char kGuestInstanceID[];
extern const char kExperimentalFeatures[];
extern const char kExperimentalCanvasFeatures[];
extern const char kOverlayScrollbars[];
extern const char kSharedWorker[];
extern const char kPageVisibility[];
extern const char kOpenerID[];
extern const char kWidevineCdmPath[];

View file

@ -41,11 +41,6 @@ namespace atom {
namespace {
bool IsSwitchEnabled(base::CommandLine* command_line,
const char* switch_string) {
return command_line->GetSwitchValueASCII(switch_string) == "true";
}
// Helper class to forward the messages to the client.
class AtomRenderFrameObserver : public content::RenderFrameObserver {
public:
@ -95,8 +90,6 @@ AtomRendererClient::~AtomRendererClient() {
}
void AtomRendererClient::WebKitInitialized() {
EnableWebRuntimeFeatures();
blink::WebCustomElement::addEmbedderCustomElementName("webview");
blink::WebCustomElement::addEmbedderCustomElementName("browserplugin");
@ -210,32 +203,6 @@ content::BrowserPluginDelegate* AtomRendererClient::CreateBrowserPluginDelegate(
}
}
bool AtomRendererClient::ShouldOverridePageVisibilityState(
const content::RenderFrame* render_frame,
blink::WebPageVisibilityState* override_state) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (IsSwitchEnabled(command_line, switches::kPageVisibility)) {
*override_state = blink::WebPageVisibilityStateVisible;
return true;
}
return false;
}
void AtomRendererClient::EnableWebRuntimeFeatures() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (IsSwitchEnabled(command_line, switches::kExperimentalFeatures))
blink::WebRuntimeFeatures::enableExperimentalFeatures(true);
if (IsSwitchEnabled(command_line, switches::kExperimentalCanvasFeatures))
blink::WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
if (IsSwitchEnabled(command_line, switches::kOverlayScrollbars))
blink::WebRuntimeFeatures::enableOverlayScrollbars(true);
if (IsSwitchEnabled(command_line, switches::kSharedWorker))
blink::WebRuntimeFeatures::enableSharedWorker(true);
}
void AtomRendererClient::AddKeySystems(
std::vector<media::KeySystemInfo>* key_systems) {
AddChromeKeySystems(key_systems);

View file

@ -56,13 +56,8 @@ class AtomRendererClient : public content::ContentRendererClient,
content::RenderFrame* render_frame,
const std::string& mime_type,
const GURL& original_url) override;
bool ShouldOverridePageVisibilityState(
const content::RenderFrame* render_frame,
blink::WebPageVisibilityState* override_state) override;
void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems) override;
void EnableWebRuntimeFeatures();
scoped_ptr<NodeBindings> node_bindings_;
scoped_ptr<AtomBindings> atom_bindings_;

View file

@ -31,8 +31,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
### `new BrowserWindow([options])`
`options` Object (optional), properties:
* `options` Object
* `width` Integer - Window's width in pixels. Default is `800`.
* `height` Integer - Window's height in pixels. Default is `600`.
* `x` Integer - Window's left offset from screen. Default is to center the
@ -78,20 +77,29 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
some GTK+3 desktop environments. Default is `false`.
* `transparent` Boolean - Makes the window [transparent](frameless-window.md).
Default is `false`.
* `type` String - Specifies the type of the window, which applies
additional platform-specific properties. By default it's undefined and you'll
get a regular app window. Supported values:
* `type` String - The type of window, default is normal window. See more about
this bellow.
* `titleBarStyle` String - The style of window title bar. See more about this
bellow.
* `webPreferences` Object - Settings of web page's features. See more about
this bellow.
The possible values and behaviors of `type` option are platform dependent,
supported values are:
* On Linux, possible types are `desktop`, `dock`, `toolbar`, `splash`,
`notification`.
* On OS X, possible types are `desktop`, `textured`. The `textured` type adds
metal gradient appearance (`NSTexturedBackgroundWindowMask`). The `desktop`
type places the window at the desktop background window level
* On OS X, possible types are `desktop`, `textured`.
* The `textured` type adds metal gradient appearance
(`NSTexturedBackgroundWindowMask`).
* The `desktop` type places the window at the desktop background window level
(`kCGDesktopWindowLevel - 1`). Note that desktop window will not receive
focus, keyboard or mouse events, but you can use `globalShortcut` to receive
input sparingly.
* `titleBarStyle` String, OS X - specifies the style of window title bar.
This option is supported on OS X 10.10 Yosemite and newer. There are three
possible values:
The `titleBarStyle` option is only supported on OS X 10.10 Yosemite and newer.
Possible values are:
* `default` or not specified, results in the standard gray opaque Mac title
bar.
* `hidden` results in a hidden title bar and a full size content window, yet
@ -99,7 +107,9 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
the top left.
* `hidden-inset` results in a hidden title bar with an alternative look
where the traffic light buttons are slightly more inset from the window edge.
* `webPreferences` Object - Settings of web page's features, properties:
The `webPreferences` option is an object that can have following properties:
* `nodeIntegration` Boolean - Whether node integration is enabled. Default
is `true`.
* `preload` String - Specifies a script that will be loaded before other
@ -136,15 +146,12 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
Default is `false`.
* `experimentalCanvasFeatures` Boolean - Enables Chromium's experimental
canvas features. Default is `false`.
* `overlayScrollbars` Boolean - Enables overlay scrollbars. Default is
`false`.
* `sharedWorker` Boolean - Enables Shared Worker support. Default is `false`.
* `directWrite` Boolean - Enables DirectWrite font rendering system on
Windows. Default is `true`.
* `pageVisibility` Boolean - Page would be forced to be always in visible
or hidden state once set, instead of reflecting current window's
visibility. Users can set it to `true` to prevent throttling of DOM
timers. Default is `false`.
* `blinkFeatures` String - A list of feature strings separated by `,`, like
`CSSVariables,KeyboardEventKey`. The full list of supported feature strings
can be found in the [setFeatureEnabledFromString][blink-feature-string]
function.
## Events
@ -757,3 +764,5 @@ Returns whether the window is visible on all workspaces.
* `ignore` Boolean
Ignore all moused events that happened in the window.
[blink-feature-string]: https://code.google.com/p/chromium/codesearch#chromium/src/out/Debug/gen/blink/platform/RuntimeEnabledFeatures.cpp&sq=package:chromium&type=cs&l=527

View file

@ -94,10 +94,6 @@ connection, and the endpoint host in a `SOCKS` proxy connection).
Like `--host-rules` but these `rules` only apply to the host resolver.
[app]: app.md
[append-switch]: app.md#appcommandlineappendswitchswitch-value
[ready]: app.md#event-ready
## --ignore-certificate-errors
Ignores certificate related errors.
@ -121,7 +117,16 @@ fallback will accept.
## --cipher-suite-blacklist=`cipher_suites`
Specify comma-separated list of SSL cipher suites to disable.
Specifies comma-separated list of SSL cipher suites to disable.
## --disable-renderer-backgrounding
Prevents Chromium from lowering the priority of invisible pages' renderer
processes.
This flag is global to all renderer processes, if you only want to disable
throttling in one window, you can take the hack of
[playing silent audio][play-silent-audio].
## --enable-logging
@ -149,3 +154,8 @@ whole pathname and not just the module. E.g. `*/foo/bar/*=2` would change the
logging level for all code in the source files under a `foo/bar` directory.
This switch only works when `--enable-logging` is also passed.
[app]: app.md
[append-switch]: app.md#appcommandlineappendswitchswitch-value
[ready]: app.md#event-ready
[play-silent-audio]: https://github.com/atom/atom/pull/9485/files