2 // Open Service Platform
\r
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Apache License, Version 2.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.apache.org/licenses/LICENSE-2.0
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an "AS IS" BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
19 * @file FWebCtrl_WebManager.cpp
\r
20 * @brief The file contains the definition of _WebManager class.
\r
22 * The file contains the definition of _WebManager class.
\r
24 #include <pthread.h>
\r
25 #include <net_connection.h>
\r
26 #include <FAppApp.h>
\r
27 #include <FBaseSysLog.h>
\r
28 #include <FIoDbEnumerator.h>
\r
29 #include <FUiControl.h>
\r
30 #include <FIo_DirectoryImpl.h>
31 #include <FIo_DatabaseImpl.h>
32 #include <FIo_FileImpl.h>
\r
33 #include <FUiCtrl_FormImpl.h>
\r
34 #include <FIo_DirectoryImpl.h>
35 #include <FIo_DatabaseImpl.h>
36 #include <FIo_FileImpl.h>
37 #include "FWebCtrl_EflWebkit.h"
\r
38 #include "FWebCtrl_Web.h"
\r
39 #include "FWebCtrl_WebImpl.h"
\r
40 #include "FWebCtrl_WebManager.h"
\r
41 #include "FWebCtrl_WebPopup.h"
\r
43 using namespace Tizen::Base;
\r
44 using namespace Tizen::Base::Collection;
\r
45 using namespace Tizen::Io;
\r
46 using namespace Tizen::Ui;
\r
47 using namespace Tizen::Ui::Controls;
\r
49 namespace Tizen { namespace Web { namespace Controls
\r
53 _WebManager* _WebManager::__pInstance = null;
\r
56 extern const wchar_t CUSTOM_DB_DIRECTORY_PATH[] = L"data/.webkit/customDatabase/";
57 extern const wchar_t USER_CONFIRM_DB_NAME[] = L"userConfirm.db";
58 extern const wchar_t GEOLOCATION_TABLE_NAME[] = L"geolocationPermission";
59 extern const wchar_t CUSTOM_PROTOCOL_TABLE_NAME[] = L"customProtocol";
60 extern const wchar_t CUSTOM_CONTENT_TABLE_NAME[] = L"customContent";
61 extern const wchar_t CERTIFICATE_TABLE_NAME[] = L"certificate";
64 static const int CUSTOM_DB_TABLE_COUNT= 4;
\r
67 _WebManager::_WebManager(void)
\r
69 , __pCallbackList(null)
\r
70 , __pActiveWeb(null)
\r
71 , __pActivePopup(null)
\r
76 _WebManager::~_WebManager(void)
\r
79 ClearCertificateDb();
\r
84 _WebManager::InitWebManager(void)
\r
86 result r = E_SUCCESS;
\r
88 std::unique_ptr<_WebManager> pInstance(new (std::nothrow) _WebManager());
\r
89 SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
\r
91 r = pInstance->Construct();
\r
92 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
\r
94 __pInstance = pInstance.release();
\r
95 std::atexit(DestroyWebManager);
\r
100 _WebManager::DestroyWebManager(void)
\r
102 delete __pInstance;
\r
103 __pInstance = null;
\r
108 _WebManager::GetInstance(void)
\r
110 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
\r
111 if (__pInstance== null)
\r
114 pthread_once(&onceBlock, InitWebManager);
\r
115 result r = GetLastResult();
\r
118 onceBlock = PTHREAD_ONCE_INIT;
\r
122 return __pInstance;
\r
127 _WebManager::Construct(void)
\r
129 result r = E_SUCCESS;
\r
131 std::unique_ptr<ArrayListT< int> > pWebList(new (std::nothrow) ArrayListT< int >());
\r
132 SysTryReturnResult(NID_WEB_CTRL, pWebList.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
\r
133 r = pWebList->Construct();
\r
134 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
136 std::unique_ptr<MultiHashMapT< int, int > > pCallbackList(new (std::nothrow) MultiHashMapT< int, int >());
\r
137 SysTryReturnResult(NID_WEB_CTRL, pCallbackList.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
\r
138 r = pCallbackList->Construct();
\r
139 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
141 r = InitializeProxyAddress();
\r
142 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
144 r = CreateResourceDirectory();
\r
145 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
147 r = InitializeCustomDb();
\r
148 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
150 __pWebList = std::move(pWebList);
\r
151 __pCallbackList = std::move(pCallbackList);
\r
158 _WebManager::ClearCertificateDb(void)
\r
160 result r = E_SUCCESS;
162 String certificatePath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
163 String table(CERTIFICATE_TABLE_NAME);
166 r = db.Construct(certificatePath, "r+", null);
167 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
169 db.BeginTransaction();
171 r = db.ExecuteSql(L"Delete From " + table, true);
172 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
174 db.CommitTransaction();
179 db.RollbackTransaction();
184 _WebManager::InitializeProxyAddress(void)
\r
187 connection_h handle = null;
\r
188 char* pProxy = null;
\r
190 ret = connection_create(&handle);
191 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to create connection.");
193 connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
195 ret = connection_get_proxy(handle, family, &pProxy);
196 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to get proxy address.");
\r
198 ret = connection_destroy(handle);
199 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to destroy connection.");
\r
208 _WebManager::CreateResourceDirectory(void) const
\r
210 String html5FeaturesPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH);
212 if (!_FileImpl::IsFileExist(html5FeaturesPath))
214 result r = E_SUCCESS;
216 r = _DirectoryImpl::Create(html5FeaturesPath, true);
217 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. create html5 features directory.");
225 _WebManager::InitializeCustomDb(void) const
\r
227 result r = E_SUCCESS;
230 String path(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
231 String geolocationTable(GEOLOCATION_TABLE_NAME);
232 String protocolTable(CUSTOM_PROTOCOL_TABLE_NAME);
233 String contentTable(CUSTOM_CONTENT_TABLE_NAME);
234 String certificateTable(CERTIFICATE_TABLE_NAME);
236 r = db.Construct(path, "a+", null);
237 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
239 std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select count(name) from sqlite_master Where type='table' And name in ('" + geolocationTable + L"', '" + protocolTable + L"', '" + contentTable + L"', '" + certificateTable + L"')"));
244 r = pEnum->MoveNext();
245 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
247 r = pEnum->GetIntAt(0, count);
248 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
250 if (count == CUSTOM_DB_TABLE_COUNT)
257 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + geolocationTable + L"'"));
261 L"CREATE TABLE IF NOT EXISTS " + geolocationTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT, permission INTEGER)",
263 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
267 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + protocolTable + L"'"));
271 L"CREATE TABLE IF NOT EXISTS " + protocolTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, baseUrl TEXT, url TEXT, mime TEXT, allow INTEGER)",
273 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
277 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + contentTable + L"'"));
281 L"CREATE TABLE IF NOT EXISTS " + contentTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, baseUrl TEXT, url TEXT, mime TEXT, allow INTEGER)",
283 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
287 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + certificateTable + L"'"));
291 L"CREATE TABLE IF NOT EXISTS " + certificateTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, pem TEXT, allow INTEGER)",
293 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
301 _WebManager::AddWeb(int webAdress)
\r
303 result r = E_SUCCESS;
\r
305 _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(webAdress);
\r
306 _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
\r
308 r = pWebCore->GetEflWebkit()->SetProxyAddress(__pProxy);
\r
309 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
311 r = __pWebList->Add(webAdress);
\r
312 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
319 _WebManager::RemoveWeb(int webAdress)
\r
321 result r = E_SUCCESS;
\r
323 r = __pWebList->Remove(webAdress);
\r
324 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
326 __pCallbackList->Remove(webAdress);
\r
333 _WebManager::IsValidWeb(int webAdress) const
\r
335 return __pWebList->Contains(webAdress);
\r
340 _WebManager::AddCallback(int callerAdress, int callbackAdress)
\r
342 result r = E_SUCCESS;
\r
344 r = __pCallbackList->Add(callerAdress, callbackAdress);
\r
345 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
352 _WebManager::RemoveCallback(int callerAdress, int callbackAdress)
\r
354 result r = E_SUCCESS;
\r
356 r = __pCallbackList->Remove(callerAdress, callbackAdress);
\r
357 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
364 _WebManager::IsValidCallback(int callerAdress, int callbackAdress) const
\r
368 result r = __pCallbackList->Contains(callerAdress, callbackAdress, ret);
\r
369 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
\r
376 _WebManager::SetActiveWeb(Tizen::Web::Controls::_WebImpl* pWebAddress)
\r
378 if (__pActiveWeb == null)
\r
380 __pActiveWeb = pWebAddress;
\r
384 if (__pActiveWeb->IsVisible() == true)
\r
388 __pActiveWeb = pWebAddress;
\r
391 if (__pActivePopup != null)
\r
393 __pActivePopup->SetShowState(false);
\r
395 _FormImpl* pFormImpl = __pActiveWeb->GetParentFormImpl(__pActiveWeb);
\r
397 if (pFormImpl != null)
\r
399 __pActivePopup->SetOwner(&pFormImpl->GetPublic());
\r
403 __pActivePopup->SetOwner(&__pActiveWeb->GetPublic());
\r
406 __pActivePopup->SetShowState(true);
\r
407 __pActivePopup->Show();
\r
413 _WebManager::RemoveActiveWeb(Tizen::Web::Controls::_WebImpl* pWebAddress)
\r
415 if (__pActiveWeb == pWebAddress)
\r
417 __pActiveWeb = null;
\r
423 _WebManager::SetActivePopup(Tizen::Web::Controls::_WebPopup* pPopupAddress)
\r
425 __pActivePopup = pPopupAddress;
\r
430 _WebManager::RemoveActivePopup(Tizen::Web::Controls::_WebPopup* pPopupAddress)
\r
432 if (__pActivePopup == pPopupAddress)
\r
434 __pActivePopup = null;
\r