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 runnable_widget_object.cpp
18 * @author Przemyslaw Ciezkowski (p.ciezkowski@samsung.com)
20 * @brief File contains defitinions of RunnableWidgetObject implementation.
23 #include <runnable_widget_object.h>
24 #include <privilege-control.h>
25 #include <dpl/exception.h>
26 #include <dpl/wrt-dao-ro/global_config.h>
27 #include <dpl/utils/wrt_global_settings.h>
28 #include <appcore-common.h>
29 #include <profiling_util.h>
31 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
32 #include <runnable_widget_object_state.h>
34 namespace { //Anonymous
35 const unsigned int UID_ROOT = 0;
36 const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
37 const char* const MESSAGE_NAME_SHUTDOWN = "ToInjectedBundle::SHUTDOWN";
38 } // namespace anonymous
41 RunnableWidgetObject::RunnableWidgetObject(WidgetModelPtr &model) :
43 m_view(ViewModule::createView()),
44 m_contextManagerFactoryMethod(ViewModule::makeContextManagerFactoryMethod())
46 //set initial state of runnable object
47 m_guardstate = std::shared_ptr<State::RunnableWidgetObjectState>(
48 new State::InitialState(*this));
49 // If current uid is 'root', change privilege to apps
50 if (UID_ROOT == getuid()) {
51 // Set privilege by tizen id
52 // this code prevent that widget launch with "root" permission,
53 // when developers launch by command in the shell
55 perm_app_set_privilege(
56 DPL::ToUTF8String(m_widgetModel->TizenId).c_str(),
57 m_widgetModel->Type.Get().getApptypeToString().c_str(),
58 DPL::ToUTF8String(m_widgetModel->InstallPath.Get()).c_str()
63 bool RunnableWidgetObject::CheckBeforeLaunch()
65 State::StateChange change = m_guardstate->allowCheckBeforeLaunch();
66 Assert(m_widgetModel);
68 #ifdef WRT_SMACK_ENABLED
69 // TODO - this should be in the very first line of the process's main()
70 // for security reasons; but for now it is easier to place here because
71 // here the pkg name is already known; we don't struggle to move it
72 // near the start of main() because we don't know yet if this will
73 // stay in this process at all: it may be moved to AUL altogether
74 set_process_config(DPL::ToUTF8String(widgetModel->TizenId).c_str());
81 bool RunnableWidgetObject::PrepareView(const std::string &startUrl,
82 Evas_Object *window, Ewk_Context* ewkContext)
84 State::StateChange change = m_guardstate->allowPrepareView();
89 std::string appId = DPL::ToUTF8String(m_widgetModel->TizenId);
91 if(!m_ewkContextManager) {
92 m_ewkContextManager = m_contextManagerFactoryMethod(appId, ewkContext, m_view);
95 ewkContext != m_ewkContextManager->getEwkContext())
97 m_ewkContextManager = m_contextManagerFactoryMethod(appId, ewkContext, m_view);
100 } Catch (DPL::Exception) {
101 LogError("Internal Error during create or initialize Ewk Context");
105 ADD_PROFILING_POINT("view_logic_init", "start");
106 Ewk_Context* context = m_ewkContextManager->getEwkContext();
109 ewk_context_message_post_to_injected_bundle(
111 MESSAGE_NAME_INITIALIZE,
112 DPL::ToUTF8String(m_widgetModel->TizenId).c_str());
115 if(!m_view->createWebView(context, window)) {
118 m_view->prepareView(m_widgetModel.get(), startUrl);
119 ADD_PROFILING_POINT("view_logic_init", "stop");
125 void RunnableWidgetObject::Show()
127 State::StateChange change = m_guardstate->allowShow();
129 m_view->showWidget();
134 void RunnableWidgetObject::Hide()
136 State::StateChange change = m_guardstate->allowHide();
138 m_view->hideWidget();
143 void RunnableWidgetObject::Suspend()
145 LogDebug("Suspending widget");
146 State::StateChange change = m_guardstate->allowSuspend();
147 m_view->suspendWidget();
152 void RunnableWidgetObject::Resume()
154 LogDebug("Resuming widget");
155 State::StateChange change = m_guardstate->allowResume();
156 m_view->resumeWidget();
161 void RunnableWidgetObject::Reset()
163 LogDebug("Reseting widget");
164 State::StateChange change = m_guardstate->allowReset();
165 m_view->resetWidget();
170 void RunnableWidgetObject::ReloadStartPage()
172 m_view->reloadStartPage();
175 Evas_Object* RunnableWidgetObject::GetCurrentWebview()
177 State::StateChange change = m_guardstate->allowGetCurrentWebview();
179 Evas_Object* cww = m_view->getCurrentWebview();
185 void RunnableWidgetObject::SetUserDelegates(const UserDelegatesPtr& cbs)
187 State::StateChange change = m_guardstate->allowSetUserDelegates();
188 m_view->setUserCallbacks(cbs);
192 void RunnableWidgetObject::Backward()
194 State::StateChange change = m_guardstate->allowBackward();
200 void RunnableWidgetObject::FireJavascriptEvent(int event, void* data)
202 State::StateChange change = m_guardstate->allowFireJavascriptEvent();
203 m_view->fireJavascriptEvent(event, data);
208 void RunnableWidgetObject::setViewModule(ViewModule::IViewModulePtr ptr)
210 LogDebug("Setting ViewModule");
214 void RunnableWidgetObject::setContextManagerFactoryMethod(
215 ViewModule::ContextManagerFactoryMethod method)
217 LogDebug("Setting ContextManagerFactoryMethod");
218 m_contextManagerFactoryMethod = method;
221 void RunnableWidgetObject::setNewState(
222 std::shared_ptr<State::RunnableWidgetObjectState> sptr)
224 LogDebug("RunnableWidgetObject changes state to: " << sptr->toString());
228 RunnableWidgetObject::~RunnableWidgetObject()
231 if(m_ewkContextManager)
233 ewk_context_message_post_to_injected_bundle(
234 m_ewkContextManager->getEwkContext(),
235 MESSAGE_NAME_SHUTDOWN,
236 DPL::ToUTF8String(m_widgetModel->TizenId).c_str());
240 LogError("ewk context manager is null");
243 } /* namespace WRT */