Changeset 207404 in webkit


Ignore:
Timestamp:
Oct 17, 2016 3:45:15 AM (8 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Switch to use API::DownloadClient instead of the C API client
https://bugs.webkit.org/show_bug.cgi?id=163537

Reviewed by Michael Catanzaro.

The code is simpler and we avoid all the toImpl/toAPI.

  • UIProcess/API/gtk/WebKitDownloadClient.cpp:

(attachDownloadClientToContext):
(didStart):
(didReceiveResponse):
(didReceiveData):
(decideDestinationWithSuggestedFilename):
(didCreateDestination):
(didFail):
(didCancel):
(didFinish):

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r207402 r207404  
     12016-10-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Switch to use API::DownloadClient instead of the C API client
     4        https://bugs.webkit.org/show_bug.cgi?id=163537
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        The code is simpler and we avoid all the toImpl/toAPI.
     9
     10        * UIProcess/API/gtk/WebKitDownloadClient.cpp:
     11        (attachDownloadClientToContext):
     12        (didStart):
     13        (didReceiveResponse):
     14        (didReceiveData):
     15        (decideDestinationWithSuggestedFilename):
     16        (didCreateDestination):
     17        (didFail):
     18        (didCancel):
     19        (didFinish):
     20
    1212016-10-17  Manuel Rego Casasnovas  <rego@igalia.com>
    222
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp

    r194532 r207404  
    2121#include "WebKitDownloadClient.h"
    2222
    23 #include "APIURLResponse.h"
     23#include "APIDownloadClient.h"
    2424#include "WebKitDownloadPrivate.h"
    2525#include "WebKitURIResponsePrivate.h"
     
    3333using namespace WebKit;
    3434
    35 static void didStart(WKContextRef, WKDownloadRef wkDownload, const void* clientInfo)
    36 {
    37     GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
    38     webkitWebContextDownloadStarted(WEBKIT_WEB_CONTEXT(clientInfo), download.get());
    39 }
     35class DownloadClient final : public API::DownloadClient {
     36public:
     37    explicit DownloadClient(WebKitWebContext* webContext)
     38        : m_webContext(webContext)
     39    {
     40    }
    4041
    41 static void didReceiveResponse(WKContextRef, WKDownloadRef wkDownload, WKURLResponseRef wkResponse, const void* /* clientInfo */)
    42 {
    43     GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
    44     if (webkitDownloadIsCancelled(download.get()))
    45         return;
     42private:
     43    void didStart(WebProcessPool*, DownloadProxy* downloadProxy) override
     44    {
     45        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
     46        webkitWebContextDownloadStarted(m_webContext, download.get());
     47    }
    4648
    47     GRefPtr<WebKitURIResponse> response = adoptGRef(webkitURIResponseCreateForResourceResponse(toImpl(wkResponse)->resourceResponse()));
    48     webkitDownloadSetResponse(download.get(), response.get());
    49 }
     49    void didReceiveResponse(WebProcessPool*, DownloadProxy* downloadProxy, const ResourceResponse& resourceResponse) override
     50    {
     51        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
     52        if (webkitDownloadIsCancelled(download.get()))
     53            return;
    5054
    51 static void didReceiveData(WKContextRef, WKDownloadRef wkDownload, uint64_t length, const void* /* clientInfo */)
    52 {
    53     GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
    54     webkitDownloadNotifyProgress(download.get(), length);
    55 }
     55        GRefPtr<WebKitURIResponse> response = adoptGRef(webkitURIResponseCreateForResourceResponse(resourceResponse));
     56        webkitDownloadSetResponse(download.get(), response.get());
     57    }
    5658
    57 static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef wkDownload, WKStringRef filename, bool* allowOverwrite, const void* /* clientInfo */)
    58 {
    59     GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
    60     CString destinationURI = webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), toImpl(filename)->string().utf8(), *allowOverwrite);
    61     return WKStringCreateWithUTF8CString(destinationURI.data());
    62 }
     59    void didReceiveData(WebProcessPool*, DownloadProxy* downloadProxy, uint64_t length) override
     60    {
     61        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
     62        webkitDownloadNotifyProgress(download.get(), length);
     63    }
    6364
    64 static void didCreateDestination(WKContextRef, WKDownloadRef wkDownload, WKStringRef path, const void* /* clientInfo */)
    65 {
    66     GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
    67     webkitDownloadDestinationCreated(download.get(), toImpl(path)->string().utf8());
    68 }
     65    String decideDestinationWithSuggestedFilename(WebProcessPool*, DownloadProxy* downloadProxy, const String& filename, bool& allowOverwrite) override
     66    {
     67        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
     68        return String::fromUTF8(webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), filename.utf8(), allowOverwrite));
     69    }
    6970
    70 static void didFail(WKContextRef, WKDownloadRef wkDownload, WKErrorRef error, const void* /* clientInfo */)
    71 {
    72     GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
    73     if (webkitDownloadIsCancelled(download.get())) {
    74         // Cancellation takes precedence over other errors.
     71    void didCreateDestination(WebProcessPool*, DownloadProxy* downloadProxy, const String& path) override
     72    {
     73        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
     74        webkitDownloadDestinationCreated(download.get(), path.utf8());
     75    }
     76
     77    void didFail(WebProcessPool*, DownloadProxy* downloadProxy, const ResourceError& error) override
     78    {
     79        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
     80        if (webkitDownloadIsCancelled(download.get())) {
     81            // Cancellation takes precedence over other errors.
     82            webkitDownloadCancelled(download.get());
     83        } else
     84            webkitDownloadFailed(download.get(), error);
     85        webkitWebContextRemoveDownload(downloadProxy);
     86    }
     87
     88    void didCancel(WebProcessPool*, DownloadProxy* downloadProxy) override
     89    {
     90        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
    7591        webkitDownloadCancelled(download.get());
    76     } else
    77         webkitDownloadFailed(download.get(), toImpl(error)->platformError());
    78     webkitWebContextRemoveDownload(toImpl(wkDownload));
    79 }
     92        webkitWebContextRemoveDownload(downloadProxy);
     93    }
    8094
    81 static void didCancel(WKContextRef, WKDownloadRef wkDownload, const void* /* clientInfo */)
    82 {
    83     GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
    84     webkitDownloadCancelled(download.get());
    85     webkitWebContextRemoveDownload(toImpl(wkDownload));
    86 }
     95    void didFinish(WebProcessPool*, DownloadProxy* downloadProxy) override
     96    {
     97        GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
     98        webkitDownloadFinished(download.get());
     99        webkitWebContextRemoveDownload(downloadProxy);
     100    }
    87101
    88 static void didFinish(WKContextRef, WKDownloadRef wkDownload, const void* /* clientInfo */)
    89 {
    90     GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload));
    91     webkitDownloadFinished(download.get());
    92     webkitWebContextRemoveDownload(toImpl(wkDownload));
    93 }
     102    WebKitWebContext* m_webContext;
     103};
    94104
    95105void attachDownloadClientToContext(WebKitWebContext* webContext)
    96106{
    97     WKContextDownloadClientV0 wkDownloadClient = {
    98         {
    99             0, // version
    100             webContext, // ClientInfo
    101         },
    102         didStart,
    103         0, // didReceiveAuthenticationChallenge
    104         didReceiveResponse,
    105         didReceiveData,
    106         0, // shouldDecodeSourceDataOfMIMEType
    107         decideDestinationWithSuggestedFilename,
    108         didCreateDestination,
    109         didFinish,
    110         didFail,
    111         didCancel,
    112         0, // processDidCrash
    113     };
    114     WKContextSetDownloadClient(toAPI(webkitWebContextGetProcessPool(webContext)), &wkDownloadClient.base);
     107    auto* processPool = webkitWebContextGetProcessPool(webContext);
     108    processPool->setDownloadClient(std::make_unique<DownloadClient>(webContext));
    115109}
    116 
Note: See TracChangeset for help on using the changeset viewer.