'atom/browser/api/atom_api_auto_updater.h',
'atom/browser/api/atom_api_browser_ipc.cc',
'atom/browser/api/atom_api_dialog.cc',
- 'atom/browser/api/atom_api_event.cc',
- 'atom/browser/api/atom_api_event.h',
'atom/browser/api/atom_api_menu.cc',
'atom/browser/api/atom_api_menu.h',
'atom/browser/api/atom_api_menu_gtk.cc',
'atom/common/api/api_messages.h',
'atom/common/api/atom_api_clipboard.cc',
'atom/common/api/atom_api_crash_reporter.cc',
- 'atom/common/api/atom_api_event_emitter.cc',
- 'atom/common/api/atom_api_event_emitter.h',
'atom/common/api/atom_api_id_weak_map.cc',
'atom/common/api/atom_api_id_weak_map.h',
'atom/common/api/atom_api_screen.cc',
'atom/common/linux/application_info.cc',
'atom/common/native_mate_converters/file_path_converter.h',
'atom/common/native_mate_converters/function_converter.h',
+ 'atom/common/native_mate_converters/gurl_converter.h',
'atom/common/native_mate_converters/string16_converter.h',
'atom/common/native_mate_converters/v8_value_converter.cc',
'atom/common/native_mate_converters/v8_value_converter.h',
'atom/common/platform_util_linux.cc',
'atom/common/platform_util_mac.mm',
'atom/common/platform_util_win.cc',
- 'atom/common/swap_or_assign.h',
- 'atom/common/v8/scoped_persistent.h',
- 'atom/common/v8/native_type_conversions.h',
'atom/renderer/api/atom_api_renderer_ipc.cc',
'atom/renderer/api/atom_renderer_bindings.cc',
'atom/renderer/api/atom_renderer_bindings.h',
#include "atom/common/node_includes.h"
-namespace mate {
-
-template<>
-struct Converter<atom::NativeWindow*> {
- static bool FromV8(v8::Isolate* isolate,
- v8::Handle<v8::Value> val,
- atom::NativeWindow** out) {
- using atom::api::Window;
- if (val->IsNull()) {
- *out = NULL;
- return true; // NULL is a valid value for NativeWindow*.
- } else if (val->IsObject()) {
- Window* window = Window::Unwrap<Window>(val->ToObject());
- *out = window->window();
- return true;
- } else {
- return false;
- }
- }
-};
-
-} // namespace mate
-
-
namespace {
void ShowMessageBox(int type,
const std::string& title,
const std::string& message,
const std::string& detail,
- atom::NativeWindow* window,
+ atom::api::Window* window,
mate::Arguments* args) {
v8::Handle<v8::Value> peek = args->PeekNext();
atom::MessageBoxCallback callback;
if (mate::Converter<atom::MessageBoxCallback>::FromV8(node_isolate,
peek,
&callback)) {
- atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, title,
- message, detail, callback);
+ atom::ShowMessageBox(window->window(), (atom::MessageBoxType)type, buttons,
+ title, message, detail, callback);
} else {
int chosen = atom::ShowMessageBox(
- window,
+ window->window(),
(atom::MessageBoxType)type,
buttons,
title,
void ShowOpenDialog(const std::string& title,
const base::FilePath& default_path,
int properties,
- atom::NativeWindow* window,
+ atom::api::Window* window,
mate::Arguments* args) {
v8::Handle<v8::Value> peek = args->PeekNext();
file_dialog::OpenDialogCallback callback;
if (mate::Converter<file_dialog::OpenDialogCallback>::FromV8(node_isolate,
peek,
&callback)) {
- file_dialog::ShowOpenDialog(window, title, default_path, properties,
- callback);
+ file_dialog::ShowOpenDialog(window->window(), title, default_path,
+ properties, callback);
} else {
std::vector<base::FilePath> paths;
- if (file_dialog::ShowOpenDialog(window,
+ if (file_dialog::ShowOpenDialog(window->window(),
title,
default_path,
properties,
void ShowSaveDialog(const std::string& title,
const base::FilePath& default_path,
- atom::NativeWindow* window,
+ atom::api::Window* window,
mate::Arguments* args) {
v8::Handle<v8::Value> peek = args->PeekNext();
file_dialog::SaveDialogCallback callback;
if (mate::Converter<file_dialog::SaveDialogCallback>::FromV8(node_isolate,
peek,
&callback)) {
- file_dialog::ShowSaveDialog(window, title, default_path, callback);
+ file_dialog::ShowSaveDialog(window->window(), title, default_path,
+ callback);
} else {
base::FilePath path;
- if (file_dialog::ShowSaveDialog(window,
- title,
- default_path,
+ if (file_dialog::ShowSaveDialog(window->window(), title, default_path,
&path))
args->Return(path);
}
+++ /dev/null
-// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "atom/browser/api/atom_api_event.h"
-
-#include "atom/common/api/api_messages.h"
-#include "atom/common/node_includes.h"
-#include "atom/common/v8/native_type_conversions.h"
-#include "content/public/browser/web_contents.h"
-
-namespace atom {
-
-namespace api {
-
-ScopedPersistent<v8::Function> Event::constructor_template_;
-
-Event::Event()
- : sender_(NULL),
- message_(NULL),
- prevent_default_(false) {
-}
-
-Event::~Event() {
-}
-
-// static
-v8::Handle<v8::Object> Event::CreateV8Object() {
- if (constructor_template_.IsEmpty()) {
- v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(New);
- 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::Function> t = constructor_template_.NewHandle(node_isolate);
- return t->NewInstance(0, NULL);
-}
-
-void Event::SetSenderAndMessage(content::WebContents* sender,
- IPC::Message* message) {
- DCHECK(!sender_);
- DCHECK(!message_);
- sender_ = sender;
- message_ = message;
-
- Observe(sender);
-}
-
-void Event::WebContentsDestroyed(content::WebContents* web_contents) {
- sender_ = NULL;
- message_ = NULL;
-}
-
-// static
-void Event::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
- Event* event = new Event;
- event->Wrap(args.This());
-}
-
-// static
-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;
-}
-
-// static
-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");
-
- if (event->message_ == NULL || event->sender_ == NULL)
- return node::ThrowError("Can only send reply to synchronous events");
-
- string16 json = FromV8Value(args[0]);
-
- AtomViewHostMsg_Message_Sync::WriteReplyParams(event->message_, json);
- event->sender_->Send(event->message_);
-
- delete event;
-}
-
-// static
-void Event::Destroy(const v8::FunctionCallbackInfo<v8::Value>& args) {
- delete Unwrap<Event>(args.This());
-}
-
-} // namespace api
-
-} // namespace atom
+++ /dev/null
-// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_BROWSER_API_ATOM_API_EVENT_H_
-#define ATOM_BROWSER_API_ATOM_API_EVENT_H_
-
-#include "atom/common/v8/scoped_persistent.h"
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/strings/string16.h"
-#include "content/public/browser/web_contents_observer.h"
-#include "vendor/node/src/node_object_wrap.h"
-
-namespace IPC {
-class Message;
-}
-
-namespace atom {
-
-namespace api {
-
-class Event : public node::ObjectWrap,
- public content::WebContentsObserver {
- public:
- virtual ~Event();
-
- // Create a V8 Event object.
- static v8::Handle<v8::Object> CreateV8Object();
-
- // Pass the sender and message to be replied.
- void SetSenderAndMessage(content::WebContents* sender, IPC::Message* message);
-
- // Whether event.preventDefault() is called.
- bool prevent_default() const { return prevent_default_; }
-
- protected:
- Event();
-
- // content::WebContentsObserver implementations:
- virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
-
- private:
- static void New(const v8::FunctionCallbackInfo<v8::Value>& 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 ScopedPersistent<v8::Function> constructor_template_;
-
- // Replyer for the synchronous messages.
- content::WebContents* sender_;
- IPC::Message* message_;
-
- bool prevent_default_;
-
- DISALLOW_COPY_AND_ASSIGN(Event);
-};
-
-} // namespace api
-
-} // namespace atom
-
-#endif // ATOM_BROWSER_API_ATOM_API_EVENT_H_
#include "atom/common/node_includes.h"
-namespace mate {
-
-template<>
-struct Converter<atom::NativeWindow*> {
- static bool FromV8(v8::Isolate* isolate,
- v8::Handle<v8::Value> val,
- atom::NativeWindow** out) {
- using atom::api::Window;
- if (val->IsNull()) {
- *out = NULL;
- return true; // NULL is a valid value for NativeWindow*.
- } else if (val->IsObject()) {
- Window* window = Window::Unwrap<Window>(val->ToObject());
- *out = window->window();
- return true;
- } else {
- return false;
- }
- }
-};
-
-} // namespace mate
-
-
namespace atom {
namespace api {
#include <string>
+#include "atom/browser/api/atom_api_window.h"
#include "base/memory/scoped_ptr.h"
#include "ui/base/models/simple_menu_model.h"
#include "native_mate/wrappable.h"
namespace atom {
-class NativeWindow;
-
namespace api {
class MenuMac;
virtual string16 GetSublabelForCommandId(int command_id) const OVERRIDE;
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
- virtual void Popup(NativeWindow* window) = 0;
+ virtual void Popup(Window* window) = 0;
scoped_ptr<ui::SimpleMenuModel> model_;
bool IsVisibleAt(int index) const;
#if defined(OS_WIN) || defined(TOOLKIT_GTK)
- void AttachToWindow(NativeWindow* window);
+ void AttachToWindow(Window* window);
#endif
DISALLOW_COPY_AND_ASSIGN(Menu);
MenuGtk::MenuGtk() {
}
-void MenuGtk::Popup(NativeWindow* native_window) {
+void MenuGtk::Popup(Window* window) {
uint32_t triggering_event_time;
gfx::Point point;
+ BrowserWindow* native_window = window->window();
GdkEventButton* event = native_window->GetWebContents()->
GetRenderWidgetHostView()->GetLastMouseDown();
if (event) {
menu_gtk_->PopupAsContext(point, triggering_event_time);
}
-void Menu::AttachToWindow(NativeWindow* window) {
- if (window == NULL)
- return node::ThrowTypeError("Window is dead");
-
- static_cast<NativeWindowGtk*>(native_window)->SetMenu(model_.get());
+void Menu::AttachToWindow(Window* window) {
+ static_cast<NativeWindowGtk*>(window->window())->SetMenu(model_.get());
}
// static
class MenuGtk : public Menu,
public ::MenuGtk::Delegate {
protected:
- virtual void Popup(NativeWindow* window) OVERRIDE;
+ virtual void Popup(Window* window) OVERRIDE;
private:
MenuGtk();
protected:
MenuMac();
- virtual void Popup(NativeWindow* window) OVERRIDE;
+ virtual void Popup(Window* window) OVERRIDE;
base::scoped_nsobject<AtomMenuController> menu_controller_;
MenuMac::MenuMac() {
}
-void MenuMac::Popup(NativeWindow* native_window) {
+void MenuMac::Popup(Window* window) {
base::scoped_nsobject<AtomMenuController> menu_controller(
[[AtomMenuController alloc] initWithModel:model_.get()]);
- NSWindow* window = native_window->GetNativeWindow();
+ NativeWindow* native_window = window->window();
+ NSWindow* nswindow = native_window->GetNativeWindow();
content::WebContents* web_contents = native_window->GetWebContents();
// Fake out a context menu event.
NSEvent* currentEvent = [NSApp currentEvent];
- NSPoint position = [window mouseLocationOutsideOfEventStream];
+ NSPoint position = [nswindow mouseLocationOutsideOfEventStream];
NSTimeInterval eventTime = [currentEvent timestamp];
NSEvent* clickEvent = [NSEvent mouseEventWithType:NSRightMouseDown
location:position
modifierFlags:NSRightMouseDownMask
timestamp:eventTime
- windowNumber:[window windowNumber]
+ windowNumber:[nswindow windowNumber]
context:nil
eventNumber:0
clickCount:1
MenuWin::MenuWin() {
}
-void MenuWin::Popup(NativeWindow* native_window) {
+void MenuWin::Popup(Window* window) {
gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
menu_.reset(new atom::Menu2(model_.get()));
menu_->RunContextMenuAt(cursor);
}
-void Menu::AttachToWindow(NativeWindow* window) {
- if (window == NULL)
- return node::ThrowTypeError("Window is dead");
-
- static_cast<NativeWindowWin*>(native_window)->SetMenu(model_.get());
+void Menu::AttachToWindow(Window* window) {
+ static_cast<NativeWindowWin*>(window->window())->SetMenu(model_.get());
}
// static
class MenuWin : public Menu {
protected:
- virtual void Popup(NativeWindow* window) OVERRIDE;
+ virtual void Popup(Window* window) OVERRIDE;
private:
MenuWin();
#include "atom/browser/api/atom_api_window.h"
-#include <string>
-
+#include "atom/browser/native_window.h"
+#include "atom/common/native_mate_converters/function_converter.h"
+#include "atom/common/native_mate_converters/gurl_converter.h"
+#include "atom/common/native_mate_converters/string16_converter.h"
+#include "atom/common/native_mate_converters/value_converter.h"
#include "base/bind.h"
+#include "base/callback.h"
#include "base/process/kill.h"
-#include "atom/browser/native_window.h"
-#include "atom/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"
+#include "native_mate/constructor.h"
+#include "native_mate/dictionary.h"
#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "atom/common/node_includes.h"
-#include "vendor/node/src/node_buffer.h"
using content::NavigationController;
-using node::ObjectWrap;
-#define UNWRAP_WINDOW_AND_CHECK \
- Window* self = ObjectWrap::Unwrap<Window>(args.This()); \
- if (self == NULL) \
- return node::ThrowError("Window is already destroyed")
+namespace mate {
+
+template<>
+struct Converter<gfx::Rect> {
+ static bool FromV8(v8::Isolate* isolate,
+ v8::Handle<v8::Value> val,
+ gfx::Rect* out) {
+ if (!val->IsObject())
+ return false;
+ mate::Dictionary dict(isolate, val->ToObject());
+ int x, y, width, height;
+ if (!dict.Get("x", &x) || !dict.Get("y", &y) ||
+ !dict.Get("width", &width) || !dict.Get("height", &height))
+ return false;
+ *out = gfx::Rect(x, y, width, height);
+ return true;
+ }
+};
+
+} // namespace mate
namespace atom {
namespace api {
-Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
- : EventEmitter(wrapper),
- window_(NativeWindow::Create(options)) {
+namespace {
+
+void OnCapturePageDone(
+ const base::Callback<void(v8::Handle<v8::Value>)>& callback,
+ const std::vector<unsigned char>& data) {
+ v8::Locker locker(node_isolate);
+ v8::HandleScope handle_scope(node_isolate);
+
+ v8::Local<v8::Value> buffer = node::Buffer::New(
+ reinterpret_cast<const char*>(data.data()),
+ data.size());
+ callback.Run(buffer);
+}
+
+} // namespace
+
+
+Window::Window(base::DictionaryValue* options)
+ : window_(NativeWindow::Create(options)) {
window_->InitFromOptions(options);
window_->AddObserver(this);
}
const std::string& title) {
base::ListValue args;
args.AppendString(title);
- *prevent_default = Emit("page-title-updated", &args);
+ *prevent_default = Emit("page-title-updated", args);
}
void Window::OnLoadingStateChanged(bool is_loading) {
base::ListValue args;
args.AppendBoolean(is_loading);
- Emit("loading-state-changed", &args);
+ Emit("loading-state-changed", args);
}
void Window::WillCloseWindow(bool* prevent_default) {
void Window::OnWindowClosed() {
Emit("closed");
-
- // Free memory when native window is closed, the delete is delayed so other
- // observers would not get a invalid pointer of NativeWindow.
- base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
void Window::OnWindowBlur() {
base::ListValue args;
args.AppendInteger(process_id);
args.AppendInteger(routing_id);
- Emit("render-view-deleted", &args);
+ Emit("render-view-deleted", args);
}
void Window::OnRendererCrashed() {
Emit("crashed");
}
-void Window::OnCapturePageDone(const RefCountedV8Function& callback,
- const std::vector<unsigned char>& data) {
- v8::Locker locker(node_isolate);
- v8::HandleScope handle_scope(node_isolate);
-
- v8::Local<v8::Value> buffer = node::Buffer::New(
- reinterpret_cast<const char*>(data.data()),
- data.size());
- callback->NewHandle(node_isolate)->Call(
- v8::Context::GetCurrent()->Global(), 1, &buffer);
-}
-
// static
-void Window::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
- if (!args.IsConstructCall())
- return node::ThrowError("Require constructor call");
-
- scoped_ptr<base::Value> options;
- if (!FromV8Arguments(args, &options))
- return node::ThrowTypeError("Bad argument");
-
- if (!options || !options->IsType(base::Value::TYPE_DICTIONARY))
- return node::ThrowTypeError("Options must be dictionary");
-
- new Window(args.This(), static_cast<base::DictionaryValue*>(options.get()));
+mate::Wrappable* Window::New(mate::Arguments* args,
+ const base::DictionaryValue& options) {
+ scoped_ptr<base::DictionaryValue> copied_options(options.DeepCopy());
+ Window* window = new Window(copied_options.get());
+ window->Wrap(args->isolate(), args->GetThis());
// Give js code a chance to do initialization.
- node::MakeCallback(args.This(), "_init", 0, NULL);
-}
-
-// static
-void Window::Destroy(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
+ node::MakeCallback(args->GetThis(), "_init", 0, NULL);
- base::ProcessHandle handle = self->window_->GetRenderProcessHandle();
- delete self;
-
- // Make sure the renderer process is terminated, it could happen that the
- // renderer process became a zombie.
- base::MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(base::IgnoreResult(base::KillProcess), handle, 0, false),
- base::TimeDelta::FromMilliseconds(5000));
+ return window;
}
-// static
-void Window::Close(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Close();
+void Window::Destroy() {
+ base::KillProcess(window_->GetRenderProcessHandle(), 0, false);
+ window_->CloseImmediately();
}
-// static
-void Window::Focus(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Focus(args[0]->IsBoolean() ? args[0]->BooleanValue(): true);
+void Window::Close() {
+ window_->Close();
}
-// static
-void Window::IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->IsFocused());
+void Window::Focus() {
+ window_->Focus(true);
}
-// static
-void Window::Show(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Show();
+bool Window::IsFocused() {
+ return window_->IsFocused();
}
-// static
-void Window::Hide(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Hide();
+void Window::Show() {
+ window_->Show();
}
-// static
-void Window::IsVisible(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- return args.GetReturnValue().Set(self->window_->IsVisible());
+void Window::Hide() {
+ window_->Hide();
}
-// static
-void Window::Maximize(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Maximize();
+bool Window::IsVisible() {
+ return window_->IsVisible();
}
-// static
-void Window::Unmaximize(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Unmaximize();
+void Window::Maximize() {
+ window_->Maximize();
}
-// static
-void Window::Minimize(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Minimize();
+void Window::Unmaximize() {
+ window_->Unmaximize();
}
-// static
-void Window::Restore(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Restore();
+void Window::Minimize() {
+ window_->Minimize();
}
-// static
-void Window::SetFullscreen(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- bool fs;
- if (!FromV8Arguments(args, &fs))
- return node::ThrowTypeError("Bad argument");
-
- self->window_->SetFullscreen(fs);
+void Window::Restore() {
+ window_->Restore();
}
-// static
-void Window::IsFullscreen(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->IsFullscreen());
+void Window::SetFullscreen(bool fullscreen) {
+ window_->SetFullscreen(fullscreen);
}
-// static
-void Window::SetSize(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_->SetSize(gfx::Size(width, height));
+bool Window::IsFullscreen() {
+ return window_->IsFullscreen();
}
-// static
-void Window::GetSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- gfx::Size size = self->window_->GetSize();
- v8::Handle<v8::Array> ret = v8::Array::New(2);
- ret->Set(0, ToV8Value(size.width()));
- ret->Set(1, ToV8Value(size.height()));
-
- args.GetReturnValue().Set(ret);
+void Window::SetSize(int width, int height) {
+ window_->SetSize(gfx::Size(width, height));
}
-// static
-void Window::SetMinimumSize(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_->SetMinimumSize(gfx::Size(width, height));
+std::vector<int> Window::GetSize() {
+ std::vector<int> result(2);
+ gfx::Size size = window_->GetSize();
+ result[0] = size.width();
+ result[1] = size.height();
+ return result;
}
-// static
-void Window::GetMinimumSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- gfx::Size size = self->window_->GetMinimumSize();
- v8::Handle<v8::Array> ret = v8::Array::New(2);
- ret->Set(0, ToV8Value(size.width()));
- ret->Set(1, ToV8Value(size.height()));
-
- args.GetReturnValue().Set(ret);
+void Window::SetMinimumSize(int width, int height) {
+ window_->SetMinimumSize(gfx::Size(width, height));
}
-// static
-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));
+std::vector<int> Window::GetMinimumSize() {
+ std::vector<int> result(2);
+ gfx::Size size = window_->GetMinimumSize();
+ result[0] = size.width();
+ result[1] = size.height();
+ return result;
}
-// static
-void Window::GetMaximumSize(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- gfx::Size size = self->window_->GetMaximumSize();
- v8::Handle<v8::Array> ret = v8::Array::New(2);
- ret->Set(0, ToV8Value(size.width()));
- ret->Set(1, ToV8Value(size.height()));
-
- args.GetReturnValue().Set(ret);
+void Window::SetMaximumSize(int width, int height) {
+ window_->SetMaximumSize(gfx::Size(width, height));
}
-// static
-void Window::SetResizable(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- bool resizable;
- if (!FromV8Arguments(args, &resizable))
- return node::ThrowTypeError("Bad argument");
-
- self->window_->SetResizable(resizable);
+std::vector<int> Window::GetMaximumSize() {
+ std::vector<int> result(2);
+ gfx::Size size = window_->GetMaximumSize();
+ result[0] = size.width();
+ result[1] = size.height();
+ return result;
}
-// static
-void Window::IsResizable(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->IsResizable());
+void Window::SetResizable(bool resizable) {
+ window_->SetResizable(resizable);
}
-// static
-void Window::SetAlwaysOnTop(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- bool top;
- if (!FromV8Arguments(args, &top))
- return node::ThrowTypeError("Bad argument");
-
- self->window_->SetAlwaysOnTop(top);
+bool Window::IsResizable() {
+ return window_->IsResizable();
}
-// static
-void Window::IsAlwaysOnTop(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->IsAlwaysOnTop());
+void Window::SetAlwaysOnTop(bool top) {
+ window_->SetAlwaysOnTop(top);
}
-// static
-void Window::Center(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->Center();
+bool Window::IsAlwaysOnTop() {
+ return window_->IsAlwaysOnTop();
}
-// static
-void Window::SetPosition(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- int x, y;
- if (!FromV8Arguments(args, &x, &y))
- return node::ThrowTypeError("Bad argument");
-
- self->window_->SetPosition(gfx::Point(x, y));
+void Window::Center() {
+ window_->Center();
}
-// static
-void Window::GetPosition(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- gfx::Point pos = self->window_->GetPosition();
- v8::Handle<v8::Array> ret = v8::Array::New(2);
- ret->Set(0, ToV8Value(pos.x()));
- ret->Set(1, ToV8Value(pos.y()));
-
- args.GetReturnValue().Set(ret);
+void Window::SetPosition(int x, int y) {
+ window_->SetPosition(gfx::Point(x, y));
}
-// static
-void Window::SetTitle(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- std::string title;
- if (!FromV8Arguments(args, &title))
- return node::ThrowTypeError("Bad argument");
-
- self->window_->SetTitle(title);
+std::vector<int> Window::GetPosition() {
+ std::vector<int> result(2);
+ gfx::Point pos = window_->GetPosition();
+ result[0] = pos.x();
+ result[1] = pos.y();
+ return result;
}
-// static
-void Window::GetTitle(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(ToV8Value(self->window_->GetTitle()));
+void Window::SetTitle(const std::string& title) {
+ window_->SetTitle(title);
}
-// static
-void Window::FlashFrame(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->FlashFrame(
- args[0]->IsBoolean() ? args[0]->BooleanValue(): true);
+std::string Window::GetTitle() {
+ return window_->GetTitle();
}
-// static
-void Window::SetKiosk(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- bool kiosk;
- if (!FromV8Arguments(args, &kiosk))
- return node::ThrowTypeError("Bad argument");
-
- self->window_->SetKiosk(kiosk);
+void Window::FlashFrame(bool flash) {
+ window_->FlashFrame(flash);
}
-// static
-void Window::IsKiosk(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->IsKiosk());
+void Window::SetKiosk(bool kiosk) {
+ window_->SetKiosk(kiosk);
}
-// static
-void Window::OpenDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->OpenDevTools();
+bool Window::IsKiosk() {
+ return window_->IsKiosk();
}
-// static
-void Window::CloseDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->CloseDevTools();
+void Window::OpenDevTools() {
+ window_->OpenDevTools();
}
-// static
-void Window::IsDevToolsOpened(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->IsDevToolsOpened());
+void Window::CloseDevTools() {
+ window_->CloseDevTools();
}
-// static
-void Window::InspectElement(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- int x, y;
- if (!FromV8Arguments(args, &x, &y))
- return node::ThrowTypeError("Bad argument");
-
- self->window_->InspectElement(x, y);
+bool Window::IsDevToolsOpened() {
+ return window_->IsDevToolsOpened();
}
-// static
-void Window::DebugDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- if (self->window_->IsDevToolsOpened())
- NativeWindow::Debug(self->window_->GetDevToolsWebContents());
+void Window::InspectElement(int x, int y) {
+ window_->InspectElement(x, y);
}
-// static
-void Window::FocusOnWebView(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->FocusOnWebView();
+void Window::DebugDevTools() {
+ if (window_->IsDevToolsOpened())
+ NativeWindow::Debug(window_->GetDevToolsWebContents());
}
-// static
-void Window::BlurWebView(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->BlurWebView();
+void Window::FocusOnWebView() {
+ window_->FocusOnWebView();
}
-// static
-void Window::IsWebViewFocused(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->IsWebViewFocused());
+void Window::BlurWebView() {
+ window_->BlurWebView();
}
-// static
-void Window::CapturePage(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
+bool Window::IsWebViewFocused() {
+ return window_->IsWebViewFocused();
+}
+void Window::CapturePage(mate::Arguments* args) {
gfx::Rect rect;
- RefCountedV8Function callback;
- if (!FromV8Arguments(args, &rect, &callback) &&
- !FromV8Arguments(args, &callback))
- return node::ThrowTypeError("Bad argument");
+ base::Callback<void(v8::Handle<v8::Value>)> callback;
- self->window_->CapturePage(rect, base::Bind(&Window::OnCapturePageDone,
- base::Unretained(self),
- callback));
-}
+ if ((args->Length() == 1 && !args->GetNext(&callback)) ||
+ (args->Length() == 2 && !args->GetNext(&rect)
+ && !args->GetNext(&callback)) ||
+ (args->Length() == 0)) {
+ args->ThrowError();
+ return;
+ }
-// static
-void Window::GetPageTitle(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(ToV8Value(
- self->window_->GetWebContents()->GetTitle()));
+ window_->CapturePage(rect, base::Bind(&OnCapturePageDone, callback));
}
-// static
-void Window::IsLoading(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->GetWebContents()->IsLoading());
+string16 Window::GetPageTitle() {
+ return window_->GetWebContents()->GetTitle();
}
-// static
-void Window::IsWaitingForResponse(
- const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(
- self->window_->GetWebContents()->IsWaitingForResponse());
+bool Window::IsLoading() {
+ return window_->GetWebContents()->IsLoading();
}
-// static
-void Window::Stop(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- self->window_->GetWebContents()->Stop();
+bool Window::IsWaitingForResponse() {
+ return window_->GetWebContents()->IsWaitingForResponse();
}
-// static
-void Window::GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->GetWebContents()->GetRoutingID());
+void Window::Stop() {
+ window_->GetWebContents()->Stop();
}
-// static
-void Window::GetProcessID(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- args.GetReturnValue().Set(
- self->window_->GetWebContents()->GetRenderProcessHost()->GetID());
+int Window::GetRoutingID() {
+ return window_->GetWebContents()->GetRoutingID();
}
-// static
-void Window::IsCrashed(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
- args.GetReturnValue().Set(self->window_->GetWebContents()->IsCrashed());
+int Window::GetProcessID() {
+ return window_->GetWebContents()->GetRenderProcessHost()->GetID();
}
-// static
-void Window::GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- content::WebContents* web_contents = self->window_->GetDevToolsWebContents();
- v8::Local<v8::Object> devtools = v8::Object::New();
- devtools->Set(ToV8Value("processId"),
- ToV8Value(web_contents->GetRenderProcessHost()->GetID()));
- devtools->Set(ToV8Value("routingId"),
- ToV8Value(web_contents->GetRoutingID()));
- args.GetReturnValue().Set(devtools);
+bool Window::IsCrashed() {
+ return window_->GetWebContents()->IsCrashed();
}
-// static
-void Window::ExecuteJavaScriptInDevTools(
- const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- std::string code;
- if (!FromV8Arguments(args, &code))
- return node::ThrowTypeError("Bad argument");
-
- self->window_->ExecuteJavaScriptInDevTools(code);
+mate::Dictionary Window::GetDevTools(v8::Isolate* isolate) {
+ content::WebContents* web_contents = window_->GetDevToolsWebContents();
+ mate::Dictionary dict(isolate);
+ dict.Set("processId", web_contents->GetRenderProcessHost()->GetID());
+ dict.Set("routingId", web_contents->GetRoutingID());
+ return dict;
}
-// static
-void Window::LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- GURL url;
- if (!FromV8Arguments(args, &url))
- return node::ThrowTypeError("Bad argument");
+void Window::ExecuteJavaScriptInDevTools(const std::string& code) {
+ window_->ExecuteJavaScriptInDevTools(code);
+}
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
+void Window::LoadURL(const GURL& url) {
+ NavigationController& controller = window_->GetWebContents()->GetController();
content::NavigationController::LoadURLParams params(url);
params.transition_type = content::PAGE_TRANSITION_TYPED;
controller.LoadURLWithParams(params);
}
-// static
-void Window::GetURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
- GURL url;
- if (controller.GetActiveEntry())
- url = controller.GetActiveEntry()->GetVirtualURL();
-
- args.GetReturnValue().Set(ToV8Value(url));
+GURL Window::GetURL() {
+ NavigationController& controller = window_->GetWebContents()->GetController();
+ if (!controller.GetActiveEntry())
+ return GURL();
+ return controller.GetActiveEntry()->GetVirtualURL();
+}
+
+bool Window::CanGoBack() {
+ return window_->GetWebContents()->GetController().CanGoBack();
+}
+
+bool Window::CanGoForward() {
+ return window_->GetWebContents()->GetController().CanGoForward();
+}
+
+bool Window::CanGoToOffset(int offset) {
+ return window_->GetWebContents()->GetController().CanGoToOffset(offset);
+}
+
+void Window::GoBack() {
+ window_->GetWebContents()->GetController().GoBack();
+}
+
+void Window::GoForward() {
+ window_->GetWebContents()->GetController().GoForward();
+}
+
+void Window::GoToIndex(int index) {
+ window_->GetWebContents()->GetController().GoToIndex(index);
+}
+
+void Window::GoToOffset(int offset) {
+ window_->GetWebContents()->GetController().GoToOffset(offset);
+}
+
+void Window::Reload() {
+ window_->GetWebContents()->GetController().Reload(false);
+}
+
+void Window::ReloadIgnoringCache() {
+ window_->GetWebContents()->GetController().ReloadIgnoringCache(false);
+}
+
+// static
+void Window::BuildPrototype(v8::Isolate* isolate,
+ v8::Handle<v8::ObjectTemplate> prototype) {
+ mate::ObjectTemplateBuilder(isolate, prototype)
+ .SetMethod("destroy", &Window::Destroy)
+ .SetMethod("close", &Window::Close)
+ .SetMethod("focus", &Window::Focus)
+ .SetMethod("isFocused", &Window::IsFocused)
+ .SetMethod("show", &Window::Show)
+ .SetMethod("hide", &Window::Hide)
+ .SetMethod("isVisible", &Window::IsVisible)
+ .SetMethod("maximize", &Window::Maximize)
+ .SetMethod("unmaximize", &Window::Unmaximize)
+ .SetMethod("minimize", &Window::Minimize)
+ .SetMethod("restore", &Window::Restore)
+ .SetMethod("setFullScreen", &Window::SetFullscreen)
+ .SetMethod("isFullScreen", &Window::IsFullscreen)
+ .SetMethod("getSize", &Window::GetSize)
+ .SetMethod("setSize", &Window::SetSize)
+ .SetMethod("setMinimumSize", &Window::SetMinimumSize)
+ .SetMethod("getMinimumSize", &Window::GetMinimumSize)
+ .SetMethod("setMaximumSize", &Window::SetMaximumSize)
+ .SetMethod("getMaximumSize", &Window::GetMaximumSize)
+ .SetMethod("setResizable", &Window::SetResizable)
+ .SetMethod("isResizable", &Window::IsResizable)
+ .SetMethod("setAlwaysOnTop", &Window::SetAlwaysOnTop)
+ .SetMethod("isAlwaysOnTop", &Window::IsAlwaysOnTop)
+ .SetMethod("center", &Window::Center)
+ .SetMethod("setPosition", &Window::SetPosition)
+ .SetMethod("getPosition", &Window::GetPosition)
+ .SetMethod("setTitle", &Window::SetTitle)
+ .SetMethod("getTitle", &Window::GetTitle)
+ .SetMethod("flashFrame", &Window::FlashFrame)
+ .SetMethod("setKiosk", &Window::SetKiosk)
+ .SetMethod("isKiosk", &Window::IsKiosk)
+ .SetMethod("openDevTools", &Window::OpenDevTools)
+ .SetMethod("closeDevTools", &Window::CloseDevTools)
+ .SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened)
+ .SetMethod("inspectElement", &Window::InspectElement)
+ .SetMethod("debugDevTools", &Window::DebugDevTools)
+ .SetMethod("focusOnWebView", &Window::FocusOnWebView)
+ .SetMethod("blurWebView", &Window::BlurWebView)
+ .SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
+ .SetMethod("capturePage", &Window::CapturePage)
+ .SetMethod("getPageTitle", &Window::GetPageTitle)
+ .SetMethod("isLoading", &Window::IsLoading)
+ .SetMethod("isWaitingForResponse", &Window::IsWaitingForResponse)
+ .SetMethod("stop", &Window::Stop)
+ .SetMethod("getRoutingId", &Window::GetRoutingID)
+ .SetMethod("getProcessId", &Window::GetProcessID)
+ .SetMethod("isCrashed", &Window::IsCrashed)
+ .SetMethod("getDevTools", &Window::GetDevTools)
+ .SetMethod("executeJavaScriptInDevTools",
+ &Window::ExecuteJavaScriptInDevTools)
+ .SetMethod("loadUrl", &Window::LoadURL)
+ .SetMethod("getUrl", &Window::GetURL)
+ .SetMethod("canGoBack", &Window::CanGoBack)
+ .SetMethod("canGoForward", &Window::CanGoForward)
+ .SetMethod("canGoToOffset", &Window::CanGoToOffset)
+ .SetMethod("goBack", &Window::GoBack)
+ .SetMethod("goForward", &Window::GoForward)
+ .SetMethod("goToIndex", &Window::GoToIndex)
+ .SetMethod("goToOffset", &Window::GoToOffset)
+ .SetMethod("reload", &Window::Reload)
+ .SetMethod("reloadIgnoringCache", &Window::ReloadIgnoringCache);
}
-// static
-void Window::CanGoBack(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
-
- args.GetReturnValue().Set(controller.CanGoBack());
-}
-
-// static
-void Window::CanGoForward(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
-
- args.GetReturnValue().Set(controller.CanGoForward());
-}
-
-// static
-void Window::CanGoToOffset(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- int offset;
- if (!FromV8Arguments(args, &offset))
- return node::ThrowTypeError("Bad argument");
-
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
-
- args.GetReturnValue().Set(controller.CanGoToOffset(offset));
-}
-
-// static
-void Window::GoBack(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
- controller.GoBack();
-}
-
-// static
-void Window::GoForward(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
- controller.GoForward();
-}
-
-// static
-void Window::GoToIndex(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- int index;
- if (!FromV8Arguments(args, &index))
- return node::ThrowTypeError("Bad argument");
-
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
- controller.GoToIndex(index);
-}
-
-// static
-void Window::GoToOffset(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
-
- int offset;
- if (!FromV8Arguments(args, &offset))
- return node::ThrowTypeError("Bad argument");
-
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
- controller.GoToOffset(offset);
-}
-
-// static
-void Window::Reload(const v8::FunctionCallbackInfo<v8::Value>& args) {
- UNWRAP_WINDOW_AND_CHECK;
+} // namespace api
- NavigationController& controller =
- self->window_->GetWebContents()->GetController();
- controller.Reload(args[0]->IsBoolean() ? args[0]->BooleanValue(): false);
-}
+} // namespace atom
-// static
-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);
-}
+namespace {
-// static
-void Window::Initialize(v8::Handle<v8::Object> target) {
- v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(Window::New);
- t->InstanceTemplate()->SetInternalFieldCount(1);
- t->SetClassName(v8::String::NewSymbol("BrowserWindow"));
-
- NODE_SET_PROTOTYPE_METHOD(t, "destroy", Destroy);
- NODE_SET_PROTOTYPE_METHOD(t, "close", Close);
- NODE_SET_PROTOTYPE_METHOD(t, "focus", Focus);
- NODE_SET_PROTOTYPE_METHOD(t, "isFocused", IsFocused);
- NODE_SET_PROTOTYPE_METHOD(t, "show", Show);
- NODE_SET_PROTOTYPE_METHOD(t, "hide", Hide);
- NODE_SET_PROTOTYPE_METHOD(t, "isVisible", IsVisible);
- NODE_SET_PROTOTYPE_METHOD(t, "maximize", Maximize);
- NODE_SET_PROTOTYPE_METHOD(t, "unmaximize", Unmaximize);
- NODE_SET_PROTOTYPE_METHOD(t, "minimize", Minimize);
- NODE_SET_PROTOTYPE_METHOD(t, "restore", Restore);
- NODE_SET_PROTOTYPE_METHOD(t, "setFullScreen", SetFullscreen);
- NODE_SET_PROTOTYPE_METHOD(t, "isFullScreen", IsFullscreen);
- NODE_SET_PROTOTYPE_METHOD(t, "setSize", SetSize);
- NODE_SET_PROTOTYPE_METHOD(t, "getSize", GetSize);
- NODE_SET_PROTOTYPE_METHOD(t, "setMinimumSize", SetMinimumSize);
- NODE_SET_PROTOTYPE_METHOD(t, "getMinimumSize", GetMinimumSize);
- NODE_SET_PROTOTYPE_METHOD(t, "setMaximumSize", SetMaximumSize);
- NODE_SET_PROTOTYPE_METHOD(t, "getMaximumSize", GetMaximumSize);
- NODE_SET_PROTOTYPE_METHOD(t, "setResizable", SetResizable);
- NODE_SET_PROTOTYPE_METHOD(t, "isResizable", IsResizable);
- NODE_SET_PROTOTYPE_METHOD(t, "setAlwaysOnTop", SetAlwaysOnTop);
- NODE_SET_PROTOTYPE_METHOD(t, "isAlwaysOnTop", IsAlwaysOnTop);
- NODE_SET_PROTOTYPE_METHOD(t, "center", Center);
- NODE_SET_PROTOTYPE_METHOD(t, "setPosition", SetPosition);
- NODE_SET_PROTOTYPE_METHOD(t, "getPosition", GetPosition);
- NODE_SET_PROTOTYPE_METHOD(t, "setTitle", SetTitle);
- NODE_SET_PROTOTYPE_METHOD(t, "getTitle", GetTitle);
- NODE_SET_PROTOTYPE_METHOD(t, "flashFrame", FlashFrame);
- NODE_SET_PROTOTYPE_METHOD(t, "setKiosk", SetKiosk);
- NODE_SET_PROTOTYPE_METHOD(t, "isKiosk", IsKiosk);
- NODE_SET_PROTOTYPE_METHOD(t, "openDevTools", OpenDevTools);
- NODE_SET_PROTOTYPE_METHOD(t, "closeDevTools", CloseDevTools);
- NODE_SET_PROTOTYPE_METHOD(t, "isDevToolsOpened", IsDevToolsOpened);
- NODE_SET_PROTOTYPE_METHOD(t, "inspectElement", InspectElement);
- NODE_SET_PROTOTYPE_METHOD(t, "debugDevTools", DebugDevTools);
- NODE_SET_PROTOTYPE_METHOD(t, "focusOnWebView", FocusOnWebView);
- NODE_SET_PROTOTYPE_METHOD(t, "blurWebView", BlurWebView);
- NODE_SET_PROTOTYPE_METHOD(t, "isWebViewFocused", IsWebViewFocused);
- NODE_SET_PROTOTYPE_METHOD(t, "capturePage", CapturePage);
-
- NODE_SET_PROTOTYPE_METHOD(t, "getPageTitle", GetPageTitle);
- NODE_SET_PROTOTYPE_METHOD(t, "isLoading", IsLoading);
- NODE_SET_PROTOTYPE_METHOD(t, "isWaitingForResponse", IsWaitingForResponse);
- NODE_SET_PROTOTYPE_METHOD(t, "stop", Stop);
- NODE_SET_PROTOTYPE_METHOD(t, "getRoutingId", GetRoutingID);
- NODE_SET_PROTOTYPE_METHOD(t, "getProcessId", GetProcessID);
- NODE_SET_PROTOTYPE_METHOD(t, "isCrashed", IsCrashed);
-
- NODE_SET_PROTOTYPE_METHOD(t, "getDevTools", GetDevTools);
- NODE_SET_PROTOTYPE_METHOD(
- t, "executeJavaScriptInDevTools", ExecuteJavaScriptInDevTools);
-
- NODE_SET_PROTOTYPE_METHOD(t, "loadUrl", LoadURL);
- NODE_SET_PROTOTYPE_METHOD(t, "getUrl", GetURL);
- NODE_SET_PROTOTYPE_METHOD(t, "canGoBack", CanGoBack);
- NODE_SET_PROTOTYPE_METHOD(t, "canGoForward", CanGoForward);
- NODE_SET_PROTOTYPE_METHOD(t, "canGoToOffset", CanGoToOffset);
- NODE_SET_PROTOTYPE_METHOD(t, "goBack", GoBack);
- NODE_SET_PROTOTYPE_METHOD(t, "goForward", GoForward);
- NODE_SET_PROTOTYPE_METHOD(t, "goToIndex", GoToIndex);
- NODE_SET_PROTOTYPE_METHOD(t, "goToOffset", GoToOffset);
- NODE_SET_PROTOTYPE_METHOD(t, "reload", Reload);
- NODE_SET_PROTOTYPE_METHOD(t, "reloadIgnoringCache", ReloadIgnoringCache);
-
- target->Set(v8::String::NewSymbol("BrowserWindow"), t->GetFunction());
+void Initialize(v8::Handle<v8::Object> exports) {
+ using atom::api::Window;
+ v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
+ node_isolate, "BrowserWindow", base::Bind(&Window::New));
+ mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
+ dict.Set("BrowserWindow", static_cast<v8::Handle<v8::Value>>(constructor));
}
-} // namespace api
-
-} // namespace atom
+} // namespace
-NODE_MODULE(atom_browser_window, atom::api::Window::Initialize)
+NODE_MODULE(atom_browser_window, Initialize)
#include "base/memory/scoped_ptr.h"
#include "atom/browser/native_window_observer.h"
-#include "atom/common/api/atom_api_event_emitter.h"
-#include "atom/common/v8/scoped_persistent.h"
+#include "atom/browser/api/event_emitter.h"
+
+class GURL;
namespace base {
class DictionaryValue;
}
+namespace mate {
+class Arguments;
+class Dictionary;
+}
+
namespace atom {
class NativeWindow;
namespace api {
-class Window : public EventEmitter,
+class Window : public mate::EventEmitter,
public NativeWindowObserver {
public:
- virtual ~Window();
+ static mate::Wrappable* New(mate::Arguments* args,
+ const base::DictionaryValue& options);
- static void Initialize(v8::Handle<v8::Object> target);
+ static void BuildPrototype(v8::Isolate* isolate,
+ v8::Handle<v8::ObjectTemplate> prototype);
- NativeWindow* window() { return window_.get(); }
+ NativeWindow* window() const { return window_.get(); }
protected:
- explicit Window(v8::Handle<v8::Object> wrapper,
- base::DictionaryValue* options);
+ explicit Window(base::DictionaryValue* options);
+ virtual ~Window();
- // Implementations of NativeWindowObserver.
+ // Implementations of NativeWindowObserver:
virtual void OnPageTitleUpdated(bool* prevent_default,
const std::string& title) OVERRIDE;
virtual void OnLoadingStateChanged(bool is_loading) OVERRIDE;
virtual void OnRendererCrashed() OVERRIDE;
private:
- static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void Destroy(const v8::FunctionCallbackInfo<v8::Value>& args);
-
// APIs for NativeWindow.
- 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 DebugDevTools(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);
+ void Destroy();
+ void Close();
+ void Focus();
+ bool IsFocused();
+ void Show();
+ void Hide();
+ bool IsVisible();
+ void Maximize();
+ void Unmaximize();
+ void Minimize();
+ void Restore();
+ void SetFullscreen(bool fullscreen);
+ bool IsFullscreen();
+ void SetSize(int width, int height);
+ std::vector<int> GetSize();
+ void SetMinimumSize(int width, int height);
+ std::vector<int> GetMinimumSize();
+ void SetMaximumSize(int width, int height);
+ std::vector<int> GetMaximumSize();
+ void SetResizable(bool resizable);
+ bool IsResizable();
+ void SetAlwaysOnTop(bool top);
+ bool IsAlwaysOnTop();
+ void Center();
+ void SetPosition(int x, int y);
+ std::vector<int> GetPosition();
+ void SetTitle(const std::string& title);
+ std::string GetTitle();
+ void FlashFrame(bool flash);
+ void SetKiosk(bool kiosk);
+ bool IsKiosk();
+ void OpenDevTools();
+ void CloseDevTools();
+ bool IsDevToolsOpened();
+ void InspectElement(int x, int y);
+ void DebugDevTools();
+ void FocusOnWebView();
+ void BlurWebView();
+ bool IsWebViewFocused();
+ void CapturePage(mate::Arguments* args);
// APIs for WebContents.
- 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);
+ string16 GetPageTitle();
+ bool IsLoading();
+ bool IsWaitingForResponse();
+ void Stop();
+ int GetRoutingID();
+ int GetProcessID();
+ bool IsCrashed();
// APIs for devtools.
- static void GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void ExecuteJavaScriptInDevTools(
- const v8::FunctionCallbackInfo<v8::Value>& args);
+ mate::Dictionary GetDevTools(v8::Isolate* isolate);
+ void ExecuteJavaScriptInDevTools(const std::string& code);
// APIs for NavigationController.
- 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(const RefCountedV8Function& callback,
- const std::vector<unsigned char>& data);
+ void LoadURL(const GURL& url);
+ GURL GetURL();
+ bool CanGoBack();
+ bool CanGoForward();
+ bool CanGoToOffset(int offset);
+ void GoBack();
+ void GoForward();
+ void GoToIndex(int index);
+ void GoToOffset(int offset);
+ void Reload();
+ void ReloadIgnoringCache();
scoped_ptr<NativeWindow> window_;
callback));
}
+void NativeWindow::DestroyWebContents() {
+ inspectable_web_contents_.reset();
+}
+
void NativeWindow::CloseWebContents() {
bool prevent_default = false;
FOR_EACH_OBSERVER(NativeWindowObserver,
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
}
-void NativeWindow::DestroyWebContents() {
- inspectable_web_contents_.reset();
-}
-
// In atom-shell all reloads and navigations started by renderer process would
// be redirected to this method, so we can have precise control of how we
// would open the url (in our case, is to restart the renderer process). See
// Should be called by platform code when user want to close the window.
virtual void CloseWebContents();
+ // Destroy the WebContents immediately.
+ virtual void DestroyWebContents();
+
base::WeakPtr<NativeWindow> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
void NotifyWindowClosed();
void NotifyWindowBlur();
- // Destroy the inspectable_web_contents.
- void DestroyWebContents();
-
// Called when the window needs to update its draggable region.
virtual void UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) = 0;
+++ /dev/null
-// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "atom/common/api/atom_api_event_emitter.h"
-
-#include <vector>
-
-#include "atom/browser/api/atom_api_event.h"
-#include "atom/common/browser_v8_locker.h"
-#include "atom/common/v8/native_type_conversions.h"
-#include "base/logging.h"
-
-#include "atom/common/node_includes.h"
-
-namespace atom {
-
-namespace api {
-
-EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
- Wrap(wrapper);
-}
-
-EventEmitter::~EventEmitter() {
- // Clear the aligned pointer, it should have been done by ObjectWrap but
- // somehow node v0.11.x changed this behaviour.
- BrowserV8Locker locker(node_isolate);
- v8::HandleScope handle_scope(node_isolate);
- handle()->SetAlignedPointerInInternalField(0, NULL);
-}
-
-bool EventEmitter::Emit(const std::string& name) {
- base::ListValue args;
- return Emit(name, &args);
-}
-
-bool EventEmitter::Emit(const std::string& name, base::ListValue* args) {
- BrowserV8Locker locker(node_isolate);
- v8::HandleScope handle_scope(node_isolate);
-
- v8::Handle<v8::Context> context = v8::Context::GetCurrent();
- scoped_ptr<V8ValueConverter> converter(new V8ValueConverter);
-
- v8::Handle<v8::Object> v8_event = Event::CreateV8Object();
- Event* event = Event::Unwrap<Event>(v8_event);
-
- // Generate arguments for calling handle.emit.
- std::vector<v8::Handle<v8::Value>> v8_args;
- v8_args.reserve(args->GetSize() + 2);
- v8_args.push_back(ToV8Value(name));
- v8_args.push_back(v8_event);
- for (size_t i = 0; i < args->GetSize(); i++) {
- base::Value* value = NULL;
- if (args->Get(i, &value)) {
- DCHECK(value);
- v8_args.push_back(converter->ToV8Value(value, context));
- } else {
- NOTREACHED() << "Wrong offset " << i << " for " << *args;
- }
- }
-
- node::MakeCallback(handle(), "emit", v8_args.size(), &v8_args[0]);
-
- bool prevent_default = event->prevent_default();
-
- // Don't wait for V8 GC, delete it immediately.
- delete event;
-
- return prevent_default;
-}
-
-} // namespace api
-
-} // namespace atom
+++ /dev/null
-// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_COMMON_API_ATOM_API_EVENT_EMITTER_H_
-#define ATOM_COMMON_API_ATOM_API_EVENT_EMITTER_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "vendor/node/src/node_object_wrap.h"
-
-namespace base {
-class ListValue;
-}
-
-namespace atom {
-
-namespace api {
-
-// Class interiting EventEmitter should assume it's a javascript object which
-// interits require('events').EventEmitter, this class provides many helper
-// methods to do event processing in C++.
-class EventEmitter : public node::ObjectWrap {
- public:
- virtual ~EventEmitter();
-
- // Emit an event and returns whether the handler has called preventDefault().
- bool Emit(const std::string& name);
- bool Emit(const std::string& name, base::ListValue* args);
-
- protected:
- explicit EventEmitter(v8::Handle<v8::Object> wrapper);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(EventEmitter);
-};
-
-} // namespace api
-
-} // namespace atom
-
-#endif // ATOM_COMMON_API_ATOM_API_EVENT_EMITTER_H_
#include "atom/common/platform_util.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
+#include "atom/common/native_mate_converters/gurl_converter.h"
#include "native_mate/dictionary.h"
-#include "url/gurl.h"
#include "atom/common/node_includes.h"
-namespace mate {
-
-template<>
-struct Converter<GURL> {
- static bool FromV8(v8::Isolate* isolate,
- v8::Handle<v8::Value> val,
- GURL* out) {
- std::string url;
- if (Converter<std::string>::FromV8(isolate, val, &url)) {
- *out = GURL(url);
- return true;
- } else {
- return false;
- }
- }
-};
-
-} // namespace mate
-
namespace {
void Initialize(v8::Handle<v8::Object> exports) {
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Copyright (c) 2012 Intel Corp. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_API_OBJECT_LIFE_MONITOR_H_
#define ATOM_COMMON_API_OBJECT_LIFE_MONITOR_H_
-#include "atom/common/v8/scoped_persistent.h"
#include "base/basictypes.h"
+#include "native_mate/scoped_persistent.h"
namespace atom {
v8::Persistent<v8::Object>* value,
ObjectLifeMonitor* self);
- ScopedPersistent<v8::Object> handle_;
+ mate::ScopedPersistent<v8::Object> handle_;
DISALLOW_COPY_AND_ASSIGN(ObjectLifeMonitor);
};
--- /dev/null
+// Copyright (c) 2014 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 ATOM_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_
+#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_
+
+#include "native_mate/converter.h"
+#include "url/gurl.h"
+
+namespace mate {
+
+template<>
+struct Converter<GURL> {
+ static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
+ const GURL& val) {
+ return Converter<std::string>::ToV8(isolate, val.spec());
+ }
+ static bool FromV8(v8::Isolate* isolate,
+ v8::Handle<v8::Value> val,
+ GURL* out) {
+ std::string url;
+ if (Converter<std::string>::FromV8(isolate, val, &url)) {
+ *out = GURL(url);
+ return true;
+ } else {
+ return false;
+ }
+ }
+};
+
+} // namespace mate
+
+#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_
namespace mate {
+bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
+ v8::Handle<v8::Value> val,
+ base::DictionaryValue* out) {
+ scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
+ scoped_ptr<base::Value> value(converter->FromV8Value(
+ val, v8::Context::GetCurrent()));
+ if (value->IsType(base::Value::TYPE_DICTIONARY)) {
+ out->Swap(static_cast<DictionaryValue*>(value.get()));
+ return true;
+ } else {
+ return false;
+ }
+}
+
bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
base::ListValue* out) {
#include "native_mate/converter.h"
namespace base {
+class DictionaryValue;
class ListValue;
}
namespace mate {
template<>
+struct Converter<base::DictionaryValue> {
+ static bool FromV8(v8::Isolate* isolate,
+ v8::Handle<v8::Value> val,
+ base::DictionaryValue* out);
+};
+
+template<>
struct Converter<base::ListValue> {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
#include "vendor/node/src/env.h"
#include "vendor/node/src/env-inl.h"
#include "vendor/node/src/node.h"
+#include "vendor/node/src/node_buffer.h"
#include "vendor/node/src/node_internals.h"
using node::node_isolate;
+++ /dev/null
-// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_COMMON_SWAP_OR_ASSIGN_H_
-#define ATOM_COMMON_SWAP_OR_ASSIGN_H_
-
-#include "base/compiler_specific.h"
-
-namespace internal {
-
-#if defined(OS_WIN)
-template<typename T> inline
-void SwapOrAssign(T& v1, const T& v2) {
- __if_exists(T::swap) {
- v1.swap(const_cast<T&>(v2));
- }
-
- __if_not_exists(T::swap) {
- v1 = v2;
- }
-}
-
-template<typename T> inline
-void SwapOrAssign(T*& v1, T* v2) {
- v1 = v2;
-}
-
-inline
-void SwapOrAssign(int& v1, int v2) {
- v1 = v2;
-}
-
-inline
-void SwapOrAssign(bool& v1, bool v2) {
- v1 = v2;
-}
-#else // defined(OS_WIN)
-// Helper to detect whether value has specified method.
-template <typename T>
-class HasSwapMethod {
- typedef char one;
- typedef long two;
- template <typename C> static one test(char[sizeof(&C::swap)]) ;
- template <typename C> static two test(...);
- public:
- enum { value = sizeof(test<T>(0)) == sizeof(char) };
-};
-
-template<bool B, class T = void>
-struct enable_if {};
-
-template<class T>
-struct enable_if<true, T> { typedef T type; };
-
-template<typename T> inline
-typename enable_if<HasSwapMethod<T>::value>::type SwapOrAssign(
- T& v1, const T& v2) {
- v1.swap(const_cast<T&>(v2));
-}
-
-template<typename T> inline
-typename enable_if<!HasSwapMethod<T>::value>::type SwapOrAssign(
- T& v1, const T& v2) {
- v1 = v2;
-}
-#endif // !defined(OS_WIN)
-
-} // namespace internal
-
-#endif // ATOM_COMMON_SWAP_OR_ASSIGN_H_
+++ /dev/null
-// Copyright (c) 2013 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_COMMON_V8_NATIVE_TYPE_CONVERSIONS_H_
-#define ATOM_COMMON_V8_NATIVE_TYPE_CONVERSIONS_H_
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "atom/browser/api/atom_api_window.h"
-#include "atom/common/swap_or_assign.h"
-#include "atom/common/v8/scoped_persistent.h"
-#include "atom/common/native_mate_converters/v8_value_converter.h"
-#include "base/files/file_path.h"
-#include "base/strings/string16.h"
-#include "base/template_util.h"
-#include "base/values.h"
-#include "ui/gfx/point.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/size.h"
-#include "url/gurl.h"
-
-// Convert V8 value to arbitrary supported types.
-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 string16() {
- v8::String::Value s(value_);
- return string16(reinterpret_cast<const char16*>(*s), s.length());
- }
-
- operator GURL() {
- std::string str = FromV8Value(value_);
- return GURL(str);
- }
-
- operator base::FilePath() {
- return base::FilePath::FromUTF8Unsafe(FromV8Value(value_));
- }
-
- operator gfx::Rect() {
- v8::Handle<v8::Object> rect = value_->ToObject();
- v8::Handle<v8::Value> x = rect->Get(v8::String::New("x"));
- v8::Handle<v8::Value> y = rect->Get(v8::String::New("y"));
- v8::Handle<v8::Value> width = rect->Get(v8::String::New("width"));
- v8::Handle<v8::Value> height = rect->Get(v8::String::New("height"));
- if (!x->IsNumber() || !y->IsNumber() ||
- !width->IsNumber() || !height->IsNumber())
- return gfx::Rect();
- else
- return gfx::Rect(x->IntegerValue(), y->IntegerValue(),
- width->IntegerValue(), height->IntegerValue());
- }
-
- operator scoped_ptr<base::Value>() {
- scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
- return scoped_ptr<base::Value>(
- converter->FromV8Value(value_, v8::Context::GetCurrent()));
- }
-
- template<class T>
- operator std::vector<T>() {
- std::vector<T> array;
- v8::Handle<v8::Array> v8_array = v8::Handle<v8::Array>::Cast(value_);
- for (uint32_t i = 0; i < v8_array->Length(); ++i)
- array.push_back(FromV8Value(v8_array->Get(i)));
-
- return array;
- }
-
- template<class K, class V>
- operator std::map<K, V>() {
- std::map<K, V> dict;
- v8::Handle<v8::Object> v8_dict = value_->ToObject();
- v8::Handle<v8::Array> v8_keys = v8_dict->GetOwnPropertyNames();
- for (uint32_t i = 0; i < v8_keys->Length(); ++i) {
- v8::Handle<v8::Value> v8_key = v8_keys->Get(i);
- K key = FromV8Value(v8_key);
- dict[key] = V(FromV8Value(v8_dict->Get(v8_key)));
- }
-
- return dict;
- }
-
- operator atom::NativeWindow*() {
- using atom::api::Window;
- if (value_->IsObject()) {
- Window* window = Window::Unwrap<Window>(value_->ToObject());
- if (window && window->window())
- return window->window();
- }
- return NULL;
- }
-
- operator atom::RefCountedV8Function() {
- v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value_);
- return atom::RefCountedV8Function(
- new atom::RefCountedPersistent<v8::Function>(func));
- }
-
- v8::Handle<v8::Value> value_;
-};
-
-// 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(float f) {
- return v8::Number::New(f);
-}
-
-inline v8::Handle<v8::Value> ToV8Value(double f) {
- return v8::Number::New(f);
-}
-
-inline v8::Handle<v8::Value> ToV8Value(const char* s) {
- return v8::String::New(s);
-}
-
-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 GURL& url) {
- return ToV8Value(url.spec());
-}
-
-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());
-}
-
-inline v8::Handle<v8::Value> ToV8Value(void* whatever) {
- return v8::Undefined();
-}
-
-template<class T> inline
-v8::Handle<v8::Value> ToV8Value(const std::vector<T>& arr) {
- v8::Handle<v8::Array> result = v8::Array::New(arr.size());
- for (size_t i = 0; i < arr.size(); ++i)
- result->Set(i, ToV8Value(arr[i]));
- return result;
-}
-
-inline v8::Handle<v8::Value> ToV8Value(const gfx::Point& point) {
- v8::Handle<v8::Object> obj = v8::Object::New();
- obj->Set(ToV8Value("x"), ToV8Value(point.x()));
- obj->Set(ToV8Value("y"), ToV8Value(point.y()));
- return obj;
-}
-
-inline v8::Handle<v8::Value> ToV8Value(const gfx::Rect& rect) {
- v8::Handle<v8::Object> obj = v8::Object::New();
- obj->Set(ToV8Value("x"), ToV8Value(rect.x()));
- obj->Set(ToV8Value("y"), ToV8Value(rect.y()));
- obj->Set(ToV8Value("width"), ToV8Value(rect.width()));
- obj->Set(ToV8Value("height"), ToV8Value(rect.height()));
- return obj;
-}
-
-inline v8::Handle<v8::Value> ToV8Value(const gfx::Size& size) {
- v8::Handle<v8::Object> obj = v8::Object::New();
- obj->Set(ToV8Value("width"), ToV8Value(size.width()));
- obj->Set(ToV8Value("height"), ToV8Value(size.height()));
- return obj;
-}
-
-// Check if a V8 Value is of specified type.
-template<class T> inline
-bool V8ValueCanBeConvertedTo(v8::Handle<v8::Value> value) {
- return false;
-}
-
-template<> inline
-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<GURL>(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);
-}
-
-template<> inline
-bool V8ValueCanBeConvertedTo<gfx::Rect>(v8::Handle<v8::Value> value) {
- return value->IsObject();
-}
-
-template<> inline
-bool V8ValueCanBeConvertedTo<scoped_ptr<base::Value>>(
- v8::Handle<v8::Value> value) {
- return value->IsObject();
-}
-
-template<> inline
-bool V8ValueCanBeConvertedTo<std::vector<std::string>>(
- v8::Handle<v8::Value> value) {
- return value->IsArray();
-}
-
-template<> inline
-bool V8ValueCanBeConvertedTo<std::map<std::string, std::string>>(
- v8::Handle<v8::Value> value) {
- return value->IsObject();
-}
-
-template<> inline
-bool V8ValueCanBeConvertedTo<atom::NativeWindow*>(v8::Handle<v8::Value> value) {
- using atom::api::Window;
- if (value->IsObject()) {
- Window* window = Window::Unwrap<Window>(value->ToObject());
- if (window && window->window())
- return true;
- }
- return false;
-}
-
-template<> inline
-bool V8ValueCanBeConvertedTo<atom::RefCountedV8Function>(
- v8::Handle<v8::Value> value) {
- return value->IsFunction();
-}
-
-// Check and convert V8's Arguments to native types.
-template<typename T1> inline
-bool FromV8Arguments(const v8::FunctionCallbackInfo<v8::Value>& args,
- T1* value,
- int index = 0) {
- if (!V8ValueCanBeConvertedTo<T1>(args[index]))
- return false;
- internal::SwapOrAssign(*value,
- FromV8Value(args[index]).operator T1());
- return true;
-}
-
-template<typename T1, typename T2> inline
-bool FromV8Arguments(const v8::FunctionCallbackInfo<v8::Value>& args,
- T1* a1,
- T2* a2) {
- return FromV8Arguments<T1>(args, a1) && FromV8Arguments<T2>(args, a2, 1);
-}
-
-template<typename T1, typename T2, typename T3> inline
-bool FromV8Arguments(const v8::FunctionCallbackInfo<v8::Value>& args,
- T1* a1,
- T2* a2,
- T3* a3) {
- return FromV8Arguments<T1, T2>(args, a1, a2) &&
- FromV8Arguments<T3>(args, a3, 2);
-}
-
-template<typename T1, typename T2, typename T3, typename T4> inline
-bool FromV8Arguments(const v8::FunctionCallbackInfo<v8::Value>& args,
- T1* a1,
- T2* a2,
- T3* a3,
- T4* a4) {
- return FromV8Arguments<T1, T2, T3>(args, a1, a2, a3) &&
- FromV8Arguments<T4>(args, a4, 3);
-}
-
-template<typename T1, typename T2, typename T3, typename T4, typename T5> inline
-bool FromV8Arguments(const v8::FunctionCallbackInfo<v8::Value>& args,
- T1* a1,
- T2* a2,
- T3* a3,
- T4* a4,
- T5* a5) {
- return FromV8Arguments<T1, T2, T3, T4>(args, a1, a2, a3, a4) &&
- FromV8Arguments<T5>(args, a5, 4);
-}
-
-template<typename T1, typename T2, typename T3, typename T4, typename T5,
- typename T6> inline
-bool FromV8Arguments(const v8::FunctionCallbackInfo<v8::Value>& args,
- T1* a1,
- T2* a2,
- T3* a3,
- T4* a4,
- T5* a5,
- T6* a6) {
- return FromV8Arguments<T1, T2, T3, T4, T5>(args, a1, a2, a3, a4, a5) &&
- FromV8Arguments<T6>(args, a6, 5);
-}
-
-template<typename T1, typename T2, typename T3, typename T4, typename T5,
- typename T6, typename T7> inline
-bool FromV8Arguments(const v8::FunctionCallbackInfo<v8::Value>& args,
- T1* a1,
- T2* a2,
- T3* a3,
- T4* a4,
- T5* a5,
- T6* a6,
- T7* a7) {
- return
- FromV8Arguments<T1, T2, T3, T4, T5, T6>(args, a1, a2, a3, a4, a5, a6) &&
- FromV8Arguments<T7>(args, a7, 6);
-}
-
-#endif // ATOM_COMMON_V8_NATIVE_TYPE_CONVERSIONS_H_
+++ /dev/null
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_COMMON_V8_SCOPED_PERSISTENT_H_
-#define ATOM_COMMON_V8_SCOPED_PERSISTENT_H_
-
-#include "base/logging.h"
-#include "base/memory/ref_counted.h"
-#include "v8/include/v8.h"
-
-namespace atom {
-
-// A v8::Persistent handle to a V8 value which destroys and clears the
-// underlying handle on destruction.
-template <typename T>
-class ScopedPersistent {
- public:
- ScopedPersistent() {
- }
-
- explicit ScopedPersistent(v8::Handle<T> handle) {
- reset(handle);
- }
-
- ~ScopedPersistent() {
- reset();
- }
-
- void reset(v8::Handle<T> handle) {
- if (!handle.IsEmpty())
- handle_.Reset(GetIsolate(handle), handle);
- else
- reset();
- }
-
- void reset() {
- handle_.Reset();
- }
-
- bool IsEmpty() const {
- return handle_.IsEmpty();
- }
-
- v8::Handle<T> NewHandle() const {
- if (handle_.IsEmpty())
- return v8::Local<T>();
- return v8::Local<T>::New(GetIsolate(handle_), handle_);
- }
-
- v8::Handle<T> NewHandle(v8::Isolate* isolate) const {
- if (handle_.IsEmpty())
- return v8::Local<T>();
- return v8::Local<T>::New(isolate, handle_);
- }
-
- template <typename P>
- void MakeWeak(P* parameters,
- typename v8::WeakReferenceCallbacks<T, P>::Revivable callback) {
- handle_.MakeWeak(parameters, callback);
- }
-
- private:
- template <typename U>
- static v8::Isolate* GetIsolate(v8::Handle<U> object_handle) {
- // Only works for v8::Object and its subclasses. Add specialisations for
- // anything else.
- if (!object_handle.IsEmpty())
- return GetIsolate(object_handle->CreationContext());
- return v8::Isolate::GetCurrent();
- }
- static v8::Isolate* GetIsolate(v8::Handle<v8::Context> context_handle) {
- if (!context_handle.IsEmpty())
- return context_handle->GetIsolate();
- return v8::Isolate::GetCurrent();
- }
- static v8::Isolate* GetIsolate(
- v8::Handle<v8::ObjectTemplate> template_handle) {
- return v8::Isolate::GetCurrent();
- }
- template <typename U>
- static v8::Isolate* GetIsolate(const U& any_handle) {
- return v8::Isolate::GetCurrent();
- }
-
- v8::Persistent<T> handle_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedPersistent);
-};
-
-template <typename T>
-class RefCountedPersistent : public ScopedPersistent<T>,
- public base::RefCounted<RefCountedPersistent<T>> {
- public:
- RefCountedPersistent() {}
-
- explicit RefCountedPersistent(v8::Handle<T> handle)
- : ScopedPersistent<T>(handle) {
- }
-
- protected:
- friend class base::RefCounted<RefCountedPersistent<T>>;
-
- ~RefCountedPersistent() {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(RefCountedPersistent);
-};
-
-typedef scoped_refptr<RefCountedPersistent<v8::Function>> RefCountedV8Function;
-typedef scoped_refptr<RefCountedPersistent<v8::Object>> RefCountedV8Object;
-
-} // namespace atom
-
-#endif // ATOM_COMMON_V8_SCOPED_PERSISTENT_H_
-Subproject commit 9cc90ac7d52e04d909ffdceda130e12d8f79e0e8
+Subproject commit 3d219b4be6f37fe99ca2e738eb0ea9d1b152af34