Adapt to API changes of Chromium and node.

This commit is contained in:
Cheng Zhao 2014-06-28 22:33:00 +08:00
parent 58ccb27792
commit cd4c5d976b
55 changed files with 281 additions and 402 deletions

View file

@ -167,8 +167,6 @@
'atom/common/api/atom_api_v8_util.cc',
'atom/common/api/atom_bindings.cc',
'atom/common/api/atom_bindings.h',
'atom/common/api/atom_extensions.cc',
'atom/common/api/atom_extensions.h',
'atom/common/api/object_life_monitor.cc',
'atom/common/api/object_life_monitor.h',
'atom/common/browser_v8_locker.cc',
@ -382,6 +380,7 @@
'<(libchromiumcontent_library_dir)/icudt.dll',
'<(libchromiumcontent_library_dir)/libEGL.dll',
'<(libchromiumcontent_library_dir)/libGLESv2.dll',
'<(libchromiumcontent_resources_dir)/icudtl.dat',
'<(libchromiumcontent_resources_dir)/content_shell.pak',
'external_binaries/d3dcompiler_43.dll',
'external_binaries/xinput1_3.dll',
@ -402,6 +401,7 @@
'files': [
'<(libchromiumcontent_library_dir)/libchromiumcontent.so',
'<(libchromiumcontent_library_dir)/libffmpegsumo.so',
'<(libchromiumcontent_resources_dir)/icudtl.dat',
'<(libchromiumcontent_resources_dir)/content_shell.pak',
],
},
@ -663,6 +663,7 @@
'mac_bundle_resources': [
'atom/common/resources/mac/MainMenu.xib',
'<(libchromiumcontent_resources_dir)/content_shell.pak',
'<(libchromiumcontent_resources_dir)/icudtl.dat',
],
'xcode_settings': {
'INFOPLIST_FILE': 'atom/common/resources/mac/Info.plist',

View file

@ -10,6 +10,6 @@
#if defined(OS_MACOSX)
int AtomMain(int argc, const char* argv[]) {
atom::AtomMainDelegate delegate;
return content::ContentMain(argc, argv, &delegate);
return content::ContentMain(content::ContentMainParams(&delegate));
}
#endif // OS_MACOSX

View file

@ -140,4 +140,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_browser_app, Initialize)
NODE_MODULE_X(atom_browser_app, Initialize, NULL, NM_F_BUILTIN)

View file

@ -93,4 +93,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_browser_auto_updater, Initialize)
NODE_MODULE_X(atom_browser_auto_updater, Initialize, NULL, NM_F_BUILTIN)

View file

@ -85,4 +85,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_browser_dialog, Initialize)
NODE_MODULE_X(atom_browser_dialog, Initialize, NULL, NM_F_BUILTIN)

View file

@ -278,4 +278,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_browser_menu, Initialize)
NODE_MODULE_X(atom_browser_menu, Initialize, NULL, NM_F_BUILTIN)

View file

@ -63,4 +63,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_browser_power_monitor, Initialize)
NODE_MODULE_X(atom_browser_power_monitor, Initialize, NULL, NM_F_BUILTIN)

View file

@ -334,4 +334,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_browser_protocol, Initialize)
NODE_MODULE_X(atom_browser_protocol, Initialize, NULL, NM_F_BUILTIN)

View file

@ -80,4 +80,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_browser_tray, Initialize)
NODE_MODULE_X(atom_browser_tray, Initialize, NULL, NM_F_BUILTIN)

View file

@ -399,4 +399,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_browser_window, Initialize)
NODE_MODULE_X(atom_browser_window, Initialize, NULL, NM_F_BUILTIN)

View file

@ -44,7 +44,8 @@ AtomBrowserClient::~AtomBrowserClient() {
net::URLRequestContextGetter* AtomBrowserClient::CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers) {
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) {
return static_cast<AtomBrowserContext*>(browser_context)->
CreateRequestContext(protocol_handlers);
}
@ -77,7 +78,7 @@ void AtomBrowserClient::OverrideWebkitPrefs(
window->OverrideWebkitPrefs(url, prefs);
}
bool AtomBrowserClient::ShouldSwapProcessesForNavigation(
bool AtomBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
content::SiteInstance* site_instance,
const GURL& current_url,
const GURL& new_url) {
@ -94,7 +95,7 @@ std::string AtomBrowserClient::GetApplicationLocale() {
}
void AtomBrowserClient::AppendExtraCommandLineSwitches(
CommandLine* command_line,
base::CommandLine* command_line,
int child_process_id) {
WindowList* list = WindowList::GetInstance();
NativeWindow* window = NULL;

View file

@ -19,16 +19,17 @@ class AtomBrowserClient : public brightray::BrowserClient {
protected:
net::URLRequestContextGetter* CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
content::ProtocolHandlerMap* protocol_handlers,
content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE;
virtual void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
const GURL& url,
WebPreferences* prefs) OVERRIDE;
virtual bool ShouldSwapProcessesForNavigation(
virtual bool ShouldSwapBrowsingInstancesForNavigation(
content::SiteInstance* site_instance,
const GURL& current_url,
const GURL& new_url) OVERRIDE;
virtual std::string GetApplicationLocale() OVERRIDE;
virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
int child_process_id) OVERRIDE;
private:

View file

@ -63,7 +63,7 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
context->Enter();
// Add atom-shell extended APIs.
atom_bindings_->BindTo(global_env->process_object());
atom_bindings_->BindTo(isolate, global_env->process_object());
}
void AtomBrowserMainParts::PreMainMessageLoopRun() {

View file

@ -34,11 +34,13 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/common/renderer_preferences.h"
#include "content/public/common/user_agent.h"
#include "ipc/ipc_message_macros.h"
#include "native_mate/dictionary.h"
#include "ui/gfx/codec/png_codec.h"
@ -49,7 +51,6 @@
#include "ui/gfx/size.h"
#include "vendor/brightray/browser/inspectable_web_contents.h"
#include "vendor/brightray/browser/inspectable_web_contents_view.h"
#include "webkit/common/user_agent/user_agent_util.h"
#include "webkit/common/webpreferences.h"
using content::NavigationEntry;
@ -104,7 +105,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
browser->GetVersion().c_str(),
CHROME_VERSION_STRING);
web_contents->GetMutableRendererPrefs()->user_agent_override =
webkit_glue::BuildUserAgentFromProduct(product_name);
content::BuildUserAgentFromProduct(product_name);
// Get notified of title updated message.
registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
@ -271,7 +272,8 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
size,
base::Bind(&NativeWindow::OnCapturePageDone,
weak_factory_.GetWeakPtr(),
callback));
callback),
SkBitmap::kARGB_8888_Config);
}
void NativeWindow::DestroyWebContents() {
@ -305,7 +307,7 @@ void NativeWindow::CloseWebContents() {
ScheduleUnresponsiveEvent(5000);
if (web_contents->NeedToFireBeforeUnload())
web_contents->GetRenderViewHost()->FirePageBeforeUnload(false);
web_contents->GetMainFrame()->DispatchBeforeUnload(false);
else
web_contents->Close();
}
@ -322,8 +324,8 @@ content::WebContents* NativeWindow::GetDevToolsWebContents() const {
return inspectable_web_contents()->devtools_web_contents();
}
void NativeWindow::AppendExtraCommandLineSwitches(CommandLine* command_line,
int child_process_id) {
void NativeWindow::AppendExtraCommandLineSwitches(
base::CommandLine* command_line, int child_process_id) {
// Append --node-integration to renderer process.
command_line->AppendSwitchASCII(switches::kNodeIntegration,
node_integration_);
@ -542,7 +544,7 @@ void NativeWindow::DevToolsSaveToFile(const std::string& url,
}
saved_files_[url] = path;
file_util::WriteFile(path, content.data(), content.size());
base::WriteFile(path, content.data(), content.size());
// Notify devtools.
base::StringValue url_value(url);
@ -557,7 +559,7 @@ void NativeWindow::DevToolsAppendToFile(const std::string& url,
PathsMap::iterator it = saved_files_.find(url);
if (it == saved_files_.end())
return;
file_util::AppendToFile(it->second, content.data(), content.size());
base::AppendToFile(it->second, content.data(), content.size());
// Notify devtools.
base::StringValue url_value(url);
@ -614,7 +616,7 @@ void NativeWindow::CallDevToolsFunction(const std::string& function_name,
}
}
GetDevToolsWebContents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
string16(), base::UTF8ToUTF16(function_name + "(" + params + ");"));
base::string16(), base::UTF8ToUTF16(function_name + "(" + params + ");"));
}
} // namespace atom

View file

@ -22,9 +22,12 @@
#include "vendor/brightray/browser/inspectable_web_contents_delegate.h"
#include "vendor/brightray/browser/inspectable_web_contents_impl.h"
class CommandLine;
struct WebPreferences;
namespace base {
class CommandLine;
}
namespace content {
class BrowserContext;
class WebContents;
@ -160,7 +163,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
content::WebContents* GetDevToolsWebContents() const;
// Called when renderer process is going to be started.
void AppendExtraCommandLineSwitches(CommandLine* command_line,
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
int child_process_id);
void OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs);

View file

@ -418,7 +418,7 @@ void NativeWindowGtk::UpdateDraggableRegions(
void NativeWindowGtk::HandleKeyboardEvent(
content::WebContents*,
const content::NativeWebKeyboardEvent& event) {
if (event.type == WebKit::WebInputEvent::RawKeyDown) {
if (event.type == blink::WebInputEvent::RawKeyDown) {
GdkEventKey* os_event = reinterpret_cast<GdkEventKey*>(event.os_event);
ui::Accelerator accelerator = ui::AcceleratorForGdkKeyCodeAndModifier(
os_event->keyval, static_cast<GdkModifierType>(os_event->state));

View file

@ -469,7 +469,7 @@ void NativeWindowWin::UpdateDraggableRegions(
void NativeWindowWin::HandleKeyboardEvent(
content::WebContents*,
const content::NativeWebKeyboardEvent& event) {
if (event.type == WebKit::WebInputEvent::RawKeyDown) {
if (event.type == blink::WebInputEvent::RawKeyDown) {
ui::Accelerator accelerator(
static_cast<ui::KeyboardCode>(event.windowsKeyCode),
content::GetModifiersFromNativeWebKeyboardEvent(event));

View file

@ -111,7 +111,7 @@ class NativeWindowWin : public NativeWindow,
virtual views::View* GetInitiallyFocusedView() OVERRIDE;
virtual bool CanResize() const OVERRIDE;
virtual bool CanMaximize() const OVERRIDE;
virtual string16 GetWindowTitle() const OVERRIDE;
virtual base::string16 GetWindowTitle() const OVERRIDE;
virtual bool ShouldHandleSystemCommands() const OVERRIDE;
virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
@ -150,7 +150,7 @@ class NativeWindowWin : public NativeWindow,
bool use_content_size_;
bool resizable_;
string16 title_;
base::string16 title_;
gfx::Size minimum_size_;
gfx::Size maximum_size_;

View file

@ -32,6 +32,7 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
#include "vendor/brightray/browser/network_delegate.h"
#include "webkit/browser/quota/special_storage_policy.h"
namespace atom {
@ -75,18 +76,18 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() {
url_request_context_->set_network_delegate(network_delegate_.get());
storage_.reset(
new net::URLRequestContextStorage(url_request_context_.get()));
storage_->set_cookie_store(content::CreatePersistentCookieStore(
auto cookie_config = content::CookieStoreConfig(
base_path_.Append(FILE_PATH_LITERAL("Cookies")),
false,
content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
nullptr,
nullptr,
nullptr));
nullptr);
storage_->set_cookie_store(content::CreateCookieStore(cookie_config));
storage_->set_server_bound_cert_service(new net::ServerBoundCertService(
new net::DefaultServerBoundCertStore(NULL),
base::WorkerPool::GetTaskRunner(true)));
storage_->set_http_user_agent_settings(
new net::StaticHttpUserAgentSettings(
"en-us,en", EmptyString()));
"en-us,en", base::EmptyString()));
scoped_ptr<net::HostResolver> host_resolver(
net::HostResolver::CreateDefaultResolver(NULL));
@ -163,9 +164,9 @@ net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() {
content::BrowserThread::GetBlockingPool()->
GetTaskRunnerWithShutdownBehavior(
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
job_factory_->SetProtocolHandler(chrome::kDataScheme,
job_factory_->SetProtocolHandler(content::kDataScheme,
new net::DataProtocolHandler);
job_factory_->SetProtocolHandler(chrome::kFileScheme,
job_factory_->SetProtocolHandler(content::kFileScheme,
file_protocol_handler.release());
storage_->set_job_factory(job_factory_);
}

View file

@ -131,7 +131,7 @@ int EventFlagsFromNSEvent(NSEvent* event) {
- (void)addItemToMenu:(NSMenu*)menu
atIndex:(NSInteger)index
fromModel:(ui::MenuModel*)model {
string16 label16 = model->GetLabelAt(index);
base::string16 label16 = model->GetLabelAt(index);
NSString* label = l10n_util::FixUpWindowsStyleLabel(label16);
base::scoped_nsobject<NSMenuItem> item(
[[NSMenuItem alloc] initWithTitle:label

View file

@ -53,7 +53,7 @@ class MessageDialog : public base::MessageLoop::Dispatcher,
virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
// Overridden from views::WidgetDelegate:
virtual string16 GetWindowTitle() const;
virtual base::string16 GetWindowTitle() const;
virtual void WindowClosing() OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
@ -73,7 +73,7 @@ class MessageDialog : public base::MessageLoop::Dispatcher,
bool should_close_;
bool delete_on_close_;
int result_;
string16 title_;
base::string16 title_;
views::Widget* widget_;
views::MessageBoxView* message_box_view_;
scoped_ptr<NativeWindow::DialogScope> dialog_scope_;

View file

@ -55,7 +55,7 @@ struct NativeMenuWin::ItemData {
// The Windows API requires that whoever creates the menus must own the
// strings used for labels, and keep them around for the lifetime of the
// created menu. So be it.
string16 label;
base::string16 label;
// Someone needs to own submenus, it may as well be us.
scoped_ptr<Menu2> submenu;
@ -182,7 +182,7 @@ class NativeMenuWin::MenuHostWindow {
if (data->submenu.get())
measure_item_struct->itemWidth += kArrowWidth;
// If the label contains an accelerator, make room for tab.
if (data->label.find(L'\t') != string16::npos)
if (data->label.find(L'\t') != base::string16::npos)
measure_item_struct->itemWidth += font.GetStringWidth(L" ");
measure_item_struct->itemHeight =
font.GetHeight() + kItemBottomMargin + kItemTopMargin;
@ -238,10 +238,10 @@ class NativeMenuWin::MenuHostWindow {
// left and the accelerator on the right.
// TODO(jungshik): This will break in RTL UI. Currently, he/ar use the
// window system UI font and will not hit here.
string16 label = data->label;
string16 accel;
string16::size_type tab_pos = label.find(L'\t');
if (tab_pos != string16::npos) {
base::string16 label = data->label;
base::string16 accel;
base::string16::size_type tab_pos = label.find(L'\t');
if (tab_pos != base::string16::npos) {
accel = label.substr(tab_pos);
label = label.substr(0, tab_pos);
}
@ -635,7 +635,7 @@ void NativeMenuWin::AddMenuItemAt(int menu_index, int model_index) {
mii.fType = MFT_OWNERDRAW;
ItemData* item_data = new ItemData;
item_data->label = string16();
item_data->label = base::string16();
ui::MenuModel::ItemType type = model_->GetTypeAt(model_index);
if (type == ui::MenuModel::TYPE_SUBMENU) {
item_data->submenu.reset(new Menu2(model_->GetSubmenuModelAt(model_index)));
@ -687,7 +687,7 @@ void NativeMenuWin::SetMenuItemState(int menu_index, bool enabled, bool checked,
void NativeMenuWin::SetMenuItemLabel(int menu_index,
int model_index,
const string16& label) {
const base::string16& label) {
if (IsSeparatorItemAt(menu_index))
return;
@ -699,8 +699,8 @@ void NativeMenuWin::SetMenuItemLabel(int menu_index,
void NativeMenuWin::UpdateMenuItemInfoForString(MENUITEMINFO* mii,
int model_index,
const string16& label) {
string16 formatted = label;
const base::string16& label) {
base::string16 formatted = label;
ui::MenuModel::ItemType type = model_->GetTypeAt(model_index);
// Strip out any tabs, otherwise they get interpreted as accelerators and can
// lead to weird behavior.

View file

@ -94,7 +94,7 @@ class NativeMenuWin {
// Sets the label of the item at the specified index.
void SetMenuItemLabel(int menu_index,
int model_index,
const string16& label);
const base::string16& label);
// Updates the local data structure with the correctly formatted version of
// |label| at the specified model_index, and adds string data to |mii| if
@ -102,7 +102,7 @@ class NativeMenuWin {
// of the peculiarities of the Windows menu API.
void UpdateMenuItemInfoForString(MENUITEMINFO* mii,
int model_index,
const string16& label);
const base::string16& label);
// Returns the alignment flags to be passed to TrackPopupMenuEx, based on the
// supplied alignment and the UI text direction.

View file

@ -8,24 +8,25 @@
#include "atom/common/native_mate_converters/string16_converter.h"
#include "native_mate/dictionary.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "atom/common/node_includes.h"
namespace mate {
template<>
struct Converter<ui::Clipboard::Buffer> {
struct Converter<ui::ClipboardType> {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
ui::Clipboard::Buffer* out) {
ui::ClipboardType* out) {
std::string type;
if (!Converter<std::string>::FromV8(isolate, val, &type))
return false;
if (type == "selection")
*out = ui::Clipboard::BUFFER_SELECTION;
*out = ui::CLIPBOARD_TYPE_SELECTION;
else
*out = ui::Clipboard::BUFFER_STANDARD;
*out = ui::CLIPBOARD_TYPE_COPY_PASTE;
return true;
}
};
@ -34,14 +35,14 @@ struct Converter<ui::Clipboard::Buffer> {
namespace {
bool Has(const std::string& format_string, ui::Clipboard::Buffer buffer) {
bool Has(const std::string& format_string, ui::ClipboardType type) {
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string));
return clipboard->IsFormatAvailable(format, buffer);
return clipboard->IsFormatAvailable(format, type);
}
std::string Read(const std::string& format_string,
ui::Clipboard::Buffer buffer) {
ui::ClipboardType type) {
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
ui::Clipboard::FormatType format(ui::Clipboard::GetFormatType(format_string));
@ -50,23 +51,20 @@ std::string Read(const std::string& format_string,
return data;
}
string16 ReadText(ui::Clipboard::Buffer buffer) {
string16 data;
ui::Clipboard::GetForCurrentThread()->ReadText(buffer, &data);
base::string16 ReadText(ui::ClipboardType type) {
base::string16 data;
ui::Clipboard::GetForCurrentThread()->ReadText(type, &data);
return data;
}
void WriteText(const std::string text, ui::Clipboard::Buffer buffer) {
ui::Clipboard::ObjectMap object_map;
object_map[ui::Clipboard::CBF_TEXT].push_back(
std::vector<char>(text.begin(), text.end()));
void WriteText(const base::string16& text, ui::ClipboardType type) {
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
clipboard->WriteObjects(buffer, object_map);
ui::ScopedClipboardWriter writer(clipboard, type);
writer.WriteText(text);
}
void Clear(ui::Clipboard::Buffer buffer) {
ui::Clipboard::GetForCurrentThread()->Clear(buffer);
void Clear(ui::ClipboardType type) {
ui::Clipboard::GetForCurrentThread()->Clear(type);
}
void Initialize(v8::Handle<v8::Object> exports) {
@ -80,4 +78,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_common_clipboard, Initialize)
NODE_MODULE_X(atom_common_clipboard, Initialize, NULL, NM_F_BUILTIN)

View file

@ -45,4 +45,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_common_crash_reporter, Initialize)
NODE_MODULE_X(atom_common_crash_reporter, Initialize, NULL, NM_F_BUILTIN)

View file

@ -29,14 +29,14 @@ int32_t IDWeakMap::Add(v8::Isolate* isolate, v8::Handle<v8::Object> object) {
mate::Converter<int32_t>::ToV8(isolate, key));
map_[key] = new mate::RefCountedPersistent<v8::Object>(object);
map_[key]->MakeWeak(this, WeakCallback);
map_[key]->SetWeak(this, WeakCallback);
return key;
}
v8::Handle<v8::Value> IDWeakMap::Get(int32_t key) {
v8::Handle<v8::Value> IDWeakMap::Get(v8::Isolate* isolate, int32_t key) {
if (!Has(key)) {
node::ThrowError("Invalid key");
return v8::Undefined();
return v8::Undefined(isolate);
}
return map_[key]->NewHandle();
@ -77,14 +77,11 @@ void IDWeakMap::BuildPrototype(v8::Isolate* isolate,
}
// static
void IDWeakMap::WeakCallback(v8::Isolate* isolate,
v8::Persistent<v8::Object>* value,
IDWeakMap* self) {
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Object> object = v8::Local<v8::Object>::New(isolate, *value);
int32_t key = object->GetHiddenValue(
mate::StringToV8(isolate, "IDWeakMapKey"))->Int32Value();
self->Remove(key);
void IDWeakMap::WeakCallback(
const v8::WeakCallbackData<v8::Object, IDWeakMap>& data) {
int32_t key = data.GetValue()->GetHiddenValue(
mate::StringToV8(data.GetIsolate(), "IDWeakMapKey"))->Int32Value();
data.GetParameter()->Remove(key);
}
} // namespace api
@ -107,4 +104,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_common_id_weak_map, Initialize)
NODE_MODULE_X(atom_common_id_weak_map, Initialize, NULL, NM_F_BUILTIN)

View file

@ -29,15 +29,14 @@ class IDWeakMap : public mate::Wrappable {
virtual ~IDWeakMap();
int32_t Add(v8::Isolate* isolate, v8::Handle<v8::Object> object);
v8::Handle<v8::Value> Get(int32_t key);
v8::Handle<v8::Value> Get(v8::Isolate* isolate, int32_t key);
bool Has(int32_t key) const;
std::vector<int32_t> Keys() const;
void Remove(int32_t key);
int GetNextID();
static void WeakCallback(v8::Isolate* isolate,
v8::Persistent<v8::Object>* value,
IDWeakMap* self);
static void WeakCallback(
const v8::WeakCallbackData<v8::Object, IDWeakMap>& data);
int32_t next_id_;

View file

@ -103,4 +103,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_common_screen, Initialize)
NODE_MODULE_X(atom_common_screen, Initialize, NULL, NM_F_BUILTIN)

View file

@ -24,4 +24,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_common_shell, Initialize)
NODE_MODULE_X(atom_common_shell, Initialize, NULL, NM_F_BUILTIN)

View file

@ -10,8 +10,9 @@
namespace {
v8::Handle<v8::Object> CreateObjectWithName(v8::Handle<v8::String> name) {
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
v8::Handle<v8::Object> CreateObjectWithName(v8::Isolate* isolate,
v8::Handle<v8::String> name) {
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
t->SetClassName(name);
return t->GetFunction()->NewInstance();
}
@ -31,14 +32,15 @@ int32_t GetObjectHash(v8::Handle<v8::Object> object) {
return object->GetIdentityHash();
}
void SetDestructor(v8::Handle<v8::Object> object,
void SetDestructor(v8::Isolate* isolate,
v8::Handle<v8::Object> object,
v8::Handle<v8::Function> callback) {
atom::ObjectLifeMonitor::BindTo(object, callback);
atom::ObjectLifeMonitor::BindTo(isolate, object, callback);
}
void TakeHeapSnapshot() {
node::node_isolate->GetHeapProfiler()->TakeHeapSnapshot(
v8::String::New("test"));
void TakeHeapSnapshot(v8::Isolate* isolate) {
isolate->GetHeapProfiler()->TakeHeapSnapshot(
mate::StringToV8(isolate, "test"));
}
void Initialize(v8::Handle<v8::Object> exports) {
@ -53,4 +55,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_common_v8_util, Initialize)
NODE_MODULE_X(atom_common_v8_util, Initialize, NULL, NM_F_BUILTIN)

View file

@ -17,9 +17,6 @@
namespace atom {
// Defined in atom_extensions.cc.
node::node_module_struct* GetBuiltinModule(const char *name, bool is_browser);
namespace {
// Async handle to wake up uv loop.
@ -35,8 +32,9 @@ base::Closure g_v8_callback;
struct DummyClass { bool crash; };
// Async handler to call next process.nextTick callbacks.
void UvCallNextTick(uv_async_t* handle, int status) {
node::Environment* env = node::Environment::GetCurrent(node_isolate);
void UvCallNextTick(uv_async_t* handle) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
node::Environment* env = node::Environment::GetCurrent(isolate);
node::Environment::TickInfo* tick_info = env->tick_info();
if (tick_info->in_tick())
@ -53,7 +51,7 @@ void UvCallNextTick(uv_async_t* handle, int status) {
}
// Async handler to execute the stored v8 callback.
void UvOnCallback(uv_async_t* handle, int status) {
void UvOnCallback(uv_async_t* handle) {
g_v8_callback.Run();
}
@ -72,45 +70,6 @@ v8::Handle<v8::Value> DumpStackFrame(v8::Isolate* isolate,
return mate::ConvertToV8(isolate, frame_dict);;
}
v8::Handle<v8::Value> Binding(v8::Handle<v8::String> module) {
v8::String::Utf8Value module_v(module);
node::node_module_struct* modp;
v8::Local<v8::Object> process = v8::Context::GetCurrent()->Global()->
Get(v8::String::New("process"))->ToObject();
DCHECK(!process.IsEmpty());
// is_browser = process.type == 'browser'.
bool is_browser = std::string("browser") == *v8::String::Utf8Value(
process->Get(v8::String::New("type")));
// Cached in process.__atom_binding_cache.
v8::Local<v8::Object> binding_cache;
v8::Local<v8::String> bc_name = v8::String::New("__atomBindingCache");
if (process->Has(bc_name)) {
binding_cache = process->Get(bc_name)->ToObject();
DCHECK(!binding_cache.IsEmpty());
} else {
binding_cache = v8::Object::New();
process->Set(bc_name, binding_cache);
}
if (binding_cache->Has(module))
return binding_cache->Get(module)->ToObject();
if ((modp = GetBuiltinModule(*module_v, is_browser)) != NULL) {
v8::Local<v8::Object> exports = v8::Object::New();
// Internal bindings don't have a "module" object,
// only exports.
modp->register_func(exports, v8::Undefined());
binding_cache->Set(module, exports);
return exports;
}
node::ThrowError("No such module");
return v8::Undefined();
}
void Crash() {
static_cast<DummyClass*>(NULL)->crash = true;
}
@ -119,17 +78,17 @@ void ActivateUVLoop() {
uv_async_send(&g_next_tick_uv_handle);
}
void Log(const string16& message) {
void Log(const base::string16& message) {
logging::LogMessage("CONSOLE", 0, 0).stream() << message;
}
v8::Handle<v8::Value> GetCurrentStackTrace(v8::Isolate* isolate,
int stack_limit) {
v8::Local<v8::StackTrace> stack_trace = v8::StackTrace::CurrentStackTrace(
stack_limit, v8::StackTrace::kDetailed);
isolate, stack_limit, v8::StackTrace::kDetailed);
int frame_count = stack_trace->GetFrameCount();
v8::Local<v8::Array> result = v8::Array::New(frame_count);
v8::Local<v8::Array> result = v8::Array::New(isolate, frame_count);
for (int i = 0; i < frame_count; ++i)
result->Set(i, DumpStackFrame(isolate, stack_trace->GetFrame(i)));
@ -153,10 +112,9 @@ AtomBindings::AtomBindings() {
AtomBindings::~AtomBindings() {
}
void AtomBindings::BindTo(v8::Handle<v8::Object> process) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
void AtomBindings::BindTo(v8::Isolate* isolate,
v8::Handle<v8::Object> process) {
mate::Dictionary dict(isolate, process);
dict.SetMethod("atomBinding", &Binding);
dict.SetMethod("crash", &Crash);
dict.SetMethod("activateUvLoop", &ActivateUVLoop);
dict.SetMethod("log", &Log);

View file

@ -17,9 +17,9 @@ class AtomBindings {
AtomBindings();
virtual ~AtomBindings();
// Add process.atom_binding function, which behaves like process.binding but
// Add process.atom_binding function, which behaves like process.atomBinding but
// load native code from atom-shell instead.
virtual void BindTo(v8::Handle<v8::Object> process);
virtual void BindTo(v8::Isolate* isolate, v8::Handle<v8::Object> process);
private:
DISALLOW_COPY_AND_ASSIGN(AtomBindings);

View file

@ -1,56 +0,0 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include <string.h>
#include <stdio.h>
#include "base/strings/string_util.h"
#include "vendor/node/src/node_version.h"
#include "atom/common/node_includes.h"
namespace atom {
#undef NODE_EXT_LIST_START
#undef NODE_EXT_LIST_ITEM
#undef NODE_EXT_LIST_END
#define NODE_EXT_LIST_START
#define NODE_EXT_LIST_ITEM NODE_MODULE_DECL
#define NODE_EXT_LIST_END
#include "atom/common/api/atom_extensions.h"
#undef NODE_EXT_LIST_START
#undef NODE_EXT_LIST_ITEM
#undef NODE_EXT_LIST_END
#define NODE_EXT_STRING(x) &x ## _module,
#define NODE_EXT_LIST_START node::node_module_struct *node_module_list[] = {
#define NODE_EXT_LIST_ITEM NODE_EXT_STRING
#define NODE_EXT_LIST_END NULL};
#include "atom/common/api/atom_extensions.h" // NOLINT
node::node_module_struct* GetBuiltinModule(const char *name, bool is_browser) {
char common[128];
char spec[128];
node::node_module_struct *cur = NULL;
base::snprintf(common, sizeof(common), "atom_common_%s", name);
base::snprintf(spec, sizeof(spec),
(is_browser ? "atom_browser_%s": "atom_renderer_%s"),
name);
/* TODO: you could look these up in a hash, but there are only
* a few, and once loaded they are cached. */
for (int i = 0; node_module_list[i] != NULL; i++) {
cur = node_module_list[i];
if (strcmp(cur->modname, common) == 0 || strcmp(cur->modname, spec) == 0) {
return cur;
}
}
return NULL;
}
} // namespace atom

View file

@ -1,35 +0,0 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
// Multiply-included file, no traditional include guard.
// Used by atom_extensions.cc to declare a list of built-in modules of Atom.
NODE_EXT_LIST_START
// Module names start with `atom_browser_` can only be used by browser process.
NODE_EXT_LIST_ITEM(atom_browser_app)
NODE_EXT_LIST_ITEM(atom_browser_auto_updater)
NODE_EXT_LIST_ITEM(atom_browser_dialog)
NODE_EXT_LIST_ITEM(atom_browser_menu)
NODE_EXT_LIST_ITEM(atom_browser_power_monitor)
NODE_EXT_LIST_ITEM(atom_browser_protocol)
NODE_EXT_LIST_ITEM(atom_browser_tray)
NODE_EXT_LIST_ITEM(atom_browser_window)
// Module names start with `atom_renderer_` can only be used by renderer
// process.
NODE_EXT_LIST_ITEM(atom_renderer_ipc)
NODE_EXT_LIST_ITEM(atom_renderer_web_view)
// Module names start with `atom_common_` can be used by both browser and
// renderer processes.
NODE_EXT_LIST_ITEM(atom_common_clipboard)
NODE_EXT_LIST_ITEM(atom_common_crash_reporter)
NODE_EXT_LIST_ITEM(atom_common_id_weak_map)
NODE_EXT_LIST_ITEM(atom_common_screen)
NODE_EXT_LIST_ITEM(atom_common_shell)
NODE_EXT_LIST_ITEM(atom_common_v8_util)
NODE_EXT_LIST_END

View file

@ -5,34 +5,32 @@
#include "atom/common/api/object_life_monitor.h"
#include "native_mate/compat.h"
namespace atom {
// static
void ObjectLifeMonitor::BindTo(v8::Handle<v8::Object> target,
void ObjectLifeMonitor::BindTo(v8::Isolate* isolate,
v8::Handle<v8::Object> target,
v8::Handle<v8::Value> destructor) {
target->SetHiddenValue(v8::String::New("destructor"), destructor);
target->SetHiddenValue(MATE_STRING_NEW(isolate, "destructor"), destructor);
ObjectLifeMonitor* olm = new ObjectLifeMonitor();
olm->handle_.reset(target);
olm->handle_.MakeWeak(olm, WeakCallback);
olm->handle_.SetWeak(olm, WeakCallback);
}
ObjectLifeMonitor::ObjectLifeMonitor() {
}
// static
void ObjectLifeMonitor::WeakCallback(v8::Isolate* isolate,
v8::Persistent<v8::Object>* value,
ObjectLifeMonitor* self) {
void ObjectLifeMonitor::WeakCallback(
const v8::WeakCallbackData<v8::Object, ObjectLifeMonitor>& data) {
// destructor.call(object, object);
{
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Object> obj = self->handle_.NewHandle();
v8::Local<v8::Function>::Cast(obj->GetHiddenValue(
v8::String::New("destructor")))->Call(obj, 0, NULL);
}
delete self;
v8::Local<v8::Object> obj = data.GetValue();
v8::Local<v8::Function>::Cast(obj->GetHiddenValue(
MATE_STRING_NEW(data.GetIsolate(), "destructor")))->Call(obj, 0, NULL);
delete data.GetParameter();
}
} // namespace atom

View file

@ -12,15 +12,15 @@ namespace atom {
class ObjectLifeMonitor {
public:
static void BindTo(v8::Handle<v8::Object> target,
static void BindTo(v8::Isolate* isolate,
v8::Handle<v8::Object> target,
v8::Handle<v8::Value> destructor);
private:
ObjectLifeMonitor();
static void WeakCallback(v8::Isolate* isolate,
v8::Persistent<v8::Object>* value,
ObjectLifeMonitor* self);
static void WeakCallback(
const v8::WeakCallbackData<v8::Object, ObjectLifeMonitor>& data);
mate::ScopedPersistent<v8::Object> handle_;

View file

@ -45,7 +45,7 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
return;
}
string16 pipe_name = ReplaceStringPlaceholders(kPipeNameFormat,
base::string16 pipe_name = ReplaceStringPlaceholders(kPipeNameFormat,
UTF8ToUTF16(product_name),
NULL);

View file

@ -68,7 +68,7 @@ int Main(const wchar_t* cmd) {
VLOG(1) << "Session start. cmdline is [" << cmd << "]";
// Setting the crash reporter.
string16 pipe_name = ReplaceStringPlaceholders(kPipeNameFormat,
base::string16 pipe_name = ReplaceStringPlaceholders(kPipeNameFormat,
application_name,
NULL);
cmd_line.AppendSwitch("no-window");

View file

@ -2,6 +2,8 @@ path = require 'path'
timers = require 'timers'
Module = require 'module'
process.atomBinding = (name) -> process.binding "atom_#{process.type}_#{name}"
# Add common/api/lib to module search paths.
globalPaths = Module.globalPaths
globalPaths.push path.join(process.resourcesPath, 'atom', 'common', 'api', 'lib')

View file

@ -12,6 +12,7 @@
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/base/layout.h"
namespace mate {

View file

@ -36,74 +36,76 @@ void V8ValueConverter::SetStripNullFromObjects(bool val) {
strip_null_from_objects_ = val;
}
v8::Handle<v8::Value> V8ValueConverter::ToV8Value(
const base::Value* value, v8::Handle<v8::Context> context) const {
v8::Local<v8::Value> V8ValueConverter::ToV8Value(
const base::Value* value, v8::Local<v8::Context> context) const {
v8::Context::Scope context_scope(context);
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
return handle_scope.Close(ToV8ValueImpl(value));
v8::EscapableHandleScope handle_scope(context->GetIsolate());
return handle_scope.Escape(ToV8ValueImpl(context->GetIsolate(), value));
}
Value* V8ValueConverter::FromV8Value(
v8::Handle<v8::Value> val,
v8::Handle<v8::Context> context) const {
base::Value* V8ValueConverter::FromV8Value(
v8::Local<v8::Value> val,
v8::Local<v8::Context> context) const {
v8::Context::Scope context_scope(context);
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::HandleScope handle_scope(context->GetIsolate());
HashToHandleMap unique_map;
return FromV8ValueImpl(val, &unique_map);
}
v8::Handle<v8::Value> V8ValueConverter::ToV8ValueImpl(
const base::Value* value) const {
v8::Local<v8::Value> V8ValueConverter::ToV8ValueImpl(
v8::Isolate* isolate, const base::Value* value) const {
CHECK(value);
switch (value->GetType()) {
case base::Value::TYPE_NULL:
return v8::Null();
return v8::Null(isolate);
case base::Value::TYPE_BOOLEAN: {
bool val = false;
CHECK(value->GetAsBoolean(&val));
return v8::Boolean::New(val);
return v8::Boolean::New(isolate, val);
}
case base::Value::TYPE_INTEGER: {
int val = 0;
CHECK(value->GetAsInteger(&val));
return v8::Integer::New(val);
return v8::Integer::New(isolate, val);
}
case base::Value::TYPE_DOUBLE: {
double val = 0.0;
CHECK(value->GetAsDouble(&val));
return v8::Number::New(val);
return v8::Number::New(isolate, val);
}
case base::Value::TYPE_STRING: {
std::string val;
CHECK(value->GetAsString(&val));
return v8::String::New(val.c_str(), val.length());
return v8::String::NewFromUtf8(
isolate, val.c_str(), v8::String::kNormalString, val.length());
}
case base::Value::TYPE_LIST:
return ToV8Array(static_cast<const base::ListValue*>(value));
return ToV8Array(isolate, static_cast<const base::ListValue*>(value));
case base::Value::TYPE_DICTIONARY:
return ToV8Object(static_cast<const base::DictionaryValue*>(value));
return ToV8Object(isolate,
static_cast<const base::DictionaryValue*>(value));
default:
LOG(ERROR) << "Unexpected value type: " << value->GetType();
return v8::Null();
return v8::Null(isolate);
}
}
v8::Handle<v8::Value> V8ValueConverter::ToV8Array(
const base::ListValue* val) const {
v8::Handle<v8::Array> result(v8::Array::New(val->GetSize()));
v8::Local<v8::Value> V8ValueConverter::ToV8Array(
v8::Isolate* isolate, const base::ListValue* val) const {
v8::Local<v8::Array> result(v8::Array::New(isolate, val->GetSize()));
for (size_t i = 0; i < val->GetSize(); ++i) {
const base::Value* child = NULL;
CHECK(val->Get(i, &child));
v8::Handle<v8::Value> child_v8 = ToV8ValueImpl(child);
v8::Local<v8::Value> child_v8 = ToV8ValueImpl(isolate, child);
CHECK(!child_v8.IsEmpty());
v8::TryCatch try_catch;
@ -115,18 +117,21 @@ v8::Handle<v8::Value> V8ValueConverter::ToV8Array(
return result;
}
v8::Handle<v8::Value> V8ValueConverter::ToV8Object(
const base::DictionaryValue* val) const {
v8::Handle<v8::Object> result(v8::Object::New());
v8::Local<v8::Value> V8ValueConverter::ToV8Object(
v8::Isolate* isolate, const base::DictionaryValue* val) const {
v8::Local<v8::Object> result(v8::Object::New(isolate));
for (base::DictionaryValue::Iterator iter(*val);
!iter.IsAtEnd(); iter.Advance()) {
const std::string& key = iter.key();
v8::Handle<v8::Value> child_v8 = ToV8ValueImpl(&iter.value());
v8::Local<v8::Value> child_v8 = ToV8ValueImpl(isolate, &iter.value());
CHECK(!child_v8.IsEmpty());
v8::TryCatch try_catch;
result->Set(v8::String::New(key.c_str(), key.length()), child_v8);
result->Set(
v8::String::NewFromUtf8(isolate, key.c_str(), v8::String::kNormalString,
key.length()),
child_v8);
if (try_catch.HasCaught()) {
LOG(ERROR) << "Setter for property " << key.c_str() << " threw an "
<< "exception.";
@ -136,7 +141,7 @@ v8::Handle<v8::Value> V8ValueConverter::ToV8Object(
return result;
}
Value* V8ValueConverter::FromV8ValueImpl(v8::Handle<v8::Value> val,
base::Value* V8ValueConverter::FromV8ValueImpl(v8::Local<v8::Value> val,
HashToHandleMap* unique_map) const {
CHECK(!val.IsEmpty());
@ -196,16 +201,17 @@ Value* V8ValueConverter::FromV8ValueImpl(v8::Handle<v8::Value> val,
return NULL;
}
Value* V8ValueConverter::FromV8Array(v8::Handle<v8::Array> val,
base::Value* V8ValueConverter::FromV8Array(v8::Local<v8::Array> val,
HashToHandleMap* unique_map) const {
if (!UpdateAndCheckUniqueness(unique_map, val))
return base::Value::CreateNullValue();
v8::Isolate* isolate = v8::Isolate::GetCurrent();
scoped_ptr<v8::Context::Scope> scope;
// If val was created in a different context than our current one, change to
// that context, but change back after val is converted.
if (!val->CreationContext().IsEmpty() &&
val->CreationContext() != v8::Context::GetCurrent())
val->CreationContext() != isolate->GetCurrentContext())
scope.reset(new v8::Context::Scope(val->CreationContext()));
base::ListValue* result = new base::ListValue();
@ -213,10 +219,10 @@ Value* V8ValueConverter::FromV8Array(v8::Handle<v8::Array> val,
// Only fields with integer keys are carried over to the ListValue.
for (uint32 i = 0; i < val->Length(); ++i) {
v8::TryCatch try_catch;
v8::Handle<v8::Value> child_v8 = val->Get(i);
v8::Local<v8::Value> child_v8 = val->Get(i);
if (try_catch.HasCaught()) {
LOG(ERROR) << "Getter for index " << i << " threw an exception.";
child_v8 = v8::Null();
child_v8 = v8::Null(isolate);
}
if (!val->HasRealIndexedProperty(i))
@ -233,28 +239,29 @@ Value* V8ValueConverter::FromV8Array(v8::Handle<v8::Array> val,
return result;
}
Value* V8ValueConverter::FromV8Object(
v8::Handle<v8::Object> val,
base::Value* V8ValueConverter::FromV8Object(
v8::Local<v8::Object> val,
HashToHandleMap* unique_map) const {
if (!UpdateAndCheckUniqueness(unique_map, val))
return base::Value::CreateNullValue();
v8::Isolate* isolate = v8::Isolate::GetCurrent();
scoped_ptr<v8::Context::Scope> scope;
// If val was created in a different context than our current one, change to
// that context, but change back after val is converted.
if (!val->CreationContext().IsEmpty() &&
val->CreationContext() != v8::Context::GetCurrent())
val->CreationContext() != isolate->GetCurrentContext())
scope.reset(new v8::Context::Scope(val->CreationContext()));
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
v8::Handle<v8::Array> property_names(val->GetOwnPropertyNames());
v8::Local<v8::Array> property_names(val->GetOwnPropertyNames());
for (uint32 i = 0; i < property_names->Length(); ++i) {
v8::Handle<v8::Value> key(property_names->Get(i));
v8::Local<v8::Value> key(property_names->Get(i));
// Extend this test to cover more types as necessary and if sensible.
if (!key->IsString() &&
!key->IsNumber()) {
NOTREACHED() << "Key \"" << *v8::String::AsciiValue(key) << "\" "
NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key) << "\" "
"is neither a string nor a number";
continue;
}
@ -266,12 +273,12 @@ Value* V8ValueConverter::FromV8Object(
v8::String::Utf8Value name_utf8(key->ToString());
v8::TryCatch try_catch;
v8::Handle<v8::Value> child_v8 = val->Get(key);
v8::Local<v8::Value> child_v8 = val->Get(key);
if (try_catch.HasCaught()) {
LOG(ERROR) << "Getter for property " << *name_utf8
<< " threw an exception.";
child_v8 = v8::Null();
child_v8 = v8::Null(isolate);
}
scoped_ptr<base::Value> child(FromV8ValueImpl(child_v8, unique_map));
@ -300,7 +307,7 @@ Value* V8ValueConverter::FromV8Object(
// there *is* a "windowId" property, but since it should be an int, code
// on the browser which doesn't additionally check for null will fail.
// We can avoid all bugs related to this by stripping null.
if (strip_null_from_objects_ && child->IsType(Value::TYPE_NULL))
if (strip_null_from_objects_ && child->IsType(base::Value::TYPE_NULL))
continue;
result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()),
@ -312,7 +319,7 @@ Value* V8ValueConverter::FromV8Object(
bool V8ValueConverter::UpdateAndCheckUniqueness(
HashToHandleMap* map,
v8::Handle<v8::Object> handle) const {
v8::Local<v8::Object> handle) const {
typedef HashToHandleMap::const_iterator Iterator;
int hash = avoid_identity_hash_for_testing_ ? 0 : handle->GetIdentityHash();
@ -326,7 +333,7 @@ bool V8ValueConverter::UpdateAndCheckUniqueness(
return false;
}
map->insert(std::pair<int, v8::Handle<v8::Object> >(hash, handle));
map->insert(std::pair<int, v8::Local<v8::Object> >(hash, handle));
return true;
}

View file

@ -28,25 +28,28 @@ class V8ValueConverter {
void SetRegExpAllowed(bool val);
void SetFunctionAllowed(bool val);
void SetStripNullFromObjects(bool val);
v8::Handle<v8::Value> ToV8Value(const base::Value* value,
v8::Handle<v8::Context> context) const;
base::Value* FromV8Value(v8::Handle<v8::Value> value,
v8::Handle<v8::Context> context) const;
v8::Local<v8::Value> ToV8Value(const base::Value* value,
v8::Local<v8::Context> context) const;
base::Value* FromV8Value(v8::Local<v8::Value> value,
v8::Local<v8::Context> context) const;
private:
typedef std::multimap<int, v8::Handle<v8::Object> > HashToHandleMap;
typedef std::multimap<int, v8::Local<v8::Object> > HashToHandleMap;
v8::Handle<v8::Value> ToV8ValueImpl(const base::Value* value) const;
v8::Handle<v8::Value> ToV8Array(const base::ListValue* list) const;
v8::Handle<v8::Value> ToV8Object(
v8::Local<v8::Value> ToV8ValueImpl(v8::Isolate* isolate,
const base::Value* value) const;
v8::Local<v8::Value> ToV8Array(v8::Isolate* isolate,
const base::ListValue* list) const;
v8::Local<v8::Value> ToV8Object(
v8::Isolate* isolate,
const base::DictionaryValue* dictionary) const;
base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value,
base::Value* FromV8ValueImpl(v8::Local<v8::Value> value,
HashToHandleMap* unique_map) const;
base::Value* FromV8Array(v8::Handle<v8::Array> array,
base::Value* FromV8Array(v8::Local<v8::Array> array,
HashToHandleMap* unique_map) const;
base::Value* FromV8Object(v8::Handle<v8::Object> object,
base::Value* FromV8Object(v8::Local<v8::Object> object,
HashToHandleMap* unique_map) const;
// If |handle| is not in |map|, then add it to |map| and return true.
@ -55,7 +58,7 @@ class V8ValueConverter {
// be unique even if there already is another handle with the same identity
// hash (key) in the map, because two objects can have the same hash.
bool UpdateAndCheckUniqueness(HashToHandleMap* map,
v8::Handle<v8::Object> handle) const;
v8::Local<v8::Object> handle) const;
// If true, we will convert Date JavaScript objects to doubles.
bool date_allowed_;

View file

@ -14,9 +14,9 @@ bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
base::DictionaryValue* out) {
scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
scoped_ptr<base::Value> value(converter->FromV8Value(
val, v8::Context::GetCurrent()));
val, isolate->GetCurrentContext()));
if (value && value->IsType(base::Value::TYPE_DICTIONARY)) {
out->Swap(static_cast<DictionaryValue*>(value.get()));
out->Swap(static_cast<base::DictionaryValue*>(value.get()));
return true;
} else {
return false;
@ -28,9 +28,9 @@ bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate,
base::ListValue* out) {
scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
scoped_ptr<base::Value> value(converter->FromV8Value(
val, v8::Context::GetCurrent()));
val, isolate->GetCurrentContext()));
if (value->IsType(base::Value::TYPE_LIST)) {
out->Swap(static_cast<ListValue*>(value.get()));
out->Swap(static_cast<base::ListValue*>(value.get()));
return true;
} else {
return false;

View file

@ -36,7 +36,7 @@ namespace atom {
namespace {
// Empty callback for async handle.
void UvNoOp(uv_async_t* handle, int status) {
void UvNoOp(uv_async_t* handle) {
}
// Convert the given vector to an array of C-strings. The strings in the
@ -85,16 +85,9 @@ NodeBindings::~NodeBindings() {
// Clear uv.
uv_sem_destroy(&embed_sem_);
uv_timer_stop(&idle_timer_);
}
void NodeBindings::Initialize() {
// 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_;
node::g_upstream_node_mode = false;
@ -162,7 +155,7 @@ node::Environment* NodeBindings::CreateEnvironment(
uv_unref(reinterpret_cast<uv_handle_t*>(env->idle_prepare_handle()));
uv_unref(reinterpret_cast<uv_handle_t*>(env->idle_check_handle()));
Local<FunctionTemplate> process_template = FunctionTemplate::New();
Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate);
process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "process"));
Local<Object> process_object = process_template->GetFunction()->NewInstance();
@ -199,15 +192,16 @@ void NodeBindings::RunMessageLoop() {
void NodeBindings::UvRunOnce() {
DCHECK(!is_browser_ || BrowserThread::CurrentlyOn(BrowserThread::UI));
// Use Locker in browser process.
BrowserV8Locker locker(node_isolate);
v8::HandleScope handle_scope(node_isolate);
// Enter node context while dealing with uv events, by default the global
// env would be used unless user specified another one (this happens for
// renderer process, which wraps the uv loop with web page context).
// By default the global env would be used unless user specified another one
// (this happens for renderer process, which wraps the uv loop with web page
// context).
node::Environment* env = uv_env() ? uv_env() : global_env;
// Use Locker in browser process.
BrowserV8Locker locker(env->isolate());
v8::HandleScope handle_scope(env->isolate());
// Enter node context while dealing with uv events.
v8::Context::Scope context_scope(env->context());
// Deal with uv events.
@ -253,9 +247,4 @@ void NodeBindings::EmbedThreadRunner(void *arg) {
}
}
// static
void NodeBindings::IdleCallback(uv_timer_t*, int) {
v8::V8::IdleNotification();
}
} // namespace atom

View file

@ -70,18 +70,12 @@ class NodeBindings {
// Thread to poll uv events.
static void EmbedThreadRunner(void *arg);
// Do idle GC.
static void IdleCallback(uv_timer_t*, int);
// Whether the libuv loop has ended.
bool embed_closed_;
// Dummy handle to make uv's loop not quit.
uv_async_t dummy_uv_handle_;
// Timer to do idle GC.
uv_timer_t idle_timer_;
// Thread for polling events.
uv_thread_t embed_thread_;

View file

@ -13,8 +13,8 @@
#include "atom/common/node_includes.h"
using content::RenderView;
using WebKit::WebFrame;
using WebKit::WebView;
using blink::WebFrame;
using blink::WebView;
namespace {
@ -30,7 +30,7 @@ RenderView* GetCurrentRenderView() {
return RenderView::FromWebView(view);
}
void Send(const string16& channel, const base::ListValue& arguments) {
void Send(const base::string16& channel, const base::ListValue& arguments) {
RenderView* render_view = GetCurrentRenderView();
if (render_view == NULL)
return;
@ -42,8 +42,9 @@ void Send(const string16& channel, const base::ListValue& arguments) {
node::ThrowError("Unable to send AtomViewHostMsg_Message");
}
string16 SendSync(const string16& channel, const base::ListValue& arguments) {
string16 json;
base::string16 SendSync(const base::string16& channel,
const base::ListValue& arguments) {
base::string16 json;
RenderView* render_view = GetCurrentRenderView();
if (render_view == NULL)
@ -69,4 +70,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_renderer_ipc, Initialize)
NODE_MODULE_X(atom_renderer_ipc, Initialize, NULL, NM_F_BUILTIN)

View file

@ -17,8 +17,8 @@ namespace api {
namespace {
WebKit::WebView* GetCurrentWebView() {
WebKit::WebFrame* frame = WebKit::WebFrame::frameForCurrentContext();
blink::WebView* GetCurrentWebView() {
blink::WebFrame* frame = blink::WebFrame::frameForCurrentContext();
if (!frame)
return NULL;
return frame->view();
@ -41,12 +41,12 @@ double WebView::GetZoomLevel() const {
}
double WebView::SetZoomFactor(double factor) {
return WebKit::WebView::zoomLevelToZoomFactor(SetZoomLevel(
WebKit::WebView::zoomFactorToZoomLevel(factor)));
return blink::WebView::zoomLevelToZoomFactor(SetZoomLevel(
blink::WebView::zoomFactorToZoomLevel(factor)));
}
double WebView::GetZoomFactor() const {
return WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel());
return blink::WebView::zoomLevelToZoomFactor(GetZoomLevel());
}
mate::ObjectTemplateBuilder WebView::GetObjectTemplateBuilder(
@ -77,4 +77,4 @@ void Initialize(v8::Handle<v8::Object> exports) {
} // namespace
NODE_MODULE(atom_renderer_web_view, Initialize)
NODE_MODULE_X(atom_renderer_web_view, Initialize, NULL, NM_F_BUILTIN)

View file

@ -8,7 +8,7 @@
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"
namespace WebKit {
namespace blink {
class WebView;
}
@ -33,7 +33,7 @@ class WebView : public mate::Wrappable {
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate);
WebKit::WebView* web_view_;
blink::WebView* web_view_;
DISALLOW_COPY_AND_ASSIGN(WebView);
};

View file

@ -11,6 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "content/public/renderer/render_view.h"
#include "native_mate/converter.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebView.h"
@ -21,8 +22,8 @@ namespace atom {
namespace {
v8::Handle<v8::Object> GetProcessObject(v8::Handle<v8::Context> context) {
v8::Handle<v8::Object> process =
context->Global()->Get(v8::String::New("process"))->ToObject();
v8::Handle<v8::Object> process = context->Global()->Get(
mate::StringToV8(context->GetIsolate(), "process"))->ToObject();
DCHECK(!process.IsEmpty());
return process;
@ -36,24 +37,26 @@ AtomRendererBindings::AtomRendererBindings() {
AtomRendererBindings::~AtomRendererBindings() {
}
void AtomRendererBindings::BindToFrame(WebKit::WebFrame* frame) {
v8::HandleScope handle_scope(node_isolate);
void AtomRendererBindings::BindToFrame(blink::WebFrame* frame) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
if (context.IsEmpty())
return;
v8::Context::Scope scope(context);
AtomBindings::BindTo(GetProcessObject(context));
AtomBindings::BindTo(isolate, GetProcessObject(context));
}
void AtomRendererBindings::OnBrowserMessage(content::RenderView* render_view,
const string16& channel,
const base::string16& channel,
const base::ListValue& args) {
if (!render_view->GetWebView())
return;
v8::HandleScope handle_scope(node_isolate);
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context =
render_view->GetWebView()->mainFrame()->mainWorldScriptContext();
@ -67,7 +70,7 @@ void AtomRendererBindings::OnBrowserMessage(content::RenderView* render_view,
std::vector<v8::Handle<v8::Value>> arguments;
arguments.reserve(1 + args.GetSize());
arguments.push_back(mate::ConvertToV8(node_isolate, channel));
arguments.push_back(mate::ConvertToV8(isolate, channel));
for (size_t i = 0; i < args.GetSize(); i++) {
const base::Value* value;
@ -75,7 +78,7 @@ void AtomRendererBindings::OnBrowserMessage(content::RenderView* render_view,
arguments.push_back(converter->ToV8Value(value, context));
}
node::MakeCallback(process, "emit", arguments.size(), &arguments[0]);
node::MakeCallback(isolate, process, "emit", arguments.size(), &arguments[0]);
}
} // namespace atom

View file

@ -17,7 +17,7 @@ namespace content {
class RenderView;
}
namespace WebKit {
namespace blink {
class WebFrame;
}
@ -29,11 +29,11 @@ class AtomRendererBindings : public AtomBindings {
virtual ~AtomRendererBindings();
// Call BindTo for process object of the frame.
void BindToFrame(WebKit::WebFrame* frame);
void BindToFrame(blink::WebFrame* frame);
// Dispatch messages from browser.
void OnBrowserMessage(content::RenderView* render_view,
const string16& channel,
const base::string16& channel,
const base::ListValue& args);
private:

View file

@ -22,7 +22,7 @@
#include "atom/common/node_includes.h"
using WebKit::WebFrame;
using blink::WebFrame;
namespace atom {
@ -36,7 +36,7 @@ AtomRenderViewObserver::AtomRenderViewObserver(
AtomRenderViewObserver::~AtomRenderViewObserver() {
}
void AtomRenderViewObserver::DidCreateDocumentElement(WebKit::WebFrame* frame) {
void AtomRenderViewObserver::DidCreateDocumentElement(blink::WebFrame* frame) {
// Read --zoom-factor from command line.
std::string zoom_factor_str = CommandLine::ForCurrentProcess()->
GetSwitchValueASCII(switches::kZoomFactor);;
@ -45,12 +45,12 @@ void AtomRenderViewObserver::DidCreateDocumentElement(WebKit::WebFrame* frame) {
double zoom_factor;
if (!base::StringToDouble(zoom_factor_str, &zoom_factor))
return;
double zoom_level = WebKit::WebView::zoomFactorToZoomLevel(zoom_factor);
double zoom_level = blink::WebView::zoomFactorToZoomLevel(zoom_factor);
frame->view()->setZoomLevel(zoom_level);
}
void AtomRenderViewObserver::DraggableRegionsChanged(WebKit::WebFrame* frame) {
WebKit::WebVector<WebKit::WebDraggableRegion> webregions =
void AtomRenderViewObserver::DraggableRegionsChanged(blink::WebFrame* frame) {
blink::WebVector<blink::WebDraggableRegion> webregions =
frame->document().draggableRegions();
std::vector<DraggableRegion> regions;
for (size_t i = 0; i < webregions.size(); ++i) {
@ -72,12 +72,12 @@ bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
return handled;
}
void AtomRenderViewObserver::OnBrowserMessage(const string16& channel,
void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel,
const base::ListValue& args) {
if (!render_view()->GetWebView())
return;
WebKit::WebFrame* frame = render_view()->GetWebView()->mainFrame();
blink::WebFrame* frame = render_view()->GetWebView()->mainFrame();
if (!renderer_client_->IsNodeBindingEnabled(frame))
return;

View file

@ -25,11 +25,11 @@ class AtomRenderViewObserver : public content::RenderViewObserver {
private:
// content::RenderViewObserver implementation.
virtual void DidCreateDocumentElement(WebKit::WebFrame* frame) OVERRIDE;
virtual void DraggableRegionsChanged(WebKit::WebFrame* frame) OVERRIDE;
virtual void DidCreateDocumentElement(blink::WebFrame* frame) OVERRIDE;
virtual void DraggableRegionsChanged(blink::WebFrame* frame) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
void OnBrowserMessage(const string16& channel,
void OnBrowserMessage(const base::string16& channel,
const base::ListValue& args);
// Weak reference to renderer client.

View file

@ -12,6 +12,7 @@
#include "atom/renderer/api/atom_renderer_bindings.h"
#include "atom/renderer/atom_render_view_observer.h"
#include "base/command_line.h"
#include "native_mate/converter.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrame.h"
@ -65,16 +66,21 @@ void AtomRendererClient::RenderThreadStarted() {
// 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<v8::Context> context = v8::Context::New(node_isolate);
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
global_env = node::Environment::New(context);
}
void AtomRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) {
}
void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
new AtomRenderViewObserver(render_view, this);
}
void AtomRendererClient::DidCreateScriptContext(WebKit::WebFrame* frame,
void AtomRendererClient::DidCreateScriptContext(blink::WebFrame* frame,
v8::Handle<v8::Context> context,
int extension_group,
int world_id) {
@ -88,7 +94,8 @@ void AtomRendererClient::DidCreateScriptContext(WebKit::WebFrame* frame,
v8::Context::Scope scope(context);
// Check the existance of process object to prevent duplicate initialization.
if (context->Global()->Has(v8::String::New("process")))
if (context->Global()->Has(
mate::StringToV8(context->GetIsolate(), "process")))
return;
// Give the node loop a run to make sure everything is ready.
@ -109,7 +116,7 @@ void AtomRendererClient::DidCreateScriptContext(WebKit::WebFrame* frame,
}
void AtomRendererClient::WillReleaseScriptContext(
WebKit::WebFrame* frame,
blink::WebFrame* frame,
v8::Handle<v8::Context> context,
int world_id) {
if (!IsNodeBindingEnabled(frame))
@ -143,7 +150,7 @@ void AtomRendererClient::WillReleaseScriptContext(
}
}
bool AtomRendererClient::ShouldFork(WebKit::WebFrame* frame,
bool AtomRendererClient::ShouldFork(blink::WebFrame* frame,
const GURL& url,
const std::string& http_method,
bool is_initial_navigation,
@ -156,7 +163,7 @@ bool AtomRendererClient::ShouldFork(WebKit::WebFrame* frame,
return http_method == "GET";
}
bool AtomRendererClient::IsNodeBindingEnabled(WebKit::WebFrame* frame) {
bool AtomRendererClient::IsNodeBindingEnabled(blink::WebFrame* frame) {
if (node_integration_ == DISABLE)
return false;
// Node integration is enabled in main frame unless explictly disabled.

View file

@ -24,7 +24,7 @@ class AtomRendererClient : public content::ContentRendererClient {
AtomRendererClient();
virtual ~AtomRendererClient();
bool IsNodeBindingEnabled(WebKit::WebFrame* frame = NULL);
bool IsNodeBindingEnabled(blink::WebFrame* frame = NULL);
AtomRendererBindings* atom_bindings() const { return atom_bindings_.get(); }
@ -36,16 +36,18 @@ class AtomRendererClient : public content::ContentRendererClient {
DISABLE,
};
// content::ContentRendererClient:
virtual void RenderThreadStarted() OVERRIDE;
virtual void RenderFrameCreated(content::RenderFrame* render_frame) OVERRIDE;
virtual void RenderViewCreated(content::RenderView*) OVERRIDE;
virtual void DidCreateScriptContext(WebKit::WebFrame* frame,
virtual void DidCreateScriptContext(blink::WebFrame* frame,
v8::Handle<v8::Context> context,
int extension_group,
int world_id) OVERRIDE;
virtual void WillReleaseScriptContext(WebKit::WebFrame* frame,
virtual void WillReleaseScriptContext(blink::WebFrame* frame,
v8::Handle<v8::Context>,
int world_id) OVERRIDE;
virtual bool ShouldFork(WebKit::WebFrame* frame,
int world_id);
virtual bool ShouldFork(blink::WebFrame* frame,
const GURL& url,
const std::string& http_method,
bool is_initial_navigation,
@ -61,7 +63,7 @@ class AtomRendererClient : public content::ContentRendererClient {
NodeIntegration node_integration_;
// The main frame.
WebKit::WebFrame* main_frame_;
blink::WebFrame* main_frame_;
DISALLOW_COPY_AND_ASSIGN(AtomRendererClient);
};

2
vendor/native_mate vendored

@ -1 +1 @@
Subproject commit 6f574c38020bdf9d6ed9dd079905f4b110fbd10e
Subproject commit e6db1875d0259d7750ad57d58d6fecaeeaea0cf6