Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / Commons / JSObjectDeclaration.cpp
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.cpp
18  * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
19  * @version
20  * @brief
21  */
22
23 #include <dpl/log/log.h>
24 #include <dpl/assert.h>
25 #include "JSObjectDeclaration.h"
26
27 JSObjectDeclaration::JSObjectDeclaration(js_entity_definition_ptr_t classD) :
28     m_name(classD->object_name),
29     m_parentName(classD->parent_name),
30     m_interfaceName(classD->interface_name),
31     m_classTemplate(NULL),
32     m_constructorCallback(classD->js_class_constructor_cb)
33 {
34     if (NULL != classD->js_class_template_getter_fun)
35     {
36         m_classTemplate = classD->js_class_template_getter_fun();
37     }
38     if(classD->class_options){
39         LogDebug("class options is not a null");
40         m_options = OptionsPtr(new Options(classD->class_options));
41     }
42 }
43
44 JSObjectDeclaration::~JSObjectDeclaration()
45 {
46 }
47
48 bool JSObjectDeclaration::checkIframesSupported() const{
49     LogDebug("Check iframe supported");
50     if(!m_options ||
51        m_options->getIframeObject() == Options::IFrameObject::None)
52     {
53         LogDebug("Iframe NOT supported for object: " << getName());
54         return false;
55     }
56
57     LogDebug("Iframe supported for object: " << getName());
58
59     return true;
60 }
61
62 JSObjectDeclaration::Options::ClassType
63     JSObjectDeclaration::Options::getType() const
64 {
65     LogDebug("Get type field from declaration's option");
66     Assert(m_options && "Pointer to options is NULL");
67
68     switch(m_options->type){
69     case JS_CLASS: return ClassType::Class;
70     case JS_FUNCTION: return ClassType::Function;
71     case JS_INTERFACE: return ClassType::Interface;
72     default: Assert(0 && "Wrong value of type");
73     }
74 }
75
76 JSObjectDeclaration::Options::IFrameObject
77     JSObjectDeclaration::Options::getIframeObject() const
78 {
79     LogDebug("Get Frame Option");
80     Assert(m_options && "Options object is NULL");
81
82     switch(m_options->iframe_option){
83     case NONE: return IFrameObject::None;
84     case REFERENCE: return IFrameObject::Reference;
85     case CREATE_INSTANCE: return IFrameObject::CreateInstance;
86     default:
87         Assert(0 && "Wrong value of behaviour type");
88     }
89 }
90
91 JSObjectDeclaration::Options::IFrameNotice
92     JSObjectDeclaration::Options::getIframeNotice() const
93 {
94     LogDebug("Get Frame Option");
95     Assert(m_options && "Pointer to options is null");
96
97     switch(m_options->iframe_notice){
98     case NONE_NOTICE: return IFrameNotice::None;
99     case ALWAYS_NOTICE: return IFrameNotice::AlwaysNotice;
100     default:
101         Assert(0 && "Wrong value of notice option");
102     }
103 }
104
105 JSObjectDeclaration::Options::IFrameOverlay
106     JSObjectDeclaration::Options::getIframeOverlay() const
107 {
108     LogDebug("Get Frame Option");
109     Assert(m_options && "Pointer to options is null");
110
111     switch(m_options->iframe_overlay){
112     case IGNORED: return IFrameOverlay::Ignored;
113     case USE_OVERLAYED: return IFrameOverlay::UseOverlayed;
114     case OVERLAYED_BEFORE_ORIGINAL:
115             return IFrameOverlay::OverlayedBeforeOriginal;
116     default:
117         Assert(0 && "Wrong value of overlay option");
118     }
119 }
120
121 js_function_impl JSObjectDeclaration::Options::getFunctionImpl() const
122 {
123     Assert(m_options && "Pointer to options is null");
124     return m_options->function;
125 }
126
127 void JSObjectDeclaration::Options::invokeCallback(JsContext ctx,
128                                                   ObjectInstance iframe,
129                                                   ObjectInstance object) const
130 {
131     LogDebug("JS Object create, notice.");
132     Assert(m_options && m_options->cb && "Empty callback pointer");
133     m_options->cb(ctx, iframe, object);
134 }
135
136 JSObjectDeclaration::Options::PrivateData
137     JSObjectDeclaration::Options::getPrivateData() const
138 {
139     Assert(m_options && m_options->private_data && "empty private data");
140     return m_options->private_data;
141 }