1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_EXTENSIONS_COMMON_XWALK_EXTERNAL_EXTENSION_H_
6 #define XWALK_EXTENSIONS_COMMON_XWALK_EXTERNAL_EXTENSION_H_
9 #include "base/values.h"
10 #include "base/scoped_native_library.h"
11 #include "xwalk/extensions/common/xwalk_extension.h"
12 #include "xwalk/extensions/public/XW_Extension.h"
13 #include "xwalk/extensions/public/XW_Extension_SyncMessage.h"
20 namespace extensions {
22 class XWalkExternalAdapter;
23 class XWalkExternalInstance;
25 // XWalkExternalExtension implements an XWalkExtension backed by a shared
26 // library implemented using our C ABI (see XW_Extension.h).
28 // It works together with XWalkExternalAdapter to handle calls from shared
29 // library, and store the callbacks to call it back later. The associated
30 // XW_Extension is used to identify this extension when calling the shared
32 class XWalkExternalExtension : public XWalkExtension {
34 explicit XWalkExternalExtension(const base::FilePath& path);
36 virtual ~XWalkExternalExtension();
40 void set_runtime_variables(const base::ValueMap& runtime_variables) {
41 runtime_variables_ = runtime_variables;
45 friend class XWalkExternalAdapter;
46 friend class XWalkExternalInstance;
48 // Variables from the browser process. Usually things like currently-running
50 base::ValueMap runtime_variables_;
52 // XWalkExtension implementation.
53 virtual XWalkExtensionInstance* CreateInstance() OVERRIDE;
55 // XW_CoreInterface_1 (from XW_Extension.h) implementation.
56 void CoreSetExtensionName(const char* name);
57 void CoreSetJavaScriptAPI(const char* js_api);
58 void CoreRegisterInstanceCallbacks(
59 XW_CreatedInstanceCallback created_callback,
60 XW_DestroyedInstanceCallback destroyed_callback);
61 void CoreRegisterShutdownCallback(XW_ShutdownCallback callback);
62 void EntryPointsSetExtraJSEntryPoints(const char** entry_points);
64 // XW_MessagingInterface_1 (from XW_Extension.h) implementation.
65 void MessagingRegister(XW_HandleMessageCallback callback);
67 // XW_Internal_SyncMessagingInterface_1 (from XW_Extension.h) implementation.
68 void SyncMessagingRegister(XW_HandleSyncMessageCallback callback);
70 // XW_Internal_BrowserInterface_1 (from XW_Browser.h) implementation.
71 void RuntimeGetStringVariable(const char* key, char* value, size_t value_len);
73 base::ScopedNativeLibrary library_;
74 XW_Extension xw_extension_;
76 XW_CreatedInstanceCallback created_instance_callback_;
77 XW_DestroyedInstanceCallback destroyed_instance_callback_;
78 XW_ShutdownCallback shutdown_callback_;
79 XW_HandleMessageCallback handle_msg_callback_;
80 XW_HandleSyncMessageCallback handle_sync_msg_callback_;
84 DISALLOW_COPY_AND_ASSIGN(XWalkExternalExtension);
87 } // namespace extensions
90 #endif // XWALK_EXTENSIONS_COMMON_XWALK_EXTERNAL_EXTENSION_H_