fix gbs/obs build failure
[framework/osp/web.git] / src / controls / FWebCtrlGeolocationPermissionManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FWebCtrlGeolocationPermissionManager.cpp
20  * @brief               The file contains the definition of GeolocationPermissionManager class.
21  *
22  * The file contains the definition of GeolocationPermissionManager class.
23  */
24 #include <unique_ptr.h>
25 #include <FBaseColIList.h>
26 #include <FBaseSysLog.h>
27 #include <FWebCtrlGeolocationPermissionManager.h>
28 #include <FIo_DatabaseImpl.h>
29 #include <FSec_AccessController.h>
30 #include "FWebCtrl_GeolocationPermissionManagerImpl.h"
31
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Security;
36
37
38 namespace Tizen { namespace Web { namespace Controls
39 {
40
41
42 GeolocationPermissionManager* GeolocationPermissionManager::__pInstance = null;
43
44
45 GeolocationPermissionManager::GeolocationPermissionManager(void)
46         : __pGeolocationPermissionManagerImpl(null)
47 {
48 }
49
50
51 GeolocationPermissionManager::~GeolocationPermissionManager(void)
52 {
53         delete __pGeolocationPermissionManagerImpl;
54         __pGeolocationPermissionManagerImpl = null;
55 }
56
57
58 result
59 GeolocationPermissionManager::Construct(void)
60 {
61         result r = E_SUCCESS;
62
63         std::unique_ptr<_GeolocationPermissionManagerImpl> pGeolocationPermissionManagerImpl(new (std::nothrow) _GeolocationPermissionManagerImpl());
64         SysTryReturnResult(NID_WEB_CTRL, pGeolocationPermissionManagerImpl.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
65
66         r = pGeolocationPermissionManagerImpl->Construct();
67         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
68
69         __pGeolocationPermissionManagerImpl = pGeolocationPermissionManagerImpl.release();
70
71         return E_SUCCESS;
72 }
73
74
75 void
76 GeolocationPermissionManager::InitGeolocationPermissionManager(void)
77 {
78         result r = E_SUCCESS;
79
80         std::unique_ptr<GeolocationPermissionManager> pInstance(new (std::nothrow) GeolocationPermissionManager());
81         SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
82
83         r = pInstance->Construct();
84         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
85
86         __pInstance = pInstance.release();
87         std::atexit(DestroyGeolocationPermissionManager);
88 }
89
90
91 void
92 GeolocationPermissionManager::DestroyGeolocationPermissionManager(void)
93 {
94         delete __pInstance;
95         __pInstance = null;
96 }
97
98
99 GeolocationPermissionManager*
100 GeolocationPermissionManager::GetInstance(void)
101 {
102         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
103         if (__pInstance== null)
104         {
105                 ClearLastResult();
106                 pthread_once(&onceBlock, InitGeolocationPermissionManager);
107                 result r = GetLastResult();
108                 if (IsFailed(r))
109                 {
110                         onceBlock = PTHREAD_ONCE_INIT;
111                 }
112         }
113
114         return __pInstance;
115 }
116
117
118 IList*
119 GeolocationPermissionManager::GetOriginListN(void) const
120 {
121         SysAssertf(__pGeolocationPermissionManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
122
123         ClearLastResult();
124         result r = E_SUCCESS;
125
126         r = _AccessController::CheckUserPrivilege(_PRV_GEOLOCATIONPERMISSION_READ);
127         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
128
129         IList* pList = __pGeolocationPermissionManagerImpl->GetOriginListN();
130         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
131
132         return pList;
133 }
134
135
136 bool
137 GeolocationPermissionManager::IsPermissionAllowed(const String& origin) const
138 {
139         SysAssertf(__pGeolocationPermissionManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
140
141         ClearLastResult();
142         result r = E_SUCCESS;
143
144         r = _AccessController::CheckUserPrivilege(_PRV_GEOLOCATIONPERMISSION_READ);
145         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
146
147         bool permission = __pGeolocationPermissionManagerImpl->IsPermissionAllowed(origin);
148         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
149
150         SysLog(NID_WEB_CTRL, "The current value of origin is %ls", origin.GetPointer());
151
152         return permission;
153 }
154
155
156 result
157 GeolocationPermissionManager::Remove(const String& origin)
158 {
159         SysAssertf(__pGeolocationPermissionManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
160
161         ClearLastResult();
162         result r = E_SUCCESS;
163
164         r = _AccessController::CheckUserPrivilege(_PRV_GEOLOCATIONPERMISSION_WRITE);
165         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.",  GetErrorMessage(E_PRIVILEGE_DENIED));
166
167         r = __pGeolocationPermissionManagerImpl->Remove(origin);
168         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
169
170         SysLog(NID_WEB_CTRL, "The current value of origin is %ls", origin.GetPointer());
171
172         return E_SUCCESS;
173 }
174
175
176 result
177 GeolocationPermissionManager::RemoveAll(void)
178 {
179         SysAssertf(__pGeolocationPermissionManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
180
181         ClearLastResult();
182         result r = E_SUCCESS;
183
184         r = _AccessController::CheckUserPrivilege(_PRV_GEOLOCATIONPERMISSION_WRITE);
185         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.",  GetErrorMessage(E_PRIVILEGE_DENIED));
186
187         r =  __pGeolocationPermissionManagerImpl->RemoveAll();
188         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
189
190         return E_SUCCESS;
191 }
192
193
194 }}} // Tizen::Web::Controls