2 * Copyright (c) 2012 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 core_module.cpp
18 * @author Tomasz Iwanek (t.iwanek@samsung.com)
20 * @brief State classes for runnable object
23 #include "runnable_widget_object_state.h"
25 #include <dpl/log/log.h>
27 #include "runnable_widget_object.h"
31 const StateChange StateChange::NoChange = StateChange();
33 StateChange::StateChange()
36 StateChange::StateChange(RunnableWidgetObjectStatePtr sptr) :
40 void StateChange::commit()
43 m_sptr->getObject().setNewState(m_sptr);
47 RunnableWidgetObjectState::RunnableWidgetObjectState(
48 RunnableWidgetObject & object) :
52 RunnableWidgetObjectState::~RunnableWidgetObjectState()
55 RunnableWidgetObject & RunnableWidgetObjectState::getObject() const
60 StateChange RunnableWidgetObjectState::allowCheckBeforeLaunch()
62 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
63 "CheckBeforeLaunch cannot be called in current state" << toString());
66 StateChange RunnableWidgetObjectState::allowPrepareView()
68 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
69 "PrepareView cannot be called in current state" << toString());
72 StateChange RunnableWidgetObjectState::allowShow()
74 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
75 "Show cannot be called in current state" << toString());
78 StateChange RunnableWidgetObjectState::allowHide()
80 return StateChange(RunnableWidgetObjectStatePtr(new HiddenState(m_object)));
83 StateChange RunnableWidgetObjectState::allowSuspend()
85 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
86 "Hide cannot be called in current state" << toString());
89 StateChange RunnableWidgetObjectState::allowResume()
91 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
92 "Resume cannot be called in current state" << toString());
95 StateChange RunnableWidgetObjectState::allowReset()
97 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
98 "Cannot reset in curretn state");
101 StateChange RunnableWidgetObjectState::allowGetCurrentWebview()
103 return StateChange::NoChange;
106 StateChange RunnableWidgetObjectState::allowSetUserDelegates()
108 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
109 "SetUserCallbacks cannot be called in current state");
112 StateChange RunnableWidgetObjectState::allowBackward()
114 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
115 "Backward cannot be called in current state ");
118 StateChange RunnableWidgetObjectState::allowForward()
120 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
121 "Foreward cannot be called in current state ");
124 StateChange RunnableWidgetObjectState::allowReload()
126 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
127 "Reload cannot be called in current state ");
130 StateChange RunnableWidgetObjectState::allowFireJavascriptEvent()
132 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
133 "FireJavascriptEvent cannot be called in current state ");
136 InitialState::InitialState(RunnableWidgetObject & object) :
137 RunnableWidgetObjectState(object)
140 std::string InitialState::toString() const
145 StateChange InitialState::allowPrepareView()
147 return StateChange(RunnableWidgetObjectStatePtr(new PreparedState(m_object)));
150 StateChange InitialState::allowHide()
152 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
153 "Cannot hide before RunnableWidgetObject initialization");
156 StateChange InitialState::allowGetCurrentWebview()
159 IRunnableWidgetObject::MethodInvocationForbidden,
160 "Cannot call GetCurrentWebview before RunnableWidgetObject initialization");
163 PreparedState::PreparedState(RunnableWidgetObject & object) :
164 RunnableWidgetObjectState(object)
167 StateChange PreparedState::allowCheckBeforeLaunch()
169 return StateChange(RunnableWidgetObjectStatePtr(new SecurityCheckedState(
173 std::string PreparedState::toString() const
178 SecurityCheckedState::SecurityCheckedState(RunnableWidgetObject & object) :
179 RunnableWidgetObjectState(object)
182 std::string SecurityCheckedState::toString() const
184 return "SECURITY_CHECKED";
187 StateChange SecurityCheckedState::allowShow()
189 return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
192 StateChange SecurityCheckedState::allowSetUserDelegates()
194 return StateChange::NoChange;
197 ShowedState::ShowedState(RunnableWidgetObject & object) :
198 RunnableWidgetObjectState(object)
201 std::string ShowedState::toString() const
206 StateChange ShowedState::allowSuspend()
208 return StateChange(RunnableWidgetObjectStatePtr(new SuspendedState(m_object)));
211 StateChange ShowedState::allowBackward()
213 return StateChange::NoChange;
216 StateChange ShowedState::allowForward()
218 return StateChange::NoChange;
221 StateChange ShowedState::allowReload()
223 return StateChange::NoChange;
226 StateChange ShowedState::allowReset()
228 return StateChange::NoChange;
231 StateChange ShowedState::allowFireJavascriptEvent()
233 return StateChange::NoChange;
236 SuspendedState::SuspendedState(RunnableWidgetObject & object) :
237 RunnableWidgetObjectState(object)
240 std::string SuspendedState::toString() const
245 StateChange SuspendedState::allowResume()
247 return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
250 StateChange SuspendedState::allowReset()
252 return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
255 HiddenState::HiddenState(RunnableWidgetObject & object) :
256 RunnableWidgetObjectState(object)
259 std::string HiddenState::toString() const
264 StateChange HiddenState::allowHide()
266 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
267 "Hide cannot be called in current state" << toString());