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>
\r
31 #include <FIo_DatabaseImpl.h>
\r
32 #include <FIo_FileImpl.h>
\r
33 #include <FUiCtrl_FormImpl.h>
\r
34 #include <FIo_DirectoryImpl.h>
\r
35 #include <FIo_DatabaseImpl.h>
\r
36 #include <FIo_FileImpl.h>
\r
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/";
\r
57 extern const wchar_t USER_CONFIRM_DB_NAME[] = L"userConfirm.db";
\r
58 extern const wchar_t GEOLOCATION_TABLE_NAME[] = L"geolocationPermission";
\r
59 extern const wchar_t CUSTOM_PROTOCOL_TABLE_NAME[] = L"customProtocol";
\r
60 extern const wchar_t CUSTOM_CONTENT_TABLE_NAME[] = L"customContent";
\r
61 extern const wchar_t CERTIFICATE_TABLE_NAME[] = L"certificate";
\r
64 static const int CUSTOM_DB_TABLE_COUNT= 4;
\r
67 _WebManager::_WebManager(void)
\r
69 , __pCallbackList(null)
\r
70 , __pActivePopupList(null)
\r
71 , __pActiveWeb(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 std::unique_ptr<ArrayListT< int> > pActivePopupList(new (std::nothrow) ArrayListT< int >());
\r
142 SysTryReturnResult(NID_WEB_CTRL, pActivePopupList.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
\r
143 r = pActivePopupList->Construct();
\r
144 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
146 r = InitializeProxyAddress();
\r
147 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
149 r = CreateResourceDirectory();
\r
150 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
152 r = InitializeCustomDb();
\r
153 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
155 __pWebList = std::move(pWebList);
\r
156 __pCallbackList = std::move(pCallbackList);
\r
157 __pActivePopupList = std::move(pActivePopupList);
\r
164 _WebManager::ClearCertificateDb(void)
\r
166 result r = E_SUCCESS;
\r
168 String certificatePath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
\r
169 String table(CERTIFICATE_TABLE_NAME);
\r
172 r = db.Construct(certificatePath, "r+", null);
\r
173 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
\r
175 db.BeginTransaction();
\r
177 r = db.ExecuteSql(L"Delete From " + table, true);
\r
178 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
\r
180 db.CommitTransaction();
\r
185 db.RollbackTransaction();
\r
190 _WebManager::InitializeProxyAddress(void)
\r
193 connection_h handle = null;
\r
194 char* pProxy = null;
\r
196 ret = connection_create(&handle);
\r
197 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to create connection.");
\r
199 connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
\r
201 ret = connection_get_proxy(handle, family, &pProxy);
\r
202 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to get proxy address.");
\r
204 ret = connection_destroy(handle);
\r
205 SysTryReturnResult(NID_WEB_CTRL, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has been occurred. Failed to destroy connection.");
\r
214 _WebManager::CreateResourceDirectory(void) const
\r
216 String html5FeaturesPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH);
\r
218 if (!_FileImpl::IsFileExist(html5FeaturesPath))
\r
220 result r = E_SUCCESS;
\r
222 r = _DirectoryImpl::Create(html5FeaturesPath, true);
\r
223 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. create html5 features directory.");
\r
231 _WebManager::InitializeCustomDb(void) const
\r
233 result r = E_SUCCESS;
\r
236 String path(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
\r
237 String geolocationTable(GEOLOCATION_TABLE_NAME);
\r
238 String protocolTable(CUSTOM_PROTOCOL_TABLE_NAME);
\r
239 String contentTable(CUSTOM_CONTENT_TABLE_NAME);
\r
240 String certificateTable(CERTIFICATE_TABLE_NAME);
\r
242 r = db.Construct(path, "a+", null);
\r
243 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
245 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"')"));
\r
250 r = pEnum->MoveNext();
\r
251 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
\r
253 r = pEnum->GetIntAt(0, count);
\r
254 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
\r
256 if (count == CUSTOM_DB_TABLE_COUNT)
\r
263 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + geolocationTable + L"'"));
\r
267 L"CREATE TABLE IF NOT EXISTS " + geolocationTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT, permission INTEGER)",
\r
269 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
273 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + protocolTable + L"'"));
\r
277 L"CREATE TABLE IF NOT EXISTS " + protocolTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, baseUrl TEXT, url TEXT, mime TEXT, allow INTEGER)",
\r
279 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
283 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + contentTable + L"'"));
\r
287 L"CREATE TABLE IF NOT EXISTS " + contentTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, baseUrl TEXT, url TEXT, mime TEXT, allow INTEGER)",
\r
289 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
293 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + certificateTable + L"'"));
\r
297 L"CREATE TABLE IF NOT EXISTS " + certificateTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, pem TEXT, allow INTEGER)",
\r
299 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
307 _WebManager::AddWeb(int webAdress)
\r
309 result r = E_SUCCESS;
\r
311 _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(webAdress);
\r
312 _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
\r
314 r = pWebCore->GetEflWebkit()->SetProxyAddress(__pProxy);
\r
315 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
317 r = __pWebList->Add(webAdress);
\r
318 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
325 _WebManager::RemoveWeb(int webAdress)
\r
327 result r = E_SUCCESS;
\r
329 r = __pWebList->Remove(webAdress);
\r
330 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
332 __pCallbackList->Remove(webAdress);
\r
339 _WebManager::IsValidWeb(int webAdress) const
\r
341 return __pWebList->Contains(webAdress);
\r
346 _WebManager::AddCallback(int callerAdress, int callbackAdress)
\r
348 result r = E_SUCCESS;
\r
350 r = __pCallbackList->Add(callerAdress, callbackAdress);
\r
351 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
358 _WebManager::RemoveCallback(int callerAdress, int callbackAdress)
\r
360 result r = E_SUCCESS;
\r
362 r = __pCallbackList->Remove(callerAdress, callbackAdress);
\r
363 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
370 _WebManager::IsValidCallback(int callerAdress, int callbackAdress) const
\r
374 result r = __pCallbackList->Contains(callerAdress, callbackAdress, ret);
\r
375 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
\r
382 _WebManager::SetActiveWeb(Tizen::Web::Controls::_WebImpl* pWebAddress)
\r
384 if (__pActiveWeb == null)
\r
386 __pActiveWeb = pWebAddress;
\r
390 if (__pActiveWeb->IsVisible() == true)
\r
394 __pActiveWeb = pWebAddress;
\r
397 for (int i = 0; i < __pActivePopupList->GetCount(); i++)
\r
399 int activePopupAddr = 0;
\r
400 __pActivePopupList->GetAt(i, activePopupAddr);
\r
401 _WebPopup* pActivePopup = reinterpret_cast< _WebPopup* >(activePopupAddr);
\r
403 if (pActivePopup != null)
\r
405 pActivePopup->SetShowState(false);
\r
407 _FormImpl* pFormImpl = __pActiveWeb->GetParentFormImpl(__pActiveWeb);
\r
409 if (pFormImpl != null)
\r
411 pActivePopup->SetOwner(&pFormImpl->GetPublic());
\r
415 pActivePopup->SetOwner(&__pActiveWeb->GetPublic());
\r
418 pActivePopup->SetShowState(true);
\r
419 pActivePopup->Show();
\r
426 _WebManager::RemoveActiveWeb(Tizen::Web::Controls::_WebImpl* pWebAddress)
\r
428 if (__pActiveWeb == pWebAddress)
\r
430 __pActiveWeb = null;
\r
436 _WebManager::SetActivePopup(int popupAddress)
\r
438 result r = E_SUCCESS;
\r
440 r = __pActivePopupList->Add(popupAddress);
\r
441 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r
448 _WebManager::RemoveActivePopup(int popupAddress)
\r
450 result r = E_SUCCESS;
\r
452 r = __pActivePopupList->Remove(popupAddress);
\r
453 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
\r