Merge "fix: use EINA_* booleans instread of TRUE/FALSE" into tizen
[platform/framework/web/wrt.git] / src / api_new / runnable_widget_object_state.cpp
1 /*
2  * Copyright (c) 2012 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    core_module.cpp
18  * @author  Tomasz Iwanek (t.iwanek@samsung.com)
19  * @version 1.0
20  * @brief   State classes for runnable object
21  */
22
23 #include "runnable_widget_object_state.h"
24
25 #include <dpl/log/log.h>
26
27 #include "runnable_widget_object.h"
28
29 namespace WRT {
30 namespace State {
31 const StateChange StateChange::NoChange = StateChange();
32
33 StateChange::StateChange()
34 {}
35
36 StateChange::StateChange(RunnableWidgetObjectStatePtr sptr) :
37     m_sptr(sptr)
38 {}
39
40 void StateChange::commit()
41 {
42     if (m_sptr) {
43         m_sptr->getObject().setNewState(m_sptr);
44     }
45 }
46
47 RunnableWidgetObjectState::RunnableWidgetObjectState(
48     RunnableWidgetObject & object) :
49     m_object(object)
50 {}
51
52 RunnableWidgetObjectState::~RunnableWidgetObjectState()
53 {}
54
55 RunnableWidgetObject & RunnableWidgetObjectState::getObject() const
56 {
57     return m_object;
58 }
59
60 StateChange RunnableWidgetObjectState::allowCheckBeforeLaunch()
61 {
62     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
63              "CheckBeforeLaunch cannot be called in current state" << toString());
64 }
65
66 StateChange RunnableWidgetObjectState::allowPrepareView()
67 {
68     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
69              "PrepareView cannot be called in current state" << toString());
70 }
71
72 StateChange RunnableWidgetObjectState::allowShow()
73 {
74     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
75              "Show cannot be called in current state" << toString());
76 }
77
78 StateChange RunnableWidgetObjectState::allowHide()
79 {
80     return StateChange(RunnableWidgetObjectStatePtr(new HiddenState(m_object)));
81 }
82
83 StateChange RunnableWidgetObjectState::allowSuspend()
84 {
85     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
86              "Hide cannot be called in current state" << toString());
87 }
88
89 StateChange RunnableWidgetObjectState::allowResume()
90 {
91     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
92              "Resume cannot be called in current state" << toString());
93 }
94
95 StateChange RunnableWidgetObjectState::allowReset()
96 {
97     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
98              "Cannot reset in curretn state");
99 }
100
101 StateChange RunnableWidgetObjectState::allowGetCurrentWebview()
102 {
103     return StateChange::NoChange;
104 }
105
106 StateChange RunnableWidgetObjectState::allowSetUserDelegates()
107 {
108     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
109              "SetUserCallbacks cannot be called in current state");
110 }
111
112 StateChange RunnableWidgetObjectState::allowBackward()
113 {
114     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
115              "Backward cannot be called in current state ");
116 }
117
118 StateChange RunnableWidgetObjectState::allowForward()
119 {
120     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
121              "Foreward cannot be called in current state ");
122 }
123
124 StateChange RunnableWidgetObjectState::allowReload()
125 {
126     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
127              "Reload cannot be called in current state ");
128 }
129
130 StateChange RunnableWidgetObjectState::allowFireJavascriptEvent()
131 {
132     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
133              "FireJavascriptEvent cannot be called in current state ");
134 }
135
136 InitialState::InitialState(RunnableWidgetObject & object) :
137     RunnableWidgetObjectState(object)
138 {}
139
140 std::string InitialState::toString() const
141 {
142     return "INITIAL";
143 }
144
145 StateChange InitialState::allowPrepareView()
146 {
147     return StateChange(RunnableWidgetObjectStatePtr(new PreparedState(m_object)));
148 }
149
150 StateChange InitialState::allowHide()
151 {
152     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
153              "Cannot hide before RunnableWidgetObject initialization");
154 }
155
156 StateChange InitialState::allowGetCurrentWebview()
157 {
158     ThrowMsg(
159         IRunnableWidgetObject::MethodInvocationForbidden,
160         "Cannot call GetCurrentWebview before RunnableWidgetObject initialization");
161 }
162
163 PreparedState::PreparedState(RunnableWidgetObject & object) :
164     RunnableWidgetObjectState(object)
165 {}
166
167 StateChange PreparedState::allowCheckBeforeLaunch()
168 {
169     return StateChange(RunnableWidgetObjectStatePtr(new SecurityCheckedState(
170                                                         m_object)));
171 }
172
173 std::string PreparedState::toString() const
174 {
175     return "PREPARED";
176 }
177
178 SecurityCheckedState::SecurityCheckedState(RunnableWidgetObject & object) :
179     RunnableWidgetObjectState(object)
180 {}
181
182 std::string SecurityCheckedState::toString() const
183 {
184     return "SECURITY_CHECKED";
185 }
186
187 StateChange SecurityCheckedState::allowShow()
188 {
189     return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
190 }
191
192 StateChange SecurityCheckedState::allowSetUserDelegates()
193 {
194     return StateChange::NoChange;
195 }
196
197 ShowedState::ShowedState(RunnableWidgetObject & object) :
198     RunnableWidgetObjectState(object)
199 {}
200
201 std::string ShowedState::toString() const
202 {
203     return "SHOWED";
204 }
205
206 StateChange ShowedState::allowSuspend()
207 {
208     return StateChange(RunnableWidgetObjectStatePtr(new SuspendedState(m_object)));
209 }
210
211 StateChange ShowedState::allowBackward()
212 {
213     return StateChange::NoChange;
214 }
215
216 StateChange ShowedState::allowForward()
217 {
218     return StateChange::NoChange;
219 }
220
221 StateChange ShowedState::allowReload()
222 {
223     return StateChange::NoChange;
224 }
225
226 StateChange ShowedState::allowReset()
227 {
228     return StateChange::NoChange;
229 }
230
231 StateChange ShowedState::allowFireJavascriptEvent()
232 {
233     return StateChange::NoChange;
234 }
235
236 SuspendedState::SuspendedState(RunnableWidgetObject & object) :
237     RunnableWidgetObjectState(object)
238 {}
239
240 std::string SuspendedState::toString() const
241 {
242     return "SUSPENDED";
243 }
244
245 StateChange SuspendedState::allowResume()
246 {
247     return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
248 }
249
250 StateChange SuspendedState::allowReset()
251 {
252     return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
253 }
254
255 HiddenState::HiddenState(RunnableWidgetObject & object) :
256     RunnableWidgetObjectState(object)
257 {}
258
259 std::string HiddenState::toString() const
260 {
261     return "HIDEN";
262 }
263
264 StateChange HiddenState::allowHide()
265 {
266     ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
267              "Hide cannot be called in current state" << toString());
268 }
269 }
270 }