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/widget_config.h>
34 #include <dpl/utils/wrt_global_settings.h>
35 #include "ewk_context_manager.h"
39 static const std::string bundlePath("/usr/lib/libwrt-injected-bundle.so");
40 static const std::string caCertPath("/opt/usr/share/certs/ca-certificate.crt");
42 EwkContextManager::EwkContextManager(
43 const std::string& tizenAppId,
44 Ewk_Context* ewkContext,
45 ViewModule::IViewModulePtr viewModule)
46 : AbstractContextManager(tizenAppId, ewkContext, viewModule),
47 m_initialized(false), m_isInternalContext(false)
50 ThrowMsg(DPL::Exception, "Fail to intialize EwkContextManager");
52 // set ewk context callbacks
56 EwkContextManager::~EwkContextManager()
58 // unset registered ewk context callbacks
63 Ewk_Context * EwkContextManager::getEwkContext() const
68 bool EwkContextManager::initialize()
71 m_ewkContext = ewk_context_new_with_injected_bundle_path(bundlePath.c_str());
77 m_isInternalContext = true;
80 // cache model setting
81 ewk_context_cache_model_set(
83 EWK_CACHE_MODEL_DOCUMENT_BROWSER);
84 ADD_PROFILING_POINT("WebProcess fork", "start");
85 // To fork a Webprocess as soon as possible,
86 // the following ewk_api is called explicitly.
87 ewk_cookie_manager_accept_policy_set(
88 ewk_context_cookie_manager_get(m_ewkContext),
89 EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
90 ADD_PROFILING_POINT("WebProcess fork", "stop");
92 // proxy server setting
95 LogInfo("ewk_context_certificate_file_set() was called.");
96 ewk_context_certificate_file_set(m_ewkContext, caCertPath.c_str());
98 // set local stroage database path
99 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
100 ewk_context_web_storage_path_set(
102 dao.getPrivateLocalStoragePath().c_str());
104 // memory saving mode
105 //ewk_context_memory_saving_mode_set(
107 // static_cast<WrtDB::SettingsType>(result) ==
108 // WrtDB::SETTINGS_TYPE_ON ? EINA_TRUE : EINA_FALSE);
110 ewk_context_tizen_extensible_api_set(
112 EWK_EXTENSIBLE_API_MEDIA_STREAM_RECORD,
114 ewk_context_tizen_extensible_api_set(
116 EWK_EXTENSIBLE_API_ROTATE_CAMERA_VIEW,
118 ewk_context_tizen_extensible_api_set(
120 EWK_EXTENSIBLE_API_MEDIA_VOLUME_CONTROL,
123 setAutoFullscreenMode();
124 setBackgroundSupport();
126 if (dao.getSecurityModelVersion() ==
127 WrtDB::WidgetSecurityModelVersion::WIDGET_SECURITY_MODEL_V2)
133 // ewk storage_path set
134 ewk_context_storage_path_reset(m_ewkContext);
136 std::string pluginsPath =
137 WrtDB::WidgetConfig::GetWidgetNPRuntimePluginsPath(
138 dao.getTizenPkgId());
140 // npruntime plugins path set
141 LogInfo("ewk_context_additional_plugin_path_set() : " << pluginsPath);
143 ewk_context_additional_plugin_path_set(m_ewkContext, pluginsPath.c_str());
145 m_initialized = true;
150 void EwkContextManager::destroy()
152 // only in the following case, webkit context should be deleted
153 if (m_initialized && m_isInternalContext) {
154 ewk_context_delete(m_ewkContext);
158 void EwkContextManager::setCallbacks()
160 if (!m_initialized) {
164 ewk_context_message_from_injected_bundle_callback_set(
166 messageFromInjectedBundleCallback,
169 ewk_context_did_start_download_callback_set(
171 didStartDownloadCallback,
174 ewk_context_vibration_client_callbacks_set(
176 vibrationClientStartCallback,
177 vibrationClientStopCallback,
180 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
181 vconfChangedCallback,
185 void EwkContextManager::unsetCallbacks()
187 if (!m_initialized) {
191 ewk_context_message_from_injected_bundle_callback_set(
192 m_ewkContext, NULL, NULL);
193 ewk_context_did_start_download_callback_set(
194 m_ewkContext, NULL, NULL);
195 ewk_context_vibration_client_callbacks_set(
196 m_ewkContext, NULL, NULL, NULL);
198 vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
199 vconfChangedCallback);
202 void EwkContextManager::setAutoFullscreenMode()
204 using namespace WrtDB;
205 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
209 std::list<DPL::String> widgetPrivilege = dao.getWidgetPrivilege();
210 bool fullscreen = false;
212 FOREACH(it, widgetPrivilege) {
213 std::map<std::string, Feature>::const_iterator result =
214 g_W3CPrivilegeTextMap.find(DPL::ToUTF8String(*it));
215 if (result != g_W3CPrivilegeTextMap.end()) {
216 if (result->second == FEATURE_FULLSCREEN_MODE) {
222 ewk_context_tizen_extensible_api_set(m_ewkContext,
223 EWK_EXTENSIBLE_API_FULL_SCREEN,
227 void EwkContextManager::setBackgroundSupport()
229 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
234 WrtDB::WidgetSettings widgetSettings;
235 dao.getWidgetSettings(widgetSettings);
236 WidgetSettingList settings(widgetSettings);
237 bool backgroundSupport = false;
238 if(settings.getBackgroundSupport() == BackgroundSupport_Enable) {
239 backgroundSupport = true;
241 ewk_context_tizen_extensible_api_set(
243 EWK_EXTENSIBLE_API_BACKGROUND_MUSIC,
247 void EwkContextManager::setCSPSupport()
253 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
254 LogInfo("Setting CSP default policy");
255 ewk_context_tizen_extensible_api_set(m_ewkContext,
256 EWK_EXTENSIBLE_API_CSP,
260 void EwkContextManager::setNetworkProxy()
262 Assert(m_ewkContext);
265 if (vconf_get_int(VCONFKEY_NETWORK_STATUS,
268 LogError("Fail to get network state");
271 if (networkState == VCONFKEY_NETWORK_OFF) {
275 char* proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
276 if (proxy && strlen(proxy) && strcmp(proxy, "0.0.0.0")) {
277 LogInfo("proxy address: " << proxy);
278 ewk_context_proxy_uri_set(m_ewkContext, proxy);
280 LogInfo("proxy address is empty");
281 ewk_context_proxy_uri_set(m_ewkContext, NULL);
285 void EwkContextManager::messageFromInjectedBundleCallback(
292 LogDebug("did recive message: " << name);
294 EwkContextManager* This = static_cast<EwkContextManager*>(clientInfo);
296 This->m_view->checkSyncMessageFromBundle(name, body, returnData);
298 This->m_view->checkAsyncMessageFromBundle(name, body);
302 void EwkContextManager::didStartDownloadCallback(const char* downloadUrl, void* data)
305 LogDebug("download url: " << downloadUrl);
307 EwkContextManager* This = static_cast<EwkContextManager*>(data);
308 This->m_view->downloadData(downloadUrl);
311 void EwkContextManager::vibrationClientStartCallback(uint64_t time, void* data)
315 EwkContextManager* This = static_cast<EwkContextManager*>(data);
316 This->m_view->activateVibration(true, static_cast<long>(time));
319 void EwkContextManager::vibrationClientStopCallback(void* data)
323 EwkContextManager* This = static_cast<EwkContextManager*>(data);
324 This->m_view->activateVibration(false, 0);
327 void EwkContextManager::vconfChangedCallback(keynode_t* keynode, void* data)
330 char* key = vconf_keynode_get_name(keynode);
333 LogError("key is null");
336 std::string keyString = key;
338 EwkContextManager* This = static_cast<EwkContextManager*>(data);
339 if (keyString == VCONFKEY_NETWORK_PROXY) {
340 This->setNetworkProxy();
344 void EwkContextManager::handleLowMemory()
350 //ewk_context_cache_clear(m_ewkContext);
351 //ewk_context_notify_low_memory(m_ewkContext);
354 ContextManagerPtr createEwkContextManager(
355 std::string& tizenAppId,
356 Ewk_Context* ewkContext,
357 ViewModule::IViewModulePtr viewModule)
359 return ContextManagerPtr(new EwkContextManager(tizenAppId, ewkContext, viewModule));