Changeset 268008 in webkit
- Timestamp:
- Oct 5, 2020 3:38:11 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r268003 r268008 1 2020-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 1 32 2020-10-05 David Kilzer <ddkilzer@apple.com> 2 33 -
trunk/Source/WebKit/NetworkProcess/Downloads/DownloadID.h
r264488 r268008 24 24 */ 25 25 26 #ifndef DownloadID_h 27 #define DownloadID_h 26 #pragma once 28 27 29 28 #include "ArgumentCoder.h" … … 34 33 namespace WebKit { 35 34 35 enum class AllowOverwrite : bool { No, Yes }; 36 37 // FIXME: This should be an ObjectIdentifier. 36 38 class DownloadID { 37 39 public: … … 94 96 95 97 } 96 #endif /* DownloadID_h */ -
trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp
r260031 r268008 82 82 } 83 83 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 91 84 void DownloadManager::convertNetworkLoadToDownload(DownloadID downloadID, std::unique_ptr<NetworkLoad>&& networkLoad, ResponseCompletionHandler&& completionHandler, Vector<RefPtr<WebCore::BlobDataFileReference>>&& blobFileReferences, const ResourceRequest& request, const ResourceResponse& response) 92 85 { … … 95 88 } 96 89 97 void DownloadManager:: continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, SandboxExtension::Handle&& sandboxExtensionHandle, bool allowOverwrite)90 void DownloadManager::downloadDestinationDecided(DownloadID downloadID, Ref<NetworkDataTask>&& networkDataTask) 98 91 { 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)); 120 94 } 121 95 … … 138 112 void DownloadManager::cancelDownload(DownloadID downloadID) 139 113 { 140 if (Download* download = m_downloads.get(downloadID)) { 141 ASSERT(!m_downloadsWaitingForDestination.contains(downloadID)); 114 if (auto* download = m_downloads.get(downloadID)) { 142 115 ASSERT(!m_pendingDownloads.contains(downloadID)); 143 116 download->cancel(); 144 117 return; 145 118 } 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)) 161 120 pendingDownload->cancel(); 162 121 } -
trunk/Source/WebKit/NetworkProcess/Downloads/DownloadManager.h
r260031 r268008 85 85 void dataTaskBecameDownloadTask(DownloadID, std::unique_ptr<Download>&&); 86 86 void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&); 87 void willDecidePendingDownloadDestination(NetworkDataTask&, ResponseCompletionHandler&&);88 87 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>&&); 90 89 91 90 void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&); … … 115 114 Client& m_client; 116 115 HashMap<DownloadID, std::unique_ptr<PendingDownload>> m_pendingDownloads; 117 HashMap<DownloadID, std::pair<RefPtr<NetworkDataTask>, ResponseCompletionHandler>> m_downloadsWaitingForDestination;118 116 HashMap<DownloadID, RefPtr<NetworkDataTask>> m_downloadsAfterDestinationDecided; 119 117 DownloadMap m_downloads; -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp
r267999 r268008 2098 2098 downloadProxyConnection()->send(Messages::DownloadProxy::DidReceiveResponse(response), destinationID); 2099 2099 2100 downloadManager().willDecidePendingDownloadDestination(networkDataTask, WTFMove(completionHandler));2101 2102 2100 // As per https://html.spec.whatwg.org/#as-a-download (step 2), the filename from the Content-Disposition header 2103 2101 // should override the suggested filename from the download attribute. … … 2105 2103 suggestedFilename = MIMETypeRegistry::appendFileExtensionIfNecessary(suggestedFilename, response.mimeType()); 2106 2104 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); 2116 2124 } 2117 2125 -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.h
r267763 r268008 430 430 #endif 431 431 void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&); 432 void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);433 432 void applicationDidEnterBackground(); 434 433 void applicationWillEnterForeground(); -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in
r267750 r268008 60 60 61 61 ContinueWillSendRequest(WebKit::DownloadID downloadID, WebCore::ResourceRequest request) 62 ContinueDecidePendingDownloadDestination(WebKit::DownloadID downloadID, String destination, WebKit::SandboxExtension::Handle sandboxExtensionHandle, bool allowOverwrite)63 62 64 63 #if PLATFORM(COCOA) -
trunk/Source/WebKit/Scripts/webkit/messages.py
r267916 r268008 665 665 'WebCore::SelectionRect': ['"EditorState.h"'], 666 666 'WebKit::ActivityStateChangeID': ['"DrawingAreaInfo.h"'], 667 'WebKit::AllowOverwrite': ['"DownloadID.h"'], 667 668 'WebKit::BackForwardListItemState': ['"SessionState.h"'], 668 669 'WebKit::ContentWorldIdentifier': ['"ContentWorldShared.h"'], -
trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.h
r255522 r268008 26 26 #pragma once 27 27 28 #include "DownloadID.h" 28 29 #include "MessageReceiver.h" 29 30 #include "NetworkProcessSupplement.h" … … 55 56 56 57 class Download; 57 class DownloadID;58 58 class NetworkProcess; 59 59 class WebFrame; -
trunk/Source/WebKit/UIProcess/API/APIDownloadClient.h
r261898 r268008 29 29 #include "AuthenticationChallengeProxy.h" 30 30 #include "AuthenticationDecisionListener.h" 31 #include "DownloadID.h" 31 32 #include <wtf/CompletionHandler.h> 32 33 #include <wtf/text/WTFString.h> … … 44 45 class WebProtectionSpace; 45 46 46 enum class AllowOverwrite { No, Yes };47 enum class AllowOverwrite : bool; 47 48 } 48 49 -
trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp
r267763 r268008 167 167 } 168 168 169 void DownloadProxy::decideDestinationWithSuggestedFilename Async(DownloadID downloadID, const String& suggestedFilename)170 { 171 if (!m_processPool) 172 return ;169 void DownloadProxy::decideDestinationWithSuggestedFilename(const String& suggestedFilename, CompletionHandler<void(String, SandboxExtension::Handle, AllowOverwrite)>&& completionHandler) 170 { 171 if (!m_processPool) 172 return completionHandler({ }, { }, { }); 173 173 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 { 175 175 SandboxExtension::Handle sandboxExtensionHandle; 176 176 if (!destination.isNull()) 177 177 SandboxExtension::createHandle(destination, SandboxExtension::Type::ReadWrite, sandboxExtensionHandle); 178 178 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); 182 180 }); 183 181 } -
trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h
r261898 r268008 50 50 namespace WebKit { 51 51 52 class DownloadID;53 52 class DownloadProxyMap; 54 53 class WebPageProxy; 55 54 class WebProcessPool; 56 55 class WebsiteDataStore; 56 57 enum class AllowOverwrite : bool; 57 58 58 59 struct FrameInfoData; … … 118 119 void didCancel(const IPC::DataReference& resumeData); 119 120 void willSendRequest(WebCore::ResourceRequest&& redirectRequest, const WebCore::ResourceResponse& redirectResponse); 120 void decideDestinationWithSuggestedFilename Async(DownloadID, const String& suggestedFilename);121 void decideDestinationWithSuggestedFilename(const String& suggestedFilename, CompletionHandler<void(String, SandboxExtension::Handle, AllowOverwrite)>&&); 121 122 122 123 DownloadProxyMap& m_downloadProxyMap; -
trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.messages.in
r261898 r268008 25 25 DidReceiveAuthenticationChallenge(WebCore::AuthenticationChallenge challenge, uint64_t challengeID) 26 26 WillSendRequest(WebCore::ResourceRequest redirectRequest, WebCore::ResourceResponse redirectResponse)) 27 DecideDestinationWithSuggestedFilename Async(WebKit::DownloadID downloadID, String suggestedFilename)27 DecideDestinationWithSuggestedFilename(String suggestedFilename) -> (String filename, WebKit::SandboxExtension::Handle handle, enum:bool WebKit::AllowOverwrite allowOverwrite) Async 28 28 29 29 DidReceiveResponse(WebCore::ResourceResponse response)
Note: See TracChangeset
for help on using the changeset viewer.