Home | History | Annotate | Download | only in C
      1 /*
      2  * Copyright (C) 2010 Apple Inc. All rights reserved.
      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 "WKDatabaseManager.h"
     28 
     29 #include "WebDatabaseManagerProxy.h"
     30 #include "WKAPICast.h"
     31 
     32 #ifdef __BLOCKS__
     33 #include <Block.h>
     34 #endif
     35 
     36 using namespace WebKit;
     37 
     38 WKTypeID WKDatabaseManagerGetTypeID()
     39 {
     40     return toAPI(WebDatabaseManagerProxy::APIType);
     41 }
     42 
     43 WKStringRef WKDatabaseManagerGetOriginKey()
     44 {
     45     static WebString* key = WebString::create(WebDatabaseManagerProxy::originKey()).releaseRef();
     46     return toAPI(key);
     47 }
     48 
     49 WKStringRef WKDatabaseManagerGetOriginQuotaKey()
     50 {
     51     static WebString* key = WebString::create(WebDatabaseManagerProxy::originQuotaKey()).releaseRef();
     52     return toAPI(key);
     53 }
     54 
     55 WKStringRef WKDatabaseManagerGetOriginUsageKey()
     56 {
     57     static WebString* key = WebString::create(WebDatabaseManagerProxy::originUsageKey()).releaseRef();
     58     return toAPI(key);
     59 }
     60 
     61 WKStringRef WKDatabaseManagerGetDatabaseDetailsKey()
     62 {
     63     static WebString* key = WebString::create(WebDatabaseManagerProxy::databaseDetailsKey()).releaseRef();
     64     return toAPI(key);
     65 }
     66 
     67 WKStringRef WKDatabaseManagerGetDatabaseDetailsNameKey()
     68 {
     69     static WebString* key = WebString::create(WebDatabaseManagerProxy::databaseDetailsNameKey()).releaseRef();
     70     return toAPI(key);
     71 }
     72 
     73 WKStringRef WKDatabaseManagerGetDatabaseDetailsDisplayNameKey()
     74 {
     75     static WebString* key = WebString::create(WebDatabaseManagerProxy::databaseDetailsDisplayNameKey()).releaseRef();
     76     return toAPI(key);
     77 }
     78 
     79 WKStringRef WKDatabaseManagerGetDatabaseDetailsExpectedUsageKey()
     80 {
     81     static WebString* key = WebString::create(WebDatabaseManagerProxy::databaseDetailsExpectedUsageKey()).releaseRef();
     82     return toAPI(key);
     83 }
     84 
     85 WKStringRef WKDatabaseManagerGetDatabaseDetailsCurrentUsageKey()
     86 {
     87     static WebString* key = WebString::create(WebDatabaseManagerProxy::databaseDetailsCurrentUsageKey()).releaseRef();
     88     return toAPI(key);
     89 }
     90 
     91 void WKDatabaseManagerSetClient(WKDatabaseManagerRef databaseManagerRef, const WKDatabaseManagerClient* wkClient)
     92 {
     93     if (wkClient && wkClient->version)
     94         return;
     95     toImpl(databaseManagerRef)->initializeClient(wkClient);
     96 }
     97 
     98 void WKDatabaseManagerGetDatabasesByOrigin(WKDatabaseManagerRef databaseManagerRef, void* context, WKDatabaseManagerGetDatabasesByOriginFunction callback)
     99 {
    100     toImpl(databaseManagerRef)->getDatabasesByOrigin(ArrayCallback::create(context, callback));
    101 }
    102 
    103 #ifdef __BLOCKS__
    104 static void callGetDatabasesByOriginBlockAndDispose(WKArrayRef resultValue, WKErrorRef errorRef, void* context)
    105 {
    106     WKDatabaseManagerGetDatabasesByOriginBlock block = (WKDatabaseManagerGetDatabasesByOriginBlock)context;
    107     block(resultValue, errorRef);
    108     Block_release(block);
    109 }
    110 
    111 void WKDatabaseManagerGetDatabasesByOrigin_b(WKDatabaseManagerRef databaseManagerRef, WKDatabaseManagerGetDatabasesByOriginBlock block)
    112 {
    113     WKDatabaseManagerGetDatabasesByOrigin(databaseManagerRef, Block_copy(block), callGetDatabasesByOriginBlockAndDispose);
    114 }
    115 #endif
    116 
    117 void WKDatabaseManagerGetDatabaseOrigins(WKDatabaseManagerRef databaseManagerRef, void* context, WKDatabaseManagerGetDatabaseOriginsFunction callback)
    118 {
    119     toImpl(databaseManagerRef)->getDatabaseOrigins(ArrayCallback::create(context, callback));
    120 }
    121 
    122 #ifdef __BLOCKS__
    123 static void callGetDatabaseOriginsBlockBlockAndDispose(WKArrayRef resultValue, WKErrorRef errorRef, void* context)
    124 {
    125     WKDatabaseManagerGetDatabaseOriginsBlock block = (WKDatabaseManagerGetDatabaseOriginsBlock)context;
    126     block(resultValue, errorRef);
    127     Block_release(block);
    128 }
    129 
    130 void WKDatabaseManagerGetDatabaseOrigins_b(WKDatabaseManagerRef databaseManagerRef, WKDatabaseManagerGetDatabaseOriginsBlock block)
    131 {
    132     WKDatabaseManagerGetDatabaseOrigins(databaseManagerRef, Block_copy(block), callGetDatabaseOriginsBlockBlockAndDispose);
    133 }
    134 #endif
    135 
    136 void WKDatabaseManagerDeleteDatabasesWithNameForOrigin(WKDatabaseManagerRef databaseManagerRef, WKStringRef databaseNameRef, WKSecurityOriginRef originRef)
    137 {
    138     toImpl(databaseManagerRef)->deleteDatabaseWithNameForOrigin(toWTFString(databaseNameRef), toImpl(originRef));
    139 }
    140 
    141 void WKDatabaseManagerDeleteDatabasesForOrigin(WKDatabaseManagerRef databaseManagerRef, WKSecurityOriginRef originRef)
    142 {
    143     toImpl(databaseManagerRef)->deleteDatabasesForOrigin(toImpl(originRef));
    144 }
    145 
    146 void WKDatabaseManagerDeleteAllDatabases(WKDatabaseManagerRef databaseManagerRef)
    147 {
    148     toImpl(databaseManagerRef)->deleteAllDatabases();
    149 }
    150 
    151 void WKDatabaseManagerSetQuotaForOrigin(WKDatabaseManagerRef databaseManagerRef, WKSecurityOriginRef originRef, uint64_t quota)
    152 {
    153     toImpl(databaseManagerRef)->setQuotaForOrigin(toImpl(originRef), quota);
    154 }
    155