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 core_module.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>
33 #include <popup-runner/PopupInvoker.h>
34 #include "ewk_context_manager.h"
36 namespace { //Anonymous
37 const unsigned int UID_ROOT = 0;
38 const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
39 const char* const MESSAGE_NAME_SHUTDOWN = "ToInjectedBundle::SHUTDOWN";
40 } // namespace anonymous
43 RunnableWidgetObject::RunnableWidgetObject(WidgetModelPtr &model) :
45 m_view(ViewModule::createView()),
46 m_contextManagerFactoryMethod(makeContextManagerFactoryMethod<EwkContextManager>())
48 //set initial state of runnable object
49 m_guardstate = std::shared_ptr<State::RunnableWidgetObjectState>(
50 new State::InitialState(*this));
51 // If current uid is 'root', change privilege to apps
52 if (UID_ROOT == getuid()) {
53 // Set privilege by tizen id
54 // this code prevent that widget launch with "root" permission,
55 // when developers launch by command in the shell
58 DPL::ToUTF8String(m_widgetModel->TizenId).c_str(),
59 m_widgetModel->Type.Get().getApptypeToString().c_str(),
60 DPL::ToUTF8String(m_widgetModel->InstallPath.Get()).c_str()
65 bool RunnableWidgetObject::CheckBeforeLaunch()
67 State::StateChange change = m_guardstate->allowCheckBeforeLaunch();
68 Assert(m_widgetModel);
70 #ifdef WRT_SMACK_ENABLED
71 // TODO - this should be in the very first line of the process's main()
72 // for security reasons; but for now it is easier to place here because
73 // here the pkg name is already known; we don't struggle to move it
74 // near the start of main() because we don't know yet if this will
75 // stay in this process at all: it may be moved to AUL altogether
76 set_process_config(DPL::ToUTF8String(widgetModel->TizenId).c_str());
83 bool RunnableWidgetObject::PrepareView(const std::string &startUrl,
84 Evas_Object *window, Ewk_Context* ewkContext)
86 State::StateChange change = m_guardstate->allowPrepareView();
91 std::string appId = DPL::ToUTF8String(m_widgetModel->TizenId);
93 if(!m_ewkContextManager) {
94 m_ewkContextManager = m_contextManagerFactoryMethod(appId, ewkContext, m_view);
97 ewkContext != m_ewkContextManager->getEwkContext())
99 m_ewkContextManager = m_contextManagerFactoryMethod(appId, ewkContext, m_view);
102 } Catch (DPL::Exception) {
103 LogError("Internal Error during create or initialize Ewk Context");
107 ADD_PROFILING_POINT("view_logic_init", "start");
108 Ewk_Context* context = m_ewkContextManager->getEwkContext();
111 ewk_context_message_post_to_injected_bundle(
113 MESSAGE_NAME_INITIALIZE,
114 DPL::ToUTF8String(m_widgetModel->TizenId).c_str());
117 if(!m_view->createWebView(context, window)) {
120 m_view->prepareView(m_widgetModel.get(), startUrl);
121 ADD_PROFILING_POINT("view_logic_init", "stop");
127 void RunnableWidgetObject::Show()
129 State::StateChange change = m_guardstate->allowShow();
131 m_view->showWidget();
136 void RunnableWidgetObject::Hide()
138 State::StateChange change = m_guardstate->allowHide();
140 m_view->hideWidget();
145 void RunnableWidgetObject::Suspend()
147 LogDebug("Suspending widget");
148 State::StateChange change = m_guardstate->allowSuspend();
149 m_view->suspendWidget();
154 void RunnableWidgetObject::Resume()
156 LogDebug("Resuming widget");
157 State::StateChange change = m_guardstate->allowResume();
158 m_view->resumeWidget();
163 void RunnableWidgetObject::Reset()
165 LogDebug("Reseting widget");
166 State::StateChange change = m_guardstate->allowReset();
167 m_view->resetWidget();
172 void RunnableWidgetObject::ReloadStartPage()
174 m_view->reloadStartPage();
177 Evas_Object* RunnableWidgetObject::GetCurrentWebview()
179 State::StateChange change = m_guardstate->allowGetCurrentWebview();
181 Evas_Object* cww = m_view->getCurrentWebview();
187 void RunnableWidgetObject::SetUserDelegates(const UserDelegatesPtr& cbs)
189 State::StateChange change = m_guardstate->allowSetUserDelegates();
190 m_view->setUserCallbacks(cbs);
194 void RunnableWidgetObject::Backward()
196 State::StateChange change = m_guardstate->allowBackward();
202 void RunnableWidgetObject::FireJavascriptEvent(int event, void* data)
204 State::StateChange change = m_guardstate->allowFireJavascriptEvent();
205 m_view->fireJavascriptEvent(event, data);
210 void RunnableWidgetObject::setViewModule(ViewModule::IViewModulePtr ptr)
212 LogDebug("Setting ViewModule");
216 void RunnableWidgetObject::setContextManagerFactoryMethod(ContextManagerFactoryMethod method)
218 LogDebug("Setting ContextManagerFactoryMethod");
219 m_contextManagerFactoryMethod = method;
222 void RunnableWidgetObject::setNewState(
223 std::shared_ptr<State::RunnableWidgetObjectState> sptr)
225 LogInfo("RunnableWidgetObject changes state to: " << sptr->toString());
229 RunnableWidgetObject::~RunnableWidgetObject()
232 if(m_ewkContextManager)
234 ewk_context_message_post_to_injected_bundle(
235 m_ewkContextManager->getEwkContext(),
236 MESSAGE_NAME_SHUTDOWN,
237 DPL::ToUTF8String(m_widgetModel->TizenId).c_str());
241 LogError("ewk context manager is null");
244 } /* namespace WRT */