Use the convient V8 wrapper in all files.
This commit is contained in:
parent
a824c88352
commit
11ca836afc
15 changed files with 198 additions and 193 deletions
1
atom.gyp
1
atom.gyp
|
@ -157,7 +157,6 @@
|
|||
'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',
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#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 {
|
||||
|
@ -111,14 +112,14 @@ v8::Handle<v8::Value> App::GetVersion(const v8::Arguments &args) {
|
|||
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);
|
||||
}
|
||||
|
@ -130,10 +131,10 @@ v8::Handle<v8::Value> App::AppendSwitch(const v8::Arguments &args) {
|
|||
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();
|
||||
|
@ -143,7 +144,7 @@ v8::Handle<v8::Value> App::AppendArgument(const v8::Arguments &args) {
|
|||
|
||||
// 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")
|
||||
|
@ -158,21 +159,20 @@ v8::Handle<v8::Value> App::DockBounce(const v8::Arguments& args) {
|
|||
|
||||
// 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)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "base/values.h"
|
||||
#include "browser/auto_updater.h"
|
||||
#include "common/v8_conversions.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -56,7 +57,7 @@ v8::Handle<v8::Value> AutoUpdater::New(const v8::Arguments &args) {
|
|||
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#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"
|
||||
|
@ -23,13 +23,11 @@ namespace api {
|
|||
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)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#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"
|
||||
|
||||
|
@ -14,22 +15,20 @@ namespace api {
|
|||
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#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;
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#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 \
|
||||
|
@ -83,7 +82,7 @@ bool Menu::GetAcceleratorForCommandId(int command_id,
|
|||
"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);
|
||||
}
|
||||
|
||||
|
@ -135,16 +134,15 @@ v8::Handle<v8::Value> Menu::New(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
@ -153,16 +151,15 @@ v8::Handle<v8::Value> Menu::InsertItem(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
@ -171,21 +168,15 @@ v8::Handle<v8::Value> Menu::InsertCheckItem(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
@ -194,11 +185,10 @@ v8::Handle<v8::Value> Menu::InsertRadioItem(const v8::Arguments &args) {
|
|||
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
|
||||
|
@ -211,25 +201,20 @@ v8::Handle<v8::Value> Menu::InsertSeparator(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
@ -238,7 +223,9 @@ v8::Handle<v8::Value> Menu::InsertSubMenu(const v8::Arguments &args) {
|
|||
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.
|
||||
|
@ -250,10 +237,12 @@ v8::Handle<v8::Value> Menu::SetIcon(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
@ -324,11 +313,11 @@ v8::Handle<v8::Value> Menu::IsVisibleAt(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#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"
|
||||
|
||||
|
@ -95,10 +96,10 @@ v8::Handle<v8::Value> Menu::SendActionToFirstResponder(
|
|||
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();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#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"
|
||||
|
@ -36,9 +37,9 @@ static const char* kEarlyUseProtocolError = "This method can only be used"
|
|||
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);
|
||||
}
|
||||
|
@ -83,7 +84,7 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
|||
|
||||
// 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,
|
||||
|
@ -95,14 +96,12 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
|||
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,
|
||||
|
@ -114,8 +113,7 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
|||
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,
|
||||
|
@ -183,7 +181,11 @@ class CustomProtocolHandler : public ProtocolHandler {
|
|||
|
||||
// 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");
|
||||
|
@ -192,10 +194,7 @@ v8::Handle<v8::Value> Protocol::RegisterProtocol(const v8::Arguments& args) {
|
|||
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,
|
||||
|
@ -206,7 +205,9 @@ v8::Handle<v8::Value> Protocol::RegisterProtocol(const v8::Arguments& args) {
|
|||
|
||||
// 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);
|
||||
|
@ -226,13 +227,16 @@ v8::Handle<v8::Value> Protocol::UnregisterProtocol(const v8::Arguments& args) {
|
|||
|
||||
// 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");
|
||||
|
||||
|
@ -243,10 +247,7 @@ v8::Handle<v8::Value> Protocol::InterceptProtocol(const v8::Arguments& args) {
|
|||
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,
|
||||
|
@ -256,7 +257,9 @@ v8::Handle<v8::Value> Protocol::InterceptProtocol(const v8::Arguments& args) {
|
|||
|
||||
// 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);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#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"
|
||||
|
@ -133,7 +133,7 @@ v8::Handle<v8::Value> Window::Focus(const v8::Arguments &args) {
|
|||
// 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
|
||||
|
@ -194,10 +194,11 @@ v8::Handle<v8::Value> Window::Restore(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -205,18 +206,18 @@ v8::Handle<v8::Value> Window::SetFullscreen(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -226,8 +227,8 @@ v8::Handle<v8::Value> Window::GetSize(const v8::Arguments &args) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -236,11 +237,11 @@ v8::Handle<v8::Value> Window::GetSize(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -250,8 +251,8 @@ v8::Handle<v8::Value> Window::GetMinimumSize(const v8::Arguments &args) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -260,11 +261,12 @@ v8::Handle<v8::Value> Window::GetMinimumSize(const v8::Arguments &args) {
|
|||
v8::Handle<v8::Value> Window::SetMaximumSize(const v8::Arguments &args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
|
||||
if (args.Length() < 2)
|
||||
return node::ThrowTypeError("Bad argument");
|
||||
self->window_->SetMaximumSize(
|
||||
gfx::Size(args[0]->IntegerValue(), args[1]->IntegerValue()));
|
||||
|
||||
int width, height;
|
||||
if (!FromV8Arguments(args, &width, &height))
|
||||
return node::ThrowTypeError("Bad argument");
|
||||
|
||||
self->window_->SetMaximumSize(gfx::Size(width, height));
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
|
@ -274,8 +276,8 @@ v8::Handle<v8::Value> Window::GetMaximumSize(const v8::Arguments &args) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -284,10 +286,11 @@ v8::Handle<v8::Value> Window::GetMaximumSize(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -295,17 +298,18 @@ v8::Handle<v8::Value> Window::SetResizable(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -313,7 +317,7 @@ v8::Handle<v8::Value> Window::SetAlwaysOnTop(const v8::Arguments &args) {
|
|||
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
|
||||
|
@ -329,11 +333,11 @@ v8::Handle<v8::Value> Window::Center(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -343,8 +347,8 @@ v8::Handle<v8::Value> Window::GetPosition(const v8::Arguments &args) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -353,20 +357,18 @@ v8::Handle<v8::Value> Window::GetPosition(const v8::Arguments &args) {
|
|||
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
|
||||
|
@ -383,10 +385,11 @@ v8::Handle<v8::Value> Window::FlashFrame(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -394,7 +397,7 @@ v8::Handle<v8::Value> Window::SetKiosk(const v8::Arguments &args) {
|
|||
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
|
||||
|
@ -419,9 +422,11 @@ v8::Handle<v8::Value> Window::CloseDevTools(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -446,7 +451,7 @@ v8::Handle<v8::Value> Window::BlurWebView(const v8::Arguments &args) {
|
|||
// 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
|
||||
|
@ -463,24 +468,21 @@ v8::Handle<v8::Value> Window::RestartHangMonitorTimeout(
|
|||
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
|
||||
|
@ -496,14 +498,14 @@ v8::Handle<v8::Value> Window::Stop(const v8::Arguments &args) {
|
|||
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());
|
||||
}
|
||||
|
||||
|
@ -511,19 +513,20 @@ v8::Handle<v8::Value> Window::GetProcessID(const v8::Arguments &args) {
|
|||
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());
|
||||
|
@ -541,7 +544,7 @@ v8::Handle<v8::Value> Window::GetURL(const v8::Arguments &args) {
|
|||
if (controller.GetActiveEntry())
|
||||
url = controller.GetActiveEntry()->GetVirtualURL().spec();
|
||||
|
||||
return v8::String::New(url.c_str(), url.size());
|
||||
return ToV8Value(url);
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -551,7 +554,7 @@ v8::Handle<v8::Value> Window::CanGoBack(const v8::Arguments &args) {
|
|||
NavigationController& controller =
|
||||
self->window_->GetWebContents()->GetController();
|
||||
|
||||
return v8::Boolean::New(controller.CanGoBack());
|
||||
return ToV8Value(controller.CanGoBack());
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -561,21 +564,21 @@ v8::Handle<v8::Value> Window::CanGoForward(const v8::Arguments &args) {
|
|||
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
|
||||
|
@ -604,12 +607,13 @@ v8::Handle<v8::Value> Window::GoForward(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
@ -618,12 +622,13 @@ v8::Handle<v8::Value> Window::GoToIndex(const v8::Arguments &args) {
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#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"
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
// 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_
|
|
@ -9,6 +9,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/string16.h"
|
||||
#include "browser/api/atom_api_window.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
|
@ -16,12 +17,21 @@
|
|||
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() {
|
||||
|
@ -59,6 +69,22 @@ struct FromV8Value {
|
|||
};
|
||||
|
||||
// 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());
|
||||
|
@ -68,10 +94,6 @@ inline v8::Handle<v8::Value> ToV8Value(void* whatever) {
|
|||
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());
|
||||
|
@ -91,11 +113,21 @@ bool V8ValueCanBeConvertedTo<int>(v8::Handle<v8::Value> value) {
|
|||
return value->IsNumber();
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#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"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#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"
|
||||
|
|
Loading…
Reference in a new issue