Skip to content

Commit 620bf81

Browse files
Do not stop navigation when fragment navigation starts
1 parent 3fc6679 commit 620bf81

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

Source/WebCore/loader/FrameLoader.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,23 +1349,6 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref
13491349
if (m_inStopAllLoaders || m_inClearProvisionalLoadForPolicyCheck)
13501350
return;
13511351

1352-
static bool keepNavigationOnFragmentLoad = false;
1353-
static bool keepNavigationOnFragmentLoadInitialized = false;
1354-
1355-
if (!keepNavigationOnFragmentLoadInitialized) {
1356-
keepNavigationOnFragmentLoad = !!getenv("WPE_KEEP_NAVIGATION_ON_FRAGMENT_LOAD");
1357-
keepNavigationOnFragmentLoadInitialized = true;
1358-
}
1359-
1360-
// If we have a policy or provisional request for a different document, a fragment scroll should be cancelled.
1361-
if (keepNavigationOnFragmentLoad && (m_policyDocumentLoader && !equalIgnoringFragmentIdentifier(m_policyDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()) ||
1362-
m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()))) {
1363-
const auto fragmentNavigationURL = frameLoadRequest.resourceRequest().url();
1364-
const auto navigationURL = m_policyDocumentLoader ? m_policyDocumentLoader->request().url(): m_provisionalDocumentLoader->request().url();
1365-
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());
1366-
return;
1367-
}
1368-
13691352
Ref<Frame> protect(m_frame);
13701353

13711354
// Anchor target is ignored when the download attribute is set since it will download the hyperlink rather than follow it.
@@ -1427,14 +1410,40 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref
14271410
// exactly the same so pages with '#' links and DHTML side effects
14281411
// work properly.
14291412
if (shouldPerformFragmentNavigation(isFormSubmission, httpMethod, newLoadType, newURL)) {
1413+
1414+
static bool keepNavigationOnFragmentLoad = false;
1415+
static bool keepNavigationOnFragmentLoadInitialized = false;
1416+
1417+
if (!keepNavigationOnFragmentLoadInitialized) {
1418+
keepNavigationOnFragmentLoad = !!getenv("WPE_KEEP_NAVIGATION_ON_FRAGMENT_LOAD");
1419+
keepNavigationOnFragmentLoadInitialized = true;
1420+
}
1421+
14301422
oldDocumentLoader->setTriggeringAction(WTFMove(action));
14311423
oldDocumentLoader->setLastCheckedRequest(ResourceRequest());
1432-
policyChecker().stopCheck();
1424+
auto loadType = policyChecker().loadType();
1425+
bool resetLoadTypeAfterFragmentNavigation = false;
1426+
if (keepNavigationOnFragmentLoad && (m_policyDocumentLoader && !equalIgnoringFragmentIdentifier(m_policyDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()) ||
1427+
m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()))) {
1428+
resetLoadTypeAfterFragmentNavigation = true;
1429+
1430+
const auto fragmentNavigationURL = frameLoadRequest.resourceRequest().url();
1431+
const auto navigationURL = m_policyDocumentLoader ? m_policyDocumentLoader->request().url(): m_provisionalDocumentLoader->request().url();
1432+
FRAMELOADER_RELEASE_LOG(ResourceLoading, "loadURL: navigation to: %s will be continued after fragment navigation to url: %s",
1433+
navigationURL.string().utf8().data(), fragmentNavigationURL.string().utf8().data());
1434+
} else {
1435+
policyChecker().stopCheck();
1436+
}
1437+
14331438
policyChecker().setLoadType(newLoadType);
14341439
RELEASE_ASSERT(!isBackForwardLoadType(newLoadType) || history().provisionalItem());
14351440
policyChecker().checkNavigationPolicy(WTFMove(request), ResourceResponse { } /* redirectResponse */, oldDocumentLoader.get(), WTFMove(formState), [this, protectedFrame = Ref { m_frame }, requesterOrigin = Ref { frameLoadRequest.requesterSecurityOrigin() }] (const ResourceRequest& request, WeakPtr<FormState>&&, NavigationPolicyDecision navigationPolicyDecision) {
14361441
continueFragmentScrollAfterNavigationPolicy(request, requesterOrigin.ptr(), navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad);
14371442
}, PolicyDecisionMode::Synchronous);
1443+
1444+
if (resetLoadTypeAfterFragmentNavigation)
1445+
policyChecker().setLoadType(loadType);
1446+
14381447
return;
14391448
}
14401449

0 commit comments

Comments
 (0)