Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / extensions / common / xwalk_external_instance.h
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.
4
5 #ifndef XWALK_EXTENSIONS_COMMON_XWALK_EXTERNAL_INSTANCE_H_
6 #define XWALK_EXTENSIONS_COMMON_XWALK_EXTERNAL_INSTANCE_H_
7
8 #include <string>
9 #include "xwalk/extensions/common/xwalk_extension.h"
10 #include "xwalk/extensions/public/XW_Extension.h"
11 #include "xwalk/extensions/public/XW_Extension_SyncMessage.h"
12
13 namespace xwalk {
14 namespace extensions {
15
16 class XWalkExternalAdapter;
17 class XWalkExternalExtension;
18
19 // XWalkExternalInstance implements the concrete context of execution of an
20 // external extension.
21 //
22 // It works together with XWalkExternalAdapter to handle calls from shared
23 // library, and with XWalkExternalExtension to get the appropriate
24 // callbacks. The associated XW_Instance is used to identify this context when
25 // calling the shared library.
26 class XWalkExternalInstance : public XWalkExtensionInstance {
27  public:
28   XWalkExternalInstance(XWalkExternalExtension* extension,
29                         XW_Instance xw_instance);
30   virtual ~XWalkExternalInstance();
31
32  private:
33   friend class XWalkExternalAdapter;
34
35   // XWalkExtensionInstance implementation.
36   void HandleMessage(scoped_ptr<base::Value> msg) override;
37   void HandleSyncMessage(scoped_ptr<base::Value> msg) override;
38
39   // XW_CoreInterface_1 (from XW_Extension.h) implementation.
40   void CoreSetInstanceData(void* data);
41   void* CoreGetInstanceData();
42
43   // XW_MessagingInterface_1 (from XW_Extension.h) implementation.
44   void MessagingPostMessage(const char* msg);
45
46   // XW_Internal_SyncMessagingInterface_1 (from XW_Extension_SyncMessage.h)
47   // implementation.
48   void SyncMessagingSetSyncReply(const char* reply);
49
50   XW_Instance xw_instance_;
51   std::string sync_reply_;
52   XWalkExternalExtension* extension_;
53   void* instance_data_;
54   bool is_handling_sync_msg_;
55
56   DISALLOW_COPY_AND_ASSIGN(XWalkExternalInstance);
57 };
58
59 }  // namespace extensions
60 }  // namespace xwalk
61
62 #endif  // XWALK_EXTENSIONS_COMMON_XWALK_EXTERNAL_INSTANCE_H_