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 FWebCtrlWebStorageManager.cpp
20 * @brief The file contains the definition of FWebCtrlWebStorageManager class.
22 * The file contains the definition of FWebCtrlWebStorageManager class.
24 #include <unique_ptr.h>
25 #include <FBaseColIList.h>
26 #include <FBaseSysLog.h>
27 #include <FWebCtrlWebStorageManager.h>
28 #include <FSec_AccessController.h>
29 #include "FWebCtrl_WebStorageManagerImpl.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Security;
37 namespace Tizen { namespace Web { namespace Controls
41 WebStorageManager* WebStorageManager::__pInstance = null;
44 WebStorageManager::WebStorageManager(void)
45 : __pWebStorageManagerImpl(null)
49 std::unique_ptr<_WebStorageManagerImpl> pWebStorageManagerImpl(new (std::nothrow) _WebStorageManagerImpl());
50 SysTryReturnVoidResult(NID_WEB_CTRL, pWebStorageManagerImpl.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
52 __pWebStorageManagerImpl = pWebStorageManagerImpl.release();
56 WebStorageManager::~WebStorageManager(void)
62 WebStorageManager::InitWebStorageManager(void)
64 std::unique_ptr<WebStorageManager> pInstance(new (std::nothrow) WebStorageManager());
65 SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
67 __pInstance = pInstance.release();
68 std::atexit(DestroyWebStorageManager);
73 WebStorageManager::DestroyWebStorageManager(void)
81 WebStorageManager::GetInstance(void)
83 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
84 if (__pInstance== null)
87 pthread_once(&onceBlock, InitWebStorageManager);
88 result r = GetLastResult();
91 onceBlock = PTHREAD_ONCE_INIT;
100 WebStorageManager::GetOriginListN(WebStorageType storageType) const
102 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
105 result r = E_SUCCESS;
107 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
108 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));
110 IList* pList = __pWebStorageManagerImpl->GetOriginListN(storageType);
111 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
118 WebStorageManager::SetQuotaForOrigin(WebStorageType storageType, const String& origin, long quota)
120 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
123 result r = E_SUCCESS;
125 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
126 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));
128 r = __pWebStorageManagerImpl->SetQuotaForOrigin(storageType, origin, quota);
129 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
136 WebStorageManager::GetQuotaForOrigin(WebStorageType storageType, const String& origin)
138 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
141 result r = E_SUCCESS;
144 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
145 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, 0, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
147 quota = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin);
148 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
155 WebStorageManager::GetUsageForOrigin(WebStorageType storageType, const String& origin) const
157 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
160 result r = E_SUCCESS;
163 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
164 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, 0, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
166 usage = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin);
167 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
174 WebStorageManager::Remove(WebStorageType storageType, const String& origin)
176 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
179 result r = E_SUCCESS;
181 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
182 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));
184 r = __pWebStorageManagerImpl->Remove(storageType, origin);
185 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
192 WebStorageManager::RemoveAll(WebStorageType storageType)
194 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
197 result r = E_SUCCESS;
199 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
200 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));
202 r = __pWebStorageManagerImpl->RemoveAll(storageType);
203 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
209 }}} // Tizen::Web::Controls