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 FWebCtrl_WebStorageManagerImpl.cpp
20 * @brief The file contains the definition of _WebStorageManagerImpl class.
23 #include <FBaseColAllElementsDeleter.h>
24 #include <FBaseColArrayList.h>
25 #include <FBaseColIList.h>
26 #include <FBaseSysLog.h>
27 #include "FWebCtrl_Utility.h"
28 #include "FWebCtrl_WebPresenter.h"
29 #include "FWebCtrl_WebStorageManagerImpl.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace Web { namespace Controls
41 OnOriginReceived(Eina_List* pOrigins, void* pUserData)
43 _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
45 pPresenter->EndAsyncProcess(pOrigins);
50 OnIntReceived(int64_t integer, void* pUserData)
52 _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
54 pPresenter->EndAsyncProcess((long)integer);
59 OnUIntReceived(uint64_t integer, void* pUserData)
61 _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
63 pPresenter->EndAsyncProcess((long)integer);
67 _WebStorageManagerImpl::_WebStorageManagerImpl(void)
72 _WebStorageManagerImpl::~_WebStorageManagerImpl(void)
78 _WebStorageManagerImpl::GetOriginListN(WebStorageType storageType)
82 Ewk_Context* pDefaultContext = ewk_context_default_get();
84 std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
85 SysTryReturn(NID_WEB_CTRL, pPresenter.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
89 case WEB_STORAGE_TYPE_APPLICATION_CACHE:
90 ewk_context_application_cache_origins_get(pDefaultContext, OnOriginReceived, pPresenter.get());
93 case WEB_STORAGE_TYPE_WEB_SQL_DATABASE:
94 ewk_context_web_database_origins_get(pDefaultContext, OnOriginReceived, pPresenter.get());
97 case WEB_STORAGE_TYPE_WEB_STORAGE:
98 ewk_context_web_storage_origins_get(pDefaultContext, OnOriginReceived, pPresenter.get());
101 case WEB_STORAGE_TYPE_FILE_SYSTEM:
102 ewk_context_local_file_system_origins_get(pDefaultContext, OnOriginReceived, pPresenter.get());
109 Eina_List* pOriginEinaList = pPresenter->WaitAsyncProcess();
110 if (!pOriginEinaList)
115 std::unique_ptr<ArrayList, AllElementsDeleter> pOriginList(new (std::nothrow) ArrayList());
116 SysTryReturn(NID_WEB_CTRL, pOriginList.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
118 r = pOriginList->Construct();
119 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
121 for (; pOriginEinaList; pOriginEinaList = eina_list_next(pOriginEinaList))
123 Ewk_Security_Origin* pOrigin = static_cast<Ewk_Security_Origin*>(eina_list_data_get(pOriginEinaList));
124 std::unique_ptr<String> pStringOrigin(new (std::nothrow) String(_Utility::CreateOrigin(pOrigin)));
125 SysTryReturn(NID_WEB_CTRL, pStringOrigin.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
127 r = pOriginList->Add(pStringOrigin.get());
128 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
129 pStringOrigin.release();
132 return pOriginList.release();
137 _WebStorageManagerImpl::SetQuotaForOrigin(WebStorageType storageType, const String& origin, long quota)
139 Ewk_Context* pDefaultContext = ewk_context_default_get();
140 Ewk_Security_Origin* pOrigin = null;
144 case WEB_STORAGE_TYPE_APPLICATION_CACHE:
145 pOrigin = CompareOrigin(WEB_STORAGE_TYPE_APPLICATION_CACHE, origin);
146 SysTryReturnResult(NID_WEB_CTRL, pOrigin, E_INVALID_ARG, "This origin does not exist.");
148 ewk_context_application_cache_quota_for_origin_set(pDefaultContext, pOrigin, quota);
151 case WEB_STORAGE_TYPE_WEB_SQL_DATABASE:
152 pOrigin = CompareOrigin(WEB_STORAGE_TYPE_WEB_SQL_DATABASE, origin);
153 SysTryReturnResult(NID_WEB_CTRL, pOrigin, E_INVALID_ARG, "This origin does not exist.");
155 ewk_context_web_database_quota_for_origin_set(pDefaultContext, pOrigin, quota);
159 SysLogException(NID_WEB_CTRL, E_UNSUPPORTED_TYPE, "This storage type %d is not supported.", storageType);
160 return E_UNSUPPORTED_TYPE;
167 _WebStorageManagerImpl::GetQuotaForOrigin(WebStorageType storageType, const String& origin)
169 Ewk_Context* pDefaultContext = ewk_context_default_get();
172 SysTryReturn(NID_WEB_CTRL, storageType == WEB_STORAGE_TYPE_WEB_SQL_DATABASE, -1, E_UNSUPPORTED_TYPE, "[%s] This storage type is not supported.", GetErrorMessage(E_UNSUPPORTED_TYPE));
174 Ewk_Security_Origin* pOrigin = CompareOrigin(storageType, origin);
175 SysTryReturn(NID_WEB_CTRL, pOrigin, -1.0, E_INVALID_ARG, "[%s] This origin does not exist.", GetErrorMessage(E_INVALID_ARG));
177 std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
178 SysTryReturn(NID_WEB_CTRL, pPresenter.get(), -1.0, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
180 ewk_context_web_database_quota_for_origin_get(pDefaultContext, OnUIntReceived, pPresenter.get(), pOrigin);
182 pPresenter->WaitAsyncProcess(quota);
189 _WebStorageManagerImpl::GetUsageForOrigin(WebStorageType storageType, const String& origin)
191 Ewk_Context* pDefaultContext = ewk_context_default_get();
194 SysTryReturn(NID_WEB_CTRL, (storageType != WEB_STORAGE_TYPE_INDEXED_DATABASE) && (storageType != WEB_STORAGE_TYPE_FILE_SYSTEM), -1, E_UNSUPPORTED_TYPE, "[%s] This storage type is not supported.", GetErrorMessage(E_UNSUPPORTED_TYPE));
196 Ewk_Security_Origin* pOrigin = CompareOrigin(storageType, origin);
197 SysTryReturn(NID_WEB_CTRL, pOrigin, -1, E_INVALID_ARG, "[%s] This origin does not exist.", GetErrorMessage(E_INVALID_ARG));
199 std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
200 SysTryReturn(NID_WEB_CTRL, pPresenter.get(), -1.0, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
204 case WEB_STORAGE_TYPE_APPLICATION_CACHE:
205 // ewk_context_application_cache_usage_for_origin_get(pDefaultContext, pOrigin, OnIntReceived, pPresenter.get());
208 case WEB_STORAGE_TYPE_WEB_SQL_DATABASE:
209 ewk_context_web_database_usage_for_origin_get(pDefaultContext, OnUIntReceived, pPresenter.get(), pOrigin);
212 case WEB_STORAGE_TYPE_WEB_STORAGE :
213 ewk_context_web_storage_usage_for_origin_get(pDefaultContext, pOrigin, OnUIntReceived, pPresenter.get());
220 pPresenter->WaitAsyncProcess(usage);
227 _WebStorageManagerImpl::Remove(WebStorageType storageType, const String& origin)
229 Ewk_Context* pDefaultContext = ewk_context_default_get();
231 SysTryReturnResult(NID_WEB_CTRL, storageType != WEB_STORAGE_TYPE_INDEXED_DATABASE, E_UNSUPPORTED_TYPE, "This storage type is not supported.");
233 Ewk_Security_Origin* pOrigin = CompareOrigin(storageType, origin);
234 SysTryReturnResult(NID_WEB_CTRL, pOrigin, E_INVALID_ARG, "This origin does not exist.");
238 case WEB_STORAGE_TYPE_APPLICATION_CACHE:
239 ewk_context_application_cache_delete(pDefaultContext, pOrigin);
242 case WEB_STORAGE_TYPE_WEB_SQL_DATABASE:
243 ewk_context_web_database_delete(pDefaultContext, pOrigin);
246 case WEB_STORAGE_TYPE_WEB_STORAGE :
247 ewk_context_web_storage_origin_delete(pDefaultContext, pOrigin);
250 case WEB_STORAGE_TYPE_FILE_SYSTEM:
251 ewk_context_local_file_system_delete(pDefaultContext, pOrigin);
263 _WebStorageManagerImpl::RemoveAll(WebStorageType storageType)
265 Ewk_Context* pDefaultContext = ewk_context_default_get();
269 case WEB_STORAGE_TYPE_APPLICATION_CACHE:
270 ewk_context_application_cache_delete_all(pDefaultContext);
273 case WEB_STORAGE_TYPE_INDEXED_DATABASE :
274 ewk_context_web_indexed_database_delete_all(pDefaultContext);
277 case WEB_STORAGE_TYPE_WEB_SQL_DATABASE:
278 ewk_context_web_database_delete_all(pDefaultContext);
281 case WEB_STORAGE_TYPE_WEB_STORAGE :
282 ewk_context_web_storage_delete_all(pDefaultContext);
285 case WEB_STORAGE_TYPE_FILE_SYSTEM:
286 ewk_context_local_file_system_all_delete(pDefaultContext);
298 _WebStorageManagerImpl::CompareOrigin(WebStorageType storageType, const String& origin)
300 Ewk_Context* pDefaultContext = ewk_context_default_get();
302 std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
303 SysTryReturn(NID_WEB_CTRL, pPresenter.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
307 case WEB_STORAGE_TYPE_APPLICATION_CACHE:
308 ewk_context_application_cache_origins_get(pDefaultContext, OnOriginReceived, pPresenter.get());
311 case WEB_STORAGE_TYPE_WEB_SQL_DATABASE:
312 ewk_context_web_database_origins_get(pDefaultContext, OnOriginReceived, pPresenter.get());
315 case WEB_STORAGE_TYPE_WEB_STORAGE:
316 ewk_context_web_storage_origins_get(pDefaultContext, OnOriginReceived, pPresenter.get());
319 case WEB_STORAGE_TYPE_FILE_SYSTEM:
320 ewk_context_local_file_system_origins_get(pDefaultContext, OnOriginReceived, pPresenter.get());
327 Eina_List* pOriginList = pPresenter->WaitAsyncProcess();
333 for (; pOriginList; pOriginList = eina_list_next(pOriginList))
335 Ewk_Security_Origin* pOrigin = static_cast<Ewk_Security_Origin*>(eina_list_data_get(pOriginList));
336 SysTryReturn(NID_WEB_CTRL, pOrigin, null, E_INVALID_ARG, "[%s] This origin does not exist.", GetErrorMessage(E_INVALID_ARG));
338 int cmp = origin.CompareTo(_Utility::CreateOrigin(pOrigin));
348 }}} // Tizen::Web::Controls