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.
25 #include <unique_ptr.h>
26 #include <FBaseColIList.h>
27 #include <FBaseSysLog.h>
28 #include <FWebCtrlWebStorageManager.h>
29 #include <FSec_AccessController.h>
30 #include "FWebCtrl_WebStorageManagerImpl.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Security;
38 namespace Tizen { namespace Web { namespace Controls
42 WebStorageManager* WebStorageManager::__pInstance = null;
45 WebStorageManager::WebStorageManager(void)
46 : __pWebStorageManagerImpl(null)
48 std::unique_ptr<_WebStorageManagerImpl> pWebStorageManagerImpl(new (std::nothrow) _WebStorageManagerImpl());
49 SysTryReturnVoidResult(NID_WEB_CTRL, pWebStorageManagerImpl.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
51 __pWebStorageManagerImpl = pWebStorageManagerImpl.release();
55 WebStorageManager::~WebStorageManager(void)
57 delete __pWebStorageManagerImpl;
58 __pWebStorageManagerImpl = null;
63 WebStorageManager::InitWebStorageManager(void)
65 std::unique_ptr<WebStorageManager> pInstance(new (std::nothrow) WebStorageManager());
66 SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
68 __pInstance = pInstance.release();
69 std::atexit(DestroyWebStorageManager);
74 WebStorageManager::DestroyWebStorageManager(void)
82 WebStorageManager::GetInstance(void)
84 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
85 if (__pInstance== null)
88 pthread_once(&onceBlock, InitWebStorageManager);
89 result r = GetLastResult();
92 onceBlock = PTHREAD_ONCE_INIT;
101 WebStorageManager::GetOriginListN(WebStorageType storageType) const
103 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
106 result r = E_SUCCESS;
108 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
109 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));
111 IList* pList = __pWebStorageManagerImpl->GetOriginListN(storageType);
112 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
119 WebStorageManager::SetQuotaForOrigin(WebStorageType storageType, const String& origin, long quota)
121 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, GetLastResult() == 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, GetLastResult() == 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.");
178 result r = E_SUCCESS;
180 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
181 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));
183 r = __pWebStorageManagerImpl->Remove(storageType, origin);
184 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
191 WebStorageManager::RemoveAll(WebStorageType storageType)
193 SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
195 result r = E_SUCCESS;
197 r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY);
198 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));
200 r = __pWebStorageManagerImpl->RemoveAll(storageType);
201 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
207 }}} // Tizen::Web::Controls