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)
47 std::unique_ptr<_WebStorageManagerImpl> pWebStorageManagerImpl(new (std::nothrow) _WebStorageManagerImpl());
48 SysTryReturnVoidResult(NID_WEB_CTRL, pWebStorageManagerImpl.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
50 __pWebStorageManagerImpl = pWebStorageManagerImpl.release();
54 WebStorageManager::~WebStorageManager(void)
56 delete __pWebStorageManagerImpl;
57 __pWebStorageManagerImpl = null;
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.");
122 result r = E_SUCCESS;
124 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
125 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));
127 r = __pWebStorageManagerImpl->SetQuotaForOrigin(storageType, origin, quota);
128 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
135 WebStorageManager::GetQuotaForOrigin(WebStorageType storageType, const String& origin)
137 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
140 result r = E_SUCCESS;
143 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
144 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));
146 quota = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin);
147 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
154 WebStorageManager::GetUsageForOrigin(WebStorageType storageType, const String& origin) const
156 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
159 result r = E_SUCCESS;
162 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
163 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));
165 usage = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin);
166 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
173 WebStorageManager::Remove(WebStorageType storageType, const String& origin)
175 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
177 result r = E_SUCCESS;
179 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
180 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));
182 r = __pWebStorageManagerImpl->Remove(storageType, origin);
183 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
190 WebStorageManager::RemoveAll(WebStorageType storageType)
192 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
194 result r = E_SUCCESS;
196 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
197 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));
199 r = __pWebStorageManagerImpl->RemoveAll(storageType);
200 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
206 }}} // Tizen::Web::Controls