Skip to content

Commit 6be9149

Browse files
authored
Merge pull request #1375 from WebPlatformForEmbedded/pgorszkowski/next/do_not_stop_navigation_when_fragment_navigation_starts
Do not stop navigation when fragment navigation starts
2 parents fe9ed18 + 5b7580e commit 6be9149

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

Source/WebCore/loader/FrameLoader.cpp

+25-18
Original file line numberDiff line numberDiff line change
@@ -1482,23 +1482,6 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref
14821482
if (m_inStopAllLoaders || m_inClearProvisionalLoadForPolicyCheck)
14831483
return;
14841484

1485-
static bool keepNavigationOnFragmentLoad = false;
1486-
static bool keepNavigationOnFragmentLoadInitialized = false;
1487-
1488-
if (!keepNavigationOnFragmentLoadInitialized) {
1489-
keepNavigationOnFragmentLoad = !!getenv("WPE_KEEP_NAVIGATION_ON_FRAGMENT_LOAD");
1490-
keepNavigationOnFragmentLoadInitialized = true;
1491-
}
1492-
1493-
// If we have a policy or provisional request for a different document, a fragment scroll should be cancelled.
1494-
if (keepNavigationOnFragmentLoad && (m_policyDocumentLoader && !equalIgnoringFragmentIdentifier(m_policyDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()) ||
1495-
m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()))) {
1496-
const auto fragmentNavigationURL = frameLoadRequest.resourceRequest().url();
1497-
const auto navigationURL = m_policyDocumentLoader ? m_policyDocumentLoader->request().url(): m_provisionalDocumentLoader->request().url();
1498-
FRAMELOADER_RELEASE_LOG(ResourceLoading, "loadURL: fragment navigation: %s is cancelled because of ongoing navigation change to url: %s", fragmentNavigationURL.string().utf8().data(), navigationURL.string().utf8().data());
1499-
return;
1500-
}
1501-
15021485
Ref frame = m_frame.get();
15031486

15041487
// Anchor target is ignored when the download attribute is set since it will download the hyperlink rather than follow it.
@@ -1577,15 +1560,39 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref
15771560

15781561
if (!dispatchNavigateEvent(newURL, newLoadType, action, frameLoadRequest.navigationHistoryBehavior(), true))
15791562
return;
1563+
static bool keepNavigationOnFragmentLoad = false;
1564+
static bool keepNavigationOnFragmentLoadInitialized = false;
1565+
1566+
if (!keepNavigationOnFragmentLoadInitialized) {
1567+
keepNavigationOnFragmentLoad = !!getenv("WPE_KEEP_NAVIGATION_ON_FRAGMENT_LOAD");
1568+
keepNavigationOnFragmentLoadInitialized = true;
1569+
}
15801570

15811571
oldDocumentLoader->setTriggeringAction(WTFMove(action));
15821572
oldDocumentLoader->setLastCheckedRequest(ResourceRequest());
1583-
policyChecker().stopCheck();
1573+
auto loadType = policyChecker().loadType();
1574+
bool resetLoadTypeAfterFragmentNavigation = false;
1575+
if (keepNavigationOnFragmentLoad && (m_policyDocumentLoader && !equalIgnoringFragmentIdentifier(m_policyDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()) ||
1576+
m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()))) {
1577+
resetLoadTypeAfterFragmentNavigation = true;
1578+
1579+
const auto fragmentNavigationURL = frameLoadRequest.resourceRequest().url();
1580+
const auto navigationURL = m_policyDocumentLoader ? m_policyDocumentLoader->request().url(): m_provisionalDocumentLoader->request().url();
1581+
FRAMELOADER_RELEASE_LOG(ResourceLoading, "loadURL: navigation to: %s will be continued after fragment navigation to url: %s",
1582+
navigationURL.string().utf8().data(), fragmentNavigationURL.string().utf8().data());
1583+
} else {
1584+
policyChecker().stopCheck();
1585+
}
1586+
15841587
policyChecker().setLoadType(newLoadType);
15851588
RELEASE_ASSERT(!isBackForwardLoadType(newLoadType) || frame->history().provisionalItem());
15861589
policyChecker().checkNavigationPolicy(WTFMove(request), ResourceResponse { } /* redirectResponse */, oldDocumentLoader.get(), WTFMove(formState), [this, frame, requesterOrigin = Ref { frameLoadRequest.requesterSecurityOrigin() }, historyHandling = frameLoadRequest.navigationHistoryBehavior()] (const ResourceRequest& request, WeakPtr<FormState>&&, NavigationPolicyDecision navigationPolicyDecision) {
15871590
continueFragmentScrollAfterNavigationPolicy(request, requesterOrigin.ptr(), navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad, historyHandling);
15881591
}, PolicyDecisionMode::Synchronous);
1592+
1593+
if (resetLoadTypeAfterFragmentNavigation)
1594+
policyChecker().setLoadType(loadType);
1595+
15891596
return;
15901597
}
15911598

Source/WebCore/loader/PolicyChecker.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ void PolicyChecker::checkNavigationPolicy(ResourceRequest&& request, const Resou
285285
}
286286

287287
auto documentLoader = frameLoader->loaderForWebsitePolicies();
288+
// PolicyDecisionMode::Synchronous means that it is a FragmentNavigation and in that case we should use documentLoader,
289+
// because there can be ongoing (in policy or provisional state) navigation.
290+
if (policyDecisionMode == PolicyDecisionMode::Synchronous)
291+
documentLoader = frameLoader->documentLoader();
288292
auto clientRedirectSourceForHistory = documentLoader ? documentLoader->clientRedirectSourceForHistory() : String();
289293
auto navigationID = documentLoader ? documentLoader->navigationID() : 0;
290294
bool hasOpener = !!frame->opener();

0 commit comments

Comments
 (0)