}
}
- auto callback = [](const std::string& /*type*/,
- const std::string& value,
- RuntimeIPCClient::JSCallback* js_callback) -> void {
- if (js_callback) {
- v8::Handle<v8::Value> args[] = {
- v8::String::NewFromUtf8(js_callback->isolate(), value.c_str()) };
- js_callback->Call(args);
+ auto callback = [js_callback](const std::string& /*type*/,
+ const std::string& value) -> void {
+ if (!js_callback) {
+ LOGGER(ERROR) << "JsCallback is NULL.";
+ return;
}
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::HandleScope handle_scope(isolate);
+ v8::Handle<v8::Value> args[] = {
+ v8::String::NewFromUtf8(isolate, value.c_str()) };
+ js_callback->Call(isolate, args);
+ delete js_callback;
};
RuntimeIPCClient* rc = RuntimeIPCClient::GetInstance();
- rc->SendAsyncMessage(std::string(*type), value_str, callback, js_callback);
+ rc->SendAsyncMessage(std::string(*type), value_str, callback);
result.Set(true);
}
#include <unistd.h>
#include <v8.h>
#include <ewk_ipc_message.h>
+#include <Ecore.h>
#include <string>
#include <memory>
extern "C" void DynamicSetWidgetInfo(const char* tizen_id) {
LOGGER(DEBUG) << "InjectedBundle::DynamicSetWidgetInfo !!" << tizen_id;
+ ecore_init();
wrt::BundleGlobalData::GetInstance()->Initialize(tizen_id);
}
extern "C" void DynamicUrlParsing(
std::string* old_url, std::string* new_url, const char* tizen_id) {
- LOGGER(DEBUG) << "InjectedBundle::DynamicUrlParsing !!" << tizen_id;
+ // LOGGER(DEBUG) << "InjectedBundle::DynamicUrlParsing !!" << tizen_id;
auto res_manager = wrt::BundleGlobalData::GetInstance()->resource_manager();
if (res_manager == NULL) {
LOGGER(ERROR) << "Widget Info was not set, Resource Manager is NULL";
}
extern "C" void DynamicDatabaseAttach(int /*attach*/) {
- LOGGER(DEBUG) << "InjectedBundle::DynamicDatabaseAttach !!";
+ // LOGGER(DEBUG) << "InjectedBundle::DynamicDatabaseAttach !!";
}
extern "C" void DynamicOnIPCMessage(const Ewk_IPC_Wrt_Message_Data& data) {
}
extern "C" void DynamicPreloading() {
- LOGGER(DEBUG) << "InjectedBundle::DynamicPreloading !!";
+ // LOGGER(DEBUG) << "InjectedBundle::DynamicPreloading !!";
}
namespace wrt {
RuntimeIPCClient::JSCallback::JSCallback(v8::Isolate* isolate,
- v8::Handle<v8::Function> callback)
- : isolate_(isolate) {
+ v8::Handle<v8::Function> callback) {
callback_.Reset(isolate, callback);
}
callback_.Reset();
}
-void RuntimeIPCClient::JSCallback::Call(v8::Handle<v8::Value> args[]) {
+void RuntimeIPCClient::JSCallback::Call(v8::Isolate* isolate,
+ v8::Handle<v8::Value> args[]) {
if (!callback_.IsEmpty()) {
- v8::HandleScope handle_scope(isolate_);
+ v8::HandleScope handle_scope(isolate);
v8::Handle<v8::Function> func =
- v8::Local<v8::Function>::New(isolate_, callback_);
+ v8::Local<v8::Function>::New(isolate, callback_);
func->Call(func, 1, args);
}
}
void RuntimeIPCClient::SendAsyncMessage(const std::string& type,
const std::string& value,
- ReplyCallback callback,
- JSCallback* js_callback) {
+ ReplyCallback callback) {
std::string msg_id = utils::GenerateUUID();
Ewk_IPC_Wrt_Message_Data* msg = ewk_ipc_wrt_message_data_new();
}
}
- callbacks_[msg_id].callback = callback;
- callbacks_[msg_id].js_callback = js_callback;
+ callbacks_[msg_id] = callback;
ewk_ipc_wrt_message_data_del(msg);
}
Eina_Stringshare* msg_type = ewk_ipc_wrt_message_data_type_get(msg);
Eina_Stringshare* msg_value = ewk_ipc_wrt_message_data_value_get(msg);
- const AsyncData& async_data = it->second;
- async_data.callback(msg_type, msg_value, async_data.js_callback);
+ ReplyCallback func = it->second;
+ if (func) {
+ func(msg_type, msg_value);
+ }
+
callbacks_.erase(it);
eina_stringshare_del(msg_refid);
v8::Handle<v8::Function> callback);
~JSCallback();
- v8::Isolate* isolate() const { return isolate_; }
-
- void Call(v8::Handle<v8::Value> args[]);
+ void Call(v8::Isolate* isolate, v8::Handle<v8::Value> args[]);
private:
- v8::Isolate* isolate_;
v8::Persistent<v8::Function> callback_;
};
typedef std::function<void(const std::string& type,
- const std::string& value,
- JSCallback* js_callback)> ReplyCallback;
+ const std::string& value)> ReplyCallback;
static RuntimeIPCClient* GetInstance();
// Send message to BrowserProcess asynchronous,
// reply message will be passed to callback function.
void SendAsyncMessage(const std::string& type, const std::string& value,
- ReplyCallback callback, JSCallback* js_callback);
+ ReplyCallback callback);
void HandleMessageFromRuntime(const Ewk_IPC_Wrt_Message_Data* msg);
void set_routing_id(int routing_id) { routing_id_ = routing_id; }
private:
- class AsyncData {
- public:
- ~AsyncData() {
- if (js_callback) delete js_callback;
- }
-
- ReplyCallback callback;
- JSCallback* js_callback;
- };
-
RuntimeIPCClient();
int routing_id_;
- std::map<std::string, AsyncData> callbacks_;
+ std::map<std::string, ReplyCallback> callbacks_;
};
} // namespace wrt
ewk_ipc_wrt_message_data_del(ans);
} else if (TYPE_IS("tizen://test-sync")) {
// TODO(wy80.choi): this type should be removed after finish test
- ewk_ipc_wrt_message_data_value_set(msg, "reply!!");
+ ewk_ipc_wrt_message_data_value_set(msg, "Reply!!");
+ } else if (TYPE_IS("tizen://test-async")) {
+ // TODO(wy80.choi): this type should be removed after finish test
+ Ewk_IPC_Wrt_Message_Data* ans = ewk_ipc_wrt_message_data_new();
+ ewk_ipc_wrt_message_data_type_set(ans, msg_type);
+ ewk_ipc_wrt_message_data_reference_id_set(ans, msg_id);
+ ewk_ipc_wrt_message_data_value_set(ans, "Aync Reply!!");
+ if (!ewk_ipc_wrt_message_send(ewk_context_, ans)) {
+ LOGGER(ERROR) << "Failed to send response";
+ }
+ ewk_ipc_wrt_message_data_del(ans);
}
#undef TYPE_IS