Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1200)

Unified Diff: Source/core/loader/FrameLoader.cpp

Issue 1156473002: Refactor FrameLoader loading interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/loader/FrameLoader.cpp
diff --git a/Source/core/loader/FrameLoader.cpp b/Source/core/loader/FrameLoader.cpp
index a149db46df552e8469c22ddf1f6ea177c05ac10e..c02c2c57d1277d5719c8e815e0087ffc6a8944f4 100644
--- a/Source/core/loader/FrameLoader.cpp
+++ b/Source/core/loader/FrameLoader.cpp
@@ -105,7 +105,64 @@ bool isBackForwardLoadType(FrameLoadType type)
static bool needsHistoryItemRestore(FrameLoadType type)
{
- return type == FrameLoadTypeBackForward || type == FrameLoadTypeReload || type == FrameLoadTypeReloadFromOrigin;
+ return type == FrameLoadTypeBackForward || type == FrameLoadTypeReload
+ || type == FrameLoadTypeReloadFromOrigin;
+}
+
+// static
+ResourceRequest FrameLoader::resourceRequestFromHistoryItem(HistoryItem* item,
+ ResourceRequestCachePolicy cachePolicy)
+{
+ RefPtr<FormData> formData = item->formData();
+ ResourceRequest request(item->url());
+ request.setHTTPReferrer(item->referrer());
+ request.setCachePolicy(cachePolicy);
+ if (formData) {
+ request.setHTTPMethod("POST");
+ request.setHTTPBody(formData);
+ request.setHTTPContentType(item->formContentType());
+ RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::createFromString(item->referrer().referrer);
+ request.addHTTPOriginIfNeeded(securityOrigin->toAtomicString());
+ }
+ return request;
+}
+
+ResourceRequest FrameLoader::resourceRequestForReload(const LocalFrame& frame,
+ FrameLoadType frameLoadType, const KURL& overrideURL, ClientRedirectPolicy clientRedirectPolicy)
+{
+ ASSERT(frameLoadType == FrameLoadTypeReload || frameLoadType == FrameLoadTypeReloadFromOrigin);
+ ResourceRequestCachePolicy cachePolicy = frameLoadType == FrameLoadTypeReloadFromOrigin ?
+ ReloadBypassingCache : ReloadIgnoringCacheData;
+ if (!m_currentItem)
+ return ResourceRequest();
+ ResourceRequest request = resourceRequestFromHistoryItem(m_currentItem.get(), cachePolicy);
+
+ // 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(frame.document()->outgoingReferrer(),
+ frame.document()->referrerPolicy()));
+ }
+
+ if (!overrideURL.isEmpty()) {
+ request.setURL(overrideURL);
+ request.clearHTTPReferrer();
+ }
+ request.setSkipServiceWorker(frameLoadType == FrameLoadTypeReloadFromOrigin);
+ return request;
+}
+
+// static
+FrameLoadRequest FrameLoader::frameRequestForReload(const ResourceRequest& resourceRequest,
+ ClientRedirectPolicy clientRedirectPolicy)
+{
+ FrameLoadRequest request = FrameLoadRequest(nullptr, resourceRequest);
+ request.setClientRedirect(clientRedirectPolicy);
+ return request;
}
FrameLoader::FrameLoader(LocalFrame* frame)
@@ -169,8 +226,9 @@ void FrameLoader::setDefersLoading(bool defers)
if (!defers) {
if (m_deferredHistoryLoad.isValid()) {
- loadHistoryItem(m_deferredHistoryLoad.m_item.get(), FrameLoadTypeBackForward,
- m_deferredHistoryLoad.m_type, m_deferredHistoryLoad.m_cachePolicy);
+ load(FrameLoadRequest(nullptr, m_deferredHistoryLoad.m_request),
+ m_deferredHistoryLoad.m_loadType, m_deferredHistoryLoad.m_item.get(),
+ m_deferredHistoryLoad.m_historyLoadType);
m_deferredHistoryLoad = DeferredHistoryLoad();
}
m_frame->navigationScheduler().startTimer();
@@ -394,8 +452,9 @@ void FrameLoader::didBeginDocument(bool dispatch)
}
}
- if (m_provisionalItem && (m_loadType == FrameLoadTypeBackForward || m_loadType == FrameLoadTypeInitialHistoryLoad))
+ if (m_provisionalItem && isBackForwardLoadType(m_loadType)) {
Nate Chapin 2015/06/02 17:19:35 Nit: No {} needed
clamy 2015/06/03 14:39:14 Done.
m_frame->document()->setStateForNewFormElements(m_provisionalItem->documentState());
+ }
client()->didCreateNewDocument();
}
@@ -756,7 +815,8 @@ static NavigationPolicy navigationPolicyForRequest(const FrameLoadRequest& reque
return policy;
}
-void FrameLoader::load(const FrameLoadRequest& passedRequest)
+void FrameLoader::load(const FrameLoadRequest& passedRequest, FrameLoadType frameLoadType,
+ HistoryItem* historyItem, HistoryLoadType historyLoadType)
{
ASSERT(m_frame->document());
@@ -765,12 +825,23 @@ void FrameLoader::load(const FrameLoadRequest& passedRequest)
if (m_inStopAllLoaders)
return;
+ if (m_frame->page()->defersLoading() && isBackForwardLoadType(frameLoadType)) {
+ m_deferredHistoryLoad = DeferredHistoryLoad(
+ passedRequest.resourceRequest(), historyItem, frameLoadType, historyLoadType);
+ return;
+ }
+
FrameLoadRequest request(passedRequest);
request.resourceRequest().setHasUserGesture(UserGestureIndicator::processingUserGesture());
if (!prepareRequestForThisFrame(request))
return;
+ if (isBackForwardLoadType(frameLoadType)) {
+ ASSERT(historyItem);
+ m_provisionalItem = historyItem;
+ }
+
RefPtrWillBeRawPtr<LocalFrame> targetFrame = toLocalFrame(request.form() ? nullptr : m_frame->findFrameForNavigation(AtomicString(request.frameName()), *m_frame));
if (targetFrame && targetFrame.get() != m_frame) {
bool wasInSamePage = targetFrame->page() == m_frame->page();
@@ -785,7 +856,8 @@ void FrameLoader::load(const FrameLoadRequest& passedRequest)
setReferrerForFrameRequest(request.resourceRequest(), request.shouldSendReferrer(), request.originDocument());
- FrameLoadType newLoadType = determineFrameLoadType(request);
+ FrameLoadType newLoadType = (frameLoadType == FrameLoadTypeStandard) ?
+ determineFrameLoadType(request) : frameLoadType;
NavigationPolicy policy = navigationPolicyForRequest(request);
if (shouldOpenInNewWindow(targetFrame.get(), request, policy)) {
if (policy == NavigationPolicyDownload) {
@@ -798,20 +870,39 @@ void FrameLoader::load(const FrameLoadRequest& passedRequest)
}
const KURL& url = request.resourceRequest().url();
- if (policy == NavigationPolicyCurrentTab && shouldPerformFragmentNavigation(request.form(), request.resourceRequest().httpMethod(), newLoadType, url)) {
+
+ // Perform history same document navigation.
+ if (isBackForwardLoadType(newLoadType) && historyLoadType == HistorySameDocumentLoad) {
Nate Chapin 2015/06/02 17:19:35 Is it possible to collapse this block into the sam
clamy 2015/06/03 14:39:14 Done.
+ ASSERT(historyItem);
+ loadInSameDocument(url, historyItem->stateObject(), newLoadType, NotClientRedirect);
+ restoreScrollPositionAndViewState();
+ return;
+ }
+
+ // Perform non-history same document navigation.
+ if ((policy == NavigationPolicyCurrentTab
+ && shouldPerformFragmentNavigation(request.form(), request.resourceRequest().httpMethod(), newLoadType, url))) {
m_documentLoader->setNavigationType(determineNavigationType(newLoadType, false, request.triggeringEvent()));
if (shouldTreatURLAsSameAsCurrent(url))
newLoadType = FrameLoadTypeRedirectWithLockedBackForwardList;
loadInSameDocument(url, nullptr, newLoadType, request.clientRedirect());
return;
}
+
+ // Perform navigation to a different document.
bool sameURL = url == m_documentLoader->urlForHistory();
startLoad(request, newLoadType, policy);
+
// Example of this case are sites that reload the same URL with a different cookie
// driving the generated content, or a master frame with links that drive a target
// frame, where the user has clicked on the same link repeatedly.
- if (sameURL && newLoadType != FrameLoadTypeReload && newLoadType != FrameLoadTypeReloadFromOrigin && request.resourceRequest().httpMethod() != "POST")
+ if (sameURL
+ && !isBackForwardLoadType(frameLoadType)
+ && newLoadType != FrameLoadTypeReload
+ && newLoadType != FrameLoadTypeReloadFromOrigin
+ && request.resourceRequest().httpMethod() != "POST") {
m_loadType = FrameLoadTypeSame;
+ }
}
SubstituteData FrameLoader::defaultSubstituteDataForURL(const KURL& url)
@@ -833,50 +924,6 @@ void FrameLoader::reportLocalLoadFailed(LocalFrame* frame, const String& url)
frame->document()->addConsoleMessage(ConsoleMessage::create(SecurityMessageSource, ErrorMessageLevel, "Not allowed to load local resource: " + url));
}
-// static
-ResourceRequest FrameLoader::requestFromHistoryItem(HistoryItem* item, ResourceRequestCachePolicy cachePolicy)
-{
- RefPtr<FormData> formData = item->formData();
- ResourceRequest request(item->url());
- request.setHTTPReferrer(item->referrer());
- request.setCachePolicy(cachePolicy);
- if (formData) {
- request.setHTTPMethod("POST");
- request.setHTTPBody(formData);
- request.setHTTPContentType(item->formContentType());
- RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::createFromString(item->referrer().referrer);
- request.addHTTPOriginIfNeeded(securityOrigin->toAtomicString());
- }
- return request;
-}
-
-void FrameLoader::reload(ReloadPolicy reloadPolicy, const KURL& overrideURL, ClientRedirectPolicy clientRedirectPolicy)
-{
- if (!m_currentItem)
- return;
-
- ResourceRequestCachePolicy cachePolicy = reloadPolicy == EndToEndReload ? ReloadBypassingCache : ReloadIgnoringCacheData;
- ResourceRequest request = requestFromHistoryItem(m_currentItem.get(), cachePolicy);
-
- // 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();
- }
- request.setSkipServiceWorker(reloadPolicy == EndToEndReload);
- FrameLoadRequest frameLoadRequest(nullptr, request);
- frameLoadRequest.setClientRedirect(clientRedirectPolicy);
- startLoad(frameLoadRequest, reloadPolicy == EndToEndReload ? FrameLoadTypeReloadFromOrigin : FrameLoadTypeReload, NavigationPolicyCurrentTab);
-}
-
void FrameLoader::stopAllLoaders()
{
if (m_frame->document()->pageDismissalEventBeingDispatched() != Document::NoDismissal)
@@ -1125,11 +1172,11 @@ void FrameLoader::receivedMainResourceError(DocumentLoader* loader, const Resour
bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, const String& httpMethod, FrameLoadType loadType, const KURL& url)
{
- ASSERT(loadType != FrameLoadTypeReloadFromOrigin);
// We don't do this if we are submitting a form with method other than "GET", explicitly reloading,
// currently displaying a frameset, or if the URL does not have a fragment.
return (!isFormSubmission || equalIgnoringCase(httpMethod, "GET"))
&& loadType != FrameLoadTypeReload
+ && loadType != FrameLoadTypeReloadFromOrigin
&& loadType != FrameLoadTypeSame
&& loadType != FrameLoadTypeBackForward
&& url.hasFragmentIdentifier()
@@ -1335,24 +1382,6 @@ bool FrameLoader::shouldTreatURLAsSrcdocDocument(const KURL& url) const
return ownerElement->fastHasAttribute(srcdocAttr);
}
-void FrameLoader::loadHistoryItem(HistoryItem* item, FrameLoadType frameLoadType, HistoryLoadType historyLoadType, ResourceRequestCachePolicy cachePolicy)
-{
- RefPtrWillBeRawPtr<LocalFrame> protect(m_frame.get());
- if (m_frame->page()->defersLoading()) {
- m_deferredHistoryLoad = DeferredHistoryLoad(item, historyLoadType, cachePolicy);
- return;
- }
-
- m_provisionalItem = item;
- if (historyLoadType == HistorySameDocumentLoad) {
- loadInSameDocument(item->url(), item->stateObject(), frameLoadType, NotClientRedirect);
- restoreScrollPositionAndViewState();
- return;
- }
- FrameLoadRequest request(nullptr, requestFromHistoryItem(item, cachePolicy));
- startLoad(request, frameLoadType, NavigationPolicyCurrentTab);
-}
-
void FrameLoader::dispatchDocumentElementAvailable()
{
client()->documentElementAvailable();

Powered by Google App Engine
This is Rietveld 408576698