1/* 2 * Copyright (C) 2014 Samsung Electronics 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "config.h" 27#include "ewk_application_cache_manager.h" 28 29#include "WKArray.h" 30#include "ewk_application_cache_manager_private.h" 31#include "ewk_object.h" 32#include "ewk_security_origin_private.h" 33 34using namespace WebKit; 35 36EwkApplicationCacheManager::EwkApplicationCacheManager(WKApplicationCacheManagerRef applicationCacheManager) 37 : m_applicationCacheManager(applicationCacheManager) 38{ 39} 40 41EwkApplicationCacheManager::~EwkApplicationCacheManager() 42{ 43} 44 45struct EwkApplicationCacheOriginsAsyncData { 46 Ewk_Application_Cache_Origins_Async_Get_Cb callback; 47 void* userData; 48 49 EwkApplicationCacheOriginsAsyncData(Ewk_Application_Cache_Origins_Async_Get_Cb callback, void* userData) 50 : callback(callback) 51 , userData(userData) 52 { } 53}; 54 55static void getApplicationCacheOriginsCallback(WKArrayRef wkOrigins, WKErrorRef, void* context) 56{ 57 Eina_List* origins = nullptr; 58 auto callbackData = std::unique_ptr<EwkApplicationCacheOriginsAsyncData>(static_cast<EwkApplicationCacheOriginsAsyncData*>(context)); 59 60 const size_t originsCount = WKArrayGetSize(wkOrigins); 61 for (size_t i = 0; i < originsCount; ++i) { 62 WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(wkOrigins, i)); 63 origins = eina_list_append(origins, EwkSecurityOrigin::create(securityOriginRef).leakRef()); 64 } 65 66 callbackData->callback(origins, callbackData->userData); 67} 68 69void ewk_application_cache_manager_origins_async_get(const Ewk_Application_Cache_Manager* manager, Ewk_Application_Cache_Origins_Async_Get_Cb callback, void* userData) 70{ 71 EINA_SAFETY_ON_NULL_RETURN(manager); 72 EINA_SAFETY_ON_NULL_RETURN(callback); 73 74 EwkApplicationCacheOriginsAsyncData* callbackData = new EwkApplicationCacheOriginsAsyncData(callback, userData); 75 WKApplicationCacheManagerGetApplicationCacheOrigins(manager->impl(), callbackData, getApplicationCacheOriginsCallback); 76} 77 78Eina_Bool ewk_application_cache_manager_clear(Ewk_Application_Cache_Manager* manager) 79{ 80 EINA_SAFETY_ON_NULL_RETURN_VAL(manager, false); 81 82 WKApplicationCacheManagerDeleteAllEntries(manager->impl()); 83 84 return true; 85} 86 87Eina_Bool ewk_application_cache_manager_entries_for_origin_del(Ewk_Application_Cache_Manager* manager, Ewk_Security_Origin* origin) 88{ 89 EINA_SAFETY_ON_NULL_RETURN_VAL(manager, false); 90 EWK_OBJ_GET_IMPL_OR_RETURN(EwkSecurityOrigin, origin, impl, false); 91 92 WKApplicationCacheManagerDeleteEntriesForOrigin(manager->impl(), impl->wkSecurityOrigin()); 93 94 return true; 95} 96