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;
61 WebStorageManager::InitWebStorageManager(void)
63 std::unique_ptr<WebStorageManager> pInstance(new (std::nothrow) WebStorageManager());
64 SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
66 __pInstance = pInstance.release();
67 std::atexit(DestroyWebStorageManager);
72 WebStorageManager::DestroyWebStorageManager(void)
80 WebStorageManager::GetInstance(void)
82 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
83 if (__pInstance== null)
86 pthread_once(&onceBlock, InitWebStorageManager);
87 result r = GetLastResult();
90 onceBlock = PTHREAD_ONCE_INIT;
99 WebStorageManager::GetOriginListN(WebStorageType storageType) const
101 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
104 result r = E_SUCCESS;
106 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
107 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));
109 IList* pList = __pWebStorageManagerImpl->GetOriginListN(storageType);
110 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
117 WebStorageManager::SetQuotaForOrigin(WebStorageType storageType, const String& origin, long quota)
119 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
121 result r = E_SUCCESS;
123 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
124 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));
126 r = __pWebStorageManagerImpl->SetQuotaForOrigin(storageType, origin, quota);
127 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
134 WebStorageManager::GetQuotaForOrigin(WebStorageType storageType, const String& origin)
136 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
139 result r = E_SUCCESS;
142 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
143 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));
145 quota = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin);
146 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
153 WebStorageManager::GetUsageForOrigin(WebStorageType storageType, const String& origin) const
155 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
158 result r = E_SUCCESS;
161 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
162 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));
164 usage = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin);
165 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
172 WebStorageManager::Remove(WebStorageType storageType, const String& origin)
174 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
176 result r = E_SUCCESS;
178 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
179 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));
181 r = __pWebStorageManagerImpl->Remove(storageType, origin);
182 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
189 WebStorageManager::RemoveAll(WebStorageType storageType)
191 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
193 result r = E_SUCCESS;
195 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
196 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));
198 r = __pWebStorageManagerImpl->RemoveAll(storageType);
199 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
205 }}} // Tizen::Web::Controls