Commit 8cd793e6 authored by toyoshim's avatar toyoshim Committed by Commit bot

FasterLocationReload: use ReloadMainResource for JS exposed reloads

Now all reloads triggered by user interfaces are replaced by
ReloadMainResource, but Location.reload() and History.go() still call
the traditional Reload.

This patch changes them to call ReloadMainResource insteads under a
runtime flag. This flag will be wired to a field study flag later.

This is discussed at loading-dev@ in the following thread.
https://groups.google.com/a/chromium.org/d/topic/loading-dev/gD-MPRcfwVA/discussion

BUG=670237

Review-Url: https://codereview.chromium.org/2555963003
Cr-Commit-Position: refs/heads/master@{#438766}
parent 967340a9
<!DOCYUPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
async_test(t => {
let testWindow = null;
let messageCount = 0;
// Test will run on testWindow that is opened below.
// This page just received messages to confirm if tests run expectedly.
const checkReady = e => {
t.step(() => {
// Will receive "READY" twice because of a reload, then receive "PASS".
assert_equals(e.data, "READY", "received message is " + e.data);
messageCount++;
if (messageCount == 2) {
window.removeEventListener("message", checkReady, false);
window.addEventListener("message", e => {
assert_equals(e.data, "PASS", "received message is " + e.data);
t.done();
}, { once: true });
}
// Send back "START" message for "READY".
assert_class_string(testWindow, "Window", "testWindow is invalid");
testWindow.postMessage("START", location.origin);
});
};
window.addEventListener("message", checkReady, false);
// Start a test in a dedicated window because we can not track navigations
// within a test harness.
t.step(() => {
testWindow = open("./resources/location-reload-window.html", "testWindow");
assert_class_string(testWindow, "Window", "window.open() failed");
});
}, "Test location.reload() cache behaviors");
</script>
<!DOCTYPE html>
<html>
<body>
<h1>random</h1>
<script src="./random-cached.cgi"></script>
<script>
const lastRandomNumberKey = "lastRandomNumber";
window.addEventListener("message", e => {
if (e.data != "START") {
window.opener.postMessage("FAIL: unknown; " + e.data, location.origin);
} else {
// window.top.randomNumber should be set by random-cached.cgi.
if (window.top === undefined || window.top.randomNumber === undefined) {
window.opener.postMessage("FAIL: randomNumber isn't defined",
location.origin);
return;
}
// If location.reload() is already triggered, lastRandomNumberKey should be
// stored in the sessionStorage. Otherwise, this is the first load.
const lastRandomNumberString = sessionStorage.getItem(lastRandomNumberKey);
if (lastRandomNumberString !== null) {
// sessionStorage returns DOMString and need to be converted to Number.
const lastRandomNumber = Number(lastRandomNumberString);
// Because the random-cached.cgi is a sub-resource, and set HTTP headers
// to allow caching, location.reload() should follow the cache-protocol to
// reuse the cached resource. That is to say the randomNumber should not
// be changed on the reload.
window.opener.postMessage(lastRandomNumber == top.randomNumber
? "PASS"
: "FAIL: randomNumber was changed",
location.origin);
} else {
// Store the first randomNumber to the sessionStorage, and call reload().
// This window will send "READY" again, then receive "START".
sessionStorage.setItem(lastRandomNumberKey, top.randomNumber);
location.reload();
}
}
}, false);
// Send "READY" message first so that parent window can ensure to send messages.
window.opener.postMessage("READY", location.origin);
</script>
</body>
</html>
...@@ -145,14 +145,19 @@ void History::go(ExecutionContext* context, int delta) { ...@@ -145,14 +145,19 @@ void History::go(ExecutionContext* context, int delta) {
if (!NavigationDisablerForUnload::isNavigationAllowed()) if (!NavigationDisablerForUnload::isNavigationAllowed())
return; return;
if (delta) {
frame()->loader().client()->navigateBackForward(delta);
} else {
// We intentionally call reload() for the current frame if delta is zero. // We intentionally call reload() for the current frame if delta is zero.
// Otherwise, navigation happens on the root frame. // Otherwise, navigation happens on the root frame.
// This behavior is designed in the following spec. // This behavior is designed in the following spec.
// https://html.spec.whatwg.org/multipage/browsers.html#dom-history-go // https://html.spec.whatwg.org/multipage/browsers.html#dom-history-go
if (delta) FrameLoadType reloadType =
frame()->loader().client()->navigateBackForward(delta); RuntimeEnabledFeatures::fasterLocationReloadEnabled()
else ? FrameLoadTypeReloadMainResource
frame()->reload(FrameLoadTypeReload, ClientRedirectPolicy::ClientRedirect); : FrameLoadTypeReload;
frame()->reload(reloadType, ClientRedirectPolicy::ClientRedirect);
}
} }
KURL History::urlForState(const String& urlString) { KURL History::urlForState(const String& urlString) {
......
...@@ -377,6 +377,9 @@ void LocalFrame::reload(FrameLoadType loadType, ...@@ -377,6 +377,9 @@ void LocalFrame::reload(FrameLoadType loadType,
request.setClientRedirect(clientRedirectPolicy); request.setClientRedirect(clientRedirectPolicy);
m_loader.load(request, loadType); m_loader.load(request, loadType);
} else { } else {
if (RuntimeEnabledFeatures::fasterLocationReloadEnabled())
DCHECK_EQ(FrameLoadTypeReloadMainResource, loadType);
else
DCHECK_EQ(FrameLoadTypeReload, loadType); DCHECK_EQ(FrameLoadTypeReload, loadType);
m_navigationScheduler->scheduleReload(); m_navigationScheduler->scheduleReload();
} }
......
...@@ -248,7 +248,11 @@ void Location::reload(LocalDOMWindow* currentWindow) { ...@@ -248,7 +248,11 @@ void Location::reload(LocalDOMWindow* currentWindow) {
return; return;
if (protocolIsJavaScript(toLocalFrame(m_frame)->document()->url())) if (protocolIsJavaScript(toLocalFrame(m_frame)->document()->url()))
return; return;
m_frame->reload(FrameLoadTypeReload, ClientRedirectPolicy::ClientRedirect); FrameLoadType reloadType =
RuntimeEnabledFeatures::fasterLocationReloadEnabled()
? FrameLoadTypeReloadMainResource
: FrameLoadTypeReload;
m_frame->reload(reloadType, ClientRedirectPolicy::ClientRedirect);
} }
void Location::setLocation(const String& url, void Location::setLocation(const String& url,
......
...@@ -271,6 +271,9 @@ class ScheduledReload final : public ScheduledNavigation { ...@@ -271,6 +271,9 @@ class ScheduledReload final : public ScheduledNavigation {
request.setClientRedirect(ClientRedirectPolicy::ClientRedirect); request.setClientRedirect(ClientRedirectPolicy::ClientRedirect);
maybeLogScheduledNavigationClobber(ScheduledNavigationType::ScheduledReload, maybeLogScheduledNavigationClobber(ScheduledNavigationType::ScheduledReload,
frame); frame);
if (RuntimeEnabledFeatures::fasterLocationReloadEnabled())
frame->loader().load(request, FrameLoadTypeReloadMainResource);
else
frame->loader().load(request, FrameLoadTypeReload); frame->loader().load(request, FrameLoadTypeReload);
} }
......
...@@ -95,6 +95,7 @@ DocumentWriteEvaluator ...@@ -95,6 +95,7 @@ DocumentWriteEvaluator
DOMConvenienceAPI status=stable DOMConvenienceAPI status=stable
DurableStorage status=stable DurableStorage status=stable
ExpensiveBackgroundTimerThrottling status=experimental ExpensiveBackgroundTimerThrottling status=experimental
FasterLocationReload status=experimental
FontCacheScaling status=test FontCacheScaling status=test
ForceDisplayList2dCanvas ForceDisplayList2dCanvas
// See crbug.com/585250. // See crbug.com/585250.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment