d098923faaa3aed92b04502a002beb0e570f3f44
[platform/framework/web/crosswalk-tizen.git] / src / extension / extension_adapter.h
1 // Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WRT_EXTENSION_EXTENSION_ADAPTER_H_
6 #define WRT_EXTENSION_EXTENSION_ADAPTER_H_
7
8 #include <map>
9
10 #include "extension/extension.h"
11 #include "extension/extension_instance.h"
12
13 #include "extension/xwalk/XW_Extension.h"
14 #include "extension/xwalk/XW_Extension_SyncMessage.h"
15 #include "extension/xwalk/XW_Extension_EntryPoints.h"
16 #include "extension/xwalk/XW_Extension_Runtime.h"
17 #include "extension/xwalk/XW_Extension_Permissions.h"
18
19 namespace wrt {
20
21 class ExtensionAdapter {
22  public:
23   typedef std::map<XW_Extension, Extension*> ExtensionMap;
24   typedef std::map<XW_Instance, ExtensionInstance*> InstanceMap;
25
26   static ExtensionAdapter* GetInstance();
27
28   XW_Extension GetNextXWExtension();
29   XW_Instance GetNextXWInstance();
30
31   void RegisterExtension(Extension* extension);
32   void UnregisterExtension(Extension* extension);
33
34   void RegisterInstance(ExtensionInstance* instance);
35   void UnregisterInstance(ExtensionInstance* instance);
36
37   // Returns the correct struct according to interface asked. This is
38   // passed to external extensions in XW_Initialize() call.
39   static const void* GetInterface(const char* name);
40
41  private:
42   ExtensionAdapter();
43   virtual ~ExtensionAdapter();
44
45   static Extension* GetExtension(XW_Extension xw_extension);
46   static ExtensionInstance* GetExtensionInstance(XW_Instance xw_instance);
47
48   static void CoreSetExtensionName(XW_Extension xw_extension, const char* name);
49   static void CoreSetJavaScriptAPI(XW_Extension xw_extension,
50                                    const char* javascript_api);
51   static void CoreRegisterInstanceCallbacks(XW_Extension xw_extension,
52                                      XW_CreatedInstanceCallback created,
53                                      XW_DestroyedInstanceCallback destroyed);
54   static void CoreRegisterShutdownCallback(XW_Extension xw_extension,
55                                     XW_ShutdownCallback shutdown);
56   static void CoreSetInstanceData(XW_Instance xw_instance, void* data);
57   static void* CoreGetInstanceData(XW_Instance xw_instance);
58   static void MessagingRegister(XW_Extension xw_extension,
59                                 XW_HandleMessageCallback handle_message);
60   static void MessagingPostMessage(XW_Instance xw_instance,
61                                    const char* message);
62   static void SyncMessagingRegister(XW_Extension xw_extension,
63                              XW_HandleSyncMessageCallback handle_sync_message);
64   static void SyncMessagingSetSyncReply(XW_Instance xw_instance,
65                                         const char* reply);
66   static void EntryPointsSetExtraJSEntryPoints(XW_Extension xw_extension,
67                                                const char** entry_points);
68   static void RuntimeGetStringVariable(XW_Extension xw_extension,
69                                        const char* key,
70                                        char* value,
71                                        unsigned int value_len);
72   static int PermissionsCheckAPIAccessControl(XW_Extension xw_extension,
73                                               const char* api_name);
74   static int PermissionsRegisterPermissions(XW_Extension xw_extension,
75                                             const char* perm_table);
76
77   ExtensionMap extension_map_;
78   InstanceMap instance_map_;
79
80   XW_Extension next_xw_extension_;
81   XW_Instance next_xw_instance_;
82 };
83
84 }  // namespace wrt
85
86 #endif  // WRT_EXTENSION_EXTENSION_ADAPTER_H_