Changeset 207404 in webkit
- Timestamp:
- Oct 17, 2016 3:45:15 AM (8 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r207402 r207404 1 2016-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 1 21 2016-10-17 Manuel Rego Casasnovas <rego@igalia.com> 2 22 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp
r194532 r207404 21 21 #include "WebKitDownloadClient.h" 22 22 23 #include "API URLResponse.h"23 #include "APIDownloadClient.h" 24 24 #include "WebKitDownloadPrivate.h" 25 25 #include "WebKitURIResponsePrivate.h" … … 33 33 using namespace WebKit; 34 34 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 } 35 class DownloadClient final : public API::DownloadClient { 36 public: 37 explicit DownloadClient(WebKitWebContext* webContext) 38 : m_webContext(webContext) 39 { 40 } 40 41 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; 42 private: 43 void didStart(WebProcessPool*, DownloadProxy* downloadProxy) override 44 { 45 GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy); 46 webkitWebContextDownloadStarted(m_webContext, download.get()); 47 } 46 48 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; 50 54 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 } 56 58 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 } 63 64 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 } 69 70 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); 75 91 webkitDownloadCancelled(download.get()); 76 } else 77 webkitDownloadFailed(download.get(), toImpl(error)->platformError()); 78 webkitWebContextRemoveDownload(toImpl(wkDownload)); 79 } 92 webkitWebContextRemoveDownload(downloadProxy); 93 } 80 94 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 } 87 101 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 }; 94 104 95 105 void attachDownloadClientToContext(WebKitWebContext* webContext) 96 106 { 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)); 115 109 } 116
Note: See TracChangeset
for help on using the changeset viewer.