Changeset 166186 in webkit


Ignore:
Timestamp:
Mar 24, 2014 12:44:35 PM (10 years ago)
Author:
aestes@apple.com
Message:

[iOS] Download support by CFURLDownloadRef under USE(CFNETWORK).
https://bugs.webkit.org/show_bug.cgi?id=129322

Reviewed by Anders Carlsson.

Source/WebCore:

  • platform/network/ResourceHandle.h:
  • platform/network/cf/ResourceHandleCFNet.cpp:

(WebCore::ResourceHandle::releaseConnectionForDownload): Changed to
return a RetainPtr that adopts the connection's retain count.

Source/WebKit/mac:

  • WebCoreSupport/WebFrameLoaderClient.mm:

(WebFrameLoaderClient::convertMainResourceLoadToDownload): Use the
RetainPtr returned by releaseConnectionForDownload() rather than
manually releasing.

Source/WebKit2:

Based on an original patch by Yongjun Zhang <yongjun_zhang@apple.com>.

  • Shared/Cocoa/APIObject.mm:

(API::Object::newObject):

  • Shared/Downloads/ios/DownloadIOS.mm:

(WebKit::dispatchOnMainThread):
(WebKit::toDownload):
(WebKit::setUpDownloadClient):
(WebKit::Download::startWithHandle):

  • UIProcess/API/APIDownloadClient.h:

(API::DownloadClient::~DownloadClient):

  • UIProcess/API/C/WKContext.cpp:

(WKContextSetDownloadClient):

  • UIProcess/API/Cocoa/WKProcessPool.mm:

(-[WKProcessPool _downloadDelegate]):
(-[WKProcessPool _setDownloadDelegate:]):

  • UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
  • UIProcess/API/Cocoa/_WKDownload.h: Added.
  • UIProcess/API/Cocoa/_WKDownload.mm: Added.

(WebKit::wrapper):
(WebKit::createAPIDownloadClient):
(-[_WKDownload dealloc]):
(-[_WKDownload API::]):

  • UIProcess/API/Cocoa/_WKDownloadDelegate.h: Added.
  • UIProcess/API/Cocoa/_WKDownloadInternal.h: Added.
  • UIProcess/Cocoa/DownloadClient.h: Added.
  • UIProcess/Cocoa/DownloadClient.mm: Added.
  • WebKit2.xcodeproj/project.pbxproj:

Tools:

Add an API test suite for _WKDownload.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm: Added.

(-[DownloadDelegate initWithSourceURL:]):
(-[DownloadDelegate sourceURL]):
(-[DownloadDelegate _downloadDidStart:]):
(-[DownloadDelegate _download:didReceiveResponse:]):
(-[DownloadDelegate _download:didReceiveData:]):
(-[DownloadDelegate _download:decideDestinationWithSuggestedFilename:allowOverwrite:]):
(-[DownloadDelegate _downloadDidFinish:]):
(TEST):
(runTestWithNavigationDelegate):
(-[DownloadNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
(-[ConvertResponseToDownloadNavigationDelegate webView:decidePolicyForNavigationResponse:decisionHandler:]):

Location:
trunk
Files:
2 added
15 edited
5 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166182 r166186  
     12014-03-24  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Download support by CFURLDownloadRef under USE(CFNETWORK).
     4        https://bugs.webkit.org/show_bug.cgi?id=129322
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * platform/network/ResourceHandle.h:
     9        * platform/network/cf/ResourceHandleCFNet.cpp:
     10        (WebCore::ResourceHandle::releaseConnectionForDownload): Changed to
     11        return a RetainPtr that adopts the connection's retain count.
     12
    1132014-03-24  Enrica Casucci  <enrica@apple.com>
    214
  • trunk/Source/WebCore/platform/network/ResourceHandle.h

    r165676 r166186  
    139139    CFURLStorageSessionRef storageSession() const;
    140140    CFURLConnectionRef connection() const;
    141     CFURLConnectionRef releaseConnectionForDownload();
     141    RetainPtr<CFURLConnectionRef> releaseConnectionForDownload();
    142142    const ResourceRequest& currentRequest() const;
    143143    static void setHostAllowsAnyHTTPSCertificate(const String&);
  • trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp

    r165676 r166186  
    461461}
    462462
    463 CFURLConnectionRef ResourceHandle::releaseConnectionForDownload()
     463RetainPtr<CFURLConnectionRef> ResourceHandle::releaseConnectionForDownload()
    464464{
    465465    LOG(Network, "CFNet - Job %p releasing connection %p for download", this, d->m_connection.get());
    466     return d->m_connection.leakRef();
     466    return std::move(d->m_connection);
    467467}
    468468
  • trunk/Source/WebKit/mac/ChangeLog

    r166168 r166186  
     12014-03-24  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Download support by CFURLDownloadRef under USE(CFNETWORK).
     4        https://bugs.webkit.org/show_bug.cgi?id=129322
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * WebCoreSupport/WebFrameLoaderClient.mm:
     9        (WebFrameLoaderClient::convertMainResourceLoadToDownload): Use the
     10        RetainPtr returned by releaseConnectionForDownload() rather than
     11        manually releasing.
     12
    1132014-03-24  Jon Lee  <jonlee@apple.com>
    214
  • trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm

    r166144 r166186  
    331331#if USE(CFNETWORK)
    332332    ASSERT([WebDownload respondsToSelector:@selector(_downloadWithLoadingCFURLConnection:request:response:delegate:proxy:)]);
    333     CFURLConnectionRef connection = handle->connection();
    334     [WebDownload _downloadWithLoadingCFURLConnection:connection
    335                                                                      request:request.cfURLRequest(UpdateHTTPBody)
    336                                                                     response:response.cfURLResponse()
    337                                                                     delegate:[webView downloadDelegate]
    338                                                                        proxy:nil];
    339 
    340     // Release the connection since the NSURLDownload (actually CFURLDownload) will retain the connection and use it.
    341     handle->releaseConnectionForDownload();
    342     CFRelease(connection);
     333    auto connection = handle->releaseConnectionForDownload();
     334    [WebDownload _downloadWithLoadingCFURLConnection:connection.get() request:request.cfURLRequest(UpdateHTTPBody) response:response.cfURLResponse() delegate:[webView downloadDelegate] proxy:nil];
    343335#else
    344     [WebDownload _downloadWithLoadingConnection:handle->connection()
    345                                                                 request:request.nsURLRequest(UpdateHTTPBody)
    346                                                                response:response.nsURLResponse()
    347                                                                delegate:[webView downloadDelegate]
    348                                                                   proxy:nil];
     336    [WebDownload _downloadWithLoadingConnection:handle->connection() request:request.nsURLRequest(UpdateHTTPBody) response:response.nsURLResponse() delegate:[webView downloadDelegate] proxy:nil];
    349337#endif
    350338}
  • trunk/Source/WebKit2/ChangeLog

    r166162 r166186  
     12014-03-24  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Download support by CFURLDownloadRef under USE(CFNETWORK).
     4        https://bugs.webkit.org/show_bug.cgi?id=129322
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Based on an original patch by Yongjun Zhang  <yongjun_zhang@apple.com>.
     9
     10        * Shared/Cocoa/APIObject.mm:
     11        (API::Object::newObject):
     12        * Shared/Downloads/ios/DownloadIOS.mm:
     13        (WebKit::dispatchOnMainThread):
     14        (WebKit::toDownload):
     15        (WebKit::setUpDownloadClient):
     16        (WebKit::Download::startWithHandle):
     17        * UIProcess/API/APIDownloadClient.h:
     18        (API::DownloadClient::~DownloadClient):
     19        * UIProcess/API/C/WKContext.cpp:
     20        (WKContextSetDownloadClient):
     21        * UIProcess/API/Cocoa/WKProcessPool.mm:
     22        (-[WKProcessPool _downloadDelegate]):
     23        (-[WKProcessPool _setDownloadDelegate:]):
     24        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
     25        * UIProcess/API/Cocoa/_WKDownload.h: Added.
     26        * UIProcess/API/Cocoa/_WKDownload.mm: Added.
     27        (WebKit::wrapper):
     28        (WebKit::createAPIDownloadClient):
     29        (-[_WKDownload dealloc]):
     30        (-[_WKDownload API::]):
     31        * UIProcess/API/Cocoa/_WKDownloadDelegate.h: Added.
     32        * UIProcess/API/Cocoa/_WKDownloadInternal.h: Added.
     33        * UIProcess/Cocoa/DownloadClient.h: Added.
     34        * UIProcess/Cocoa/DownloadClient.mm: Added.
     35        * WebKit2.xcodeproj/project.pbxproj:
     36
    1372014-03-24  Dániel Bátyai  <dbatyai.u-szeged@partner.samsung.com>
    238
  • trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm

    r164603 r166186  
    2929#if WK_API_ENABLED
    3030
     31#import "_WKDownloadInternal.h"
    3132#import "WKBackForwardListInternal.h"
    3233#import "WKBackForwardListItemInternal.h"
     
    114115        break;
    115116
     117    case Type::Download:
     118        wrapper = [_WKDownload alloc];
     119        break;
     120
    116121    case Type::Error:
    117122        wrapper = NSAllocateObject([WKNSError self], size, nullptr);
  • trunk/Source/WebKit2/Shared/Downloads/ios/DownloadIOS.mm

    r164776 r166186  
    2929#if PLATFORM(IOS)
    3030
     31#import "DataReference.h"
     32#import <CFNetwork/CFURLDownload.h>
    3133#import <WebCore/NotImplemented.h>
     34#import <WebCore/ResourceError.h>
     35#import <WebCore/ResourceHandle.h>
     36#import <WebCore/ResourceResponse.h>
     37#import <wtf/RetainPtr.h>
     38#import <wtf/RunLoop.h>
    3239
    3340using namespace WebCore;
    3441
    3542namespace WebKit {
    36    
     43
     44// FIXME: If possible, we should consider moving some callbacks off the main thread or at least
     45// making them asynchonous calls.
     46static void dispatchOnMainThread(void(^block)())
     47{
     48    if (RunLoop::isMain()) {
     49        block();
     50        return;
     51    }
     52
     53    dispatch_sync(dispatch_get_main_queue(), block);
     54}
     55
     56static inline Download* toDownload(const void* clientInfo)
     57{
     58    return static_cast<Download*>(const_cast<void*>(clientInfo));
     59}
     60
     61static void setUpDownloadClient(CFURLDownloadClient& client, Download& download)
     62{
     63    memset(&client, 0, sizeof(client));
     64    client.clientInfo = &download;
     65
     66    client.didStart = [](CFURLDownloadRef, const void* clientInfo) {
     67        dispatchOnMainThread(^{
     68            toDownload(clientInfo)->didStart();
     69        });
     70    };
     71
     72    client.willSendRequest = [](CFURLDownloadRef, CFURLRequestRef request, CFURLResponseRef, const void*) -> CFURLRequestRef {
     73        return CFRetain(request);
     74    };
     75
     76    client.didReceiveResponse = [](CFURLDownloadRef, CFURLResponseRef response, const void* clientInfo) {
     77        dispatchOnMainThread(^{
     78            toDownload(clientInfo)->didReceiveResponse(response);
     79        });
     80    };
     81
     82    client.didReceiveData = [](CFURLDownloadRef, CFIndex length, const void* clientInfo) {
     83        dispatchOnMainThread(^{
     84            toDownload(clientInfo)->didReceiveData(length);
     85        });
     86    };
     87
     88    client.shouldDecodeDataOfMIMEType = [](CFURLDownloadRef, CFStringRef encodingType, const void* clientInfo) -> Boolean {
     89        __block BOOL returnValue = NO;
     90        dispatchOnMainThread(^{
     91            returnValue = toDownload(clientInfo)->shouldDecodeSourceDataOfMIMEType(encodingType);
     92        });
     93        return returnValue;
     94    };
     95
     96    client.decideDestinationWithSuggestedObjectName = [](CFURLDownloadRef downloadRef, CFStringRef objectName, const void* clientInfo) {
     97        dispatchOnMainThread(^{
     98            BOOL allowOverwrite;
     99            String destination = toDownload(clientInfo)->decideDestinationWithSuggestedFilename(objectName, allowOverwrite);
     100            if (!destination.isNull())
     101                CFURLDownloadSetDestination(downloadRef, reinterpret_cast<CFURLRef>([NSURL fileURLWithPath:destination]), allowOverwrite);
     102        });
     103    };
     104
     105    client.didCreateDestination = [](CFURLDownloadRef, CFURLRef path, const void* clientInfo) {
     106        dispatchOnMainThread(^{
     107            toDownload(clientInfo)->didCreateDestination(CFURLGetString(path));
     108        });
     109    };
     110
     111    client.didFinish = [](CFURLDownloadRef, const void* clientInfo) {
     112        dispatchOnMainThread(^{
     113            toDownload(clientInfo)->didFinish();
     114        });
     115    };
     116
     117    client.didFail = [](CFURLDownloadRef downloadRef, CFErrorRef error, const void* clientInfo) {
     118        dispatchOnMainThread(^{
     119            auto resumeData = adoptCF(CFURLDownloadCopyResumeData(downloadRef));
     120            toDownload(clientInfo)->didFail(error, IPC::DataReference(CFDataGetBytePtr(resumeData.get()), CFDataGetLength(resumeData.get())));
     121        });
     122    };
     123}
     124
    37125void Download::start()
    38126{
     
    40128}
    41129
    42 void Download::startWithHandle(ResourceHandle*, const ResourceResponse&)
     130void Download::startWithHandle(ResourceHandle* handle, const ResourceResponse& response)
    43131{
    44     notImplemented();
     132    CFURLDownloadClient client;
     133    setUpDownloadClient(client, *this);
     134    m_download = adoptCF(CFURLDownloadCreateAndStartWithLoadingConnection(NULL, handle->releaseConnectionForDownload().get(), m_request.cfURLRequest(UpdateHTTPBody), response.cfURLResponse(), &client));
    45135}
    46136
  • trunk/Source/WebKit2/UIProcess/API/APIDownloadClient.h

    r166096 r166186  
    3030
    3131namespace WebCore {
     32class ResourceError;
    3233class ResourceResponse;
    33 class ResourceError;
    3434}
    3535
    3636namespace WebKit {
    3737class AuthenticationChallengeProxy;
     38class DownloadProxy;
    3839class WebContext;
    39 class DownloadProxy;
    4040}
    4141
     
    4444class DownloadClient {
    4545public:
    46     virtual ~DownloadClient()   { }
     46    virtual ~DownloadClient() { }
    4747
    4848    virtual void didStart(WebKit::WebContext*, WebKit::DownloadProxy*) { }
     
    5151    virtual void didReceiveData(WebKit::WebContext*, WebKit::DownloadProxy*, uint64_t length) { }
    5252    virtual bool shouldDecodeSourceDataOfMIMEType(WebKit::WebContext*, WebKit::DownloadProxy*, const WTF::String& mimeType) { return true; }
    53     virtual WTF::String decideDestinationWithSuggestedFilename(WebKit::WebContext*, WebKit::DownloadProxy*, const WTF::String& filename, bool& allowOverwrite)
    54     {
    55         return WTF::String();
    56     }
     53    virtual WTF::String decideDestinationWithSuggestedFilename(WebKit::WebContext*, WebKit::DownloadProxy*, const WTF::String& filename, bool& allowOverwrite) { return {}; }
    5754    virtual void didCreateDestination(WebKit::WebContext*, WebKit::DownloadProxy*, const WTF::String& path) { }
    5855    virtual void didFinish(WebKit::WebContext*, WebKit::DownloadProxy*) { }
  • trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp

    r166096 r166186  
    171171        {
    172172            if (!m_client.didStart)
    173             return;
     173                return;
    174174
    175175            m_client.didStart(toAPI(webContext), toAPI(downloadProxy), m_client.base.clientInfo);
     
    179179        {
    180180            if (!m_client.didReceiveAuthenticationChallenge)
    181             return;
     181                return;
    182182
    183183            m_client.didReceiveAuthenticationChallenge(toAPI(webContext), toAPI(downloadProxy), toAPI(authenticationChallengeProxy), m_client.base.clientInfo);
     
    187187        {
    188188            if (!m_client.didReceiveResponse)
    189             return;
     189                return;
    190190
    191191            m_client.didReceiveResponse(toAPI(webContext), toAPI(downloadProxy), toAPI(API::URLResponse::create(response).get()), m_client.base.clientInfo);
     
    195195        {
    196196            if (!m_client.didReceiveData)
    197             return;
     197                return;
    198198
    199199            m_client.didReceiveData(toAPI(webContext), toAPI(downloadProxy), length, m_client.base.clientInfo);
     
    203203        {
    204204            if (!m_client.shouldDecodeSourceDataOfMIMEType)
    205             return true;
     205                return true;
    206206
    207207            return m_client.shouldDecodeSourceDataOfMIMEType(toAPI(webContext), toAPI(downloadProxy), toAPI(mimeType.impl()), m_client.base.clientInfo);
     
    211211        {
    212212            if (!m_client.decideDestinationWithSuggestedFilename)
    213             return String();
     213                return String();
    214214
    215215            WKRetainPtr<WKStringRef> destination(AdoptWK, m_client.decideDestinationWithSuggestedFilename(toAPI(webContext), toAPI(downloadProxy), toAPI(filename.impl()), &allowOverwrite, m_client.base.clientInfo));
     
    220220        {
    221221            if (!m_client.didCreateDestination)
    222             return;
     222                return;
    223223
    224224            m_client.didCreateDestination(toAPI(webContext), toAPI(downloadProxy), toAPI(path.impl()), m_client.base.clientInfo);
     
    228228        {
    229229            if (!m_client.didFinish)
    230             return;
     230                return;
    231231
    232232            m_client.didFinish(toAPI(webContext), toAPI(downloadProxy), m_client.base.clientInfo);
     
    236236        {
    237237            if (!m_client.didFail)
    238             return;
     238                return;
    239239
    240240            m_client.didFail(toAPI(webContext), toAPI(downloadProxy), toAPI(error), m_client.base.clientInfo);
     
    244244        {
    245245            if (!m_client.didCancel)
    246             return;
     246                return;
    247247           
    248248            m_client.didCancel(toAPI(webContext), toAPI(downloadProxy), m_client.base.clientInfo);
     
    252252        {
    253253            if (!m_client.processDidCrash)
    254             return;
     254                return;
    255255           
    256256            m_client.processDidCrash(toAPI(webContext), toAPI(downloadProxy), m_client.base.clientInfo);
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPool.mm

    r166011 r166186  
    2929#if WK_API_ENABLED
    3030
     31#import "_WKDownloadDelegate.h"
    3132#import "CacheModel.h"
     33#import "DownloadClient.h"
    3234#import "HistoryClient.h"
    3335#import "ProcessModel.h"
    3436#import "WKObject.h"
    3537#import "WKProcessPoolConfigurationPrivate.h"
     38#import "WeakObjCPtr.h"
    3639#import "WebCertificateInfo.h"
    3740#import "WebContext.h"
     
    5962#endif
    6063
    61 @implementation WKProcessPool
     64@implementation WKProcessPool {
     65    WebKit::WeakObjCPtr<id <_WKDownloadDelegate>> _downloadDelegate;
     66}
    6267
    6368- (instancetype)init
     
    174179}
    175180
     181- (id <_WKDownloadDelegate>)_downloadDelegate
     182{
     183    return _downloadDelegate.getAutoreleased();
     184}
     185
     186- (void)_setDownloadDelegate:(id <_WKDownloadDelegate>)downloadDelegate
     187{
     188    _downloadDelegate = downloadDelegate;
     189    _context->setDownloadClient(std::make_unique<WebKit::DownloadClient>(downloadDelegate));
     190}
     191
    176192@end
    177193
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h

    r166011 r166186  
    2929
    3030@class _WKProcessPoolConfiguration;
     31@protocol _WKDownloadDelegate;
    3132
    3233@interface WKProcessPool (WKPrivate)
     
    4243- (void)_setObject:(id <NSCopying, NSSecureCoding>)object forBundleParameter:(NSString *)parameter;
    4344
     45@property (nonatomic, weak, setter=_setDownloadDelegate:) id <_WKDownloadDelegate> _downloadDelegate;
     46
    4447@end
    4548
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKDownload.h

    r166185 r166186  
    2424 */
    2525
    26 #import <WebKit2/WKProcessPool.h>
     26#import <WebKit2/WKFoundation.h>
    2727
    2828#if WK_API_ENABLED
    2929
    30 @class _WKProcessPoolConfiguration;
     30#import <Foundation/Foundation.h>
    3131
    32 @interface WKProcessPool (WKPrivate)
    33 
    34 - (instancetype)_initWithConfiguration:(_WKProcessPoolConfiguration *)configuration WK_DESIGNATED_INITIALIZER;
    35 
    36 @property (nonatomic, readonly) _WKProcessPoolConfiguration *_configuration;
    37 
    38 - (void)_setAllowsSpecificHTTPSCertificate:(NSArray *)certificateChain forHost:(NSString *)host;
    39 - (void)_setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy;
    40 
    41 - (id)_objectForBundleParameter:(NSString *)parameter;
    42 - (void)_setObject:(id <NSCopying, NSSecureCoding>)object forBundleParameter:(NSString *)parameter;
     32WK_API_CLASS
     33@interface _WKDownload : NSObject
    4334
    4435@end
    4536
    46 #endif
     37#endif // WK_API_ENABLED
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKDownload.mm

    r166185 r166186  
    2424 */
    2525
    26 #import <WebKit2/WKProcessPool.h>
     26#import "config.h"
     27#import "_WKDownloadInternal.h"
    2728
    2829#if WK_API_ENABLED
    2930
    30 @class _WKProcessPoolConfiguration;
     31#import "DownloadProxy.h"
    3132
    32 @interface WKProcessPool (WKPrivate)
     33@implementation _WKDownload {
     34    API::ObjectStorage<WebKit::DownloadProxy> _download;
     35}
    3336
    34 - (instancetype)_initWithConfiguration:(_WKProcessPoolConfiguration *)configuration WK_DESIGNATED_INITIALIZER;
     37- (void)dealloc
     38{
     39    _download->~DownloadProxy();
    3540
    36 @property (nonatomic, readonly) _WKProcessPoolConfiguration *_configuration;
     41    [super dealloc];
     42}
    3743
    38 - (void)_setAllowsSpecificHTTPSCertificate:(NSArray *)certificateChain forHost:(NSString *)host;
    39 - (void)_setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy;
     44#pragma mark WKObject protocol implementation
    4045
    41 - (id)_objectForBundleParameter:(NSString *)parameter;
    42 - (void)_setObject:(id <NSCopying, NSSecureCoding>)object forBundleParameter:(NSString *)parameter;
     46- (API::Object&)_apiObject
     47{
     48    return *_download;
     49}
    4350
    4451@end
    4552
    46 #endif
     53#endif // WK_API_ENABLED
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKDownloadDelegate.h

    r166185 r166186  
    2424 */
    2525
    26 #import <WebKit2/WKProcessPool.h>
     26#import <WebKit2/WKFoundation.h>
    2727
    2828#if WK_API_ENABLED
    2929
    30 @class _WKProcessPoolConfiguration;
     30#import <Foundation/Foundation.h>
    3131
    32 @interface WKProcessPool (WKPrivate)
     32@class _WKDownload;
    3333
    34 - (instancetype)_initWithConfiguration:(_WKProcessPoolConfiguration *)configuration WK_DESIGNATED_INITIALIZER;
    35 
    36 @property (nonatomic, readonly) _WKProcessPoolConfiguration *_configuration;
    37 
    38 - (void)_setAllowsSpecificHTTPSCertificate:(NSArray *)certificateChain forHost:(NSString *)host;
    39 - (void)_setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy;
    40 
    41 - (id)_objectForBundleParameter:(NSString *)parameter;
    42 - (void)_setObject:(id <NSCopying, NSSecureCoding>)object forBundleParameter:(NSString *)parameter;
    43 
     34@protocol _WKDownloadDelegate <NSObject>
     35@optional
     36- (void)_downloadDidStart:(_WKDownload *)download;
     37- (void)_download:(_WKDownload *)download didReceiveResponse:(NSURLResponse *)response;
     38- (void)_download:(_WKDownload *)download didReceiveData:(uint64_t)length;
     39- (NSString *)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename allowOverwrite:(BOOL *)allowOverwrite;
     40- (void)_downloadDidFinish:(_WKDownload *)download;
    4441@end
    4542
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKDownloadInternal.h

    r166185 r166186  
    2424 */
    2525
    26 #import <WebKit2/WKProcessPool.h>
     26#import "_WKDownload.h"
    2727
    2828#if WK_API_ENABLED
    2929
    30 @class _WKProcessPoolConfiguration;
     30#import "WKObject.h"
    3131
    32 @interface WKProcessPool (WKPrivate)
     32@protocol _WKDownloadDelegate;
    3333
    34 - (instancetype)_initWithConfiguration:(_WKProcessPoolConfiguration *)configuration WK_DESIGNATED_INITIALIZER;
     34namespace API {
     35class DownloadClient;
     36}
    3537
    36 @property (nonatomic, readonly) _WKProcessPoolConfiguration *_configuration;
     38namespace WebKit {
     39std::unique_ptr<API::DownloadClient> createAPIDownloadClient(id <_WKDownloadDelegate>);
     40}
    3741
    38 - (void)_setAllowsSpecificHTTPSCertificate:(NSArray *)certificateChain forHost:(NSString *)host;
    39 - (void)_setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy;
    40 
    41 - (id)_objectForBundleParameter:(NSString *)parameter;
    42 - (void)_setObject:(id <NSCopying, NSSecureCoding>)object forBundleParameter:(NSString *)parameter;
    43 
     42@interface _WKDownload () <WKObject>
    4443@end
    4544
    46 #endif
     45#endif // WK_API_ENABLED
  • trunk/Source/WebKit2/UIProcess/Cocoa/DownloadClient.h

    r166185 r166186  
    2424 */
    2525
    26 #import <WebKit2/WKProcessPool.h>
     26#ifndef DownloadClient_h
     27#define DownloadClient_h
     28
     29#import "WKFoundation.h"
    2730
    2831#if WK_API_ENABLED
    2932
    30 @class _WKProcessPoolConfiguration;
     33#import "APIDownloadClient.h"
     34#import "WeakObjCPtr.h"
    3135
    32 @interface WKProcessPool (WKPrivate)
     36@protocol _WKDownloadDelegate;
    3337
    34 - (instancetype)_initWithConfiguration:(_WKProcessPoolConfiguration *)configuration WK_DESIGNATED_INITIALIZER;
     38namespace WebCore {
     39class ResourceResponse;
     40}
    3541
    36 @property (nonatomic, readonly) _WKProcessPoolConfiguration *_configuration;
     42namespace WebKit {
     43   
     44class DownloadClient final : public API::DownloadClient {
     45public:
     46    explicit DownloadClient(id <_WKDownloadDelegate>);
     47   
     48private:
     49    // From API::DownloadClient
     50    virtual void didStart(WebContext*, DownloadProxy*);
     51    virtual void didReceiveResponse(WebContext*, DownloadProxy*, const WebCore::ResourceResponse&);
     52    virtual void didReceiveData(WebContext*, DownloadProxy*, uint64_t length);
     53    virtual String decideDestinationWithSuggestedFilename(WebContext*, DownloadProxy*, const String& filename, bool& allowOverwriteParam);
     54    virtual void didFinish(WebContext*, DownloadProxy*);
    3755
    38 - (void)_setAllowsSpecificHTTPSCertificate:(NSArray *)certificateChain forHost:(NSString *)host;
    39 - (void)_setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy;
     56    WeakObjCPtr<id <_WKDownloadDelegate>> m_delegate;
    4057
    41 - (id)_objectForBundleParameter:(NSString *)parameter;
    42 - (void)_setObject:(id <NSCopying, NSSecureCoding>)object forBundleParameter:(NSString *)parameter;
     58    struct {
     59        bool downloadDidStart : 1;           
     60        bool downloadDidReceiveResponse : 1;
     61        bool downloadDidReceiveData : 1;
     62        bool downloadDecideDestinationWithSuggestedFilenameAllowOverwrite : 1;
     63        bool downloadDidFinish : 1;
     64    } m_delegateMethods;
     65};
    4366
    44 @end
     67} // namespace WebKit
    4568
    4669#endif
     70
     71#endif // DownloadClient_h
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r166103 r166186  
    987987                9FB5F394169E6A80002C25BF /* WKContextPrivateMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9FB5F392169E6A80002C25BF /* WKContextPrivateMac.mm */; };
    988988                9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
     989                A1A4FE5A18DCE9FA00B5EA8A /* _WKDownload.h in Headers */ = {isa = PBXBuildFile; fileRef = A1A4FE5718DCE9FA00B5EA8A /* _WKDownload.h */; settings = {ATTRIBUTES = (Private, ); }; };
     990                A1A4FE5B18DCE9FA00B5EA8A /* _WKDownload.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1A4FE5818DCE9FA00B5EA8A /* _WKDownload.mm */; };
     991                A1A4FE5C18DCE9FA00B5EA8A /* _WKDownloadInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1A4FE5918DCE9FA00B5EA8A /* _WKDownloadInternal.h */; };
     992                A1A4FE6118DD54A400B5EA8A /* _WKDownloadDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = A1A4FE6018DD54A400B5EA8A /* _WKDownloadDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     993                A1DF631218E0B7C8003A3E2A /* DownloadClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1DF631018E0B7C8003A3E2A /* DownloadClient.mm */; };
     994                A1DF631318E0B7C8003A3E2A /* DownloadClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DF631118E0B7C8003A3E2A /* DownloadClient.h */; };
    989995                A5EFD38C16B0E88C00B2F0E8 /* WKPageVisibilityTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = A5EFD38B16B0E88C00B2F0E8 /* WKPageVisibilityTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
    990996                A7D792D61767CB6E00881CBE /* ActivityAssertion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D792D51767CB6E00881CBE /* ActivityAssertion.cpp */; };
     
    28062812                9FB5F392169E6A80002C25BF /* WKContextPrivateMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKContextPrivateMac.mm; path = mac/WKContextPrivateMac.mm; sourceTree = "<group>"; };
    28072813                9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKContextPrivateMac.h; path = mac/WKContextPrivateMac.h; sourceTree = "<group>"; };
     2814                A1A4FE5718DCE9FA00B5EA8A /* _WKDownload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKDownload.h; sourceTree = "<group>"; };
     2815                A1A4FE5818DCE9FA00B5EA8A /* _WKDownload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKDownload.mm; sourceTree = "<group>"; };
     2816                A1A4FE5918DCE9FA00B5EA8A /* _WKDownloadInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKDownloadInternal.h; sourceTree = "<group>"; };
     2817                A1A4FE6018DD54A400B5EA8A /* _WKDownloadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKDownloadDelegate.h; sourceTree = "<group>"; };
     2818                A1DF631018E0B7C8003A3E2A /* DownloadClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadClient.mm; sourceTree = "<group>"; };
     2819                A1DF631118E0B7C8003A3E2A /* DownloadClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadClient.h; sourceTree = "<group>"; };
    28082820                A1EDD2D91884ACE000BBFE98 /* All.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = All.xcconfig; sourceTree = "<group>"; };
    28092821                A1EDD2DB1884B96400BBFE98 /* PluginProcessShim.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = PluginProcessShim.xcconfig; sourceTree = "<group>"; };
     
    41834195                        isa = PBXGroup;
    41844196                        children = (
    4185                                 2D7AAFD218C8640600A7ACD4 /* WKWebViewContentProvider.h */,
    4186                                 2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */,
    4187                                 2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */,
    4188                                 0F0C365918C0555800F607D7 /* LayerRepresentation.h */,
     4197                                A1DF631118E0B7C8003A3E2A /* DownloadClient.h */,
     4198                                A1DF631018E0B7C8003A3E2A /* DownloadClient.mm */,
    41894199                                1A422F8D18B29C6400D8CD96 /* HistoryClient.h */,
    41904200                                1A422F8C18B29C6400D8CD96 /* HistoryClient.mm */,
     4201                                0F0C365918C0555800F607D7 /* LayerRepresentation.h */,
    41914202                                1ABC3DF41899E437004F0626 /* NavigationState.h */,
    41924203                                1ABC3DF31899E437004F0626 /* NavigationState.mm */,
    41934204                                1AFE436418B6C081009C7A48 /* UIClient.h */,
    41944205                                1AFE436318B6C081009C7A48 /* UIClient.mm */,
     4206                                2D7AAFD218C8640600A7ACD4 /* WKWebViewContentProvider.h */,
     4207                                2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */,
     4208                                2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */,
    41954209                        );
    41964210                        path = Cocoa;
     
    45444558                                37A5E01118BBF937000A081E /* _WKActivatedElementInfo.mm */,
    45454559                                379A873518BBFA4300588AF2 /* _WKActivatedElementInfoInternal.h */,
     4560                                A1A4FE5718DCE9FA00B5EA8A /* _WKDownload.h */,
     4561                                A1A4FE5818DCE9FA00B5EA8A /* _WKDownload.mm */,
     4562                                A1A4FE6018DD54A400B5EA8A /* _WKDownloadDelegate.h */,
     4563                                A1A4FE5918DCE9FA00B5EA8A /* _WKDownloadInternal.h */,
    45464564                                379A873818BBFE0F00588AF2 /* _WKElementAction.h */,
    45474565                                379A873718BBFE0F00588AF2 /* _WKElementAction.mm */,
     
    65566574                                BC8452A81162C80900CAB9B5 /* DrawingArea.h in Headers */,
    65576575                                378E1A4A18208CD60031007A /* WKNSString.h in Headers */,
     6576                                A1A4FE5C18DCE9FA00B5EA8A /* _WKDownloadInternal.h in Headers */,
    65586577                                2D8949F1182044F600E898AA /* PlatformCALayerRemoteTiledBacking.h in Headers */,
    65596578                                0FB659231208B4DB0044816C /* DrawingAreaInfo.h in Headers */,
     
    66616680                                E152551B17011819003D7ADB /* NetworkResourceLoaderMessages.h in Headers */,
    66626681                                51CBBA10165219B6005BE8FD /* NetworkResourceLoadParameters.h in Headers */,
     6682                                A1DF631318E0B7C8003A3E2A /* DownloadClient.h in Headers */,
    66636683                                51829DA61637C70C000953D6 /* NetworkResourceLoadScheduler.h in Headers */,
    66646684                                31A2EC5614899C0900810D71 /* NotificationPermissionRequest.h in Headers */,
     
    70407060                                BC7B633D12A45D1200D174A4 /* WKBundlePageGroup.h in Headers */,
    70417061                                ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */,
     7062                                A1A4FE5A18DCE9FA00B5EA8A /* _WKDownload.h in Headers */,
    70427063                                BC1B419811D41D570011E8DD /* WKBundlePagePrivate.h in Headers */,
    70437064                                BCF049E711FE20F600F86A58 /* WKBundlePrivate.h in Headers */,
     
    70647085                                3309345B1315B9980097A7BC /* WKCookieManager.h in Headers */,
    70657086                                512F58FA12A88A5400629530 /* WKCredential.h in Headers */,
     7087                                A1A4FE6118DD54A400B5EA8A /* _WKDownloadDelegate.h in Headers */,
    70667088                                0FCB4E4618BBE044000FCFC9 /* PageClientImplIOS.h in Headers */,
    70677089                                518ACF1112B015F800B04B83 /* WKCredentialTypes.h in Headers */,
     
    82188240                                374436881820E7240049579F /* WKObject.mm in Sources */,
    82198241                                1A0F29E3120B44420053D1B9 /* VisitedLinkProvider.cpp in Sources */,
     8242                                A1DF631218E0B7C8003A3E2A /* DownloadClient.mm in Sources */,
    82208243                                1A0F29CB120B37160053D1B9 /* VisitedLinkTable.cpp in Sources */,
    82218244                                1AC1337F18590AE400F3EC05 /* RemoteObjectRegistry.mm in Sources */,
     
    84058428                                BC111B11112F5E4F00337BAB /* WebProcessProxy.cpp in Sources */,
    84068429                                51032F18180F73BB00961BB7 /* WebToDatabaseProcessConnection.cpp in Sources */,
     8430                                A1A4FE5B18DCE9FA00B5EA8A /* _WKDownload.mm in Sources */,
    84078431                                51D130581382F10500351EDD /* WebProcessProxyMac.mm in Sources */,
    84088432                                BCEE7AD012817988009827DA /* WebProcessProxyMessageReceiver.cpp in Sources */,
  • trunk/Tools/ChangeLog

    r166177 r166186  
     12014-03-24  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Download support by CFURLDownloadRef under USE(CFNETWORK).
     4        https://bugs.webkit.org/show_bug.cgi?id=129322
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Add an API test suite for _WKDownload.
     9
     10        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     11        * TestWebKitAPI/Tests/WebKit2Cocoa/Download.mm: Added.
     12        (-[DownloadDelegate initWithSourceURL:]):
     13        (-[DownloadDelegate sourceURL]):
     14        (-[DownloadDelegate _downloadDidStart:]):
     15        (-[DownloadDelegate _download:didReceiveResponse:]):
     16        (-[DownloadDelegate _download:didReceiveData:]):
     17        (-[DownloadDelegate _download:decideDestinationWithSuggestedFilename:allowOverwrite:]):
     18        (-[DownloadDelegate _downloadDidFinish:]):
     19        (TEST):
     20        (runTestWithNavigationDelegate):
     21        (-[DownloadNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
     22        (-[ConvertResponseToDownloadNavigationDelegate webView:decidePolicyForNavigationResponse:decisionHandler:]):
     23
    1242014-03-24  Joseph Pecoraro  <pecoraro@apple.com>
    225
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r163053 r166186  
    143143                9B4F8FA4159D52B1002D9F94 /* HTMLCollectionNamedItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */; };
    144144                9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */; };
     145                A1A4FE5F18DD3DB700B5EA8A /* Download.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1A4FE5D18DD3DB700B5EA8A /* Download.mm */; };
    145146                A57A34F016AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm in Sources */ = {isa = PBXBuildFile; fileRef = A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */; };
    146147                A57A34F216AF6B2B00C2501F /* PageVisibilityStateWithWindowChanges.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */; };
     
    470471                9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLCollectionNamedItem.mm; sourceTree = "<group>"; };
    471472                9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLCollectionNamedItem.html; sourceTree = "<group>"; };
     473                A1A4FE5D18DD3DB700B5EA8A /* Download.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Download.mm; sourceTree = "<group>"; };
    472474                A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PageVisibilityStateWithWindowChanges.mm; sourceTree = "<group>"; };
    473475                A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = PageVisibilityStateWithWindowChanges.html; sourceTree = "<group>"; };
     
    673675                        isa = PBXGroup;
    674676                        children = (
     677                                A1A4FE5D18DD3DB700B5EA8A /* Download.mm */,
    675678                                1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
    676679                        );
     
    12081211                                2D640B5517875DFF00BFAF99 /* ScrollPinningBehaviors.cpp in Sources */,
    12091212                                26300B1816755CD90066886D /* ListHashSet.cpp in Sources */,
     1213                                A1A4FE5F18DD3DB700B5EA8A /* Download.mm in Sources */,
    12101214                                52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */,
    12111215                                33DC8911141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.