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

@ -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();
}
}