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