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 #include "common/extension_adapter.h"
8 #include "common/XW_Extension_EntryPoints.h"
12 XW_Extension g_extension = 0;
14 const XW_CoreInterface* g_core = NULL;
15 const XW_MessagingInterface* g_messaging = NULL;
16 const XW_Internal_SyncMessagingInterface* g_sync_messaging = NULL;
17 const XW_Internal_EntryPointsInterface* g_entry_points = NULL;
23 int32_t InitializeExtension(XW_Extension extension,
24 XW_GetInterface get_interface,
27 const char** entry_points,
28 XW_CreatedInstanceCallback created,
29 XW_DestroyedInstanceCallback destroyed,
30 XW_HandleMessageCallback handle_message,
31 XW_HandleSyncMessageCallback handle_sync_message) {
32 if (g_extension != 0) {
33 std::cerr << "Can't initialize same extension multiple times!\n";
37 g_extension = extension;
39 g_core = reinterpret_cast<const XW_CoreInterface*>(
40 get_interface(XW_CORE_INTERFACE));
42 std::cerr << "Can't initialize extension: error getting Core interface.\n";
45 g_core->SetExtensionName(extension, name);
46 g_core->SetJavaScriptAPI(extension, api);
47 g_core->RegisterInstanceCallbacks(extension, created, destroyed);
49 g_messaging = reinterpret_cast<const XW_MessagingInterface*>(
50 get_interface(XW_MESSAGING_INTERFACE));
53 "Can't initialize extension: error getting Messaging interface.\n";
56 g_messaging->Register(extension, handle_message);
59 reinterpret_cast<const XW_Internal_SyncMessagingInterface*>(
60 get_interface(XW_INTERNAL_SYNC_MESSAGING_INTERFACE));
61 if (!g_sync_messaging) {
63 "Can't initialize extension: error getting Messaging interface.\n";
66 g_sync_messaging->Register(extension, handle_sync_message);
68 g_entry_points = reinterpret_cast<const XW_Internal_EntryPointsInterface*>(
69 get_interface(XW_INTERNAL_ENTRY_POINTS_INTERFACE));
70 if (!g_entry_points) {
71 std::cerr << "NOTE: Entry points interface not available in this version "
72 << "of Crosswalk, ignoring entry point data for extensions.\n";
74 g_entry_points->SetExtraJSEntryPoints(extension, entry_points);
80 void PostMessage(XW_Instance instance, const char* message) {
81 g_messaging->PostMessage(instance, message);
84 void SetSyncReply(XW_Instance instance, const char* reply) {
85 g_sync_messaging->SetSyncReply(instance, reply);
88 } // namespace internal