Skip to content

Commit

Permalink
[Navigation] Support download navigations
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=272349

Reviewed by Alex Christensen.

Implement detecting download requests and firing a navigate event for them [1].

[1] https://html.spec.whatwg.org/multipage/nav-history-apis.html#fire-a-download-request-navigate-event

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-anchor-download-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-anchor-download-userInitiated-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/ordering-and-transition/anchor-download-expected.txt:
* Source/WebCore/loader/PolicyChecker.cpp:
(WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
* Source/WebCore/page/Navigation.cpp:
(WebCore::Navigation::dispatchDownloadNavigateEvent):

Canonical link: https://commits.webkit.org/278950@main
  • Loading branch information
rwlbuis committed May 18, 2024
1 parent 596b3b0 commit d41105b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

Harness Error (TIMEOUT), message = null

TIMEOUT <a> fires navigate and populates downloadRequest with '' Test timed out
TIMEOUT <a> fires navigate and populates downloadRequest with 'filename' Test timed out
TIMEOUT <area> fires navigate and populates downloadRequest with '' Test timed out
TIMEOUT <area> fires navigate and populates downloadRequest with 'filename' Test timed out
PASS <a> fires navigate and populates downloadRequest with ''
PASS <a> fires navigate and populates downloadRequest with 'filename'
PASS <area> fires navigate and populates downloadRequest with ''
PASS <area> fires navigate and populates downloadRequest with 'filename'

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Click me

Harness Error (TIMEOUT), message = null

TIMEOUT <a download> click fires navigate event Test timed out
PASS <a download> click fires navigate event

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


FAIL <a download> fires navigate, but not navigatesuccess or navigateerror when not intercepted by intercept() assert_true: expected true got false
PASS <a download> fires navigate, but not navigatesuccess or navigateerror when not intercepted by intercept()

10 changes: 10 additions & 0 deletions Source/WebCore/loader/PolicyChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "LocalFrame.h"
#include "LocalFrameLoaderClient.h"
#include "Logging.h"
#include "Navigation.h"
#include "ThreadableBlobRegistry.h"
#include "URLKeepingBlobAlive.h"
#include <wtf/CompletionHandler.h>
Expand Down Expand Up @@ -206,6 +207,15 @@ void PolicyChecker::checkNavigationPolicy(ResourceRequest&& request, const Resou
bool isInitialEmptyDocumentLoad = !frameLoader->stateMachine().committedFirstRealDocumentLoad() && request.url().protocolIsAbout() && !substituteData.isValid();
m_delegateIsDecidingNavigationPolicy = true;
String suggestedFilename = action.downloadAttribute().isEmpty() ? nullAtom() : action.downloadAttribute();
if (!action.downloadAttribute().isNull()) {
RefPtr document = frame->document();
if (document && document->settings().navigationAPIEnabled()) {
if (RefPtr domWindow = document->domWindow()) {
if (!domWindow->protectedNavigation()->dispatchDownloadNavigateEvent(request.url(), action.downloadAttribute()))
return function({ }, nullptr, NavigationPolicyDecision::IgnoreLoad);
}
}
}
FramePolicyFunction decisionHandler = [
this,
weakThis = WeakPtr { *this },
Expand Down
7 changes: 3 additions & 4 deletions Source/WebCore/page/Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,10 @@ bool Navigation::dispatchPushReplaceReloadNavigateEvent(const URL& url, Navigati
}

// https://html.spec.whatwg.org/multipage/nav-history-apis.html#fire-a-download-request-navigate-event
bool Navigation::dispatchDownloadNavigateEvent(const URL&, const String& downloadFilename)
bool Navigation::dispatchDownloadNavigateEvent(const URL& url, const String& downloadFilename)
{
// FIXME
UNUSED_PARAM(downloadFilename);
return false;
Ref destination = NavigationDestination::create(url, nullptr, false);
return innerDispatchNavigateEvent(NavigationNavigationType::Push, WTFMove(destination), downloadFilename);
}

} // namespace WebCore

0 comments on commit d41105b

Please sign in to comment.