Changeset 268008 in webkit


Ignore:
Timestamp:
Oct 5, 2020 3:38:11 PM (4 years ago)
Author:
achristensen@apple.com
Message:

Use sendWithAsyncReply for DecideDestinationWithSuggestedFilename
https://bugs.webkit.org/show_bug.cgi?id=209195

Reviewed by Tim Horton.

This makes the download flow more clear.
No change in behavior.

  • NetworkProcess/Downloads/DownloadID.h:
  • NetworkProcess/Downloads/DownloadManager.cpp:

(WebKit::DownloadManager::downloadDestinationDecided):
(WebKit::DownloadManager::cancelDownload):
(WebKit::DownloadManager::willDecidePendingDownloadDestination): Deleted.
(WebKit::DownloadManager::continueDecidePendingDownloadDestination): Deleted.

  • NetworkProcess/Downloads/DownloadManager.h:
  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::findPendingDownloadLocation):
(WebKit::NetworkProcess::continueDecidePendingDownloadDestination): Deleted.

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/NetworkProcess.messages.in:
  • Scripts/webkit/messages.py:
  • Shared/Authentication/AuthenticationManager.h:
  • UIProcess/API/APIDownloadClient.h:
  • UIProcess/Downloads/DownloadProxy.cpp:

(WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):
(WebKit::DownloadProxy::decideDestinationWithSuggestedFilenameAsync): Deleted.

  • UIProcess/Downloads/DownloadProxy.h:
  • UIProcess/Downloads/DownloadProxy.messages.in:
Location:
trunk/Source/WebKit
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r268003 r268008  
     12020-10-05  Alex Christensen  <achristensen@webkit.org>
     2
     3        Use sendWithAsyncReply for DecideDestinationWithSuggestedFilename
     4        https://bugs.webkit.org/show_bug.cgi?id=209195
     5
     6        Reviewed by Tim Horton.
     7
     8        This makes the download flow more clear.
     9        No change in behavior.
     10
     11        * NetworkProcess/Downloads/DownloadID.h:
     12        * NetworkProcess/Downloads/DownloadManager.cpp:
     13        (WebKit::DownloadManager::downloadDestinationDecided):
     14        (WebKit::DownloadManager::cancelDownload):
     15        (WebKit::DownloadManager::willDecidePendingDownloadDestination): Deleted.
     16        (WebKit::DownloadManager::continueDecidePendingDownloadDestination): Deleted.
     17        * NetworkProcess/Downloads/DownloadManager.h:
     18        * NetworkProcess/NetworkProcess.cpp:
     19        (WebKit::NetworkProcess::findPendingDownloadLocation):
     20        (WebKit::NetworkProcess::continueDecidePendingDownloadDestination): Deleted.
     21        * NetworkProcess/NetworkProcess.h:
     22        * NetworkProcess/NetworkProcess.messages.in:
     23        * Scripts/webkit/messages.py:
     24        * Shared/Authentication/AuthenticationManager.h:
     25        * UIProcess/API/APIDownloadClient.h:
     26        * UIProcess/Downloads/DownloadProxy.cpp:
     27        (WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):
     28        (WebKit::DownloadProxy::decideDestinationWithSuggestedFilenameAsync): Deleted.
     29        * UIProcess/Downloads/DownloadProxy.h:
     30        * UIProcess/Downloads/DownloadProxy.messages.in:
     31
    1322020-10-05  David Kilzer  <ddkilzer@apple.com>
    233
  • trunk/Source/WebKit/NetworkProcess/Downloads/DownloadID.h

    r264488 r268008  
    2424 */
    2525
    26 #ifndef DownloadID_h
    27 #define DownloadID_h
     26#pragma once
    2827
    2928#include "ArgumentCoder.h"
     
    3433namespace WebKit {
    3534
     35enum class AllowOverwrite : bool { No, Yes };
     36
     37// FIXME: This should be an ObjectIdentifier.
    3638class DownloadID {
    3739public:
     
    9496
    9597}
    96 #endif /* DownloadID_h */
  • trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp

    r260031 r268008  
    8282}
    8383
    84 void DownloadManager::willDecidePendingDownloadDestination(NetworkDataTask& networkDataTask, ResponseCompletionHandler&& completionHandler)
    85 {
    86     auto downloadID = networkDataTask.pendingDownloadID();
    87     auto addResult = m_downloadsWaitingForDestination.set(downloadID, std::make_pair<RefPtr<NetworkDataTask>, ResponseCompletionHandler>(&networkDataTask, WTFMove(completionHandler)));
    88     ASSERT_UNUSED(addResult, addResult.isNewEntry);
    89 }
    90 
    9184void DownloadManager::convertNetworkLoadToDownload(DownloadID downloadID, std::unique_ptr<NetworkLoad>&& networkLoad, ResponseCompletionHandler&& completionHandler, Vector<RefPtr<WebCore::BlobDataFileReference>>&& blobFileReferences, const ResourceRequest& request, const ResourceResponse& response)
    9285{
     
    9588}
    9689
    97 void DownloadManager::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, SandboxExtension::Handle&& sandboxExtensionHandle, bool allowOverwrite)
     90void DownloadManager::downloadDestinationDecided(DownloadID downloadID, Ref<NetworkDataTask>&& networkDataTask)
    9891{
    99     if (m_downloadsWaitingForDestination.contains(downloadID)) {
    100         auto pair = m_downloadsWaitingForDestination.take(downloadID);
    101         auto networkDataTask = WTFMove(pair.first);
    102         auto completionHandler = WTFMove(pair.second);
    103         ASSERT(networkDataTask);
    104         ASSERT(completionHandler);
    105         ASSERT(m_pendingDownloads.contains(downloadID));
    106 
    107         networkDataTask->setPendingDownloadLocation(destination, WTFMove(sandboxExtensionHandle), allowOverwrite);
    108         completionHandler(PolicyAction::Download);
    109         if (networkDataTask->state() == NetworkDataTask::State::Canceling || networkDataTask->state() == NetworkDataTask::State::Completed)
    110             return;
    111 
    112         if (m_downloads.contains(downloadID)) {
    113             // The completion handler already called dataTaskBecameDownloadTask().
    114             return;
    115         }
    116 
    117         ASSERT(!m_downloadsAfterDestinationDecided.contains(downloadID));
    118         m_downloadsAfterDestinationDecided.set(downloadID, networkDataTask);
    119     }
     92    ASSERT(!m_downloadsAfterDestinationDecided.contains(downloadID));
     93    m_downloadsAfterDestinationDecided.set(downloadID, WTFMove(networkDataTask));
    12094}
    12195
     
    138112void DownloadManager::cancelDownload(DownloadID downloadID)
    139113{
    140     if (Download* download = m_downloads.get(downloadID)) {
    141         ASSERT(!m_downloadsWaitingForDestination.contains(downloadID));
     114    if (auto* download = m_downloads.get(downloadID)) {
    142115        ASSERT(!m_pendingDownloads.contains(downloadID));
    143116        download->cancel();
    144117        return;
    145118    }
    146     auto pendingDownload = m_pendingDownloads.take(downloadID);
    147     if (m_downloadsWaitingForDestination.contains(downloadID)) {
    148         auto pair = m_downloadsWaitingForDestination.take(downloadID);
    149         auto networkDataTask = WTFMove(pair.first);
    150         auto completionHandler = WTFMove(pair.second);
    151         ASSERT(networkDataTask);
    152         ASSERT(completionHandler);
    153 
    154         networkDataTask->cancel();
    155         completionHandler(PolicyAction::Ignore);
    156         m_client.pendingDownloadCanceled(downloadID);
    157         return;
    158     }
    159 
    160     if (pendingDownload)
     119    if (auto pendingDownload = m_pendingDownloads.take(downloadID))
    161120        pendingDownload->cancel();
    162121}
  • trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h

    r260031 r268008  
    8585    void dataTaskBecameDownloadTask(DownloadID, std::unique_ptr<Download>&&);
    8686    void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
    87     void willDecidePendingDownloadDestination(NetworkDataTask&, ResponseCompletionHandler&&);
    8887    void convertNetworkLoadToDownload(DownloadID, std::unique_ptr<NetworkLoad>&&, ResponseCompletionHandler&&,  Vector<RefPtr<WebCore::BlobDataFileReference>>&&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
    89     void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
     88    void downloadDestinationDecided(DownloadID, Ref<NetworkDataTask>&&);
    9089
    9190    void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&);
     
    115114    Client& m_client;
    116115    HashMap<DownloadID, std::unique_ptr<PendingDownload>> m_pendingDownloads;
    117     HashMap<DownloadID, std::pair<RefPtr<NetworkDataTask>, ResponseCompletionHandler>> m_downloadsWaitingForDestination;
    118116    HashMap<DownloadID, RefPtr<NetworkDataTask>> m_downloadsAfterDestinationDecided;
    119117    DownloadMap m_downloads;
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r267999 r268008  
    20982098    downloadProxyConnection()->send(Messages::DownloadProxy::DidReceiveResponse(response), destinationID);
    20992099
    2100     downloadManager().willDecidePendingDownloadDestination(networkDataTask, WTFMove(completionHandler));
    2101 
    21022100    // As per https://html.spec.whatwg.org/#as-a-download (step 2), the filename from the Content-Disposition header
    21032101    // should override the suggested filename from the download attribute.
     
    21052103    suggestedFilename = MIMETypeRegistry::appendFileExtensionIfNecessary(suggestedFilename, response.mimeType());
    21062104
    2107     downloadProxyConnection()->send(Messages::DownloadProxy::DecideDestinationWithSuggestedFilenameAsync(networkDataTask.pendingDownloadID(), suggestedFilename), destinationID);
    2108 }
    2109 
    2110 void NetworkProcess::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, SandboxExtension::Handle&& sandboxExtensionHandle, bool allowOverwrite)
    2111 {
    2112     if (destination.isEmpty())
    2113         downloadManager().cancelDownload(downloadID);
    2114     else
    2115         downloadManager().continueDecidePendingDownloadDestination(downloadID, destination, WTFMove(sandboxExtensionHandle), allowOverwrite);
     2105    downloadProxyConnection()->sendWithAsyncReply(Messages::DownloadProxy::DecideDestinationWithSuggestedFilename(suggestedFilename), [this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler), networkDataTask = makeRef(networkDataTask)] (String&& destination, SandboxExtension::Handle&& sandboxExtensionHandle, AllowOverwrite allowOverwrite) mutable {
     2106        auto downloadID = networkDataTask->pendingDownloadID();
     2107        if (destination.isEmpty()) {
     2108            downloadManager().cancelDownload(downloadID);
     2109            completionHandler(PolicyAction::Ignore);
     2110            return;
     2111        }
     2112        networkDataTask->setPendingDownloadLocation(destination, WTFMove(sandboxExtensionHandle), allowOverwrite == AllowOverwrite::Yes);
     2113        completionHandler(PolicyAction::Download);
     2114        if (networkDataTask->state() == NetworkDataTask::State::Canceling || networkDataTask->state() == NetworkDataTask::State::Completed)
     2115            return;
     2116
     2117        if (downloadManager().download(downloadID)) {
     2118            // The completion handler already called dataTaskBecameDownloadTask().
     2119            return;
     2120        }
     2121
     2122        downloadManager().downloadDestinationDecided(downloadID, WTFMove(networkDataTask));
     2123    }, destinationID);
    21162124}
    21172125
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r267763 r268008  
    430430#endif
    431431    void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
    432     void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
    433432    void applicationDidEnterBackground();
    434433    void applicationWillEnterForeground();
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in

    r267750 r268008  
    6060
    6161    ContinueWillSendRequest(WebKit::DownloadID downloadID, WebCore::ResourceRequest request)
    62     ContinueDecidePendingDownloadDestination(WebKit::DownloadID downloadID, String destination, WebKit::SandboxExtension::Handle sandboxExtensionHandle, bool allowOverwrite)
    6362
    6463#if PLATFORM(COCOA)
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r267916 r268008  
    665665        'WebCore::SelectionRect': ['"EditorState.h"'],
    666666        'WebKit::ActivityStateChangeID': ['"DrawingAreaInfo.h"'],
     667        'WebKit::AllowOverwrite': ['"DownloadID.h"'],
    667668        'WebKit::BackForwardListItemState': ['"SessionState.h"'],
    668669        'WebKit::ContentWorldIdentifier': ['"ContentWorldShared.h"'],
  • trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.h

    r255522 r268008  
    2626#pragma once
    2727
     28#include "DownloadID.h"
    2829#include "MessageReceiver.h"
    2930#include "NetworkProcessSupplement.h"
     
    5556
    5657class Download;
    57 class DownloadID;
    5858class NetworkProcess;
    5959class WebFrame;
  • trunk/Source/WebKit/UIProcess/API/APIDownloadClient.h

    r261898 r268008  
    2929#include "AuthenticationChallengeProxy.h"
    3030#include "AuthenticationDecisionListener.h"
     31#include "DownloadID.h"
    3132#include <wtf/CompletionHandler.h>
    3233#include <wtf/text/WTFString.h>
     
    4445class WebProtectionSpace;
    4546
    46 enum class AllowOverwrite { No, Yes };
     47enum class AllowOverwrite : bool;
    4748}
    4849
  • trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp

    r267763 r268008  
    167167}
    168168
    169 void DownloadProxy::decideDestinationWithSuggestedFilenameAsync(DownloadID downloadID, const String& suggestedFilename)
    170 {
    171     if (!m_processPool)
    172         return;
     169void DownloadProxy::decideDestinationWithSuggestedFilename(const String& suggestedFilename, CompletionHandler<void(String, SandboxExtension::Handle, AllowOverwrite)>&& completionHandler)
     170{
     171    if (!m_processPool)
     172        return completionHandler({ }, { }, { });
    173173   
    174     m_processPool->downloadClient().decideDestinationWithSuggestedFilename(*this, ResourceResponseBase::sanitizeSuggestedFilename(suggestedFilename), [this, protectedThis = makeRef(*this), downloadID] (AllowOverwrite allowOverwrite, String destination) {
     174    m_processPool->downloadClient().decideDestinationWithSuggestedFilename(*this, ResourceResponseBase::sanitizeSuggestedFilename(suggestedFilename), [completionHandler = WTFMove(completionHandler)] (AllowOverwrite allowOverwrite, String destination) mutable {
    175175        SandboxExtension::Handle sandboxExtensionHandle;
    176176        if (!destination.isNull())
    177177            SandboxExtension::createHandle(destination, SandboxExtension::Type::ReadWrite, sandboxExtensionHandle);
    178178
    179         if (!m_dataStore)
    180             return;
    181         m_dataStore->networkProcess().send(Messages::NetworkProcess::ContinueDecidePendingDownloadDestination(downloadID, destination, sandboxExtensionHandle, allowOverwrite == AllowOverwrite::Yes), 0);
     179        completionHandler(destination, WTFMove(sandboxExtensionHandle), allowOverwrite);
    182180    });
    183181}
  • trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h

    r261898 r268008  
    5050namespace WebKit {
    5151
    52 class DownloadID;
    5352class DownloadProxyMap;
    5453class WebPageProxy;
    5554class WebProcessPool;
    5655class WebsiteDataStore;
     56
     57enum class AllowOverwrite : bool;
    5758
    5859struct FrameInfoData;
     
    118119    void didCancel(const IPC::DataReference& resumeData);
    119120    void willSendRequest(WebCore::ResourceRequest&& redirectRequest, const WebCore::ResourceResponse& redirectResponse);
    120     void decideDestinationWithSuggestedFilenameAsync(DownloadID, const String& suggestedFilename);
     121    void decideDestinationWithSuggestedFilename(const String& suggestedFilename, CompletionHandler<void(String, SandboxExtension::Handle, AllowOverwrite)>&&);
    121122
    122123    DownloadProxyMap& m_downloadProxyMap;
  • trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.messages.in

    r261898 r268008  
    2525    DidReceiveAuthenticationChallenge(WebCore::AuthenticationChallenge challenge, uint64_t challengeID)
    2626    WillSendRequest(WebCore::ResourceRequest redirectRequest, WebCore::ResourceResponse redirectResponse))
    27     DecideDestinationWithSuggestedFilenameAsync(WebKit::DownloadID downloadID, String suggestedFilename)
     27    DecideDestinationWithSuggestedFilename(String suggestedFilename) -> (String filename, WebKit::SandboxExtension::Handle handle, enum:bool WebKit::AllowOverwrite allowOverwrite) Async
    2828
    2929    DidReceiveResponse(WebCore::ResourceResponse response)
Note: See TracChangeset for help on using the changeset viewer.