Fix RuntimeIPCClient to set routing_id in V8Context
authorWonYoung Choi <wy80.choi@samsung.com>
Thu, 22 Oct 2015 10:11:56 +0000 (19:11 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Fri, 23 Oct 2015 00:27:55 +0000 (09:27 +0900)
Chromium-EFL creates a routing index for each global context.
The index is stored in V8Context's embedder data with index number 12.

extensions/renderer/runtime_ipc_client.cc
extensions/renderer/runtime_ipc_client.h
extensions/renderer/xwalk_extension_module.cc
runtime/renderer/injected_bundle.cc

index b48ad99..aaae627 100644 (file)
 
 namespace extensions {
 
+namespace {
+
+const int kRoutingIdEmbedderDataIndex = 12;
+
+}  // namespace
+
 RuntimeIPCClient::JSCallback::JSCallback(v8::Isolate* isolate,
                                          v8::Handle<v8::Function> callback) {
   callback_.Reset(isolate, callback);
@@ -46,18 +52,39 @@ RuntimeIPCClient* RuntimeIPCClient::GetInstance() {
   return &self;
 }
 
-RuntimeIPCClient::RuntimeIPCClient() : routing_id_(0) {
+RuntimeIPCClient::RuntimeIPCClient() {
+}
+
+int RuntimeIPCClient::GetRoutingId(v8::Handle<v8::Context> context) {
+  v8::Handle<v8::Value> value =
+      context->GetEmbedderData(kRoutingIdEmbedderDataIndex);
+  int routing_id = 0;
+  if (value->IsNumber()) {
+    routing_id = value->IntegerValue();
+  } else {
+    LOGGER(WARN) << "Failed to get routing index from context.";
+  }
+
+  return routing_id;
+}
+
+void RuntimeIPCClient::SetRoutingId(v8::Handle<v8::Context> context,
+                                    int routing_id) {
+  context->SetEmbedderData(kRoutingIdEmbedderDataIndex,
+                           v8::Integer::New(context->GetIsolate(), routing_id));
 }
 
-void RuntimeIPCClient::SendMessage(const std::string& type,
+void RuntimeIPCClient::SendMessage(v8::Handle<v8::Context> context,
+                                   const std::string& type,
                                    const std::string& value) {
   Ewk_IPC_Wrt_Message_Data* msg = ewk_ipc_wrt_message_data_new();
   ewk_ipc_wrt_message_data_id_set(msg, "");
   ewk_ipc_wrt_message_data_type_set(msg, type.c_str());
   ewk_ipc_wrt_message_data_value_set(msg, value.c_str());
 
-  if (routing_id_ > 0) {
-    if (!ewk_ipc_plugins_message_send(routing_id_, msg)) {
+  int routing_id = GetRoutingId(context);
+  if (routing_id > 0) {
+    if (!ewk_ipc_plugins_message_send(routing_id, msg)) {
       LOGGER(ERROR) << "Failed to send message to runtime using ewk_ipc.";
     }
   }
@@ -65,14 +92,16 @@ void RuntimeIPCClient::SendMessage(const std::string& type,
   ewk_ipc_wrt_message_data_del(msg);
 }
 
-std::string RuntimeIPCClient::SendSyncMessage(const std::string& type,
+std::string RuntimeIPCClient::SendSyncMessage(v8::Handle<v8::Context> context,
+                                              const std::string& type,
                                               const std::string& value) {
   Ewk_IPC_Wrt_Message_Data* msg = ewk_ipc_wrt_message_data_new();
   ewk_ipc_wrt_message_data_type_set(msg, type.c_str());
   ewk_ipc_wrt_message_data_value_set(msg, value.c_str());
 
-  if (routing_id_ > 0) {
-    if (!ewk_ipc_plugins_sync_message_send(routing_id_, msg)) {
+  int routing_id = GetRoutingId(context);
+  if (routing_id > 0) {
+    if (!ewk_ipc_plugins_sync_message_send(routing_id, msg)) {
       LOGGER(ERROR) << "Failed to send message to runtime using ewk_ipc.";
       ewk_ipc_wrt_message_data_del(msg);
       return std::string();
@@ -88,7 +117,8 @@ std::string RuntimeIPCClient::SendSyncMessage(const std::string& type,
   return result;
 }
 
-void RuntimeIPCClient::SendAsyncMessage(const std::string& type,
+void RuntimeIPCClient::SendAsyncMessage(v8::Handle<v8::Context> context,
+                                        const std::string& type,
                                         const std::string& value,
                                         ReplyCallback callback) {
   std::string msg_id = common::utils::GenerateUUID();
@@ -98,8 +128,9 @@ void RuntimeIPCClient::SendAsyncMessage(const std::string& type,
   ewk_ipc_wrt_message_data_type_set(msg, type.c_str());
   ewk_ipc_wrt_message_data_value_set(msg, value.c_str());
 
-  if (routing_id_ > 0) {
-    if (!ewk_ipc_plugins_message_send(routing_id_, msg)) {
+  int routing_id = GetRoutingId(context);
+  if (routing_id > 0) {
+    if (!ewk_ipc_plugins_message_send(routing_id, msg)) {
       LOGGER(ERROR) << "Failed to send message to runtime using ewk_ipc.";
       ewk_ipc_wrt_message_data_del(msg);
       return;
index d04575b..c743570 100644 (file)
@@ -45,26 +45,29 @@ class RuntimeIPCClient {
   static RuntimeIPCClient* GetInstance();
 
   // Send message to BrowserProcess without reply
-  void SendMessage(const std::string& type, const std::string& value);
+  void SendMessage(v8::Handle<v8::Context> context,
+                   const std::string& type, const std::string& value);
 
   // Send message to BrowserProcess synchronous with reply
-  std::string SendSyncMessage(const std::string& type,
+  std::string SendSyncMessage(v8::Handle<v8::Context> context,
+                              const std::string& type,
                               const std::string& value);
 
   // Send message to BrowserProcess asynchronous,
   // reply message will be passed to callback function.
-  void SendAsyncMessage(const std::string& type, const std::string& value,
+  void SendAsyncMessage(v8::Handle<v8::Context> context,
+                        const std::string& type, const std::string& value,
                         ReplyCallback callback);
 
   void HandleMessageFromRuntime(const Ewk_IPC_Wrt_Message_Data* msg);
 
-  int routing_id() const { return routing_id_; }
-  void set_routing_id(int routing_id) { routing_id_ = routing_id; }
+  int GetRoutingId(v8::Handle<v8::Context> context);
+
+  void SetRoutingId(v8::Handle<v8::Context> context, int routing_id);
 
  private:
   RuntimeIPCClient();
 
-  int routing_id_;
   std::map<std::string, ReplyCallback> callbacks_;
 };
 
index e7d6f3c..82e22c1 100644 (file)
@@ -411,7 +411,8 @@ void XWalkExtensionModule::SendRuntimeMessageCallback(
   }
 
   RuntimeIPCClient* rc = RuntimeIPCClient::GetInstance();
-  rc->SendMessage(std::string(*type), data_str);
+  rc->SendMessage(module->module_system_->GetV8Context(),
+                  std::string(*type), data_str);
 
   result.Set(true);
 }
@@ -436,7 +437,9 @@ void XWalkExtensionModule::SendRuntimeSyncMessageCallback(
   }
 
   RuntimeIPCClient* rc = RuntimeIPCClient::GetInstance();
-  std::string reply = rc->SendSyncMessage(std::string(*type), data_str);
+  std::string reply = rc->SendSyncMessage(
+      module->module_system_->GetV8Context(),
+      std::string(*type), data_str);
 
   result.Set(v8::String::NewFromUtf8(isolate, reply.c_str()));
 }
@@ -488,7 +491,8 @@ void XWalkExtensionModule::SendRuntimeAsyncMessageCallback(
   };
 
   RuntimeIPCClient* rc = RuntimeIPCClient::GetInstance();
-  rc->SendAsyncMessage(std::string(*type), value_str, callback);
+  rc->SendAsyncMessage(module->module_system_->GetV8Context(),
+                       std::string(*type), value_str, callback);
 
   result.Set(true);
 }
index 4f9cb4c..57cfc3b 100644 (file)
@@ -109,7 +109,7 @@ extern "C" void DynamicPluginStartSession(const char* tizen_id,
   // Initialize RuntimeIPCClient
   extensions::RuntimeIPCClient* rc =
       extensions::RuntimeIPCClient::GetInstance();
-  rc->set_routing_id(routing_handle);
+  rc->SetRoutingId(context, routing_handle);
   STEP_PROFILE_END("Initialize RuntimeIPCClient");
 
   extensions::XWalkExtensionRendererController& controller =