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/wrt-dao-ro/global_config.h>
26 #include <dpl/utils/wrt_global_settings.h>
27 #include <appcore-common.h>
28 #include <profiling_util.h>
30 #include "webkit/bundles/plugin_module_support.h"
31 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
32 #include <runnable_widget_object_state.h>
33 #include <wrt_ocsp_api.h>
34 #include <popup-runner/PopupInvoker.h>
36 namespace { //Anonymous
37 const std::string ACCESS_DENIED = _("IDS_BR_POP_ACCESS_DENIED");
38 const std::string ALREADY_RUNNING = _("IDS_BR_POP_ALREADY_RUNNING");
39 const std::string INVALID_LOCALE = _("IDS_IM_POP_INVALID_WIDGET_LOCALE");
40 const std::string STILL_AUTHORIZING = _("IDS_IM_POP_AUTHORIZING_ING_ATNT");
41 const unsigned int UID_ROOT = 0;
43 } // namespace anonymous
47 RunnableWidgetObject::RunnableWidgetObject(WidgetModelPtr &model, Ewk_Context* context) :
49 m_view(ViewModule::createView()),
52 //set initial state of runnable object
53 m_guardstate = std::shared_ptr<State::RunnableWidgetObjectState>(new State::InitialState(*this));
54 // If current uid is 'root', change privilege to apps
55 if (UID_ROOT == getuid()) {
56 // Set privilege by tizen id
57 // this code prevent that widget launch with "root" permission,
58 // when developers launch by command in the shell
59 set_privilege(DPL::ToUTF8String(m_widgetModel->TizenId).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());
77 // Inform view controller about new widget model displaying
78 ADD_PROFILING_POINT("OCSPCheck", "start");
80 wrt_ocsp_widget_verification_status_t response;
81 if (m_widgetModel->Type.Get().appType == WrtDB::APP_TYPE_WAC20) {
83 wrt_ocsp_initialize();
84 wrt_ocsp_verify_widget(WrtDB::WidgetDAOReadOnly::getHandle(m_widgetModel->TizenId), &response);
88 response = WRT_OCSP_WIDGET_VERIFICATION_STATUS_GOOD;
90 ADD_PROFILING_POINT("OCSPCheck", "stop");
92 LogDebug("WRT OCSP response " << static_cast<int>(response));
93 if (response == WRT_OCSP_WIDGET_VERIFICATION_STATUS_GOOD) {
97 if (!GlobalSettings::PopupsTestModeEnabled()) {
98 Wrt::Popup::PopupInvoker().showInfo(
99 _("IDS_IM_POP_WIDGET_REVOKED_TITLE"),
100 _("IDS_IM_POP_WIDGET_REVOKED_ERROR"),
101 _("IDS_IM_BUTTON_OK"));
107 bool RunnableWidgetObject::PrepareView(const std::string &startUrl,
110 State::StateChange change = m_guardstate->allowPrepareView();
113 ADD_PROFILING_POINT("view_logic_init", "start");
114 if(!m_view->createWebView(m_ewkContext, window))
118 m_view->initialize();
119 m_view->prepareView(m_widgetModel.get(), startUrl);
120 ADD_PROFILING_POINT("view_logic_init", "stop");
126 void RunnableWidgetObject::Show()
128 State::StateChange change = m_guardstate->allowShow();
130 m_view->showWidget();
135 void RunnableWidgetObject::Hide()
137 State::StateChange change = m_guardstate->allowHide();
139 m_view->hideWidget();
140 m_view->destroyWebView();
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) {
188 State::StateChange change = m_guardstate->allowSetUserDelegates();
189 m_view->setUserCallbacks(cbs);
193 void RunnableWidgetObject::Backward()
195 State::StateChange change = m_guardstate->allowBackward();
201 void RunnableWidgetObject::FireJavascriptEvent(int event, void* data)
203 State::StateChange change = m_guardstate->allowFireJavascriptEvent();
204 m_view->fireJavascriptEvent(event, data);
209 void RunnableWidgetObject::setNewState(std::shared_ptr<State::RunnableWidgetObjectState> sptr)
211 LogInfo("RunnableWidgetObject changes state to: " << sptr->toString());
215 RunnableWidgetObject::~RunnableWidgetObject()
218 PluginModuleSupport::shutdown(m_ewkContext);
221 } /* namespace WRT */