From 3d94e755d7f4283d01316cfc7e0361f9261e7863 Mon Sep 17 00:00:00 2001 From: Hyun Lee Date: Mon, 18 Mar 2013 18:30:24 +0900 Subject: [PATCH] Add Web storage API Change-Id: Ibed57140aa6239fa1176980052940aaa9c07f78a Signed-off-by: Hyun Lee --- CMakeLists.txt | 2 + inc/FWebControls.h | 1 + inc/FWebCtrlWebStorageManager.h | 10 +- src/controls/FWebCtrlWebStorageManager.cpp | 209 +++++++++++++++ src/controls/FWebCtrl_WebPresenter.cpp | 43 +++ src/controls/FWebCtrl_WebPresenter.h | 7 +- src/controls/FWebCtrl_WebStorageManagerImpl.cpp | 340 ++++++++++++++++++++++++ src/controls/FWebCtrl_WebStorageManagerImpl.h | 69 +++++ 8 files changed, 678 insertions(+), 3 deletions(-) create mode 100755 src/controls/FWebCtrlWebStorageManager.cpp create mode 100755 src/controls/FWebCtrl_WebStorageManagerImpl.cpp create mode 100755 src/controls/FWebCtrl_WebStorageManagerImpl.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e31ae6..cf51265 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,8 @@ SET (${this_target}_SOURCE_FILES src/controls/FWebCtrl_UserConfirmPopup.cpp src/controls/FWebCtrl_WebPopup.cpp src/controls/FWebCtrl_CertificatePopup.cpp + src/controls/FWebCtrlWebStorageManager.cpp + src/controls/FWebCtrl_WebStorageManagerImpl.cpp ) ## Add Definitions ADD_DEFINITIONS(${OSP_DEFINITIONS} -D_MODEL_RES_WVGA) diff --git a/inc/FWebControls.h b/inc/FWebControls.h index 6473a43..01ef909 100755 --- a/inc/FWebControls.h +++ b/inc/FWebControls.h @@ -37,6 +37,7 @@ #include #include #include +#include /** * @namespace Tizen::Web::Controls diff --git a/inc/FWebCtrlWebStorageManager.h b/inc/FWebCtrlWebStorageManager.h index a7cf936..5be40a2 100755 --- a/inc/FWebCtrlWebStorageManager.h +++ b/inc/FWebCtrlWebStorageManager.h @@ -24,6 +24,7 @@ #ifndef _FWEB_CTRL_WEB_STORAGE_MANAGER_H_ #define _FWEB_CTRL_WEB_STORAGE_MANAGER_H_ +#include #include namespace Tizen { namespace Base { namespace Collection @@ -102,6 +103,7 @@ public: * @param[in] origin The origin * @param[in] quota The quota of the web storage to set in bytes * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c origin is invalid. * @exception E_UNSUPPORTED_TYPE The specified storageType is not supported. * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. */ @@ -121,10 +123,11 @@ public: * @param[in] storageType The web storage type * @param[in] origin The origin * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c origin is invalid. * @exception E_UNSUPPORTED_TYPE The specified storageType is not supported. * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. */ - long GetQuotaForOrigin(WebStorageType storageType, , const Tizen::Base::String& origin); + long GetQuotaForOrigin(WebStorageType storageType, const Tizen::Base::String& origin); /** * Gets the usage for the given origin for the given storage type. @@ -139,6 +142,7 @@ public: * @param[in] storageType The web storage type * @param[in] origin The origin * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c origin is invalid. * @exception E_UNSUPPORTED_TYPE The specified storageType is not supported. * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. * @remarks The specific error code can be accessed using the GetLastResult() method. @@ -158,6 +162,7 @@ public: * @param[in] storageType The web storage type * @param[in] origin The origin * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c origin is invalid. * @exception E_UNSUPPORTED_TYPE The specified storageType is not supported. * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. * @see RemoveAll() @@ -186,10 +191,11 @@ public: * * @since 2.1 * + * * @return A pointer to the %WebStorageManager instance, @n * else @c null if it fails * @exception E_SUCCESS The method is successful. - * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OUT_OF_MEMORY The memory is insufficient. * @remarks The specific error code can be accessed using the GetLastResult() method. */ static WebStorageManager* GetInstance(void); diff --git a/src/controls/FWebCtrlWebStorageManager.cpp b/src/controls/FWebCtrlWebStorageManager.cpp new file mode 100755 index 0000000..d49eb6e --- /dev/null +++ b/src/controls/FWebCtrlWebStorageManager.cpp @@ -0,0 +1,209 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FWebCtrlWebStorageManager.cpp + * @brief The file contains the definition of FWebCtrlWebStorageManager class. + * + * The file contains the definition of FWebCtrlWebStorageManager class. + */ +#include +#include +#include +#include +#include +#include "FWebCtrl_WebStorageManagerImpl.h" + + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Security; + + +namespace Tizen { namespace Web { namespace Controls +{ + + +WebStorageManager* WebStorageManager::__pInstance = null; + + +WebStorageManager::WebStorageManager(void) + : __pWebStorageManagerImpl(null) +{ + result r = E_SUCCESS; + + std::unique_ptr<_WebStorageManagerImpl> pWebStorageManagerImpl(new (std::nothrow) _WebStorageManagerImpl()); + SysTryReturnVoidResult(NID_WEB_CTRL, pWebStorageManagerImpl.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + + __pWebStorageManagerImpl = pWebStorageManagerImpl.release(); +} + + +WebStorageManager::~WebStorageManager(void) +{ +} + + +void +WebStorageManager::InitWebStorageManager(void) +{ + std::unique_ptr pInstance(new (std::nothrow) WebStorageManager()); + SysTryReturnVoidResult(NID_WEB_CTRL, pInstance.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + + __pInstance = pInstance.release(); + std::atexit(DestroyWebStorageManager); +} + + +void +WebStorageManager::DestroyWebStorageManager(void) +{ + delete __pInstance; + __pInstance = null; +} + + +WebStorageManager* +WebStorageManager::GetInstance(void) +{ + static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; + if (__pInstance== null) + { + ClearLastResult(); + pthread_once(&onceBlock, InitWebStorageManager); + result r = GetLastResult(); + if (IsFailed(r)) + { + onceBlock = PTHREAD_ONCE_INIT; + } + } + + return __pInstance; +} + + +IList* +WebStorageManager::GetOriginListN(WebStorageType storageType) const +{ + SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + ClearLastResult(); + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY); + 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)); + + IList* pList = __pWebStorageManagerImpl->GetOriginListN(storageType); + SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + return pList; +} + + +result +WebStorageManager::SetQuotaForOrigin(WebStorageType storageType, const String& origin, long quota) +{ + SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + ClearLastResult(); + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY); + 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)); + + r = __pWebStorageManagerImpl->SetQuotaForOrigin(storageType, origin, quota); + SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; +} + + +long +WebStorageManager::GetQuotaForOrigin(WebStorageType storageType, const String& origin) +{ + SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + ClearLastResult(); + result r = E_SUCCESS; + long quota = 0; + + r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY); + 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)); + + quota = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin); + SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + return quota; +} + + +long +WebStorageManager::GetUsageForOrigin(WebStorageType storageType, const String& origin) const +{ + SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + ClearLastResult(); + result r = E_SUCCESS; + long usage = 0; + + r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY); + 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)); + + usage = __pWebStorageManagerImpl->GetQuotaForOrigin(storageType, origin); + SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + return usage; +} + + +result +WebStorageManager::Remove(WebStorageType storageType, const String& origin) +{ + SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + ClearLastResult(); + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY); + 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)); + + r = __pWebStorageManagerImpl->Remove(storageType, origin); + SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; +} + + +result +WebStorageManager::RemoveAll(WebStorageType storageType) +{ + SysAssertf(__pWebStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + ClearLastResult(); + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_WEB_PRIVACY); + 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)); + + r = __pWebStorageManagerImpl->RemoveAll(storageType); + SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; +} + + +}}} // Tizen::Web::Controls \ No newline at end of file diff --git a/src/controls/FWebCtrl_WebPresenter.cpp b/src/controls/FWebCtrl_WebPresenter.cpp index 1d189f4..90a2cbf 100755 --- a/src/controls/FWebCtrl_WebPresenter.cpp +++ b/src/controls/FWebCtrl_WebPresenter.cpp @@ -30,15 +30,19 @@ namespace Tizen { namespace Web { namespace Controls { + _WebPresenter::_WebPresenter(void) : __stopState(false) , __boolean(false) , __string(L"") , __integer(0) + , __pIList(null) + , __longInteger(0) { //empty statement } + _WebPresenter::~_WebPresenter(void) { } @@ -70,6 +74,8 @@ _WebPresenter::WaitAsyncProcess(Tizen::Base::String& result) result = __string; } + + void _WebPresenter::WaitAsyncProcess(int& result) { @@ -78,6 +84,25 @@ _WebPresenter::WaitAsyncProcess(int& result) result = __integer; } + +void +_WebPresenter::WaitAsyncProcess(Eina_List* result) +{ + ProcessEvent(); + + result = __pIList; +} + + +void +_WebPresenter::WaitAsyncProcess(long& result) +{ + ProcessEvent(); + + result = __longInteger; +} + + void _WebPresenter::ProcessEvent(void) { @@ -120,4 +145,22 @@ _WebPresenter::EndAsyncProcess(int result) __integer = result; __stopState = true; } + + +void +_WebPresenter::EndAsyncProcess(const Eina_List* result) +{ + __pIList = const_cast(result); + __stopState = true; +} + + +void +_WebPresenter::EndAsyncProcess(long result) +{ + __longInteger = result; + __stopState = true; +} + + }}} // Tizen::Web::Controls diff --git a/src/controls/FWebCtrl_WebPresenter.h b/src/controls/FWebCtrl_WebPresenter.h index e747554..f3c2e93 100755 --- a/src/controls/FWebCtrl_WebPresenter.h +++ b/src/controls/FWebCtrl_WebPresenter.h @@ -45,10 +45,14 @@ public: void WaitAsyncProcess(bool& result); void WaitAsyncProcess(Tizen::Base::String& result); void WaitAsyncProcess(int& result); + void WaitAsyncProcess(Eina_List* result); + void WaitAsyncProcess(long& result); void EndAsyncProcess(bool result); void EndAsyncProcess(const Tizen::Base::String& result); void EndAsyncProcess(int result); + void EndAsyncProcess(const Eina_List* result); + void EndAsyncProcess(long result); private: _WebPresenter(const _WebPresenter& rhs); @@ -61,9 +65,10 @@ private: bool __stopState; bool __boolean; - Tizen::Base::String __string; int __integer; + Eina_List* __pIList; + long __longInteger; }; }}} // Tizen::Web::Controls diff --git a/src/controls/FWebCtrl_WebStorageManagerImpl.cpp b/src/controls/FWebCtrl_WebStorageManagerImpl.cpp new file mode 100755 index 0000000..b464c60 --- /dev/null +++ b/src/controls/FWebCtrl_WebStorageManagerImpl.cpp @@ -0,0 +1,340 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FWebCtrl_WebStorageManagerImpl.cpp + * @brief The file contains the definition of _WebStorageManagerImpl class. + */ +#include +#include +#include +#include +#include "FWebCtrl_Utility.h" +#include "FWebCtrl_WebPresenter.h" +#include "FWebCtrl_WebStorageManagerImpl.h" + + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + + +namespace Tizen { namespace Web { namespace Controls +{ + + +void +OnOriginReceived(Eina_List* pOrigins, void* pUserData) +{ + _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData); + + pPresenter->EndAsyncProcess(pOrigins); +} + + +void +OnIntReceived(int64_t integer, void* pUserData) +{ + _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData); + + + + pPresenter->EndAsyncProcess((long)integer); +} + + +void +OnUIntReceived(uint64_t integer, void* pUserData) +{ + _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData); + + + + pPresenter->EndAsyncProcess((long)integer); +} + + +_WebStorageManagerImpl::_WebStorageManagerImpl(void) +{ +} + + +_WebStorageManagerImpl::~_WebStorageManagerImpl(void) +{ +} + + +IList* +_WebStorageManagerImpl::GetOriginListN(WebStorageType storageType) +{ + Ewk_Context* pDefaultContext = ewk_context_default_get(); + Eina_List* pOriginEinaList; + ArrayList* pOriginList; + _WebPresenter presenter; + presenter.InitAsyncProcess(); + + switch (storageType) + { + case WEB_STORAGE_TYPE_APPLICATION_CACHE: + ewk_context_application_cache_origins_get(pDefaultContext, OnOriginReceived, &presenter); + break; + + case WEB_STORAGE_TYPE_WEB_SQL_DATABASE: + ewk_context_web_database_origins_get(pDefaultContext, OnOriginReceived, &presenter); + break; + + case WEB_STORAGE_TYPE_WEB_STORAGE: + ewk_context_web_storage_origins_get(pDefaultContext, OnOriginReceived, &presenter); + break; + + case WEB_STORAGE_TYPE_FILE_SYSTEM: + ewk_context_local_file_system_origins_get(pDefaultContext, OnOriginReceived, &presenter); + break; + + default: + break; + } + + presenter.WaitAsyncProcess(pOriginEinaList); + + pOriginList = new (std::nothrow) ArrayList(); + pOriginList->Construct(); + + for(; pOriginEinaList; pOriginEinaList = eina_list_next(pOriginEinaList)) + { + Ewk_Security_Origin* pOrigin = static_cast(eina_list_data_get(pOriginEinaList)); + String* pStringOrigin = new (std::nothrow) String(_Utility::CreateOrigin(pOrigin)); + pOriginList->Add(pStringOrigin); + } + + return pOriginList; +} + + +result +_WebStorageManagerImpl::SetQuotaForOrigin(WebStorageType storageType, const String& origin, long quota) +{ + Ewk_Context* pDefaultContext = ewk_context_default_get(); + + SysTryReturnResult(NID_WEB_CTRL, (storageType == WEB_STORAGE_TYPE_WEB_SQL_DATABASE) || (storageType == WEB_STORAGE_TYPE_APPLICATION_CACHE), E_UNSUPPORTED_TYPE, "[%s] This storage type is not supported.", GetErrorMessage(E_UNSUPPORTED_TYPE)); + + Ewk_Security_Origin* pOrigin = CompareOrigin(storageType, origin); + SysTryReturnResult(NID_WEB_CTRL, pOrigin, E_INVALID_ARG, "[%s] This origin does not exist.", GetErrorMessage(E_INVALID_ARG)); + + switch (storageType) + { + case WEB_STORAGE_TYPE_APPLICATION_CACHE: + ewk_context_application_cache_quota_for_origin_set(pDefaultContext, pOrigin, quota); + break; + + case WEB_STORAGE_TYPE_WEB_SQL_DATABASE: + ewk_context_web_database_quota_for_origin_set(pDefaultContext, pOrigin, quota); + break; + + default: + break; + } + return E_SUCCESS; +} + + +long +_WebStorageManagerImpl::GetQuotaForOrigin(WebStorageType storageType, const String& origin) +{ + Ewk_Context* pDefaultContext = ewk_context_default_get(); + long quota = 0; + + SysTryReturn(NID_WEB_CTRL, storageType == WEB_STORAGE_TYPE_WEB_SQL_DATABASE, 0, E_UNSUPPORTED_TYPE, "[%s] This storage type is not supported.", GetErrorMessage(E_UNSUPPORTED_TYPE)); + + Ewk_Security_Origin* pOrigin = CompareOrigin(storageType, origin); + SysTryReturnResult(NID_WEB_CTRL, pOrigin, E_INVALID_ARG, "[%s] This origin does not exist.", GetErrorMessage(E_INVALID_ARG)); + + _WebPresenter presenter; + presenter.InitAsyncProcess(); + + switch (storageType) + { + case WEB_STORAGE_TYPE_APPLICATION_CACHE: + ewk_context_application_cache_usage_for_origin_get(pDefaultContext, pOrigin, OnIntReceived, &presenter); + break; + + case WEB_STORAGE_TYPE_WEB_SQL_DATABASE: + ewk_context_web_database_quota_for_origin_get(pDefaultContext, OnUIntReceived, &presenter, pOrigin); + break; + + default: + break; + } + + presenter.WaitAsyncProcess(quota); + + return quota; +} + + +long +_WebStorageManagerImpl::GetUsageForOrigin(WebStorageType storageType, const String& origin) +{ + Ewk_Context* pDefaultContext = ewk_context_default_get(); + long usage = 0; + + SysTryReturn(NID_WEB_CTRL, (storageType != WEB_STORAGE_TYPE_INDEXED_DATABASE) && (storageType != WEB_STORAGE_TYPE_FILE_SYSTEM), 0, E_UNSUPPORTED_TYPE, "[%s] This storage type is not supported.", GetErrorMessage(E_UNSUPPORTED_TYPE)); + + Ewk_Security_Origin* pOrigin = CompareOrigin(storageType, origin); + SysTryReturnResult(NID_WEB_CTRL, pOrigin, E_INVALID_ARG, "[%s] This origin does not exist.", GetErrorMessage(E_INVALID_ARG)); + + _WebPresenter presenter; + presenter.InitAsyncProcess(); + + switch (storageType) + { + case WEB_STORAGE_TYPE_APPLICATION_CACHE: + //ewk_context_application_cache_usage_for_origin_get(pDefaultContext, pOrigin, OnIntReceived, &presenter); + break; + + case WEB_STORAGE_TYPE_WEB_SQL_DATABASE: + ewk_context_web_database_usage_for_origin_get(pDefaultContext, OnUIntReceived, &presenter, pOrigin); + break; + + case WEB_STORAGE_TYPE_WEB_STORAGE : + ewk_context_web_storage_usage_for_origin_get(pDefaultContext, pOrigin, OnUIntReceived, &presenter); + break; + + default: + break; + } + + presenter.WaitAsyncProcess(usage); + + return usage; +} + + +result +_WebStorageManagerImpl::Remove(WebStorageType storageType, const String& origin) +{ + Ewk_Context* pDefaultContext = ewk_context_default_get(); + + SysTryReturnResult(NID_WEB_CTRL, storageType != WEB_STORAGE_TYPE_INDEXED_DATABASE, E_UNSUPPORTED_TYPE, "[%s] This storage type is not supported.", GetErrorMessage(E_UNSUPPORTED_TYPE)); + + Ewk_Security_Origin* pOrigin = CompareOrigin(storageType, origin); + SysTryReturnResult(NID_WEB_CTRL, pOrigin, E_INVALID_ARG, "[%s] This origin does not exist.", GetErrorMessage(E_INVALID_ARG)); + + switch (storageType) + { + case WEB_STORAGE_TYPE_APPLICATION_CACHE: + ewk_context_application_cache_delete(pDefaultContext, pOrigin); + break; + + case WEB_STORAGE_TYPE_WEB_SQL_DATABASE: + ewk_context_web_database_delete(pDefaultContext, pOrigin); + break; + + case WEB_STORAGE_TYPE_WEB_STORAGE : + ewk_context_web_storage_origin_delete(pDefaultContext, pOrigin); + break; + + case WEB_STORAGE_TYPE_FILE_SYSTEM: + ewk_context_local_file_system_delete(pDefaultContext, pOrigin); + break; + + default: + break; + } + + return E_SUCCESS; +} + + +result +_WebStorageManagerImpl::RemoveAll(WebStorageType storageType) +{ + Ewk_Context* pDefaultContext = ewk_context_default_get(); + + switch (storageType) + { + case WEB_STORAGE_TYPE_APPLICATION_CACHE: + ewk_context_application_cache_delete_all(pDefaultContext); + break; + + case WEB_STORAGE_TYPE_INDEXED_DATABASE : + ewk_context_web_indexed_database_delete_all(pDefaultContext); + break; + + case WEB_STORAGE_TYPE_WEB_SQL_DATABASE: + ewk_context_web_database_delete_all(pDefaultContext); + break; + + case WEB_STORAGE_TYPE_WEB_STORAGE : + ewk_context_web_storage_delete_all(pDefaultContext); + break; + + case WEB_STORAGE_TYPE_FILE_SYSTEM: + ewk_context_local_file_system_all_delete(pDefaultContext); + break; + + default: + break; + } + return E_SUCCESS; +} + + +Ewk_Security_Origin* +_WebStorageManagerImpl::CompareOrigin(WebStorageType storageType, const String& origin) +{ + Ewk_Context* pDefaultContext = ewk_context_default_get(); + _WebPresenter presenter; + Eina_List* pOriginList; + presenter.InitAsyncProcess(); + + switch (storageType) + { + case WEB_STORAGE_TYPE_APPLICATION_CACHE: + ewk_context_application_cache_origins_get(pDefaultContext, OnOriginReceived, &presenter); + break; + + case WEB_STORAGE_TYPE_WEB_SQL_DATABASE: + ewk_context_web_database_origins_get(pDefaultContext, OnOriginReceived, &presenter); + break; + + case WEB_STORAGE_TYPE_WEB_STORAGE: + ewk_context_web_storage_origins_get(pDefaultContext, OnOriginReceived, &presenter); + break; + + case WEB_STORAGE_TYPE_FILE_SYSTEM: + ewk_context_local_file_system_origins_get(pDefaultContext, OnOriginReceived, &presenter); + break; + + default: + break; + } + + presenter.WaitAsyncProcess(pOriginList); + + for(; pOriginList; pOriginList = eina_list_next(pOriginList)) + { + Ewk_Security_Origin* pOrigin = static_cast(eina_list_data_get(pOriginList)); + int cmp = origin.CompareTo(_Utility::CreateOrigin(pOrigin)); + + if (cmp ==0) + { + return pOrigin; + } + } + return null; +} +}}} // Tizen::Web::Controls diff --git a/src/controls/FWebCtrl_WebStorageManagerImpl.h b/src/controls/FWebCtrl_WebStorageManagerImpl.h new file mode 100755 index 0000000..6f917aa --- /dev/null +++ b/src/controls/FWebCtrl_WebStorageManagerImpl.h @@ -0,0 +1,69 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FWebCtrl_WebStorageManagerImpl.h + * @brief The file contains the declaration of _WebStorageManagerImpl class. + * + * The file contains the declaration of _WebStorageManagerImpl class. + */ +#ifndef _FWEB_CTRL_INTERNAL_WEB_STORAGE_MANAGER_IMPL_H_ +#define _FWEB_CTRL_INTERNAL_WEB_STORAGE_MANAGER_IMPL_H_ + +#include +#include +#include + +namespace Tizen { namespace Base { namespace Collection +{ +class IList; +}}} + +namespace Tizen { namespace Web { namespace Controls +{ + +class _WebStorageManagerImpl + : public Tizen::Base::Object +{ +public: + _WebStorageManagerImpl(void); + + virtual ~_WebStorageManagerImpl(void); + + Tizen::Base::Collection::IList* GetOriginListN(WebStorageType storageType); + + result SetQuotaForOrigin(WebStorageType storageType, const Tizen::Base::String& origin, long quota); + + long GetQuotaForOrigin(WebStorageType storageType, const Tizen::Base::String& origin); + + long GetUsageForOrigin(WebStorageType storageType, const Tizen::Base::String& origin); + + result Remove(WebStorageType storageType, const Tizen::Base::String& origin); + + result RemoveAll(WebStorageType storageType); + + Ewk_Security_Origin* CompareOrigin(WebStorageType storageType, const Tizen::Base::String& origin); + +private: + _WebStorageManagerImpl(const _WebStorageManagerImpl& rhs); + + _WebStorageManagerImpl& operator=(const _WebStorageManagerImpl& rhs); + +}; + +}}} // Tizen::Web::Controls +#endif // _FWEB_CTRL_INTERNAL_WEB_STORAGE_MANAGER_IMPL_H_ \ No newline at end of file -- 2.7.4