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.
5 #ifndef WRT_EXTENSION_EXTENSION_ADAPTER_H_
6 #define WRT_EXTENSION_EXTENSION_ADAPTER_H_
10 #include "extension/extension.h"
11 #include "extension/extension_instance.h"
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"
21 class ExtensionAdapter {
23 typedef std::map<XW_Extension, Extension*> ExtensionMap;
24 typedef std::map<XW_Instance, ExtensionInstance*> InstanceMap;
26 static ExtensionAdapter* GetInstance();
28 XW_Extension GetNextXWExtension();
29 XW_Instance GetNextXWInstance();
31 void RegisterExtension(Extension* extension);
32 void UnregisterExtension(Extension* extension);
34 void RegisterInstance(ExtensionInstance* instance);
35 void UnregisterInstance(ExtensionInstance* instance);
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);
43 virtual ~ExtensionAdapter();
45 static Extension* GetExtension(XW_Extension xw_extension);
46 static ExtensionInstance* GetExtensionInstance(XW_Instance xw_instance);
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,
62 static void SyncMessagingRegister(XW_Extension xw_extension,
63 XW_HandleSyncMessageCallback handle_sync_message);
64 static void SyncMessagingSetSyncReply(XW_Instance xw_instance,
66 static void EntryPointsSetExtraJSEntryPoints(XW_Extension xw_extension,
67 const char** entry_points);
68 static void RuntimeGetStringVariable(XW_Extension xw_extension,
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);
77 ExtensionMap extension_map_;
78 InstanceMap instance_map_;
80 XW_Extension next_xw_extension_;
81 XW_Instance next_xw_instance_;
86 #endif // WRT_EXTENSION_EXTENSION_ADAPTER_H_