Skip to content

Commit

Permalink
Merge pull request #1369 from WebPlatformForEmbedded/pgorszkowski/2.3…
Browse files Browse the repository at this point in the history
…8/do_not_stop_navigation_when_fragment_navigation_starts

Do not stop navigation when fragment navigation starts
  • Loading branch information
magomez authored Jul 22, 2024
2 parents dfbdfe7 + 620bf81 commit 4c6f6d1
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions Source/WebCore/loader/FrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,23 +1349,6 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref
if (m_inStopAllLoaders || m_inClearProvisionalLoadForPolicyCheck)
return;

static bool keepNavigationOnFragmentLoad = false;
static bool keepNavigationOnFragmentLoadInitialized = false;

if (!keepNavigationOnFragmentLoadInitialized) {
keepNavigationOnFragmentLoad = !!getenv("WPE_KEEP_NAVIGATION_ON_FRAGMENT_LOAD");
keepNavigationOnFragmentLoadInitialized = true;
}

// If we have a policy or provisional request for a different document, a fragment scroll should be cancelled.
if (keepNavigationOnFragmentLoad && (m_policyDocumentLoader && !equalIgnoringFragmentIdentifier(m_policyDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()) ||
m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()))) {
const auto fragmentNavigationURL = frameLoadRequest.resourceRequest().url();
const auto navigationURL = m_policyDocumentLoader ? m_policyDocumentLoader->request().url(): m_provisionalDocumentLoader->request().url();
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());
return;
}

Ref<Frame> protect(m_frame);

// Anchor target is ignored when the download attribute is set since it will download the hyperlink rather than follow it.
Expand Down Expand Up @@ -1427,14 +1410,40 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref
// exactly the same so pages with '#' links and DHTML side effects
// work properly.
if (shouldPerformFragmentNavigation(isFormSubmission, httpMethod, newLoadType, newURL)) {

static bool keepNavigationOnFragmentLoad = false;
static bool keepNavigationOnFragmentLoadInitialized = false;

if (!keepNavigationOnFragmentLoadInitialized) {
keepNavigationOnFragmentLoad = !!getenv("WPE_KEEP_NAVIGATION_ON_FRAGMENT_LOAD");
keepNavigationOnFragmentLoadInitialized = true;
}

oldDocumentLoader->setTriggeringAction(WTFMove(action));
oldDocumentLoader->setLastCheckedRequest(ResourceRequest());
policyChecker().stopCheck();
auto loadType = policyChecker().loadType();
bool resetLoadTypeAfterFragmentNavigation = false;
if (keepNavigationOnFragmentLoad && (m_policyDocumentLoader && !equalIgnoringFragmentIdentifier(m_policyDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()) ||
m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()))) {
resetLoadTypeAfterFragmentNavigation = true;

const auto fragmentNavigationURL = frameLoadRequest.resourceRequest().url();
const auto navigationURL = m_policyDocumentLoader ? m_policyDocumentLoader->request().url(): m_provisionalDocumentLoader->request().url();
FRAMELOADER_RELEASE_LOG(ResourceLoading, "loadURL: navigation to: %s will be continued after fragment navigation to url: %s",
navigationURL.string().utf8().data(), fragmentNavigationURL.string().utf8().data());
} else {
policyChecker().stopCheck();
}

policyChecker().setLoadType(newLoadType);
RELEASE_ASSERT(!isBackForwardLoadType(newLoadType) || history().provisionalItem());
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) {
continueFragmentScrollAfterNavigationPolicy(request, requesterOrigin.ptr(), navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad);
}, PolicyDecisionMode::Synchronous);

if (resetLoadTypeAfterFragmentNavigation)
policyChecker().setLoadType(loadType);

return;
}

Expand Down

0 comments on commit 4c6f6d1

Please sign in to comment.