Commit cf62ba45 authored by japhet@chromium.org's avatar japhet@chromium.org

location.reload() after POST should re-POST

Currently, location.reload() always triggers a get. Change it to go through
the FrameLoaer::reload() path, like a user-initiated reload.

This aligns our behavior with firefox and IE.

BUG=6429
TEST=http/tests/navigation/location-reload-after-post.php

Review URL: https://codereview.chromium.org/410223003

git-svn-id: svn://svn.chromium.org/blink/trunk@179176 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e3e0bdf0
http://127.0.0.1:8000/navigation/location-reload-after-post.php - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/navigation/location-reload-after-post.php, main document URL http://127.0.0.1:8000/navigation/location-reload-after-post.php, http method POST> redirectResponse (null)
http://127.0.0.1:8000/navigation/location-reload-after-post.php - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/navigation/location-reload-after-post.php, http status code 200>
http://127.0.0.1:8000/navigation/location-reload-after-post.php - didFinishLoading
http://127.0.0.1:8000/navigation/location-reload-after-post.php - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/navigation/location-reload-after-post.php, main document URL http://127.0.0.1:8000/navigation/location-reload-after-post.php, http method POST> redirectResponse (null)
http://127.0.0.1:8000/navigation/location-reload-after-post.php - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/navigation/location-reload-after-post.php, http status code 200>
http://127.0.0.1:8000/navigation/location-reload-after-post.php - didFinishLoading
<body>
<form method=post>
<input type=submit></input>
</form>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.dumpResourceLoadCallbacks();
testRunner.waitUntilDone();
}
window.onload = function() {
setTimeout(function() {
if (sessionStorage.getItem("reloadAfterPost") == null) {
sessionStorage.setItem("reloadAfterPost", "step1");
document.forms[0].submit();
} else if (sessionStorage.getItem("reloadAfterPost") == "step1") {
sessionStorage.setItem("reloadAfterPost", "step2");
location.reload();
} else {
sessionStorage.removeItem("reloadAfterPost");
if (window.testRunner)
testRunner.notifyDone();
}
}, 0);
};
</script>
</body>
......@@ -817,7 +817,7 @@ ResourceRequest FrameLoader::requestFromHistoryItem(HistoryItem* item, ResourceR
return request;
}
void FrameLoader::reload(ReloadPolicy reloadPolicy, const KURL& overrideURL, const AtomicString& overrideEncoding)
void FrameLoader::reload(ReloadPolicy reloadPolicy, const KURL& overrideURL, const AtomicString& overrideEncoding, ClientRedirectPolicy clientRedirectPolicy)
{
if (!m_currentItem)
return;
......@@ -826,13 +826,23 @@ void FrameLoader::reload(ReloadPolicy reloadPolicy, const KURL& overrideURL, con
ResourceRequest request = requestFromHistoryItem(m_currentItem.get(), cachePolicy);
request.setFrameType(m_frame->isMainFrame() ? WebURLRequest::FrameTypeTopLevel : WebURLRequest::FrameTypeNested);
request.setRequestContext(WebURLRequest::RequestContextInternal);
// ClientRedirectPolicy is an indication that this load was triggered by
// some direct interaction with the page. If this reload is not a client
// redirect, we should reuse the referrer from the original load of the
// current document. If this reload is a client redirect (e.g., location.reload()),
// it was initiated by something in the current document and should
// therefore show the current document's url as the referrer.
if (clientRedirectPolicy == ClientRedirect)
request.setHTTPReferrer(Referrer(m_frame->document()->outgoingReferrer(), m_frame->document()->referrerPolicy()));
if (!overrideURL.isEmpty()) {
request.setURL(overrideURL);
request.clearHTTPReferrer();
}
FrameLoadType type = reloadPolicy == EndToEndReload ? FrameLoadTypeReloadFromOrigin : FrameLoadTypeReload;
loadWithNavigationAction(NavigationAction(request, type), type, nullptr, SubstituteData(), CheckContentSecurityPolicy, NotClientRedirect, overrideEncoding);
loadWithNavigationAction(NavigationAction(request, type), type, nullptr, SubstituteData(), CheckContentSecurityPolicy, clientRedirectPolicy, overrideEncoding);
}
void FrameLoader::stopAllLoaders()
......
......@@ -89,7 +89,7 @@ public:
// These functions start a load. All eventually call into loadWithNavigationAction() or loadInSameDocument().
void load(const FrameLoadRequest&); // The entry point for non-reload, non-history loads.
void reload(ReloadPolicy = NormalReload, const KURL& overrideURL = KURL(), const AtomicString& overrideEncoding = nullAtom);
void reload(ReloadPolicy = NormalReload, const KURL& overrideURL = KURL(), const AtomicString& overrideEncoding = nullAtom, ClientRedirectPolicy = NotClientRedirect);
void loadHistoryItem(HistoryItem*, HistoryLoadType = HistoryDifferentDocumentLoad, ResourceRequestCachePolicy = UseProtocolCachePolicy); // The entry point for all back/forward loads
static void reportLocalLoadFailed(LocalFrame*, const String& url);
......
......@@ -157,20 +157,17 @@ public:
: ScheduledURLNavigation(0.0, originDocument, url, referrer, lockBackForwardList, true) { }
};
class ScheduledRefresh FINAL : public ScheduledURLNavigation {
class ScheduledRefresh FINAL : public ScheduledNavigation {
public:
ScheduledRefresh(Document* originDocument, const String& url, const Referrer& referrer)
: ScheduledURLNavigation(0.0, originDocument, url, referrer, true, true)
ScheduledRefresh()
: ScheduledNavigation(0.0, true, true)
{
}
virtual void fire(LocalFrame* frame) OVERRIDE
{
OwnPtr<UserGestureIndicator> gestureIndicator = createUserGestureIndicator();
FrameLoadRequest request(originDocument(), ResourceRequest(KURL(ParsedURLString, url()), referrer(), ReloadIgnoringCacheData), "_self");
request.setLockBackForwardList(lockBackForwardList());
request.setClientRedirect(ClientRedirect);
frame->loader().load(request);
frame->loader().reload(NormalReload, KURL(), nullAtom, ClientRedirect);
}
};
......@@ -343,11 +340,9 @@ void NavigationScheduler::scheduleRefresh()
{
if (!shouldScheduleNavigation())
return;
const KURL& url = m_frame->document()->url();
if (url.isEmpty())
if (m_frame->document()->url().isEmpty())
return;
schedule(adoptPtr(new ScheduledRefresh(m_frame->document(), url.string(), Referrer(m_frame->document()->outgoingReferrer(), m_frame->document()->referrerPolicy()))));
schedule(adoptPtr(new ScheduledRefresh));
}
void NavigationScheduler::scheduleHistoryNavigation(int steps)
......
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