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/utils/wrt_global_settings.h>
34 #include "ewk_context_manager.h"
38 static const std::string bundlePath("/usr/lib/libwrt-injected-bundle.so");
39 static const std::string caCertPath("/opt/usr/share/certs/ca-certificate.crt");
42 const std::string plugins_arch = "plugins/arm";
44 const std::string plugins_arch = "plugins/x86";
47 EwkContextManager::EwkContextManager(
48 const std::string& tizenAppId,
49 Ewk_Context* ewkContext,
50 ViewModule::IViewModulePtr viewModule)
51 : AbstractContextManager(tizenAppId, ewkContext, viewModule),
52 m_initialized(false), m_isInternalContext(false)
55 ThrowMsg(DPL::Exception, "Fail to intialize EwkContextManager");
57 // set ewk context callbacks
61 EwkContextManager::~EwkContextManager()
63 // unset registered ewk context callbacks
68 Ewk_Context * EwkContextManager::getEwkContext() const
73 bool EwkContextManager::initialize()
76 m_ewkContext = ewk_context_new_with_injected_bundle_path(bundlePath.c_str());
82 m_isInternalContext = true;
85 // cache model setting
86 ewk_context_cache_model_set(
88 EWK_CACHE_MODEL_DOCUMENT_BROWSER);
89 ADD_PROFILING_POINT("WebProcess fork", "start");
90 // To fork a Webprocess as soon as possible,
91 // the following ewk_api is called explicitly.
92 ewk_cookie_manager_accept_policy_set(
93 ewk_context_cookie_manager_get(m_ewkContext),
94 EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
95 ADD_PROFILING_POINT("WebProcess fork", "stop");
97 // proxy server setting
100 LogInfo("ewk_context_certificate_file_set() was called.");
101 ewk_context_certificate_file_set(m_ewkContext, caCertPath.c_str());
103 // set local stroage database path
104 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
105 ewk_context_web_storage_path_set(
107 dao.getPrivateLocalStoragePath().c_str());
109 // memory saving mode
110 //ewk_context_memory_saving_mode_set(
112 // static_cast<WrtDB::SettingsType>(result) ==
113 // WrtDB::SETTINGS_TYPE_ON ? EINA_TRUE : EINA_FALSE);
115 ewk_context_tizen_extensible_api_set(
117 EWK_EXTENSIBLE_API_MEDIA_STREAM_RECORD,
119 ewk_context_tizen_extensible_api_set(
121 EWK_EXTENSIBLE_API_ROTATE_CAMERA_VIEW,
123 ewk_context_tizen_extensible_api_set(
125 EWK_EXTENSIBLE_API_MEDIA_VOLUME_CONTROL,
128 setAutoFullscreenMode();
129 setBackgroundSupport();
131 if (dao.getSecurityModelVersion() ==
132 WrtDB::WidgetSecurityModelVersion::WIDGET_SECURITY_MODEL_V2)
138 // ewk storage_path set
139 ewk_context_storage_path_reset(m_ewkContext);
141 // npruntime plugins path set
142 std::ostringstream plugins_path;
143 plugins_path << dao.getPath() << plugins_arch;
144 LogInfo("ewk_context_additional_plugin_path_set() : " << plugins_path.str());
146 ewk_context_additional_plugin_path_set(m_ewkContext, plugins_path.str().c_str());
148 m_initialized = true;
153 void EwkContextManager::destroy()
155 // only in the following case, webkit context should be deleted
156 if (m_initialized && m_isInternalContext) {
157 ewk_context_delete(m_ewkContext);
161 void EwkContextManager::setCallbacks()
163 if (!m_initialized) {
167 ewk_context_message_from_injected_bundle_callback_set(
169 messageFromInjectedBundleCallback,
172 ewk_context_did_start_download_callback_set(
174 didStartDownloadCallback,
177 ewk_context_vibration_client_callbacks_set(
179 vibrationClientStartCallback,
180 vibrationClientStopCallback,
183 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
184 vconfChangedCallback,
188 void EwkContextManager::unsetCallbacks()
190 if (!m_initialized) {
194 ewk_context_message_from_injected_bundle_callback_set(
195 m_ewkContext, NULL, NULL);
196 ewk_context_did_start_download_callback_set(
197 m_ewkContext, NULL, NULL);
198 ewk_context_vibration_client_callbacks_set(
199 m_ewkContext, NULL, NULL, NULL);
201 vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
202 vconfChangedCallback);
205 void EwkContextManager::setAutoFullscreenMode()
207 using namespace WrtDB;
208 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
212 std::list<DPL::String> widgetPrivilege = dao.getWidgetPrivilege();
213 bool fullscreen = false;
215 FOREACH(it, widgetPrivilege) {
216 std::map<std::string, Feature>::const_iterator result =
217 g_W3CPrivilegeTextMap.find(DPL::ToUTF8String(*it));
218 if (result != g_W3CPrivilegeTextMap.end()) {
219 if (result->second == FEATURE_FULLSCREEN_MODE) {
225 ewk_context_tizen_extensible_api_set(m_ewkContext,
226 EWK_EXTENSIBLE_API_FULL_SCREEN,
230 void EwkContextManager::setBackgroundSupport()
232 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
237 WrtDB::WidgetSettings widgetSettings;
238 dao.getWidgetSettings(widgetSettings);
239 WidgetSettingList settings(widgetSettings);
240 bool backgroundSupport = false;
241 if(settings.getBackgroundSupport() == BackgroundSupport_Enable) {
242 backgroundSupport = true;
244 ewk_context_tizen_extensible_api_set(
246 EWK_EXTENSIBLE_API_BACKGROUND_MUSIC,
250 void EwkContextManager::setCSPSupport()
256 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
257 LogInfo("Setting CSP default policy");
258 ewk_context_tizen_extensible_api_set(m_ewkContext,
259 EWK_EXTENSIBLE_API_CSP,
263 void EwkContextManager::setNetworkProxy()
265 Assert(m_ewkContext);
268 if (vconf_get_int(VCONFKEY_NETWORK_STATUS,
271 LogError("Fail to get network state");
274 if (networkState == VCONFKEY_NETWORK_OFF) {
278 char* proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
279 if (proxy && strlen(proxy) && strcmp(proxy, "0.0.0.0")) {
280 LogInfo("proxy address: " << proxy);
281 ewk_context_proxy_uri_set(m_ewkContext, proxy);
283 LogInfo("proxy address is empty");
284 ewk_context_proxy_uri_set(m_ewkContext, NULL);
288 void EwkContextManager::messageFromInjectedBundleCallback(
295 LogDebug("did recive message: " << name);
297 EwkContextManager* This = static_cast<EwkContextManager*>(clientInfo);
299 This->m_view->checkSyncMessageFromBundle(name, body, returnData);
301 This->m_view->checkAsyncMessageFromBundle(name, body);
305 void EwkContextManager::didStartDownloadCallback(const char* downloadUrl, void* data)
308 LogDebug("download url: " << downloadUrl);
310 EwkContextManager* This = static_cast<EwkContextManager*>(data);
311 This->m_view->downloadData(downloadUrl);
314 void EwkContextManager::vibrationClientStartCallback(uint64_t time, void* data)
318 EwkContextManager* This = static_cast<EwkContextManager*>(data);
319 This->m_view->activateVibration(true, static_cast<long>(time));
322 void EwkContextManager::vibrationClientStopCallback(void* data)
326 EwkContextManager* This = static_cast<EwkContextManager*>(data);
327 This->m_view->activateVibration(false, 0);
330 void EwkContextManager::vconfChangedCallback(keynode_t* keynode, void* data)
333 char* key = vconf_keynode_get_name(keynode);
336 LogError("key is null");
339 std::string keyString = key;
341 EwkContextManager* This = static_cast<EwkContextManager*>(data);
342 if (keyString == VCONFKEY_NETWORK_PROXY) {
343 This->setNetworkProxy();
347 void EwkContextManager::handleLowMemory()
353 //ewk_context_cache_clear(m_ewkContext);
354 //ewk_context_notify_low_memory(m_ewkContext);
357 ContextManagerPtr createEwkContextManager(
358 std::string& tizenAppId,
359 Ewk_Context* ewkContext,
360 ViewModule::IViewModulePtr viewModule)
362 return ContextManagerPtr(new EwkContextManager(tizenAppId, ewkContext, viewModule));