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");
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
93 char *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
94 if (proxy && strlen(proxy) && strcmp(proxy, "0.0.0.0")) {
95 LogInfo("proxy address: " << proxy);
96 ewk_context_proxy_uri_set(m_ewkContext, proxy);
98 LogInfo("proxy address is empty");
99 ewk_context_proxy_uri_set(m_ewkContext, NULL);
106 ewk_context_certificate_file_set(m_ewkContext, caCertPath.c_str());
108 // set local stroage database path
109 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
110 ewk_context_web_storage_path_set(
112 dao.getPrivateLocalStoragePath().c_str());
114 // memory saving mode
117 WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
118 DPL::FromUTF8String(m_appId)).c_str(), &result);
120 ewk_context_memory_saving_mode_set(
122 static_cast<WrtDB::SettingsType>(result) ==
123 WrtDB::SETTINGS_TYPE_ON ? EINA_TRUE : EINA_FALSE);
125 setAutoFullscreenMode();
126 setBackgroundSupport();
128 // ewk storage_path set
129 ewk_context_storage_path_reset(m_ewkContext);
131 m_initialized = true;
136 void EwkContextManager::destroy()
138 // only in the following case, webkit context should be deleted
139 if (m_initialized && m_isInternalContext) {
140 ewk_context_delete(m_ewkContext);
144 void EwkContextManager::setCallbacks()
146 if (!m_initialized) {
150 ewk_context_message_from_injected_bundle_callback_set(
152 messageFromInjectedBundleCallback,
155 ewk_context_did_start_download_callback_set(
157 didStartDownloadCallback,
160 ewk_context_vibration_client_callbacks_set(
162 vibrationClientStartCallback,
163 vibrationClientStopCallback,
167 void EwkContextManager::setAutoFullscreenMode()
169 using namespace WrtDB;
170 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
174 std::list<DPL::String> widgetPrivilege = dao.getWidgetPrivilege();
175 bool fullscreen = false;
177 FOREACH(it, widgetPrivilege) {
178 std::map<std::string, Feature>::const_iterator result =
179 g_W3CPrivilegeTextMap.find(DPL::ToUTF8String(*it));
180 if (result != g_W3CPrivilegeTextMap.end()) {
181 if (result->second == FEATURE_FULLSCREEN_MODE) {
187 ewk_context_tizen_extensible_api_set(m_ewkContext,
188 EWK_EXTENSIBLE_API_FULL_SCREEN,
192 void EwkContextManager::setBackgroundSupport()
194 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
199 WidgetSettings widgetSettings;
200 dao.getWidgetSettings(widgetSettings);
201 WidgetSettingList settings(widgetSettings);
202 bool backgroundSupport = false;
203 if(settings.getBackgroundSupport() == BackgroundSupport_Enable) {
204 backgroundSupport = true;
206 ewk_context_tizen_extensible_api_set(
208 EWK_EXTENSIBLE_API_BACKGROUND_MUSIC,
212 void EwkContextManager::unsetCallbacks()
214 if (!m_initialized) {
218 ewk_context_message_from_injected_bundle_callback_set(
219 m_ewkContext, NULL, NULL);
220 ewk_context_did_start_download_callback_set(
221 m_ewkContext, NULL, NULL);
222 ewk_context_vibration_client_callbacks_set(
223 m_ewkContext, NULL, NULL, NULL);
227 void EwkContextManager::messageFromInjectedBundleCallback(
234 LogDebug("did recive message: " << name);
236 EwkContextManager* This = static_cast<EwkContextManager*>(clientInfo);
237 This->m_view->checkSyncMessageFromBundle(name, body, returnData);
240 void EwkContextManager::didStartDownloadCallback(const char* downloadUrl, void* data)
243 LogDebug("download url: " << downloadUrl);
245 EwkContextManager* This = static_cast<EwkContextManager*>(data);
246 This->m_view->downloadData(downloadUrl);
249 void EwkContextManager::vibrationClientStartCallback(uint64_t time, void* data)
253 EwkContextManager* This = static_cast<EwkContextManager*>(data);
254 This->m_view->activateVibration(true, static_cast<long>(time));
257 void EwkContextManager::vibrationClientStopCallback(void* data)
261 EwkContextManager* This = static_cast<EwkContextManager*>(data);
262 This->m_view->activateVibration(false, 0);
265 void EwkContextManager::handleLowMemory()
271 //ewk_context_cache_clear(m_ewkContext);
272 //ewk_context_notify_low_memory(m_ewkContext);
275 ContextManagerPtr createEwkContextManager(
276 std::string& tizenAppId,
277 Ewk_Context* ewkContext,
278 ViewModule::IViewModulePtr viewModule)
280 return ContextManagerPtr(new EwkContextManager(tizenAppId, ewkContext, viewModule));