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 "global_logic.h"
27 #include <dpl/utils/wrt_global_settings.h>
28 #include <dpl/popup/popup_controller.h>
29 #include <appcore-common.h>
30 #include <profiling_util.h>
32 #include "webkit/bundles/plugin_module_support.h"
33 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
34 #include <runnable_widget_object_state.h>
35 #include <wrt_ocsp_api.h>
37 namespace { //Anonymous
39 const wchar_t* BACKGROUND_ENABLED = L"background_enabled" ;
41 class Popups : DPL::Popup::PopupControllerUser
44 void displayCertificateRevokedPopup()
46 using namespace DPL::Popup;
48 PopupControllerSingleton::Instance().CreatePopup();
49 popup->SetTitle(_("IDS_IM_POP_WIDGET_REVOKED_TITLE"));
50 popup->Append(new PopupObject::Label(
51 _("IDS_IM_POP_WIDGET_REVOKED_ERROR")));
52 popup->Append(new PopupObject::Button(_("IDS_IM_BUTTON_OK"), 0));
53 ListenForAnswer(popup);
55 PopupAnswerCallback cb =
56 MakeAnswerCallback(this, &Popups::dummyCallback);
58 ShowPopupEventShort event(popup, cb);
59 CONTROLLER_POST_EVENT(PopupController, event);
62 void dummyCallback(const DPL::Popup::AnswerCallbackData& /*data*/)
67 Popups popupsDisplayer;
69 const std::string ACCESS_DENIED = _("IDS_BR_POP_ACCESS_DENIED");
70 const std::string ALREADY_RUNNING = _("IDS_BR_POP_ALREADY_RUNNING");
71 const std::string INVALID_LOCALE = _("IDS_IM_POP_INVALID_WIDGET_LOCALE");
72 const std::string STILL_AUTHORIZING = _("IDS_IM_POP_AUTHORIZING_ING_ATNT");
73 const unsigned int UID_ROOT = 0;
75 } // namespace anonymous
80 RunnableWidgetObject::RunnableWidgetObject(WidgetModelPtr &model, Ewk_Context* context) :
82 m_view(ViewModule::createView()),
85 //set initial state of runnable object
86 m_guardstate = std::shared_ptr<State::RunnableWidgetObjectState>(new State::InitialState(*this));
87 // If current uid is 'root', change privilege to apps
88 if (UID_ROOT == getuid()) {
89 // Set privilege by tizen id
90 // this code prevent that widget launch with "root" permission,
91 // when developers launch by command in the shell
92 set_privilege(DPL::ToUTF8String(m_widgetModel->TizenId).c_str());
96 bool RunnableWidgetObject::CheckBeforeLaunch()
98 State::StateChange change = m_guardstate->allowCheckBeforeLaunch();
99 Assert(m_widgetModel);
101 #ifdef WRT_SMACK_ENABLED
102 // TODO - this should be in the very first line of the process's main()
103 // for security reasons; but for now it is easier to place here because
104 // here the pkg name is already known; we don't struggle to move it
105 // near the start of main() because we don't know yet if this will
106 // stay in this process at all: it may be moved to AUL altogether
107 set_process_config(DPL::ToUTF8String(widgetModel->TizenId).c_str());
110 // Inform view controller about new widget model displaying
111 ADD_PROFILING_POINT("OCSPCheck", "start");
113 wrt_ocsp_widget_verification_status_t response;
114 if (m_widgetModel->Type.Get().appType == WrtDB::APP_TYPE_WAC20) {
116 wrt_ocsp_initialize();
117 wrt_ocsp_verify_widget(m_widgetModel->Handle.Get(), &response);
121 response = WRT_OCSP_WIDGET_VERIFICATION_STATUS_GOOD;
123 ADD_PROFILING_POINT("OCSPCheck", "stop");
125 LogDebug("WRT OCSP response " << static_cast<int>(response));
126 if (response == WRT_OCSP_WIDGET_VERIFICATION_STATUS_GOOD) {
130 if (!GlobalSettings::PopupsTestModeEnabled()) {
131 popupsDisplayer.displayCertificateRevokedPopup();
137 void RunnableWidgetObject::PrepareView(const std::string &startUrl,
140 State::StateChange change = m_guardstate->allowPrepareView();
143 ADD_PROFILING_POINT("view_logic_init", "start");
144 m_view->createWebView(m_ewkContext, window);
145 m_view->initialize();
146 m_view->prepareView(m_widgetModel.get(), startUrl);
147 ADD_PROFILING_POINT("view_logic_init", "stop");
152 void RunnableWidgetObject::Show()
154 State::StateChange change = m_guardstate->allowShow();
156 m_view->showWidget();
161 void RunnableWidgetObject::Hide() {
162 State::StateChange change = m_guardstate->allowHide();
164 m_view->hideWidget();
165 m_view->destroyWebView();
170 void RunnableWidgetObject::Suspend() {
171 LogDebug("Suspending widget");
172 State::StateChange change = m_guardstate->allowSuspend();
173 Assert(m_widgetModel);
175 bool suspendWebkit = true;
177 if( m_widgetModel->SettingList.Get().getBackgroundSupport()
178 == BackgroundSupport_Enable ) {
180 LogDebug("Background enabled, skipping suspend");
181 suspendWebkit = false;
183 #ifndef DEPRECATED_SETTING_STRING
185 WrtDB::WidgetDAOReadOnly dao(m_widgetModel->TizenId);
186 WrtDB::PropertyDAOReadOnly::WidgetPropertyValue bgEnableValue =
187 dao.getPropertyValue(DPL::String(BACKGROUND_ENABLED));
189 if(!bgEnableValue.IsNull() && !bgEnableValue->compare(L"true")) {
191 LogDebug("Background enabled, skipping suspend");
192 suspendWebkit = false;
197 if(suspendWebkit) //if widget has background page suspending wk will be skipped
199 m_view->suspendWidget();
205 void RunnableWidgetObject::Resume()
207 LogDebug("Resuming widget");
208 State::StateChange change = m_guardstate->allowResume();
209 m_view->resumeWidget();
214 void RunnableWidgetObject::Reset()
216 LogDebug("Reseting widget");
217 State::StateChange change = m_guardstate->allowReset();
218 m_view->resetWidget();
223 void RunnableWidgetObject::ReloadStartPage()
225 m_view->reloadStartPage();
228 Evas_Object* RunnableWidgetObject::GetCurrentWebview() {
229 State::StateChange change = m_guardstate->allowGetCurrentWebview();
231 Evas_Object* cww = m_view->getCurrentWebview();
237 void RunnableWidgetObject::SetUserDelegates(const UserDelegatesPtr& cbs) {
238 State::StateChange change = m_guardstate->allowSetUserDelegates();
239 m_view->setUserCallbacks(cbs);
243 void RunnableWidgetObject::Backward() {
244 State::StateChange change = m_guardstate->allowBackward();
250 void RunnableWidgetObject::Reload() {
251 State::StateChange change = m_guardstate->allowReload();
257 void RunnableWidgetObject::Forward() {
258 State::StateChange change = m_guardstate->allowForward();
264 void RunnableWidgetObject::FireJavascriptEvent(int event, void* data)
266 State::StateChange change = m_guardstate->allowFireJavascriptEvent();
267 m_view->fireJavascriptEvent(event, data);
272 void RunnableWidgetObject::setNewState(std::shared_ptr<State::RunnableWidgetObjectState> sptr)
274 LogInfo("RunnableWidgetObject changes state to: " << sptr->toString());
278 RunnableWidgetObject::~RunnableWidgetObject()
281 PluginModuleSupport::shutdown(m_ewkContext);
284 } /* namespace WRT */