2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebCtrl_GeolocationPermissionManagerImpl.cpp
20 * @brief The file contains the definition of _GeolocationPermissionManagerImp class.
24 #include <unique_ptr.h>
26 #include <FBaseColIList.h>
27 #include <FBaseSysLog.h>
28 #include <FIoDbEnumerator.h>
29 #include <FWebCtrlGeolocationPermissionManager.h>
30 #include <FIo_DatabaseImpl.h>
31 #include "FWebCtrl_EflWebkit.h"
32 #include "FWebCtrl_GeolocationPermissionManagerImpl.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Io;
40 namespace Tizen { namespace Web { namespace Controls
44 _GeolocationPermissionManagerImpl::_GeolocationPermissionManagerImpl(void)
49 _GeolocationPermissionManagerImpl::~_GeolocationPermissionManagerImpl(void)
55 _GeolocationPermissionManagerImpl::Construct(void)
59 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
61 r = __db.Construct(geolocationPath, "r+", null);
62 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
69 _GeolocationPermissionManagerImpl::GetOriginListN(void) const
73 String table(GEOLOCATION_TABLE_NAME);
74 std::unique_ptr<DbEnumerator> pEnum(__db.QueryN(L"Select origin From " + table));
78 std::unique_ptr<ArrayList> pList(new (std::nothrow) ArrayList());
79 SysTryReturn(NID_WEB_CTRL, pList.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
81 r = pList->Construct();
82 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
84 while (pEnum->MoveNext() == E_SUCCESS)
86 std::unique_ptr<String> origin(new (std::nothrow) String());
87 SysTryReturn(NID_WEB_CTRL, origin.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
88 r = pEnum->GetStringAt(0, *origin.get());
89 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
91 SysLog(NID_WEB_CTRL, "The current value of origin is %ls", origin->GetPointer());
93 r = pList->Add(*origin.get());
94 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
98 return pList.release();
106 _GeolocationPermissionManagerImpl::IsPermissionAllowed(const String& origin) const
108 result r = E_SUCCESS;
110 String table(GEOLOCATION_TABLE_NAME);
112 std::unique_ptr<DbEnumerator> pEnum(__db.QueryN(L"Select permission From " + table + " Where origin = '" + origin + "'"));
115 r = pEnum->MoveNext();
116 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
119 r = pEnum->GetIntAt(0, permission);
120 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
122 return static_cast <bool>(permission);
130 _GeolocationPermissionManagerImpl::Remove(const String& origin)
132 result r = E_SUCCESS;
134 String table(GEOLOCATION_TABLE_NAME);
136 __db.BeginTransaction();
138 r = __db.ExecuteSql(L"Delete From " + table + " Where origin = '" + origin + "'", true);
139 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
141 __db.CommitTransaction();
146 __db.RollbackTransaction();
153 _GeolocationPermissionManagerImpl::RemoveAll(void)
155 result r = E_SUCCESS;
157 String table(GEOLOCATION_TABLE_NAME);
159 __db.BeginTransaction();
161 r = __db.ExecuteSql(L"Delete From " + table, true);
162 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
164 __db.CommitTransaction();
169 __db.RollbackTransaction();
175 _GeolocationPermissionManagerImpl*
176 _GeolocationPermissionManagerImpl::GetInstance(GeolocationPermissionManager* pGeolocationPermissionManager)
178 SysTryReturn(NID_WEB_CTRL, pGeolocationPermissionManager, null, E_INVALID_ARG, "[%s] Invalid argument(s) is used. pGeolocationPermissionManager instance is null" , GetErrorMessage(E_INVALID_ARG));
179 return pGeolocationPermissionManager->__pGeolocationPermissionManagerImpl;
183 const _GeolocationPermissionManagerImpl*
184 _GeolocationPermissionManagerImpl::GetInstance(const GeolocationPermissionManager* pGeolocationPermissionManager)
186 SysTryReturn(NID_WEB_CTRL, pGeolocationPermissionManager, null, E_INVALID_ARG, "[%s] Invalid argument(s) is used. pGeolocationPermissionManager instance is null" , GetErrorMessage(E_INVALID_ARG));
187 return pGeolocationPermissionManager->__pGeolocationPermissionManagerImpl;
191 }}} // Tizen::Web::Controls