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"
32 const StateChange StateChange::NoChange = StateChange();
34 StateChange::StateChange()
38 StateChange::StateChange(RunnableWidgetObjectStatePtr sptr)
43 void StateChange::commit()
47 m_sptr->getObject().setNewState(m_sptr);
51 RunnableWidgetObjectState::RunnableWidgetObjectState(RunnableWidgetObject & object)
56 RunnableWidgetObjectState::~RunnableWidgetObjectState()
60 RunnableWidgetObject & RunnableWidgetObjectState::getObject() const
65 StateChange RunnableWidgetObjectState::allowCheckBeforeLaunch()
67 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
68 "CheckBeforeLaunch cannot be called in current state" << toString());
71 StateChange RunnableWidgetObjectState::allowPrepareView()
73 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
74 "PrepareView cannot be called in current state" << toString());
77 StateChange RunnableWidgetObjectState::allowShow()
79 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
80 "Show cannot be called in current state" << toString());
83 StateChange RunnableWidgetObjectState::allowHide()
85 return StateChange(RunnableWidgetObjectStatePtr(new HiddenState(m_object)));
88 StateChange RunnableWidgetObjectState::allowSuspend()
90 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
91 "Hide cannot be called in current state" << toString());
94 StateChange RunnableWidgetObjectState::allowResume()
96 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
97 "Resume cannot be called in current state" << toString());
100 StateChange RunnableWidgetObjectState::allowReset()
102 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
103 "Cannot reset in curretn state");
106 StateChange RunnableWidgetObjectState::allowGetCurrentWebview()
108 return StateChange::NoChange;
111 StateChange RunnableWidgetObjectState::allowSetUserDelegates()
113 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
114 "SetUserCallbacks cannot be called in current state");
117 StateChange RunnableWidgetObjectState::allowBackward()
119 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
120 "Backward cannot be called in current state ");
123 StateChange RunnableWidgetObjectState::allowForward()
125 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
126 "Foreward cannot be called in current state ");
129 StateChange RunnableWidgetObjectState::allowReload()
131 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
132 "Reload cannot be called in current state ");
135 InitialState::InitialState(RunnableWidgetObject & object) : RunnableWidgetObjectState(object)
139 std::string InitialState::toString() const
144 StateChange InitialState::allowPrepareView()
146 return StateChange(RunnableWidgetObjectStatePtr(new PreparedState(m_object)));
149 StateChange InitialState::allowHide()
151 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
152 "Cannot hide before RunnableWidgetObject initialization");
155 StateChange InitialState::allowGetCurrentWebview()
157 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
158 "Cannot call GetCurrentWebview before RunnableWidgetObject initialization");
161 PreparedState::PreparedState(RunnableWidgetObject & object) : RunnableWidgetObjectState(object)
165 StateChange PreparedState::allowCheckBeforeLaunch()
167 return StateChange(RunnableWidgetObjectStatePtr(new SecurityCheckedState(m_object)));
170 std::string PreparedState::toString() const
175 SecurityCheckedState::SecurityCheckedState(RunnableWidgetObject & object) : RunnableWidgetObjectState(object)
179 std::string SecurityCheckedState::toString() const
181 return "SECURITY_CHECKED";
184 StateChange SecurityCheckedState::allowShow()
186 return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
189 StateChange SecurityCheckedState::allowSetUserDelegates()
191 return StateChange::NoChange;
194 ShowedState::ShowedState(RunnableWidgetObject & object) : RunnableWidgetObjectState(object)
198 std::string ShowedState::toString() const
203 StateChange ShowedState::allowSuspend()
205 return StateChange(RunnableWidgetObjectStatePtr(new SuspendedState(m_object)));
208 StateChange ShowedState::allowBackward()
210 return StateChange::NoChange;
213 StateChange ShowedState::allowForward()
215 return StateChange::NoChange;
218 StateChange ShowedState::allowReload()
220 return StateChange::NoChange;
223 StateChange ShowedState::allowReset()
225 return StateChange::NoChange;
228 SuspendedState::SuspendedState(RunnableWidgetObject & object) : RunnableWidgetObjectState(object)
232 std::string SuspendedState::toString() const
237 StateChange SuspendedState::allowResume()
239 return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
242 StateChange SuspendedState::allowReset()
244 return StateChange(RunnableWidgetObjectStatePtr(new ShowedState(m_object)));
247 HiddenState::HiddenState(RunnableWidgetObject & object) : RunnableWidgetObjectState(object)
251 std::string HiddenState::toString() const
256 StateChange HiddenState::allowHide()
258 ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
259 "Hide cannot be called in current state" << toString());