Tizen 2.0 Release
[framework/web/wrt-plugins-common.git] / src / 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
43     class Options : DPL::Noncopyable {
44       public:
45         enum class ClassType{
46             Class,
47             Function,
48             Interface
49         };
50
51         enum class IFrameObject{
52             None,
53             Reference,
54             CreateInstance
55         };
56
57         enum class IFrameNotice{
58             None,
59             AlwaysNotice
60         };
61
62         //only for function
63         enum class IFrameOverlay{
64            Ignored,
65            UseOverlayed,
66            OverlayedBeforeOriginal
67         };
68
69         typedef js_object_instance_t ObjectInstance;
70         typedef java_script_context_t JsContext;
71         typedef void* PrivateData;
72
73         public:
74           ClassType getType() const;
75
76           IFrameObject getIframeObject() const;
77           IFrameNotice getIframeNotice() const;
78           IFrameOverlay getIframeOverlay() const;
79           js_function_impl getFunctionImpl() const;
80
81           void invokeCallback(JsContext ctx,
82                               ObjectInstance iframe,
83                               ObjectInstance object) const;
84
85           PrivateData getPrivateData() const;
86
87         private:
88           const ClassOptions* m_options;
89
90         private:
91           explicit Options(const ClassOptions* options) : m_options(options)
92         {
93             assert(options && "Dont create empty options");
94         }
95
96         friend class JSObjectDeclaration;
97
98     };
99
100     typedef std::shared_ptr<Options> OptionsPtr;
101
102   public:
103
104     explicit JSObjectDeclaration(js_entity_definition_ptr_t declaration);
105
106     virtual const std::string& getName() const
107     {
108         return m_name;
109     }
110
111     virtual const std::string& getParentName() const
112     {
113         return m_parentName;
114     }
115
116     virtual ConstClassTemplate getClassTemplate() const
117     {
118         return m_classTemplate;
119     }
120
121     virtual const std::string& getInterfaceName() const
122     {
123         return m_interfaceName;
124     }
125
126     virtual ConstructorCallback getConstructorCallback() const
127     {
128         return m_constructorCallback;
129     }
130
131
132     const OptionsPtr getOptions() const{
133         return m_options;
134     }
135
136     bool checkIframesSupported() const;
137
138     virtual ~JSObjectDeclaration();
139
140   private:
141     std::string m_name;
142     std::string m_parentName;
143     std::string m_interfaceName;
144     ConstClassTemplate m_classTemplate;
145     ConstructorCallback m_constructorCallback;
146     OptionsPtr m_options;
147 };
148
149 typedef DPL::SharedPtr<JSObjectDeclaration> JSObjectDeclarationPtr;
150
151 #endif