2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file js_object_declaration.cpp
18 * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
23 #include <dpl/log/log.h>
24 #include <dpl/assert.h>
25 #include "JSObjectDeclaration.h"
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)
34 if (NULL != classD->js_class_template_getter_fun) {
35 m_classTemplate = classD->js_class_template_getter_fun();
37 if (classD->class_options) {
38 LogDebug("class options is not a null");
39 m_options = OptionsPtr(new Options(classD->class_options));
43 JSObjectDeclaration::~JSObjectDeclaration()
46 bool JSObjectDeclaration::checkIframesSupported() const
48 LogDebug("Check iframe supported");
50 m_options->getIframeObject() == Options::IFrameObject::None)
52 LogDebug("Iframe NOT supported for object: " << getName());
56 LogDebug("Iframe supported for object: " << getName());
61 JSObjectDeclaration::Options::ClassType
62 JSObjectDeclaration::Options::getType() const
64 LogDebug("Get type field from declaration's option");
65 Assert(m_options && "Pointer to options is NULL");
67 switch (m_options->type) {
68 case JS_CLASS: return ClassType::Class;
69 case JS_FUNCTION: return ClassType::Function;
70 case JS_INTERFACE: return ClassType::Interface;
71 default: Assert(0 && "Wrong value of type");
75 JSObjectDeclaration::Options::IFrameObject
76 JSObjectDeclaration::Options::getIframeObject() const
78 LogDebug("Get Frame Option");
79 Assert(m_options && "Options object is NULL");
81 switch (m_options->iframe_option) {
82 case NONE: return IFrameObject::None;
83 case REFERENCE: return IFrameObject::Reference;
84 case CREATE_INSTANCE: return IFrameObject::CreateInstance;
86 Assert(0 && "Wrong value of behaviour type");
90 JSObjectDeclaration::Options::IFrameNotice
91 JSObjectDeclaration::Options::getIframeNotice() const
93 LogDebug("Get Frame Option");
94 Assert(m_options && "Pointer to options is null");
96 switch (m_options->iframe_notice) {
97 case NONE_NOTICE: return IFrameNotice::None;
98 case ALWAYS_NOTICE: return IFrameNotice::AlwaysNotice;
100 Assert(0 && "Wrong value of notice option");
104 JSObjectDeclaration::Options::IFrameOverlay
105 JSObjectDeclaration::Options::getIframeOverlay() const
107 LogDebug("Get Frame Option");
108 Assert(m_options && "Pointer to options is null");
110 switch (m_options->iframe_overlay) {
111 case IGNORED: return IFrameOverlay::Ignored;
112 case USE_OVERLAYED: return IFrameOverlay::UseOverlayed;
113 case OVERLAYED_BEFORE_ORIGINAL:
114 return IFrameOverlay::OverlayedBeforeOriginal;
116 Assert(0 && "Wrong value of overlay option");
120 js_function_impl JSObjectDeclaration::Options::getFunctionImpl() const
122 Assert(m_options && "Pointer to options is null");
123 return m_options->function;
126 void JSObjectDeclaration::Options::invokeCallback(JsContext ctx,
127 ObjectInstance iframe,
128 ObjectInstance object) const
130 LogDebug("JS Object create, notice.");
131 Assert(m_options && m_options->cb && "Empty callback pointer");
132 m_options->cb(ctx, iframe, object);
135 JSObjectDeclaration::Options::PrivateData
136 JSObjectDeclaration::Options::getPrivateData() const
138 Assert(m_options && m_options->private_data && "empty private data");
139 return m_options->private_data;