2 * Copyright (c) 2013 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 ewk_context_manager.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
20 * @brief Implementation of EwkContextManager class.
21 * This file handles operation regarding Ewk_Context
26 #include <ewk_context.h>
27 #include <dpl/log/log.h>
28 #include <dpl/exception.h>
29 #include <profiling_util.h>
30 #include <i_view_module.h>
31 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
32 #include <dpl/wrt-dao-ro/widget_dao_types.h>
33 #include <dpl/wrt-dao-ro/vconf_config.h>
34 #include <dpl/utils/wrt_global_settings.h>
35 #include "ewk_context_manager.h"
39 static const std::string bundlePath("/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so");
40 static const std::string caCertPath("/opt/usr/share/certs/ca-certificate.crt");
43 const std::string plugins_arch = "plugins/arm";
45 const std::string plugins_arch = "plugins/x86";
48 EwkContextManager::EwkContextManager(
49 const std::string& tizenAppId,
50 Ewk_Context* ewkContext,
51 ViewModule::IViewModulePtr viewModule)
52 : AbstractContextManager(tizenAppId, ewkContext, viewModule),
53 m_initialized(false), m_isInternalContext(false)
56 ThrowMsg(DPL::Exception, "Fail to intialize EwkContextManager");
58 // set ewk context callbacks
62 EwkContextManager::~EwkContextManager()
64 // unset registered ewk context callbacks
69 Ewk_Context * EwkContextManager::getEwkContext() const
74 bool EwkContextManager::initialize()
77 m_ewkContext = ewk_context_new_with_injected_bundle_path(bundlePath.c_str());
83 m_isInternalContext = true;
86 // cache model setting
87 ewk_context_cache_model_set(
89 EWK_CACHE_MODEL_DOCUMENT_BROWSER);
90 ADD_PROFILING_POINT("WebProcess fork", "start");
91 // To fork a Webprocess as soon as possible,
92 // the following ewk_api is called explicitly.
93 ewk_cookie_manager_accept_policy_set(
94 ewk_context_cookie_manager_get(m_ewkContext),
95 EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
96 ADD_PROFILING_POINT("WebProcess fork", "stop");
98 // proxy server setting
99 char *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
100 if (proxy && strlen(proxy) && strcmp(proxy, "0.0.0.0")) {
101 LogInfo("proxy address: " << proxy);
102 ewk_context_proxy_uri_set(m_ewkContext, proxy);
104 LogInfo("proxy address is empty");
105 ewk_context_proxy_uri_set(m_ewkContext, NULL);
112 // temp - this api was moved to wrt-client for performance
113 //ewk_context_certificate_file_set(m_ewkContext, caCertPath.c_str());
115 // set local stroage database path
116 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
117 ewk_context_web_storage_path_set(
119 dao.getPrivateLocalStoragePath().c_str());
121 // memory saving mode
124 WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
125 DPL::FromUTF8String(m_appId)).c_str(), &result);
127 ewk_context_memory_saving_mode_set(
129 static_cast<WrtDB::SettingsType>(result) ==
130 WrtDB::SETTINGS_TYPE_ON ? EINA_TRUE : EINA_FALSE);
132 ewk_context_tizen_extensible_api_set(
134 EWK_EXTENSIBLE_API_MEDIA_STREAM_RECORD,
136 ewk_context_tizen_extensible_api_set(
138 EWK_EXTENSIBLE_API_ROTATE_CAMERA_VIEW,
140 ewk_context_tizen_extensible_api_set(
142 EWK_EXTENSIBLE_API_MEDIA_VOLUME_CONTROL,
145 setAutoFullscreenMode();
146 setBackgroundSupport();
148 if (dao.getSecurityModelVersion() ==
149 WrtDB::WidgetSecurityModelVersion::WIDGET_SECURITY_MODEL_V2)
155 // ewk storage_path set
156 ewk_context_storage_path_reset(m_ewkContext);
158 // npruntime plugins path set
159 std::ostringstream plugins_path;
160 plugins_path << dao.getPath() << plugins_arch;
161 LogInfo("ewk_context_additional_plugin_path_set() : " << plugins_path.str());
163 ewk_context_additional_plugin_path_set(m_ewkContext, plugins_path.str().c_str());
165 m_initialized = true;
170 void EwkContextManager::destroy()
172 // only in the following case, webkit context should be deleted
173 if (m_initialized && m_isInternalContext) {
174 ewk_context_delete(m_ewkContext);
178 void EwkContextManager::setCallbacks()
180 if (!m_initialized) {
184 ewk_context_message_from_injected_bundle_callback_set(
186 messageFromInjectedBundleCallback,
189 ewk_context_did_start_download_callback_set(
191 didStartDownloadCallback,
194 ewk_context_vibration_client_callbacks_set(
196 vibrationClientStartCallback,
197 vibrationClientStopCallback,
201 void EwkContextManager::setAutoFullscreenMode()
203 using namespace WrtDB;
204 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
208 std::list<DPL::String> widgetPrivilege = dao.getWidgetPrivilege();
209 bool fullscreen = false;
211 FOREACH(it, widgetPrivilege) {
212 std::map<std::string, Feature>::const_iterator result =
213 g_W3CPrivilegeTextMap.find(DPL::ToUTF8String(*it));
214 if (result != g_W3CPrivilegeTextMap.end()) {
215 if (result->second == FEATURE_FULLSCREEN_MODE) {
221 ewk_context_tizen_extensible_api_set(m_ewkContext,
222 EWK_EXTENSIBLE_API_FULL_SCREEN,
226 void EwkContextManager::setBackgroundSupport()
228 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
233 WrtDB::WidgetSettings widgetSettings;
234 dao.getWidgetSettings(widgetSettings);
235 WidgetSettingList settings(widgetSettings);
236 bool backgroundSupport = false;
237 if(settings.getBackgroundSupport() == BackgroundSupport_Enable) {
238 backgroundSupport = true;
240 ewk_context_tizen_extensible_api_set(
242 EWK_EXTENSIBLE_API_BACKGROUND_MUSIC,
246 void EwkContextManager::setCSPSupport()
252 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
253 LogInfo("Setting CSP default policy");
254 ewk_context_tizen_extensible_api_set(m_ewkContext,
255 EWK_EXTENSIBLE_API_CSP,
259 void EwkContextManager::unsetCallbacks()
261 if (!m_initialized) {
265 ewk_context_message_from_injected_bundle_callback_set(
266 m_ewkContext, NULL, NULL);
267 ewk_context_did_start_download_callback_set(
268 m_ewkContext, NULL, NULL);
269 ewk_context_vibration_client_callbacks_set(
270 m_ewkContext, NULL, NULL, NULL);
274 void EwkContextManager::messageFromInjectedBundleCallback(
281 LogDebug("did recive message: " << name);
283 EwkContextManager* This = static_cast<EwkContextManager*>(clientInfo);
284 This->m_view->checkSyncMessageFromBundle(name, body, returnData);
287 void EwkContextManager::didStartDownloadCallback(const char* downloadUrl, void* data)
290 LogDebug("download url: " << downloadUrl);
292 EwkContextManager* This = static_cast<EwkContextManager*>(data);
293 This->m_view->downloadData(downloadUrl);
296 void EwkContextManager::vibrationClientStartCallback(uint64_t time, void* data)
300 EwkContextManager* This = static_cast<EwkContextManager*>(data);
301 This->m_view->activateVibration(true, static_cast<long>(time));
304 void EwkContextManager::vibrationClientStopCallback(void* data)
308 EwkContextManager* This = static_cast<EwkContextManager*>(data);
309 This->m_view->activateVibration(false, 0);
312 void EwkContextManager::handleLowMemory()
318 //ewk_context_cache_clear(m_ewkContext);
319 //ewk_context_notify_low_memory(m_ewkContext);
322 ContextManagerPtr createEwkContextManager(
323 std::string& tizenAppId,
324 Ewk_Context* ewkContext,
325 ViewModule::IViewModulePtr viewModule)
327 return ContextManagerPtr(new EwkContextManager(tizenAppId, ewkContext, viewModule));