2 * Copyright (c) 2011 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 core_module.cpp
18 * @author Przemyslaw Ciezkowski (p.ciezkowski@samsung.com)
19 * @author Andrzej Surdej (a.surdej@samsung.com)
21 * @brief File contains definitions of wrt core module.
24 #include "core_module.h"
25 #include "runnable_widget_object.h"
27 #include <main_thread.h>
28 #include <dpl/log/log.h>
29 #include <dpl/assert.h>
30 #include <dpl/exception.h>
31 #include <dpl/singleton_impl.h>
32 #include "localization_setting.h"
33 #include <dpl/wrt-dao-ro/global_config.h>
34 #include <profiling_util.h>
35 #include <widget_deserialize_model.h>
36 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
37 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
42 IMPLEMENT_SINGLETON(WRT::CoreModule)
44 namespace { //Anonymous
46 const char * const bundlePath = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
48 std::string cutOffFileName(const std::string& path)
50 size_t found = path.find_last_of("/");
51 if (found == std::string::npos) {
54 return path.substr(0, found);
58 bool isDir(const std::string& path)
61 if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
64 LogError("Cannot access directory [ " << path << " ]");
70 using namespace WrtDB;
71 using namespace WrtDB::GlobalConfig;
74 if_ok &= (isDir(cutOffFileName(GetWrtDatabaseFilePath())));
76 LogError("Path <" << GetWrtDatabaseFilePath() << "> does not exist.");
79 if_ok &= (isDir(GetDevicePluginPath()));
81 LogError("Path <" << GetDevicePluginPath() << "> does not exist.");
84 if_ok &= (isDir(GetUserInstalledWidgetPath()));
86 LogError("Path <" << GetUserInstalledWidgetPath() <<
91 }// namespace anonymous
99 CoreModuleImpl() : m_initialized(false), m_ewkContext(NULL)
106 LogDebug("Core module implementation destroyed");
111 if (!m_initialized) {
112 ADD_PROFILING_POINT("CoreModule::Init", "point");
113 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
114 LogDebug("Initialize");
116 LogError("Required path does not exist");
122 // Needed settings for WKContext are located here
123 // create Ewk_Context
124 Ewk_Context* newEwkContext =
125 ewk_context_new_with_injected_bundle_path(bundlePath);
126 if (!newEwkContext) {
127 LogError("Failed to create Ewk_Context");
128 ThrowMsg(DPL::Exception, "Failed to create ewk context");
130 // cache model setting
131 ewk_context_cache_model_set(newEwkContext,
132 EWK_CACHE_MODEL_DOCUMENT_BROWSER);
133 m_ewkContext = newEwkContext;
134 ADD_PROFILING_POINT("WebProcess fork", "start");
136 // To fork a Webprocess as soon as possible,
137 // the following ewk_api is called explicitly.
138 Ewk_Cookie_Manager *ewkCookieManager;
140 ewk_context_cookie_manager_get(m_ewkContext);
141 ewk_cookie_manager_accept_policy_set(ewkCookieManager,
142 EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
143 ADD_PROFILING_POINT("WebProcess fork", "stop");
145 ADD_PROFILING_POINT("attach databases", "start");
146 MainThreadSingleton::Instance().AttachDatabases();
147 ADD_PROFILING_POINT("attach databases", "stop");
149 LogDebug("Initialize finished");
150 } catch (const DPL::Exception& ex) {
151 LogError("Internal Error during screen preparation:");
152 DPL::Exception::DisplayKnownException(ex);
154 * Do deinitialization: check on which step exception occured
155 * and deinitialize only initialized parts.
159 m_initialized = true;
167 LogInfo("finalizeEwkContext called");
168 ewk_context_delete(m_ewkContext);
171 MainThreadSingleton::Instance().DetachDatabases();
173 m_initialized = false;
176 RunnableWidgetObjectPtr getRunnableWidgetObject(
177 const std::string& tizenId)
180 RunnableWidgetObjectPtr runnable;
181 WidgetModelPtr model = Domain::deserializeWidgetModel(tizenId);
183 runnable.reset(new RunnableWidgetObject(model, m_ewkContext));
186 } catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
187 LogDebug("Widget not found.");
188 return RunnableWidgetObjectPtr();
192 CoreModule::NetworkAccessMode homeNetworkAccess()
194 switch (WrtDB::GlobalDAOReadOnly::GetHomeNetworkDataUsage()) {
195 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
196 return CoreModule::NEVER_CONNECT;
197 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
198 return CoreModule::ALWAYS_ASK;
199 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
200 return CoreModule::CONNECT_AUTOMATICALLY;
204 LogWarning("using default value");
205 return CoreModule::ALWAYS_ASK;
208 CoreModule::NetworkAccessMode roamingNetworkAccess()
210 switch (WrtDB::GlobalDAOReadOnly::GetRoamingDataUsage()) {
211 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
212 return CoreModule::NEVER_CONNECT;
213 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
214 return CoreModule::ALWAYS_ASK;
215 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
216 return CoreModule::CONNECT_AUTOMATICALLY;
220 LogWarning("using default value");
221 return CoreModule::ALWAYS_ASK;
226 return WrtDB::GlobalDAOReadOnly::GetDeveloperMode();
231 Ewk_Context* m_ewkContext;
234 CoreModule::CoreModule() : m_impl(new CoreModuleImpl())
238 CoreModule::~CoreModule()
242 bool CoreModule::Init()
244 return m_impl->Init();
247 void CoreModule::Terminate()
249 return m_impl->Terminate();
252 RunnableWidgetObjectPtr CoreModule::getRunnableWidgetObject(
253 const std::string& tizenId)
255 return m_impl->getRunnableWidgetObject(tizenId);
258 CoreModule::NetworkAccessMode CoreModule::homeNetworkAccess()
260 return m_impl->homeNetworkAccess();
263 CoreModule::NetworkAccessMode CoreModule::roamingNetworkAccess()
265 return m_impl->roamingNetworkAccess();
268 bool CoreModule::developerMode()
270 return m_impl->developerMode();
273 } /* namespace WRT */