Home | History | Annotate | Download | only in C
      1 /*
      2  * Copyright (C) 2010, 2011 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 "WKContext.h"
     28 #include "WKContextPrivate.h"
     29 
     30 #include "WKAPICast.h"
     31 #include "WebContext.h"
     32 #include "WebURLRequest.h"
     33 #include <wtf/PassRefPtr.h>
     34 #include <wtf/RefPtr.h>
     35 #include <wtf/text/WTFString.h>
     36 
     37 using namespace WebKit;
     38 
     39 WKTypeID WKContextGetTypeID()
     40 {
     41     return toAPI(WebContext::APIType);
     42 }
     43 
     44 WKContextRef WKContextCreate()
     45 {
     46     RefPtr<WebContext> context = WebContext::create(String());
     47     return toAPI(context.release().releaseRef());
     48 }
     49 
     50 WKContextRef WKContextCreateWithInjectedBundlePath(WKStringRef pathRef)
     51 {
     52     RefPtr<WebContext> context = WebContext::create(toImpl(pathRef)->string());
     53     return toAPI(context.release().releaseRef());
     54 }
     55 
     56 WKContextRef WKContextGetSharedProcessContext()
     57 {
     58     return toAPI(WebContext::sharedProcessContext());
     59 }
     60 
     61 WKContextRef WKContextGetSharedThreadContext()
     62 {
     63     return toAPI(WebContext::sharedThreadContext());
     64 }
     65 
     66 void WKContextSetInjectedBundleClient(WKContextRef contextRef, const WKContextInjectedBundleClient* wkClient)
     67 {
     68     if (wkClient && wkClient->version)
     69         return;
     70     toImpl(contextRef)->initializeInjectedBundleClient(wkClient);
     71 }
     72 
     73 void WKContextSetHistoryClient(WKContextRef contextRef, const WKContextHistoryClient* wkClient)
     74 {
     75     if (wkClient && wkClient->version)
     76         return;
     77     toImpl(contextRef)->initializeHistoryClient(wkClient);
     78 }
     79 
     80 void WKContextSetDownloadClient(WKContextRef contextRef, const WKContextDownloadClient* wkClient)
     81 {
     82     if (wkClient && wkClient->version)
     83         return;
     84     toImpl(contextRef)->initializeDownloadClient(wkClient);
     85 }
     86 
     87 WKDownloadRef WKContextDownloadURLRequest(WKContextRef contextRef, const WKURLRequestRef requestRef)
     88 {
     89     return toAPI(toImpl(contextRef)->download(0, toImpl(requestRef)->resourceRequest()));
     90 }
     91 
     92 void WKContextSetInitializationUserDataForInjectedBundle(WKContextRef contextRef,  WKTypeRef userDataRef)
     93 {
     94     toImpl(contextRef)->setInjectedBundleInitializationUserData(toImpl(userDataRef));
     95 }
     96 
     97 void WKContextPostMessageToInjectedBundle(WKContextRef contextRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
     98 {
     99     toImpl(contextRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
    100 }
    101 
    102 void WKContextGetGlobalStatistics(WKContextStatistics* statistics)
    103 {
    104     const WebContext::Statistics& webContextStatistics = WebContext::statistics();
    105 
    106     statistics->wkViewCount = webContextStatistics.wkViewCount;
    107     statistics->wkPageCount = webContextStatistics.wkPageCount;
    108     statistics->wkFrameCount = webContextStatistics.wkViewCount;
    109 }
    110 
    111 void WKContextAddVisitedLink(WKContextRef contextRef, WKStringRef visitedURL)
    112 {
    113     toImpl(contextRef)->addVisitedLink(toImpl(visitedURL)->string());
    114 }
    115 
    116 void WKContextSetCacheModel(WKContextRef contextRef, WKCacheModel cacheModel)
    117 {
    118     toImpl(contextRef)->setCacheModel(toCacheModel(cacheModel));
    119 }
    120 
    121 WKCacheModel WKContextGetCacheModel(WKContextRef contextRef)
    122 {
    123     return toAPI(toImpl(contextRef)->cacheModel());
    124 }
    125 
    126 void _WKContextSetAlwaysUsesComplexTextCodePath(WKContextRef contextRef, bool alwaysUseComplexTextCodePath)
    127 {
    128     toImpl(contextRef)->setAlwaysUsesComplexTextCodePath(alwaysUseComplexTextCodePath);
    129 }
    130 
    131 void _WKContextSetAdditionalPluginsDirectory(WKContextRef contextRef, WKStringRef pluginsDirectory)
    132 {
    133     toImpl(contextRef)->setAdditionalPluginsDirectory(toImpl(pluginsDirectory)->string());
    134 }
    135 
    136 void _WKContextRegisterURLSchemeAsEmptyDocument(WKContextRef contextRef, WKStringRef urlScheme)
    137 {
    138     toImpl(contextRef)->registerURLSchemeAsEmptyDocument(toImpl(urlScheme)->string());
    139 }
    140 
    141 void WKContextRegisterURLSchemeAsSecure(WKContextRef contextRef, WKStringRef urlScheme)
    142 {
    143     toImpl(contextRef)->registerURLSchemeAsSecure(toImpl(urlScheme)->string());
    144 }
    145 
    146 void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef contextRef, WKStringRef urlScheme)
    147 {
    148     toImpl(contextRef)->setDomainRelaxationForbiddenForURLScheme(toImpl(urlScheme)->string());
    149 }
    150 
    151 WKCookieManagerRef WKContextGetCookieManager(WKContextRef contextRef)
    152 {
    153     return toAPI(toImpl(contextRef)->cookieManagerProxy());
    154 }
    155 
    156 WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef contextRef)
    157 {
    158     return toAPI(toImpl(contextRef)->applicationCacheManagerProxy());
    159 }
    160 
    161 WKDatabaseManagerRef WKContextGetDatabaseManager(WKContextRef contextRef)
    162 {
    163     return toAPI(toImpl(contextRef)->databaseManagerProxy());
    164 }
    165 
    166 WKGeolocationManagerRef WKContextGetGeolocationManager(WKContextRef contextRef)
    167 {
    168     return toAPI(toImpl(contextRef)->geolocationManagerProxy());
    169 }
    170 
    171 WKIconDatabaseRef WKContextGetIconDatabase(WKContextRef contextRef)
    172 {
    173     return toAPI(toImpl(contextRef)->iconDatabase());
    174 }
    175 
    176 WKKeyValueStorageManagerRef WKContextGetKeyValueStorageManager(WKContextRef contextRef)
    177 {
    178     return toAPI(toImpl(contextRef)->keyValueStorageManagerProxy());
    179 }
    180 
    181 WKMediaCacheManagerRef WKContextGetMediaCacheManager(WKContextRef contextRef)
    182 {
    183     return toAPI(toImpl(contextRef)->mediaCacheManagerProxy());
    184 }
    185 
    186 WKPluginSiteDataManagerRef WKContextGetPluginSiteDataManager(WKContextRef contextRef)
    187 {
    188     return toAPI(toImpl(contextRef)->pluginSiteDataManager());
    189 }
    190 
    191 WKResourceCacheManagerRef WKContextGetResourceCacheManager(WKContextRef contextRef)
    192 {
    193     return toAPI(toImpl(contextRef)->resourceCacheManagerProxy());
    194 }
    195 
    196 void WKContextStartMemorySampler(WKContextRef contextRef, WKDoubleRef interval)
    197 {
    198     toImpl(contextRef)->startMemorySampler(toImpl(interval)->value());
    199 }
    200 
    201 void WKContextStopMemorySampler(WKContextRef contextRef)
    202 {
    203     toImpl(contextRef)->stopMemorySampler();
    204 }
    205 
    206 void WKContextSetIconDatabasePath(WKContextRef contextRef, WKStringRef iconDatabasePath)
    207 {
    208     toImpl(contextRef)->setIconDatabasePath(toImpl(iconDatabasePath)->string());
    209 }
    210 
    211 void WKContextSetDatabaseDirectory(WKContextRef contextRef, WKStringRef databaseDirectory)
    212 {
    213     toImpl(contextRef)->setDatabaseDirectory(toImpl(databaseDirectory)->string());
    214 }
    215 
    216 void WKContextSetLocalStorageDirectory(WKContextRef contextRef, WKStringRef localStorageDirectory)
    217 {
    218     toImpl(contextRef)->setLocalStorageDirectory(toImpl(localStorageDirectory)->string());
    219 }
    220 
    221 void WKContextDisableProcessTermination(WKContextRef contextRef)
    222 {
    223     toImpl(contextRef)->disableProcessTermination();
    224 }
    225 
    226 void WKContextEnableProcessTermination(WKContextRef contextRef)
    227 {
    228     toImpl(contextRef)->enableProcessTermination();
    229 }
    230 
    231 void _WKContextSetHTTPPipeliningEnabled(WKContextRef contextRef, bool enabled)
    232 {
    233     toImpl(contextRef)->setHTTPPipeliningEnabled(enabled);
    234 }
    235