Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / Commons / JSObjectDeclaration.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    js_object_declaration.h
18  * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
19  * @version
20  * @brief
21  */
22
23 #ifndef WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_DECLARATION_H_
24 #define WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_DECLARATION_H_
25
26 #include <string>
27 #include <memory>
28 #include <cassert>
29 #include <dpl/shared_ptr.h>
30 #include <dpl/noncopyable.h>
31 #include <dpl/log/log.h>
32 #include <wrt_plugin_export.h>
33
34 class JSObjectDeclaration : private DPL::Noncopyable
35 {
36   public:
37     typedef const void* ConstClassTemplate;
38     typedef void* ClassTemplate;
39     typedef js_class_constructor_cb_t ConstructorCallback;
40     typedef class_definition_options_t ClassOptions;
41
42     class Options : DPL::Noncopyable
43     {
44       public:
45         enum class ClassType
46         {
47             Class,
48             Function,
49             Interface
50         };
51
52         enum class IFrameObject
53         {
54             None,
55             Reference,
56             CreateInstance
57         };
58
59         enum class IFrameNotice
60         {
61             None,
62             AlwaysNotice
63         };
64
65         //only for function
66         enum class IFrameOverlay
67         {
68             Ignored,
69             UseOverlayed,           //deprecated
70             OverlayedBeforeOriginal //deprecated
71         };
72
73         typedef js_object_instance_t ObjectInstance;
74         typedef java_script_context_t JsContext;
75         typedef void* PrivateData;
76
77       public:
78         ClassType getType() const;
79
80         IFrameObject getIframeObject() const;
81         IFrameNotice getIframeNotice() const;
82         js_function_impl getFunctionImpl() const;
83
84         void invokeCallback(JsContext ctx,
85                             ObjectInstance iframe,
86                             ObjectInstance object) const;
87
88         PrivateData getPrivateData() const;
89
90       private:
91         const ClassOptions* m_options;
92
93       private:
94         explicit Options(const ClassOptions* options) : m_options(options)
95         {
96             assert(options && "Dont create empty options");
97         }
98
99         friend class JSObjectDeclaration;
100     };
101
102     typedef std::shared_ptr<Options> OptionsPtr;
103
104   public:
105
106     explicit JSObjectDeclaration(js_entity_definition_ptr_t declaration);
107
108     virtual const std::string& getName() const
109     {
110         return m_name;
111     }
112
113     virtual const std::string& getParentName() const
114     {
115         return m_parentName;
116     }
117
118     virtual ConstClassTemplate getClassTemplate() const
119     {
120         return m_classTemplate;
121     }
122
123     virtual const std::string& getInterfaceName() const
124     {
125         return m_interfaceName;
126     }
127
128     virtual ConstructorCallback getConstructorCallback() const
129     {
130         return m_constructorCallback;
131     }
132
133     const OptionsPtr getOptions() const
134     {
135         return m_options;
136     }
137
138     bool checkIframesSupported() const;
139
140     virtual ~JSObjectDeclaration();
141
142   private:
143     std::string m_name;
144     std::string m_parentName;
145     std::string m_interfaceName;
146     ConstClassTemplate m_classTemplate;
147     ConstructorCallback m_constructorCallback;
148     OptionsPtr m_options;
149 };
150
151 typedef DPL::SharedPtr<JSObjectDeclaration> JSObjectDeclarationPtr;
152
153 #endif