Add the App.commandLine API to control Chromium's command line.

This commit is contained in:
Cheng Zhao 2013-05-17 15:39:44 +08:00
parent 394bf0a8d9
commit 61bca04dfd
4 changed files with 50 additions and 3 deletions

View file

@ -4,6 +4,7 @@
#include "browser/api/atom_api_app.h"
#include "base/command_line.h"
#include "browser/browser.h"
#include "vendor/node/src/node.h"
@ -58,6 +59,38 @@ v8::Handle<v8::Value> App::Terminate(const v8::Arguments &args) {
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::AppendSwitch(const v8::Arguments &args) {
v8::HandleScope scope;
if (!args[0]->IsString())
return node::ThrowError("Bad argument");
std::string switch_string(*v8::String::Utf8Value(args[0]));
if (args.Length() == 1) {
CommandLine::ForCurrentProcess()->AppendSwitch(switch_string);
} else {
std::string value(*v8::String::Utf8Value(args[1]));
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switch_string, value);
}
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::AppendArgument(const v8::Arguments &args) {
v8::HandleScope scope;
if (!args[0]->IsString())
return node::ThrowError("Bad argument");
std::string value(*v8::String::Utf8Value(args[0]));
CommandLine::ForCurrentProcess()->AppendArg(value);
return v8::Undefined();
}
// static
void App::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
@ -70,6 +103,9 @@ void App::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "terminate", Terminate);
target->Set(v8::String::NewSymbol("Application"), t->GetFunction());
NODE_SET_METHOD(target, "appendSwitch", AppendSwitch);
NODE_SET_METHOD(target, "appendArgument", AppendArgument);
}
} // namespace api

View file

@ -32,6 +32,8 @@ class App : public EventEmitter,
static v8::Handle<v8::Value> Quit(const v8::Arguments &args);
static v8::Handle<v8::Value> Terminate(const v8::Arguments &args);
static v8::Handle<v8::Value> AppendSwitch(const v8::Arguments &args);
static v8::Handle<v8::Value> AppendArgument(const v8::Arguments &args);
DISALLOW_COPY_AND_ASSIGN(App);
};

View file

@ -1,7 +1,14 @@
bindings = process.atomBinding 'app'
EventEmitter = require('events').EventEmitter
Application = process.atomBinding('app').Application
Application.prototype.__proto__ = EventEmitter.prototype
Application = bindings.Application
Application::__proto__ = EventEmitter.prototype
app = new Application
app.commandLine =
appendSwitch: bindings.appendSwitch,
appendArgument: bindings.appendArgument
# Only one App object pemitted.
module.exports = new Application
module.exports = app

View file

@ -14,6 +14,8 @@ app.on('window-all-closed', function() {
});
delegate.browserMainParts.preMainMessageLoopRun = function() {
app.commandLine.appendSwitch('js-flags', '--harmony_collections');
mainWindow = new BrowserWindow({ width: 800, height: 600 });
mainWindow.loadUrl('file://' + __dirname + '/index.html');