'common/platform_util.h',
'common/platform_util_mac.mm',
'common/platform_util_win.cc',
- 'common/string16_conversions.h',
'common/v8_conversions.h',
'common/v8_value_converter_impl.cc',
'common/v8_value_converter_impl.h',
#include "base/values.h"
#include "base/command_line.h"
#include "browser/browser.h"
+#include "common/v8_conversions.h"
#include "vendor/node/src/node.h"
namespace atom {
v8::Handle<v8::Value> App::AppendSwitch(const v8::Arguments &args) {
v8::HandleScope scope;
- if (!args[0]->IsString())
+ std::string switch_string;
+ if (!FromV8Arguments(args, &switch_string))
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]));
+ std::string value = FromV8Value(args[1]);
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switch_string, value);
}
v8::Handle<v8::Value> App::AppendArgument(const v8::Arguments &args) {
v8::HandleScope scope;
- if (!args[0]->IsString())
+ std::string value;
+ if (!FromV8Arguments(args, &value))
return node::ThrowError("Bad argument");
- std::string value(*v8::String::Utf8Value(args[0]));
CommandLine::ForCurrentProcess()->AppendArg(value);
return v8::Undefined();
// static
v8::Handle<v8::Value> App::DockBounce(const v8::Arguments& args) {
- std::string type(*v8::String::Utf8Value(args[0]));
+ std::string type = FromV8Value(args[0]);
int request_id = -1;
if (type == "critical")
// static
v8::Handle<v8::Value> App::DockCancelBounce(const v8::Arguments& args) {
- Browser::Get()->DockCancelBounce(args[0]->IntegerValue());
+ Browser::Get()->DockCancelBounce(FromV8Value(args[0]));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::DockSetBadgeText(const v8::Arguments& args) {
- std::string label(*v8::String::Utf8Value(args[0]));
- Browser::Get()->DockSetBadgeText(label);
+ Browser::Get()->DockSetBadgeText(FromV8Value(args[0]));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::DockGetBadgeText(const v8::Arguments& args) {
std::string text(Browser::Get()->DockGetBadgeText());
- return v8::String::New(text.data(), text.size());
+ return ToV8Value(text);
}
#endif // defined(OS_MACOSX)
#include "base/values.h"
#include "browser/auto_updater.h"
+#include "common/v8_conversions.h"
namespace atom {
// static
v8::Handle<v8::Value> AutoUpdater::SetFeedURL(const v8::Arguments &args) {
- auto_updater::AutoUpdater::SetFeedURL(*v8::String::Utf8Value(args[0]));
+ auto_updater::AutoUpdater::SetFeedURL(FromV8Value(args[0]));
return v8::Undefined();
}
#include "base/values.h"
#include "common/api/api_messages.h"
-#include "common/string16_conversions.h"
+#include "common/v8_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/render_view_host.h"
#include "vendor/node/src/node.h"
v8::Handle<v8::Value> BrowserIPC::Send(const v8::Arguments &args) {
v8::HandleScope scope;
- if (!args[0]->IsString() || !args[1]->IsNumber() || !args[2]->IsNumber())
+ string16 channel;
+ int process_id, routing_id;
+ if (!FromV8Arguments(args, &channel, &process_id, &routing_id))
return node::ThrowTypeError("Bad argument");
- string16 channel(FromV8Value(args[0]));
- int process_id = args[1]->IntegerValue();
- int routing_id = args[2]->IntegerValue();
-
RenderViewHost* render_view_host(RenderViewHost::FromID(
process_id, routing_id));
if (!render_view_host)
#include "browser/api/atom_api_crash_reporter.h"
#include "browser/crash_reporter.h"
+#include "common/v8_conversions.h"
#include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h"
// static
v8::Handle<v8::Value> CrashReporter::SetCompanyName(const v8::Arguments &args) {
- std::string name(*v8::String::Utf8Value(args[0]));
- crash_reporter::CrashReporter::SetCompanyName(name);
+ crash_reporter::CrashReporter::SetCompanyName(FromV8Value(args[0]));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> CrashReporter::SetSubmissionURL(
const v8::Arguments &args) {
- std::string url(*v8::String::Utf8Value(args[0]));
- crash_reporter::CrashReporter::SetSubmissionURL(url);
+ crash_reporter::CrashReporter::SetSubmissionURL(FromV8Value(args[0]));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> CrashReporter::SetAutoSubmit(const v8::Arguments &args) {
- crash_reporter::CrashReporter::SetAutoSubmit(args[0]->BooleanValue());
+ crash_reporter::CrashReporter::SetAutoSubmit(FromV8Value(args[0]));
return v8::Undefined();
}
#include "browser/native_window.h"
#include "common/api/api_messages.h"
-#include "common/string16_conversions.h"
+#include "common/v8_conversions.h"
using node::node_isolate;
#include "browser/api/atom_api_menu.h"
#include "browser/ui/accelerator_util.h"
-#include "common/string16_conversions.h"
#include "common/v8_conversions.h"
#define UNWRAP_MEMNU_AND_CHECK \
"getAcceleratorForCommandId",
command_id);
if (shortcut->IsString()) {
- std::string shortcut_str(*v8::String::Utf8Value(shortcut));
+ std::string shortcut_str = FromV8Value(shortcut);
return accelerator_util::StringToAccelerator(shortcut_str, accelerator);
}
v8::Handle<v8::Value> Menu::InsertItem(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- if (!args[0]->IsNumber() || !args[1]->IsNumber() || !args[2]->IsString())
+ int index, command_id;
+ string16 label;
+ if (!FromV8Arguments(args, &index, &command_id, &label))
return node::ThrowTypeError("Bad argument");
- int index = args[0]->IntegerValue();
-
if (index < 0)
- self->model_->AddItem(args[1]->IntegerValue(), FromV8Value(args[2]));
+ self->model_->AddItem(command_id, label);
else
- self->model_->InsertItemAt(
- index, args[1]->IntegerValue(), FromV8Value(args[2]));
+ self->model_->InsertItemAt(index, command_id, label);
return v8::Undefined();
}
v8::Handle<v8::Value> Menu::InsertCheckItem(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- if (!args[0]->IsNumber() || !args[1]->IsNumber() || !args[2]->IsString())
+ int index, command_id;
+ string16 label;
+ if (!FromV8Arguments(args, &index, &command_id, &label))
return node::ThrowTypeError("Bad argument");
- int index = args[0]->IntegerValue();
- int command_id = args[1]->IntegerValue();
-
if (index < 0)
- self->model_->AddCheckItem(command_id, FromV8Value(args[2]));
+ self->model_->AddCheckItem(command_id, label);
else
- self->model_->InsertCheckItemAt(index, command_id, FromV8Value(args[2]));
+ self->model_->InsertCheckItemAt(index, command_id, label);
return v8::Undefined();
}
v8::Handle<v8::Value> Menu::InsertRadioItem(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- if (!args[0]->IsNumber() ||
- !args[1]->IsNumber() ||
- !args[2]->IsString() ||
- !args[3]->IsNumber())
+ int index, command_id, group_id;
+ string16 label;
+ if (!FromV8Arguments(args, &index, &command_id, &label, &group_id))
return node::ThrowTypeError("Bad argument");
- int index = args[0]->IntegerValue();
- int command_id = args[1]->IntegerValue();
- int group_id = args[3]->IntegerValue();
-
if (index < 0)
- self->model_->AddRadioItem(command_id, FromV8Value(args[2]), group_id);
+ self->model_->AddRadioItem(command_id, label, group_id);
else
- self->model_->InsertRadioItemAt(
- index, command_id, FromV8Value(args[2]), group_id);
+ self->model_->InsertRadioItemAt(index, command_id, label, group_id);
return v8::Undefined();
}
v8::Handle<v8::Value> Menu::InsertSeparator(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- if (!args[0]->IsNumber())
+ int index;
+ if (!FromV8Arguments(args, &index))
return node::ThrowTypeError("Bad argument");
- int index = args[0]->IntegerValue();
-
if (index < 0)
self->model_->AddSeparator(ui::NORMAL_SEPARATOR);
else
v8::Handle<v8::Value> Menu::InsertSubMenu(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- if (!args[0]->IsNumber() ||
- !args[1]->IsNumber() ||
- !args[2]->IsString() ||
- !args[3]->IsObject())
+ int index, command_id;
+ string16 label;
+ if (!FromV8Arguments(args, &index, &command_id, &label))
return node::ThrowTypeError("Bad argument");
Menu* submenu = ObjectWrap::Unwrap<Menu>(args[3]->ToObject());
if (!submenu)
return node::ThrowTypeError("The submenu is already destroyed");
- int index = args[0]->IntegerValue();
- int command_id = args[1]->IntegerValue();
-
if (index < 0)
- self->model_->AddSubMenu(
- command_id, FromV8Value(args[2]), submenu->model_.get());
+ self->model_->AddSubMenu(command_id, label, submenu->model_.get());
else
self->model_->InsertSubMenuAt(
- index, command_id, FromV8Value(args[2]), submenu->model_.get());
+ index, command_id, label, submenu->model_.get());
return v8::Undefined();
}
v8::Handle<v8::Value> Menu::SetIcon(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- if (!args[0]->IsNumber() || !args[1]->IsString())
+ int index;
+ base::FilePath path;
+ if (!FromV8Arguments(args, &index, &path))
return node::ThrowTypeError("Bad argument");
// FIXME use webkit_glue's image decoder here.
v8::Handle<v8::Value> Menu::SetSublabel(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- if (!args[0]->IsNumber() || !args[1]->IsString())
+ int index;
+ string16 label;
+ if (!FromV8Arguments(args, &index, &label))
return node::ThrowTypeError("Bad argument");
- self->model_->SetSublabel(args[0]->IntegerValue(), FromV8Value(args[1]));
+ self->model_->SetSublabel(index, label);
return v8::Undefined();
}
v8::Handle<v8::Value> Menu::Popup(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- Window* window = Window::Unwrap<Window>(args[0]->ToObject());
- if (!window)
- return node::ThrowTypeError("Invalid window");
+ atom::NativeWindow* window;
+ if (!FromV8Arguments(args, &window))
+ return node::ThrowTypeError("Bad argument");
- self->Popup(window->window());
+ self->Popup(window);
return v8::Undefined();
}
#include "base/mac/scoped_sending_event.h"
#include "base/strings/sys_string_conversions.h"
#include "browser/native_window.h"
+#include "common/v8_conversions.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
const v8::Arguments &args) {
v8::HandleScope scope;
- if (!args[0]->IsString())
+ std::string action;
+ if (!FromV8Arguments(args, &action))
return node::ThrowTypeError("Bad argument");
- std::string action(*v8::String::Utf8Value(args[0]));
MenuMac::SendActionToFirstResponder(action);
return v8::Undefined();
#include "browser/net/adapter_request_job.h"
#include "browser/net/atom_url_request_context_getter.h"
#include "browser/net/atom_url_request_job_factory.h"
+#include "common/v8_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "net/url_request/url_request_context.h"
#include "vendor/node/src/node.h"
void EmitEventInUI(const std::string& event, const std::string& parameter) {
v8::HandleScope scope;
- v8::Local<v8::Value> argv[] = {
- v8::String::New(event.data(), event.size()),
- v8::String::New(parameter.data(), parameter.size()),
+ v8::Handle<v8::Value> argv[] = {
+ ToV8Value(event),
+ ToV8Value(parameter),
};
node::MakeCallback(g_protocol_object, "emit", arraysize(argv), argv);
}
// Determine the type of the job we are going to create.
if (result->IsString()) {
- std::string data = *v8::String::Utf8Value(result);
+ std::string data = FromV8Value(result);
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
return;
} else if (result->IsObject()) {
v8::Handle<v8::Object> obj = result->ToObject();
- std::string name = *v8::String::Utf8Value(obj->GetConstructorName());
+ std::string name = FromV8Value(obj->GetConstructorName());
if (name == "RequestStringJob") {
- std::string mime_type = *v8::String::Utf8Value(obj->Get(
+ std::string mime_type = FromV8Value(obj->Get(
v8::String::New("mimeType")));
- std::string charset = *v8::String::Utf8Value(obj->Get(
- v8::String::New("charset")));
- std::string data = *v8::String::Utf8Value(obj->Get(
- v8::String::New("data")));
+ std::string charset = FromV8Value(obj->Get(v8::String::New("charset")));
+ std::string data = FromV8Value(obj->Get(v8::String::New("data")));
content::BrowserThread::PostTask(
content::BrowserThread::IO,
data));
return;
} else if (name == "RequestFileJob") {
- base::FilePath path = base::FilePath::FromUTF8Unsafe(
- *v8::String::Utf8Value(obj->Get(v8::String::New("path"))));
+ base::FilePath path = FromV8Value(obj->Get(v8::String::New("path")));
content::BrowserThread::PostTask(
content::BrowserThread::IO,
// static
v8::Handle<v8::Value> Protocol::RegisterProtocol(const v8::Arguments& args) {
- std::string scheme(*v8::String::Utf8Value(args[0]));
+ std::string scheme;
+ v8::Persistent<v8::Function> callback;
+ if (!FromV8Arguments(args, &scheme, &callback))
+ return node::ThrowTypeError("Bad argument");
+
if (g_handlers.find(scheme) != g_handlers.end() ||
net::URLRequest::IsHandledProtocol(scheme))
return node::ThrowError("The scheme is already registered");
return node::ThrowError(kEarlyUseProtocolError);
// Store the handler in a map.
- if (!args[1]->IsFunction())
- return node::ThrowError("Handler must be a function");
- g_handlers[scheme] = v8::Persistent<v8::Function>::New(
- node::node_isolate, v8::Handle<v8::Function>::Cast(args[1]));
+ g_handlers[scheme] = callback;
content::BrowserThread::PostTask(content::BrowserThread::IO,
FROM_HERE,
// static
v8::Handle<v8::Value> Protocol::UnregisterProtocol(const v8::Arguments& args) {
- std::string scheme(*v8::String::Utf8Value(args[0]));
+ std::string scheme;
+ if (!FromV8Arguments(args, &scheme))
+ return node::ThrowTypeError("Bad argument");
if (AtomBrowserContext::Get()->url_request_context_getter() == NULL)
return node::ThrowError(kEarlyUseProtocolError);
// static
v8::Handle<v8::Value> Protocol::IsHandledProtocol(const v8::Arguments& args) {
- return v8::Boolean::New(net::URLRequest::IsHandledProtocol(
- *v8::String::Utf8Value(args[0])));
+ return ToV8Value(net::URLRequest::IsHandledProtocol(FromV8Value(args[0])));
}
// static
v8::Handle<v8::Value> Protocol::InterceptProtocol(const v8::Arguments& args) {
- std::string scheme(*v8::String::Utf8Value(args[0]));
+ std::string scheme;
+ v8::Persistent<v8::Function> callback;
+ if (!FromV8Arguments(args, &scheme, &callback))
+ return node::ThrowTypeError("Bad argument");
+
if (!GetRequestJobFactory()->HasProtocolHandler(scheme))
return node::ThrowError("Cannot intercept procotol");
return node::ThrowError(kEarlyUseProtocolError);
// Store the handler in a map.
- if (!args[1]->IsFunction())
- return node::ThrowError("Handler must be a function");
- g_handlers[scheme] = v8::Persistent<v8::Function>::New(
- node::node_isolate, v8::Handle<v8::Function>::Cast(args[1]));
+ g_handlers[scheme] = callback;
content::BrowserThread::PostTask(content::BrowserThread::IO,
FROM_HERE,
// static
v8::Handle<v8::Value> Protocol::UninterceptProtocol(const v8::Arguments& args) {
- std::string scheme(*v8::String::Utf8Value(args[0]));
+ std::string scheme;
+ if (!FromV8Arguments(args, &scheme))
+ return node::ThrowTypeError("Bad argument");
if (AtomBrowserContext::Get()->url_request_context_getter() == NULL)
return node::ThrowError(kEarlyUseProtocolError);
#include "base/values.h"
#include "browser/native_window.h"
-#include "common/string16_conversions.h"
+#include "common/v8_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
// static
v8::Handle<v8::Value> Window::IsFocused(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(self->window_->IsFocused());
+ return ToV8Value(self->window_->IsFocused());
}
// static
v8::Handle<v8::Value> Window::SetFullscreen(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1 || !args[0]->IsBoolean())
+ bool fs;
+ if (!FromV8Arguments(args, &fs))
return node::ThrowTypeError("Bad argument");
- self->window_->SetFullscreen(args[0]->BooleanValue());
+ self->window_->SetFullscreen(fs);
return v8::Undefined();
}
v8::Handle<v8::Value> Window::IsFullscreen(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(self->window_->IsFullscreen());
+ return ToV8Value(self->window_->IsFullscreen());
}
// static
v8::Handle<v8::Value> Window::SetSize(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 2)
+ int width, height;
+ if (!FromV8Arguments(args, &width, &height))
return node::ThrowTypeError("Bad argument");
- self->window_->SetSize(
- gfx::Size(args[0]->IntegerValue(), args[1]->IntegerValue()));
+ self->window_->SetSize(gfx::Size(width, height));
return v8::Undefined();
}
gfx::Size size = self->window_->GetSize();
v8::Handle<v8::Array> ret = v8::Array::New(2);
- ret->Set(0, v8::Integer::New(size.width()));
- ret->Set(1, v8::Integer::New(size.height()));
+ ret->Set(0, ToV8Value(size.width()));
+ ret->Set(1, ToV8Value(size.height()));
return ret;
}
v8::Handle<v8::Value> Window::SetMinimumSize(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 2)
+ int width, height;
+ if (!FromV8Arguments(args, &width, &height))
return node::ThrowTypeError("Bad argument");
- self->window_->SetMinimumSize(
- gfx::Size(args[0]->IntegerValue(), args[1]->IntegerValue()));
+ self->window_->SetMinimumSize(gfx::Size(width, height));
return v8::Undefined();
}
gfx::Size size = self->window_->GetMinimumSize();
v8::Handle<v8::Array> ret = v8::Array::New(2);
- ret->Set(0, v8::Integer::New(size.width()));
- ret->Set(1, v8::Integer::New(size.height()));
+ ret->Set(0, ToV8Value(size.width()));
+ ret->Set(1, ToV8Value(size.height()));
return ret;
}
v8::Handle<v8::Value> Window::SetMaximumSize(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 2)
+
+ int width, height;
+ if (!FromV8Arguments(args, &width, &height))
return node::ThrowTypeError("Bad argument");
- self->window_->SetMaximumSize(
- gfx::Size(args[0]->IntegerValue(), args[1]->IntegerValue()));
+ self->window_->SetMaximumSize(gfx::Size(width, height));
return v8::Undefined();
}
gfx::Size size = self->window_->GetMaximumSize();
v8::Handle<v8::Array> ret = v8::Array::New(2);
- ret->Set(0, v8::Integer::New(size.width()));
- ret->Set(1, v8::Integer::New(size.height()));
+ ret->Set(0, ToV8Value(size.width()));
+ ret->Set(1, ToV8Value(size.height()));
return ret;
}
v8::Handle<v8::Value> Window::SetResizable(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1 || !args[0]->IsBoolean())
+ bool resizable;
+ if (!FromV8Arguments(args, &resizable))
return node::ThrowTypeError("Bad argument");
- self->window_->SetResizable(args[0]->BooleanValue());
+ self->window_->SetResizable(resizable);
return v8::Undefined();
}
v8::Handle<v8::Value> Window::IsResizable(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(self->window_->IsResizable());
+ return ToV8Value(self->window_->IsResizable());
}
// static
v8::Handle<v8::Value> Window::SetAlwaysOnTop(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1 || !args[0]->IsBoolean())
+ bool top;
+ if (!FromV8Arguments(args, &top))
return node::ThrowTypeError("Bad argument");
- self->window_->SetAlwaysOnTop(args[0]->BooleanValue());
+ self->window_->SetAlwaysOnTop(top);
return v8::Undefined();
}
v8::Handle<v8::Value> Window::IsAlwaysOnTop(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(self->window_->IsAlwaysOnTop());
+ return ToV8Value(self->window_->IsAlwaysOnTop());
}
// static
v8::Handle<v8::Value> Window::SetPosition(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 2)
+ int x, y;
+ if (!FromV8Arguments(args, &x, &y))
return node::ThrowTypeError("Bad argument");
- self->window_->SetPosition(
- gfx::Point(args[0]->IntegerValue(), args[1]->IntegerValue()));
+ self->window_->SetPosition(gfx::Point(x, y));
return v8::Undefined();
}
gfx::Point pos = self->window_->GetPosition();
v8::Handle<v8::Array> ret = v8::Array::New(2);
- ret->Set(0, v8::Integer::New(pos.x()));
- ret->Set(1, v8::Integer::New(pos.y()));
+ ret->Set(0, ToV8Value(pos.x()));
+ ret->Set(1, ToV8Value(pos.y()));
return ret;
}
v8::Handle<v8::Value> Window::SetTitle(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1 || !args[0]->IsString())
+ std::string title;
+ if (!FromV8Arguments(args, &title))
return node::ThrowTypeError("Bad argument");
- self->window_->SetTitle(*v8::String::Utf8Value(args[0]));
+ self->window_->SetTitle(title);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetTitle(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
-
- std::string title = self->window_->GetTitle();
-
- return v8::String::New(title.c_str(), title.size());
+ return ToV8Value(self->window_->GetTitle());
}
// static
v8::Handle<v8::Value> Window::SetKiosk(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1 || !args[0]->IsBoolean())
+ bool kiosk;
+ if (!FromV8Arguments(args, &kiosk))
return node::ThrowTypeError("Bad argument");
- self->window_->SetKiosk(args[0]->BooleanValue());
+ self->window_->SetKiosk(kiosk);
return v8::Undefined();
}
v8::Handle<v8::Value> Window::IsKiosk(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(self->window_->IsKiosk());
+ return ToV8Value(self->window_->IsKiosk());
}
// static
v8::Handle<v8::Value> Window::InspectElement(const v8::Arguments& args) {
UNWRAP_WINDOW_AND_CHECK;
- self->window_->InspectElement(args[0]->IntegerValue(),
- args[1]->IntegerValue());
+ int x, y;
+ if (!FromV8Arguments(args, &x, &y))
+ return node::ThrowTypeError("Bad argument");
+ self->window_->InspectElement(x, y);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsWebViewFocused(const v8::Arguments& args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(self->window_->IsWebViewFocused());
+ return ToV8Value(self->window_->IsWebViewFocused());
}
// static
v8::Handle<v8::Value> Window::GetPageTitle(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- string16 title = self->window_->GetWebContents()->GetTitle();
-
- return ToV8Value(title);
+ return ToV8Value(self->window_->GetWebContents()->GetTitle());
}
// static
v8::Handle<v8::Value> Window::IsLoading(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(self->window_->GetWebContents()->IsLoading());
+ return ToV8Value(self->window_->GetWebContents()->IsLoading());
}
// static
v8::Handle<v8::Value> Window::IsWaitingForResponse(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(
- self->window_->GetWebContents()->IsWaitingForResponse());
+ return ToV8Value(self->window_->GetWebContents()->IsWaitingForResponse());
}
// static
v8::Handle<v8::Value> Window::GetRoutingID(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Integer::New(self->window_->GetWebContents()->GetRoutingID());
+ return ToV8Value(self->window_->GetWebContents()->GetRoutingID());
}
// static
v8::Handle<v8::Value> Window::GetProcessID(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Integer::New(
+ return ToV8Value(
self->window_->GetWebContents()->GetRenderProcessHost()->GetID());
}
v8::Handle<v8::Value> Window::IsCrashed(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- return v8::Boolean::New(self->window_->GetWebContents()->IsCrashed());
+ return ToV8Value(self->window_->GetWebContents()->IsCrashed());
}
// static
v8::Handle<v8::Value> Window::LoadURL(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1 || !args[0]->IsString())
+ std::string url;
+ if (!FromV8Arguments(args, &url))
return node::ThrowTypeError("Bad argument");
NavigationController& controller =
self->window_->GetWebContents()->GetController();
- controller.LoadURL(GURL(*v8::String::Utf8Value(args[0])),
+ controller.LoadURL(GURL(url),
content::Referrer(),
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
if (controller.GetActiveEntry())
url = controller.GetActiveEntry()->GetVirtualURL().spec();
- return v8::String::New(url.c_str(), url.size());
+ return ToV8Value(url);
}
// static
NavigationController& controller =
self->window_->GetWebContents()->GetController();
- return v8::Boolean::New(controller.CanGoBack());
+ return ToV8Value(controller.CanGoBack());
}
// static
NavigationController& controller =
self->window_->GetWebContents()->GetController();
- return v8::Boolean::New(controller.CanGoForward());
+ return ToV8Value(controller.CanGoForward());
}
// static
v8::Handle<v8::Value> Window::CanGoToOffset(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1)
+ int offset;
+ if (!FromV8Arguments(args, &offset))
return node::ThrowTypeError("Bad argument");
NavigationController& controller =
self->window_->GetWebContents()->GetController();
- int offset = args[0]->IntegerValue();
- return v8::Boolean::New(controller.CanGoToOffset(offset));
+ return ToV8Value(controller.CanGoToOffset(offset));
}
// static
v8::Handle<v8::Value> Window::GoToIndex(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1)
+ int index;
+ if (!FromV8Arguments(args, &index))
return node::ThrowTypeError("Bad argument");
NavigationController& controller =
self->window_->GetWebContents()->GetController();
- controller.GoToIndex(args[0]->IntegerValue());
+ controller.GoToIndex(index);
return v8::Undefined();
}
v8::Handle<v8::Value> Window::GoToOffset(const v8::Arguments &args) {
UNWRAP_WINDOW_AND_CHECK;
- if (args.Length() < 1)
+ int offset;
+ if (!FromV8Arguments(args, &offset))
return node::ThrowTypeError("Bad argument");
NavigationController& controller =
self->window_->GetWebContents()->GetController();
- controller.GoToOffset(args[0]->IntegerValue());
+ controller.GoToOffset(offset);
return v8::Undefined();
}
#include "base/logging.h"
#include "base/values.h"
#include "browser/api/atom_api_event.h"
-#include "common/string16_conversions.h"
+#include "common/v8_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/browser_thread.h"
#include "vendor/node/src/node.h"
+++ /dev/null
-// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMMON_STRING16_CONVERSIONS_H_
-#define COMMON_STRING16_CONVERSIONS_H_
-
-#include "base/string16.h"
-#include "v8/include/v8.h"
-
-// Converts a V8 value to a string16.
-inline string16 FromV8Value(v8::Handle<v8::Value> value) {
- v8::String::Value s(value);
- return string16(reinterpret_cast<const char16*>(*s), s.length());
-}
-
-// Converts string16 to V8 String.
-inline v8::Handle<v8::Value> ToV8Value(const string16& s) {
- return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
-}
-
-#endif // COMMON_STRING16_CONVERSIONS_H_
#include <vector>
#include "base/files/file_path.h"
+#include "base/string16.h"
#include "browser/api/atom_api_window.h"
#include "v8/include/v8.h"
struct FromV8Value {
explicit FromV8Value(v8::Handle<v8::Value> value) : value_(value) {}
+ operator int() {
+ return value_->IntegerValue();
+ }
+
+ operator bool() {
+ return value_->BooleanValue();
+ }
+
operator std::string() {
return *v8::String::Utf8Value(value_);
}
- operator int() {
- return value_->IntegerValue();
+ operator string16() {
+ v8::String::Value s(value_);
+ return string16(reinterpret_cast<const char16*>(*s), s.length());
}
operator base::FilePath() {
};
// Convert arbitrary supported native type to V8 value.
+inline v8::Handle<v8::Value> ToV8Value(int i) {
+ return v8::Integer::New(i);
+}
+
+inline v8::Handle<v8::Value> ToV8Value(bool b) {
+ return v8::Boolean::New(b);
+}
+
+inline v8::Handle<v8::Value> ToV8Value(const std::string& s) {
+ return v8::String::New(s.data(), s.size());
+}
+
+inline v8::Handle<v8::Value> ToV8Value(const string16& s) {
+ return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
+}
+
inline v8::Handle<v8::Value> ToV8Value(const base::FilePath& path) {
std::string path_string(path.AsUTF8Unsafe());
return v8::String::New(path_string.data(), path_string.size());
return v8::Undefined();
}
-inline v8::Handle<v8::Value> ToV8Value(int code) {
- return v8::Integer::New(code);
-}
-
inline
v8::Handle<v8::Value> ToV8Value(const std::vector<base::FilePath>& paths) {
v8::Handle<v8::Array> result = v8::Array::New(paths.size());
}
template<> inline
+bool V8ValueCanBeConvertedTo<bool>(v8::Handle<v8::Value> value) {
+ return value->IsBoolean();
+}
+
+template<> inline
bool V8ValueCanBeConvertedTo<std::string>(v8::Handle<v8::Value> value) {
return value->IsString();
}
template<> inline
+bool V8ValueCanBeConvertedTo<string16>(v8::Handle<v8::Value> value) {
+ return V8ValueCanBeConvertedTo<std::string>(value);
+}
+
+template<> inline
bool V8ValueCanBeConvertedTo<base::FilePath>(v8::Handle<v8::Value> value) {
return V8ValueCanBeConvertedTo<std::string>(value);
}
#include "base/values.h"
#include "common/api/api_messages.h"
-#include "common/string16_conversions.h"
+#include "common/v8_conversions.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/v8_value_converter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "base/logging.h"
#include "base/values.h"
-#include "common/string16_conversions.h"
+#include "common/v8_conversions.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/v8_value_converter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"