Change the chromium header from ewk_chromium.h to EWebKit.h/Ewebkit_internal.h
[platform/framework/web/crosswalk-tizen.git] / extensions / renderer / runtime_ipc_client.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef XWALK_EXTENSIONS_RENDERER_RUNTIME_IPC_CLIENT_H_
18 #define XWALK_EXTENSIONS_RENDERER_RUNTIME_IPC_CLIENT_H_
19
20 #include <v8/v8.h>
21 #include <EWebKit.h>
22 #include <EWebKit_internal.h>
23
24 #include <functional>
25 #include <map>
26 #include <string>
27
28 namespace extensions {
29
30 class RuntimeIPCClient {
31  public:
32   class JSCallback {
33    public:
34     explicit JSCallback(v8::Isolate* isolate,
35                         v8::Handle<v8::Function> callback);
36     ~JSCallback();
37
38     void Call(v8::Isolate* isolate, v8::Handle<v8::Value> args[]);
39    private:
40     v8::Persistent<v8::Function> callback_;
41   };
42
43   typedef std::function<void(const std::string& type,
44                              const std::string& value)> ReplyCallback;
45
46   static RuntimeIPCClient* GetInstance();
47
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);
52
53   void SendMessage(v8::Handle<v8::Context> context,
54                    const std::string& type,
55                    const std::string& id,
56                    const std::string& value);
57
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);
63
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);
68
69   std::string SendSyncMessage(v8::Handle<v8::Context> context,
70                               const std::string& type,
71                               const std::string& id,
72                               const std::string& value);
73
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);
79
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);
85
86   void HandleMessageFromRuntime(const Ewk_IPC_Wrt_Message_Data* msg);
87
88   int GetRoutingId(v8::Handle<v8::Context> context);
89
90   void SetRoutingId(v8::Handle<v8::Context> context, int routing_id);
91
92  private:
93   RuntimeIPCClient();
94
95   std::map<std::string, ReplyCallback> callbacks_;
96 };
97
98 }  // namespace extensions
99
100 #endif  // XWALK_EXTENSIONS_RENDERER_RUNTIME_IPC_CLIENT_H_