'common/platform_util.h',
'common/platform_util_mac.mm',
'common/platform_util_win.cc',
+ 'common/string16_conversions.h',
'common/v8_value_converter_impl.cc',
'common/v8_value_converter_impl.h',
'renderer/api/atom_api_renderer_ipc.cc',
#include "base/values.h"
#include "common/api/api_messages.h"
+#include "common/string16_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/render_view_host.h"
#include "vendor/node/src/node.h"
if (!args[0]->IsString() || !args[1]->IsNumber() || !args[2]->IsNumber())
return node::ThrowTypeError("Bad argument");
- std::string channel(*v8::String::Utf8Value(args[0]));
+ string16 channel(V8ValueToUTF16(args[0]));
int process_id = args[1]->IntegerValue();
int routing_id = args[2]->IntegerValue();
#include "browser/api/atom_api_event.h"
+#include "common/string16_conversions.h"
+
using node::node_isolate;
namespace atom {
}
// static
-std::string Event::GetReturnValue(v8::Handle<v8::Object> event) {
+string16 Event::GetReturnValue(v8::Handle<v8::Object> event) {
v8::HandleScope scope;
v8::Local<v8::Value> json = event->Get(v8::String::New("returnValue"));
- return *v8::String::Utf8Value(json);
+ return V8ValueToUTF16(json);
}
v8::Handle<v8::Value> Event::New(const v8::Arguments &args) {
#ifndef ATOM_BROWSER_ATOM_API_EVENT_H_
#define ATOM_BROWSER_ATOM_API_EVENT_H_
-#include <string>
-
#include "base/basictypes.h"
+#include "base/string16.h"
#include "vendor/node/src/node_object_wrap.h"
namespace atom {
static v8::Handle<v8::Object> CreateV8Object();
// Get JSON string of the event.returnValue from a Event object.
- static std::string GetReturnValue(v8::Handle<v8::Object> event);
+ static string16 GetReturnValue(v8::Handle<v8::Object> event);
// Accessor to return handle_, this follows Google C++ Style.
v8::Persistent<v8::Object>& handle() { return handle_; }
#include "browser/api/atom_api_window.h"
#include "browser/ui/accelerator_util.h"
+#include "common/string16_conversions.h"
#define UNWRAP_MEMNU_AND_CHECK \
Menu* self = ObjectWrap::Unwrap<Menu>(args.This()); \
namespace {
-// Converts a V8 value to a string16.
-string16 V8ValueToUTF16(v8::Handle<v8::Value> value) {
- v8::String::Value s(value);
- return string16(reinterpret_cast<const char16*>(*s), s.length());
-}
-
-// Converts string16 to V8 String.
-v8::Handle<v8::Value> UTF16ToV8Value(const string16& s) {
- return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
-}
-
// Call method of delegate object.
v8::Handle<v8::Value> CallDelegate(v8::Handle<v8::Value> default_value,
v8::Handle<v8::Object> menu,
#include "base/values.h"
#include "browser/native_window.h"
+#include "common/string16_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
namespace api {
-namespace {
-
-// Converts string16 to V8 String.
-v8::Handle<v8::String> UTF16ToV8String(const string16& s) {
- return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
-}
-
-} // namespace
-
Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
: EventEmitter(wrapper),
window_(NativeWindow::Create(options)) {
string16 title = self->window_->GetWebContents()->GetTitle();
- return UTF16ToV8String(title);
+ return UTF16ToV8Value(title);
}
// static
#include "base/logging.h"
#include "base/values.h"
#include "browser/api/atom_api_event.h"
+#include "common/string16_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/browser_thread.h"
#include "vendor/node/src/node.h"
void AtomBrowserBindings::OnRendererMessage(int process_id,
int routing_id,
- const std::string& channel,
+ const string16& channel,
const base::ListValue& args) {
v8::HandleScope scope;
// process.emit(channel, 'message', process_id, routing_id);
std::vector<v8::Handle<v8::Value>> arguments;
arguments.reserve(3 + args.GetSize());
- arguments.push_back(v8::String::New(channel.c_str(), channel.size()));
+ arguments.push_back(UTF16ToV8Value(channel));
const base::Value* value;
if (args.Get(0, &value))
arguments.push_back(converter->ToV8Value(value, context));
void AtomBrowserBindings::OnRendererMessageSync(
int process_id,
int routing_id,
- const std::string& channel,
+ const string16& channel,
const base::ListValue& args,
- std::string* result) {
+ string16* result) {
v8::HandleScope scope;
v8::Handle<v8::Context> context = v8::Context::GetCurrent();
// process.emit(channel, 'sync-message', event, process_id, routing_id);
std::vector<v8::Handle<v8::Value>> arguments;
arguments.reserve(3 + args.GetSize());
- arguments.push_back(v8::String::New(channel.c_str(), channel.size()));
+ arguments.push_back(UTF16ToV8Value(channel));
const base::Value* value;
if (args.Get(0, &value))
arguments.push_back(converter->ToV8Value(value, context));
#ifndef ATOM_BROWSER_API_ATOM_BROWSER_BINDINGS_
#define ATOM_BROWSER_API_ATOM_BROWSER_BINDINGS_
-#include <string>
-
+#include "base/string16.h"
#include "common/api/atom_bindings.h"
namespace base {
// Called when received a message from renderer.
void OnRendererMessage(int process_id,
int routing_id,
- const std::string& channel,
+ const string16& channel,
const base::ListValue& args);
// Called when received a synchronous message from renderer.
void OnRendererMessageSync(int process_id,
int routing_id,
- const std::string& channel,
+ const string16& channel,
const base::ListValue& args,
- std::string* result);
+ string16* result);
// The require('atom').browserMainParts object.
v8::Handle<v8::Object> browser_main_parts() {
}
}
-void NativeWindow::OnRendererMessage(const std::string& channel,
+void NativeWindow::OnRendererMessage(const string16& channel,
const base::ListValue& args) {
AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessage(
GetWebContents()->GetRenderProcessHost()->GetID(),
args);
}
-void NativeWindow::OnRendererMessageSync(const std::string& channel,
+void NativeWindow::OnRendererMessageSync(const string16& channel,
const base::ListValue& args,
IPC::Message* reply_msg) {
- std::string json;
+ string16 json;
AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessageSync(
GetWebContents()->GetRenderProcessHost()->GetID(),
GetWebContents()->GetRoutingID(),
private:
void RendererUnresponsiveDelayed();
- void OnRendererMessage(const std::string& channel,
+ void OnRendererMessage(const string16& channel,
const base::ListValue& args);
- void OnRendererMessageSync(const std::string& channel,
+ void OnRendererMessageSync(const string16& channel,
const base::ListValue& args,
IPC::Message* reply_msg);
// Multiply-included file, no traditional include guard.
-#include <string>
-
+#include "base/string16.h"
#include "base/values.h"
#include "common/draggable_region.h"
#include "content/public/common/common_param_traits.h"
IPC_STRUCT_TRAITS_END()
IPC_MESSAGE_ROUTED2(AtomViewHostMsg_Message,
- std::string /* channel */,
+ string16 /* channel */,
ListValue /* arguments */)
IPC_SYNC_MESSAGE_ROUTED2_1(AtomViewHostMsg_Message_Sync,
- std::string /* channel */,
+ string16 /* channel */,
ListValue /* arguments */,
- std::string /* result (in JSON) */)
+ string16 /* result (in JSON) */)
IPC_MESSAGE_ROUTED2(AtomViewMsg_Message,
- std::string /* channel */,
+ string16 /* channel */,
ListValue /* arguments */)
// Sent by the renderer when the draggable regions are updated.
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STRING16_CONVERSIONS_H_
+#define COMMON_STRING16_CONVERSIONS_H_
+
+#include "v8/include/v8.h"
+
+class string16;
+
+// Converts a V8 value to a string16.
+inline string16 V8ValueToUTF16(v8::Handle<v8::Value> value) {
+ v8::String::Value s(value);
+ return string16(reinterpret_cast<const char16*>(*s), s.length());
+}
+
+// Converts string16 to V8 String.
+inline v8::Handle<v8::Value> UTF16ToV8Value(const string16& s) {
+ return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
+}
+
+#endif // COMMON_STRING16_CONVERSIONS_H_
#include "base/values.h"
#include "common/api/api_messages.h"
+#include "common/string16_conversions.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/v8_value_converter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
if (!args[0]->IsString())
return node::ThrowTypeError("Bad argument");
- std::string channel(*v8::String::Utf8Value(args[0]));
-
+ string16 channel(V8ValueToUTF16(args[0]));
RenderView* render_view = GetCurrentRenderView();
// Convert Arguments to Array, so we can use V8ValueConverter to convert it
return node::ThrowTypeError("Bad argument");
v8::Handle<v8::Context> context = v8::Context::GetCurrent();
- std::string channel(*v8::String::Utf8Value(args[0]));
+ string16 channel(V8ValueToUTF16(args[0]));
// Convert Arguments to Array, so we can use V8ValueConverter to convert it
// to ListValue.
RenderView* render_view = GetCurrentRenderView();
- std::string json;
+ string16 json;
IPC::SyncMessage* message = new AtomViewHostMsg_Message_Sync(
render_view->GetRoutingID(),
channel,
if (!success)
return node::ThrowError("Unable to send AtomViewHostMsg_Message_Sync");
- return scope.Close(v8::String::New(json.data(), json.size()));
+ return scope.Close(UTF16ToV8Value(json));
}
// static
#include "base/logging.h"
#include "base/values.h"
+#include "common/string16_conversions.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/v8_value_converter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
AtomBindings::BindTo(GetProcessObject(context));
}
-void AtomRendererBindings::OnBrowserMessage(const std::string& channel,
+void AtomRendererBindings::OnBrowserMessage(const string16& channel,
const base::ListValue& args) {
if (!render_view_->GetWebView())
return;
std::vector<v8::Handle<v8::Value>> arguments;
arguments.reserve(1 + args.GetSize());
- arguments.push_back(v8::String::New(channel.c_str(), channel.size()));
+ arguments.push_back(UTF16ToV8Value(channel));
for (size_t i = 0; i < args.GetSize(); i++) {
const base::Value* value;
#ifndef ATOM_RENDERER_API_ATOM_RENDERER_BINDINGS_H_
#define ATOM_RENDERER_API_ATOM_RENDERER_BINDINGS_H_
-#include <string>
-
#include "common/api/atom_bindings.h"
+#include "base/string16.h"
+
namespace base {
class ListValue;
}
void BindToFrame(WebKit::WebFrame* frame);
// Dispatch messages from browser.
- void OnBrowserMessage(const std::string& channel,
+ void OnBrowserMessage(const string16& channel,
const base::ListValue& args);
private:
return handled;
}
-void AtomRenderViewObserver::OnBrowserMessage(const std::string& channel,
+void AtomRenderViewObserver::OnBrowserMessage(const string16& channel,
const base::ListValue& args) {
atom_bindings()->OnBrowserMessage(channel, args);
}
virtual void DraggableRegionsChanged(WebKit::WebFrame* frame) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
- void OnBrowserMessage(const std::string& channel,
+ void OnBrowserMessage(const string16& channel,
const base::ListValue& args);
scoped_ptr<AtomRendererBindings> atom_bindings_;