2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef XWALK_EXTENSIONS_RENDERER_RUNTIME_IPC_CLIENT_H_
18 #define XWALK_EXTENSIONS_RENDERER_RUNTIME_IPC_CLIENT_H_
22 #include <EWebKit_internal.h>
28 namespace extensions {
30 class RuntimeIPCClient {
34 explicit JSCallback(v8::Isolate* isolate,
35 v8::Handle<v8::Function> callback);
38 void Call(v8::Isolate* isolate, v8::Handle<v8::Value> args[]);
40 v8::Persistent<v8::Function> callback_;
43 typedef std::function<void(const std::string& type,
44 const std::string& value)> ReplyCallback;
46 static RuntimeIPCClient* GetInstance();
48 // Send message to BrowserProcess without reply
49 void SendMessage(v8::Handle<v8::Context> context,
50 const std::string& type,
51 const std::string& value);
53 void SendMessage(v8::Handle<v8::Context> context,
54 const std::string& type,
55 const std::string& id,
56 const std::string& value);
58 void SendMessage(v8::Handle<v8::Context> context,
59 const std::string& type,
60 const std::string& id,
61 const std::string& ref_id,
62 const std::string& value);
64 // Send message to BrowserProcess synchronous with reply
65 std::string SendSyncMessage(v8::Handle<v8::Context> context,
66 const std::string& type,
67 const std::string& value);
69 std::string SendSyncMessage(v8::Handle<v8::Context> context,
70 const std::string& type,
71 const std::string& id,
72 const std::string& value);
74 std::string SendSyncMessage(v8::Handle<v8::Context> context,
75 const std::string& type,
76 const std::string& id,
77 const std::string& ref_id,
78 const std::string& value);
80 // Send message to BrowserProcess asynchronous,
81 // reply message will be passed to callback function.
82 void SendAsyncMessage(v8::Handle<v8::Context> context,
83 const std::string& type, const std::string& value,
84 ReplyCallback callback);
86 void HandleMessageFromRuntime(const Ewk_IPC_Wrt_Message_Data* msg);
88 int GetRoutingId(v8::Handle<v8::Context> context);
90 void SetRoutingId(v8::Handle<v8::Context> context, int routing_id);
95 std::map<std::string, ReplyCallback> callbacks_;
98 } // namespace extensions
100 #endif // XWALK_EXTENSIONS_RENDERER_RUNTIME_IPC_CLIENT_H_