Huge commit to use new V8 and Content APIs.

Still got a lots of linking errors!
This commit is contained in:
Cheng Zhao 2013-12-11 15:48:19 +08:00
parent d82cfc023f
commit 409a431892
78 changed files with 969 additions and 1057 deletions

View file

@ -7,8 +7,9 @@
#include "base/values.h"
#include "base/command_line.h"
#include "browser/browser.h"
#include "common/v8_conversions.h"
#include "vendor/node/src/node.h"
#include "common/v8/native_type_conversions.h"
#include "common/v8/node_common.h"
namespace atom {
@ -52,93 +53,65 @@ void App::OnFinishLaunching() {
}
// static
v8::Handle<v8::Value> App::New(const v8::Arguments& args) {
v8::HandleScope scope;
void App::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope scope(args.GetIsolate());
if (!args.IsConstructCall())
return node::ThrowError("Require constructor call");
new App(args.This());
return args.This();
}
// static
v8::Handle<v8::Value> App::Quit(const v8::Arguments& args) {
v8::HandleScope scope;
void App::Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
Browser::Get()->Quit();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::Exit(const v8::Arguments& args) {
v8::HandleScope scope;
void App::Exit(const v8::FunctionCallbackInfo<v8::Value>& args) {
exit(args[0]->IntegerValue());
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::Terminate(const v8::Arguments& args) {
v8::HandleScope scope;
void App::Terminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
Browser::Get()->Terminate();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::Focus(const v8::Arguments& args) {
v8::HandleScope scope;
void App::Focus(const v8::FunctionCallbackInfo<v8::Value>& args) {
Browser::Get()->Focus();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::GetVersion(const v8::Arguments& args) {
return ToV8Value(Browser::Get()->GetVersion());
void App::GetVersion(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(ToV8Value(Browser::Get()->GetVersion()));
}
// static
v8::Handle<v8::Value> App::SetVersion(const v8::Arguments& args) {
v8::HandleScope scope;
void App::SetVersion(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string version;
if (!FromV8Arguments(args, &version))
return node::ThrowError("Bad argument");
Browser::Get()->SetVersion(version);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::GetName(const v8::Arguments& args) {
return ToV8Value(Browser::Get()->GetName());
void App::GetName(const v8::FunctionCallbackInfo<v8::Value>& args) {
return args.GetReturnValue().Set(ToV8Value(Browser::Get()->GetName()));
}
// static
v8::Handle<v8::Value> App::SetName(const v8::Arguments& args) {
v8::HandleScope scope;
void App::SetName(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string name;
if (!FromV8Arguments(args, &name))
return node::ThrowError("Bad argument");
Browser::Get()->SetName(name);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::AppendSwitch(const v8::Arguments& args) {
v8::HandleScope scope;
void App::AppendSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string switch_string;
if (!FromV8Arguments(args, &switch_string))
return node::ThrowError("Bad argument");
@ -150,27 +123,21 @@ v8::Handle<v8::Value> App::AppendSwitch(const v8::Arguments& args) {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switch_string, value);
}
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::AppendArgument(const v8::Arguments& args) {
v8::HandleScope scope;
void App::AppendArgument(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string value;
if (!FromV8Arguments(args, &value))
return node::ThrowError("Bad argument");
CommandLine::ForCurrentProcess()->AppendArg(value);
return v8::Undefined();
}
#if defined(OS_MACOSX)
// static
v8::Handle<v8::Value> App::DockBounce(const v8::Arguments& args) {
void App::DockBounce(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string type;
if (!FromV8Arguments(args, &type))
return node::ThrowError("Bad argument");
@ -184,34 +151,32 @@ v8::Handle<v8::Value> App::DockBounce(const v8::Arguments& args) {
else
return node::ThrowTypeError("Invalid bounce type");
return ToV8Value(request_id);
args.GetReturnValue().Set(request_id);
}
// static
v8::Handle<v8::Value> App::DockCancelBounce(const v8::Arguments& args) {
void App::DockCancelBounce(const v8::FunctionCallbackInfo<v8::Value>& args) {
Browser::Get()->DockCancelBounce(FromV8Value(args[0]));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::DockSetBadgeText(const v8::Arguments& args) {
void App::DockSetBadgeText(const v8::FunctionCallbackInfo<v8::Value>& args) {
Browser::Get()->DockSetBadgeText(FromV8Value(args[0]));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::DockGetBadgeText(const v8::Arguments& args) {
void App::DockGetBadgeText(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string text(Browser::Get()->DockGetBadgeText());
return ToV8Value(text);
args.GetReturnValue().Set(ToV8Value(text));
}
#endif // defined(OS_MACOSX)
// static
void App::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(App::New);
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(v8::String::NewSymbol("Application"));

View file

@ -33,24 +33,24 @@ class App : public EventEmitter,
virtual void OnFinishLaunching() OVERRIDE;
private:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> Quit(const v8::Arguments& args);
static v8::Handle<v8::Value> Exit(const v8::Arguments& args);
static v8::Handle<v8::Value> Terminate(const v8::Arguments& args);
static v8::Handle<v8::Value> Focus(const v8::Arguments& args);
static v8::Handle<v8::Value> GetVersion(const v8::Arguments& args);
static v8::Handle<v8::Value> SetVersion(const v8::Arguments& args);
static v8::Handle<v8::Value> GetName(const v8::Arguments& args);
static v8::Handle<v8::Value> SetName(const v8::Arguments& args);
static v8::Handle<v8::Value> AppendSwitch(const v8::Arguments& args);
static v8::Handle<v8::Value> AppendArgument(const v8::Arguments& args);
static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Exit(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Terminate(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetVersion(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetVersion(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetName(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetName(const v8::FunctionCallbackInfo<v8::Value>& args);
static void AppendSwitch(const v8::FunctionCallbackInfo<v8::Value>& args);
static void AppendArgument(const v8::FunctionCallbackInfo<v8::Value>& args);
#if defined(OS_MACOSX)
static v8::Handle<v8::Value> DockBounce(const v8::Arguments& args);
static v8::Handle<v8::Value> DockCancelBounce(const v8::Arguments& args);
static v8::Handle<v8::Value> DockSetBadgeText(const v8::Arguments& args);
static v8::Handle<v8::Value> DockGetBadgeText(const v8::Arguments& args);
static void DockBounce(const v8::FunctionCallbackInfo<v8::Value>& args);
static void DockCancelBounce(const v8::FunctionCallbackInfo<v8::Value>& args);
static void DockSetBadgeText(const v8::FunctionCallbackInfo<v8::Value>& args);
static void DockGetBadgeText(const v8::FunctionCallbackInfo<v8::Value>& args);
#endif // defined(OS_MACOSX)
DISALLOW_COPY_AND_ASSIGN(App);

View file

@ -6,7 +6,12 @@
#include "base/values.h"
#include "browser/auto_updater.h"
#include "common/v8_conversions.h"
#include "common/v8/native_type_conversions.h"
#undef CHECK
#undef DISALLOW_COPY_AND_ASSIGN
#include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h"
namespace atom {
@ -44,69 +49,63 @@ void AutoUpdater::ReadyForUpdateOnQuit(const std::string& version,
}
// static
v8::Handle<v8::Value> AutoUpdater::New(const v8::Arguments& args) {
v8::HandleScope scope;
void AutoUpdater::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
if (!args.IsConstructCall())
return node::ThrowError("Require constructor call");
new AutoUpdater(args.This());
return args.This();
}
// static
v8::Handle<v8::Value> AutoUpdater::SetFeedURL(const v8::Arguments& args) {
void AutoUpdater::SetFeedURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
auto_updater::AutoUpdater::SetFeedURL(FromV8Value(args[0]));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> AutoUpdater::SetAutomaticallyChecksForUpdates(
const v8::Arguments& args) {
void AutoUpdater::SetAutomaticallyChecksForUpdates(
const v8::FunctionCallbackInfo<v8::Value>& args) {
auto_updater::AutoUpdater::SetAutomaticallyChecksForUpdates(
args[0]->BooleanValue());
return v8::Undefined();
FromV8Value(args[0]));
}
// static
v8::Handle<v8::Value> AutoUpdater::SetAutomaticallyDownloadsUpdates(
const v8::Arguments& args) {
void AutoUpdater::SetAutomaticallyDownloadsUpdates(
const v8::FunctionCallbackInfo<v8::Value>& args) {
auto_updater::AutoUpdater::SetAutomaticallyDownloadsUpdates(
args[0]->BooleanValue());
return v8::Undefined();
FromV8Value(args[0]));
}
// static
v8::Handle<v8::Value> AutoUpdater::CheckForUpdates(const v8::Arguments& args) {
void AutoUpdater::CheckForUpdates(
const v8::FunctionCallbackInfo<v8::Value>& args) {
auto_updater::AutoUpdater::CheckForUpdates();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> AutoUpdater::CheckForUpdatesInBackground(
const v8::Arguments& args) {
void AutoUpdater::CheckForUpdatesInBackground(
const v8::FunctionCallbackInfo<v8::Value>& args) {
auto_updater::AutoUpdater::CheckForUpdatesInBackground();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> AutoUpdater::ContinueUpdate(const v8::Arguments& args) {
void AutoUpdater::ContinueUpdate(
const v8::FunctionCallbackInfo<v8::Value>& args) {
AutoUpdater* self = AutoUpdater::Unwrap<AutoUpdater>(args.This());
self->continue_update_.Run();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> AutoUpdater::QuitAndInstall(const v8::Arguments& args) {
void AutoUpdater::QuitAndInstall(
const v8::FunctionCallbackInfo<v8::Value>& args) {
AutoUpdater* self = AutoUpdater::Unwrap<AutoUpdater>(args.This());
self->quit_and_install_.Run();
return v8::Undefined();
}
// static
void AutoUpdater::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::Local<v8::FunctionTemplate> t(
v8::FunctionTemplate::New(AutoUpdater::New));

View file

@ -31,19 +31,19 @@ class AutoUpdater : public EventEmitter,
const base::Closure& quit_and_install) OVERRIDE;
private:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> SetFeedURL(const v8::Arguments& args);
static v8::Handle<v8::Value> SetAutomaticallyChecksForUpdates(
const v8::Arguments& args);
static v8::Handle<v8::Value> SetAutomaticallyDownloadsUpdates(
const v8::Arguments& args);
static v8::Handle<v8::Value> CheckForUpdates(const v8::Arguments& args);
static v8::Handle<v8::Value> CheckForUpdatesInBackground(
const v8::Arguments& args);
static void SetFeedURL(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetAutomaticallyChecksForUpdates(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetAutomaticallyDownloadsUpdates(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void CheckForUpdates(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CheckForUpdatesInBackground(
const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> ContinueUpdate(const v8::Arguments& args);
static v8::Handle<v8::Value> QuitAndInstall(const v8::Arguments& args);
static void ContinueUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);
static void QuitAndInstall(const v8::FunctionCallbackInfo<v8::Value>& args);
base::Closure continue_update_;
base::Closure quit_and_install_;

View file

@ -5,10 +5,9 @@
#include "browser/api/atom_api_browser_ipc.h"
#include "common/api/api_messages.h"
#include "common/v8_conversions.h"
#include "common/v8/node_common.h"
#include "common/v8/native_type_conversions.h"
#include "content/public/browser/render_view_host.h"
#include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h"
using content::RenderViewHost;
using content::V8ValueConverter;
@ -18,9 +17,7 @@ namespace atom {
namespace api {
// static
v8::Handle<v8::Value> BrowserIPC::Send(const v8::Arguments& args) {
v8::HandleScope scope;
void BrowserIPC::Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
string16 channel;
int process_id, routing_id;
scoped_ptr<base::Value> arguments;
@ -34,17 +31,15 @@ v8::Handle<v8::Value> BrowserIPC::Send(const v8::Arguments& args) {
if (!render_view_host)
return node::ThrowError("Invalid render view host");
render_view_host->Send(new AtomViewMsg_Message(
args.GetReturnValue().Set(render_view_host->Send(new AtomViewMsg_Message(
routing_id,
channel,
*static_cast<base::ListValue*>(arguments.get())));
return v8::Undefined();
*static_cast<base::ListValue*>(arguments.get()))));
}
// static
void BrowserIPC::Initialize(v8::Handle<v8::Object> target) {
node::SetMethod(target, "send", Send);
NODE_SET_METHOD(target, "send", Send);
}
} // namespace api

View file

@ -17,7 +17,7 @@ class BrowserIPC {
static void Initialize(v8::Handle<v8::Object> target);
private:
static v8::Handle<v8::Value> Send(const v8::Arguments& args);
static void Send(const v8::FunctionCallbackInfo<v8::Value>& args);
DISALLOW_IMPLICIT_CONSTRUCTORS(BrowserIPC);
};

View file

@ -8,10 +8,8 @@
#include "browser/native_window.h"
#include "browser/ui/file_dialog.h"
#include "browser/ui/message_box.h"
#include "common/v8_conversions.h"
#include "vendor/node/src/node_internals.h"
using node::node_isolate;
#include "common/v8/node_common.h"
#include "common/v8/native_type_conversions.h"
namespace atom {
@ -20,19 +18,14 @@ namespace api {
namespace {
template<typename T>
void CallV8Function(v8::Persistent<v8::Function> callback, T arg) {
DCHECK(!callback.IsEmpty());
v8::HandleScope scope;
void CallV8Function(const RefCountedV8Function& callback, T arg) {
v8::Handle<v8::Value> value = ToV8Value(arg);
callback->Call(callback, 1, &value);
callback.Dispose(node_isolate);
callback->NewHandle(node_isolate)->Call(
v8::Context::GetCurrent()->Global(), 1, &value);
}
template<typename T>
void CallV8Function2(v8::Persistent<v8::Function> callback,
bool result,
T arg) {
void CallV8Function2(const RefCountedV8Function& callback, bool result, T arg) {
if (result)
return CallV8Function<T>(callback, arg);
else
@ -40,7 +33,7 @@ void CallV8Function2(v8::Persistent<v8::Function> callback,
}
void Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
NODE_SET_METHOD(target, "showMessageBox", ShowMessageBox);
NODE_SET_METHOD(target, "showOpenDialog", ShowOpenDialog);
@ -49,9 +42,7 @@ void Initialize(v8::Handle<v8::Object> target) {
} // namespace
v8::Handle<v8::Value> ShowMessageBox(const v8::Arguments& args) {
v8::HandleScope scope;
void ShowMessageBox(const v8::FunctionCallbackInfo<v8::Value>& args) {
int type;
std::vector<std::string> buttons;
std::string title, message, detail;
@ -68,9 +59,9 @@ v8::Handle<v8::Value> ShowMessageBox(const v8::Arguments& args) {
title,
message,
detail);
return scope.Close(v8::Integer::New(chosen));
args.GetReturnValue().Set(chosen);
} else {
v8::Persistent<v8::Function> callback = FromV8Value(args[6]);
RefCountedV8Function callback = FromV8Value(args[6]);
atom::ShowMessageBox(
native_window,
(MessageBoxType)type,
@ -79,13 +70,10 @@ v8::Handle<v8::Value> ShowMessageBox(const v8::Arguments& args) {
message,
detail,
base::Bind(&CallV8Function<int>, callback));
return v8::Undefined();
}
}
v8::Handle<v8::Value> ShowOpenDialog(const v8::Arguments& args) {
v8::HandleScope scope;
void ShowOpenDialog(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string title;
base::FilePath default_path;
int properties;
@ -101,15 +89,15 @@ v8::Handle<v8::Value> ShowOpenDialog(const v8::Arguments& args) {
default_path,
properties,
&paths))
return v8::Undefined();
return;
v8::Handle<v8::Array> result = v8::Array::New(paths.size());
for (size_t i = 0; i < paths.size(); ++i)
result->Set(i, ToV8Value(paths[i]));
return scope.Close(result);
args.GetReturnValue().Set(result);
} else {
v8::Persistent<v8::Function> callback = FromV8Value(args[4]);
RefCountedV8Function callback = FromV8Value(args[4]);
file_dialog::ShowOpenDialog(
native_window,
title,
@ -117,13 +105,10 @@ v8::Handle<v8::Value> ShowOpenDialog(const v8::Arguments& args) {
properties,
base::Bind(&CallV8Function2<const std::vector<base::FilePath>&>,
callback));
return v8::Undefined();
}
}
v8::Handle<v8::Value> ShowSaveDialog(const v8::Arguments& args) {
v8::HandleScope scope;
void ShowSaveDialog(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string title;
base::FilePath default_path;
if (!FromV8Arguments(args, &title, &default_path))
@ -133,21 +118,18 @@ v8::Handle<v8::Value> ShowSaveDialog(const v8::Arguments& args) {
if (!args[3]->IsFunction()) {
base::FilePath path;
if (!file_dialog::ShowSaveDialog(native_window,
title,
default_path,
&path))
return v8::Undefined();
return scope.Close(ToV8Value(path));
if (file_dialog::ShowSaveDialog(native_window,
title,
default_path,
&path))
args.GetReturnValue().Set(ToV8Value(path));
} else {
v8::Persistent<v8::Function> callback = FromV8Value(args[3]);
RefCountedV8Function callback = FromV8Value(args[3]);
file_dialog::ShowSaveDialog(
native_window,
title,
default_path,
base::Bind(&CallV8Function2<const base::FilePath&>, callback));
return v8::Undefined();
}
}

View file

@ -11,9 +11,9 @@ namespace atom {
namespace api {
v8::Handle<v8::Value> ShowMessageBox(const v8::Arguments& args);
v8::Handle<v8::Value> ShowOpenDialog(const v8::Arguments& args);
v8::Handle<v8::Value> ShowSaveDialog(const v8::Arguments& args);
void ShowMessageBox(const v8::FunctionCallbackInfo<v8::Value>& args);
void ShowOpenDialog(const v8::FunctionCallbackInfo<v8::Value>& args);
void ShowSaveDialog(const v8::FunctionCallbackInfo<v8::Value>& args);
} // namespace api

View file

@ -6,15 +6,14 @@
#include "browser/native_window.h"
#include "common/api/api_messages.h"
#include "common/v8_conversions.h"
using node::node_isolate;
#include "common/v8/node_common.h"
#include "common/v8/native_type_conversions.h"
namespace atom {
namespace api {
v8::Persistent<v8::FunctionTemplate> Event::constructor_template_;
ScopedPersistent<v8::Function> Event::constructor_template_;
Event::Event()
: sender_(NULL),
@ -29,24 +28,20 @@ Event::~Event() {
// static
v8::Handle<v8::Object> Event::CreateV8Object() {
v8::HandleScope scope;
if (constructor_template_.IsEmpty()) {
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(New);
constructor_template_ = v8::Persistent<v8::FunctionTemplate>::New(
node_isolate, t);
constructor_template_->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template_->SetClassName(v8::String::NewSymbol("Event"));
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(v8::String::NewSymbol("Event"));
NODE_SET_PROTOTYPE_METHOD(t, "preventDefault", PreventDefault);
NODE_SET_PROTOTYPE_METHOD(t, "sendReply", SendReply);
NODE_SET_PROTOTYPE_METHOD(t, "destroy", Destroy);
constructor_template_.reset(t->GetFunction());
}
v8::Handle<v8::Object> v8_event =
constructor_template_->GetFunction()->NewInstance(0, NULL);
return scope.Close(v8_event);
v8::Handle<v8::Function> t = constructor_template_.NewHandle(node_isolate);
return t->NewInstance(0, NULL);
}
void Event::SetSenderAndMessage(NativeWindow* sender, IPC::Message* message) {
@ -64,26 +59,22 @@ void Event::OnWindowClosed() {
}
// static
v8::Handle<v8::Value> Event::New(const v8::Arguments& args) {
void Event::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
Event* event = new Event;
event->Wrap(args.This());
return args.This();
}
// static
v8::Handle<v8::Value> Event::PreventDefault(const v8::Arguments& args) {
void Event::PreventDefault(const v8::FunctionCallbackInfo<v8::Value>& args) {
Event* event = Unwrap<Event>(args.This());
if (event == NULL)
return node::ThrowError("Event is already destroyed");
event->prevent_default_ = true;
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Event::SendReply(const v8::Arguments& args) {
void Event::SendReply(const v8::FunctionCallbackInfo<v8::Value>& args) {
Event* event = Unwrap<Event>(args.This());
if (event == NULL)
return node::ThrowError("Event is already destroyed");
@ -97,14 +88,11 @@ v8::Handle<v8::Value> Event::SendReply(const v8::Arguments& args) {
event->sender_->Send(event->message_);
delete event;
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Event::Destroy(const v8::Arguments& args) {
void Event::Destroy(const v8::FunctionCallbackInfo<v8::Value>& args) {
delete Unwrap<Event>(args.This());
return v8::Undefined();
}
} // namespace api

View file

@ -9,6 +9,7 @@
#include "base/compiler_specific.h"
#include "base/strings/string16.h"
#include "browser/native_window_observer.h"
#include "common/v8/scoped_persistent.h"
#include "vendor/node/src/node_object_wrap.h"
namespace IPC {
@ -32,9 +33,6 @@ class Event : public node::ObjectWrap,
// Pass the sender and message to be replied.
void SetSenderAndMessage(NativeWindow* sender, IPC::Message* message);
// Accessor to return handle_, this follows Google C++ Style.
v8::Persistent<v8::Object>& handle() { return handle_; }
// Whether event.preventDefault() is called.
bool prevent_default() const { return prevent_default_; }
@ -45,13 +43,13 @@ class Event : public node::ObjectWrap,
virtual void OnWindowClosed() OVERRIDE;
private:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> PreventDefault(const v8::Arguments& args);
static v8::Handle<v8::Value> SendReply(const v8::Arguments& args);
static v8::Handle<v8::Value> Destroy(const v8::Arguments& args);
static void PreventDefault(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SendReply(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Destroy(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Persistent<v8::FunctionTemplate> constructor_template_;
static ScopedPersistent<v8::Function> constructor_template_;
// Replyer for the synchronous messages.
NativeWindow* sender_;

View file

@ -8,9 +8,8 @@
#include "base/logging.h"
#include "browser/api/atom_api_event.h"
#include "common/v8_conversions.h"
#include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h"
#include "common/v8/node_common.h"
#include "common/v8/native_type_conversions.h"
namespace atom {
@ -24,7 +23,8 @@ EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
v8::String::New("ATOM_BROWSER_INTERNAL_NEW"),
wrapper,
};
node::MakeCallback(node::process, "emit", 2, args);
node::Environment* env = node::Environment::GetCurrent(node_isolate);
node::MakeCallback(env->process_object(), "emit", 2, args);
}
EventEmitter::~EventEmitter() {
@ -36,7 +36,7 @@ bool EventEmitter::Emit(const std::string& name) {
}
bool EventEmitter::Emit(const std::string& name, base::ListValue* args) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
v8::Handle<v8::Context> context = v8::Context::GetCurrent();
scoped_ptr<content::V8ValueConverter> converter(new V8ValueConverterImpl);

View file

@ -29,6 +29,11 @@ class EventEmitter : public node::ObjectWrap {
bool Emit(const std::string& name);
bool Emit(const std::string& name, base::ListValue* args);
// The handle() of ObjectWrap doesn't provide the const version.
inline v8::Local<v8::Object> handle() const {
return const_cast<EventEmitter*>(this)->handle();
}
protected:
explicit EventEmitter(v8::Handle<v8::Object> wrapper);

View file

@ -5,7 +5,8 @@
#include "browser/api/atom_api_menu.h"
#include "browser/ui/accelerator_util.h"
#include "common/v8_conversions.h"
#include "common/v8/node_common.h"
#include "common/v8/native_type_conversions.h"
#define UNWRAP_MEMNU_AND_CHECK \
Menu* self = ObjectWrap::Unwrap<Menu>(args.This()); \
@ -23,7 +24,7 @@ v8::Handle<v8::Value> CallDelegate(v8::Handle<v8::Value> default_value,
v8::Handle<v8::Object> menu,
const char* method,
int command_id) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
v8::Handle<v8::Value> delegate = menu->Get(v8::String::New("delegate"));
if (!delegate->IsObject())
@ -36,7 +37,7 @@ v8::Handle<v8::Value> CallDelegate(v8::Handle<v8::Value> default_value,
v8::Handle<v8::Value> argv = v8::Integer::New(command_id);
return scope.Close(
return handle_scope.Close(
function->Call(v8::Context::GetCurrent()->Global(), 1, &argv));
}
@ -51,7 +52,7 @@ Menu::~Menu() {
}
bool Menu::IsCommandIdChecked(int command_id) const {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
return CallDelegate(v8::False(),
handle(),
"isCommandIdChecked",
@ -59,7 +60,7 @@ bool Menu::IsCommandIdChecked(int command_id) const {
}
bool Menu::IsCommandIdEnabled(int command_id) const {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
return CallDelegate(v8::True(),
handle(),
"isCommandIdEnabled",
@ -67,7 +68,7 @@ bool Menu::IsCommandIdEnabled(int command_id) const {
}
bool Menu::IsCommandIdVisible(int command_id) const {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
return CallDelegate(v8::True(),
handle(),
"isCommandIdVisible",
@ -76,7 +77,7 @@ bool Menu::IsCommandIdVisible(int command_id) const {
bool Menu::GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
v8::Handle<v8::Value> shortcut = CallDelegate(v8::Undefined(),
handle(),
"getAcceleratorForCommandId",
@ -90,7 +91,7 @@ bool Menu::GetAcceleratorForCommandId(int command_id,
}
bool Menu::IsItemForCommandIdDynamic(int command_id) const {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
return CallDelegate(v8::False(),
handle(),
"isItemForCommandIdDynamic",
@ -98,7 +99,7 @@ bool Menu::IsItemForCommandIdDynamic(int command_id) const {
}
string16 Menu::GetLabelForCommandId(int command_id) const {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
return FromV8Value(CallDelegate(v8::False(),
handle(),
"getLabelForCommandId",
@ -106,7 +107,7 @@ string16 Menu::GetLabelForCommandId(int command_id) const {
}
string16 Menu::GetSublabelForCommandId(int command_id) const {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
return FromV8Value(CallDelegate(v8::False(),
handle(),
"getSubLabelForCommandId",
@ -114,24 +115,22 @@ string16 Menu::GetSublabelForCommandId(int command_id) const {
}
void Menu::ExecuteCommand(int command_id, int event_flags) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
CallDelegate(v8::False(), handle(), "executeCommand", command_id);
}
// static
v8::Handle<v8::Value> Menu::New(const v8::Arguments& args) {
v8::HandleScope scope;
void Menu::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
if (!args.IsConstructCall())
return node::ThrowError("Require constructor call");
Menu::Create(args.This());
return args.This();
}
// static
v8::Handle<v8::Value> Menu::InsertItem(const v8::Arguments& args) {
void Menu::InsertItem(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index, command_id;
@ -143,12 +142,10 @@ v8::Handle<v8::Value> Menu::InsertItem(const v8::Arguments& args) {
self->model_->AddItem(command_id, label);
else
self->model_->InsertItemAt(index, command_id, label);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::InsertCheckItem(const v8::Arguments& args) {
void Menu::InsertCheckItem(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index, command_id;
@ -160,12 +157,10 @@ v8::Handle<v8::Value> Menu::InsertCheckItem(const v8::Arguments& args) {
self->model_->AddCheckItem(command_id, label);
else
self->model_->InsertCheckItemAt(index, command_id, label);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::InsertRadioItem(const v8::Arguments& args) {
void Menu::InsertRadioItem(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index, command_id, group_id;
@ -177,12 +172,10 @@ v8::Handle<v8::Value> Menu::InsertRadioItem(const v8::Arguments& args) {
self->model_->AddRadioItem(command_id, label, group_id);
else
self->model_->InsertRadioItemAt(index, command_id, label, group_id);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::InsertSeparator(const v8::Arguments& args) {
void Menu::InsertSeparator(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index;
@ -193,12 +186,10 @@ v8::Handle<v8::Value> Menu::InsertSeparator(const v8::Arguments& args) {
self->model_->AddSeparator(ui::NORMAL_SEPARATOR);
else
self->model_->InsertSeparatorAt(index, ui::NORMAL_SEPARATOR);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::InsertSubMenu(const v8::Arguments& args) {
void Menu::InsertSubMenu(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index, command_id;
@ -215,12 +206,10 @@ v8::Handle<v8::Value> Menu::InsertSubMenu(const v8::Arguments& args) {
else
self->model_->InsertSubMenuAt(
index, command_id, label, submenu->model_.get());
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::SetIcon(const v8::Arguments& args) {
void Menu::SetIcon(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index;
@ -229,12 +218,10 @@ v8::Handle<v8::Value> Menu::SetIcon(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
// FIXME use webkit_glue's image decoder here.
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::SetSublabel(const v8::Arguments& args) {
void Menu::SetSublabel(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index;
@ -243,74 +230,71 @@ v8::Handle<v8::Value> Menu::SetSublabel(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->model_->SetSublabel(index, label);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::Clear(const v8::Arguments& args) {
void Menu::Clear(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
self->model_->Clear();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::GetIndexOfCommandId(const v8::Arguments& args) {
void Menu::GetIndexOfCommandId(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index = args[0]->IntegerValue();
return v8::Integer::New(self->model_->GetIndexOfCommandId(index));
int index = FromV8Value(args[0]);
args.GetReturnValue().Set(self->model_->GetIndexOfCommandId(index));
}
// static
v8::Handle<v8::Value> Menu::GetItemCount(const v8::Arguments& args) {
void Menu::GetItemCount(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
return v8::Integer::New(self->model_->GetItemCount());
args.GetReturnValue().Set(self->model_->GetItemCount());
}
// static
v8::Handle<v8::Value> Menu::GetCommandIdAt(const v8::Arguments& args) {
void Menu::GetCommandIdAt(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index = args[0]->IntegerValue();
return v8::Integer::New(self->model_->GetCommandIdAt(index));
int index = FromV8Value(args[0]);
args.GetReturnValue().Set(self->model_->GetCommandIdAt(index));
}
// static
v8::Handle<v8::Value> Menu::GetLabelAt(const v8::Arguments& args) {
void Menu::GetLabelAt(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index = args[0]->IntegerValue();
return ToV8Value(self->model_->GetLabelAt(index));
int index = FromV8Value(args[0]);
args.GetReturnValue().Set(ToV8Value(self->model_->GetLabelAt(index)));
}
// static
v8::Handle<v8::Value> Menu::GetSublabelAt(const v8::Arguments& args) {
void Menu::GetSublabelAt(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index = args[0]->IntegerValue();
return ToV8Value(self->model_->GetSublabelAt(index));
int index = FromV8Value(args[0]);
args.GetReturnValue().Set(ToV8Value(self->model_->GetSublabelAt(index)));
}
// static
v8::Handle<v8::Value> Menu::IsItemCheckedAt(const v8::Arguments& args) {
void Menu::IsItemCheckedAt(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
int index = args[0]->IntegerValue();
return v8::Boolean::New(self->model_->IsItemCheckedAt(index));
int index = FromV8Value(args[0]);
args.GetReturnValue().Set(self->model_->IsItemCheckedAt(index));
}
// static
v8::Handle<v8::Value> Menu::IsEnabledAt(const v8::Arguments& args) {
void Menu::IsEnabledAt(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
return v8::Boolean::New(self->model_->IsEnabledAt(args[0]->IntegerValue()));
int index = FromV8Value(args[0]);
args.GetReturnValue().Set(self->model_->IsEnabledAt(index));
}
// static
v8::Handle<v8::Value> Menu::IsVisibleAt(const v8::Arguments& args) {
void Menu::IsVisibleAt(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
return v8::Boolean::New(self->model_->IsVisibleAt(args[0]->IntegerValue()));
int index = FromV8Value(args[0]);
args.GetReturnValue().Set(self->model_->IsVisibleAt(index));
}
// static
v8::Handle<v8::Value> Menu::Popup(const v8::Arguments& args) {
void Menu::Popup(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_MEMNU_AND_CHECK;
atom::NativeWindow* window;
@ -318,12 +302,11 @@ v8::Handle<v8::Value> Menu::Popup(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->Popup(window);
return v8::Undefined();
}
// static
void Menu::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
v8::Local<v8::FunctionTemplate> t(v8::FunctionTemplate::New(Menu::New));
t->InstanceTemplate()->SetInternalFieldCount(1);

View file

@ -44,36 +44,37 @@ class Menu : public EventEmitter,
scoped_ptr<ui::SimpleMenuModel> model_;
private:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> InsertItem(const v8::Arguments& args);
static v8::Handle<v8::Value> InsertCheckItem(const v8::Arguments& args);
static v8::Handle<v8::Value> InsertRadioItem(const v8::Arguments& args);
static v8::Handle<v8::Value> InsertSeparator(const v8::Arguments& args);
static v8::Handle<v8::Value> InsertSubMenu(const v8::Arguments& args);
static void InsertItem(const v8::FunctionCallbackInfo<v8::Value>& args);
static void InsertCheckItem(const v8::FunctionCallbackInfo<v8::Value>& args);
static void InsertRadioItem(const v8::FunctionCallbackInfo<v8::Value>& args);
static void InsertSeparator(const v8::FunctionCallbackInfo<v8::Value>& args);
static void InsertSubMenu(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> SetIcon(const v8::Arguments& args);
static v8::Handle<v8::Value> SetSublabel(const v8::Arguments& args);
static void SetIcon(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetSublabel(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> Clear(const v8::Arguments& args);
static void Clear(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> GetIndexOfCommandId(const v8::Arguments& args);
static v8::Handle<v8::Value> GetItemCount(const v8::Arguments& args);
static v8::Handle<v8::Value> GetCommandIdAt(const v8::Arguments& args);
static v8::Handle<v8::Value> GetLabelAt(const v8::Arguments& args);
static v8::Handle<v8::Value> GetSublabelAt(const v8::Arguments& args);
static v8::Handle<v8::Value> IsItemCheckedAt(const v8::Arguments& args);
static v8::Handle<v8::Value> IsEnabledAt(const v8::Arguments& args);
static v8::Handle<v8::Value> IsVisibleAt(const v8::Arguments& args);
static void GetIndexOfCommandId(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetItemCount(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetCommandIdAt(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetLabelAt(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetSublabelAt(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsItemCheckedAt(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsEnabledAt(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsVisibleAt(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> Popup(const v8::Arguments& args);
static void Popup(const v8::FunctionCallbackInfo<v8::Value>& args);
#if defined(OS_WIN)
static v8::Handle<v8::Value> AttachToWindow(const v8::Arguments& args);
static void AttachToWindow(const v8::FunctionCallbackInfo<v8::Value>& args);
#elif defined(OS_MACOSX)
static v8::Handle<v8::Value> SetApplicationMenu(const v8::Arguments& args);
static v8::Handle<v8::Value> SendActionToFirstResponder(
const v8::Arguments& args);
static void SetApplicationMenu(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void SendActionToFirstResponder(
const v8::FunctionCallbackInfo<v8::Value>& args);
#endif
DISALLOW_COPY_AND_ASSIGN(Menu);

View file

@ -21,7 +21,7 @@ class MenuMac : public Menu {
protected:
virtual void Popup(NativeWindow* window) OVERRIDE;
scoped_nsobject<AtomMenuController> menu_controller_;
base::scoped_nsobject<AtomMenuController> menu_controller_;
private:
friend class Menu;

View file

@ -4,11 +4,12 @@
#import "browser/api/atom_api_menu_mac.h"
#include "base/message_loop.h"
#include "base/mac/scoped_sending_event.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/sys_string_conversions.h"
#include "browser/native_window.h"
#include "common/v8_conversions.h"
#include "common/v8/node_common.h"
#include "common/v8/native_type_conversions.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
@ -24,7 +25,7 @@ MenuMac::~MenuMac() {
}
void MenuMac::Popup(NativeWindow* native_window) {
scoped_nsobject<AtomMenuController> menu_controller(
base::scoped_nsobject<AtomMenuController> menu_controller(
[[AtomMenuController alloc] initWithModel:model_.get()]);
NSWindow* window = native_window->GetNativeWindow();
@ -46,7 +47,8 @@ void MenuMac::Popup(NativeWindow* native_window) {
{
// Make sure events can be pumped while the menu is up.
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
// One of the events that could be pumped is |window.close()|.
// User-initiated event-tracking loops protect against this by
@ -71,8 +73,8 @@ void MenuMac::SendActionToFirstResponder(const std::string& action) {
}
// static
v8::Handle<v8::Value> Menu::SetApplicationMenu(const v8::Arguments& args) {
v8::HandleScope scope;
void Menu::SetApplicationMenu(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
if (!args[0]->IsObject())
return node::ThrowTypeError("Bad argument");
@ -81,28 +83,24 @@ v8::Handle<v8::Value> Menu::SetApplicationMenu(const v8::Arguments& args) {
if (!menu)
return node::ThrowError("Menu is destroyed");
scoped_nsobject<AtomMenuController> menu_controller(
base::scoped_nsobject<AtomMenuController> menu_controller(
[[AtomMenuController alloc] initWithModel:menu->model_.get()]);
[NSApp setMainMenu:[menu_controller menu]];
// Ensure the menu_controller_ is destroyed after main menu is set.
menu_controller.swap(menu->menu_controller_);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Menu::SendActionToFirstResponder(
const v8::Arguments& args) {
v8::HandleScope scope;
void Menu::SendActionToFirstResponder(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
std::string action;
if (!FromV8Arguments(args, &action))
return node::ThrowTypeError("Bad argument");
MenuMac::SendActionToFirstResponder(action);
return v8::Undefined();
}
// static

View file

@ -6,7 +6,7 @@
#include "browser/native_window_win.h"
#include "browser/ui/win/menu_2.h"
#include "common/v8_conversions.h"
#include "common/v8/native_type_conversions.h"
#include "ui/gfx/point.h"
#include "ui/gfx/screen.h"
@ -28,8 +28,8 @@ void MenuWin::Popup(NativeWindow* native_window) {
}
// static
v8::Handle<v8::Value> Menu::AttachToWindow(const v8::Arguments& args) {
v8::HandleScope scope;
void Menu::AttachToWindow(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
Menu* self = ObjectWrap::Unwrap<Menu>(args.This());
if (self == NULL)

View file

@ -5,6 +5,9 @@
#include "browser/api/atom_api_power_monitor.h"
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_device_source.h"
#include "common/v8/node_common.h"
namespace atom {
@ -35,20 +38,22 @@ void PowerMonitor::OnResume() {
}
// static
v8::Handle<v8::Value> PowerMonitor::New(const v8::Arguments& args) {
v8::HandleScope scope;
void PowerMonitor::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
if (!args.IsConstructCall())
return node::ThrowError("Require constructor call");
new PowerMonitor(args.This());
return args.This();
}
// static
void PowerMonitor::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
#if defined(OS_MACOSX)
base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
#endif
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(
PowerMonitor::New);

View file

@ -29,7 +29,7 @@ class PowerMonitor : public EventEmitter,
virtual void OnResume() OVERRIDE;
private:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
};

View file

@ -9,11 +9,11 @@
#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 "common/v8/native_type_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "net/url_request/url_request_context.h"
#include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h"
#include "common/v8/node_common.h"
namespace atom {
@ -24,10 +24,10 @@ typedef net::URLRequestJobFactory::ProtocolHandler ProtocolHandler;
namespace {
// The protocol module object.
v8::Persistent<v8::Object> g_protocol_object;
ScopedPersistent<v8::Object> g_protocol_object;
// Registered protocol handlers.
typedef std::map<std::string, v8::Persistent<v8::Function>> HandlersMap;
typedef std::map<std::string, RefCountedV8Function> HandlersMap;
static HandlersMap g_handlers;
static const char* kEarlyUseProtocolError = "This method can only be used"
@ -35,25 +35,23 @@ static const char* kEarlyUseProtocolError = "This method can only be used"
// Emit an event for the protocol module.
void EmitEventInUI(const std::string& event, const std::string& parameter) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
v8::Handle<v8::Value> argv[] = {
ToV8Value(event),
ToV8Value(parameter),
ToV8Value(event),
ToV8Value(parameter),
};
node::MakeCallback(g_protocol_object, "emit", arraysize(argv), argv);
node::MakeCallback(g_protocol_object.NewHandle(node_isolate),
"emit", 2, argv);
}
// Convert the URLRequest object to V8 object.
v8::Handle<v8::Object> ConvertURLRequestToV8Object(
const net::URLRequest* request) {
v8::Local<v8::Object> obj = v8::Object::New();
obj->Set(v8::String::New("method"),
v8::String::New(request->method().c_str()));
obj->Set(v8::String::New("url"),
v8::String::New(request->url().spec().c_str()));
obj->Set(v8::String::New("referrer"),
v8::String::New(request->referrer().c_str()));
obj->Set(ToV8Value("method"), ToV8Value(request->method()));
obj->Set(ToV8Value("url"), ToV8Value(request->url().spec()));
obj->Set(ToV8Value("referrer"), ToV8Value(request->referrer()));
return obj;
}
@ -74,13 +72,15 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
virtual void GetJobTypeInUI() OVERRIDE {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
v8::HandleScope handle_scope(node_isolate);
// Call the JS handler.
v8::HandleScope scope;
v8::Handle<v8::Value> argv[] = {
ConvertURLRequestToV8Object(request()),
};
v8::Handle<v8::Value> result = g_handlers[request()->url().scheme()]->Call(
v8::Context::GetCurrent()->Global(), arraysize(argv), argv);
RefCountedV8Function callback = g_handlers[request()->url().scheme()];
v8::Handle<v8::Value> result = callback->NewHandle(node_isolate)->Call(
v8::Context::GetCurrent()->Global(), 1, argv);
// Determine the type of the job we are going to create.
if (result->IsString()) {
@ -180,9 +180,10 @@ class CustomProtocolHandler : public ProtocolHandler {
} // namespace
// static
v8::Handle<v8::Value> Protocol::RegisterProtocol(const v8::Arguments& args) {
void Protocol::RegisterProtocol(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string scheme;
v8::Persistent<v8::Function> callback;
RefCountedV8Function callback;
if (!FromV8Arguments(args, &scheme, &callback))
return node::ThrowTypeError("Bad argument");
@ -199,12 +200,11 @@ v8::Handle<v8::Value> Protocol::RegisterProtocol(const v8::Arguments& args) {
content::BrowserThread::PostTask(content::BrowserThread::IO,
FROM_HERE,
base::Bind(&RegisterProtocolInIO, scheme));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Protocol::UnregisterProtocol(const v8::Arguments& args) {
void Protocol::UnregisterProtocol(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string scheme;
if (!FromV8Arguments(args, &scheme))
return node::ThrowTypeError("Bad argument");
@ -221,19 +221,20 @@ v8::Handle<v8::Value> Protocol::UnregisterProtocol(const v8::Arguments& args) {
content::BrowserThread::PostTask(content::BrowserThread::IO,
FROM_HERE,
base::Bind(&UnregisterProtocolInIO, scheme));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Protocol::IsHandledProtocol(const v8::Arguments& args) {
return ToV8Value(net::URLRequest::IsHandledProtocol(FromV8Value(args[0])));
void Protocol::IsHandledProtocol(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string scheme = FromV8Value(args[0]);
args.GetReturnValue().Set(net::URLRequest::IsHandledProtocol(scheme));
}
// static
v8::Handle<v8::Value> Protocol::InterceptProtocol(const v8::Arguments& args) {
void Protocol::InterceptProtocol(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string scheme;
v8::Persistent<v8::Function> callback;
RefCountedV8Function callback;
if (!FromV8Arguments(args, &scheme, &callback))
return node::ThrowTypeError("Bad argument");
@ -252,11 +253,11 @@ v8::Handle<v8::Value> Protocol::InterceptProtocol(const v8::Arguments& args) {
content::BrowserThread::PostTask(content::BrowserThread::IO,
FROM_HERE,
base::Bind(&InterceptProtocolInIO, scheme));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Protocol::UninterceptProtocol(const v8::Arguments& args) {
void Protocol::UninterceptProtocol(
const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string scheme;
if (!FromV8Arguments(args, &scheme))
return node::ThrowTypeError("Bad argument");
@ -274,7 +275,6 @@ v8::Handle<v8::Value> Protocol::UninterceptProtocol(const v8::Arguments& args) {
FROM_HERE,
base::Bind(&UninterceptProtocolInIO,
scheme));
return v8::Undefined();
}
// static
@ -361,14 +361,13 @@ void Protocol::UninterceptProtocolInIO(const std::string& scheme) {
// static
void Protocol::Initialize(v8::Handle<v8::Object> target) {
// Remember the protocol object, used for emitting event later.
g_protocol_object = v8::Persistent<v8::Object>::New(
node::node_isolate, target);
g_protocol_object.reset(v8::Object::New());
node::SetMethod(target, "registerProtocol", RegisterProtocol);
node::SetMethod(target, "unregisterProtocol", UnregisterProtocol);
node::SetMethod(target, "isHandledProtocol", IsHandledProtocol);
node::SetMethod(target, "interceptProtocol", InterceptProtocol);
node::SetMethod(target, "uninterceptProtocol", UninterceptProtocol);
NODE_SET_METHOD(target, "registerProtocol", RegisterProtocol);
NODE_SET_METHOD(target, "unregisterProtocol", UnregisterProtocol);
NODE_SET_METHOD(target, "isHandledProtocol", IsHandledProtocol);
NODE_SET_METHOD(target, "interceptProtocol", InterceptProtocol);
NODE_SET_METHOD(target, "uninterceptProtocol", UninterceptProtocol);
}
} // namespace api

View file

@ -20,12 +20,12 @@ class Protocol {
static void Initialize(v8::Handle<v8::Object> target);
private:
static v8::Handle<v8::Value> RegisterProtocol(const v8::Arguments& args);
static v8::Handle<v8::Value> UnregisterProtocol(const v8::Arguments& args);
static v8::Handle<v8::Value> IsHandledProtocol(const v8::Arguments& args);
static void RegisterProtocol(const v8::FunctionCallbackInfo<v8::Value>& args);
static void UnregisterProtocol(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsHandledProtocol(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Handle<v8::Value> InterceptProtocol(const v8::Arguments& args);
static v8::Handle<v8::Value> UninterceptProtocol(const v8::Arguments& args);
static void InterceptProtocol(const v8::FunctionCallbackInfo<v8::Value>& args);
static void UninterceptProtocol(const v8::FunctionCallbackInfo<v8::Value>& args);
static void RegisterProtocolInIO(const std::string& scheme);
static void UnregisterProtocolInIO(const std::string& scheme);

View file

@ -4,9 +4,9 @@
#include "browser/api/atom_api_window.h"
#include "base/process_util.h"
#include "base/process/kill.h"
#include "browser/native_window.h"
#include "common/v8_conversions.h"
#include "common/v8/native_type_conversions.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/render_process_host.h"
@ -14,6 +14,8 @@
#include "ui/gfx/size.h"
#include "vendor/node/src/node_buffer.h"
#include "common/v8/node_common.h"
using content::NavigationController;
using node::ObjectWrap;
@ -87,23 +89,20 @@ void Window::OnRendererCrashed() {
Emit("crashed");
}
void Window::OnCapturePageDone(v8::Persistent<v8::Function> callback,
void Window::OnCapturePageDone(const RefCountedV8Function& callback,
const std::vector<unsigned char>& data) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
// TODO(zcbenz): Use new Buffer API when we updated to node v0.12.x.
node::Buffer* buffer = node::Buffer::New(
v8::Local<v8::Value> buffer = node::Buffer::New(
reinterpret_cast<const char*>(data.data()),
data.size());
v8::Handle<v8::Value> arg = buffer->handle_;
callback->Call(v8::Context::GetCurrent()->Global(), 1, &arg);
callback.Dispose(v8::Isolate::GetCurrent());
callback->NewHandle(node_isolate)->Call(
v8::Context::GetCurrent()->Global(), 1, &buffer);
}
// static
v8::Handle<v8::Value> Window::New(const v8::Arguments& args) {
v8::HandleScope scope;
void Window::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
if (!args.IsConstructCall())
return node::ThrowError("Require constructor call");
@ -119,12 +118,10 @@ v8::Handle<v8::Value> Window::New(const v8::Arguments& args) {
// Give js code a chance to do initialization.
node::MakeCallback(args.This(), "_init", 0, NULL);
return args.This();
}
// static
v8::Handle<v8::Value> Window::Destroy(const v8::Arguments& args) {
void Window::Destroy(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
base::ProcessHandle handle = self->window_->GetRenderProcessHandle();
@ -135,96 +132,70 @@ v8::Handle<v8::Value> Window::Destroy(const v8::Arguments& args) {
if (!base::WaitForSingleProcess(handle,
base::TimeDelta::FromMilliseconds(500)))
base::KillProcess(handle, 0, true);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::Close(const v8::Arguments& args) {
void Window::Close(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Close();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::Focus(const v8::Arguments& args) {
void Window::Focus(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Focus(args[0]->IsBoolean() ? args[0]->BooleanValue(): true);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsFocused(const v8::Arguments& args) {
void Window::IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->IsFocused());
args.GetReturnValue().Set(self->window_->IsFocused());
}
// static
v8::Handle<v8::Value> Window::Show(const v8::Arguments& args) {
void Window::Show(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Show();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::Hide(const v8::Arguments& args) {
void Window::Hide(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Hide();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsVisible(const v8::Arguments& args) {
void Window::IsVisible(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->IsVisible());
return args.GetReturnValue().Set(self->window_->IsVisible());
}
// static
v8::Handle<v8::Value> Window::Maximize(const v8::Arguments& args) {
void Window::Maximize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Maximize();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::Unmaximize(const v8::Arguments& args) {
void Window::Unmaximize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Unmaximize();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::Minimize(const v8::Arguments& args) {
void Window::Minimize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Minimize();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::Restore(const v8::Arguments& args) {
void Window::Restore(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Restore();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::SetFullscreen(const v8::Arguments& args) {
void Window::SetFullscreen(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
bool fs;
@ -232,18 +203,16 @@ v8::Handle<v8::Value> Window::SetFullscreen(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->SetFullscreen(fs);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsFullscreen(const v8::Arguments& args) {
void Window::IsFullscreen(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->IsFullscreen());
args.GetReturnValue().Set(self->window_->IsFullscreen());
}
// static
v8::Handle<v8::Value> Window::SetSize(const v8::Arguments& args) {
void Window::SetSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
int width, height;
@ -251,11 +220,10 @@ v8::Handle<v8::Value> Window::SetSize(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->SetSize(gfx::Size(width, height));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetSize(const v8::Arguments& args) {
void Window::GetSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
gfx::Size size = self->window_->GetSize();
@ -263,11 +231,11 @@ v8::Handle<v8::Value> Window::GetSize(const v8::Arguments& args) {
ret->Set(0, ToV8Value(size.width()));
ret->Set(1, ToV8Value(size.height()));
return ret;
args.GetReturnValue().Set(ret);
}
// static
v8::Handle<v8::Value> Window::SetMinimumSize(const v8::Arguments& args) {
void Window::SetMinimumSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
int width, height;
@ -275,11 +243,10 @@ v8::Handle<v8::Value> Window::SetMinimumSize(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->SetMinimumSize(gfx::Size(width, height));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetMinimumSize(const v8::Arguments& args) {
void Window::GetMinimumSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
gfx::Size size = self->window_->GetMinimumSize();
@ -287,24 +254,22 @@ v8::Handle<v8::Value> Window::GetMinimumSize(const v8::Arguments& args) {
ret->Set(0, ToV8Value(size.width()));
ret->Set(1, ToV8Value(size.height()));
return ret;
args.GetReturnValue().Set(ret);
}
// static
v8::Handle<v8::Value> Window::SetMaximumSize(const v8::Arguments& args) {
void Window::SetMaximumSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
int width, height;
if (!FromV8Arguments(args, &width, &height))
return node::ThrowTypeError("Bad argument");
self->window_->SetMaximumSize(gfx::Size(width, height));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetMaximumSize(const v8::Arguments& args) {
void Window::GetMaximumSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
gfx::Size size = self->window_->GetMaximumSize();
@ -312,11 +277,11 @@ v8::Handle<v8::Value> Window::GetMaximumSize(const v8::Arguments& args) {
ret->Set(0, ToV8Value(size.width()));
ret->Set(1, ToV8Value(size.height()));
return ret;
args.GetReturnValue().Set(ret);
}
// static
v8::Handle<v8::Value> Window::SetResizable(const v8::Arguments& args) {
void Window::SetResizable(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
bool resizable;
@ -324,18 +289,16 @@ v8::Handle<v8::Value> Window::SetResizable(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->SetResizable(resizable);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsResizable(const v8::Arguments& args) {
void Window::IsResizable(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->IsResizable());
args.GetReturnValue().Set(self->window_->IsResizable());
}
// static
v8::Handle<v8::Value> Window::SetAlwaysOnTop(const v8::Arguments& args) {
void Window::SetAlwaysOnTop(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
bool top;
@ -343,27 +306,22 @@ v8::Handle<v8::Value> Window::SetAlwaysOnTop(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->SetAlwaysOnTop(top);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsAlwaysOnTop(const v8::Arguments& args) {
void Window::IsAlwaysOnTop(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->IsAlwaysOnTop());
args.GetReturnValue().Set(self->window_->IsAlwaysOnTop());
}
// static
v8::Handle<v8::Value> Window::Center(const v8::Arguments& args) {
void Window::Center(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->Center();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::SetPosition(const v8::Arguments& args) {
void Window::SetPosition(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
int x, y;
@ -371,11 +329,10 @@ v8::Handle<v8::Value> Window::SetPosition(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->SetPosition(gfx::Point(x, y));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetPosition(const v8::Arguments& args) {
void Window::GetPosition(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
gfx::Point pos = self->window_->GetPosition();
@ -383,11 +340,11 @@ v8::Handle<v8::Value> Window::GetPosition(const v8::Arguments& args) {
ret->Set(0, ToV8Value(pos.x()));
ret->Set(1, ToV8Value(pos.y()));
return ret;
args.GetReturnValue().Set(ret);
}
// static
v8::Handle<v8::Value> Window::SetTitle(const v8::Arguments& args) {
void Window::SetTitle(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
std::string title;
@ -395,27 +352,23 @@ v8::Handle<v8::Value> Window::SetTitle(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->SetTitle(title);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetTitle(const v8::Arguments& args) {
void Window::GetTitle(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->GetTitle());
args.GetReturnValue().Set(ToV8Value(self->window_->GetTitle()));
}
// static
v8::Handle<v8::Value> Window::FlashFrame(const v8::Arguments& args) {
void Window::FlashFrame(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->FlashFrame(
args[0]->IsBoolean() ? args[0]->BooleanValue(): true);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::SetKiosk(const v8::Arguments& args) {
void Window::SetKiosk(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
bool kiosk;
@ -423,42 +376,34 @@ v8::Handle<v8::Value> Window::SetKiosk(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->SetKiosk(kiosk);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsKiosk(const v8::Arguments& args) {
void Window::IsKiosk(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->IsKiosk());
args.GetReturnValue().Set(self->window_->IsKiosk());
}
// static
v8::Handle<v8::Value> Window::OpenDevTools(const v8::Arguments& args) {
void Window::OpenDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->OpenDevTools();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::CloseDevTools(const v8::Arguments& args) {
void Window::CloseDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->CloseDevTools();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsDevToolsOpened(const v8::Arguments& args) {
void Window::IsDevToolsOpened(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->IsDevToolsOpened());
args.GetReturnValue().Set(self->window_->IsDevToolsOpened());
}
// static
v8::Handle<v8::Value> Window::InspectElement(const v8::Arguments& args) {
void Window::InspectElement(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
int x, y;
@ -466,39 +411,32 @@ v8::Handle<v8::Value> Window::InspectElement(const v8::Arguments& args) {
return node::ThrowTypeError("Bad argument");
self->window_->InspectElement(x, y);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::FocusOnWebView(const v8::Arguments& args) {
void Window::FocusOnWebView(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->FocusOnWebView();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::BlurWebView(const v8::Arguments& args) {
void Window::BlurWebView(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->BlurWebView();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::IsWebViewFocused(const v8::Arguments& args) {
void Window::IsWebViewFocused(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->IsWebViewFocused());
args.GetReturnValue().Set(self->window_->IsWebViewFocused());
}
// static
v8::Handle<v8::Value> Window::CapturePage(const v8::Arguments& args) {
void Window::CapturePage(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
gfx::Rect rect;
v8::Persistent<v8::Function> callback;
RefCountedV8Function callback;
if (!FromV8Arguments(args, &rect, &callback) &&
!FromV8Arguments(args, &callback))
return node::ThrowTypeError("Bad argument");
@ -506,64 +444,56 @@ v8::Handle<v8::Value> Window::CapturePage(const v8::Arguments& args) {
self->window_->CapturePage(rect, base::Bind(&Window::OnCapturePageDone,
base::Unretained(self),
callback));
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetPageTitle(const v8::Arguments& args) {
void Window::GetPageTitle(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->GetWebContents()->GetTitle());
args.GetReturnValue().Set(ToV8Value(
self->window_->GetWebContents()->GetTitle()));
}
// static
v8::Handle<v8::Value> Window::IsLoading(const v8::Arguments& args) {
void Window::IsLoading(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->GetWebContents()->IsLoading());
args.GetReturnValue().Set(self->window_->GetWebContents()->IsLoading());
}
// static
v8::Handle<v8::Value> Window::IsWaitingForResponse(const v8::Arguments& args) {
void Window::IsWaitingForResponse(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->GetWebContents()->IsWaitingForResponse());
args.GetReturnValue().Set(
self->window_->GetWebContents()->IsWaitingForResponse());
}
// static
v8::Handle<v8::Value> Window::Stop(const v8::Arguments& args) {
void Window::Stop(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
self->window_->GetWebContents()->Stop();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetRoutingID(const v8::Arguments& args) {
void Window::GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->GetWebContents()->GetRoutingID());
args.GetReturnValue().Set(self->window_->GetWebContents()->GetRoutingID());
}
// static
v8::Handle<v8::Value> Window::GetProcessID(const v8::Arguments& args) {
void Window::GetProcessID(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(
args.GetReturnValue().Set(
self->window_->GetWebContents()->GetRenderProcessHost()->GetID());
}
// static
v8::Handle<v8::Value> Window::IsCrashed(const v8::Arguments& args) {
void Window::IsCrashed(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
return ToV8Value(self->window_->GetWebContents()->IsCrashed());
args.GetReturnValue().Set(self->window_->GetWebContents()->IsCrashed());
}
// static
v8::Handle<v8::Value> Window::LoadURL(const v8::Arguments& args) {
void Window::LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
GURL url;
@ -577,12 +507,10 @@ v8::Handle<v8::Value> Window::LoadURL(const v8::Arguments& args) {
params.transition_type = content::PAGE_TRANSITION_TYPED;
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
controller.LoadURLWithParams(params);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GetURL(const v8::Arguments& args) {
void Window::GetURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
NavigationController& controller =
@ -591,31 +519,31 @@ v8::Handle<v8::Value> Window::GetURL(const v8::Arguments& args) {
if (controller.GetActiveEntry())
url = controller.GetActiveEntry()->GetVirtualURL();
return ToV8Value(url);
args.GetReturnValue().Set(ToV8Value(url));
}
// static
v8::Handle<v8::Value> Window::CanGoBack(const v8::Arguments& args) {
void Window::CanGoBack(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
NavigationController& controller =
self->window_->GetWebContents()->GetController();
return ToV8Value(controller.CanGoBack());
args.GetReturnValue().Set(controller.CanGoBack());
}
// static
v8::Handle<v8::Value> Window::CanGoForward(const v8::Arguments& args) {
void Window::CanGoForward(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
NavigationController& controller =
self->window_->GetWebContents()->GetController();
return ToV8Value(controller.CanGoForward());
args.GetReturnValue().Set(controller.CanGoForward());
}
// static
v8::Handle<v8::Value> Window::CanGoToOffset(const v8::Arguments& args) {
void Window::CanGoToOffset(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
int offset;
@ -625,33 +553,29 @@ v8::Handle<v8::Value> Window::CanGoToOffset(const v8::Arguments& args) {
NavigationController& controller =
self->window_->GetWebContents()->GetController();
return ToV8Value(controller.CanGoToOffset(offset));
args.GetReturnValue().Set(controller.CanGoToOffset(offset));
}
// static
v8::Handle<v8::Value> Window::GoBack(const v8::Arguments& args) {
void Window::GoBack(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
NavigationController& controller =
self->window_->GetWebContents()->GetController();
controller.GoBack();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GoForward(const v8::Arguments& args) {
void Window::GoForward(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
NavigationController& controller =
self->window_->GetWebContents()->GetController();
controller.GoForward();
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GoToIndex(const v8::Arguments& args) {
void Window::GoToIndex(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
int index;
@ -661,12 +585,10 @@ v8::Handle<v8::Value> Window::GoToIndex(const v8::Arguments& args) {
NavigationController& controller =
self->window_->GetWebContents()->GetController();
controller.GoToIndex(index);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::GoToOffset(const v8::Arguments& args) {
void Window::GoToOffset(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
int offset;
@ -676,36 +598,30 @@ v8::Handle<v8::Value> Window::GoToOffset(const v8::Arguments& args) {
NavigationController& controller =
self->window_->GetWebContents()->GetController();
controller.GoToOffset(offset);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::Reload(const v8::Arguments& args) {
void Window::Reload(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
NavigationController& controller =
self->window_->GetWebContents()->GetController();
controller.Reload(args[0]->IsBoolean() ? args[0]->BooleanValue(): false);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> Window::ReloadIgnoringCache(const v8::Arguments& args) {
void Window::ReloadIgnoringCache(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
NavigationController& controller =
self->window_->GetWebContents()->GetController();
controller.ReloadIgnoringCache(
args[0]->IsBoolean() ? args[0]->BooleanValue(): false);
return v8::Undefined();
}
// static
void Window::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(Window::New);
t->InstanceTemplate()->SetInternalFieldCount(1);

View file

@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "browser/api/atom_api_event_emitter.h"
#include "browser/native_window_observer.h"
#include "common/v8/scoped_persistent.h"
namespace base {
class DictionaryValue;
@ -47,73 +48,73 @@ class Window : public EventEmitter,
virtual void OnRendererCrashed() OVERRIDE;
private:
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> Destroy(const v8::Arguments& args);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Destroy(const v8::FunctionCallbackInfo<v8::Value>& args);
// APIs for NativeWindow.
static v8::Handle<v8::Value> Close(const v8::Arguments& args);
static v8::Handle<v8::Value> Focus(const v8::Arguments& args);
static v8::Handle<v8::Value> IsFocused(const v8::Arguments& args);
static v8::Handle<v8::Value> Show(const v8::Arguments& args);
static v8::Handle<v8::Value> Hide(const v8::Arguments& args);
static v8::Handle<v8::Value> IsVisible(const v8::Arguments& args);
static v8::Handle<v8::Value> Maximize(const v8::Arguments& args);
static v8::Handle<v8::Value> Unmaximize(const v8::Arguments& args);
static v8::Handle<v8::Value> Minimize(const v8::Arguments& args);
static v8::Handle<v8::Value> Restore(const v8::Arguments& args);
static v8::Handle<v8::Value> SetFullscreen(const v8::Arguments& args);
static v8::Handle<v8::Value> IsFullscreen(const v8::Arguments& args);
static v8::Handle<v8::Value> SetSize(const v8::Arguments& args);
static v8::Handle<v8::Value> GetSize(const v8::Arguments& args);
static v8::Handle<v8::Value> SetMinimumSize(const v8::Arguments& args);
static v8::Handle<v8::Value> GetMinimumSize(const v8::Arguments& args);
static v8::Handle<v8::Value> SetMaximumSize(const v8::Arguments& args);
static v8::Handle<v8::Value> GetMaximumSize(const v8::Arguments& args);
static v8::Handle<v8::Value> SetResizable(const v8::Arguments& args);
static v8::Handle<v8::Value> IsResizable(const v8::Arguments& args);
static v8::Handle<v8::Value> SetAlwaysOnTop(const v8::Arguments& args);
static v8::Handle<v8::Value> IsAlwaysOnTop(const v8::Arguments& args);
static v8::Handle<v8::Value> Center(const v8::Arguments& args);
static v8::Handle<v8::Value> SetPosition(const v8::Arguments& args);
static v8::Handle<v8::Value> GetPosition(const v8::Arguments& args);
static v8::Handle<v8::Value> SetTitle(const v8::Arguments& args);
static v8::Handle<v8::Value> GetTitle(const v8::Arguments& args);
static v8::Handle<v8::Value> FlashFrame(const v8::Arguments& args);
static v8::Handle<v8::Value> SetKiosk(const v8::Arguments& args);
static v8::Handle<v8::Value> IsKiosk(const v8::Arguments& args);
static v8::Handle<v8::Value> OpenDevTools(const v8::Arguments& args);
static v8::Handle<v8::Value> CloseDevTools(const v8::Arguments& args);
static v8::Handle<v8::Value> IsDevToolsOpened(const v8::Arguments& args);
static v8::Handle<v8::Value> InspectElement(const v8::Arguments& args);
static v8::Handle<v8::Value> FocusOnWebView(const v8::Arguments& args);
static v8::Handle<v8::Value> BlurWebView(const v8::Arguments& args);
static v8::Handle<v8::Value> IsWebViewFocused(const v8::Arguments& args);
static v8::Handle<v8::Value> CapturePage(const v8::Arguments& args);
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Show(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Hide(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsVisible(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Maximize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Unmaximize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Minimize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Restore(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetFullscreen(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsFullscreen(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetSize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetSize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetMinimumSize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetMinimumSize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetMaximumSize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetMaximumSize(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetResizable(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsResizable(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetAlwaysOnTop(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsAlwaysOnTop(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Center(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetPosition(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetPosition(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetTitle(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetTitle(const v8::FunctionCallbackInfo<v8::Value>& args);
static void FlashFrame(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetKiosk(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsKiosk(const v8::FunctionCallbackInfo<v8::Value>& args);
static void OpenDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CloseDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsDevToolsOpened(const v8::FunctionCallbackInfo<v8::Value>& args);
static void InspectElement(const v8::FunctionCallbackInfo<v8::Value>& args);
static void FocusOnWebView(const v8::FunctionCallbackInfo<v8::Value>& args);
static void BlurWebView(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsWebViewFocused(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CapturePage(const v8::FunctionCallbackInfo<v8::Value>& args);
// APIs for WebContents.
static v8::Handle<v8::Value> GetPageTitle(const v8::Arguments& args);
static v8::Handle<v8::Value> IsLoading(const v8::Arguments& args);
static v8::Handle<v8::Value> IsWaitingForResponse(const v8::Arguments& args);
static v8::Handle<v8::Value> Stop(const v8::Arguments& args);
static v8::Handle<v8::Value> GetRoutingID(const v8::Arguments& args);
static v8::Handle<v8::Value> GetProcessID(const v8::Arguments& args);
static v8::Handle<v8::Value> IsCrashed(const v8::Arguments& args);
static void GetPageTitle(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsLoading(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsWaitingForResponse(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Stop(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetProcessID(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsCrashed(const v8::FunctionCallbackInfo<v8::Value>& args);
// APIs for NavigationController.
static v8::Handle<v8::Value> LoadURL(const v8::Arguments& args);
static v8::Handle<v8::Value> GetURL(const v8::Arguments& args);
static v8::Handle<v8::Value> CanGoBack(const v8::Arguments& args);
static v8::Handle<v8::Value> CanGoForward(const v8::Arguments& args);
static v8::Handle<v8::Value> CanGoToOffset(const v8::Arguments& args);
static v8::Handle<v8::Value> GoBack(const v8::Arguments& args);
static v8::Handle<v8::Value> GoForward(const v8::Arguments& args);
static v8::Handle<v8::Value> GoToIndex(const v8::Arguments& args);
static v8::Handle<v8::Value> GoToOffset(const v8::Arguments& args);
static v8::Handle<v8::Value> Reload(const v8::Arguments& args);
static v8::Handle<v8::Value> ReloadIgnoringCache(const v8::Arguments& args);
static void LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetURL(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CanGoBack(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CanGoForward(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CanGoToOffset(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GoBack(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GoForward(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GoToIndex(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GoToOffset(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Reload(const v8::FunctionCallbackInfo<v8::Value>& args);
static void ReloadIgnoringCache(const v8::FunctionCallbackInfo<v8::Value>& args);
// Called when capturePage is done.
void OnCapturePageDone(v8::Persistent<v8::Function> callback,
void OnCapturePageDone(const RefCountedV8Function& callback,
const std::vector<unsigned char>& data);
scoped_ptr<NativeWindow> window_;

View file

@ -8,13 +8,12 @@
#include "base/logging.h"
#include "browser/api/atom_api_event.h"
#include "common/v8_conversions.h"
#include "common/v8/native_type_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h"
#include "common/v8/node_common.h"
using content::V8ValueConverter;
using node::node_isolate;
namespace atom {
@ -27,16 +26,14 @@ AtomBrowserBindings::~AtomBrowserBindings() {
void AtomBrowserBindings::AfterLoad() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
v8::HandleScope scope;
v8::HandleScope handle_scope(node_isolate);
v8::Handle<v8::Object> global = node::g_context->Global();
v8::Handle<v8::Object> atom =
global->Get(v8::String::New("__atom"))->ToObject();
v8::Handle<v8::Object> global = global_env->context()->Global();
v8::Handle<v8::Object> atom = global->Get(ToV8Value("__atom"))->ToObject();
DCHECK(!atom.IsEmpty());
browser_main_parts_ = v8::Persistent<v8::Object>::New(
node_isolate,
atom->Get(v8::String::New("browserMainParts"))->ToObject());
browser_main_parts_.reset(
atom->Get(ToV8Value("browserMainParts"))->ToObject());
DCHECK(!browser_main_parts_.IsEmpty());
}
@ -44,9 +41,7 @@ void AtomBrowserBindings::OnRendererMessage(int process_id,
int routing_id,
const string16& channel,
const base::ListValue& args) {
v8::HandleScope scope;
v8::Handle<v8::Context> context = v8::Context::GetCurrent();
v8::HandleScope handle_scope(node_isolate);
scoped_ptr<V8ValueConverter> converter(new V8ValueConverterImpl());
@ -56,17 +51,20 @@ void AtomBrowserBindings::OnRendererMessage(int process_id,
arguments.push_back(ToV8Value(channel));
const base::Value* value;
if (args.Get(0, &value))
arguments.push_back(converter->ToV8Value(value, context));
arguments.push_back(converter->ToV8Value(value, global_env->context()));
arguments.push_back(v8::Integer::New(process_id));
arguments.push_back(v8::Integer::New(routing_id));
for (size_t i = 1; i < args.GetSize(); i++) {
const base::Value* value;
if (args.Get(i, &value))
arguments.push_back(converter->ToV8Value(value, context));
arguments.push_back(converter->ToV8Value(value, global_env->context()));
}
node::MakeCallback(node::process, "emit", arguments.size(), &arguments[0]);
node::MakeCallback(global_env->process_object(),
"emit",
arguments.size(),
&arguments[0]);
}
void AtomBrowserBindings::OnRendererMessageSync(
@ -76,9 +74,7 @@ void AtomBrowserBindings::OnRendererMessageSync(
const base::ListValue& args,
NativeWindow* sender,
IPC::Message* message) {
v8::HandleScope scope;
v8::Handle<v8::Context> context = v8::Context::GetCurrent();
v8::HandleScope handle_scope(node_isolate);
scoped_ptr<V8ValueConverter> converter(new V8ValueConverterImpl());
@ -92,7 +88,7 @@ void AtomBrowserBindings::OnRendererMessageSync(
arguments.push_back(ToV8Value(channel));
const base::Value* value;
if (args.Get(0, &value))
arguments.push_back(converter->ToV8Value(value, context));
arguments.push_back(converter->ToV8Value(value, global_env->context()));
arguments.push_back(event);
arguments.push_back(v8::Integer::New(process_id));
arguments.push_back(v8::Integer::New(routing_id));
@ -100,10 +96,13 @@ void AtomBrowserBindings::OnRendererMessageSync(
for (size_t i = 1; i < args.GetSize(); i++) {
const base::Value* value;
if (args.Get(i, &value))
arguments.push_back(converter->ToV8Value(value, context));
arguments.push_back(converter->ToV8Value(value, global_env->context()));
}
node::MakeCallback(node::process, "emit", arguments.size(), &arguments[0]);
node::MakeCallback(global_env->process_object(),
"emit",
arguments.size(),
&arguments[0]);
}
} // namespace atom

View file

@ -7,6 +7,7 @@
#include "base/strings/string16.h"
#include "common/api/atom_bindings.h"
#include "common/v8/scoped_persistent.h"
namespace base {
class ListValue;
@ -44,11 +45,11 @@ class AtomBrowserBindings : public AtomBindings {
// The require('atom').browserMainParts object.
v8::Handle<v8::Object> browser_main_parts() {
return browser_main_parts_;
return browser_main_parts_.NewHandle();
}
private:
v8::Persistent<v8::Object> browser_main_parts_;
ScopedPersistent<v8::Object> browser_main_parts_;
DISALLOW_COPY_AND_ASSIGN(AtomBrowserBindings);
};