Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / 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     if (!m_options ||
48         m_options->getIframeObject() == Options::IFrameObject::None)
49     {
50         return false;
51     }
52
53     return true;
54 }
55
56 JSObjectDeclaration::Options::ClassType
57 JSObjectDeclaration::Options::getType() const
58 {
59     Assert(m_options && "Pointer to options is NULL");
60
61     switch (m_options->type) {
62     case JS_CLASS: return ClassType::Class;
63     case JS_FUNCTION: return ClassType::Function;
64     case JS_INTERFACE: return ClassType::Interface;
65     default: Assert(0 && "Wrong value of type");
66     }
67 }
68
69 JSObjectDeclaration::Options::IFrameObject
70 JSObjectDeclaration::Options::getIframeObject() const
71 {
72     Assert(m_options && "Options object is NULL");
73
74     switch (m_options->iframe_option) {
75     case NONE: return IFrameObject::None;
76     case REFERENCE: return IFrameObject::Reference; // deprecated
77     case CREATE_INSTANCE: return IFrameObject::CreateInstance;
78     default:
79         Assert(0 && "Wrong value of behaviour type");
80     }
81 }
82
83 JSObjectDeclaration::Options::IFrameNotice
84 JSObjectDeclaration::Options::getIframeNotice() const
85 {
86     Assert(m_options && "Pointer to options is null");
87
88     switch (m_options->iframe_notice) {
89     case NONE_NOTICE: return IFrameNotice::None;
90     case ALWAYS_NOTICE: return IFrameNotice::AlwaysNotice;
91     default:
92         Assert(0 && "Wrong value of notice option");
93     }
94 }
95
96 js_function_impl JSObjectDeclaration::Options::getFunctionImpl() const
97 {
98     Assert(m_options && "Pointer to options is null");
99     return m_options->function;
100 }
101
102 void JSObjectDeclaration::Options::invokeCallback(JsContext ctx,
103                                                   ObjectInstance iframe,
104                                                   ObjectInstance object) const
105 {
106     LogDebug("JS Object create, notice.");
107     Assert(m_options && m_options->cb && "Empty callback pointer");
108     m_options->cb(ctx, iframe, object);
109 }
110
111 JSObjectDeclaration::Options::PrivateData
112 JSObjectDeclaration::Options::getPrivateData() const
113 {
114     Assert(m_options && m_options->private_data && "empty private data");
115     return m_options->private_data;
116 }