[Release] wrt-plugins-common_0.3.94
[platform/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         m_classTemplate = classD->js_class_template_getter_fun();
36     }
37     if (classD->class_options) {
38         m_options = OptionsPtr(new Options(classD->class_options));
39     }
40 }
41
42 JSObjectDeclaration::~JSObjectDeclaration()
43 {}
44
45 bool JSObjectDeclaration::checkIframesSupported() const
46 {
47     LogDebug("Check iframe supported");
48     if (!m_options ||
49         m_options->getIframeObject() == Options::IFrameObject::None)
50     {
51         LogDebug("Iframe NOT supported for object: " << getName());
52         return false;
53     }
54
55     LogDebug("Iframe supported for object: " << getName());
56
57     return true;
58 }
59
60 JSObjectDeclaration::Options::ClassType
61 JSObjectDeclaration::Options::getType() const
62 {
63     LogDebug("Get type field from declaration's option");
64     Assert(m_options && "Pointer to options is NULL");
65
66     switch (m_options->type) {
67     case JS_CLASS: return ClassType::Class;
68     case JS_FUNCTION: return ClassType::Function;
69     case JS_INTERFACE: return ClassType::Interface;
70     default: Assert(0 && "Wrong value of type");
71     }
72 }
73
74 JSObjectDeclaration::Options::IFrameObject
75 JSObjectDeclaration::Options::getIframeObject() const
76 {
77     LogDebug("Get Frame Option");
78     Assert(m_options && "Options object is NULL");
79
80     switch (m_options->iframe_option) {
81     case NONE: return IFrameObject::None;
82     case REFERENCE: return IFrameObject::Reference;
83     case CREATE_INSTANCE: return IFrameObject::CreateInstance;
84     default:
85         Assert(0 && "Wrong value of behaviour type");
86     }
87 }
88
89 JSObjectDeclaration::Options::IFrameNotice
90 JSObjectDeclaration::Options::getIframeNotice() const
91 {
92     LogDebug("Get Frame Option");
93     Assert(m_options && "Pointer to options is null");
94
95     switch (m_options->iframe_notice) {
96     case NONE_NOTICE: return IFrameNotice::None;
97     case ALWAYS_NOTICE: return IFrameNotice::AlwaysNotice;
98     default:
99         Assert(0 && "Wrong value of notice option");
100     }
101 }
102
103 JSObjectDeclaration::Options::IFrameOverlay
104 JSObjectDeclaration::Options::getIframeOverlay() const
105 {
106     LogDebug("Get Frame Option");
107     Assert(m_options && "Pointer to options is null");
108
109     switch (m_options->iframe_overlay) {
110     case IGNORED: return IFrameOverlay::Ignored;
111     case USE_OVERLAYED: return IFrameOverlay::UseOverlayed;
112     case OVERLAYED_BEFORE_ORIGINAL:
113         return IFrameOverlay::OverlayedBeforeOriginal;
114     default:
115         Assert(0 && "Wrong value of overlay option");
116     }
117 }
118
119 js_function_impl JSObjectDeclaration::Options::getFunctionImpl() const
120 {
121     Assert(m_options && "Pointer to options is null");
122     return m_options->function;
123 }
124
125 void JSObjectDeclaration::Options::invokeCallback(JsContext ctx,
126                                                   ObjectInstance iframe,
127                                                   ObjectInstance object) const
128 {
129     LogDebug("JS Object create, notice.");
130     Assert(m_options && m_options->cb && "Empty callback pointer");
131     m_options->cb(ctx, iframe, object);
132 }
133
134 JSObjectDeclaration::Options::PrivateData
135 JSObjectDeclaration::Options::getPrivateData() const
136 {
137     Assert(m_options && m_options->private_data && "empty private data");
138     return m_options->private_data;
139 }