Home | History | Annotate | Download | only in C
      1 /*
      2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
      3  * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     24  * THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #ifndef WKAPICast_h
     28 #define WKAPICast_h
     29 
     30 #include "CacheModel.h"
     31 #include "FontSmoothingLevel.h"
     32 #include "HTTPCookieAcceptPolicy.h"
     33 #include "ResourceCachesToClear.h"
     34 #include "WKContext.h"
     35 #include "WKCookieManager.h"
     36 #include "WKCredentialTypes.h"
     37 #include "WKPage.h"
     38 #include "WKPreferencesPrivate.h"
     39 #include "WKProtectionSpaceTypes.h"
     40 #include "WKResourceCacheManager.h"
     41 #include "WKSharedAPICast.h"
     42 #include <WebCore/CookieJar.h>
     43 #include <WebCore/Credential.h>
     44 #include <WebCore/FrameLoaderTypes.h>
     45 #include <WebCore/ProtectionSpace.h>
     46 #include <WebCore/Settings.h>
     47 
     48 namespace WebKit {
     49 
     50 class AuthenticationChallengeProxy;
     51 class AuthenticationDecisionListener;
     52 class DownloadProxy;
     53 class GeolocationPermissionRequestProxy;
     54 class WebApplicationCacheManagerProxy;
     55 class WebBackForwardList;
     56 class WebBackForwardListItem;
     57 class WebResourceCacheManagerProxy;
     58 class WebContext;
     59 class WebCookieManagerProxy;
     60 class WebCredential;
     61 class WebDatabaseManagerProxy;
     62 class WebFormSubmissionListenerProxy;
     63 class WebFramePolicyListenerProxy;
     64 class WebFrameProxy;
     65 class WebGeolocationManagerProxy;
     66 class WebGeolocationPosition;
     67 class WebIconDatabase;
     68 class WebInspectorProxy;
     69 class WebKeyValueStorageManagerProxy;
     70 class WebMediaCacheManagerProxy;
     71 class WebNavigationData;
     72 class WebOpenPanelParameters;
     73 class WebOpenPanelResultListenerProxy;
     74 class WebPageGroup;
     75 class WebPageProxy;
     76 class WebPluginSiteDataManager;
     77 class WebPreferences;
     78 class WebProtectionSpace;
     79 
     80 WK_ADD_API_MAPPING(WKApplicationCacheManagerRef, WebApplicationCacheManagerProxy)
     81 WK_ADD_API_MAPPING(WKAuthenticationChallengeRef, AuthenticationChallengeProxy)
     82 WK_ADD_API_MAPPING(WKAuthenticationDecisionListenerRef, AuthenticationDecisionListener)
     83 WK_ADD_API_MAPPING(WKBackForwardListItemRef, WebBackForwardListItem)
     84 WK_ADD_API_MAPPING(WKBackForwardListRef, WebBackForwardList)
     85 WK_ADD_API_MAPPING(WKResourceCacheManagerRef, WebResourceCacheManagerProxy)
     86 WK_ADD_API_MAPPING(WKContextRef, WebContext)
     87 WK_ADD_API_MAPPING(WKCookieManagerRef, WebCookieManagerProxy)
     88 WK_ADD_API_MAPPING(WKCredentialRef, WebCredential)
     89 WK_ADD_API_MAPPING(WKDatabaseManagerRef, WebDatabaseManagerProxy)
     90 WK_ADD_API_MAPPING(WKDownloadRef, DownloadProxy)
     91 WK_ADD_API_MAPPING(WKFormSubmissionListenerRef, WebFormSubmissionListenerProxy)
     92 WK_ADD_API_MAPPING(WKFramePolicyListenerRef, WebFramePolicyListenerProxy)
     93 WK_ADD_API_MAPPING(WKFrameRef, WebFrameProxy)
     94 WK_ADD_API_MAPPING(WKGeolocationManagerRef, WebGeolocationManagerProxy)
     95 WK_ADD_API_MAPPING(WKGeolocationPermissionRequestRef, GeolocationPermissionRequestProxy)
     96 WK_ADD_API_MAPPING(WKGeolocationPositionRef, WebGeolocationPosition)
     97 WK_ADD_API_MAPPING(WKIconDatabaseRef, WebIconDatabase)
     98 WK_ADD_API_MAPPING(WKKeyValueStorageManagerRef, WebKeyValueStorageManagerProxy)
     99 WK_ADD_API_MAPPING(WKMediaCacheManagerRef, WebMediaCacheManagerProxy)
    100 WK_ADD_API_MAPPING(WKNavigationDataRef, WebNavigationData)
    101 WK_ADD_API_MAPPING(WKOpenPanelParametersRef, WebOpenPanelParameters)
    102 WK_ADD_API_MAPPING(WKOpenPanelResultListenerRef, WebOpenPanelResultListenerProxy)
    103 WK_ADD_API_MAPPING(WKPageGroupRef, WebPageGroup)
    104 WK_ADD_API_MAPPING(WKPageRef, WebPageProxy)
    105 WK_ADD_API_MAPPING(WKPluginSiteDataManagerRef, WebPluginSiteDataManager)
    106 WK_ADD_API_MAPPING(WKPreferencesRef, WebPreferences)
    107 WK_ADD_API_MAPPING(WKProtectionSpaceRef, WebProtectionSpace)
    108 
    109 #if ENABLE(INSPECTOR)
    110 WK_ADD_API_MAPPING(WKInspectorRef, WebInspectorProxy)
    111 #endif
    112 
    113 /* Enum conversions */
    114 
    115 inline CacheModel toCacheModel(WKCacheModel wkCacheModel)
    116 {
    117     switch (wkCacheModel) {
    118     case kWKCacheModelDocumentViewer:
    119         return CacheModelDocumentViewer;
    120     case kWKCacheModelDocumentBrowser:
    121         return CacheModelDocumentBrowser;
    122     case kWKCacheModelPrimaryWebBrowser:
    123         return CacheModelPrimaryWebBrowser;
    124     }
    125 
    126     ASSERT_NOT_REACHED();
    127     return CacheModelDocumentViewer;
    128 }
    129 
    130 inline WKCacheModel toAPI(CacheModel cacheModel)
    131 {
    132     switch (cacheModel) {
    133     case CacheModelDocumentViewer:
    134         return kWKCacheModelDocumentViewer;
    135     case CacheModelDocumentBrowser:
    136         return kWKCacheModelDocumentBrowser;
    137     case CacheModelPrimaryWebBrowser:
    138         return kWKCacheModelPrimaryWebBrowser;
    139     }
    140 
    141     return kWKCacheModelDocumentViewer;
    142 }
    143 
    144 inline FontSmoothingLevel toFontSmoothingLevel(WKFontSmoothingLevel wkLevel)
    145 {
    146     switch (wkLevel) {
    147     case kWKFontSmoothingLevelNoSubpixelAntiAliasing:
    148         return FontSmoothingLevelNoSubpixelAntiAliasing;
    149     case kWKFontSmoothingLevelLight:
    150         return FontSmoothingLevelLight;
    151     case kWKFontSmoothingLevelMedium:
    152         return FontSmoothingLevelMedium;
    153     case kWKFontSmoothingLevelStrong:
    154         return FontSmoothingLevelStrong;
    155 #if PLATFORM(WIN)
    156     case kWKFontSmoothingLevelWindows:
    157         return FontSmoothingLevelWindows;
    158 #endif
    159     }
    160 
    161     ASSERT_NOT_REACHED();
    162     return FontSmoothingLevelMedium;
    163 }
    164 
    165 
    166 inline WKFontSmoothingLevel toAPI(FontSmoothingLevel level)
    167 {
    168     switch (level) {
    169     case FontSmoothingLevelNoSubpixelAntiAliasing:
    170         return kWKFontSmoothingLevelNoSubpixelAntiAliasing;
    171     case FontSmoothingLevelLight:
    172         return kWKFontSmoothingLevelLight;
    173     case FontSmoothingLevelMedium:
    174         return kWKFontSmoothingLevelMedium;
    175     case FontSmoothingLevelStrong:
    176         return kWKFontSmoothingLevelStrong;
    177 #if PLATFORM(WIN)
    178     case FontSmoothingLevelWindows:
    179         return kWKFontSmoothingLevelWindows;
    180 #endif
    181     }
    182 
    183     ASSERT_NOT_REACHED();
    184     return kWKFontSmoothingLevelMedium;
    185 }
    186 
    187 inline WKEditableLinkBehavior toAPI(WebCore::EditableLinkBehavior behavior)
    188 {
    189     switch (behavior) {
    190     case WebCore::EditableLinkDefaultBehavior:
    191         return kWKEditableLinkBehaviorDefault;
    192     case WebCore::EditableLinkAlwaysLive:
    193         return kWKEditableLinkBehaviorAlwaysLive;
    194     case WebCore::EditableLinkOnlyLiveWithShiftKey:
    195         return kWKEditableLinkBehaviorOnlyLiveWithShiftKey;
    196     case WebCore::EditableLinkLiveWhenNotFocused:
    197         return kWKEditableLinkBehaviorLiveWhenNotFocused;
    198     case WebCore::EditableLinkNeverLive:
    199         return kWKEditableLinkBehaviorNeverLive;
    200     }
    201 
    202     ASSERT_NOT_REACHED();
    203     return kWKEditableLinkBehaviorNeverLive;
    204 }
    205 
    206 inline WebCore::EditableLinkBehavior toEditableLinkBehavior(WKEditableLinkBehavior wkBehavior)
    207 {
    208     switch (wkBehavior) {
    209     case kWKEditableLinkBehaviorDefault:
    210         return WebCore::EditableLinkDefaultBehavior;
    211     case kWKEditableLinkBehaviorAlwaysLive:
    212         return WebCore::EditableLinkAlwaysLive;
    213     case kWKEditableLinkBehaviorOnlyLiveWithShiftKey:
    214         return WebCore::EditableLinkOnlyLiveWithShiftKey;
    215     case kWKEditableLinkBehaviorLiveWhenNotFocused:
    216         return WebCore::EditableLinkLiveWhenNotFocused;
    217     case kWKEditableLinkBehaviorNeverLive:
    218         return WebCore::EditableLinkNeverLive;
    219     }
    220 
    221     ASSERT_NOT_REACHED();
    222     return WebCore::EditableLinkNeverLive;
    223 }
    224 
    225 inline WKProtectionSpaceServerType toAPI(WebCore::ProtectionSpaceServerType type)
    226 {
    227     switch (type) {
    228     case WebCore::ProtectionSpaceServerHTTP:
    229         return kWKProtectionSpaceServerTypeHTTP;
    230     case WebCore::ProtectionSpaceServerHTTPS:
    231         return kWKProtectionSpaceServerTypeHTTPS;
    232     case WebCore::ProtectionSpaceServerFTP:
    233         return kWKProtectionSpaceServerTypeFTP;
    234     case WebCore::ProtectionSpaceServerFTPS:
    235         return kWKProtectionSpaceServerTypeFTPS;
    236     case WebCore::ProtectionSpaceProxyHTTP:
    237         return kWKProtectionSpaceProxyTypeHTTP;
    238     case WebCore::ProtectionSpaceProxyHTTPS:
    239         return kWKProtectionSpaceProxyTypeHTTPS;
    240     case WebCore::ProtectionSpaceProxyFTP:
    241         return kWKProtectionSpaceProxyTypeFTP;
    242     case WebCore::ProtectionSpaceProxySOCKS:
    243         return kWKProtectionSpaceProxyTypeSOCKS;
    244     }
    245     return kWKProtectionSpaceServerTypeHTTP;
    246 }
    247 
    248 inline WKProtectionSpaceAuthenticationScheme toAPI(WebCore::ProtectionSpaceAuthenticationScheme type)
    249 {
    250     switch (type) {
    251     case WebCore::ProtectionSpaceAuthenticationSchemeDefault:
    252         return kWKProtectionSpaceAuthenticationSchemeDefault;
    253     case WebCore::ProtectionSpaceAuthenticationSchemeHTTPBasic:
    254         return kWKProtectionSpaceAuthenticationSchemeHTTPBasic;
    255     case WebCore::ProtectionSpaceAuthenticationSchemeHTTPDigest:
    256         return kWKProtectionSpaceAuthenticationSchemeHTTPDigest;
    257     case WebCore::ProtectionSpaceAuthenticationSchemeHTMLForm:
    258         return kWKProtectionSpaceAuthenticationSchemeHTMLForm;
    259     case WebCore::ProtectionSpaceAuthenticationSchemeNTLM:
    260         return kWKProtectionSpaceAuthenticationSchemeNTLM;
    261     case WebCore::ProtectionSpaceAuthenticationSchemeNegotiate:
    262         return kWKProtectionSpaceAuthenticationSchemeNegotiate;
    263     case WebCore::ProtectionSpaceAuthenticationSchemeClientCertificateRequested:
    264         return kWKProtectionSpaceAuthenticationSchemeClientCertificateRequested;
    265     case WebCore::ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested:
    266         return kWKProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested;
    267     default:
    268         return kWKProtectionSpaceAuthenticationSchemeUnknown;
    269     }
    270 }
    271 
    272 inline WebCore::CredentialPersistence toCredentialPersistence(WKCredentialPersistence type)
    273 {
    274     switch (type) {
    275     case kWKCredentialPersistenceNone:
    276         return WebCore::CredentialPersistenceNone;
    277     case kWKCredentialPersistenceForSession:
    278         return WebCore::CredentialPersistenceForSession;
    279     case kWKCredentialPersistencePermanent:
    280         return WebCore::CredentialPersistencePermanent;
    281     default:
    282         return WebCore::CredentialPersistenceNone;
    283     }
    284 }
    285 
    286 inline ResourceCachesToClear toResourceCachesToClear(WKResourceCachesToClear wkResourceCachesToClear)
    287 {
    288     switch (wkResourceCachesToClear) {
    289     case WKResourceCachesToClearAll:
    290         return AllResourceCaches;
    291     case WKResourceCachesToClearInMemoryOnly:
    292         return InMemoryResourceCachesOnly;
    293     }
    294 
    295     ASSERT_NOT_REACHED();
    296     return AllResourceCaches;
    297 }
    298 
    299 inline HTTPCookieAcceptPolicy toHTTPCookieAcceptPolicy(WKHTTPCookieAcceptPolicy policy)
    300 {
    301     switch (policy) {
    302     case kWKHTTPCookieAcceptPolicyAlways:
    303         return HTTPCookieAcceptPolicyAlways;
    304     case kWKHTTPCookieAcceptPolicyNever:
    305         return HTTPCookieAcceptPolicyNever;
    306     case kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain:
    307         return HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
    308     }
    309 
    310     ASSERT_NOT_REACHED();
    311     return HTTPCookieAcceptPolicyAlways;
    312 }
    313 
    314 inline WKHTTPCookieAcceptPolicy toAPI(HTTPCookieAcceptPolicy policy)
    315 {
    316     switch (policy) {
    317     case HTTPCookieAcceptPolicyAlways:
    318         return kWKHTTPCookieAcceptPolicyAlways;
    319     case HTTPCookieAcceptPolicyNever:
    320         return kWKHTTPCookieAcceptPolicyNever;
    321     case HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain:
    322         return kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
    323     }
    324 
    325     ASSERT_NOT_REACHED();
    326     return kWKHTTPCookieAcceptPolicyAlways;
    327 }
    328 
    329 } // namespace WebKit
    330 
    331 #if defined(WIN32) || defined(_WIN32)
    332 #include "WKAPICastWin.h"
    333 #endif
    334 
    335 #if defined(BUILDING_GTK__)
    336 #include "WKAPICastGtk.h"
    337 #endif
    338 #endif // WKAPICast_h
    339