From 42ffa5813f6643fb55f4f8461cf86fc4cd180133 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Dec 2013 17:23:32 +0800 Subject: [PATCH 01/55] Update libchromiumcontent and brightray to use Chrome31. --- vendor/brightray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/brightray b/vendor/brightray index 2f84310fe4a4..8e453e36fe6a 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 2f84310fe4a4f47a72020b9bb99228093a6252a1 +Subproject commit 8e453e36fe6ab74cf4e72fe0fa67e30eb048d2b3 From 0a37852757e901ef70ded6f6a5b42af5c9023fb9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Dec 2013 23:18:36 +0800 Subject: [PATCH 02/55] Update to node v0.11.9. --- atom.gyp | 2 ++ common.gypi | 7 +++++++ vendor/node | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/atom.gyp b/atom.gyp index e52121e6e5c5..a973cad86cf9 100644 --- a/atom.gyp +++ b/atom.gyp @@ -326,6 +326,8 @@ 'include_dirs': [ '.', 'vendor', + # The `node.h` is using `#include"v8.h"`. + 'vendor/brightray/vendor/download/libchromiumcontent/src/v8/include', ], 'direct_dependent_settings': { 'include_dirs': [ diff --git a/common.gypi b/common.gypi index d153c79d3e32..5975647d2724 100644 --- a/common.gypi +++ b/common.gypi @@ -13,6 +13,7 @@ }], ], # Reflects node's config.gypi. + 'component%': 'static_library', 'python': 'python', 'node_install_npm': 'false', 'node_prefix': '', @@ -29,6 +30,7 @@ 'node_use_openssl': 'true', 'node_use_perfctr': 'false', 'node_use_systemtap': 'false', + 'v8_postmortem_support': 'false', }, # Settings to compile node under Windows. 'target_defaults': { @@ -72,6 +74,11 @@ ], }, }], + ['_target_name=="node"', { + 'include_dirs': [ + 'vendor/brightray/vendor/download/libchromiumcontent/src/v8/include', + ], + }], ['_target_name=="libuv"', { 'conditions': [ ['OS=="win"', { diff --git a/vendor/node b/vendor/node index 44483b45881e..4b6ab23cb972 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 44483b45881e0757af30c092a562b8d0ff6cceeb +Subproject commit 4b6ab23cb972a96bde40c899aab41703f08a1f0d From 4ec4b0121853095b8fc9d16418ade2ad496868ab Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Dec 2013 14:14:05 +0800 Subject: [PATCH 03/55] base/string16.h was moved to base/strings/string16.h. --- browser/api/atom_api_event.h | 2 +- browser/api/atom_browser_bindings.h | 2 +- browser/native_window_win.h | 2 +- browser/ui/atom_menu_controller_mac.h | 2 +- browser/ui/win/native_menu_win.h | 2 +- common/api/api_messages.h | 2 +- common/v8_conversions.h | 2 +- renderer/api/atom_renderer_bindings.h | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/browser/api/atom_api_event.h b/browser/api/atom_api_event.h index 7abe240c9799..3b1359e135da 100644 --- a/browser/api/atom_api_event.h +++ b/browser/api/atom_api_event.h @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/string16.h" +#include "base/strings/string16.h" #include "browser/native_window_observer.h" #include "vendor/node/src/node_object_wrap.h" diff --git a/browser/api/atom_browser_bindings.h b/browser/api/atom_browser_bindings.h index dde6997a8c70..ae93329fafba 100644 --- a/browser/api/atom_browser_bindings.h +++ b/browser/api/atom_browser_bindings.h @@ -5,7 +5,7 @@ #ifndef ATOM_BROWSER_API_ATOM_BROWSER_BINDINGS_ #define ATOM_BROWSER_API_ATOM_BROWSER_BINDINGS_ -#include "base/string16.h" +#include "base/strings/string16.h" #include "common/api/atom_bindings.h" namespace base { diff --git a/browser/native_window_win.h b/browser/native_window_win.h index a583a982e90a..84b7ac0bd20f 100644 --- a/browser/native_window_win.h +++ b/browser/native_window_win.h @@ -5,7 +5,7 @@ #ifndef ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ #define ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ -#include "base/string16.h" +#include "base/strings/string16.h" #include "base/memory/scoped_ptr.h" #include "browser/native_window.h" diff --git a/browser/ui/atom_menu_controller_mac.h b/browser/ui/atom_menu_controller_mac.h index 74c2240efac1..c2d1b1800376 100644 --- a/browser/ui/atom_menu_controller_mac.h +++ b/browser/ui/atom_menu_controller_mac.h @@ -9,7 +9,7 @@ #import #include "base/memory/scoped_nsobject.h" -#include "base/string16.h" +#include "base/strings/string16.h" namespace ui { class MenuModel; diff --git a/browser/ui/win/native_menu_win.h b/browser/ui/win/native_menu_win.h index b74c654e0c67..4b6a67423031 100644 --- a/browser/ui/win/native_menu_win.h +++ b/browser/ui/win/native_menu_win.h @@ -13,7 +13,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" -#include "base/string16.h" +#include "base/strings/string16.h" namespace gfx { class Point; diff --git a/common/api/api_messages.h b/common/api/api_messages.h index 8d21a7d93c03..e92a4d3f0b2a 100644 --- a/common/api/api_messages.h +++ b/common/api/api_messages.h @@ -4,7 +4,7 @@ // Multiply-included file, no traditional include guard. -#include "base/string16.h" +#include "base/strings/string16.h" #include "base/values.h" #include "common/draggable_region.h" #include "content/public/common/common_param_traits.h" diff --git a/common/v8_conversions.h b/common/v8_conversions.h index 90ae2fc79d2b..afd879351509 100644 --- a/common/v8_conversions.h +++ b/common/v8_conversions.h @@ -10,7 +10,7 @@ #include #include "base/files/file_path.h" -#include "base/string16.h" +#include "base/strings/string16.h" #include "base/template_util.h" #include "base/values.h" #include "browser/api/atom_api_window.h" diff --git a/renderer/api/atom_renderer_bindings.h b/renderer/api/atom_renderer_bindings.h index 394cdea41ec2..39a5be91968f 100644 --- a/renderer/api/atom_renderer_bindings.h +++ b/renderer/api/atom_renderer_bindings.h @@ -7,7 +7,7 @@ #include "common/api/atom_bindings.h" -#include "base/string16.h" +#include "base/strings/string16.h" namespace base { class ListValue; From f9c41f33e5aa40b364def70ae1c9c9fe65aee9f8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Dec 2013 14:15:14 +0800 Subject: [PATCH 04/55] node::ObjectWrap how had a handle() method. --- browser/api/atom_api_event_emitter.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/browser/api/atom_api_event_emitter.h b/browser/api/atom_api_event_emitter.h index aec37d7f1685..dd2292238601 100644 --- a/browser/api/atom_api_event_emitter.h +++ b/browser/api/atom_api_event_emitter.h @@ -29,9 +29,6 @@ class EventEmitter : public node::ObjectWrap { bool Emit(const std::string& name); bool Emit(const std::string& name, base::ListValue* args); - // Small accessor to return handle_, this follows Google C++ Style. - v8::Persistent handle() const { return handle_; } - protected: explicit EventEmitter(v8::Handle wrapper); From d82cfc023f7ebc91550d458c9fa4bcf0f59a2ccd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Dec 2013 14:27:25 +0800 Subject: [PATCH 05/55] :lipstick: There should be no space between & and type name. --- browser/api/atom_api_app.cc | 22 ++--- browser/api/atom_api_app.h | 22 ++--- browser/api/atom_api_auto_updater.cc | 16 ++-- browser/api/atom_api_auto_updater.h | 16 ++-- browser/api/atom_api_browser_ipc.cc | 2 +- browser/api/atom_api_browser_ipc.h | 2 +- browser/api/atom_api_dialog.cc | 6 +- browser/api/atom_api_dialog.h | 6 +- browser/api/atom_api_menu.cc | 36 ++++----- browser/api/atom_api_menu.h | 42 +++++----- browser/api/atom_api_menu_mac.mm | 4 +- browser/api/atom_api_power_monitor.h | 2 +- browser/api/atom_api_window.cc | 106 ++++++++++++------------ browser/api/atom_api_window.h | 112 +++++++++++++------------- common/api/atom_api_clipboard.cc | 10 +-- common/api/atom_api_clipboard.h | 10 +-- common/api/atom_api_shell.cc | 10 +-- common/api/atom_api_shell.h | 10 +-- renderer/api/atom_api_renderer_ipc.cc | 4 +- renderer/api/atom_api_renderer_ipc.h | 4 +- 20 files changed, 221 insertions(+), 221 deletions(-) diff --git a/browser/api/atom_api_app.cc b/browser/api/atom_api_app.cc index 375087a99f6c..7ad96d19d606 100644 --- a/browser/api/atom_api_app.cc +++ b/browser/api/atom_api_app.cc @@ -52,7 +52,7 @@ void App::OnFinishLaunching() { } // static -v8::Handle App::New(const v8::Arguments &args) { +v8::Handle App::New(const v8::Arguments& args) { v8::HandleScope scope; if (!args.IsConstructCall()) @@ -64,7 +64,7 @@ v8::Handle App::New(const v8::Arguments &args) { } // static -v8::Handle App::Quit(const v8::Arguments &args) { +v8::Handle App::Quit(const v8::Arguments& args) { v8::HandleScope scope; Browser::Get()->Quit(); @@ -73,7 +73,7 @@ v8::Handle App::Quit(const v8::Arguments &args) { } // static -v8::Handle App::Exit(const v8::Arguments &args) { +v8::Handle App::Exit(const v8::Arguments& args) { v8::HandleScope scope; exit(args[0]->IntegerValue()); @@ -82,7 +82,7 @@ v8::Handle App::Exit(const v8::Arguments &args) { } // static -v8::Handle App::Terminate(const v8::Arguments &args) { +v8::Handle App::Terminate(const v8::Arguments& args) { v8::HandleScope scope; Browser::Get()->Terminate(); @@ -91,7 +91,7 @@ v8::Handle App::Terminate(const v8::Arguments &args) { } // static -v8::Handle App::Focus(const v8::Arguments &args) { +v8::Handle App::Focus(const v8::Arguments& args) { v8::HandleScope scope; Browser::Get()->Focus(); @@ -100,12 +100,12 @@ v8::Handle App::Focus(const v8::Arguments &args) { } // static -v8::Handle App::GetVersion(const v8::Arguments &args) { +v8::Handle App::GetVersion(const v8::Arguments& args) { return ToV8Value(Browser::Get()->GetVersion()); } // static -v8::Handle App::SetVersion(const v8::Arguments &args) { +v8::Handle App::SetVersion(const v8::Arguments& args) { v8::HandleScope scope; std::string version; @@ -118,12 +118,12 @@ v8::Handle App::SetVersion(const v8::Arguments &args) { } // static -v8::Handle App::GetName(const v8::Arguments &args) { +v8::Handle App::GetName(const v8::Arguments& args) { return ToV8Value(Browser::Get()->GetName()); } // static -v8::Handle App::SetName(const v8::Arguments &args) { +v8::Handle App::SetName(const v8::Arguments& args) { v8::HandleScope scope; std::string name; @@ -136,7 +136,7 @@ v8::Handle App::SetName(const v8::Arguments &args) { } // static -v8::Handle App::AppendSwitch(const v8::Arguments &args) { +v8::Handle App::AppendSwitch(const v8::Arguments& args) { v8::HandleScope scope; std::string switch_string; @@ -155,7 +155,7 @@ v8::Handle App::AppendSwitch(const v8::Arguments &args) { } // static -v8::Handle App::AppendArgument(const v8::Arguments &args) { +v8::Handle App::AppendArgument(const v8::Arguments& args) { v8::HandleScope scope; std::string value; diff --git a/browser/api/atom_api_app.h b/browser/api/atom_api_app.h index ab701d9369f3..634a1441746f 100644 --- a/browser/api/atom_api_app.h +++ b/browser/api/atom_api_app.h @@ -33,18 +33,18 @@ class App : public EventEmitter, virtual void OnFinishLaunching() OVERRIDE; private: - static v8::Handle New(const v8::Arguments &args); + static v8::Handle New(const v8::Arguments& args); - static v8::Handle Quit(const v8::Arguments &args); - static v8::Handle Exit(const v8::Arguments &args); - static v8::Handle Terminate(const v8::Arguments &args); - static v8::Handle Focus(const v8::Arguments &args); - static v8::Handle GetVersion(const v8::Arguments &args); - static v8::Handle SetVersion(const v8::Arguments &args); - static v8::Handle GetName(const v8::Arguments &args); - static v8::Handle SetName(const v8::Arguments &args); - static v8::Handle AppendSwitch(const v8::Arguments &args); - static v8::Handle AppendArgument(const v8::Arguments &args); + static v8::Handle Quit(const v8::Arguments& args); + static v8::Handle Exit(const v8::Arguments& args); + static v8::Handle Terminate(const v8::Arguments& args); + static v8::Handle Focus(const v8::Arguments& args); + static v8::Handle GetVersion(const v8::Arguments& args); + static v8::Handle SetVersion(const v8::Arguments& args); + static v8::Handle GetName(const v8::Arguments& args); + static v8::Handle SetName(const v8::Arguments& args); + static v8::Handle AppendSwitch(const v8::Arguments& args); + static v8::Handle AppendArgument(const v8::Arguments& args); #if defined(OS_MACOSX) static v8::Handle DockBounce(const v8::Arguments& args); diff --git a/browser/api/atom_api_auto_updater.cc b/browser/api/atom_api_auto_updater.cc index 29bdacc056da..69584bd85f0a 100644 --- a/browser/api/atom_api_auto_updater.cc +++ b/browser/api/atom_api_auto_updater.cc @@ -44,7 +44,7 @@ void AutoUpdater::ReadyForUpdateOnQuit(const std::string& version, } // static -v8::Handle AutoUpdater::New(const v8::Arguments &args) { +v8::Handle AutoUpdater::New(const v8::Arguments& args) { v8::HandleScope scope; if (!args.IsConstructCall()) @@ -56,14 +56,14 @@ v8::Handle AutoUpdater::New(const v8::Arguments &args) { } // static -v8::Handle AutoUpdater::SetFeedURL(const v8::Arguments &args) { +v8::Handle AutoUpdater::SetFeedURL(const v8::Arguments& args) { auto_updater::AutoUpdater::SetFeedURL(FromV8Value(args[0])); return v8::Undefined(); } // static v8::Handle AutoUpdater::SetAutomaticallyChecksForUpdates( - const v8::Arguments &args) { + const v8::Arguments& args) { auto_updater::AutoUpdater::SetAutomaticallyChecksForUpdates( args[0]->BooleanValue()); return v8::Undefined(); @@ -71,34 +71,34 @@ v8::Handle AutoUpdater::SetAutomaticallyChecksForUpdates( // static v8::Handle AutoUpdater::SetAutomaticallyDownloadsUpdates( - const v8::Arguments &args) { + const v8::Arguments& args) { auto_updater::AutoUpdater::SetAutomaticallyDownloadsUpdates( args[0]->BooleanValue()); return v8::Undefined(); } // static -v8::Handle AutoUpdater::CheckForUpdates(const v8::Arguments &args) { +v8::Handle AutoUpdater::CheckForUpdates(const v8::Arguments& args) { auto_updater::AutoUpdater::CheckForUpdates(); return v8::Undefined(); } // static v8::Handle AutoUpdater::CheckForUpdatesInBackground( - const v8::Arguments &args) { + const v8::Arguments& args) { auto_updater::AutoUpdater::CheckForUpdatesInBackground(); return v8::Undefined(); } // static -v8::Handle AutoUpdater::ContinueUpdate(const v8::Arguments &args) { +v8::Handle AutoUpdater::ContinueUpdate(const v8::Arguments& args) { AutoUpdater* self = AutoUpdater::Unwrap(args.This()); self->continue_update_.Run(); return v8::Undefined(); } // static -v8::Handle AutoUpdater::QuitAndInstall(const v8::Arguments &args) { +v8::Handle AutoUpdater::QuitAndInstall(const v8::Arguments& args) { AutoUpdater* self = AutoUpdater::Unwrap(args.This()); self->quit_and_install_.Run(); return v8::Undefined(); diff --git a/browser/api/atom_api_auto_updater.h b/browser/api/atom_api_auto_updater.h index d473624e36f7..7385d9ddb6c6 100644 --- a/browser/api/atom_api_auto_updater.h +++ b/browser/api/atom_api_auto_updater.h @@ -31,19 +31,19 @@ class AutoUpdater : public EventEmitter, const base::Closure& quit_and_install) OVERRIDE; private: - static v8::Handle New(const v8::Arguments &args); + static v8::Handle New(const v8::Arguments& args); - static v8::Handle SetFeedURL(const v8::Arguments &args); + static v8::Handle SetFeedURL(const v8::Arguments& args); static v8::Handle SetAutomaticallyChecksForUpdates( - const v8::Arguments &args); + const v8::Arguments& args); static v8::Handle SetAutomaticallyDownloadsUpdates( - const v8::Arguments &args); - static v8::Handle CheckForUpdates(const v8::Arguments &args); + const v8::Arguments& args); + static v8::Handle CheckForUpdates(const v8::Arguments& args); static v8::Handle CheckForUpdatesInBackground( - const v8::Arguments &args); + const v8::Arguments& args); - static v8::Handle ContinueUpdate(const v8::Arguments &args); - static v8::Handle QuitAndInstall(const v8::Arguments &args); + static v8::Handle ContinueUpdate(const v8::Arguments& args); + static v8::Handle QuitAndInstall(const v8::Arguments& args); base::Closure continue_update_; base::Closure quit_and_install_; diff --git a/browser/api/atom_api_browser_ipc.cc b/browser/api/atom_api_browser_ipc.cc index 359743acfd86..39feb5658143 100644 --- a/browser/api/atom_api_browser_ipc.cc +++ b/browser/api/atom_api_browser_ipc.cc @@ -18,7 +18,7 @@ namespace atom { namespace api { // static -v8::Handle BrowserIPC::Send(const v8::Arguments &args) { +v8::Handle BrowserIPC::Send(const v8::Arguments& args) { v8::HandleScope scope; string16 channel; diff --git a/browser/api/atom_api_browser_ipc.h b/browser/api/atom_api_browser_ipc.h index 5411daf38ab2..670a84e582ae 100644 --- a/browser/api/atom_api_browser_ipc.h +++ b/browser/api/atom_api_browser_ipc.h @@ -17,7 +17,7 @@ class BrowserIPC { static void Initialize(v8::Handle target); private: - static v8::Handle Send(const v8::Arguments &args); + static v8::Handle Send(const v8::Arguments& args); DISALLOW_IMPLICIT_CONSTRUCTORS(BrowserIPC); }; diff --git a/browser/api/atom_api_dialog.cc b/browser/api/atom_api_dialog.cc index 063ed0d4cffb..bc6d70c7e222 100644 --- a/browser/api/atom_api_dialog.cc +++ b/browser/api/atom_api_dialog.cc @@ -49,7 +49,7 @@ void Initialize(v8::Handle target) { } // namespace -v8::Handle ShowMessageBox(const v8::Arguments &args) { +v8::Handle ShowMessageBox(const v8::Arguments& args) { v8::HandleScope scope; int type; @@ -83,7 +83,7 @@ v8::Handle ShowMessageBox(const v8::Arguments &args) { } } -v8::Handle ShowOpenDialog(const v8::Arguments &args) { +v8::Handle ShowOpenDialog(const v8::Arguments& args) { v8::HandleScope scope; std::string title; @@ -121,7 +121,7 @@ v8::Handle ShowOpenDialog(const v8::Arguments &args) { } } -v8::Handle ShowSaveDialog(const v8::Arguments &args) { +v8::Handle ShowSaveDialog(const v8::Arguments& args) { v8::HandleScope scope; std::string title; diff --git a/browser/api/atom_api_dialog.h b/browser/api/atom_api_dialog.h index 0aec5cb85c74..d0f77d2784cf 100644 --- a/browser/api/atom_api_dialog.h +++ b/browser/api/atom_api_dialog.h @@ -11,9 +11,9 @@ namespace atom { namespace api { -v8::Handle ShowMessageBox(const v8::Arguments &args); -v8::Handle ShowOpenDialog(const v8::Arguments &args); -v8::Handle ShowSaveDialog(const v8::Arguments &args); +v8::Handle ShowMessageBox(const v8::Arguments& args); +v8::Handle ShowOpenDialog(const v8::Arguments& args); +v8::Handle ShowSaveDialog(const v8::Arguments& args); } // namespace api diff --git a/browser/api/atom_api_menu.cc b/browser/api/atom_api_menu.cc index 06ac6b2542c0..89c64ea1e48c 100644 --- a/browser/api/atom_api_menu.cc +++ b/browser/api/atom_api_menu.cc @@ -119,7 +119,7 @@ void Menu::ExecuteCommand(int command_id, int event_flags) { } // static -v8::Handle Menu::New(const v8::Arguments &args) { +v8::Handle Menu::New(const v8::Arguments& args) { v8::HandleScope scope; if (!args.IsConstructCall()) @@ -131,7 +131,7 @@ v8::Handle Menu::New(const v8::Arguments &args) { } // static -v8::Handle Menu::InsertItem(const v8::Arguments &args) { +v8::Handle Menu::InsertItem(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index, command_id; @@ -148,7 +148,7 @@ v8::Handle Menu::InsertItem(const v8::Arguments &args) { } // static -v8::Handle Menu::InsertCheckItem(const v8::Arguments &args) { +v8::Handle Menu::InsertCheckItem(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index, command_id; @@ -165,7 +165,7 @@ v8::Handle Menu::InsertCheckItem(const v8::Arguments &args) { } // static -v8::Handle Menu::InsertRadioItem(const v8::Arguments &args) { +v8::Handle Menu::InsertRadioItem(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index, command_id, group_id; @@ -182,7 +182,7 @@ v8::Handle Menu::InsertRadioItem(const v8::Arguments &args) { } // static -v8::Handle Menu::InsertSeparator(const v8::Arguments &args) { +v8::Handle Menu::InsertSeparator(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index; @@ -198,7 +198,7 @@ v8::Handle Menu::InsertSeparator(const v8::Arguments &args) { } // static -v8::Handle Menu::InsertSubMenu(const v8::Arguments &args) { +v8::Handle Menu::InsertSubMenu(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index, command_id; @@ -220,7 +220,7 @@ v8::Handle Menu::InsertSubMenu(const v8::Arguments &args) { } // static -v8::Handle Menu::SetIcon(const v8::Arguments &args) { +v8::Handle Menu::SetIcon(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index; @@ -234,7 +234,7 @@ v8::Handle Menu::SetIcon(const v8::Arguments &args) { } // static -v8::Handle Menu::SetSublabel(const v8::Arguments &args) { +v8::Handle Menu::SetSublabel(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index; @@ -248,7 +248,7 @@ v8::Handle Menu::SetSublabel(const v8::Arguments &args) { } // static -v8::Handle Menu::Clear(const v8::Arguments &args) { +v8::Handle Menu::Clear(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; self->model_->Clear(); @@ -257,60 +257,60 @@ v8::Handle Menu::Clear(const v8::Arguments &args) { } // static -v8::Handle Menu::GetIndexOfCommandId(const v8::Arguments &args) { +v8::Handle Menu::GetIndexOfCommandId(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index = args[0]->IntegerValue(); return v8::Integer::New(self->model_->GetIndexOfCommandId(index)); } // static -v8::Handle Menu::GetItemCount(const v8::Arguments &args) { +v8::Handle Menu::GetItemCount(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; return v8::Integer::New(self->model_->GetItemCount()); } // static -v8::Handle Menu::GetCommandIdAt(const v8::Arguments &args) { +v8::Handle Menu::GetCommandIdAt(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index = args[0]->IntegerValue(); return v8::Integer::New(self->model_->GetCommandIdAt(index)); } // static -v8::Handle Menu::GetLabelAt(const v8::Arguments &args) { +v8::Handle Menu::GetLabelAt(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index = args[0]->IntegerValue(); return ToV8Value(self->model_->GetLabelAt(index)); } // static -v8::Handle Menu::GetSublabelAt(const v8::Arguments &args) { +v8::Handle Menu::GetSublabelAt(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index = args[0]->IntegerValue(); return ToV8Value(self->model_->GetSublabelAt(index)); } // static -v8::Handle Menu::IsItemCheckedAt(const v8::Arguments &args) { +v8::Handle Menu::IsItemCheckedAt(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; int index = args[0]->IntegerValue(); return v8::Boolean::New(self->model_->IsItemCheckedAt(index)); } // static -v8::Handle Menu::IsEnabledAt(const v8::Arguments &args) { +v8::Handle Menu::IsEnabledAt(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; return v8::Boolean::New(self->model_->IsEnabledAt(args[0]->IntegerValue())); } // static -v8::Handle Menu::IsVisibleAt(const v8::Arguments &args) { +v8::Handle Menu::IsVisibleAt(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; return v8::Boolean::New(self->model_->IsVisibleAt(args[0]->IntegerValue())); } // static -v8::Handle Menu::Popup(const v8::Arguments &args) { +v8::Handle Menu::Popup(const v8::Arguments& args) { UNWRAP_MEMNU_AND_CHECK; atom::NativeWindow* window; diff --git a/browser/api/atom_api_menu.h b/browser/api/atom_api_menu.h index bae25aa0573a..d0a7b1fb29f1 100644 --- a/browser/api/atom_api_menu.h +++ b/browser/api/atom_api_menu.h @@ -44,36 +44,36 @@ class Menu : public EventEmitter, scoped_ptr model_; private: - static v8::Handle New(const v8::Arguments &args); + static v8::Handle New(const v8::Arguments& args); - static v8::Handle InsertItem(const v8::Arguments &args); - static v8::Handle InsertCheckItem(const v8::Arguments &args); - static v8::Handle InsertRadioItem(const v8::Arguments &args); - static v8::Handle InsertSeparator(const v8::Arguments &args); - static v8::Handle InsertSubMenu(const v8::Arguments &args); + static v8::Handle InsertItem(const v8::Arguments& args); + static v8::Handle InsertCheckItem(const v8::Arguments& args); + static v8::Handle InsertRadioItem(const v8::Arguments& args); + static v8::Handle InsertSeparator(const v8::Arguments& args); + static v8::Handle InsertSubMenu(const v8::Arguments& args); - static v8::Handle SetIcon(const v8::Arguments &args); - static v8::Handle SetSublabel(const v8::Arguments &args); + static v8::Handle SetIcon(const v8::Arguments& args); + static v8::Handle SetSublabel(const v8::Arguments& args); - static v8::Handle Clear(const v8::Arguments &args); + static v8::Handle Clear(const v8::Arguments& args); - static v8::Handle GetIndexOfCommandId(const v8::Arguments &args); - static v8::Handle GetItemCount(const v8::Arguments &args); - static v8::Handle GetCommandIdAt(const v8::Arguments &args); - static v8::Handle GetLabelAt(const v8::Arguments &args); - static v8::Handle GetSublabelAt(const v8::Arguments &args); - static v8::Handle IsItemCheckedAt(const v8::Arguments &args); - static v8::Handle IsEnabledAt(const v8::Arguments &args); - static v8::Handle IsVisibleAt(const v8::Arguments &args); + static v8::Handle GetIndexOfCommandId(const v8::Arguments& args); + static v8::Handle GetItemCount(const v8::Arguments& args); + static v8::Handle GetCommandIdAt(const v8::Arguments& args); + static v8::Handle GetLabelAt(const v8::Arguments& args); + static v8::Handle GetSublabelAt(const v8::Arguments& args); + static v8::Handle IsItemCheckedAt(const v8::Arguments& args); + static v8::Handle IsEnabledAt(const v8::Arguments& args); + static v8::Handle IsVisibleAt(const v8::Arguments& args); - static v8::Handle Popup(const v8::Arguments &args); + static v8::Handle Popup(const v8::Arguments& args); #if defined(OS_WIN) - static v8::Handle AttachToWindow(const v8::Arguments &args); + static v8::Handle AttachToWindow(const v8::Arguments& args); #elif defined(OS_MACOSX) - static v8::Handle SetApplicationMenu(const v8::Arguments &args); + static v8::Handle SetApplicationMenu(const v8::Arguments& args); static v8::Handle SendActionToFirstResponder( - const v8::Arguments &args); + const v8::Arguments& args); #endif DISALLOW_COPY_AND_ASSIGN(Menu); diff --git a/browser/api/atom_api_menu_mac.mm b/browser/api/atom_api_menu_mac.mm index 89270190baa3..a312089b95ec 100644 --- a/browser/api/atom_api_menu_mac.mm +++ b/browser/api/atom_api_menu_mac.mm @@ -71,7 +71,7 @@ void MenuMac::SendActionToFirstResponder(const std::string& action) { } // static -v8::Handle Menu::SetApplicationMenu(const v8::Arguments &args) { +v8::Handle Menu::SetApplicationMenu(const v8::Arguments& args) { v8::HandleScope scope; if (!args[0]->IsObject()) @@ -93,7 +93,7 @@ v8::Handle Menu::SetApplicationMenu(const v8::Arguments &args) { // static v8::Handle Menu::SendActionToFirstResponder( - const v8::Arguments &args) { + const v8::Arguments& args) { v8::HandleScope scope; std::string action; diff --git a/browser/api/atom_api_power_monitor.h b/browser/api/atom_api_power_monitor.h index 997d1d6441de..a393e75b61ff 100644 --- a/browser/api/atom_api_power_monitor.h +++ b/browser/api/atom_api_power_monitor.h @@ -29,7 +29,7 @@ class PowerMonitor : public EventEmitter, virtual void OnResume() OVERRIDE; private: - static v8::Handle New(const v8::Arguments &args); + static v8::Handle New(const v8::Arguments& args); DISALLOW_COPY_AND_ASSIGN(PowerMonitor); }; diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 768198f3e48b..0dddad319bd2 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -102,7 +102,7 @@ void Window::OnCapturePageDone(v8::Persistent callback, } // static -v8::Handle Window::New(const v8::Arguments &args) { +v8::Handle Window::New(const v8::Arguments& args) { v8::HandleScope scope; if (!args.IsConstructCall()) @@ -124,7 +124,7 @@ v8::Handle Window::New(const v8::Arguments &args) { } // static -v8::Handle Window::Destroy(const v8::Arguments &args) { +v8::Handle Window::Destroy(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; base::ProcessHandle handle = self->window_->GetRenderProcessHandle(); @@ -140,7 +140,7 @@ v8::Handle Window::Destroy(const v8::Arguments &args) { } // static -v8::Handle Window::Close(const v8::Arguments &args) { +v8::Handle Window::Close(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Close(); @@ -149,7 +149,7 @@ v8::Handle Window::Close(const v8::Arguments &args) { } // static -v8::Handle Window::Focus(const v8::Arguments &args) { +v8::Handle Window::Focus(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Focus(args[0]->IsBoolean() ? args[0]->BooleanValue(): true); @@ -158,13 +158,13 @@ v8::Handle Window::Focus(const v8::Arguments &args) { } // static -v8::Handle Window::IsFocused(const v8::Arguments &args) { +v8::Handle Window::IsFocused(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->IsFocused()); } // static -v8::Handle Window::Show(const v8::Arguments &args) { +v8::Handle Window::Show(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Show(); @@ -173,7 +173,7 @@ v8::Handle Window::Show(const v8::Arguments &args) { } // static -v8::Handle Window::Hide(const v8::Arguments &args) { +v8::Handle Window::Hide(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Hide(); @@ -188,7 +188,7 @@ v8::Handle Window::IsVisible(const v8::Arguments& args) { } // static -v8::Handle Window::Maximize(const v8::Arguments &args) { +v8::Handle Window::Maximize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Maximize(); @@ -197,7 +197,7 @@ v8::Handle Window::Maximize(const v8::Arguments &args) { } // static -v8::Handle Window::Unmaximize(const v8::Arguments &args) { +v8::Handle Window::Unmaximize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Unmaximize(); @@ -206,7 +206,7 @@ v8::Handle Window::Unmaximize(const v8::Arguments &args) { } // static -v8::Handle Window::Minimize(const v8::Arguments &args) { +v8::Handle Window::Minimize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Minimize(); @@ -215,7 +215,7 @@ v8::Handle Window::Minimize(const v8::Arguments &args) { } // static -v8::Handle Window::Restore(const v8::Arguments &args) { +v8::Handle Window::Restore(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Restore(); @@ -224,7 +224,7 @@ v8::Handle Window::Restore(const v8::Arguments &args) { } // static -v8::Handle Window::SetFullscreen(const v8::Arguments &args) { +v8::Handle Window::SetFullscreen(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; bool fs; @@ -236,14 +236,14 @@ v8::Handle Window::SetFullscreen(const v8::Arguments &args) { } // static -v8::Handle Window::IsFullscreen(const v8::Arguments &args) { +v8::Handle Window::IsFullscreen(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->IsFullscreen()); } // static -v8::Handle Window::SetSize(const v8::Arguments &args) { +v8::Handle Window::SetSize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; int width, height; @@ -255,7 +255,7 @@ v8::Handle Window::SetSize(const v8::Arguments &args) { } // static -v8::Handle Window::GetSize(const v8::Arguments &args) { +v8::Handle Window::GetSize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Size size = self->window_->GetSize(); @@ -267,7 +267,7 @@ v8::Handle Window::GetSize(const v8::Arguments &args) { } // static -v8::Handle Window::SetMinimumSize(const v8::Arguments &args) { +v8::Handle Window::SetMinimumSize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; int width, height; @@ -279,7 +279,7 @@ v8::Handle Window::SetMinimumSize(const v8::Arguments &args) { } // static -v8::Handle Window::GetMinimumSize(const v8::Arguments &args) { +v8::Handle Window::GetMinimumSize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Size size = self->window_->GetMinimumSize(); @@ -291,7 +291,7 @@ v8::Handle Window::GetMinimumSize(const v8::Arguments &args) { } // static -v8::Handle Window::SetMaximumSize(const v8::Arguments &args) { +v8::Handle Window::SetMaximumSize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; @@ -304,7 +304,7 @@ v8::Handle Window::SetMaximumSize(const v8::Arguments &args) { } // static -v8::Handle Window::GetMaximumSize(const v8::Arguments &args) { +v8::Handle Window::GetMaximumSize(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Size size = self->window_->GetMaximumSize(); @@ -316,7 +316,7 @@ v8::Handle Window::GetMaximumSize(const v8::Arguments &args) { } // static -v8::Handle Window::SetResizable(const v8::Arguments &args) { +v8::Handle Window::SetResizable(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; bool resizable; @@ -328,14 +328,14 @@ v8::Handle Window::SetResizable(const v8::Arguments &args) { } // static -v8::Handle Window::IsResizable(const v8::Arguments &args) { +v8::Handle Window::IsResizable(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->IsResizable()); } // static -v8::Handle Window::SetAlwaysOnTop(const v8::Arguments &args) { +v8::Handle Window::SetAlwaysOnTop(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; bool top; @@ -347,14 +347,14 @@ v8::Handle Window::SetAlwaysOnTop(const v8::Arguments &args) { } // static -v8::Handle Window::IsAlwaysOnTop(const v8::Arguments &args) { +v8::Handle Window::IsAlwaysOnTop(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->IsAlwaysOnTop()); } // static -v8::Handle Window::Center(const v8::Arguments &args) { +v8::Handle Window::Center(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->Center(); @@ -363,7 +363,7 @@ v8::Handle Window::Center(const v8::Arguments &args) { } // static -v8::Handle Window::SetPosition(const v8::Arguments &args) { +v8::Handle Window::SetPosition(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; int x, y; @@ -375,7 +375,7 @@ v8::Handle Window::SetPosition(const v8::Arguments &args) { } // static -v8::Handle Window::GetPosition(const v8::Arguments &args) { +v8::Handle Window::GetPosition(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Point pos = self->window_->GetPosition(); @@ -387,7 +387,7 @@ v8::Handle Window::GetPosition(const v8::Arguments &args) { } // static -v8::Handle Window::SetTitle(const v8::Arguments &args) { +v8::Handle Window::SetTitle(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; std::string title; @@ -399,13 +399,13 @@ v8::Handle Window::SetTitle(const v8::Arguments &args) { } // static -v8::Handle Window::GetTitle(const v8::Arguments &args) { +v8::Handle Window::GetTitle(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->GetTitle()); } // static -v8::Handle Window::FlashFrame(const v8::Arguments &args) { +v8::Handle Window::FlashFrame(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->FlashFrame( @@ -415,7 +415,7 @@ v8::Handle Window::FlashFrame(const v8::Arguments &args) { } // static -v8::Handle Window::SetKiosk(const v8::Arguments &args) { +v8::Handle Window::SetKiosk(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; bool kiosk; @@ -427,14 +427,14 @@ v8::Handle Window::SetKiosk(const v8::Arguments &args) { } // static -v8::Handle Window::IsKiosk(const v8::Arguments &args) { +v8::Handle Window::IsKiosk(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->IsKiosk()); } // static -v8::Handle Window::OpenDevTools(const v8::Arguments &args) { +v8::Handle Window::OpenDevTools(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->OpenDevTools(); @@ -443,7 +443,7 @@ v8::Handle Window::OpenDevTools(const v8::Arguments &args) { } // static -v8::Handle Window::CloseDevTools(const v8::Arguments &args) { +v8::Handle Window::CloseDevTools(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->CloseDevTools(); @@ -470,7 +470,7 @@ v8::Handle Window::InspectElement(const v8::Arguments& args) { } // static -v8::Handle Window::FocusOnWebView(const v8::Arguments &args) { +v8::Handle Window::FocusOnWebView(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->FocusOnWebView(); @@ -479,7 +479,7 @@ v8::Handle Window::FocusOnWebView(const v8::Arguments &args) { } // static -v8::Handle Window::BlurWebView(const v8::Arguments &args) { +v8::Handle Window::BlurWebView(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->BlurWebView(); @@ -511,28 +511,28 @@ v8::Handle Window::CapturePage(const v8::Arguments& args) { } // static -v8::Handle Window::GetPageTitle(const v8::Arguments &args) { +v8::Handle Window::GetPageTitle(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->GetWebContents()->GetTitle()); } // static -v8::Handle Window::IsLoading(const v8::Arguments &args) { +v8::Handle Window::IsLoading(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->GetWebContents()->IsLoading()); } // static -v8::Handle Window::IsWaitingForResponse(const v8::Arguments &args) { +v8::Handle Window::IsWaitingForResponse(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->GetWebContents()->IsWaitingForResponse()); } // static -v8::Handle Window::Stop(const v8::Arguments &args) { +v8::Handle Window::Stop(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; self->window_->GetWebContents()->Stop(); @@ -541,14 +541,14 @@ v8::Handle Window::Stop(const v8::Arguments &args) { } // static -v8::Handle Window::GetRoutingID(const v8::Arguments &args) { +v8::Handle Window::GetRoutingID(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->GetWebContents()->GetRoutingID()); } // static -v8::Handle Window::GetProcessID(const v8::Arguments &args) { +v8::Handle Window::GetProcessID(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value( @@ -556,14 +556,14 @@ v8::Handle Window::GetProcessID(const v8::Arguments &args) { } // static -v8::Handle Window::IsCrashed(const v8::Arguments &args) { +v8::Handle Window::IsCrashed(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; return ToV8Value(self->window_->GetWebContents()->IsCrashed()); } // static -v8::Handle Window::LoadURL(const v8::Arguments &args) { +v8::Handle Window::LoadURL(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; GURL url; @@ -582,7 +582,7 @@ v8::Handle Window::LoadURL(const v8::Arguments &args) { } // static -v8::Handle Window::GetURL(const v8::Arguments &args) { +v8::Handle Window::GetURL(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = @@ -595,7 +595,7 @@ v8::Handle Window::GetURL(const v8::Arguments &args) { } // static -v8::Handle Window::CanGoBack(const v8::Arguments &args) { +v8::Handle Window::CanGoBack(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = @@ -605,7 +605,7 @@ v8::Handle Window::CanGoBack(const v8::Arguments &args) { } // static -v8::Handle Window::CanGoForward(const v8::Arguments &args) { +v8::Handle Window::CanGoForward(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = @@ -615,7 +615,7 @@ v8::Handle Window::CanGoForward(const v8::Arguments &args) { } // static -v8::Handle Window::CanGoToOffset(const v8::Arguments &args) { +v8::Handle Window::CanGoToOffset(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; int offset; @@ -629,7 +629,7 @@ v8::Handle Window::CanGoToOffset(const v8::Arguments &args) { } // static -v8::Handle Window::GoBack(const v8::Arguments &args) { +v8::Handle Window::GoBack(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = @@ -640,7 +640,7 @@ v8::Handle Window::GoBack(const v8::Arguments &args) { } // static -v8::Handle Window::GoForward(const v8::Arguments &args) { +v8::Handle Window::GoForward(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = @@ -651,7 +651,7 @@ v8::Handle Window::GoForward(const v8::Arguments &args) { } // static -v8::Handle Window::GoToIndex(const v8::Arguments &args) { +v8::Handle Window::GoToIndex(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; int index; @@ -666,7 +666,7 @@ v8::Handle Window::GoToIndex(const v8::Arguments &args) { } // static -v8::Handle Window::GoToOffset(const v8::Arguments &args) { +v8::Handle Window::GoToOffset(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; int offset; @@ -681,7 +681,7 @@ v8::Handle Window::GoToOffset(const v8::Arguments &args) { } // static -v8::Handle Window::Reload(const v8::Arguments &args) { +v8::Handle Window::Reload(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = @@ -692,7 +692,7 @@ v8::Handle Window::Reload(const v8::Arguments &args) { } // static -v8::Handle Window::ReloadIgnoringCache(const v8::Arguments &args) { +v8::Handle Window::ReloadIgnoringCache(const v8::Arguments& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = diff --git a/browser/api/atom_api_window.h b/browser/api/atom_api_window.h index 4558bf69d969..f410615d68ee 100644 --- a/browser/api/atom_api_window.h +++ b/browser/api/atom_api_window.h @@ -47,70 +47,70 @@ class Window : public EventEmitter, virtual void OnRendererCrashed() OVERRIDE; private: - static v8::Handle New(const v8::Arguments &args); - static v8::Handle Destroy(const v8::Arguments &args); + static v8::Handle New(const v8::Arguments& args); + static v8::Handle Destroy(const v8::Arguments& args); // APIs for NativeWindow. - static v8::Handle Close(const v8::Arguments &args); - static v8::Handle Focus(const v8::Arguments &args); - static v8::Handle IsFocused(const v8::Arguments &args); - static v8::Handle Show(const v8::Arguments &args); - static v8::Handle Hide(const v8::Arguments &args); - static v8::Handle IsVisible(const v8::Arguments &args); - static v8::Handle Maximize(const v8::Arguments &args); - static v8::Handle Unmaximize(const v8::Arguments &args); - static v8::Handle Minimize(const v8::Arguments &args); - static v8::Handle Restore(const v8::Arguments &args); - static v8::Handle SetFullscreen(const v8::Arguments &args); - static v8::Handle IsFullscreen(const v8::Arguments &args); - static v8::Handle SetSize(const v8::Arguments &args); - static v8::Handle GetSize(const v8::Arguments &args); - static v8::Handle SetMinimumSize(const v8::Arguments &args); - static v8::Handle GetMinimumSize(const v8::Arguments &args); - static v8::Handle SetMaximumSize(const v8::Arguments &args); - static v8::Handle GetMaximumSize(const v8::Arguments &args); - static v8::Handle SetResizable(const v8::Arguments &args); - static v8::Handle IsResizable(const v8::Arguments &args); - static v8::Handle SetAlwaysOnTop(const v8::Arguments &args); - static v8::Handle IsAlwaysOnTop(const v8::Arguments &args); - static v8::Handle Center(const v8::Arguments &args); - static v8::Handle SetPosition(const v8::Arguments &args); - static v8::Handle GetPosition(const v8::Arguments &args); - static v8::Handle SetTitle(const v8::Arguments &args); - static v8::Handle GetTitle(const v8::Arguments &args); - static v8::Handle FlashFrame(const v8::Arguments &args); - static v8::Handle SetKiosk(const v8::Arguments &args); - static v8::Handle IsKiosk(const v8::Arguments &args); - static v8::Handle OpenDevTools(const v8::Arguments &args); - static v8::Handle CloseDevTools(const v8::Arguments &args); - static v8::Handle IsDevToolsOpened(const v8::Arguments &args); - static v8::Handle InspectElement(const v8::Arguments &args); - static v8::Handle FocusOnWebView(const v8::Arguments &args); - static v8::Handle BlurWebView(const v8::Arguments &args); + static v8::Handle Close(const v8::Arguments& args); + static v8::Handle Focus(const v8::Arguments& args); + static v8::Handle IsFocused(const v8::Arguments& args); + static v8::Handle Show(const v8::Arguments& args); + static v8::Handle Hide(const v8::Arguments& args); + static v8::Handle IsVisible(const v8::Arguments& args); + static v8::Handle Maximize(const v8::Arguments& args); + static v8::Handle Unmaximize(const v8::Arguments& args); + static v8::Handle Minimize(const v8::Arguments& args); + static v8::Handle Restore(const v8::Arguments& args); + static v8::Handle SetFullscreen(const v8::Arguments& args); + static v8::Handle IsFullscreen(const v8::Arguments& args); + static v8::Handle SetSize(const v8::Arguments& args); + static v8::Handle GetSize(const v8::Arguments& args); + static v8::Handle SetMinimumSize(const v8::Arguments& args); + static v8::Handle GetMinimumSize(const v8::Arguments& args); + static v8::Handle SetMaximumSize(const v8::Arguments& args); + static v8::Handle GetMaximumSize(const v8::Arguments& args); + static v8::Handle SetResizable(const v8::Arguments& args); + static v8::Handle IsResizable(const v8::Arguments& args); + static v8::Handle SetAlwaysOnTop(const v8::Arguments& args); + static v8::Handle IsAlwaysOnTop(const v8::Arguments& args); + static v8::Handle Center(const v8::Arguments& args); + static v8::Handle SetPosition(const v8::Arguments& args); + static v8::Handle GetPosition(const v8::Arguments& args); + static v8::Handle SetTitle(const v8::Arguments& args); + static v8::Handle GetTitle(const v8::Arguments& args); + static v8::Handle FlashFrame(const v8::Arguments& args); + static v8::Handle SetKiosk(const v8::Arguments& args); + static v8::Handle IsKiosk(const v8::Arguments& args); + static v8::Handle OpenDevTools(const v8::Arguments& args); + static v8::Handle CloseDevTools(const v8::Arguments& args); + static v8::Handle IsDevToolsOpened(const v8::Arguments& args); + static v8::Handle InspectElement(const v8::Arguments& args); + static v8::Handle FocusOnWebView(const v8::Arguments& args); + static v8::Handle BlurWebView(const v8::Arguments& args); static v8::Handle IsWebViewFocused(const v8::Arguments& args); static v8::Handle CapturePage(const v8::Arguments& args); // APIs for WebContents. - static v8::Handle GetPageTitle(const v8::Arguments &args); - static v8::Handle IsLoading(const v8::Arguments &args); - static v8::Handle IsWaitingForResponse(const v8::Arguments &args); - static v8::Handle Stop(const v8::Arguments &args); - static v8::Handle GetRoutingID(const v8::Arguments &args); - static v8::Handle GetProcessID(const v8::Arguments &args); - static v8::Handle IsCrashed(const v8::Arguments &args); + static v8::Handle GetPageTitle(const v8::Arguments& args); + static v8::Handle IsLoading(const v8::Arguments& args); + static v8::Handle IsWaitingForResponse(const v8::Arguments& args); + static v8::Handle Stop(const v8::Arguments& args); + static v8::Handle GetRoutingID(const v8::Arguments& args); + static v8::Handle GetProcessID(const v8::Arguments& args); + static v8::Handle IsCrashed(const v8::Arguments& args); // APIs for NavigationController. - static v8::Handle LoadURL(const v8::Arguments &args); - static v8::Handle GetURL(const v8::Arguments &args); - static v8::Handle CanGoBack(const v8::Arguments &args); - static v8::Handle CanGoForward(const v8::Arguments &args); - static v8::Handle CanGoToOffset(const v8::Arguments &args); - static v8::Handle GoBack(const v8::Arguments &args); - static v8::Handle GoForward(const v8::Arguments &args); - static v8::Handle GoToIndex(const v8::Arguments &args); - static v8::Handle GoToOffset(const v8::Arguments &args); - static v8::Handle Reload(const v8::Arguments &args); - static v8::Handle ReloadIgnoringCache(const v8::Arguments &args); + static v8::Handle LoadURL(const v8::Arguments& args); + static v8::Handle GetURL(const v8::Arguments& args); + static v8::Handle CanGoBack(const v8::Arguments& args); + static v8::Handle CanGoForward(const v8::Arguments& args); + static v8::Handle CanGoToOffset(const v8::Arguments& args); + static v8::Handle GoBack(const v8::Arguments& args); + static v8::Handle GoForward(const v8::Arguments& args); + static v8::Handle GoToIndex(const v8::Arguments& args); + static v8::Handle GoToOffset(const v8::Arguments& args); + static v8::Handle Reload(const v8::Arguments& args); + static v8::Handle ReloadIgnoringCache(const v8::Arguments& args); // Called when capturePage is done. void OnCapturePageDone(v8::Persistent callback, diff --git a/common/api/atom_api_clipboard.cc b/common/api/atom_api_clipboard.cc index 4c26750d2cd6..3d0fd0c6381b 100644 --- a/common/api/atom_api_clipboard.cc +++ b/common/api/atom_api_clipboard.cc @@ -14,7 +14,7 @@ namespace atom { namespace api { // static -v8::Handle Clipboard::Has(const v8::Arguments &args) { +v8::Handle Clipboard::Has(const v8::Arguments& args) { v8::HandleScope scope; if (!args[0]->IsString()) @@ -30,7 +30,7 @@ v8::Handle Clipboard::Has(const v8::Arguments &args) { } // static -v8::Handle Clipboard::Read(const v8::Arguments &args) { +v8::Handle Clipboard::Read(const v8::Arguments& args) { v8::HandleScope scope; if (!args[0]->IsString()) @@ -48,7 +48,7 @@ v8::Handle Clipboard::Read(const v8::Arguments &args) { } // static -v8::Handle Clipboard::ReadText(const v8::Arguments &args) { +v8::Handle Clipboard::ReadText(const v8::Arguments& args) { v8::HandleScope scope; ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); @@ -60,7 +60,7 @@ v8::Handle Clipboard::ReadText(const v8::Arguments &args) { } // static -v8::Handle Clipboard::WriteText(const v8::Arguments &args) { +v8::Handle Clipboard::WriteText(const v8::Arguments& args) { v8::HandleScope scope; if (!args[0]->IsString()) @@ -78,7 +78,7 @@ v8::Handle Clipboard::WriteText(const v8::Arguments &args) { } // static -v8::Handle Clipboard::Clear(const v8::Arguments &args) { +v8::Handle Clipboard::Clear(const v8::Arguments& args) { ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); clipboard->Clear(ui::Clipboard::BUFFER_STANDARD); diff --git a/common/api/atom_api_clipboard.h b/common/api/atom_api_clipboard.h index 38495a0db2fe..7b92f0cd36fc 100644 --- a/common/api/atom_api_clipboard.h +++ b/common/api/atom_api_clipboard.h @@ -17,11 +17,11 @@ class Clipboard { static void Initialize(v8::Handle target); private: - static v8::Handle Has(const v8::Arguments &args); - static v8::Handle Read(const v8::Arguments &args); - static v8::Handle ReadText(const v8::Arguments &args); - static v8::Handle WriteText(const v8::Arguments &args); - static v8::Handle Clear(const v8::Arguments &args); + static v8::Handle Has(const v8::Arguments& args); + static v8::Handle Read(const v8::Arguments& args); + static v8::Handle ReadText(const v8::Arguments& args); + static v8::Handle WriteText(const v8::Arguments& args); + static v8::Handle Clear(const v8::Arguments& args); DISALLOW_IMPLICIT_CONSTRUCTORS(Clipboard); }; diff --git a/common/api/atom_api_shell.cc b/common/api/atom_api_shell.cc index 97671cad07d7..355c4d69df5a 100644 --- a/common/api/atom_api_shell.cc +++ b/common/api/atom_api_shell.cc @@ -34,7 +34,7 @@ bool V8ValueToFilePath(v8::Handle value, base::FilePath* path) { } // namespace // static -v8::Handle Shell::ShowItemInFolder(const v8::Arguments &args) { +v8::Handle Shell::ShowItemInFolder(const v8::Arguments& args) { v8::HandleScope scope; base::FilePath file_path; @@ -46,7 +46,7 @@ v8::Handle Shell::ShowItemInFolder(const v8::Arguments &args) { } // static -v8::Handle Shell::OpenItem(const v8::Arguments &args) { +v8::Handle Shell::OpenItem(const v8::Arguments& args) { v8::HandleScope scope; base::FilePath file_path; @@ -58,7 +58,7 @@ v8::Handle Shell::OpenItem(const v8::Arguments &args) { } // static -v8::Handle Shell::OpenExternal(const v8::Arguments &args) { +v8::Handle Shell::OpenExternal(const v8::Arguments& args) { v8::HandleScope scope; if (!args[0]->IsString()) @@ -69,7 +69,7 @@ v8::Handle Shell::OpenExternal(const v8::Arguments &args) { } // static -v8::Handle Shell::MoveItemToTrash(const v8::Arguments &args) { +v8::Handle Shell::MoveItemToTrash(const v8::Arguments& args) { v8::HandleScope scope; base::FilePath file_path; @@ -81,7 +81,7 @@ v8::Handle Shell::MoveItemToTrash(const v8::Arguments &args) { } // static -v8::Handle Shell::Beep(const v8::Arguments &args) { +v8::Handle Shell::Beep(const v8::Arguments& args) { platform_util::Beep(); return v8::Undefined(); } diff --git a/common/api/atom_api_shell.h b/common/api/atom_api_shell.h index 7d0659938357..4b17fc8cffd1 100644 --- a/common/api/atom_api_shell.h +++ b/common/api/atom_api_shell.h @@ -17,11 +17,11 @@ class Shell { static void Initialize(v8::Handle target); private: - static v8::Handle ShowItemInFolder(const v8::Arguments &args); - static v8::Handle OpenItem(const v8::Arguments &args); - static v8::Handle OpenExternal(const v8::Arguments &args); - static v8::Handle MoveItemToTrash(const v8::Arguments &args); - static v8::Handle Beep(const v8::Arguments &args); + static v8::Handle ShowItemInFolder(const v8::Arguments& args); + static v8::Handle OpenItem(const v8::Arguments& args); + static v8::Handle OpenExternal(const v8::Arguments& args); + static v8::Handle MoveItemToTrash(const v8::Arguments& args); + static v8::Handle Beep(const v8::Arguments& args); DISALLOW_IMPLICIT_CONSTRUCTORS(Shell); }; diff --git a/renderer/api/atom_api_renderer_ipc.cc b/renderer/api/atom_api_renderer_ipc.cc index 3600a3923153..3a1e03640216 100644 --- a/renderer/api/atom_api_renderer_ipc.cc +++ b/renderer/api/atom_api_renderer_ipc.cc @@ -36,7 +36,7 @@ RenderView* GetCurrentRenderView() { } // namespace // static -v8::Handle RendererIPC::Send(const v8::Arguments &args) { +v8::Handle RendererIPC::Send(const v8::Arguments& args) { v8::HandleScope scope; string16 channel; @@ -60,7 +60,7 @@ v8::Handle RendererIPC::Send(const v8::Arguments &args) { } // static -v8::Handle RendererIPC::SendSync(const v8::Arguments &args) { +v8::Handle RendererIPC::SendSync(const v8::Arguments& args) { v8::HandleScope scope; string16 channel; diff --git a/renderer/api/atom_api_renderer_ipc.h b/renderer/api/atom_api_renderer_ipc.h index 9e880e370e65..60315dac7325 100644 --- a/renderer/api/atom_api_renderer_ipc.h +++ b/renderer/api/atom_api_renderer_ipc.h @@ -17,8 +17,8 @@ class RendererIPC { static void Initialize(v8::Handle target); private: - static v8::Handle Send(const v8::Arguments &args); - static v8::Handle SendSync(const v8::Arguments &args); + static v8::Handle Send(const v8::Arguments& args); + static v8::Handle SendSync(const v8::Arguments& args); DISALLOW_IMPLICIT_CONSTRUCTORS(RendererIPC); }; From 409a431892dc44a82d1435d82dd54ff731087c2e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 11 Dec 2013 15:48:19 +0800 Subject: [PATCH 06/55] Huge commit to use new V8 and Content APIs. Still got a lots of linking errors! --- app/atom_main_delegate.cc | 1 - app/atom_main_delegate.h | 1 - app/atom_main_delegate_mac.mm | 18 -- atom.gyp | 6 +- browser/api/atom_api_app.cc | 85 ++---- browser/api/atom_api_app.h | 30 +- browser/api/atom_api_auto_updater.cc | 49 ++-- browser/api/atom_api_auto_updater.h | 22 +- browser/api/atom_api_browser_ipc.cc | 17 +- browser/api/atom_api_browser_ipc.h | 2 +- browser/api/atom_api_dialog.cc | 60 ++-- browser/api/atom_api_dialog.h | 6 +- browser/api/atom_api_event.cc | 38 +-- browser/api/atom_api_event.h | 14 +- browser/api/atom_api_event_emitter.cc | 10 +- browser/api/atom_api_event_emitter.h | 5 + browser/api/atom_api_menu.cc | 111 +++---- browser/api/atom_api_menu.h | 45 +-- browser/api/atom_api_menu_mac.h | 2 +- browser/api/atom_api_menu_mac.mm | 26 +- browser/api/atom_api_menu_win.cc | 6 +- browser/api/atom_api_power_monitor.cc | 15 +- browser/api/atom_api_power_monitor.h | 2 +- browser/api/atom_api_protocol.cc | 77 +++-- browser/api/atom_api_protocol.h | 10 +- browser/api/atom_api_window.cc | 274 ++++++------------ browser/api/atom_api_window.h | 119 ++++---- browser/api/atom_browser_bindings.cc | 45 ++- browser/api/atom_browser_bindings.h | 5 +- browser/atom_browser_client.cc | 2 +- browser/atom_browser_context.cc | 8 + browser/atom_browser_main_parts.cc | 27 +- browser/atom_browser_main_parts.h | 1 - browser/atom_javascript_dialog_manager.cc | 2 +- browser/atom_javascript_dialog_manager.h | 4 +- browser/native_window.cc | 41 +-- browser/native_window.h | 3 +- browser/native_window_mac.mm | 5 +- browser/net/adapter_request_job.cc | 9 +- .../net/atom_url_request_context_getter.cc | 19 +- browser/net/atom_url_request_job_factory.cc | 6 +- browser/net/atom_url_request_job_factory.h | 1 + browser/ui/accelerator_util.cc | 2 +- browser/ui/accelerator_util_mac.mm | 2 +- browser/ui/atom_event_processing_window.h | 2 - browser/ui/atom_menu_controller_mac.h | 4 +- browser/ui/atom_menu_controller_mac.mm | 2 +- browser/ui/file_dialog_mac.mm | 2 +- common/api/atom_api_clipboard.cc | 67 ++--- common/api/atom_api_clipboard.h | 10 +- common/api/atom_api_crash_reporter.cc | 12 +- common/api/atom_api_crash_reporter.h | 2 +- common/api/atom_api_id_weak_map.cc | 119 ++++---- common/api/atom_api_id_weak_map.h | 22 +- common/api/atom_api_shell.cc | 70 ++--- common/api/atom_api_shell.h | 10 +- common/api/atom_api_v8_util.cc | 41 ++- common/api/atom_bindings.cc | 46 ++- common/api/atom_bindings.h | 11 +- common/api/atom_extensions.cc | 5 +- common/api/object_life_monitor.cc | 29 +- common/api/object_life_monitor.h | 9 +- common/node_bindings.cc | 71 +++-- common/node_bindings.h | 5 +- common/node_bindings_mac.cc | 3 +- common/platform_util_mac.mm | 2 +- .../native_type_conversions.h} | 39 ++- common/v8/node_common.h | 22 ++ common/v8/scoped_persistent.h | 115 ++++++++ common/v8_value_converter_impl.cc | 8 +- common/v8_value_converter_impl.h | 1 + renderer/api/atom_api_renderer_ipc.cc | 31 +- renderer/api/atom_api_renderer_ipc.h | 4 +- renderer/api/atom_renderer_bindings.cc | 13 +- renderer/atom_render_view_observer.cc | 6 +- renderer/atom_renderer_client.cc | 6 +- vendor/brightray | 2 +- vendor/node | 2 +- 78 files changed, 969 insertions(+), 1057 deletions(-) rename common/{v8_conversions.h => v8/native_type_conversions.h} (87%) create mode 100644 common/v8/node_common.h create mode 100644 common/v8/scoped_persistent.h diff --git a/app/atom_main_delegate.cc b/app/atom_main_delegate.cc index 696f22f6ba03..4a9581e34315 100644 --- a/app/atom_main_delegate.cc +++ b/app/atom_main_delegate.cc @@ -43,7 +43,6 @@ void AtomMainDelegate::PreSandboxStartup() { #if defined(OS_MACOSX) OverrideChildProcessPath(); OverrideFrameworkBundlePath(); - SetProcessName(); #endif InitializeResourceBundle(); diff --git a/app/atom_main_delegate.h b/app/atom_main_delegate.h index 1b2a85304309..8a11c086cd9f 100644 --- a/app/atom_main_delegate.h +++ b/app/atom_main_delegate.h @@ -23,7 +23,6 @@ class AtomMainDelegate : public brightray::MainDelegate { virtual base::FilePath GetResourcesPakFilePath(); virtual void OverrideChildProcessPath(); virtual void OverrideFrameworkBundlePath(); - virtual void SetProcessName(); #endif private: diff --git a/app/atom_main_delegate_mac.mm b/app/atom_main_delegate_mac.mm index e304582ee9ca..d9ddb4d93c79 100644 --- a/app/atom_main_delegate_mac.mm +++ b/app/atom_main_delegate_mac.mm @@ -45,22 +45,4 @@ void AtomMainDelegate::OverrideChildProcessPath() { PathService::Override(content::CHILD_PROCESS_EXE, helper_path); } -void AtomMainDelegate::SetProcessName() { - const auto& command_line = *CommandLine::ForCurrentProcess(); - auto process_type = command_line.GetSwitchValueASCII(switches::kProcessType); - std::string suffix; - if (process_type == switches::kRendererProcess) - suffix = "Renderer"; - else if (process_type == switches::kPluginProcess || - process_type == switches::kPpapiPluginProcess) - suffix = "Plug-In Host"; - else if (process_type == switches::kUtilityProcess) - suffix = "Utility"; - else - return; - - base::mac::SetProcessName(base::mac::NSToCFCast(base::SysUTF8ToNSString( - brightray::GetApplicationName() + " " + suffix))); -} - } // namespace atom diff --git a/atom.gyp b/atom.gyp index a973cad86cf9..a9d8b92b420a 100644 --- a/atom.gyp +++ b/atom.gyp @@ -165,7 +165,9 @@ 'common/platform_util_mac.mm', 'common/platform_util_win.cc', 'common/swap_or_assign.h', - 'common/v8_conversions.h', + 'common/v8/node_common.h', + 'common/v8/scoped_persistent.h', + 'common/v8/native_type_conversions.h', 'common/v8_value_converter_impl.cc', 'common/v8_value_converter_impl.h', 'renderer/api/atom_api_renderer_ipc.cc', @@ -328,6 +330,8 @@ 'vendor', # The `node.h` is using `#include"v8.h"`. 'vendor/brightray/vendor/download/libchromiumcontent/src/v8/include', + # The `node.h` is using `#include"ares.h"`. + 'vendor/node/deps/cares/include', ], 'direct_dependent_settings': { 'include_dirs': [ diff --git a/browser/api/atom_api_app.cc b/browser/api/atom_api_app.cc index 7ad96d19d606..d3b3b2e64ddf 100644 --- a/browser/api/atom_api_app.cc +++ b/browser/api/atom_api_app.cc @@ -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 App::New(const v8::Arguments& args) { - v8::HandleScope scope; +void App::New(const v8::FunctionCallbackInfo& 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 App::Quit(const v8::Arguments& args) { - v8::HandleScope scope; - +void App::Quit(const v8::FunctionCallbackInfo& args) { Browser::Get()->Quit(); - - return v8::Undefined(); } // static -v8::Handle App::Exit(const v8::Arguments& args) { - v8::HandleScope scope; - +void App::Exit(const v8::FunctionCallbackInfo& args) { exit(args[0]->IntegerValue()); - - return v8::Undefined(); } // static -v8::Handle App::Terminate(const v8::Arguments& args) { - v8::HandleScope scope; - +void App::Terminate(const v8::FunctionCallbackInfo& args) { Browser::Get()->Terminate(); - - return v8::Undefined(); } // static -v8::Handle App::Focus(const v8::Arguments& args) { - v8::HandleScope scope; - +void App::Focus(const v8::FunctionCallbackInfo& args) { Browser::Get()->Focus(); - - return v8::Undefined(); } // static -v8::Handle App::GetVersion(const v8::Arguments& args) { - return ToV8Value(Browser::Get()->GetVersion()); +void App::GetVersion(const v8::FunctionCallbackInfo& args) { + args.GetReturnValue().Set(ToV8Value(Browser::Get()->GetVersion())); } // static -v8::Handle App::SetVersion(const v8::Arguments& args) { - v8::HandleScope scope; - +void App::SetVersion(const v8::FunctionCallbackInfo& args) { std::string version; if (!FromV8Arguments(args, &version)) return node::ThrowError("Bad argument"); Browser::Get()->SetVersion(version); - - return v8::Undefined(); } // static -v8::Handle App::GetName(const v8::Arguments& args) { - return ToV8Value(Browser::Get()->GetName()); +void App::GetName(const v8::FunctionCallbackInfo& args) { + return args.GetReturnValue().Set(ToV8Value(Browser::Get()->GetName())); } // static -v8::Handle App::SetName(const v8::Arguments& args) { - v8::HandleScope scope; - +void App::SetName(const v8::FunctionCallbackInfo& args) { std::string name; if (!FromV8Arguments(args, &name)) return node::ThrowError("Bad argument"); Browser::Get()->SetName(name); - - return v8::Undefined(); } // static -v8::Handle App::AppendSwitch(const v8::Arguments& args) { - v8::HandleScope scope; - +void App::AppendSwitch(const v8::FunctionCallbackInfo& args) { std::string switch_string; if (!FromV8Arguments(args, &switch_string)) return node::ThrowError("Bad argument"); @@ -150,27 +123,21 @@ v8::Handle App::AppendSwitch(const v8::Arguments& args) { CommandLine::ForCurrentProcess()->AppendSwitchASCII( switch_string, value); } - - return v8::Undefined(); } // static -v8::Handle App::AppendArgument(const v8::Arguments& args) { - v8::HandleScope scope; - +void App::AppendArgument(const v8::FunctionCallbackInfo& 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 App::DockBounce(const v8::Arguments& args) { +void App::DockBounce(const v8::FunctionCallbackInfo& args) { std::string type; if (!FromV8Arguments(args, &type)) return node::ThrowError("Bad argument"); @@ -184,34 +151,32 @@ v8::Handle 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 App::DockCancelBounce(const v8::Arguments& args) { +void App::DockCancelBounce(const v8::FunctionCallbackInfo& args) { Browser::Get()->DockCancelBounce(FromV8Value(args[0])); - return v8::Undefined(); } // static -v8::Handle App::DockSetBadgeText(const v8::Arguments& args) { +void App::DockSetBadgeText(const v8::FunctionCallbackInfo& args) { Browser::Get()->DockSetBadgeText(FromV8Value(args[0])); - return v8::Undefined(); } // static -v8::Handle App::DockGetBadgeText(const v8::Arguments& args) { +void App::DockGetBadgeText(const v8::FunctionCallbackInfo& 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 target) { - v8::HandleScope scope; + v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); - v8::Local t = v8::FunctionTemplate::New(App::New); + v8::Local t = v8::FunctionTemplate::New(New); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(v8::String::NewSymbol("Application")); diff --git a/browser/api/atom_api_app.h b/browser/api/atom_api_app.h index 634a1441746f..7bfa6d091aac 100644 --- a/browser/api/atom_api_app.h +++ b/browser/api/atom_api_app.h @@ -33,24 +33,24 @@ class App : public EventEmitter, virtual void OnFinishLaunching() OVERRIDE; private: - static v8::Handle New(const v8::Arguments& args); + static void New(const v8::FunctionCallbackInfo& args); - static v8::Handle Quit(const v8::Arguments& args); - static v8::Handle Exit(const v8::Arguments& args); - static v8::Handle Terminate(const v8::Arguments& args); - static v8::Handle Focus(const v8::Arguments& args); - static v8::Handle GetVersion(const v8::Arguments& args); - static v8::Handle SetVersion(const v8::Arguments& args); - static v8::Handle GetName(const v8::Arguments& args); - static v8::Handle SetName(const v8::Arguments& args); - static v8::Handle AppendSwitch(const v8::Arguments& args); - static v8::Handle AppendArgument(const v8::Arguments& args); + static void Quit(const v8::FunctionCallbackInfo& args); + static void Exit(const v8::FunctionCallbackInfo& args); + static void Terminate(const v8::FunctionCallbackInfo& args); + static void Focus(const v8::FunctionCallbackInfo& args); + static void GetVersion(const v8::FunctionCallbackInfo& args); + static void SetVersion(const v8::FunctionCallbackInfo& args); + static void GetName(const v8::FunctionCallbackInfo& args); + static void SetName(const v8::FunctionCallbackInfo& args); + static void AppendSwitch(const v8::FunctionCallbackInfo& args); + static void AppendArgument(const v8::FunctionCallbackInfo& args); #if defined(OS_MACOSX) - static v8::Handle DockBounce(const v8::Arguments& args); - static v8::Handle DockCancelBounce(const v8::Arguments& args); - static v8::Handle DockSetBadgeText(const v8::Arguments& args); - static v8::Handle DockGetBadgeText(const v8::Arguments& args); + static void DockBounce(const v8::FunctionCallbackInfo& args); + static void DockCancelBounce(const v8::FunctionCallbackInfo& args); + static void DockSetBadgeText(const v8::FunctionCallbackInfo& args); + static void DockGetBadgeText(const v8::FunctionCallbackInfo& args); #endif // defined(OS_MACOSX) DISALLOW_COPY_AND_ASSIGN(App); diff --git a/browser/api/atom_api_auto_updater.cc b/browser/api/atom_api_auto_updater.cc index 69584bd85f0a..70fa17296699 100644 --- a/browser/api/atom_api_auto_updater.cc +++ b/browser/api/atom_api_auto_updater.cc @@ -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 AutoUpdater::New(const v8::Arguments& args) { - v8::HandleScope scope; +void AutoUpdater::New(const v8::FunctionCallbackInfo& 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 AutoUpdater::SetFeedURL(const v8::Arguments& args) { +void AutoUpdater::SetFeedURL(const v8::FunctionCallbackInfo& args) { auto_updater::AutoUpdater::SetFeedURL(FromV8Value(args[0])); - return v8::Undefined(); } // static -v8::Handle AutoUpdater::SetAutomaticallyChecksForUpdates( - const v8::Arguments& args) { +void AutoUpdater::SetAutomaticallyChecksForUpdates( + const v8::FunctionCallbackInfo& args) { auto_updater::AutoUpdater::SetAutomaticallyChecksForUpdates( - args[0]->BooleanValue()); - return v8::Undefined(); + FromV8Value(args[0])); } // static -v8::Handle AutoUpdater::SetAutomaticallyDownloadsUpdates( - const v8::Arguments& args) { +void AutoUpdater::SetAutomaticallyDownloadsUpdates( + const v8::FunctionCallbackInfo& args) { auto_updater::AutoUpdater::SetAutomaticallyDownloadsUpdates( - args[0]->BooleanValue()); - return v8::Undefined(); + FromV8Value(args[0])); } // static -v8::Handle AutoUpdater::CheckForUpdates(const v8::Arguments& args) { +void AutoUpdater::CheckForUpdates( + const v8::FunctionCallbackInfo& args) { auto_updater::AutoUpdater::CheckForUpdates(); - return v8::Undefined(); } // static -v8::Handle AutoUpdater::CheckForUpdatesInBackground( - const v8::Arguments& args) { +void AutoUpdater::CheckForUpdatesInBackground( + const v8::FunctionCallbackInfo& args) { auto_updater::AutoUpdater::CheckForUpdatesInBackground(); - return v8::Undefined(); } // static -v8::Handle AutoUpdater::ContinueUpdate(const v8::Arguments& args) { +void AutoUpdater::ContinueUpdate( + const v8::FunctionCallbackInfo& args) { AutoUpdater* self = AutoUpdater::Unwrap(args.This()); self->continue_update_.Run(); - return v8::Undefined(); } // static -v8::Handle AutoUpdater::QuitAndInstall(const v8::Arguments& args) { +void AutoUpdater::QuitAndInstall( + const v8::FunctionCallbackInfo& args) { AutoUpdater* self = AutoUpdater::Unwrap(args.This()); self->quit_and_install_.Run(); - return v8::Undefined(); } // static void AutoUpdater::Initialize(v8::Handle target) { - v8::HandleScope scope; + v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); v8::Local t( v8::FunctionTemplate::New(AutoUpdater::New)); diff --git a/browser/api/atom_api_auto_updater.h b/browser/api/atom_api_auto_updater.h index 7385d9ddb6c6..b75d55212c21 100644 --- a/browser/api/atom_api_auto_updater.h +++ b/browser/api/atom_api_auto_updater.h @@ -31,19 +31,19 @@ class AutoUpdater : public EventEmitter, const base::Closure& quit_and_install) OVERRIDE; private: - static v8::Handle New(const v8::Arguments& args); + static void New(const v8::FunctionCallbackInfo& args); - static v8::Handle SetFeedURL(const v8::Arguments& args); - static v8::Handle SetAutomaticallyChecksForUpdates( - const v8::Arguments& args); - static v8::Handle SetAutomaticallyDownloadsUpdates( - const v8::Arguments& args); - static v8::Handle CheckForUpdates(const v8::Arguments& args); - static v8::Handle CheckForUpdatesInBackground( - const v8::Arguments& args); + static void SetFeedURL(const v8::FunctionCallbackInfo& args); + static void SetAutomaticallyChecksForUpdates( + const v8::FunctionCallbackInfo& args); + static void SetAutomaticallyDownloadsUpdates( + const v8::FunctionCallbackInfo& args); + static void CheckForUpdates(const v8::FunctionCallbackInfo& args); + static void CheckForUpdatesInBackground( + const v8::FunctionCallbackInfo& args); - static v8::Handle ContinueUpdate(const v8::Arguments& args); - static v8::Handle QuitAndInstall(const v8::Arguments& args); + static void ContinueUpdate(const v8::FunctionCallbackInfo& args); + static void QuitAndInstall(const v8::FunctionCallbackInfo& args); base::Closure continue_update_; base::Closure quit_and_install_; diff --git a/browser/api/atom_api_browser_ipc.cc b/browser/api/atom_api_browser_ipc.cc index 39feb5658143..c82bc670a3c7 100644 --- a/browser/api/atom_api_browser_ipc.cc +++ b/browser/api/atom_api_browser_ipc.cc @@ -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 BrowserIPC::Send(const v8::Arguments& args) { - v8::HandleScope scope; - +void BrowserIPC::Send(const v8::FunctionCallbackInfo& args) { string16 channel; int process_id, routing_id; scoped_ptr arguments; @@ -34,17 +31,15 @@ v8::Handle 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(arguments.get()))); - - return v8::Undefined(); + *static_cast(arguments.get())))); } // static void BrowserIPC::Initialize(v8::Handle target) { - node::SetMethod(target, "send", Send); + NODE_SET_METHOD(target, "send", Send); } } // namespace api diff --git a/browser/api/atom_api_browser_ipc.h b/browser/api/atom_api_browser_ipc.h index 670a84e582ae..93f0ba79d419 100644 --- a/browser/api/atom_api_browser_ipc.h +++ b/browser/api/atom_api_browser_ipc.h @@ -17,7 +17,7 @@ class BrowserIPC { static void Initialize(v8::Handle target); private: - static v8::Handle Send(const v8::Arguments& args); + static void Send(const v8::FunctionCallbackInfo& args); DISALLOW_IMPLICIT_CONSTRUCTORS(BrowserIPC); }; diff --git a/browser/api/atom_api_dialog.cc b/browser/api/atom_api_dialog.cc index bc6d70c7e222..a0b9fcf281c5 100644 --- a/browser/api/atom_api_dialog.cc +++ b/browser/api/atom_api_dialog.cc @@ -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 -void CallV8Function(v8::Persistent callback, T arg) { - DCHECK(!callback.IsEmpty()); - - v8::HandleScope scope; +void CallV8Function(const RefCountedV8Function& callback, T arg) { v8::Handle value = ToV8Value(arg); - callback->Call(callback, 1, &value); - callback.Dispose(node_isolate); + callback->NewHandle(node_isolate)->Call( + v8::Context::GetCurrent()->Global(), 1, &value); } template -void CallV8Function2(v8::Persistent callback, - bool result, - T arg) { +void CallV8Function2(const RefCountedV8Function& callback, bool result, T arg) { if (result) return CallV8Function(callback, arg); else @@ -40,7 +33,7 @@ void CallV8Function2(v8::Persistent callback, } void Initialize(v8::Handle 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 target) { } // namespace -v8::Handle ShowMessageBox(const v8::Arguments& args) { - v8::HandleScope scope; - +void ShowMessageBox(const v8::FunctionCallbackInfo& args) { int type; std::vector buttons; std::string title, message, detail; @@ -68,9 +59,9 @@ v8::Handle ShowMessageBox(const v8::Arguments& args) { title, message, detail); - return scope.Close(v8::Integer::New(chosen)); + args.GetReturnValue().Set(chosen); } else { - v8::Persistent callback = FromV8Value(args[6]); + RefCountedV8Function callback = FromV8Value(args[6]); atom::ShowMessageBox( native_window, (MessageBoxType)type, @@ -79,13 +70,10 @@ v8::Handle ShowMessageBox(const v8::Arguments& args) { message, detail, base::Bind(&CallV8Function, callback)); - return v8::Undefined(); } } -v8::Handle ShowOpenDialog(const v8::Arguments& args) { - v8::HandleScope scope; - +void ShowOpenDialog(const v8::FunctionCallbackInfo& args) { std::string title; base::FilePath default_path; int properties; @@ -101,15 +89,15 @@ v8::Handle ShowOpenDialog(const v8::Arguments& args) { default_path, properties, &paths)) - return v8::Undefined(); + return; v8::Handle 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 callback = FromV8Value(args[4]); + RefCountedV8Function callback = FromV8Value(args[4]); file_dialog::ShowOpenDialog( native_window, title, @@ -117,13 +105,10 @@ v8::Handle ShowOpenDialog(const v8::Arguments& args) { properties, base::Bind(&CallV8Function2&>, callback)); - return v8::Undefined(); } } -v8::Handle ShowSaveDialog(const v8::Arguments& args) { - v8::HandleScope scope; - +void ShowSaveDialog(const v8::FunctionCallbackInfo& args) { std::string title; base::FilePath default_path; if (!FromV8Arguments(args, &title, &default_path)) @@ -133,21 +118,18 @@ v8::Handle 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 callback = FromV8Value(args[3]); + RefCountedV8Function callback = FromV8Value(args[3]); file_dialog::ShowSaveDialog( native_window, title, default_path, base::Bind(&CallV8Function2, callback)); - return v8::Undefined(); } } diff --git a/browser/api/atom_api_dialog.h b/browser/api/atom_api_dialog.h index d0f77d2784cf..86c718dae094 100644 --- a/browser/api/atom_api_dialog.h +++ b/browser/api/atom_api_dialog.h @@ -11,9 +11,9 @@ namespace atom { namespace api { -v8::Handle ShowMessageBox(const v8::Arguments& args); -v8::Handle ShowOpenDialog(const v8::Arguments& args); -v8::Handle ShowSaveDialog(const v8::Arguments& args); +void ShowMessageBox(const v8::FunctionCallbackInfo& args); +void ShowOpenDialog(const v8::FunctionCallbackInfo& args); +void ShowSaveDialog(const v8::FunctionCallbackInfo& args); } // namespace api diff --git a/browser/api/atom_api_event.cc b/browser/api/atom_api_event.cc index c2afd3265144..155fdbbebd26 100644 --- a/browser/api/atom_api_event.cc +++ b/browser/api/atom_api_event.cc @@ -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 Event::constructor_template_; +ScopedPersistent Event::constructor_template_; Event::Event() : sender_(NULL), @@ -29,24 +28,20 @@ Event::~Event() { // static v8::Handle Event::CreateV8Object() { - v8::HandleScope scope; - if (constructor_template_.IsEmpty()) { v8::Local t = v8::FunctionTemplate::New(New); - constructor_template_ = v8::Persistent::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_event = - constructor_template_->GetFunction()->NewInstance(0, NULL); - - return scope.Close(v8_event); + v8::Handle 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 Event::New(const v8::Arguments& args) { +void Event::New(const v8::FunctionCallbackInfo& args) { Event* event = new Event; event->Wrap(args.This()); - - return args.This(); } // static -v8::Handle Event::PreventDefault(const v8::Arguments& args) { +void Event::PreventDefault(const v8::FunctionCallbackInfo& args) { Event* event = Unwrap(args.This()); if (event == NULL) return node::ThrowError("Event is already destroyed"); event->prevent_default_ = true; - - return v8::Undefined(); } // static -v8::Handle Event::SendReply(const v8::Arguments& args) { +void Event::SendReply(const v8::FunctionCallbackInfo& args) { Event* event = Unwrap(args.This()); if (event == NULL) return node::ThrowError("Event is already destroyed"); @@ -97,14 +88,11 @@ v8::Handle Event::SendReply(const v8::Arguments& args) { event->sender_->Send(event->message_); delete event; - - return v8::Undefined(); } // static -v8::Handle Event::Destroy(const v8::Arguments& args) { +void Event::Destroy(const v8::FunctionCallbackInfo& args) { delete Unwrap(args.This()); - return v8::Undefined(); } } // namespace api diff --git a/browser/api/atom_api_event.h b/browser/api/atom_api_event.h index 3b1359e135da..1a46f052c7cd 100644 --- a/browser/api/atom_api_event.h +++ b/browser/api/atom_api_event.h @@ -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& 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 New(const v8::Arguments& args); + static void New(const v8::FunctionCallbackInfo& args); - static v8::Handle PreventDefault(const v8::Arguments& args); - static v8::Handle SendReply(const v8::Arguments& args); - static v8::Handle Destroy(const v8::Arguments& args); + static void PreventDefault(const v8::FunctionCallbackInfo& args); + static void SendReply(const v8::FunctionCallbackInfo& args); + static void Destroy(const v8::FunctionCallbackInfo& args); - static v8::Persistent constructor_template_; + static ScopedPersistent constructor_template_; // Replyer for the synchronous messages. NativeWindow* sender_; diff --git a/browser/api/atom_api_event_emitter.cc b/browser/api/atom_api_event_emitter.cc index 3196546adf1e..4a1bddb98b4e 100644 --- a/browser/api/atom_api_event_emitter.cc +++ b/browser/api/atom_api_event_emitter.cc @@ -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 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 context = v8::Context::GetCurrent(); scoped_ptr converter(new V8ValueConverterImpl); diff --git a/browser/api/atom_api_event_emitter.h b/browser/api/atom_api_event_emitter.h index dd2292238601..959d4b7f9b17 100644 --- a/browser/api/atom_api_event_emitter.h +++ b/browser/api/atom_api_event_emitter.h @@ -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 handle() const { + return const_cast(this)->handle(); + } + protected: explicit EventEmitter(v8::Handle wrapper); diff --git a/browser/api/atom_api_menu.cc b/browser/api/atom_api_menu.cc index 89c64ea1e48c..814cdc75f413 100644 --- a/browser/api/atom_api_menu.cc +++ b/browser/api/atom_api_menu.cc @@ -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(args.This()); \ @@ -23,7 +24,7 @@ v8::Handle CallDelegate(v8::Handle default_value, v8::Handle menu, const char* method, int command_id) { - v8::HandleScope scope; + v8::HandleScope handle_scope(node_isolate); v8::Handle delegate = menu->Get(v8::String::New("delegate")); if (!delegate->IsObject()) @@ -36,7 +37,7 @@ v8::Handle CallDelegate(v8::Handle default_value, v8::Handle 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 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 Menu::New(const v8::Arguments& args) { - v8::HandleScope scope; +void Menu::New(const v8::FunctionCallbackInfo& 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 Menu::InsertItem(const v8::Arguments& args) { +void Menu::InsertItem(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; int index, command_id; @@ -143,12 +142,10 @@ v8::Handle 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 Menu::InsertCheckItem(const v8::Arguments& args) { +void Menu::InsertCheckItem(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; int index, command_id; @@ -160,12 +157,10 @@ v8::Handle 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 Menu::InsertRadioItem(const v8::Arguments& args) { +void Menu::InsertRadioItem(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; int index, command_id, group_id; @@ -177,12 +172,10 @@ v8::Handle 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 Menu::InsertSeparator(const v8::Arguments& args) { +void Menu::InsertSeparator(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; int index; @@ -193,12 +186,10 @@ v8::Handle 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 Menu::InsertSubMenu(const v8::Arguments& args) { +void Menu::InsertSubMenu(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; int index, command_id; @@ -215,12 +206,10 @@ v8::Handle Menu::InsertSubMenu(const v8::Arguments& args) { else self->model_->InsertSubMenuAt( index, command_id, label, submenu->model_.get()); - - return v8::Undefined(); } // static -v8::Handle Menu::SetIcon(const v8::Arguments& args) { +void Menu::SetIcon(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; int index; @@ -229,12 +218,10 @@ v8::Handle 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 Menu::SetSublabel(const v8::Arguments& args) { +void Menu::SetSublabel(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; int index; @@ -243,74 +230,71 @@ v8::Handle Menu::SetSublabel(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->model_->SetSublabel(index, label); - - return v8::Undefined(); } // static -v8::Handle Menu::Clear(const v8::Arguments& args) { +void Menu::Clear(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; - self->model_->Clear(); - - return v8::Undefined(); } // static -v8::Handle Menu::GetIndexOfCommandId(const v8::Arguments& args) { +void Menu::GetIndexOfCommandId(const v8::FunctionCallbackInfo& 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 Menu::GetItemCount(const v8::Arguments& args) { +void Menu::GetItemCount(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; - return v8::Integer::New(self->model_->GetItemCount()); + args.GetReturnValue().Set(self->model_->GetItemCount()); } // static -v8::Handle Menu::GetCommandIdAt(const v8::Arguments& args) { +void Menu::GetCommandIdAt(const v8::FunctionCallbackInfo& 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 Menu::GetLabelAt(const v8::Arguments& args) { +void Menu::GetLabelAt(const v8::FunctionCallbackInfo& 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 Menu::GetSublabelAt(const v8::Arguments& args) { +void Menu::GetSublabelAt(const v8::FunctionCallbackInfo& 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 Menu::IsItemCheckedAt(const v8::Arguments& args) { +void Menu::IsItemCheckedAt(const v8::FunctionCallbackInfo& 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 Menu::IsEnabledAt(const v8::Arguments& args) { +void Menu::IsEnabledAt(const v8::FunctionCallbackInfo& 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 Menu::IsVisibleAt(const v8::Arguments& args) { +void Menu::IsVisibleAt(const v8::FunctionCallbackInfo& 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 Menu::Popup(const v8::Arguments& args) { +void Menu::Popup(const v8::FunctionCallbackInfo& args) { UNWRAP_MEMNU_AND_CHECK; atom::NativeWindow* window; @@ -318,12 +302,11 @@ v8::Handle Menu::Popup(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->Popup(window); - return v8::Undefined(); } // static void Menu::Initialize(v8::Handle target) { - v8::HandleScope scope; + v8::HandleScope handle_scope(node_isolate); v8::Local t(v8::FunctionTemplate::New(Menu::New)); t->InstanceTemplate()->SetInternalFieldCount(1); diff --git a/browser/api/atom_api_menu.h b/browser/api/atom_api_menu.h index d0a7b1fb29f1..0e1d1a5c2483 100644 --- a/browser/api/atom_api_menu.h +++ b/browser/api/atom_api_menu.h @@ -44,36 +44,37 @@ class Menu : public EventEmitter, scoped_ptr model_; private: - static v8::Handle New(const v8::Arguments& args); + static void New(const v8::FunctionCallbackInfo& args); - static v8::Handle InsertItem(const v8::Arguments& args); - static v8::Handle InsertCheckItem(const v8::Arguments& args); - static v8::Handle InsertRadioItem(const v8::Arguments& args); - static v8::Handle InsertSeparator(const v8::Arguments& args); - static v8::Handle InsertSubMenu(const v8::Arguments& args); + static void InsertItem(const v8::FunctionCallbackInfo& args); + static void InsertCheckItem(const v8::FunctionCallbackInfo& args); + static void InsertRadioItem(const v8::FunctionCallbackInfo& args); + static void InsertSeparator(const v8::FunctionCallbackInfo& args); + static void InsertSubMenu(const v8::FunctionCallbackInfo& args); - static v8::Handle SetIcon(const v8::Arguments& args); - static v8::Handle SetSublabel(const v8::Arguments& args); + static void SetIcon(const v8::FunctionCallbackInfo& args); + static void SetSublabel(const v8::FunctionCallbackInfo& args); - static v8::Handle Clear(const v8::Arguments& args); + static void Clear(const v8::FunctionCallbackInfo& args); - static v8::Handle GetIndexOfCommandId(const v8::Arguments& args); - static v8::Handle GetItemCount(const v8::Arguments& args); - static v8::Handle GetCommandIdAt(const v8::Arguments& args); - static v8::Handle GetLabelAt(const v8::Arguments& args); - static v8::Handle GetSublabelAt(const v8::Arguments& args); - static v8::Handle IsItemCheckedAt(const v8::Arguments& args); - static v8::Handle IsEnabledAt(const v8::Arguments& args); - static v8::Handle IsVisibleAt(const v8::Arguments& args); + static void GetIndexOfCommandId(const v8::FunctionCallbackInfo& args); + static void GetItemCount(const v8::FunctionCallbackInfo& args); + static void GetCommandIdAt(const v8::FunctionCallbackInfo& args); + static void GetLabelAt(const v8::FunctionCallbackInfo& args); + static void GetSublabelAt(const v8::FunctionCallbackInfo& args); + static void IsItemCheckedAt(const v8::FunctionCallbackInfo& args); + static void IsEnabledAt(const v8::FunctionCallbackInfo& args); + static void IsVisibleAt(const v8::FunctionCallbackInfo& args); - static v8::Handle Popup(const v8::Arguments& args); + static void Popup(const v8::FunctionCallbackInfo& args); #if defined(OS_WIN) - static v8::Handle AttachToWindow(const v8::Arguments& args); + static void AttachToWindow(const v8::FunctionCallbackInfo& args); #elif defined(OS_MACOSX) - static v8::Handle SetApplicationMenu(const v8::Arguments& args); - static v8::Handle SendActionToFirstResponder( - const v8::Arguments& args); + static void SetApplicationMenu( + const v8::FunctionCallbackInfo& args); + static void SendActionToFirstResponder( + const v8::FunctionCallbackInfo& args); #endif DISALLOW_COPY_AND_ASSIGN(Menu); diff --git a/browser/api/atom_api_menu_mac.h b/browser/api/atom_api_menu_mac.h index 5f88c9b0e8fa..46c133e66f2a 100644 --- a/browser/api/atom_api_menu_mac.h +++ b/browser/api/atom_api_menu_mac.h @@ -21,7 +21,7 @@ class MenuMac : public Menu { protected: virtual void Popup(NativeWindow* window) OVERRIDE; - scoped_nsobject menu_controller_; + base::scoped_nsobject menu_controller_; private: friend class Menu; diff --git a/browser/api/atom_api_menu_mac.mm b/browser/api/atom_api_menu_mac.mm index a312089b95ec..432ddb52e19f 100644 --- a/browser/api/atom_api_menu_mac.mm +++ b/browser/api/atom_api_menu_mac.mm @@ -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 menu_controller( + base::scoped_nsobject 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 Menu::SetApplicationMenu(const v8::Arguments& args) { - v8::HandleScope scope; +void Menu::SetApplicationMenu(const v8::FunctionCallbackInfo& args) { + v8::HandleScope handle_scope(args.GetIsolate()); if (!args[0]->IsObject()) return node::ThrowTypeError("Bad argument"); @@ -81,28 +83,24 @@ v8::Handle Menu::SetApplicationMenu(const v8::Arguments& args) { if (!menu) return node::ThrowError("Menu is destroyed"); - scoped_nsobject menu_controller( + base::scoped_nsobject 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 Menu::SendActionToFirstResponder( - const v8::Arguments& args) { - v8::HandleScope scope; +void Menu::SendActionToFirstResponder( + const v8::FunctionCallbackInfo& 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 diff --git a/browser/api/atom_api_menu_win.cc b/browser/api/atom_api_menu_win.cc index 3e41ab18d1f6..e6bce18c2103 100644 --- a/browser/api/atom_api_menu_win.cc +++ b/browser/api/atom_api_menu_win.cc @@ -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 Menu::AttachToWindow(const v8::Arguments& args) { - v8::HandleScope scope; +void Menu::AttachToWindow(const v8::FunctionCallbackInfo& args) { + v8::HandleScope handle_scope(args.GetIsolate()); Menu* self = ObjectWrap::Unwrap(args.This()); if (self == NULL) diff --git a/browser/api/atom_api_power_monitor.cc b/browser/api/atom_api_power_monitor.cc index 21b8c606edb8..df1ac1f27e23 100644 --- a/browser/api/atom_api_power_monitor.cc +++ b/browser/api/atom_api_power_monitor.cc @@ -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 PowerMonitor::New(const v8::Arguments& args) { - v8::HandleScope scope; +void PowerMonitor::New(const v8::FunctionCallbackInfo& 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 target) { - v8::HandleScope scope; + v8::HandleScope handle_scope(node_isolate); + +#if defined(OS_MACOSX) + base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); +#endif v8::Local t = v8::FunctionTemplate::New( PowerMonitor::New); diff --git a/browser/api/atom_api_power_monitor.h b/browser/api/atom_api_power_monitor.h index a393e75b61ff..88c68168b853 100644 --- a/browser/api/atom_api_power_monitor.h +++ b/browser/api/atom_api_power_monitor.h @@ -29,7 +29,7 @@ class PowerMonitor : public EventEmitter, virtual void OnResume() OVERRIDE; private: - static v8::Handle New(const v8::Arguments& args); + static void New(const v8::FunctionCallbackInfo& args); DISALLOW_COPY_AND_ASSIGN(PowerMonitor); }; diff --git a/browser/api/atom_api_protocol.cc b/browser/api/atom_api_protocol.cc index a1ae29223e47..f7e49a23b2f2 100644 --- a/browser/api/atom_api_protocol.cc +++ b/browser/api/atom_api_protocol.cc @@ -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 g_protocol_object; +ScopedPersistent g_protocol_object; // Registered protocol handlers. -typedef std::map> HandlersMap; +typedef std::map 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 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 ConvertURLRequestToV8Object( const net::URLRequest* request) { v8::Local 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 argv[] = { ConvertURLRequestToV8Object(request()), }; - v8::Handle result = g_handlers[request()->url().scheme()]->Call( - v8::Context::GetCurrent()->Global(), arraysize(argv), argv); + RefCountedV8Function callback = g_handlers[request()->url().scheme()]; + v8::Handle 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 Protocol::RegisterProtocol(const v8::Arguments& args) { +void Protocol::RegisterProtocol( + const v8::FunctionCallbackInfo& args) { std::string scheme; - v8::Persistent callback; + RefCountedV8Function callback; if (!FromV8Arguments(args, &scheme, &callback)) return node::ThrowTypeError("Bad argument"); @@ -199,12 +200,11 @@ v8::Handle Protocol::RegisterProtocol(const v8::Arguments& args) { content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&RegisterProtocolInIO, scheme)); - - return v8::Undefined(); } // static -v8::Handle Protocol::UnregisterProtocol(const v8::Arguments& args) { +void Protocol::UnregisterProtocol( + const v8::FunctionCallbackInfo& args) { std::string scheme; if (!FromV8Arguments(args, &scheme)) return node::ThrowTypeError("Bad argument"); @@ -221,19 +221,20 @@ v8::Handle Protocol::UnregisterProtocol(const v8::Arguments& args) { content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&UnregisterProtocolInIO, scheme)); - - return v8::Undefined(); } // static -v8::Handle Protocol::IsHandledProtocol(const v8::Arguments& args) { - return ToV8Value(net::URLRequest::IsHandledProtocol(FromV8Value(args[0]))); +void Protocol::IsHandledProtocol( + const v8::FunctionCallbackInfo& args) { + std::string scheme = FromV8Value(args[0]); + args.GetReturnValue().Set(net::URLRequest::IsHandledProtocol(scheme)); } // static -v8::Handle Protocol::InterceptProtocol(const v8::Arguments& args) { +void Protocol::InterceptProtocol( + const v8::FunctionCallbackInfo& args) { std::string scheme; - v8::Persistent callback; + RefCountedV8Function callback; if (!FromV8Arguments(args, &scheme, &callback)) return node::ThrowTypeError("Bad argument"); @@ -252,11 +253,11 @@ v8::Handle Protocol::InterceptProtocol(const v8::Arguments& args) { content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&InterceptProtocolInIO, scheme)); - return v8::Undefined(); } // static -v8::Handle Protocol::UninterceptProtocol(const v8::Arguments& args) { +void Protocol::UninterceptProtocol( + const v8::FunctionCallbackInfo& args) { std::string scheme; if (!FromV8Arguments(args, &scheme)) return node::ThrowTypeError("Bad argument"); @@ -274,7 +275,6 @@ v8::Handle 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 target) { // Remember the protocol object, used for emitting event later. - g_protocol_object = v8::Persistent::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 diff --git a/browser/api/atom_api_protocol.h b/browser/api/atom_api_protocol.h index 6e38b5014695..1397591038b6 100644 --- a/browser/api/atom_api_protocol.h +++ b/browser/api/atom_api_protocol.h @@ -20,12 +20,12 @@ class Protocol { static void Initialize(v8::Handle target); private: - static v8::Handle RegisterProtocol(const v8::Arguments& args); - static v8::Handle UnregisterProtocol(const v8::Arguments& args); - static v8::Handle IsHandledProtocol(const v8::Arguments& args); + static void RegisterProtocol(const v8::FunctionCallbackInfo& args); + static void UnregisterProtocol(const v8::FunctionCallbackInfo& args); + static void IsHandledProtocol(const v8::FunctionCallbackInfo& args); - static v8::Handle InterceptProtocol(const v8::Arguments& args); - static v8::Handle UninterceptProtocol(const v8::Arguments& args); + static void InterceptProtocol(const v8::FunctionCallbackInfo& args); + static void UninterceptProtocol(const v8::FunctionCallbackInfo& args); static void RegisterProtocolInIO(const std::string& scheme); static void UnregisterProtocolInIO(const std::string& scheme); diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 0dddad319bd2..c914d0f97b92 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -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 callback, +void Window::OnCapturePageDone(const RefCountedV8Function& callback, const std::vector& 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 buffer = node::Buffer::New( reinterpret_cast(data.data()), data.size()); - - v8::Handle 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 Window::New(const v8::Arguments& args) { - v8::HandleScope scope; +void Window::New(const v8::FunctionCallbackInfo& args) { + v8::HandleScope handle_scope(args.GetIsolate()); if (!args.IsConstructCall()) return node::ThrowError("Require constructor call"); @@ -119,12 +118,10 @@ v8::Handle 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 Window::Destroy(const v8::Arguments& args) { +void Window::Destroy(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; base::ProcessHandle handle = self->window_->GetRenderProcessHandle(); @@ -135,96 +132,70 @@ v8::Handle 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 Window::Close(const v8::Arguments& args) { +void Window::Close(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Close(); - - return v8::Undefined(); } // static -v8::Handle Window::Focus(const v8::Arguments& args) { +void Window::Focus(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Focus(args[0]->IsBoolean() ? args[0]->BooleanValue(): true); - - return v8::Undefined(); } // static -v8::Handle Window::IsFocused(const v8::Arguments& args) { +void Window::IsFocused(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - return ToV8Value(self->window_->IsFocused()); + args.GetReturnValue().Set(self->window_->IsFocused()); } // static -v8::Handle Window::Show(const v8::Arguments& args) { +void Window::Show(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Show(); - - return v8::Undefined(); } // static -v8::Handle Window::Hide(const v8::Arguments& args) { +void Window::Hide(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Hide(); - - return v8::Undefined(); } // static -v8::Handle Window::IsVisible(const v8::Arguments& args) { +void Window::IsVisible(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - return ToV8Value(self->window_->IsVisible()); + return args.GetReturnValue().Set(self->window_->IsVisible()); } // static -v8::Handle Window::Maximize(const v8::Arguments& args) { +void Window::Maximize(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Maximize(); - - return v8::Undefined(); } // static -v8::Handle Window::Unmaximize(const v8::Arguments& args) { +void Window::Unmaximize(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Unmaximize(); - - return v8::Undefined(); } // static -v8::Handle Window::Minimize(const v8::Arguments& args) { +void Window::Minimize(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Minimize(); - - return v8::Undefined(); } // static -v8::Handle Window::Restore(const v8::Arguments& args) { +void Window::Restore(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Restore(); - - return v8::Undefined(); } // static -v8::Handle Window::SetFullscreen(const v8::Arguments& args) { +void Window::SetFullscreen(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; bool fs; @@ -232,18 +203,16 @@ v8::Handle Window::SetFullscreen(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->SetFullscreen(fs); - return v8::Undefined(); } // static -v8::Handle Window::IsFullscreen(const v8::Arguments& args) { +void Window::IsFullscreen(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->IsFullscreen()); + args.GetReturnValue().Set(self->window_->IsFullscreen()); } // static -v8::Handle Window::SetSize(const v8::Arguments& args) { +void Window::SetSize(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; int width, height; @@ -251,11 +220,10 @@ v8::Handle Window::SetSize(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->SetSize(gfx::Size(width, height)); - return v8::Undefined(); } // static -v8::Handle Window::GetSize(const v8::Arguments& args) { +void Window::GetSize(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Size size = self->window_->GetSize(); @@ -263,11 +231,11 @@ v8::Handle 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 Window::SetMinimumSize(const v8::Arguments& args) { +void Window::SetMinimumSize(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; int width, height; @@ -275,11 +243,10 @@ v8::Handle Window::SetMinimumSize(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->SetMinimumSize(gfx::Size(width, height)); - return v8::Undefined(); } // static -v8::Handle Window::GetMinimumSize(const v8::Arguments& args) { +void Window::GetMinimumSize(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Size size = self->window_->GetMinimumSize(); @@ -287,24 +254,22 @@ v8::Handle 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 Window::SetMaximumSize(const v8::Arguments& args) { +void Window::SetMaximumSize(const v8::FunctionCallbackInfo& 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 Window::GetMaximumSize(const v8::Arguments& args) { +void Window::GetMaximumSize(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Size size = self->window_->GetMaximumSize(); @@ -312,11 +277,11 @@ v8::Handle 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 Window::SetResizable(const v8::Arguments& args) { +void Window::SetResizable(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; bool resizable; @@ -324,18 +289,16 @@ v8::Handle Window::SetResizable(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->SetResizable(resizable); - return v8::Undefined(); } // static -v8::Handle Window::IsResizable(const v8::Arguments& args) { +void Window::IsResizable(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->IsResizable()); + args.GetReturnValue().Set(self->window_->IsResizable()); } // static -v8::Handle Window::SetAlwaysOnTop(const v8::Arguments& args) { +void Window::SetAlwaysOnTop(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; bool top; @@ -343,27 +306,22 @@ v8::Handle Window::SetAlwaysOnTop(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->SetAlwaysOnTop(top); - return v8::Undefined(); } // static -v8::Handle Window::IsAlwaysOnTop(const v8::Arguments& args) { +void Window::IsAlwaysOnTop(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->IsAlwaysOnTop()); + args.GetReturnValue().Set(self->window_->IsAlwaysOnTop()); } // static -v8::Handle Window::Center(const v8::Arguments& args) { +void Window::Center(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->Center(); - - return v8::Undefined(); } // static -v8::Handle Window::SetPosition(const v8::Arguments& args) { +void Window::SetPosition(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; int x, y; @@ -371,11 +329,10 @@ v8::Handle Window::SetPosition(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->SetPosition(gfx::Point(x, y)); - return v8::Undefined(); } // static -v8::Handle Window::GetPosition(const v8::Arguments& args) { +void Window::GetPosition(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Point pos = self->window_->GetPosition(); @@ -383,11 +340,11 @@ v8::Handle 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 Window::SetTitle(const v8::Arguments& args) { +void Window::SetTitle(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; std::string title; @@ -395,27 +352,23 @@ v8::Handle Window::SetTitle(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->SetTitle(title); - return v8::Undefined(); } // static -v8::Handle Window::GetTitle(const v8::Arguments& args) { +void Window::GetTitle(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - return ToV8Value(self->window_->GetTitle()); + args.GetReturnValue().Set(ToV8Value(self->window_->GetTitle())); } // static -v8::Handle Window::FlashFrame(const v8::Arguments& args) { +void Window::FlashFrame(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->FlashFrame( args[0]->IsBoolean() ? args[0]->BooleanValue(): true); - - return v8::Undefined(); } // static -v8::Handle Window::SetKiosk(const v8::Arguments& args) { +void Window::SetKiosk(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; bool kiosk; @@ -423,42 +376,34 @@ v8::Handle Window::SetKiosk(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->SetKiosk(kiosk); - return v8::Undefined(); } // static -v8::Handle Window::IsKiosk(const v8::Arguments& args) { +void Window::IsKiosk(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->IsKiosk()); + args.GetReturnValue().Set(self->window_->IsKiosk()); } // static -v8::Handle Window::OpenDevTools(const v8::Arguments& args) { +void Window::OpenDevTools(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->OpenDevTools(); - - return v8::Undefined(); } // static -v8::Handle Window::CloseDevTools(const v8::Arguments& args) { +void Window::CloseDevTools(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->CloseDevTools(); - - return v8::Undefined(); } // static -v8::Handle Window::IsDevToolsOpened(const v8::Arguments& args) { +void Window::IsDevToolsOpened(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - return ToV8Value(self->window_->IsDevToolsOpened()); + args.GetReturnValue().Set(self->window_->IsDevToolsOpened()); } // static -v8::Handle Window::InspectElement(const v8::Arguments& args) { +void Window::InspectElement(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; int x, y; @@ -466,39 +411,32 @@ v8::Handle Window::InspectElement(const v8::Arguments& args) { return node::ThrowTypeError("Bad argument"); self->window_->InspectElement(x, y); - return v8::Undefined(); } // static -v8::Handle Window::FocusOnWebView(const v8::Arguments& args) { +void Window::FocusOnWebView(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->FocusOnWebView(); - - return v8::Undefined(); } // static -v8::Handle Window::BlurWebView(const v8::Arguments& args) { +void Window::BlurWebView(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->BlurWebView(); - - return v8::Undefined(); } // static -v8::Handle Window::IsWebViewFocused(const v8::Arguments& args) { +void Window::IsWebViewFocused(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - return ToV8Value(self->window_->IsWebViewFocused()); + args.GetReturnValue().Set(self->window_->IsWebViewFocused()); } // static -v8::Handle Window::CapturePage(const v8::Arguments& args) { +void Window::CapturePage(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; gfx::Rect rect; - v8::Persistent callback; + RefCountedV8Function callback; if (!FromV8Arguments(args, &rect, &callback) && !FromV8Arguments(args, &callback)) return node::ThrowTypeError("Bad argument"); @@ -506,64 +444,56 @@ v8::Handle Window::CapturePage(const v8::Arguments& args) { self->window_->CapturePage(rect, base::Bind(&Window::OnCapturePageDone, base::Unretained(self), callback)); - - return v8::Undefined(); } // static -v8::Handle Window::GetPageTitle(const v8::Arguments& args) { +void Window::GetPageTitle(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->GetWebContents()->GetTitle()); + args.GetReturnValue().Set(ToV8Value( + self->window_->GetWebContents()->GetTitle())); } // static -v8::Handle Window::IsLoading(const v8::Arguments& args) { +void Window::IsLoading(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->GetWebContents()->IsLoading()); + args.GetReturnValue().Set(self->window_->GetWebContents()->IsLoading()); } // static -v8::Handle Window::IsWaitingForResponse(const v8::Arguments& args) { +void Window::IsWaitingForResponse(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->GetWebContents()->IsWaitingForResponse()); + args.GetReturnValue().Set( + self->window_->GetWebContents()->IsWaitingForResponse()); } // static -v8::Handle Window::Stop(const v8::Arguments& args) { +void Window::Stop(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->GetWebContents()->Stop(); - - return v8::Undefined(); } // static -v8::Handle Window::GetRoutingID(const v8::Arguments& args) { +void Window::GetRoutingID(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->GetWebContents()->GetRoutingID()); + args.GetReturnValue().Set(self->window_->GetWebContents()->GetRoutingID()); } // static -v8::Handle Window::GetProcessID(const v8::Arguments& args) { +void Window::GetProcessID(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - return ToV8Value( + args.GetReturnValue().Set( self->window_->GetWebContents()->GetRenderProcessHost()->GetID()); } // static -v8::Handle Window::IsCrashed(const v8::Arguments& args) { +void Window::IsCrashed(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - - return ToV8Value(self->window_->GetWebContents()->IsCrashed()); + args.GetReturnValue().Set(self->window_->GetWebContents()->IsCrashed()); } // static -v8::Handle Window::LoadURL(const v8::Arguments& args) { +void Window::LoadURL(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; GURL url; @@ -577,12 +507,10 @@ v8::Handle 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 Window::GetURL(const v8::Arguments& args) { +void Window::GetURL(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = @@ -591,31 +519,31 @@ v8::Handle Window::GetURL(const v8::Arguments& args) { if (controller.GetActiveEntry()) url = controller.GetActiveEntry()->GetVirtualURL(); - return ToV8Value(url); + args.GetReturnValue().Set(ToV8Value(url)); } // static -v8::Handle Window::CanGoBack(const v8::Arguments& args) { +void Window::CanGoBack(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = self->window_->GetWebContents()->GetController(); - return ToV8Value(controller.CanGoBack()); + args.GetReturnValue().Set(controller.CanGoBack()); } // static -v8::Handle Window::CanGoForward(const v8::Arguments& args) { +void Window::CanGoForward(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = self->window_->GetWebContents()->GetController(); - return ToV8Value(controller.CanGoForward()); + args.GetReturnValue().Set(controller.CanGoForward()); } // static -v8::Handle Window::CanGoToOffset(const v8::Arguments& args) { +void Window::CanGoToOffset(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; int offset; @@ -625,33 +553,29 @@ v8::Handle 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 Window::GoBack(const v8::Arguments& args) { +void Window::GoBack(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = self->window_->GetWebContents()->GetController(); controller.GoBack(); - - return v8::Undefined(); } // static -v8::Handle Window::GoForward(const v8::Arguments& args) { +void Window::GoForward(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; NavigationController& controller = self->window_->GetWebContents()->GetController(); controller.GoForward(); - - return v8::Undefined(); } // static -v8::Handle Window::GoToIndex(const v8::Arguments& args) { +void Window::GoToIndex(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; int index; @@ -661,12 +585,10 @@ v8::Handle Window::GoToIndex(const v8::Arguments& args) { NavigationController& controller = self->window_->GetWebContents()->GetController(); controller.GoToIndex(index); - - return v8::Undefined(); } // static -v8::Handle Window::GoToOffset(const v8::Arguments& args) { +void Window::GoToOffset(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; int offset; @@ -676,36 +598,30 @@ v8::Handle Window::GoToOffset(const v8::Arguments& args) { NavigationController& controller = self->window_->GetWebContents()->GetController(); controller.GoToOffset(offset); - - return v8::Undefined(); } // static -v8::Handle Window::Reload(const v8::Arguments& args) { +void Window::Reload(const v8::FunctionCallbackInfo& 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 Window::ReloadIgnoringCache(const v8::Arguments& args) { +void Window::ReloadIgnoringCache(const v8::FunctionCallbackInfo& 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 target) { - v8::HandleScope scope; + v8::HandleScope handle_scope(node_isolate); v8::Local t = v8::FunctionTemplate::New(Window::New); t->InstanceTemplate()->SetInternalFieldCount(1); diff --git a/browser/api/atom_api_window.h b/browser/api/atom_api_window.h index f410615d68ee..e1ac0675f344 100644 --- a/browser/api/atom_api_window.h +++ b/browser/api/atom_api_window.h @@ -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 New(const v8::Arguments& args); - static v8::Handle Destroy(const v8::Arguments& args); + static void New(const v8::FunctionCallbackInfo& args); + static void Destroy(const v8::FunctionCallbackInfo& args); // APIs for NativeWindow. - static v8::Handle Close(const v8::Arguments& args); - static v8::Handle Focus(const v8::Arguments& args); - static v8::Handle IsFocused(const v8::Arguments& args); - static v8::Handle Show(const v8::Arguments& args); - static v8::Handle Hide(const v8::Arguments& args); - static v8::Handle IsVisible(const v8::Arguments& args); - static v8::Handle Maximize(const v8::Arguments& args); - static v8::Handle Unmaximize(const v8::Arguments& args); - static v8::Handle Minimize(const v8::Arguments& args); - static v8::Handle Restore(const v8::Arguments& args); - static v8::Handle SetFullscreen(const v8::Arguments& args); - static v8::Handle IsFullscreen(const v8::Arguments& args); - static v8::Handle SetSize(const v8::Arguments& args); - static v8::Handle GetSize(const v8::Arguments& args); - static v8::Handle SetMinimumSize(const v8::Arguments& args); - static v8::Handle GetMinimumSize(const v8::Arguments& args); - static v8::Handle SetMaximumSize(const v8::Arguments& args); - static v8::Handle GetMaximumSize(const v8::Arguments& args); - static v8::Handle SetResizable(const v8::Arguments& args); - static v8::Handle IsResizable(const v8::Arguments& args); - static v8::Handle SetAlwaysOnTop(const v8::Arguments& args); - static v8::Handle IsAlwaysOnTop(const v8::Arguments& args); - static v8::Handle Center(const v8::Arguments& args); - static v8::Handle SetPosition(const v8::Arguments& args); - static v8::Handle GetPosition(const v8::Arguments& args); - static v8::Handle SetTitle(const v8::Arguments& args); - static v8::Handle GetTitle(const v8::Arguments& args); - static v8::Handle FlashFrame(const v8::Arguments& args); - static v8::Handle SetKiosk(const v8::Arguments& args); - static v8::Handle IsKiosk(const v8::Arguments& args); - static v8::Handle OpenDevTools(const v8::Arguments& args); - static v8::Handle CloseDevTools(const v8::Arguments& args); - static v8::Handle IsDevToolsOpened(const v8::Arguments& args); - static v8::Handle InspectElement(const v8::Arguments& args); - static v8::Handle FocusOnWebView(const v8::Arguments& args); - static v8::Handle BlurWebView(const v8::Arguments& args); - static v8::Handle IsWebViewFocused(const v8::Arguments& args); - static v8::Handle CapturePage(const v8::Arguments& args); + static void Close(const v8::FunctionCallbackInfo& args); + static void Focus(const v8::FunctionCallbackInfo& args); + static void IsFocused(const v8::FunctionCallbackInfo& args); + static void Show(const v8::FunctionCallbackInfo& args); + static void Hide(const v8::FunctionCallbackInfo& args); + static void IsVisible(const v8::FunctionCallbackInfo& args); + static void Maximize(const v8::FunctionCallbackInfo& args); + static void Unmaximize(const v8::FunctionCallbackInfo& args); + static void Minimize(const v8::FunctionCallbackInfo& args); + static void Restore(const v8::FunctionCallbackInfo& args); + static void SetFullscreen(const v8::FunctionCallbackInfo& args); + static void IsFullscreen(const v8::FunctionCallbackInfo& args); + static void SetSize(const v8::FunctionCallbackInfo& args); + static void GetSize(const v8::FunctionCallbackInfo& args); + static void SetMinimumSize(const v8::FunctionCallbackInfo& args); + static void GetMinimumSize(const v8::FunctionCallbackInfo& args); + static void SetMaximumSize(const v8::FunctionCallbackInfo& args); + static void GetMaximumSize(const v8::FunctionCallbackInfo& args); + static void SetResizable(const v8::FunctionCallbackInfo& args); + static void IsResizable(const v8::FunctionCallbackInfo& args); + static void SetAlwaysOnTop(const v8::FunctionCallbackInfo& args); + static void IsAlwaysOnTop(const v8::FunctionCallbackInfo& args); + static void Center(const v8::FunctionCallbackInfo& args); + static void SetPosition(const v8::FunctionCallbackInfo& args); + static void GetPosition(const v8::FunctionCallbackInfo& args); + static void SetTitle(const v8::FunctionCallbackInfo& args); + static void GetTitle(const v8::FunctionCallbackInfo& args); + static void FlashFrame(const v8::FunctionCallbackInfo& args); + static void SetKiosk(const v8::FunctionCallbackInfo& args); + static void IsKiosk(const v8::FunctionCallbackInfo& args); + static void OpenDevTools(const v8::FunctionCallbackInfo& args); + static void CloseDevTools(const v8::FunctionCallbackInfo& args); + static void IsDevToolsOpened(const v8::FunctionCallbackInfo& args); + static void InspectElement(const v8::FunctionCallbackInfo& args); + static void FocusOnWebView(const v8::FunctionCallbackInfo& args); + static void BlurWebView(const v8::FunctionCallbackInfo& args); + static void IsWebViewFocused(const v8::FunctionCallbackInfo& args); + static void CapturePage(const v8::FunctionCallbackInfo& args); // APIs for WebContents. - static v8::Handle GetPageTitle(const v8::Arguments& args); - static v8::Handle IsLoading(const v8::Arguments& args); - static v8::Handle IsWaitingForResponse(const v8::Arguments& args); - static v8::Handle Stop(const v8::Arguments& args); - static v8::Handle GetRoutingID(const v8::Arguments& args); - static v8::Handle GetProcessID(const v8::Arguments& args); - static v8::Handle IsCrashed(const v8::Arguments& args); + static void GetPageTitle(const v8::FunctionCallbackInfo& args); + static void IsLoading(const v8::FunctionCallbackInfo& args); + static void IsWaitingForResponse(const v8::FunctionCallbackInfo& args); + static void Stop(const v8::FunctionCallbackInfo& args); + static void GetRoutingID(const v8::FunctionCallbackInfo& args); + static void GetProcessID(const v8::FunctionCallbackInfo& args); + static void IsCrashed(const v8::FunctionCallbackInfo& args); // APIs for NavigationController. - static v8::Handle LoadURL(const v8::Arguments& args); - static v8::Handle GetURL(const v8::Arguments& args); - static v8::Handle CanGoBack(const v8::Arguments& args); - static v8::Handle CanGoForward(const v8::Arguments& args); - static v8::Handle CanGoToOffset(const v8::Arguments& args); - static v8::Handle GoBack(const v8::Arguments& args); - static v8::Handle GoForward(const v8::Arguments& args); - static v8::Handle GoToIndex(const v8::Arguments& args); - static v8::Handle GoToOffset(const v8::Arguments& args); - static v8::Handle Reload(const v8::Arguments& args); - static v8::Handle ReloadIgnoringCache(const v8::Arguments& args); + static void LoadURL(const v8::FunctionCallbackInfo& args); + static void GetURL(const v8::FunctionCallbackInfo& args); + static void CanGoBack(const v8::FunctionCallbackInfo& args); + static void CanGoForward(const v8::FunctionCallbackInfo& args); + static void CanGoToOffset(const v8::FunctionCallbackInfo& args); + static void GoBack(const v8::FunctionCallbackInfo& args); + static void GoForward(const v8::FunctionCallbackInfo& args); + static void GoToIndex(const v8::FunctionCallbackInfo& args); + static void GoToOffset(const v8::FunctionCallbackInfo& args); + static void Reload(const v8::FunctionCallbackInfo& args); + static void ReloadIgnoringCache(const v8::FunctionCallbackInfo& args); // Called when capturePage is done. - void OnCapturePageDone(v8::Persistent callback, + void OnCapturePageDone(const RefCountedV8Function& callback, const std::vector& data); scoped_ptr window_; diff --git a/browser/api/atom_browser_bindings.cc b/browser/api/atom_browser_bindings.cc index 3fb174573161..35488612c2be 100644 --- a/browser/api/atom_browser_bindings.cc +++ b/browser/api/atom_browser_bindings.cc @@ -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 global = node::g_context->Global(); - v8::Handle atom = - global->Get(v8::String::New("__atom"))->ToObject(); + v8::Handle global = global_env->context()->Global(); + v8::Handle atom = global->Get(ToV8Value("__atom"))->ToObject(); DCHECK(!atom.IsEmpty()); - browser_main_parts_ = v8::Persistent::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 context = v8::Context::GetCurrent(); + v8::HandleScope handle_scope(node_isolate); scoped_ptr 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 context = v8::Context::GetCurrent(); + v8::HandleScope handle_scope(node_isolate); scoped_ptr 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 diff --git a/browser/api/atom_browser_bindings.h b/browser/api/atom_browser_bindings.h index ae93329fafba..25e17f24890a 100644 --- a/browser/api/atom_browser_bindings.h +++ b/browser/api/atom_browser_bindings.h @@ -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 browser_main_parts() { - return browser_main_parts_; + return browser_main_parts_.NewHandle(); } private: - v8::Persistent browser_main_parts_; + ScopedPersistent browser_main_parts_; DISALLOW_COPY_AND_ASSIGN(AtomBrowserBindings); }; diff --git a/browser/atom_browser_client.cc b/browser/atom_browser_client.cc index bdff197d58fc..3c38721e52ff 100644 --- a/browser/atom_browser_client.cc +++ b/browser/atom_browser_client.cc @@ -7,7 +7,7 @@ #include "browser/atom_browser_context.h" #include "browser/atom_browser_main_parts.h" #include "browser/net/atom_url_request_context_getter.h" -#include "webkit/glue/webpreferences.h" +#include "webkit/common/webpreferences.h" namespace atom { diff --git a/browser/atom_browser_context.cc b/browser/atom_browser_context.cc index e2a80b80b514..9f8be6bc0868 100644 --- a/browser/atom_browser_context.cc +++ b/browser/atom_browser_context.cc @@ -33,6 +33,14 @@ class AtomResourceContext : public content::ResourceContext { return getter_->GetURLRequestContext(); } + virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { + return true; + } + + virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE { + return true; + } + private: AtomURLRequestContextGetter* getter_; diff --git a/browser/atom_browser_main_parts.cc b/browser/atom_browser_main_parts.cc index 8656e0af2154..93e99dca43db 100644 --- a/browser/atom_browser_main_parts.cc +++ b/browser/atom_browser_main_parts.cc @@ -4,15 +4,13 @@ #include "browser/atom_browser_main_parts.h" -#include "base/power_monitor/power_monitor.h" #include "browser/api/atom_browser_bindings.h" #include "browser/atom_browser_client.h" #include "browser/atom_browser_context.h" #include "browser/browser.h" #include "common/node_bindings.h" -#include "net/proxy/proxy_resolver_v8.h" -#include "vendor/node/src/node.h" -#include "vendor/node/src/node_internals.h" + +#include "common/v8/node_common.h" namespace atom { @@ -43,19 +41,14 @@ brightray::BrowserContext* AtomBrowserMainParts::CreateBrowserContext() { void AtomBrowserMainParts::PostEarlyInitialization() { brightray::BrowserMainParts::PostEarlyInitialization(); -#if defined(OS_MACOSX) - base::PowerMonitor::AllocateSystemIOPorts(); -#endif + v8::HandleScope handle_scope(node_isolate); node_bindings_->Initialize(); // Wrap whole process in one global context. - node::g_context->Enter(); - - atom_bindings_->BindTo(node::process); - - node_bindings_->Load(); + global_env->context()->Enter(); + atom_bindings_->BindTo(global_env->process_object()); atom_bindings_->AfterLoad(); } @@ -65,8 +58,8 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { brightray::BrowserMainParts::PreMainMessageLoopRun(); { - v8::HandleScope scope; - v8::Context::Scope context_scope(node::g_context); + v8::HandleScope handle_scope(node_isolate); + v8::Context::Scope context_scope(global_env->context()); v8::Handle args; node::MakeCallback(atom_bindings_->browser_main_parts(), @@ -88,10 +81,4 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { #endif } -int AtomBrowserMainParts::PreCreateThreads() { - // TODO(zcbenz): Calling CreateIsolate() on Windows when updated to Chrome30. - net::ProxyResolverV8::RememberDefaultIsolate(); - return 0; -} - } // namespace atom diff --git a/browser/atom_browser_main_parts.h b/browser/atom_browser_main_parts.h index a7fd1809328c..3b7ac1071aa2 100644 --- a/browser/atom_browser_main_parts.h +++ b/browser/atom_browser_main_parts.h @@ -30,7 +30,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { // Implementations of content::BrowserMainParts. virtual void PostEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopRun() OVERRIDE; - virtual int PreCreateThreads() OVERRIDE; #if defined(OS_MACOSX) virtual void PreMainMessageLoopStart() OVERRIDE; virtual void PostDestroyThreads() OVERRIDE; diff --git a/browser/atom_javascript_dialog_manager.cc b/browser/atom_javascript_dialog_manager.cc index 83f80a89f572..52cd59fd2b71 100644 --- a/browser/atom_javascript_dialog_manager.cc +++ b/browser/atom_javascript_dialog_manager.cc @@ -4,7 +4,7 @@ #include "browser/atom_javascript_dialog_manager.h" -#include "base/utf_string_conversions.h" +#include "base/strings/utf_string_conversions.h" namespace atom { diff --git a/browser/atom_javascript_dialog_manager.h b/browser/atom_javascript_dialog_manager.h index cdeada7cf760..38ed75b317d9 100644 --- a/browser/atom_javascript_dialog_manager.h +++ b/browser/atom_javascript_dialog_manager.h @@ -26,7 +26,9 @@ class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager { const string16& message_text, bool is_reload, const DialogClosedCallback& callback) OVERRIDE; - virtual void ResetJavaScriptState( + virtual void CancelActiveAndPendingDialogs( + content::WebContents* web_contents) OVERRIDE {} + virtual void WebContentsDestroyed( content::WebContents* web_contents) OVERRIDE {} }; diff --git a/browser/native_window.cc b/browser/native_window.cc index 09ed8237ba98..ad7773327e6b 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -7,9 +7,9 @@ #include #include "base/file_util.h" -#include "base/message_loop.h" -#include "base/stringprintf.h" -#include "base/utf_string_conversions.h" +#include "base/message_loop/message_loop.h" +#include "base/strings/stringprintf.h" +#include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "brightray/browser/inspectable_web_contents.h" #include "brightray/browser/inspectable_web_contents_view.h" @@ -37,8 +37,7 @@ #include "ui/gfx/point.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" -#include "webkit/glue/image_decoder.h" -#include "webkit/user_agent/user_agent_util.h" +#include "webkit/common/user_agent/user_agent_util.h" using content::NavigationEntry; @@ -165,7 +164,7 @@ void NativeWindow::CloseDevTools() { } bool NativeWindow::IsDevToolsOpened() { - return inspectable_web_contents()->IsDevToolsOpened(); + return inspectable_web_contents()->IsDevToolsViewShowing(); } void NativeWindow::InspectElement(int x, int y) { @@ -193,15 +192,14 @@ bool NativeWindow::SetIcon(const std::string& str_path) { // Read the file from disk. std::string file_contents; - if (path.empty() || !file_util::ReadFileToString(path, &file_contents)) + if (path.empty() || !base::ReadFileToString(path, &file_contents)) return false; // Decode the bitmap using WebKit's image decoder. const unsigned char* data = reinterpret_cast(file_contents.data()); - webkit_glue::ImageDecoder decoder; scoped_ptr decoded(new SkBitmap()); - *decoded = decoder.Decode(data, file_contents.length()); + gfx::PNGCodec::Decode(data, file_contents.length(), decoded.get()); if (decoded->empty()) return false; // Unable to decode. @@ -383,6 +381,21 @@ void NativeWindow::RendererResponsive(content::WebContents* source) { FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive()); } +void NativeWindow::RenderViewDeleted(content::RenderViewHost* rvh) { + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, + OnRenderViewDeleted(rvh->GetProcess()->GetID(), + rvh->GetRoutingID())); +} + +void NativeWindow::RenderProcessGone(base::TerminationStatus status) { + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererCrashed()); +} + +void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) { + // Do nothing, we override this method just to avoid compilation error since + // there are two virtual functions named BeforeUnloadFired. +} + bool NativeWindow::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(NativeWindow, message) @@ -397,16 +410,6 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) { return handled; } -void NativeWindow::RenderViewDeleted(content::RenderViewHost* rvh) { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnRenderViewDeleted(rvh->GetProcess()->GetID(), - rvh->GetRoutingID())); -} - -void NativeWindow::RenderViewGone(base::TerminationStatus status) { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererCrashed()); -} - void NativeWindow::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { diff --git a/browser/native_window.h b/browser/native_window.h index 40ce3ee3fb1e..5e1346138c97 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -184,7 +184,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // Implementations of content::WebContentsObserver. virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE; - virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; + virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; + virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; // Implementations of content::NotificationObserver diff --git a/browser/native_window_mac.mm b/browser/native_window_mac.mm index e9c12ba976ea..3d55ecb65e21 100644 --- a/browser/native_window_mac.mm +++ b/browser/native_window_mac.mm @@ -11,6 +11,7 @@ #define BASE_MAC_FOUNDATION_UTIL_H_ #include "base/mac/mac_util.h" +#include "base/mac/scoped_nsobject.h" #include "base/strings/sys_string_conversions.h" #include "base/values.h" #import "browser/ui/atom_event_processing_window.h" @@ -490,7 +491,7 @@ void NativeWindowMac::InstallDraggableRegionViews() { // Note that [webView subviews] returns the view's mutable internal array and // it should be copied to avoid mutating the original array while enumerating // it. - scoped_nsobject subviews([[webView subviews] copy]); + base::scoped_nsobject subviews([[webView subviews] copy]); for (NSView* subview in subviews.get()) if ([subview isKindOfClass:[ControlRegionView class]]) [subview removeFromSuperview]; @@ -501,7 +502,7 @@ void NativeWindowMac::InstallDraggableRegionViews() { system_drag_exclude_areas_.begin(); iter != system_drag_exclude_areas_.end(); ++iter) { - scoped_nsobject controlRegion( + base::scoped_nsobject controlRegion( [[ControlRegionView alloc] initWithShellWindow:this]); [controlRegion setFrame:NSMakeRect(iter->x(), webViewHeight - iter->bottom(), diff --git a/browser/net/adapter_request_job.cc b/browser/net/adapter_request_job.cc index 7dea112608c3..70c9293273c2 100644 --- a/browser/net/adapter_request_job.cc +++ b/browser/net/adapter_request_job.cc @@ -4,6 +4,7 @@ #include "browser/net/adapter_request_job.h" +#include "base/threading/sequenced_worker_pool.h" #include "browser/net/url_request_string_job.h" #include "content/public/browser/browser_thread.h" #include "net/base/net_errors.h" @@ -87,7 +88,13 @@ void AdapterRequestJob::CreateStringJobAndStart(const std::string& mime_type, void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - real_job_ = new net::URLRequestFileJob(request(), network_delegate(), path); + real_job_ = new net::URLRequestFileJob( + request(), + network_delegate(), + path, + content::BrowserThread::GetBlockingPool()-> + GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); real_job_->Start(); } diff --git a/browser/net/atom_url_request_context_getter.cc b/browser/net/atom_url_request_context_getter.cc index e7252b7eaf9e..bc9fe5150274 100644 --- a/browser/net/atom_url_request_context_getter.cc +++ b/browser/net/atom_url_request_context_getter.cc @@ -4,7 +4,8 @@ #include "browser/net/atom_url_request_context_getter.h" -#include "base/string_util.h" +#include "base/strings/string_util.h" +#include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" #include "browser/net/atom_url_request_job_factory.h" #include "content/public/browser/browser_thread.h" @@ -36,8 +37,8 @@ using content::BrowserThread; AtomURLRequestContextGetter::AtomURLRequestContextGetter( const base::FilePath& base_path, - MessageLoop* io_loop, - MessageLoop* file_loop, + base::MessageLoop* io_loop, + base::MessageLoop* file_loop, scoped_ptr network_delegate, content::ProtocolHandlerMap* protocol_handlers) : base_path_(base_path), @@ -74,6 +75,7 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() { base_path_.Append(FILE_PATH_LITERAL("Cookies")), false, nullptr, + nullptr, nullptr)); storage_->set_server_bound_cert_service(new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), @@ -98,7 +100,9 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() { storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); storage_->set_http_auth_handler_factory( net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); - storage_->set_http_server_properties(new net::HttpServerPropertiesImpl); + scoped_ptr server_properties( + new net::HttpServerPropertiesImpl); + storage_->set_http_server_properties(server_properties.Pass()); base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); net::HttpCache::DefaultBackend* main_backend = @@ -147,10 +151,15 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() { } protocol_handlers_.clear(); + scoped_ptr file_protocol_handler( + new net::FileProtocolHandler( + content::BrowserThread::GetBlockingPool()-> + GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); job_factory_->SetProtocolHandler(chrome::kDataScheme, new net::DataProtocolHandler); job_factory_->SetProtocolHandler(chrome::kFileScheme, - new net::FileProtocolHandler); + file_protocol_handler.release()); storage_->set_job_factory(job_factory_); } diff --git a/browser/net/atom_url_request_job_factory.cc b/browser/net/atom_url_request_job_factory.cc index d5d7c98f8d6e..01188674dc0e 100644 --- a/browser/net/atom_url_request_job_factory.cc +++ b/browser/net/atom_url_request_job_factory.cc @@ -6,7 +6,6 @@ #include "browser/net/atom_url_request_job_factory.h" #include "base/stl_util.h" -#include "googleurl/src/gurl.h" #include "net/base/load_flags.h" #include "net/url_request/url_request.h" @@ -102,4 +101,9 @@ bool AtomURLRequestJobFactory::IsHandledURL(const GURL& url) const { return IsHandledProtocol(url.scheme()); } +bool AtomURLRequestJobFactory::IsSafeRedirectTarget( + const GURL& location) const { + return IsHandledURL(location); +} + } // namespace atom diff --git a/browser/net/atom_url_request_job_factory.h b/browser/net/atom_url_request_job_factory.h index 6bba11cf904f..e18883610a47 100644 --- a/browser/net/atom_url_request_job_factory.h +++ b/browser/net/atom_url_request_job_factory.h @@ -45,6 +45,7 @@ class AtomURLRequestJobFactory : public net::URLRequestJobFactory { net::NetworkDelegate* network_delegate) const OVERRIDE; virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; virtual bool IsHandledURL(const GURL& url) const OVERRIDE; + virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE; private: typedef std::map ProtocolHandlerMap; diff --git a/browser/ui/accelerator_util.cc b/browser/ui/accelerator_util.cc index 625dee768927..85b5dc3b15e8 100644 --- a/browser/ui/accelerator_util.cc +++ b/browser/ui/accelerator_util.cc @@ -8,7 +8,7 @@ #include -#include "base/string_util.h" +#include "base/strings/string_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "ui/base/accelerators/accelerator.h" diff --git a/browser/ui/accelerator_util_mac.mm b/browser/ui/accelerator_util_mac.mm index c7dc2d07b0f8..5f5bb700a46f 100644 --- a/browser/ui/accelerator_util_mac.mm +++ b/browser/ui/accelerator_util_mac.mm @@ -6,7 +6,7 @@ #include "ui/base/accelerators/accelerator.h" #import "ui/base/accelerators/platform_accelerator_cocoa.h" -#import "ui/base/keycodes/keyboard_code_conversion_mac.h" +#import "ui/events/keycodes/keyboard_code_conversion_mac.h" namespace accelerator_util { diff --git a/browser/ui/atom_event_processing_window.h b/browser/ui/atom_event_processing_window.h index e657e1aa076d..92a24712468c 100644 --- a/browser/ui/atom_event_processing_window.h +++ b/browser/ui/atom_event_processing_window.h @@ -7,8 +7,6 @@ #import -#include "base/memory/scoped_nsobject.h" - // Override NSWindow to access unhandled keyboard events (for command // processing); subclassing NSWindow is the only method to do // this. diff --git a/browser/ui/atom_menu_controller_mac.h b/browser/ui/atom_menu_controller_mac.h index c2d1b1800376..834ea9a98ef2 100644 --- a/browser/ui/atom_menu_controller_mac.h +++ b/browser/ui/atom_menu_controller_mac.h @@ -8,7 +8,7 @@ #import -#include "base/memory/scoped_nsobject.h" +#include "base/mac/scoped_nsobject.h" #include "base/strings/string16.h" namespace ui { @@ -24,7 +24,7 @@ class MenuModel; @interface AtomMenuController : NSObject { @protected ui::MenuModel* model_; // weak - scoped_nsobject menu_; + base::scoped_nsobject menu_; BOOL isMenuOpen_; } diff --git a/browser/ui/atom_menu_controller_mac.mm b/browser/ui/atom_menu_controller_mac.mm index e0f5bdb3c919..13fd73bc1756 100644 --- a/browser/ui/atom_menu_controller_mac.mm +++ b/browser/ui/atom_menu_controller_mac.mm @@ -133,7 +133,7 @@ int EventFlagsFromNSEvent(NSEvent* event) { fromModel:(ui::MenuModel*)model { string16 label16 = model->GetLabelAt(index); NSString* label = l10n_util::FixUpWindowsStyleLabel(label16); - scoped_nsobject item( + base::scoped_nsobject item( [[NSMenuItem alloc] initWithTitle:label action:@selector(itemSelected:) keyEquivalent:@""]); diff --git a/browser/ui/file_dialog_mac.mm b/browser/ui/file_dialog_mac.mm index fd28cf55d6fd..80f655d9f6e7 100644 --- a/browser/ui/file_dialog_mac.mm +++ b/browser/ui/file_dialog_mac.mm @@ -24,7 +24,7 @@ void SetupDialog(NSSavePanel* dialog, NSString* default_dir = nil; NSString* default_filename = nil; if (!default_path.empty()) { - if (file_util::DirectoryExists(default_path)) { + if (base::DirectoryExists(default_path)) { default_dir = base::SysUTF8ToNSString(default_path.value()); } else { default_dir = base::SysUTF8ToNSString(default_path.DirName().value()); diff --git a/common/api/atom_api_clipboard.cc b/common/api/atom_api_clipboard.cc index 3d0fd0c6381b..e83b1eb5494c 100644 --- a/common/api/atom_api_clipboard.cc +++ b/common/api/atom_api_clipboard.cc @@ -6,92 +6,81 @@ #include +#include "common/v8/native_type_conversions.h" #include "ui/base/clipboard/clipboard.h" -#include "vendor/node/src/node.h" + +#include "common/v8/node_common.h" namespace atom { namespace api { // static -v8::Handle Clipboard::Has(const v8::Arguments& args) { - v8::HandleScope scope; - - if (!args[0]->IsString()) +void Clipboard::Has(const v8::FunctionCallbackInfo& args) { + std::string format_string; + if (!FromV8Arguments(args, &format_string)) return node::ThrowTypeError("Bad argument"); ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); - - std::string format_string(*v8::String::Utf8Value(args[0])); ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string)); - return scope.Close(v8::Boolean::New( - clipboard->IsFormatAvailable(format, ui::Clipboard::BUFFER_STANDARD))); + args.GetReturnValue().Set( + clipboard->IsFormatAvailable(format, ui::Clipboard::BUFFER_STANDARD)); } // static -v8::Handle Clipboard::Read(const v8::Arguments& args) { - v8::HandleScope scope; - - if (!args[0]->IsString()) +void Clipboard::Read(const v8::FunctionCallbackInfo& args) { + std::string format_string; + if (!FromV8Arguments(args, &format_string)) return node::ThrowTypeError("Bad argument"); ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); - - std::string format_string(*v8::String::Utf8Value(args[0])); ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string)); std::string data; clipboard->ReadData(format, &data); - return scope.Close(v8::String::New(data.c_str(), data.size())); + args.GetReturnValue().Set(ToV8Value(data)); } // static -v8::Handle Clipboard::ReadText(const v8::Arguments& args) { - v8::HandleScope scope; - +void Clipboard::ReadText(const v8::FunctionCallbackInfo& args) { ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); std::string data; clipboard->ReadAsciiText(ui::Clipboard::BUFFER_STANDARD, &data); - return scope.Close(v8::String::New(data.c_str(), data.size())); + args.GetReturnValue().Set(ToV8Value(data)); } // static -v8::Handle Clipboard::WriteText(const v8::Arguments& args) { - v8::HandleScope scope; - - if (!args[0]->IsString()) +void Clipboard::WriteText(const v8::FunctionCallbackInfo& args) { + std::string text; + if (!FromV8Arguments(args, &text)) return node::ThrowTypeError("Bad argument"); - ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); - std::string text(*v8::String::Utf8Value(args[0])); - ui::Clipboard::ObjectMap object_map; object_map[ui::Clipboard::CBF_TEXT].push_back( std::vector(text.begin(), text.end())); - clipboard->WriteObjects(ui::Clipboard::BUFFER_STANDARD, object_map, NULL); - return v8::Undefined(); + ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); + clipboard->WriteObjects(ui::Clipboard::BUFFER_STANDARD, object_map); } // static -v8::Handle Clipboard::Clear(const v8::Arguments& args) { - ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); - clipboard->Clear(ui::Clipboard::BUFFER_STANDARD); - - return v8::Undefined(); +void Clipboard::Clear(const v8::FunctionCallbackInfo& args) { + ui::Clipboard::GetForCurrentThread()->Clear(ui::Clipboard::BUFFER_STANDARD); } // static void Clipboard::Initialize(v8::Handle target) { - node::SetMethod(target, "has", Has); - node::SetMethod(target, "read", Read); - node::SetMethod(target, "readText", ReadText); - node::SetMethod(target, "writeText", WriteText); - node::SetMethod(target, "clear", Clear); + v8::HandleScope handle_scope(node_isolate); + + NODE_SET_METHOD(target, "has", Has); + NODE_SET_METHOD(target, "read", Read); + NODE_SET_METHOD(target, "readText", ReadText); + NODE_SET_METHOD(target, "writeText", WriteText); + NODE_SET_METHOD(target, "clear", Clear); } } // namespace api diff --git a/common/api/atom_api_clipboard.h b/common/api/atom_api_clipboard.h index 7b92f0cd36fc..70360d28ad25 100644 --- a/common/api/atom_api_clipboard.h +++ b/common/api/atom_api_clipboard.h @@ -17,11 +17,11 @@ class Clipboard { static void Initialize(v8::Handle target); private: - static v8::Handle Has(const v8::Arguments& args); - static v8::Handle Read(const v8::Arguments& args); - static v8::Handle ReadText(const v8::Arguments& args); - static v8::Handle WriteText(const v8::Arguments& args); - static v8::Handle Clear(const v8::Arguments& args); + static void Has(const v8::FunctionCallbackInfo& args); + static void Read(const v8::FunctionCallbackInfo& args); + static void ReadText(const v8::FunctionCallbackInfo& args); + static void WriteText(const v8::FunctionCallbackInfo& args); + static void Clear(const v8::FunctionCallbackInfo& args); DISALLOW_IMPLICIT_CONSTRUCTORS(Clipboard); }; diff --git a/common/api/atom_api_crash_reporter.cc b/common/api/atom_api_crash_reporter.cc index 26b1c2938f13..d64796e2c12f 100644 --- a/common/api/atom_api_crash_reporter.cc +++ b/common/api/atom_api_crash_reporter.cc @@ -5,16 +5,16 @@ #include "common/api/atom_api_crash_reporter.h" #include "common/crash_reporter/crash_reporter.h" -#include "common/v8_conversions.h" -#include "vendor/node/src/node.h" -#include "vendor/node/src/node_internals.h" +#include "common/v8/native_type_conversions.h" + +#include "common/v8/node_common.h" namespace atom { namespace api { // static -v8::Handle CrashReporter::Start(const v8::Arguments& args) { +void CrashReporter::Start(const v8::FunctionCallbackInfo& args) { std::string product_name, company_name, submit_url; bool auto_submit, skip_system; std::map dict; @@ -24,13 +24,11 @@ v8::Handle CrashReporter::Start(const v8::Arguments& args) { crash_reporter::CrashReporter::GetInstance()->Start( product_name, company_name, submit_url, auto_submit, skip_system, dict); - - return v8::Undefined(); } // static void CrashReporter::Initialize(v8::Handle target) { - node::SetMethod(target, "start", Start); + NODE_SET_METHOD(target, "start", Start); } } // namespace api diff --git a/common/api/atom_api_crash_reporter.h b/common/api/atom_api_crash_reporter.h index f31b8b1e9471..f92141ba767a 100644 --- a/common/api/atom_api_crash_reporter.h +++ b/common/api/atom_api_crash_reporter.h @@ -17,7 +17,7 @@ class CrashReporter { static void Initialize(v8::Handle target); private: - static v8::Handle Start(const v8::Arguments& args); + static void Start(const v8::FunctionCallbackInfo& args); DISALLOW_IMPLICIT_CONSTRUCTORS(CrashReporter); }; diff --git a/common/api/atom_api_id_weak_map.cc b/common/api/atom_api_id_weak_map.cc index 601ac2771617..75a18fb17c8f 100644 --- a/common/api/atom_api_id_weak_map.cc +++ b/common/api/atom_api_id_weak_map.cc @@ -5,7 +5,11 @@ #include "common/api/atom_api_id_weak_map.h" +#include + #include "base/logging.h" +#include "common/v8/native_type_conversions.h" +#include "common/v8/node_common.h" namespace atom { @@ -16,29 +20,17 @@ IDWeakMap::IDWeakMap() } IDWeakMap::~IDWeakMap() { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - - auto copied_map = map_; - for (auto el = copied_map.begin(); el != copied_map.end(); ++el) - Erase(isolate, el->first); } bool IDWeakMap::Has(int key) const { return map_.find(key) != map_.end(); } -void IDWeakMap::Erase(v8::Isolate* isolate, int key) { - if (!Has(key)) { +void IDWeakMap::Erase(int key) { + if (Has(key)) + map_.erase(key); + else LOG(WARNING) << "Object with key " << key << " is being GCed for twice."; - return; - } - - v8::Persistent value = map_[key]; - value.ClearWeak(isolate); - value.Dispose(isolate); - value.Clear(); - - map_.erase(key); } int IDWeakMap::GetNextID() { @@ -47,104 +39,93 @@ int IDWeakMap::GetNextID() { // static void IDWeakMap::WeakCallback(v8::Isolate* isolate, - v8::Persistent value, - void *data) { - v8::HandleScope scope; - - IDWeakMap* obj = static_cast(data); - int key = value->ToObject()->GetHiddenValue( - v8::String::New("IDWeakMapKey"))->IntegerValue(); - - obj->Erase(isolate, key); + v8::Persistent* value, + IDWeakMap* self) { + v8::HandleScope handle_scope(isolate); + v8::Local local = v8::Local::New(isolate, *value); + self->Erase( + FromV8Value(local->GetHiddenValue(v8::String::New("IDWeakMapKey")))); } // static -v8::Handle IDWeakMap::New(const v8::Arguments& args) { - IDWeakMap* obj = new IDWeakMap(); - obj->Wrap(args.This()); - return args.This(); +void IDWeakMap::New(const v8::FunctionCallbackInfo& args) { + (new IDWeakMap)->Wrap(args.This()); } // static -v8::Handle IDWeakMap::Add(const v8::Arguments& args) { +void IDWeakMap::Add(const v8::FunctionCallbackInfo& args) { if (!args[0]->IsObject()) return node::ThrowTypeError("Bad argument"); - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - IDWeakMap* obj = ObjectWrap::Unwrap(args.This()); - int key = obj->GetNextID(); + IDWeakMap* self = Unwrap(args.This()); - v8::Handle v8_key = v8::Integer::New(key); - v8::Persistent value = - v8::Persistent::New(isolate, args[0]); + int key = self->GetNextID(); + v8::Local v8_value = args[0]->ToObject(); + v8_value->SetHiddenValue(v8::String::New("IDWeakMapKey"), ToV8Value(key)); - value->ToObject()->SetHiddenValue(v8::String::New("IDWeakMapKey"), v8_key); - value.MakeWeak(isolate, obj, WeakCallback); - obj->map_[key] = value; + RefCountedV8Object& value = self->map_[key]; + value->reset(v8_value); + value->MakeWeak(self, WeakCallback); - return v8_key; + args.GetReturnValue().Set(key); } // static -v8::Handle IDWeakMap::Get(const v8::Arguments& args) { - if (!args[0]->IsNumber()) +void IDWeakMap::Get(const v8::FunctionCallbackInfo& args) { + int key; + if (!FromV8Arguments(args, &key)) return node::ThrowTypeError("Bad argument"); - IDWeakMap* obj = ObjectWrap::Unwrap(args.This()); - - int key = args[0]->IntegerValue(); - if (!obj->Has(key)) + IDWeakMap* self = Unwrap(args.This()); + if (!self->Has(key)) return node::ThrowError("Invalid key"); - return obj->map_[key]; + args.GetReturnValue().Set(self->map_[key]->NewHandle()); } // static -v8::Handle IDWeakMap::Has(const v8::Arguments& args) { - if (!args[0]->IsNumber()) +void IDWeakMap::Has(const v8::FunctionCallbackInfo& args) { + int key; + if (!FromV8Arguments(args, &key)) return node::ThrowTypeError("Bad argument"); - IDWeakMap* obj = ObjectWrap::Unwrap(args.This()); - - int key = args[0]->IntegerValue(); - return v8::Boolean::New(obj->Has(key)); + IDWeakMap* self = Unwrap(args.This()); + args.GetReturnValue().Set(self->Has(key)); } // static -v8::Handle IDWeakMap::Keys(const v8::Arguments& args) { - IDWeakMap* obj = ObjectWrap::Unwrap(args.This()); +void IDWeakMap::Keys(const v8::FunctionCallbackInfo& args) { + IDWeakMap* self = Unwrap(args.This()); - v8::Handle keys = v8::Array::New(obj->map_.size()); + v8::Local keys = v8::Array::New(self->map_.size()); int i = 0; - for (auto el = obj->map_.begin(); el != obj->map_.end(); ++el) { - keys->Set(i, v8::Integer::New(el->first)); + for (auto el = self->map_.begin(); el != self->map_.end(); ++el) { + keys->Set(i, ToV8Value(el->first)); ++i; } - return keys; + args.GetReturnValue().Set(keys); } // static -v8::Handle IDWeakMap::Remove(const v8::Arguments& args) { - if (!args[0]->IsNumber()) +void IDWeakMap::Remove(const v8::FunctionCallbackInfo& args) { + int key; + if (!FromV8Arguments(args, &key)) return node::ThrowTypeError("Bad argument"); - IDWeakMap* obj = ObjectWrap::Unwrap(args.This()); - - int key = args[0]->IntegerValue(); - if (!obj->Has(key)) + IDWeakMap* self = Unwrap(args.This()); + if (!self->Has(key)) return node::ThrowError("Invalid key"); - obj->Erase(v8::Isolate::GetCurrent(), key); - return v8::Undefined(); + self->Erase(key); } // static void IDWeakMap::Initialize(v8::Handle target) { - v8::HandleScope scope; + v8::HandleScope handle_scope(node_isolate); - v8::Local t = v8::FunctionTemplate::New(IDWeakMap::New); + v8::Local t = v8::FunctionTemplate::New(New); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(v8::String::NewSymbol("IDWeakMap")); diff --git a/common/api/atom_api_id_weak_map.h b/common/api/atom_api_id_weak_map.h index 6ae064f284e7..d2c0a33ac68f 100644 --- a/common/api/atom_api_id_weak_map.h +++ b/common/api/atom_api_id_weak_map.h @@ -9,6 +9,7 @@ #include #include "base/basictypes.h" +#include "common/v8/scoped_persistent.h" #include "vendor/node/src/node_object_wrap.h" namespace atom { @@ -24,23 +25,22 @@ class IDWeakMap : public node::ObjectWrap { virtual ~IDWeakMap(); bool Has(int key) const; - void Erase(v8::Isolate* isolate, int key); + void Erase(int key); int GetNextID(); static void WeakCallback(v8::Isolate* isolate, - v8::Persistent value, - void *data); + v8::Persistent* value, + IDWeakMap* self); - static v8::Handle New(const v8::Arguments& args); - static v8::Handle Add(const v8::Arguments& args); - static v8::Handle Get(const v8::Arguments& args); - static v8::Handle Has(const v8::Arguments& args); - static v8::Handle Keys(const v8::Arguments& args); - static v8::Handle Remove(const v8::Arguments& args); + static void New(const v8::FunctionCallbackInfo& args); + static void Add(const v8::FunctionCallbackInfo& args); + static void Get(const v8::FunctionCallbackInfo& args); + static void Has(const v8::FunctionCallbackInfo& args); + static void Keys(const v8::FunctionCallbackInfo& args); + static void Remove(const v8::FunctionCallbackInfo& args); int next_id_; - - std::map> map_; + std::map map_; DISALLOW_COPY_AND_ASSIGN(IDWeakMap); }; diff --git a/common/api/atom_api_shell.cc b/common/api/atom_api_shell.cc index 355c4d69df5a..5f7f2d80c843 100644 --- a/common/api/atom_api_shell.cc +++ b/common/api/atom_api_shell.cc @@ -8,91 +8,65 @@ #include "base/files/file_path.h" #include "common/platform_util.h" -#include "googleurl/src/gurl.h" -#include "vendor/node/src/node.h" +#include "common/v8/native_type_conversions.h" +#include "url/gurl.h" + +#include "common/v8/node_common.h" namespace atom { namespace api { -namespace { - -bool V8ValueToFilePath(v8::Handle value, base::FilePath* path) { - if (!value->IsString()) - return false; - - std::string file_path_string(*v8::String::Utf8Value(value)); - base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string); - - if (file_path.empty()) - return false; - - *path = file_path; - return true; -} - -} // namespace - // static -v8::Handle Shell::ShowItemInFolder(const v8::Arguments& args) { - v8::HandleScope scope; - +void Shell::ShowItemInFolder(const v8::FunctionCallbackInfo& args) { base::FilePath file_path; - if (!V8ValueToFilePath(args[0], &file_path)) + if (!FromV8Arguments(args, &file_path)) return node::ThrowTypeError("Bad argument"); platform_util::ShowItemInFolder(file_path); - return v8::Undefined(); } // static -v8::Handle Shell::OpenItem(const v8::Arguments& args) { - v8::HandleScope scope; - +void Shell::OpenItem(const v8::FunctionCallbackInfo& args) { base::FilePath file_path; - if (!V8ValueToFilePath(args[0], &file_path)) + if (!FromV8Arguments(args, &file_path)) return node::ThrowTypeError("Bad argument"); platform_util::OpenItem(file_path); - return v8::Undefined(); } // static -v8::Handle Shell::OpenExternal(const v8::Arguments& args) { - v8::HandleScope scope; - - if (!args[0]->IsString()) +void Shell::OpenExternal(const v8::FunctionCallbackInfo& args) { + GURL url; + if (!FromV8Arguments(args, &url)) return node::ThrowTypeError("Bad argument"); - platform_util::OpenExternal(GURL(*v8::String::Utf8Value(args[0]))); - return v8::Undefined(); + platform_util::OpenExternal(url); } // static -v8::Handle Shell::MoveItemToTrash(const v8::Arguments& args) { - v8::HandleScope scope; - +void Shell::MoveItemToTrash(const v8::FunctionCallbackInfo& args) { base::FilePath file_path; - if (!V8ValueToFilePath(args[0], &file_path)) + if (!FromV8Arguments(args, &file_path)) return node::ThrowTypeError("Bad argument"); platform_util::MoveItemToTrash(file_path); - return v8::Undefined(); } // static -v8::Handle Shell::Beep(const v8::Arguments& args) { +void Shell::Beep(const v8::FunctionCallbackInfo& args) { platform_util::Beep(); - return v8::Undefined(); } // static void Shell::Initialize(v8::Handle target) { - node::SetMethod(target, "showItemInFolder", ShowItemInFolder); - node::SetMethod(target, "openItem", OpenItem); - node::SetMethod(target, "openExternal", OpenExternal); - node::SetMethod(target, "moveItemToTrash", MoveItemToTrash); - node::SetMethod(target, "beep", Beep); + v8::HandleScope handle_scope(node_isolate); + + NODE_SET_METHOD(target, "showItemInFolder", ShowItemInFolder); + NODE_SET_METHOD(target, "openItem", OpenItem); + NODE_SET_METHOD(target, "openExternal", OpenExternal); + NODE_SET_METHOD(target, "moveItemToTrash", MoveItemToTrash); + NODE_SET_METHOD(target, "beep", Beep); } } // namespace api diff --git a/common/api/atom_api_shell.h b/common/api/atom_api_shell.h index 4b17fc8cffd1..7a35bb2787aa 100644 --- a/common/api/atom_api_shell.h +++ b/common/api/atom_api_shell.h @@ -17,11 +17,11 @@ class Shell { static void Initialize(v8::Handle target); private: - static v8::Handle ShowItemInFolder(const v8::Arguments& args); - static v8::Handle OpenItem(const v8::Arguments& args); - static v8::Handle OpenExternal(const v8::Arguments& args); - static v8::Handle MoveItemToTrash(const v8::Arguments& args); - static v8::Handle Beep(const v8::Arguments& args); + static void ShowItemInFolder(const v8::FunctionCallbackInfo& args); + static void OpenItem(const v8::FunctionCallbackInfo& args); + static void OpenExternal(const v8::FunctionCallbackInfo& args); + static void MoveItemToTrash(const v8::FunctionCallbackInfo& args); + static void Beep(const v8::FunctionCallbackInfo& args); DISALLOW_IMPLICIT_CONSTRUCTORS(Shell); }; diff --git a/common/api/atom_api_v8_util.cc b/common/api/atom_api_v8_util.cc index e07d4f098a39..01d779c3b984 100644 --- a/common/api/atom_api_v8_util.cc +++ b/common/api/atom_api_v8_util.cc @@ -3,9 +3,11 @@ // found in the LICENSE file. #include "common/api/object_life_monitor.h" + +#include "common/v8/native_type_conversions.h" #include "v8/include/v8-profiler.h" -#include "vendor/node/src/node.h" -#include "vendor/node/src/node_internals.h" + +#include "common/v8/node_common.h" namespace atom { @@ -13,48 +15,39 @@ namespace api { namespace { -v8::Handle DummyNew(const v8::Arguments& args) { - return args.This(); -} - -v8::Handle CreateObjectWithName(const v8::Arguments& args) { - v8::HandleScope scope; - - v8::Local t = v8::FunctionTemplate::New(DummyNew); +void CreateObjectWithName(const v8::FunctionCallbackInfo& args) { + v8::Local t = v8::FunctionTemplate::New(); t->SetClassName(args[0]->ToString()); - - return scope.Close(t->GetFunction()->NewInstance()); + args.GetReturnValue().Set(t->GetFunction()->NewInstance()); } -v8::Handle GetHiddenValue(const v8::Arguments& args) { - return args[0]->ToObject()->GetHiddenValue(args[1]->ToString()); +void GetHiddenValue(const v8::FunctionCallbackInfo& args) { + args.GetReturnValue().Set( + args[0]->ToObject()->GetHiddenValue(args[1]->ToString())); } -v8::Handle SetHiddenValue(const v8::Arguments& args) { +void SetHiddenValue(const v8::FunctionCallbackInfo& args) { args[0]->ToObject()->SetHiddenValue(args[1]->ToString(), args[2]); - return v8::Undefined(); } -v8::Handle GetObjectHash(const v8::Arguments& args) { - v8::HandleScope handle_scope; - return handle_scope.Close(v8::Integer::New( - args[0]->ToObject()->GetIdentityHash())); +void GetObjectHash(const v8::FunctionCallbackInfo& args) { + args.GetReturnValue().Set(args[0]->ToObject()->GetIdentityHash()); } -v8::Handle SetDestructor(const v8::Arguments& args) { +void SetDestructor(const v8::FunctionCallbackInfo& args) { ObjectLifeMonitor::BindTo(args[0]->ToObject(), args[1]); - return v8::Undefined(); } -v8::Handle TakeHeapSnapshot(const v8::Arguments& args) { +void TakeHeapSnapshot(const v8::FunctionCallbackInfo& args) { node::node_isolate->GetHeapProfiler()->TakeHeapSnapshot( v8::String::New("test")); - return v8::Undefined(); } } // namespace void InitializeV8Util(v8::Handle target) { + v8::HandleScope handle_scope(node_isolate); + NODE_SET_METHOD(target, "createObjectWithName", CreateObjectWithName); NODE_SET_METHOD(target, "getHiddenValue", GetHiddenValue); NODE_SET_METHOD(target, "setHiddenValue", SetHiddenValue); diff --git a/common/api/atom_bindings.cc b/common/api/atom_bindings.cc index d86698df9642..f8fbccc81198 100644 --- a/common/api/atom_bindings.cc +++ b/common/api/atom_bindings.cc @@ -6,8 +6,9 @@ #include "base/logging.h" #include "common/atom_version.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 { @@ -50,22 +51,20 @@ AtomBindings::~AtomBindings() { } void AtomBindings::BindTo(v8::Handle process) { - v8::HandleScope scope; + v8::HandleScope handle_scope(node_isolate); - node::SetMethod(process, "atomBinding", Binding); - node::SetMethod(process, "crash", Crash); - node::SetMethod(process, "activateUvLoop", ActivateUVLoop); - node::SetMethod(process, "log", Log); - node::SetMethod(process, "getCurrentStackTrace", GetCurrentStackTrace); + NODE_SET_METHOD(process, "atomBinding", Binding); + NODE_SET_METHOD(process, "crash", Crash); + NODE_SET_METHOD(process, "activateUvLoop", ActivateUVLoop); + NODE_SET_METHOD(process, "log", Log); + NODE_SET_METHOD(process, "getCurrentStackTrace", GetCurrentStackTrace); process->Get(v8::String::New("versions"))->ToObject()-> Set(v8::String::New("atom-shell"), v8::String::New(ATOM_VERSION_STRING)); } // static -v8::Handle AtomBindings::Binding(const v8::Arguments& args) { - v8::HandleScope scope; - +void AtomBindings::Binding(const v8::FunctionCallbackInfo& args) { v8::Local module = args[0]->ToString(); v8::String::Utf8Value module_v(module); node::node_module_struct* modp; @@ -93,7 +92,7 @@ v8::Handle AtomBindings::Binding(const v8::Arguments& args) { if (binding_cache->Has(module)) { exports = binding_cache->Get(module)->ToObject(); - return scope.Close(exports); + return args.GetReturnValue().Set(exports); } if ((modp = GetBuiltinModule(*module_v, is_browser)) != NULL) { @@ -102,39 +101,36 @@ v8::Handle AtomBindings::Binding(const v8::Arguments& args) { // only exports. modp->register_func(exports, v8::Undefined()); binding_cache->Set(module, exports); - return scope.Close(exports); + return args.GetReturnValue().Set(exports); } - return v8::ThrowException(v8::Exception::Error( - v8::String::New("No such module"))); + return node::ThrowError("No such module"); } // static -v8::Handle AtomBindings::Crash(const v8::Arguments& args) { +void AtomBindings::Crash(const v8::FunctionCallbackInfo& args) { static_cast(NULL)->crash = true; - return v8::Undefined(); } // static -v8::Handle AtomBindings::ActivateUVLoop(const v8::Arguments& args) { +void AtomBindings::ActivateUVLoop( + const v8::FunctionCallbackInfo& args) { uv_async_send(&dummy_uv_handle); - return v8::Undefined(); } // static -v8::Handle AtomBindings::Log(const v8::Arguments& args) { +void AtomBindings::Log(const v8::FunctionCallbackInfo& args) { std::string message; for (int i = 0; i < args.Length(); ++i) message += *v8::String::Utf8Value(args[i]); logging::LogMessage("CONSOLE", 0, 0).stream() << message; - return v8::Undefined(); } // static -v8::Handle AtomBindings::GetCurrentStackTrace( - const v8::Arguments& args) { - v8::HandleScope scope; +void AtomBindings::GetCurrentStackTrace( + const v8::FunctionCallbackInfo& args) { + v8::HandleScope handle_scope(args.GetIsolate()); int stack_limit = kMaxCallStackSize; FromV8Arguments(args, &stack_limit); @@ -147,7 +143,7 @@ v8::Handle AtomBindings::GetCurrentStackTrace( for (int i = 0; i < frame_count; ++i) result->Set(i, DumpStackFrame(stack_trace->GetFrame(i))); - return scope.Close(result); + args.GetReturnValue().Set(result); } } // namespace atom diff --git a/common/api/atom_bindings.h b/common/api/atom_bindings.h index 84fc098d1f83..a414bea22566 100644 --- a/common/api/atom_bindings.h +++ b/common/api/atom_bindings.h @@ -20,11 +20,12 @@ class AtomBindings { virtual void BindTo(v8::Handle process); private: - static v8::Handle Binding(const v8::Arguments& args); - static v8::Handle Crash(const v8::Arguments& args); - static v8::Handle ActivateUVLoop(const v8::Arguments& args); - static v8::Handle Log(const v8::Arguments& args); - static v8::Handle GetCurrentStackTrace(const v8::Arguments& args); + static void Binding(const v8::FunctionCallbackInfo& args); + static void Crash(const v8::FunctionCallbackInfo& args); + static void ActivateUVLoop(const v8::FunctionCallbackInfo& args); + static void Log(const v8::FunctionCallbackInfo& args); + static void GetCurrentStackTrace( + const v8::FunctionCallbackInfo& args); DISALLOW_COPY_AND_ASSIGN(AtomBindings); }; diff --git a/common/api/atom_extensions.cc b/common/api/atom_extensions.cc index c587c0718757..4bbf7dd634a8 100644 --- a/common/api/atom_extensions.cc +++ b/common/api/atom_extensions.cc @@ -5,10 +5,11 @@ #include #include -#include "base/string_util.h" -#include "vendor/node/src/node.h" +#include "base/strings/string_util.h" #include "vendor/node/src/node_version.h" +#include "common/v8/node_common.h" + namespace atom { #undef NODE_EXT_LIST_START diff --git a/common/api/object_life_monitor.cc b/common/api/object_life_monitor.cc index 27e4a1616c0a..fc9514363f49 100644 --- a/common/api/object_life_monitor.cc +++ b/common/api/object_life_monitor.cc @@ -10,42 +10,29 @@ namespace atom { // static void ObjectLifeMonitor::BindTo(v8::Handle target, v8::Handle destructor) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); target->SetHiddenValue(v8::String::New("destructor"), destructor); ObjectLifeMonitor* olm = new ObjectLifeMonitor(); - olm->handle_ = v8::Persistent::New(isolate, target); - olm->handle_.MakeWeak(isolate, olm, WeakCallback); + olm->handle_.reset(target); + olm->handle_.MakeWeak(olm, WeakCallback); } ObjectLifeMonitor::ObjectLifeMonitor() { } -ObjectLifeMonitor::~ObjectLifeMonitor() { - if (!handle_.IsEmpty()) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - handle_.ClearWeak(isolate); - handle_.Dispose(isolate); - handle_.Clear(); - } -} - // static void ObjectLifeMonitor::WeakCallback(v8::Isolate* isolate, - v8::Persistent value, - void *data) { + v8::Persistent* value, + ObjectLifeMonitor* self) { // destructor.call(object, object); { - v8::HandleScope scope; - - v8::Local obj = value->ToObject(); - v8::Local args[] = { obj }; + v8::HandleScope handle_scope(isolate); + v8::Local obj = self->handle_.NewHandle(); v8::Local::Cast(obj->GetHiddenValue( - v8::String::New("destructor")))->Call(obj, 1, args); + v8::String::New("destructor")))->Call(obj, 0, NULL); } - ObjectLifeMonitor* obj = static_cast(data); - delete obj; + delete self; } } // namespace atom diff --git a/common/api/object_life_monitor.h b/common/api/object_life_monitor.h index ba68f17ec65f..2621a62baf30 100644 --- a/common/api/object_life_monitor.h +++ b/common/api/object_life_monitor.h @@ -7,7 +7,7 @@ #define ATOM_COMMON_API_OBJECT_LIFE_MONITOR_H_ #include "base/basictypes.h" -#include "v8/include/v8.h" +#include "common/v8/scoped_persistent.h" namespace atom { @@ -18,13 +18,12 @@ class ObjectLifeMonitor { private: ObjectLifeMonitor(); - virtual ~ObjectLifeMonitor(); static void WeakCallback(v8::Isolate* isolate, - v8::Persistent value, - void *data); + v8::Persistent* value, + ObjectLifeMonitor* self); - v8::Persistent handle_; + ScopedPersistent handle_; DISALLOW_COPY_AND_ASSIGN(ObjectLifeMonitor); }; diff --git a/common/node_bindings.cc b/common/node_bindings.cc index 3e800417ef43..05dae33e8df3 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -6,22 +6,34 @@ #include "base/command_line.h" #include "base/logging.h" -#include "base/message_loop.h" -#include "common/v8_conversions.h" +#include "base/message_loop/message_loop.h" +#include "common/v8/native_type_conversions.h" #include "content/public/browser/browser_thread.h" #include "net/base/escape.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" -#include "vendor/node/src/node.h" -#include "vendor/node/src/node_internals.h" +#include "third_party/WebKit/public/web/WebDocument.h" +#include "third_party/WebKit/public/web/WebFrame.h" #include "vendor/node/src/node_javascript.h" #if defined(OS_WIN) #include "base/strings/utf_string_conversions.h" #endif +#include "common/v8/node_common.h" + using content::BrowserThread; +namespace node { +void Init(int* argc, + const char** argv, + int* exec_argc, + const char*** exec_argv); +Environment* CreateEnvironment(v8::Isolate* isolate, + int argc, + const char* const* argv, + int exec_argc, + const char* const* exec_argv); +} + namespace atom { namespace { @@ -31,6 +43,8 @@ void UvNoOp(uv_async_t* handle, int status) { } // namespace +node::Environment* global_env = NULL; + NodeBindings::NodeBindings(bool is_browser) : is_browser_(is_browser), message_loop_(NULL), @@ -61,14 +75,14 @@ void NodeBindings::Initialize() { utf8_str_argv.reserve(str_argv.size()); #endif - // Convert string vector to char* array. - std::vector argv(str_argv.size(), NULL); + // Convert string vector to const char* array. + std::vector args(str_argv.size(), NULL); for (size_t i = 0; i < str_argv.size(); ++i) { #if defined(OS_WIN) utf8_str_argv.push_back(UTF16ToUTF8(str_argv[i])); - argv[i] = const_cast(utf8_str_argv[i].c_str()); + args[i] = utf8_str_argv[i].c_str(); #else - argv[i] = const_cast(str_argv[i].c_str()); + args[i] = str_argv[i].c_str(); #endif } @@ -81,33 +95,30 @@ void NodeBindings::Initialize() { node::g_upstream_node_mode = false; // Init node. - node::Init(argv.size(), &argv[0]); + int argc = args.size(); + const char** argv = &args[0]; + int exec_argc; + const char** exec_argv; + node::Init(&argc, argv, &exec_argc, &exec_argv); v8::V8::Initialize(); - // Load node.js. - v8::HandleScope scope; - node::g_context = v8::Persistent::New( - node::node_isolate, v8::Context::New(node::node_isolate)); + // Create environment (setup process object and load node.js). + global_env = node::CreateEnvironment(node_isolate, argc, argv, argc, argv); + + // Set the process.__atom_type. { - v8::Context::Scope context_scope(node::g_context); - v8::Handle process = node::SetupProcessObject( - argv.size(), &argv[0]); + v8::Context::Scope context_scope(global_env->context()); + v8::HandleScope handle_scope(global_env->isolate()); // Tell node.js we are in browser or renderer. v8::Handle type = is_browser_ ? v8::String::New("browser") : v8::String::New("renderer"); - process->Set(v8::String::New("__atom_type"), type); + global_env->process_object()->Set(v8::String::New("__atom_type"), type); } } -void NodeBindings::Load() { - v8::HandleScope scope; - v8::Context::Scope context_scope(node::g_context); - node::Load(node::process); -} - void NodeBindings::BindTo(WebKit::WebFrame* frame) { - v8::HandleScope handle_scope; + v8::HandleScope handle_scope(node_isolate); v8::Handle context = frame->mainWorldScriptContext(); if (context.IsEmpty()) @@ -116,7 +127,7 @@ void NodeBindings::BindTo(WebKit::WebFrame* frame) { v8::Context::Scope scope(context); // Erase security token. - context->SetSecurityToken(node::g_context->GetSecurityToken()); + context->SetSecurityToken(global_env->context()->GetSecurityToken()); // Evaluate cefode.js. v8::Handle script = node::CompileCefodeMainSource(); @@ -128,7 +139,7 @@ void NodeBindings::BindTo(WebKit::WebFrame* frame) { script_path, net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); v8::Handle args[2] = { - v8::Local::New(node::process), + global_env->process_object(), ToV8Value(script_path), }; v8::Local::Cast(result)->Call(context->Global(), 2, args); @@ -160,8 +171,8 @@ void NodeBindings::UvRunOnce() { DCHECK(!is_browser_ || BrowserThread::CurrentlyOn(BrowserThread::UI)); // Enter node context while dealing with uv events. - v8::HandleScope scope; - v8::Context::Scope context_scope(node::g_context); + v8::HandleScope handle_scope(node_isolate); + v8::Context::Scope context_scope(global_env->context()); // Deal with uv events. int r = uv_run(uv_loop_, (uv_run_mode)(UV_RUN_ONCE | UV_RUN_NOWAIT)); diff --git a/common/node_bindings.h b/common/node_bindings.h index cadf168ea7a1..a9ac5852a129 100644 --- a/common/node_bindings.h +++ b/common/node_bindings.h @@ -24,12 +24,9 @@ class NodeBindings { virtual ~NodeBindings(); - // Setup V8, libuv and the process object. + // Setup V8, libuv and the process object, then load the node.js script. virtual void Initialize(); - // Load node.js main script. - virtual void Load(); - // Load cefode.js script under web frame. virtual void BindTo(WebKit::WebFrame* frame); diff --git a/common/node_bindings_mac.cc b/common/node_bindings_mac.cc index 3fe8eed0c9d2..0a31a1dd1fac 100644 --- a/common/node_bindings_mac.cc +++ b/common/node_bindings_mac.cc @@ -9,8 +9,7 @@ #include #include -#include "vendor/node/src/node.h" -#include "vendor/node/src/node_internals.h" +#include "common/v8/node_common.h" namespace atom { diff --git a/common/platform_util_mac.mm b/common/platform_util_mac.mm index 1c4c90b9434a..c01c43fdd047 100644 --- a/common/platform_util_mac.mm +++ b/common/platform_util_mac.mm @@ -12,7 +12,7 @@ #include "base/mac/mac_logging.h" #include "base/mac/scoped_aedesc.h" #include "base/strings/sys_string_conversions.h" -#include "googleurl/src/gurl.h" +#include "url/gurl.h" namespace platform_util { diff --git a/common/v8_conversions.h b/common/v8/native_type_conversions.h similarity index 87% rename from common/v8_conversions.h rename to common/v8/native_type_conversions.h index afd879351509..8a1e96615cc3 100644 --- a/common/v8_conversions.h +++ b/common/v8/native_type_conversions.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMMON_V8_CONVERSIONS_H_ -#define COMMON_V8_CONVERSIONS_H_ +#ifndef ATOM_COMMON_V8_NATIVE_TYPE_CONVERSIONS_H_ +#define ATOM_COMMON_V8_NATIVE_TYPE_CONVERSIONS_H_ #include #include @@ -15,11 +15,11 @@ #include "base/values.h" #include "browser/api/atom_api_window.h" #include "common/swap_or_assign.h" +#include "common/v8/scoped_persistent.h" #include "common/v8_value_converter_impl.h" #include "content/public/renderer/v8_value_converter.h" -#include "googleurl/src/gurl.h" #include "ui/gfx/rect.h" -#include "v8/include/v8.h" +#include "url/gurl.h" // Convert V8 value to arbitrary supported types. struct FromV8Value { @@ -104,10 +104,10 @@ struct FromV8Value { return NULL; } - operator v8::Persistent() { - return v8::Persistent::New( - node::node_isolate, - v8::Handle::Cast(value_)); + operator atom::RefCountedV8Function() { + v8::Handle func = v8::Handle::Cast(value_); + return atom::RefCountedV8Function( + new atom::RefCountedPersistent(func)); } v8::Handle value_; @@ -233,7 +233,9 @@ bool V8ValueCanBeConvertedTo>( // Check and convert V8's Arguments to native types. template inline -bool FromV8Arguments(const v8::Arguments& args, T1* value, int index = 0) { +bool FromV8Arguments(const v8::FunctionCallbackInfo& args, + T1* value, + int index = 0) { if (!V8ValueCanBeConvertedTo(args[index])) return false; internal::SwapOrAssign(*value, @@ -242,18 +244,23 @@ bool FromV8Arguments(const v8::Arguments& args, T1* value, int index = 0) { } template inline -bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2) { +bool FromV8Arguments(const v8::FunctionCallbackInfo& args, + T1* a1, + T2* a2) { return FromV8Arguments(args, a1) && FromV8Arguments(args, a2, 1); } template inline -bool FromV8Arguments(const v8::Arguments& args, T1* a1, T2* a2, T3* a3) { +bool FromV8Arguments(const v8::FunctionCallbackInfo& args, + T1* a1, + T2* a2, + T3* a3) { return FromV8Arguments(args, a1, a2) && FromV8Arguments(args, a3, 2); } template inline -bool FromV8Arguments(const v8::Arguments& args, +bool FromV8Arguments(const v8::FunctionCallbackInfo& args, T1* a1, T2* a2, T3* a3, @@ -263,7 +270,7 @@ bool FromV8Arguments(const v8::Arguments& args, } template inline -bool FromV8Arguments(const v8::Arguments& args, +bool FromV8Arguments(const v8::FunctionCallbackInfo& args, T1* a1, T2* a2, T3* a3, @@ -275,7 +282,7 @@ bool FromV8Arguments(const v8::Arguments& args, template inline -bool FromV8Arguments(const v8::Arguments& args, +bool FromV8Arguments(const v8::FunctionCallbackInfo& args, T1* a1, T2* a2, T3* a3, @@ -288,7 +295,7 @@ bool FromV8Arguments(const v8::Arguments& args, template inline -bool FromV8Arguments(const v8::Arguments& args, +bool FromV8Arguments(const v8::FunctionCallbackInfo& args, T1* a1, T2* a2, T3* a3, @@ -301,4 +308,4 @@ bool FromV8Arguments(const v8::Arguments& args, FromV8Arguments(args, a7, 6); } -#endif // COMMON_V8_CONVERSIONS_H_ +#endif // ATOM_COMMON_V8_NATIVE_TYPE_CONVERSIONS_H_ diff --git a/common/v8/node_common.h b/common/v8/node_common.h new file mode 100644 index 000000000000..5b8147f93122 --- /dev/null +++ b/common/v8/node_common.h @@ -0,0 +1,22 @@ +// 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_NODE_COMMON_H_ +#define ATOM_COMMON_V8_NODE_COMMON_H_ + +// Common helper for using node APIs. + +#undef CHECK +#undef DISALLOW_COPY_AND_ASSIGN +#include "vendor/node/src/env.h" +#include "vendor/node/src/node.h" +#include "vendor/node/src/node_internals.h" +using node::node_isolate; + +namespace atom { +// Defined in node_bindings.cc. +extern node::Environment* global_env; +} + +#endif // ATOM_COMMON_V8_NODE_COMMON_H_ diff --git a/common/v8/scoped_persistent.h b/common/v8/scoped_persistent.h new file mode 100644 index 000000000000..ac0abacd13d4 --- /dev/null +++ b/common/v8/scoped_persistent.h @@ -0,0 +1,115 @@ +// 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_SCOPED_PERSISTENT_H_ +#define ATOM_COMMON_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 +class ScopedPersistent { + public: + ScopedPersistent() { + } + + explicit ScopedPersistent(v8::Handle handle) { + reset(handle); + } + + ~ScopedPersistent() { + reset(); + } + + void reset(v8::Handle handle) { + if (!handle.IsEmpty()) + handle_.Reset(GetIsolate(handle), handle); + else + reset(); + } + + void reset() { + handle_.Reset(); + } + + bool IsEmpty() const { + return handle_.IsEmpty(); + } + + v8::Handle NewHandle() const { + if (handle_.IsEmpty()) + return v8::Local(); + return v8::Local::New(GetIsolate(handle_), handle_); + } + + v8::Handle NewHandle(v8::Isolate* isolate) const { + if (handle_.IsEmpty()) + return v8::Local(); + return v8::Local::New(isolate, handle_); + } + + template + void MakeWeak(P* parameters, + typename v8::WeakReferenceCallbacks::Revivable callback) { + handle_.MakeWeak(parameters, callback); + } + + private: + template + static v8::Isolate* GetIsolate(v8::Handle 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 context_handle) { + if (!context_handle.IsEmpty()) + return context_handle->GetIsolate(); + return v8::Isolate::GetCurrent(); + } + static v8::Isolate* GetIsolate( + v8::Handle template_handle) { + return v8::Isolate::GetCurrent(); + } + template + static v8::Isolate* GetIsolate(const U& any_handle) { + return v8::Isolate::GetCurrent(); + } + + v8::Persistent handle_; + + DISALLOW_COPY_AND_ASSIGN(ScopedPersistent); +}; + +template +class RefCountedPersistent : public ScopedPersistent, + public base::RefCounted> { + public: + RefCountedPersistent() {} + + explicit RefCountedPersistent(v8::Handle handle) + : ScopedPersistent(handle) { + } + + protected: + friend class base::RefCounted>; + + ~RefCountedPersistent() {} + + private: + DISALLOW_COPY_AND_ASSIGN(RefCountedPersistent); +}; + +typedef scoped_refptr> RefCountedV8Function; +typedef scoped_refptr> RefCountedV8Object; + +} // namespace atom + +#endif // ATOM_COMMON_SCOPED_PERSISTENT_H_ diff --git a/common/v8_value_converter_impl.cc b/common/v8_value_converter_impl.cc index e76ddf94cec4..9ad9845e23f5 100644 --- a/common/v8_value_converter_impl.cc +++ b/common/v8_value_converter_impl.cc @@ -36,10 +36,14 @@ void V8ValueConverterImpl::SetStripNullFromObjects(bool val) { strip_null_from_objects_ = val; } +void V8ValueConverterImpl::SetStrategy(Strategy* strategy) { + // Ignore any strategy. +} + v8::Handle V8ValueConverterImpl::ToV8Value( const base::Value* value, v8::Handle context) const { v8::Context::Scope context_scope(context); - v8::HandleScope handle_scope; + v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); return handle_scope.Close(ToV8ValueImpl(value)); } @@ -47,7 +51,7 @@ Value* V8ValueConverterImpl::FromV8Value( v8::Handle val, v8::Handle context) const { v8::Context::Scope context_scope(context); - v8::HandleScope handle_scope; + v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); HashToHandleMap unique_map; return FromV8ValueImpl(val, &unique_map); } diff --git a/common/v8_value_converter_impl.h b/common/v8_value_converter_impl.h index 47e485d098ea..38d19a4d521b 100644 --- a/common/v8_value_converter_impl.h +++ b/common/v8_value_converter_impl.h @@ -31,6 +31,7 @@ class V8ValueConverterImpl : public content::V8ValueConverter { virtual void SetRegExpAllowed(bool val) OVERRIDE; virtual void SetFunctionAllowed(bool val) OVERRIDE; virtual void SetStripNullFromObjects(bool val) OVERRIDE; + virtual void SetStrategy(Strategy* strategy) OVERRIDE; virtual v8::Handle ToV8Value( const base::Value* value, v8::Handle context) const OVERRIDE; diff --git a/renderer/api/atom_api_renderer_ipc.cc b/renderer/api/atom_api_renderer_ipc.cc index 3a1e03640216..3bc185900fba 100644 --- a/renderer/api/atom_api_renderer_ipc.cc +++ b/renderer/api/atom_api_renderer_ipc.cc @@ -5,11 +5,12 @@ #include "renderer/api/atom_api_renderer_ipc.h" #include "common/api/api_messages.h" -#include "common/v8_conversions.h" +#include "common/v8/native_type_conversions.h" #include "content/public/renderer/render_view.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" -#include "vendor/node/src/node.h" +#include "third_party/WebKit/public/web/WebFrame.h" +#include "third_party/WebKit/public/web/WebView.h" + +#include "common/v8/node_common.h" using content::RenderView; using WebKit::WebFrame; @@ -36,9 +37,7 @@ RenderView* GetCurrentRenderView() { } // namespace // static -v8::Handle RendererIPC::Send(const v8::Arguments& args) { - v8::HandleScope scope; - +void RendererIPC::Send(const v8::FunctionCallbackInfo& args) { string16 channel; scoped_ptr arguments; if (!FromV8Arguments(args, &channel, &arguments)) @@ -46,7 +45,7 @@ v8::Handle RendererIPC::Send(const v8::Arguments& args) { RenderView* render_view = GetCurrentRenderView(); if (render_view == NULL) - return v8::Undefined(); + return; bool success = render_view->Send(new AtomViewHostMsg_Message( render_view->GetRoutingID(), @@ -55,14 +54,10 @@ v8::Handle RendererIPC::Send(const v8::Arguments& args) { if (!success) return node::ThrowError("Unable to send AtomViewHostMsg_Message"); - - return v8::Undefined(); } // static -v8::Handle RendererIPC::SendSync(const v8::Arguments& args) { - v8::HandleScope scope; - +void RendererIPC::SendSync(const v8::FunctionCallbackInfo& args) { string16 channel; scoped_ptr arguments; if (!FromV8Arguments(args, &channel, &arguments)) @@ -70,7 +65,7 @@ v8::Handle RendererIPC::SendSync(const v8::Arguments& args) { RenderView* render_view = GetCurrentRenderView(); if (render_view == NULL) - return v8::Undefined(); + return; string16 json; IPC::SyncMessage* message = new AtomViewHostMsg_Message_Sync( @@ -85,13 +80,15 @@ v8::Handle RendererIPC::SendSync(const v8::Arguments& args) { if (!success) return node::ThrowError("Unable to send AtomViewHostMsg_Message_Sync"); - return scope.Close(ToV8Value(json)); + args.GetReturnValue().Set(ToV8Value(json)); } // static void RendererIPC::Initialize(v8::Handle target) { - node::SetMethod(target, "send", Send); - node::SetMethod(target, "sendSync", SendSync); + v8::HandleScope handle_scope(node_isolate); + + NODE_SET_METHOD(target, "send", Send); + NODE_SET_METHOD(target, "sendSync", SendSync); } } // namespace api diff --git a/renderer/api/atom_api_renderer_ipc.h b/renderer/api/atom_api_renderer_ipc.h index 60315dac7325..915859501a62 100644 --- a/renderer/api/atom_api_renderer_ipc.h +++ b/renderer/api/atom_api_renderer_ipc.h @@ -17,8 +17,8 @@ class RendererIPC { static void Initialize(v8::Handle target); private: - static v8::Handle Send(const v8::Arguments& args); - static v8::Handle SendSync(const v8::Arguments& args); + static void Send(const v8::FunctionCallbackInfo& args); + static void SendSync(const v8::FunctionCallbackInfo& args); DISALLOW_IMPLICIT_CONSTRUCTORS(RendererIPC); }; diff --git a/renderer/api/atom_renderer_bindings.cc b/renderer/api/atom_renderer_bindings.cc index 4f54e6548c91..0957f7c1d24d 100644 --- a/renderer/api/atom_renderer_bindings.cc +++ b/renderer/api/atom_renderer_bindings.cc @@ -7,11 +7,12 @@ #include #include "base/logging.h" -#include "common/v8_conversions.h" +#include "common/v8/native_type_conversions.h" #include "content/public/renderer/render_view.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" -#include "vendor/node/src/node.h" +#include "third_party/WebKit/public/web/WebFrame.h" +#include "third_party/WebKit/public/web/WebView.h" + +#include "common/v8/node_common.h" using content::RenderView; using content::V8ValueConverter; @@ -39,7 +40,7 @@ AtomRendererBindings::~AtomRendererBindings() { } void AtomRendererBindings::BindToFrame(WebFrame* frame) { - v8::HandleScope handle_scope; + v8::HandleScope handle_scope(node_isolate); v8::Handle context = frame->mainWorldScriptContext(); if (context.IsEmpty()) @@ -55,7 +56,7 @@ void AtomRendererBindings::OnBrowserMessage(const string16& channel, if (!render_view_->GetWebView()) return; - v8::HandleScope scope; + v8::HandleScope handle_scope(node_isolate); v8::Local context = render_view_->GetWebView()->mainFrame()->mainWorldScriptContext(); diff --git a/renderer/atom_render_view_observer.cc b/renderer/atom_render_view_observer.cc index 4405d531afb0..dd4dfbe553db 100644 --- a/renderer/atom_render_view_observer.cc +++ b/renderer/atom_render_view_observer.cc @@ -12,9 +12,9 @@ #include "ipc/ipc_message_macros.h" #include "renderer/api/atom_renderer_bindings.h" #include "renderer/atom_renderer_client.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebDraggableRegion.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/public/web/WebDocument.h" +#include "third_party/WebKit/public/web/WebDraggableRegion.h" +#include "third_party/WebKit/public/web/WebFrame.h" #include "v8/include/v8.h" using WebKit::WebFrame; diff --git a/renderer/atom_renderer_client.cc b/renderer/atom_renderer_client.cc index 36cb4052532d..183d2d57ca4c 100644 --- a/renderer/atom_renderer_client.cc +++ b/renderer/atom_renderer_client.cc @@ -6,7 +6,8 @@ #include "common/node_bindings.h" #include "renderer/atom_render_view_observer.h" -#include "vendor/node/src/node_internals.h" + +#include "common/v8/node_common.h" namespace webkit { extern void SetGetNodeContext(v8::Handle (*)()); @@ -17,7 +18,7 @@ namespace atom { namespace { v8::Handle GetNodeContext() { - return node::g_context; + return global_env->context(); } } // namespace @@ -35,7 +36,6 @@ void AtomRendererClient::RenderThreadStarted() { // Interact with dirty workarounds of extra node context in WebKit. webkit::SetGetNodeContext(GetNodeContext); - node_bindings_->Load(); node_bindings_->PrepareMessageLoop(); node_bindings_->RunMessageLoop(); } diff --git a/vendor/brightray b/vendor/brightray index 8e453e36fe6a..3f92be3fd3e7 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 8e453e36fe6ab74cf4e72fe0fa67e30eb048d2b3 +Subproject commit 3f92be3fd3e7d841e0153d32eb8945ed65827225 diff --git a/vendor/node b/vendor/node index 4b6ab23cb972..264b0177bc11 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 4b6ab23cb972a96bde40c899aab41703f08a1f0d +Subproject commit 264b0177bc11c4b2e733294c7921fd4c72e5b4e5 From d53915c6ab7753adf1efb737481b07facb483900 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 11 Dec 2013 23:57:37 +0800 Subject: [PATCH 07/55] Fix recursive calling of handle(). --- browser/api/atom_api_event_emitter.h | 5 ----- browser/api/atom_api_menu.cc | 12 ++++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/browser/api/atom_api_event_emitter.h b/browser/api/atom_api_event_emitter.h index 959d4b7f9b17..dd2292238601 100644 --- a/browser/api/atom_api_event_emitter.h +++ b/browser/api/atom_api_event_emitter.h @@ -29,11 +29,6 @@ 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 handle() const { - return const_cast(this)->handle(); - } - protected: explicit EventEmitter(v8::Handle wrapper); diff --git a/browser/api/atom_api_menu.cc b/browser/api/atom_api_menu.cc index 814cdc75f413..4367dac6c0b6 100644 --- a/browser/api/atom_api_menu.cc +++ b/browser/api/atom_api_menu.cc @@ -54,7 +54,7 @@ Menu::~Menu() { bool Menu::IsCommandIdChecked(int command_id) const { v8::HandleScope handle_scope(node_isolate); return CallDelegate(v8::False(), - handle(), + const_cast(this)->handle(), "isCommandIdChecked", command_id)->BooleanValue(); } @@ -62,7 +62,7 @@ bool Menu::IsCommandIdChecked(int command_id) const { bool Menu::IsCommandIdEnabled(int command_id) const { v8::HandleScope handle_scope(node_isolate); return CallDelegate(v8::True(), - handle(), + const_cast(this)->handle(), "isCommandIdEnabled", command_id)->BooleanValue(); } @@ -70,7 +70,7 @@ bool Menu::IsCommandIdEnabled(int command_id) const { bool Menu::IsCommandIdVisible(int command_id) const { v8::HandleScope handle_scope(node_isolate); return CallDelegate(v8::True(), - handle(), + const_cast(this)->handle(), "isCommandIdVisible", command_id)->BooleanValue(); } @@ -93,7 +93,7 @@ bool Menu::GetAcceleratorForCommandId(int command_id, bool Menu::IsItemForCommandIdDynamic(int command_id) const { v8::HandleScope handle_scope(node_isolate); return CallDelegate(v8::False(), - handle(), + const_cast(this)->handle(), "isItemForCommandIdDynamic", command_id)->BooleanValue(); } @@ -101,7 +101,7 @@ bool Menu::IsItemForCommandIdDynamic(int command_id) const { string16 Menu::GetLabelForCommandId(int command_id) const { v8::HandleScope handle_scope(node_isolate); return FromV8Value(CallDelegate(v8::False(), - handle(), + const_cast(this)->handle(), "getLabelForCommandId", command_id)); } @@ -109,7 +109,7 @@ string16 Menu::GetLabelForCommandId(int command_id) const { string16 Menu::GetSublabelForCommandId(int command_id) const { v8::HandleScope handle_scope(node_isolate); return FromV8Value(CallDelegate(v8::False(), - handle(), + const_cast(this)->handle(), "getSubLabelForCommandId", command_id)); } From e4bfa373ded902bb0b5685893135a3165c409c96 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 11 Dec 2013 23:59:03 +0800 Subject: [PATCH 08/55] Fix node integration to browser after updated to Chrome31. --- atom.gyp | 1 + browser/atom/atom-renderer.coffee | 5 +++ browser/atom/atom.coffee | 72 +++++++++++++++++------------- browser/atom_browser_main_parts.cc | 2 - common/node_bindings.cc | 42 +++++++++++------ vendor/node | 2 +- 6 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 browser/atom/atom-renderer.coffee diff --git a/atom.gyp b/atom.gyp index a9d8b92b420a..60f8c77941e7 100644 --- a/atom.gyp +++ b/atom.gyp @@ -22,6 +22,7 @@ 'browser/api/lib/power-monitor.coffee', 'browser/api/lib/protocol.coffee', 'browser/atom/atom.coffee', + 'browser/atom/atom-renderer.coffee', 'browser/atom/objects-registry.coffee', 'browser/atom/rpc-server.coffee', 'common/api/lib/callbacks-registry.coffee', diff --git a/browser/atom/atom-renderer.coffee b/browser/atom/atom-renderer.coffee new file mode 100644 index 000000000000..8430d183340d --- /dev/null +++ b/browser/atom/atom-renderer.coffee @@ -0,0 +1,5 @@ +path = require 'path' + +process.__atom_type = 'renderer' +process.resourcesPath = path.resolve process.argv[1], '..', '..', '..' +process.argv.splice 1, 1 diff --git a/browser/atom/atom.coffee b/browser/atom/atom.coffee index 2488620467f4..6212dd0b2959 100644 --- a/browser/atom/atom.coffee +++ b/browser/atom/atom.coffee @@ -1,6 +1,11 @@ fs = require 'fs' path = require 'path' +# Restore the proces.argv. +process.__atom_type = 'browser' +process.resourcesPath = path.resolve process.argv[1], '..', '..', '..' +process.argv.splice 1, 1 + if process.platform is 'win32' # Redirect node's console to use our own implementations, since node can not # handle output when running as GUI program. @@ -33,41 +38,44 @@ globalPaths.push path.join process.resourcesPath, 'browser', 'api', 'lib' # And also common/api/lib globalPaths.push path.join process.resourcesPath, 'common', 'api', 'lib' -# Don't quit on fatal error. -process.on 'uncaughtException', (error) -> - # Show error in GUI. - message = error.stack ? "#{error.name}: #{error.message}" - require('dialog').showMessageBox - type: 'warning' - title: 'An javascript error occured in the browser' - message: 'uncaughtException' - detail: message - buttons: ['OK'] +# Do loading in next tick since we still need some initialize work before +# native bindings can work. +setImmediate -> + # Don't quit on fatal error. + process.on 'uncaughtException', (error) -> + # Show error in GUI. + message = error.stack ? "#{error.name}: #{error.message}" + require('dialog').showMessageBox + type: 'warning' + title: 'An javascript error occured in the browser' + message: 'uncaughtException' + detail: message + buttons: ['OK'] -# Load the RPC server. -require './rpc-server.js' + # Load the RPC server. + require './rpc-server.js' -# Now we try to load app's package.json. -packageJson = null + # Now we try to load app's package.json. + packageJson = null -packagePath = path.join process.resourcesPath, 'app' -try - # First we try to load process.resourcesPath/app - packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'))) -catch error - # If not found then we load browser/default_app - packagePath = path.join process.resourcesPath, 'browser', 'default_app' - packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'))) + packagePath = path.join process.resourcesPath, 'app' + try + # First we try to load process.resourcesPath/app + packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'))) + catch error + # If not found then we load browser/default_app + packagePath = path.join process.resourcesPath, 'browser', 'default_app' + packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'))) -# Set application's version. -app = require 'app' -app.setVersion packageJson.version if packageJson.version? + # Set application's version. + app = require 'app' + app.setVersion packageJson.version if packageJson.version? -# Set application's name. -if packageJson.productName? - app.setName packageJson.productName -else if packageJson.name? - app.setName packageJson.name + # Set application's name. + if packageJson.productName? + app.setName packageJson.productName + else if packageJson.name? + app.setName packageJson.name -# Finally load app's main.js and transfer control to C++. -require path.join(packagePath, packageJson.main) + # Finally load app's main.js and transfer control to C++. + require path.join(packagePath, packageJson.main) diff --git a/browser/atom_browser_main_parts.cc b/browser/atom_browser_main_parts.cc index 93e99dca43db..2328fda1bb29 100644 --- a/browser/atom_browser_main_parts.cc +++ b/browser/atom_browser_main_parts.cc @@ -41,8 +41,6 @@ brightray::BrowserContext* AtomBrowserMainParts::CreateBrowserContext() { void AtomBrowserMainParts::PostEarlyInitialization() { brightray::BrowserMainParts::PostEarlyInitialization(); - v8::HandleScope handle_scope(node_isolate); - node_bindings_->Initialize(); // Wrap whole process in one global context. diff --git a/common/node_bindings.cc b/common/node_bindings.cc index 05dae33e8df3..9bda801b95f2 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -4,9 +4,13 @@ #include "common/node_bindings.h" +#include // PATH_MAX + #include "base/command_line.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" +#include "base/base_paths.h" +#include "base/path_service.h" #include "common/v8/native_type_conversions.h" #include "content/public/browser/browser_thread.h" #include "net/base/escape.h" @@ -22,6 +26,7 @@ using content::BrowserThread; +// Forward declaration of internal node functions. namespace node { void Init(int* argc, const char** argv, @@ -86,9 +91,29 @@ void NodeBindings::Initialize() { #endif } - // Init idle GC. - uv_timer_init(uv_default_loop(), &idle_timer_); - uv_timer_start(&idle_timer_, IdleCallback, 5000, 5000); + // Feed node the path to initialization script. + base::FilePath exec_path(str_argv[0]); + PathService::Get(base::FILE_EXE, &exec_path); + base::FilePath resources_path = +#if defined(OS_MACOSX) + is_browser_ ? exec_path.DirName().DirName().Append("Resources") : + exec_path.DirName().DirName().DirName().DirName().DirName() + .Append("Resources"); +#else + exec_path.DirName().Append("resources"); +#endif + base::FilePath script_path = + resources_path.AppendASCII("browser") + .AppendASCII("atom") + .AppendASCII(is_browser_ ? "atom.js" : "atom-renderer.js"); + std::string script_path_str = script_path.AsUTF8Unsafe(); + args.insert(args.begin() + 1, script_path_str.c_str()); + + // Init idle GC for browser. + if (is_browser_) { + uv_timer_init(uv_default_loop(), &idle_timer_); + uv_timer_start(&idle_timer_, IdleCallback, 5000, 5000); + } // Open node's error reporting system for browser process. node::g_standalone_mode = is_browser_; @@ -104,17 +129,6 @@ void NodeBindings::Initialize() { // Create environment (setup process object and load node.js). global_env = node::CreateEnvironment(node_isolate, argc, argv, argc, argv); - - // Set the process.__atom_type. - { - v8::Context::Scope context_scope(global_env->context()); - v8::HandleScope handle_scope(global_env->isolate()); - - // Tell node.js we are in browser or renderer. - v8::Handle type = - is_browser_ ? v8::String::New("browser") : v8::String::New("renderer"); - global_env->process_object()->Set(v8::String::New("__atom_type"), type); - } } void NodeBindings::BindTo(WebKit::WebFrame* frame) { diff --git a/vendor/node b/vendor/node index 264b0177bc11..4e04c9f0a2d9 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 264b0177bc11c4b2e733294c7921fd4c72e5b4e5 +Subproject commit 4e04c9f0a2d97e0b20a0980266917e11f2805280 From 61c63a6af9d63f757f9fa591543d13ff3ed5a1de Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Dec 2013 00:10:09 +0800 Subject: [PATCH 09/55] Fix crashes about persistent v8 functions. --- common/api/atom_api_id_weak_map.cc | 5 ++--- common/v8/native_type_conversions.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/common/api/atom_api_id_weak_map.cc b/common/api/atom_api_id_weak_map.cc index 75a18fb17c8f..2ee2cf32913c 100644 --- a/common/api/atom_api_id_weak_map.cc +++ b/common/api/atom_api_id_weak_map.cc @@ -63,9 +63,8 @@ void IDWeakMap::Add(const v8::FunctionCallbackInfo& args) { v8::Local v8_value = args[0]->ToObject(); v8_value->SetHiddenValue(v8::String::New("IDWeakMapKey"), ToV8Value(key)); - RefCountedV8Object& value = self->map_[key]; - value->reset(v8_value); - value->MakeWeak(self, WeakCallback); + self->map_[key] = new RefCountedPersistent(v8_value); + self->map_[key]->MakeWeak(self, WeakCallback); args.GetReturnValue().Set(key); } diff --git a/common/v8/native_type_conversions.h b/common/v8/native_type_conversions.h index 8a1e96615cc3..49ad3a6f71a7 100644 --- a/common/v8/native_type_conversions.h +++ b/common/v8/native_type_conversions.h @@ -226,7 +226,7 @@ bool V8ValueCanBeConvertedTo(v8::Handle value) { } template<> inline -bool V8ValueCanBeConvertedTo>( +bool V8ValueCanBeConvertedTo( v8::Handle value) { return value->IsFunction(); } From 9ea75b7519b050a80550e76cb97b466b8d0d6294 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Dec 2013 10:43:34 +0800 Subject: [PATCH 10/55] We are now at v0.8.0-pre. --- common/atom_version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/atom_version.h b/common/atom_version.h index 34f83448bb08..fc4e648bf252 100644 --- a/common/atom_version.h +++ b/common/atom_version.h @@ -6,10 +6,10 @@ #define ATOM_VERSION_H #define ATOM_MAJOR_VERSION 0 -#define ATOM_MINOR_VERSION 7 -#define ATOM_PATCH_VERSION 5 +#define ATOM_MINOR_VERSION 8 +#define ATOM_PATCH_VERSION 0 -#define ATOM_VERSION_IS_RELEASE 1 +#define ATOM_VERSION_IS_RELEASE 0 #ifndef ATOM_TAG # define ATOM_TAG "" From fc00da97325dd03c613641d9810c25e433a23a33 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Dec 2013 10:43:50 +0800 Subject: [PATCH 11/55] Update brightray, which contains all our patches in master. --- vendor/brightray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/brightray b/vendor/brightray index 3f92be3fd3e7..4ca4ef93c54c 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 3f92be3fd3e7d841e0153d32eb8945ed65827225 +Subproject commit 4ca4ef93c54c30001e0cac1da8a681c5af4f3cbb From 28f5d184b3216f8c9ee98c3038c084928b335082 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Dec 2013 14:07:00 +0800 Subject: [PATCH 12/55] Do not depend on node to set include_dirs. Part of atom/node#2. --- atom.gyp | 4 ++++ vendor/node | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/atom.gyp b/atom.gyp index 60f8c77941e7..3a03dd51165b 100644 --- a/atom.gyp +++ b/atom.gyp @@ -329,6 +329,10 @@ 'include_dirs': [ '.', 'vendor', + # Include directories for uv and node. + 'vendor/node/src', + 'vendor/node/deps/http_parser', + 'vendor/node/deps/uv/include', # The `node.h` is using `#include"v8.h"`. 'vendor/brightray/vendor/download/libchromiumcontent/src/v8/include', # The `node.h` is using `#include"ares.h"`. diff --git a/vendor/node b/vendor/node index 4e04c9f0a2d9..e8ddf565e882 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 4e04c9f0a2d97e0b20a0980266917e11f2805280 +Subproject commit e8ddf565e88200dd71bf0d8f652ffc7ff10e66fa From 1c0b391419b035f78b41ee3bce8934f42896eef2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Dec 2013 15:49:08 +0800 Subject: [PATCH 13/55] Fix the black devtools view. Without using UnderlayOpenGLHostingWindow the devtools view would just be black. --- browser/ui/atom_event_processing_window.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/browser/ui/atom_event_processing_window.h b/browser/ui/atom_event_processing_window.h index 92a24712468c..3080084195be 100644 --- a/browser/ui/atom_event_processing_window.h +++ b/browser/ui/atom_event_processing_window.h @@ -7,10 +7,12 @@ #import +#import "ui/base/cocoa/underlay_opengl_hosting_window.h" + // Override NSWindow to access unhandled keyboard events (for command // processing); subclassing NSWindow is the only method to do // this. -@interface AtomEventProcessingWindow : NSWindow { +@interface AtomEventProcessingWindow : UnderlayOpenGLHostingWindow { @private BOOL redispatchingEvent_; BOOL eventHandled_; From 7708e7a8c4a9fe97a0b3c86a74e6400b638ded13 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Dec 2013 16:49:56 +0800 Subject: [PATCH 14/55] Update node for renderer node integration fixes. --- vendor/node | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/node b/vendor/node index e8ddf565e882..9a7dea685069 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit e8ddf565e88200dd71bf0d8f652ffc7ff10e66fa +Subproject commit 9a7dea6850695c4a7c783c721aec0d4e5f1245b4 From 2413eebd7b554688e2268f1294f8bead4f792ce4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 13 Dec 2013 00:57:08 +0800 Subject: [PATCH 15/55] Disable accelerated compositing to fix everything. --- app/atom_main_delegate.cc | 7 ++++++- browser/ui/atom_event_processing_window.h | 4 +--- vendor/brightray | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/atom_main_delegate.cc b/app/atom_main_delegate.cc index 4a9581e34315..1f3d9cb69039 100644 --- a/app/atom_main_delegate.cc +++ b/app/atom_main_delegate.cc @@ -46,9 +46,14 @@ void AtomMainDelegate::PreSandboxStartup() { #endif InitializeResourceBundle(); - // Disable renderer sandbox for most of node's functions. CommandLine* command_line = CommandLine::ForCurrentProcess(); + + // Disable renderer sandbox for most of node's functions. command_line->AppendSwitch(switches::kNoSandbox); + + // Disable accelerated compositing since it caused a lot of troubles (black + // devtools, screen flashes) and needed lots of effort to make it right. + command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); } void AtomMainDelegate::InitializeResourceBundle() { diff --git a/browser/ui/atom_event_processing_window.h b/browser/ui/atom_event_processing_window.h index 3080084195be..92a24712468c 100644 --- a/browser/ui/atom_event_processing_window.h +++ b/browser/ui/atom_event_processing_window.h @@ -7,12 +7,10 @@ #import -#import "ui/base/cocoa/underlay_opengl_hosting_window.h" - // Override NSWindow to access unhandled keyboard events (for command // processing); subclassing NSWindow is the only method to do // this. -@interface AtomEventProcessingWindow : UnderlayOpenGLHostingWindow { +@interface AtomEventProcessingWindow : NSWindow { @private BOOL redispatchingEvent_; BOOL eventHandled_; diff --git a/vendor/brightray b/vendor/brightray index 4ca4ef93c54c..927194b05eaf 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 4ca4ef93c54c30001e0cac1da8a681c5af4f3cbb +Subproject commit 927194b05eafd56df6633d225919a65d2e2812ee From 886ebdb0029478629c785a1373c546ee1cc0de23 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 14:20:28 +0800 Subject: [PATCH 16/55] Use node's Environment feature to add "require" in renderer. --- app/atom_main_delegate.cc | 3 + atom.gyp | 8 +- browser/api/lib/app.coffee | 2 +- browser/atom/atom-renderer.coffee | 5 - browser/atom_browser_main_parts.cc | 14 +- browser/{atom/atom.coffee => lib/init.coffee} | 5 +- browser/{atom => lib}/objects-registry.coffee | 0 browser/{atom => lib}/rpc-server.coffee | 0 common/node_bindings.cc | 168 ++++++++++-------- common/node_bindings.h | 21 +-- common/v8/node_common.h | 4 +- renderer/atom_render_view_observer.cc | 65 +++---- renderer/atom_render_view_observer.h | 1 - renderer/atom_renderer_client.cc | 25 +-- renderer/lib/init.coffee | 23 +++ vendor/node | 2 +- 16 files changed, 180 insertions(+), 166 deletions(-) delete mode 100644 browser/atom/atom-renderer.coffee rename browser/{atom/atom.coffee => lib/init.coffee} (94%) rename browser/{atom => lib}/objects-registry.coffee (100%) rename browser/{atom => lib}/rpc-server.coffee (100%) create mode 100644 renderer/lib/init.coffee diff --git a/app/atom_main_delegate.cc b/app/atom_main_delegate.cc index 1f3d9cb69039..47718e22baa3 100644 --- a/app/atom_main_delegate.cc +++ b/app/atom_main_delegate.cc @@ -54,6 +54,9 @@ void AtomMainDelegate::PreSandboxStartup() { // Disable accelerated compositing since it caused a lot of troubles (black // devtools, screen flashes) and needed lots of effort to make it right. command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); + + // Add a flag to mark the end of switches added by atom-shell. + command_line->AppendSwitch("no-more-switches"); } void AtomMainDelegate::InitializeResourceBundle() { diff --git a/atom.gyp b/atom.gyp index 3a03dd51165b..63562cfa4e71 100644 --- a/atom.gyp +++ b/atom.gyp @@ -21,15 +21,15 @@ 'browser/api/lib/menu-item.coffee', 'browser/api/lib/power-monitor.coffee', 'browser/api/lib/protocol.coffee', - 'browser/atom/atom.coffee', - 'browser/atom/atom-renderer.coffee', - 'browser/atom/objects-registry.coffee', - 'browser/atom/rpc-server.coffee', + 'browser/lib/init.coffee', + 'browser/lib/objects-registry.coffee', + 'browser/lib/rpc-server.coffee', 'common/api/lib/callbacks-registry.coffee', 'common/api/lib/clipboard.coffee', 'common/api/lib/crash-reporter.coffee', 'common/api/lib/id-weak-map.coffee', 'common/api/lib/shell.coffee', + 'renderer/lib/init.coffee', 'renderer/api/lib/ipc.coffee', 'renderer/api/lib/remote.coffee', ], diff --git a/browser/api/lib/app.coffee b/browser/api/lib/app.coffee index 9fc9664ed423..e578c3ef7d3c 100644 --- a/browser/api/lib/app.coffee +++ b/browser/api/lib/app.coffee @@ -10,7 +10,7 @@ app.getHomeDir = -> process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME'] app.getBrowserWindows = -> - require('../../atom/objects-registry.js').getAllWindows() + require('../../lib/objects-registry.js').getAllWindows() app.setApplicationMenu = (menu) -> require('menu').setApplicationMenu menu diff --git a/browser/atom/atom-renderer.coffee b/browser/atom/atom-renderer.coffee deleted file mode 100644 index 8430d183340d..000000000000 --- a/browser/atom/atom-renderer.coffee +++ /dev/null @@ -1,5 +0,0 @@ -path = require 'path' - -process.__atom_type = 'renderer' -process.resourcesPath = path.resolve process.argv[1], '..', '..', '..' -process.argv.splice 1, 1 diff --git a/browser/atom_browser_main_parts.cc b/browser/atom_browser_main_parts.cc index 2328fda1bb29..3c3b2e70196e 100644 --- a/browser/atom_browser_main_parts.cc +++ b/browser/atom_browser_main_parts.cc @@ -43,9 +43,19 @@ void AtomBrowserMainParts::PostEarlyInitialization() { node_bindings_->Initialize(); - // Wrap whole process in one global context. - global_env->context()->Enter(); + v8::V8::Initialize(); + // Create context. + v8::HandleScope handle_scope(node_isolate); + v8::Local context = v8::Context::New(node_isolate); + + // Wrap whole process in one global context. + context->Enter(); + + // Create the global environment. + global_env = node_bindings_->CreateEnvironment(context); + + // Add atom-shell extended APIs. atom_bindings_->BindTo(global_env->process_object()); atom_bindings_->AfterLoad(); } diff --git a/browser/atom/atom.coffee b/browser/lib/init.coffee similarity index 94% rename from browser/atom/atom.coffee rename to browser/lib/init.coffee index 6212dd0b2959..a9393f16aa5d 100644 --- a/browser/atom/atom.coffee +++ b/browser/lib/init.coffee @@ -1,9 +1,12 @@ fs = require 'fs' path = require 'path' -# Restore the proces.argv. +# Expose information of current process. process.__atom_type = 'browser' process.resourcesPath = path.resolve process.argv[1], '..', '..', '..' + +# We modified the original process.argv to let node.js load the atom.js, +# we need to restore it here. process.argv.splice 1, 1 if process.platform is 'win32' diff --git a/browser/atom/objects-registry.coffee b/browser/lib/objects-registry.coffee similarity index 100% rename from browser/atom/objects-registry.coffee rename to browser/lib/objects-registry.coffee diff --git a/browser/atom/rpc-server.coffee b/browser/lib/rpc-server.coffee similarity index 100% rename from browser/atom/rpc-server.coffee rename to browser/lib/rpc-server.coffee diff --git a/common/node_bindings.cc b/common/node_bindings.cc index 9bda801b95f2..a2fe827d71a0 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -13,9 +13,6 @@ #include "base/path_service.h" #include "common/v8/native_type_conversions.h" #include "content/public/browser/browser_thread.h" -#include "net/base/escape.h" -#include "third_party/WebKit/public/web/WebDocument.h" -#include "third_party/WebKit/public/web/WebFrame.h" #include "vendor/node/src/node_javascript.h" #if defined(OS_WIN) @@ -28,24 +25,42 @@ using content::BrowserThread; // Forward declaration of internal node functions. namespace node { -void Init(int* argc, - const char** argv, - int* exec_argc, - const char*** exec_argv); -Environment* CreateEnvironment(v8::Isolate* isolate, - int argc, - const char* const* argv, - int exec_argc, - const char* const* exec_argv); +void Init(int*, const char**, int*, const char***); +void Load(Environment* env); +void SetupProcessObject(Environment*, int, const char* const*, int, + const char* const*); } namespace atom { namespace { +// Empty callback for async handle. void UvNoOp(uv_async_t* handle, int status) { } +// Convert the given vector to an array of C-strings. The strings in the +// returned vector are only guaranteed valid so long as the vector of strings +// is not modified. +scoped_ptr StringVectorToArgArray( + const std::vector& vector) { + scoped_ptr array(new const char*[vector.size()]); + for (size_t i = 0; i < vector.size(); ++i) + array[i] = vector[i].c_str(); + return array.Pass(); +} + +#if defined(OS_WIN) +std::vector String16VectorToStringVector( + const std::vector& vector) { + std::vector utf8_vector; + utf8_vector.reserve(vector.size()); + for (size_t i = 0; i < vector.size(); ++i) + utf8_vector.push_back(UTF16ToUTF8(vector[i])); + return utf8_vector; +} +#endif + } // namespace node::Environment* global_env = NULL; @@ -73,42 +88,6 @@ NodeBindings::~NodeBindings() { } void NodeBindings::Initialize() { - CommandLine::StringVector str_argv = CommandLine::ForCurrentProcess()->argv(); - -#if defined(OS_WIN) - std::vector utf8_str_argv; - utf8_str_argv.reserve(str_argv.size()); -#endif - - // Convert string vector to const char* array. - std::vector args(str_argv.size(), NULL); - for (size_t i = 0; i < str_argv.size(); ++i) { -#if defined(OS_WIN) - utf8_str_argv.push_back(UTF16ToUTF8(str_argv[i])); - args[i] = utf8_str_argv[i].c_str(); -#else - args[i] = str_argv[i].c_str(); -#endif - } - - // Feed node the path to initialization script. - base::FilePath exec_path(str_argv[0]); - PathService::Get(base::FILE_EXE, &exec_path); - base::FilePath resources_path = -#if defined(OS_MACOSX) - is_browser_ ? exec_path.DirName().DirName().Append("Resources") : - exec_path.DirName().DirName().DirName().DirName().DirName() - .Append("Resources"); -#else - exec_path.DirName().Append("resources"); -#endif - base::FilePath script_path = - resources_path.AppendASCII("browser") - .AppendASCII("atom") - .AppendASCII(is_browser_ ? "atom.js" : "atom-renderer.js"); - std::string script_path_str = script_path.AsUTF8Unsafe(); - args.insert(args.begin() + 1, script_path_str.c_str()); - // Init idle GC for browser. if (is_browser_) { uv_timer_init(uv_default_loop(), &idle_timer_); @@ -120,43 +99,76 @@ void NodeBindings::Initialize() { node::g_upstream_node_mode = false; // Init node. - int argc = args.size(); - const char** argv = &args[0]; - int exec_argc; - const char** exec_argv; - node::Init(&argc, argv, &exec_argc, &exec_argv); - v8::V8::Initialize(); - - // Create environment (setup process object and load node.js). - global_env = node::CreateEnvironment(node_isolate, argc, argv, argc, argv); + // (we assume it would not node::Init would not modify the parameters under + // embedded mode). + node::Init(NULL, NULL, NULL, NULL); } -void NodeBindings::BindTo(WebKit::WebFrame* frame) { - v8::HandleScope handle_scope(node_isolate); +node::Environment* NodeBindings::CreateEnvironment( + v8::Handle context) { + std::vector args = +#if defined(OS_WIN) + String16VectorToStringVector(CommandLine::ForCurrentProcess()->argv()); +#else + CommandLine::ForCurrentProcess()->argv(); +#endif - v8::Handle context = frame->mainWorldScriptContext(); - if (context.IsEmpty()) - return; + // Feed node the path to initialization script. + base::FilePath exec_path(args[0]); + PathService::Get(base::FILE_EXE, &exec_path); + base::FilePath resources_path = +#if defined(OS_MACOSX) + is_browser_ ? exec_path.DirName().DirName().Append("Resources") : + exec_path.DirName().DirName().DirName().DirName().DirName() + .Append("Resources"); +#else + exec_path.DirName().Append("resources"); +#endif + base::FilePath script_path = + resources_path.AppendASCII(is_browser_ ? "browser" : "renderer") + .AppendASCII("lib") + .AppendASCII("init.js"); + std::string script_path_str = script_path.AsUTF8Unsafe(); + args.insert(args.begin() + 1, script_path_str.c_str()); - v8::Context::Scope scope(context); + // Convert string vector to const char* array. + scoped_ptr c_argv = StringVectorToArgArray(args); - // Erase security token. - context->SetSecurityToken(global_env->context()->GetSecurityToken()); + // Construct the parameters that passed to node::CreateEnvironment: + v8::Isolate* isolate = context->GetIsolate(); + int argc = args.size(); + const char** argv = c_argv.get(); + int exec_argc = 0; + const char** exec_argv = NULL; - // Evaluate cefode.js. - v8::Handle script = node::CompileCefodeMainSource(); - v8::Local result = script->Run(); + using namespace v8; // NOLINT + using namespace node; // NOLINT - // Run the script of cefode.js. - std::string script_path(GURL(frame->document().url()).path()); - script_path = net::UnescapeURLComponent( - script_path, - net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); - v8::Handle args[2] = { - global_env->process_object(), - ToV8Value(script_path), - }; - v8::Local::Cast(result)->Call(context->Global(), 2, args); + // Following code are stripped from node::CreateEnvironment in node.cc: + HandleScope handle_scope(isolate); + + Environment* env = Environment::New(context); + + uv_check_init(env->event_loop(), env->immediate_check_handle()); + uv_unref( + reinterpret_cast(env->immediate_check_handle())); + uv_idle_init(env->event_loop(), env->immediate_idle_handle()); + + uv_prepare_init(env->event_loop(), env->idle_prepare_handle()); + uv_check_init(env->event_loop(), env->idle_check_handle()); + uv_unref(reinterpret_cast(env->idle_prepare_handle())); + uv_unref(reinterpret_cast(env->idle_check_handle())); + + Local process_template = FunctionTemplate::New(); + process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "process")); + + Local process_object = process_template->GetFunction()->NewInstance(); + env->set_process_object(process_object); + + SetupProcessObject(env, argc, argv, exec_argc, exec_argv); + Load(env); + + return env; } void NodeBindings::PrepareMessageLoop() { diff --git a/common/node_bindings.h b/common/node_bindings.h index a9ac5852a129..7ed22806d115 100644 --- a/common/node_bindings.h +++ b/common/node_bindings.h @@ -2,20 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef RAVE_COMMON_NODE_BINDINGS_ -#define RAVE_COMMON_NODE_BINDINGS_ +#ifndef ATOM_COMMON_NODE_BINDINGS_H_ +#define ATOM_COMMON_NODE_BINDINGS_H_ #include "base/basictypes.h" +#include "v8/include/v8.h" #include "vendor/node/deps/uv/include/uv.h" -namespace WebKit { -class WebFrame; -} - namespace base { class MessageLoop; } +namespace node { +class Environment; +} + namespace atom { class NodeBindings { @@ -24,11 +25,11 @@ class NodeBindings { virtual ~NodeBindings(); - // Setup V8, libuv and the process object, then load the node.js script. + // Setup V8, libuv. virtual void Initialize(); - // Load cefode.js script under web frame. - virtual void BindTo(WebKit::WebFrame* frame); + // Create the environment and load node.js. + virtual node::Environment* CreateEnvironment(v8::Handle context); // Prepare for message loop integration. virtual void PrepareMessageLoop(); @@ -87,4 +88,4 @@ class NodeBindings { } // namespace atom -#endif // RAVE_COMMON_NODE_BINDINGS_ +#endif // ATOM_COMMON_NODE_BINDINGS_H_ diff --git a/common/v8/node_common.h b/common/v8/node_common.h index 5b8147f93122..7174b902a59e 100644 --- a/common/v8/node_common.h +++ b/common/v8/node_common.h @@ -5,7 +5,7 @@ #ifndef ATOM_COMMON_V8_NODE_COMMON_H_ #define ATOM_COMMON_V8_NODE_COMMON_H_ -// Common helper for using node APIs. +// Include common headers for using node APIs. #undef CHECK #undef DISALLOW_COPY_AND_ASSIGN @@ -16,6 +16,8 @@ using node::node_isolate; namespace atom { // Defined in node_bindings.cc. +// For renderer it's created in atom_renderer_client.cc. +// For browser it's created in atom_browser_main_parts.cc. extern node::Environment* global_env; } diff --git a/renderer/atom_render_view_observer.cc b/renderer/atom_render_view_observer.cc index dd4dfbe553db..673435e048e1 100644 --- a/renderer/atom_render_view_observer.cc +++ b/renderer/atom_render_view_observer.cc @@ -4,9 +4,6 @@ #include "renderer/atom_render_view_observer.h" -#include -#include - #include "common/api/api_messages.h" #include "common/node_bindings.h" #include "ipc/ipc_message_macros.h" @@ -15,69 +12,47 @@ #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebDraggableRegion.h" #include "third_party/WebKit/public/web/WebFrame.h" -#include "v8/include/v8.h" + +#include "common/v8/node_common.h" using WebKit::WebFrame; -namespace webkit { -extern void SetGetFirstWindowContext(v8::Handle (*)()); -extern void SetIsValidWindowContext(bool (*)(v8::Handle)); -} - namespace atom { -namespace { - -std::vector& web_frames() { - CR_DEFINE_STATIC_LOCAL(std::vector, frames, ()); - return frames; -} - -v8::Handle GetFirstWindowContext() { - if (web_frames().size() == 0) - return v8::Handle(); - - return web_frames()[0]->mainWorldScriptContext(); -} - -bool IsValidWindowContext(v8::Handle context) { - size_t size = web_frames().size(); - for (size_t i = 0; i < size; ++i) - if (web_frames()[i]->mainWorldScriptContext() == context) - return true; - - return false; -} - -} // namespace - AtomRenderViewObserver::AtomRenderViewObserver( content::RenderView* render_view, AtomRendererClient* renderer_client) : content::RenderViewObserver(render_view), atom_bindings_(new AtomRendererBindings(render_view)), renderer_client_(renderer_client) { - // Interact with dirty workarounds of extra node context in WebKit. - webkit::SetGetFirstWindowContext(GetFirstWindowContext); - webkit::SetIsValidWindowContext(IsValidWindowContext); } AtomRenderViewObserver::~AtomRenderViewObserver() { } void AtomRenderViewObserver::DidClearWindowObject(WebFrame* frame) { - // Remember the web frame. - web_frames().push_back(frame); + // Get the context. + v8::HandleScope handle_scope(node_isolate); + v8::Handle context = frame->mainWorldScriptContext(); + if (context.IsEmpty()) + return; - renderer_client_->node_bindings()->BindTo(frame); + v8::Context::Scope scope(context); + + // Check the existance of process object to prevent duplicate initialization. + if (context->Global()->Has(v8::String::New("process"))) + return; + + // Give the node loop a run to make sure everything is ready. + renderer_client_->node_bindings()->RunMessageLoop(); + + // Setup node environment for each window. + renderer_client_->node_bindings()->CreateEnvironment(context); + + // Add atom-shell extended APIs. atom_bindings()->BindToFrame(frame); } -void AtomRenderViewObserver::FrameWillClose(WebFrame* frame) { - std::vector& vec = web_frames(); - vec.erase(std::remove(vec.begin(), vec.end(), frame), vec.end()); -} - void AtomRenderViewObserver::DraggableRegionsChanged(WebKit::WebFrame* frame) { WebKit::WebVector webregions = frame->document().draggableRegions(); diff --git a/renderer/atom_render_view_observer.h b/renderer/atom_render_view_observer.h index d8d90e0cb4b1..12c15fa63675 100644 --- a/renderer/atom_render_view_observer.h +++ b/renderer/atom_render_view_observer.h @@ -28,7 +28,6 @@ class AtomRenderViewObserver : content::RenderViewObserver { virtual ~AtomRenderViewObserver(); virtual void DidClearWindowObject(WebKit::WebFrame*) OVERRIDE; - virtual void FrameWillClose(WebKit::WebFrame*) OVERRIDE; private: // content::RenderViewObserver implementation. diff --git a/renderer/atom_renderer_client.cc b/renderer/atom_renderer_client.cc index 183d2d57ca4c..3574b02cacad 100644 --- a/renderer/atom_renderer_client.cc +++ b/renderer/atom_renderer_client.cc @@ -9,20 +9,8 @@ #include "common/v8/node_common.h" -namespace webkit { -extern void SetGetNodeContext(v8::Handle (*)()); -} - namespace atom { -namespace { - -v8::Handle GetNodeContext() { - return global_env->context(); -} - -} // namespace - AtomRendererClient::AtomRendererClient() : node_bindings_(NodeBindings::Create(false)) { } @@ -32,12 +20,15 @@ AtomRendererClient::~AtomRendererClient() { void AtomRendererClient::RenderThreadStarted() { node_bindings_->Initialize(); - - // Interact with dirty workarounds of extra node context in WebKit. - webkit::SetGetNodeContext(GetNodeContext); - node_bindings_->PrepareMessageLoop(); - node_bindings_->RunMessageLoop(); + + DCHECK(!global_env); + + // Create a default empty environment which would be used when we need to + // run V8 code out of a window context (like running a uv callback). + v8::HandleScope handle_scope(node_isolate); + v8::Local context = v8::Context::New(node_isolate); + global_env = node::Environment::New(context); } void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) { diff --git a/renderer/lib/init.coffee b/renderer/lib/init.coffee new file mode 100644 index 000000000000..8a14c69128d1 --- /dev/null +++ b/renderer/lib/init.coffee @@ -0,0 +1,23 @@ +path = require 'path' + +# Expose information of current process. +process.__atom_type = 'renderer' +process.resourcesPath = path.resolve process.argv[1], '..', '..', '..' + +# We modified the original process.argv to let node.js load the +# atom-renderer.js, we need to restore it here. +process.argv.splice 1, 1 + +# Add renderer/api/lib to require's search paths, which contains javascript part +# of Atom's built-in libraries. +globalPaths = require('module').globalPaths +globalPaths.push path.join process.resourcesPath, 'renderer', 'api', 'lib' + +# And also common/api/lib +globalPaths.push path.join process.resourcesPath, 'common', 'api', 'lib' + +# Expose global variables. +global.require = require +global.module = module +global.__filename = __filename +global.__dirname = __dirname diff --git a/vendor/node b/vendor/node index 9a7dea685069..2fce49829b4d 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 9a7dea6850695c4a7c783c721aec0d4e5f1245b4 +Subproject commit 2fce49829b4dde69bceed91c00cec578517541b0 From aa3e8385df8b117b432201a9f5fdd9eca6519c06 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 16:11:00 +0800 Subject: [PATCH 17/55] Set __filename to the html file in renderer. --- common/node_bindings.cc | 4 ---- renderer/lib/init.coffee | 25 ++++++++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/common/node_bindings.cc b/common/node_bindings.cc index a2fe827d71a0..98cca1829b3c 100644 --- a/common/node_bindings.cc +++ b/common/node_bindings.cc @@ -4,16 +4,12 @@ #include "common/node_bindings.h" -#include // PATH_MAX - #include "base/command_line.h" -#include "base/logging.h" #include "base/message_loop/message_loop.h" #include "base/base_paths.h" #include "base/path_service.h" #include "common/v8/native_type_conversions.h" #include "content/public/browser/browser_thread.h" -#include "vendor/node/src/node_javascript.h" #if defined(OS_WIN) #include "base/strings/utf_string_conversions.h" diff --git a/renderer/lib/init.coffee b/renderer/lib/init.coffee index 8a14c69128d1..01fbcbdc29e2 100644 --- a/renderer/lib/init.coffee +++ b/renderer/lib/init.coffee @@ -1,4 +1,5 @@ path = require 'path' +Module = require 'module' # Expose information of current process. process.__atom_type = 'renderer' @@ -10,14 +11,24 @@ process.argv.splice 1, 1 # Add renderer/api/lib to require's search paths, which contains javascript part # of Atom's built-in libraries. -globalPaths = require('module').globalPaths -globalPaths.push path.join process.resourcesPath, 'renderer', 'api', 'lib' - -# And also common/api/lib -globalPaths.push path.join process.resourcesPath, 'common', 'api', 'lib' +globalPaths = Module.globalPaths +globalPaths.push path.join(process.resourcesPath, 'renderer', 'api', 'lib') +# And also common/api/lib. +globalPaths.push path.join(process.resourcesPath, 'common', 'api', 'lib') +# And also app. +globalPaths.push path.join(process.resourcesPath, 'app') # Expose global variables. global.require = require global.module = module -global.__filename = __filename -global.__dirname = __dirname + +# Set the __filename to the path of html file if it's file:// protocol. +if window.location.protocol is 'file:' + global.__filename = window.location.pathname + global.__dirname = path.dirname global.__filename + + # Also search for module under the html file. + module.paths = module.paths.concat Module._nodeModulePaths(global.__dirname) +else + global.__filename = __filename + global.__dirname = __dirname From cc5db4dab9411e4bb288c67bc24ecbf1be41d4e3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 16:15:18 +0800 Subject: [PATCH 18/55] Suppress the EventEmitter's warning for ObjectsRegistry. It's possible that many objects subscribed to it. --- browser/lib/objects-registry.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/browser/lib/objects-registry.coffee b/browser/lib/objects-registry.coffee index df2ad535244d..12063fed3f3b 100644 --- a/browser/lib/objects-registry.coffee +++ b/browser/lib/objects-registry.coffee @@ -41,6 +41,8 @@ class ObjectsStore class ObjectsRegistry extends EventEmitter constructor: -> + @setMaxListeners Number.MAX_VALUE + # Objects in weak map will be not referenced (so we won't leak memory), and # every object created in browser will have a unique id in weak map. @objectsWeakMap = new IDWeakMap From 7ba03ce23dda588b9b5fa0735e5f437ea467d146 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 16:21:23 +0800 Subject: [PATCH 19/55] Add setImmediate function in renderer. --- renderer/lib/init.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/renderer/lib/init.coffee b/renderer/lib/init.coffee index 01fbcbdc29e2..32d3d2ac61d5 100644 --- a/renderer/lib/init.coffee +++ b/renderer/lib/init.coffee @@ -1,4 +1,5 @@ -path = require 'path' +path = require 'path' +timers = require 'timers' Module = require 'module' # Expose information of current process. @@ -21,6 +22,10 @@ globalPaths.push path.join(process.resourcesPath, 'app') # Expose global variables. global.require = require global.module = module +global.setImmediate = -> + process.activateUvLoop() + timers.setImmediate.apply this, arguments +global.clearImmediate = timers.clearImmediate # Set the __filename to the path of html file if it's file:// protocol. if window.location.protocol is 'file:' From 0a84c30d3ba48c4591b1299fbef0f9feaab5dcda Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 16:32:41 +0800 Subject: [PATCH 20/55] Redirect window.onerror to uncaughtException. --- renderer/lib/init.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/renderer/lib/init.coffee b/renderer/lib/init.coffee index 32d3d2ac61d5..f481146ace62 100644 --- a/renderer/lib/init.coffee +++ b/renderer/lib/init.coffee @@ -37,3 +37,11 @@ if window.location.protocol is 'file:' else global.__filename = __filename global.__dirname = __dirname + +# Redirect window.onerror to uncaughtException. +window.onerror = (error) -> + if global.process.listeners('uncaughtException').length > 0 + global.process.emit 'uncaughtException', error + true + else + false From cfeeec37eb219d0214f97766284e30e2163fcb8c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 16:32:49 +0800 Subject: [PATCH 21/55] Fix capturePage() spec. --- spec/api-browser-window-spec.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/api-browser-window-spec.coffee b/spec/api-browser-window-spec.coffee index bcf308a2803c..c6a7283ff3d3 100644 --- a/spec/api-browser-window-spec.coffee +++ b/spec/api-browser-window-spec.coffee @@ -77,10 +77,11 @@ describe 'browser-window module', -> w.close() describe 'BrowserWindow.capturePage(rect, callback)', -> - it 'calls the callback with a Buffer', -> + it 'calls the callback with a Buffer', (done) -> w = new BrowserWindow(show: false) w.capturePage {x: 0, y: 0, width: 100, height: 100}, (image) -> - assert.equal image.constructor.name, 'SlowBuffer' + assert.equal image.constructor.name, 'Buffer' + done() w.close() describe 'beforeunload handler', -> From 474e1fcd3b79e8d5028fd925d453d854d0ab9fa5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 16:53:07 +0800 Subject: [PATCH 22/55] Fix protocol module specs. --- browser/api/atom_api_protocol.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/browser/api/atom_api_protocol.cc b/browser/api/atom_api_protocol.cc index f7e49a23b2f2..01dc0de4bac0 100644 --- a/browser/api/atom_api_protocol.cc +++ b/browser/api/atom_api_protocol.cc @@ -188,7 +188,7 @@ void Protocol::RegisterProtocol( return node::ThrowTypeError("Bad argument"); if (g_handlers.find(scheme) != g_handlers.end() || - net::URLRequest::IsHandledProtocol(scheme)) + GetRequestJobFactory()->IsHandledProtocol(scheme)) return node::ThrowError("The scheme is already registered"); if (AtomBrowserContext::Get()->url_request_context_getter() == NULL) @@ -226,8 +226,11 @@ void Protocol::UnregisterProtocol( // static void Protocol::IsHandledProtocol( const v8::FunctionCallbackInfo& args) { - std::string scheme = FromV8Value(args[0]); - args.GetReturnValue().Set(net::URLRequest::IsHandledProtocol(scheme)); + std::string scheme; + if (!FromV8Arguments(args, &scheme)) + return node::ThrowTypeError("Bad argument"); + + args.GetReturnValue().Set(GetRequestJobFactory()->IsHandledProtocol(scheme)); } // static @@ -361,7 +364,7 @@ void Protocol::UninterceptProtocolInIO(const std::string& scheme) { // static void Protocol::Initialize(v8::Handle target) { // Remember the protocol object, used for emitting event later. - g_protocol_object.reset(v8::Object::New()); + g_protocol_object.reset(target); NODE_SET_METHOD(target, "registerProtocol", RegisterProtocol); NODE_SET_METHOD(target, "unregisterProtocol", UnregisterProtocol); From cd68396bd519c3e6ddb31bc097e257541d9b3035 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 17:02:43 +0800 Subject: [PATCH 23/55] Disable use of deprecated functions in specs. --- spec/api-crash-reporter-spec.coffee | 2 ++ spec/static/index.html | 3 +++ 2 files changed, 5 insertions(+) diff --git a/spec/api-crash-reporter-spec.coffee b/spec/api-crash-reporter-spec.coffee index 0555d804c64f..3aad097239d0 100644 --- a/spec/api-crash-reporter-spec.coffee +++ b/spec/api-crash-reporter-spec.coffee @@ -13,7 +13,9 @@ describe 'crash-reporter module', -> w = new BrowserWindow(show: false) server = http.createServer (req, res) -> form = new formidable.IncomingForm() + process.throwDeprecation = false form.parse req, (error, fields, files) -> + process.throwDeprecation = true assert.equal fields['prod'], 'Atom-Shell' assert.equal fields['ver'], process.versions['atom-shell'] assert.equal fields['process_type'], 'renderer' diff --git a/spec/static/index.html b/spec/static/index.html index 351af228a5b9..cb3d76c05bf7 100644 --- a/spec/static/index.html +++ b/spec/static/index.html @@ -10,6 +10,9 @@