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 <cert-service.h>
28 #include <ewk_context.h>
29 #include <dpl/log/log.h>
30 #include <dpl/exception.h>
31 #include <profiling_util.h>
32 #include <i_view_module.h>
33 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
34 #include <dpl/wrt-dao-ro/widget_dao_types.h>
35 #include <dpl/wrt-dao-ro/widget_config.h>
36 #include <dpl/utils/wrt_global_settings.h>
37 #include "ewk_context_manager.h"
39 namespace ViewModule {
41 const std::string bundlePath( LIBDIR_PREFIX "/libwrt-injected-bundle.so");
42 std::map<Ewk_Extensible_API, Eina_Bool> defaultExtensibleAPI = {
43 { EWK_EXTENSIBLE_API_MEDIA_STREAM_RECORD, EINA_TRUE },
44 { EWK_EXTENSIBLE_API_ROTATE_CAMERA_VIEW, EINA_FALSE },
45 { EWK_EXTENSIBLE_API_MEDIA_VOLUME_CONTROL, EINA_TRUE },
47 } // anonymous namespace
49 EwkContextManager::EwkContextManager(
50 const std::string& tizenAppId,
51 Ewk_Context* ewkContext,
52 IViewModulePtr viewModule)
53 : IContextManager(tizenAppId, ewkContext, viewModule),
54 m_initialized(false), m_isInternalContext(false)
57 ThrowMsg(DPL::Exception, "Fail to intialize EwkContextManager");
59 // set ewk context callbacks
63 EwkContextManager::~EwkContextManager()
65 // unset registered ewk context callbacks
70 Ewk_Context * EwkContextManager::getEwkContext() const
75 bool EwkContextManager::initialize()
78 m_ewkContext = ewk_context_new_with_injected_bundle_path(bundlePath.c_str());
84 m_isInternalContext = true;
87 // cache model setting
88 ewk_context_cache_model_set(
90 EWK_CACHE_MODEL_DOCUMENT_BROWSER);
91 ADD_PROFILING_POINT("WebProcess fork", "start");
92 // To fork a Webprocess as soon as possible,
93 // the following ewk_api is called explicitly.
94 ewk_cookie_manager_accept_policy_set(
95 ewk_context_cookie_manager_get(m_ewkContext),
96 EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
97 ADD_PROFILING_POINT("WebProcess fork", "stop");
99 // proxy server setting
102 LogDebug("ewk_context_certificate_file_set() was called.");
103 const char* caCertPath = cert_svc_get_certificate_crt_file_path();
105 ewk_context_certificate_file_set(m_ewkContext, caCertPath);
107 LogError("cert path is null");
110 FOREACH(it, defaultExtensibleAPI) {
111 ewk_context_tizen_extensible_api_set(m_ewkContext,
116 // web application dependent settings
117 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
118 ewk_context_web_storage_path_set(
120 dao.getPrivateLocalStoragePath().c_str());
122 setAutoFullscreenMode();
124 if (dao.getSecurityModelVersion() ==
125 WrtDB::WidgetSecurityModelVersion::WIDGET_SECURITY_MODEL_V2)
127 ewk_context_tizen_extensible_api_set(m_ewkContext,
128 EWK_EXTENSIBLE_API_CSP,
133 // WidgetSettingList dependent settings
134 WrtDB::WidgetSettings widgetSettings;
135 dao.getWidgetSettings(widgetSettings);
136 WidgetSettingList settings(widgetSettings);
138 ewk_context_tizen_extensible_api_set(
140 EWK_EXTENSIBLE_API_BACKGROUND_MUSIC,
141 settings.getBackgroundSupport() == BackgroundSupport_Enable ?
142 EINA_TRUE : EINA_FALSE);
143 // Disable in the RSA
144 //ewk_context_tizen_extensible_api_set(
146 // EWK_EXTENSIBLE_API_SOUND_MODE,
147 // settings.getSoundMode() == SoundMode_Exclusive ?
148 // EINA_TRUE : EINA_FALSE);
150 // ewk storage_path set
151 ewk_context_storage_path_reset(m_ewkContext);
153 std::string pluginsPath =
154 WrtDB::WidgetConfig::GetWidgetNPRuntimePluginsPath(
155 dao.getTizenPkgId());
157 // npruntime plugins path set
158 LogDebug("ewk_context_additional_plugin_path_set() : " << pluginsPath);
160 ewk_context_additional_plugin_path_set(m_ewkContext, pluginsPath.c_str());
162 m_initialized = true;
167 void EwkContextManager::destroy()
169 // only in the following case, webkit context should be deleted
170 if (m_initialized && m_isInternalContext) {
171 ewk_context_delete(m_ewkContext);
175 void EwkContextManager::setCallbacks()
177 if (!m_initialized) {
181 ewk_context_message_from_injected_bundle_callback_set(
183 messageFromInjectedBundleCallback,
186 ewk_context_did_start_download_callback_set(
188 didStartDownloadCallback,
191 ewk_context_vibration_client_callbacks_set(
193 vibrationClientStartCallback,
194 vibrationClientStopCallback,
197 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
198 vconfChangedCallback,
202 void EwkContextManager::unsetCallbacks()
204 if (!m_initialized) {
208 ewk_context_message_from_injected_bundle_callback_set(
209 m_ewkContext, NULL, NULL);
210 ewk_context_did_start_download_callback_set(
211 m_ewkContext, NULL, NULL);
212 ewk_context_vibration_client_callbacks_set(
213 m_ewkContext, NULL, NULL, NULL);
215 vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
216 vconfChangedCallback);
219 void EwkContextManager::setAutoFullscreenMode()
221 using namespace WrtDB;
222 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
226 std::list<DPL::String> widgetPrivilege = dao.getWidgetPrivilege();
227 bool fullscreen = false;
229 FOREACH(it, widgetPrivilege) {
230 std::map<std::string, Feature>::const_iterator result =
231 g_W3CPrivilegeTextMap.find(DPL::ToUTF8String(*it));
232 if (result != g_W3CPrivilegeTextMap.end()) {
233 if (result->second == FEATURE_FULLSCREEN_MODE) {
239 ewk_context_tizen_extensible_api_set(m_ewkContext,
240 EWK_EXTENSIBLE_API_FULL_SCREEN,
244 void EwkContextManager::setNetworkProxy()
246 Assert(m_ewkContext);
249 if (vconf_get_int(VCONFKEY_NETWORK_STATUS,
252 LogError("Fail to get network state");
255 if (networkState == VCONFKEY_NETWORK_OFF) {
259 char* proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
260 if (proxy && strlen(proxy) && strcmp(proxy, "0.0.0.0")) {
261 LogDebug("proxy address: " << proxy);
262 ewk_context_proxy_uri_set(m_ewkContext, proxy);
264 LogDebug("proxy address is empty");
265 ewk_context_proxy_uri_set(m_ewkContext, NULL);
269 void EwkContextManager::messageFromInjectedBundleCallback(
277 EwkContextManager* This = static_cast<EwkContextManager*>(clientInfo);
279 This->m_view->checkSyncMessageFromBundle(name, body, returnData);
281 This->m_view->checkAsyncMessageFromBundle(name, body);
285 void EwkContextManager::didStartDownloadCallback(const char* downloadUrl, void* data)
289 EwkContextManager* This = static_cast<EwkContextManager*>(data);
290 This->m_view->downloadData(downloadUrl);
293 void EwkContextManager::vibrationClientStartCallback(uint64_t time, void* data)
297 EwkContextManager* This = static_cast<EwkContextManager*>(data);
298 This->m_view->activateVibration(true, static_cast<long>(time));
301 void EwkContextManager::vibrationClientStopCallback(void* data)
305 EwkContextManager* This = static_cast<EwkContextManager*>(data);
306 This->m_view->activateVibration(false, 0);
309 void EwkContextManager::vconfChangedCallback(keynode_t* keynode, void* data)
312 char* key = vconf_keynode_get_name(keynode);
315 LogError("key is null");
318 std::string keyString = key;
320 EwkContextManager* This = static_cast<EwkContextManager*>(data);
321 if (keyString == VCONFKEY_NETWORK_PROXY) {
322 This->setNetworkProxy();
326 void EwkContextManager::handleLowMemory()
332 //ewk_context_cache_clear(m_ewkContext);
333 //ewk_context_notify_low_memory(m_ewkContext);
336 ContextManagerPtr createEwkContextManager(
337 std::string& tizenAppId,
338 Ewk_Context* ewkContext,
339 ViewModule::IViewModulePtr viewModule)
341 return ContextManagerPtr(new EwkContextManager(tizenAppId, ewkContext, viewModule));
344 } // namespace ViewModule