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

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameLoader.cpp

Issue 2710983003: Move HistoryItem handling to DocumentLoader (Closed)
Patch Set: Address kinuko's comments Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
6 * (http://www.torchmobile.com/) 6 * (http://www.torchmobile.com/)
7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 7 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 8 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
10 * Copyright (C) 2011 Google Inc. All rights reserved. 10 * Copyright (C) 2011 Google Inc. All rights reserved.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return; 131 return;
132 } 132 }
133 if (SchemeRegistry::shouldTreatURLSchemeAsLegacy( 133 if (SchemeRegistry::shouldTreatURLSchemeAsLegacy(
134 document->getSecurityOrigin()->protocol())) { 134 document->getSecurityOrigin()->protocol())) {
135 return; 135 return;
136 } 136 }
137 Deprecation::countDeprecation( 137 Deprecation::countDeprecation(
138 document, UseCounter::LegacyProtocolEmbeddedAsSubresource); 138 document, UseCounter::LegacyProtocolEmbeddedAsSubresource);
139 } 139 }
140 140
141 // static
142 ResourceRequest FrameLoader::resourceRequestFromHistoryItem(
143 HistoryItem* item,
144 WebCachePolicy cachePolicy) {
145 RefPtr<EncodedFormData> formData = item->formData();
146 ResourceRequest request(item->url());
147 request.setHTTPReferrer(item->referrer());
148 request.setCachePolicy(cachePolicy);
149 if (formData) {
150 request.setHTTPMethod(HTTPNames::POST);
151 request.setHTTPBody(formData);
152 request.setHTTPContentType(item->formContentType());
153 request.addHTTPOriginIfNeeded(item->referrer().referrer);
154 }
155 return request;
156 }
157
158 ResourceRequest FrameLoader::resourceRequestForReload( 141 ResourceRequest FrameLoader::resourceRequestForReload(
159 FrameLoadType frameLoadType, 142 FrameLoadType frameLoadType,
160 const KURL& overrideURL, 143 const KURL& overrideURL,
161 ClientRedirectPolicy clientRedirectPolicy) { 144 ClientRedirectPolicy clientRedirectPolicy) {
162 DCHECK(isReloadLoadType(frameLoadType)); 145 DCHECK(isReloadLoadType(frameLoadType));
163 WebCachePolicy cachePolicy = 146 WebCachePolicy cachePolicy =
164 frameLoadType == FrameLoadTypeReloadBypassingCache 147 frameLoadType == FrameLoadTypeReloadBypassingCache
165 ? WebCachePolicy::BypassingCache 148 ? WebCachePolicy::BypassingCache
166 : WebCachePolicy::ValidatingCacheData; 149 : WebCachePolicy::ValidatingCacheData;
167 if (!m_currentItem) 150 if (!m_documentLoader || !m_documentLoader->historyItem())
168 return ResourceRequest(); 151 return ResourceRequest();
169 ResourceRequest request = 152 ResourceRequest request =
170 resourceRequestFromHistoryItem(m_currentItem.get(), cachePolicy); 153 m_documentLoader->historyItem()->generateResourceRequest(cachePolicy);
171 154
172 // ClientRedirectPolicy is an indication that this load was triggered by some 155 // ClientRedirectPolicy is an indication that this load was triggered by some
173 // direct interaction with the page. If this reload is not a client redirect, 156 // direct interaction with the page. If this reload is not a client redirect,
174 // we should reuse the referrer from the original load of the current 157 // we should reuse the referrer from the original load of the current
175 // document. If this reload is a client redirect (e.g., location.reload()), it 158 // document. If this reload is a client redirect (e.g., location.reload()), it
176 // was initiated by something in the current document and should therefore 159 // was initiated by something in the current document and should therefore
177 // show the current document's url as the referrer. 160 // show the current document's url as the referrer.
178 if (clientRedirectPolicy == ClientRedirectPolicy::ClientRedirect) { 161 if (clientRedirectPolicy == ClientRedirectPolicy::ClientRedirect) {
179 request.setHTTPReferrer(SecurityPolicy::generateReferrer( 162 request.setHTTPReferrer(SecurityPolicy::generateReferrer(
180 m_frame->document()->getReferrerPolicy(), m_frame->document()->url(), 163 m_frame->document()->getReferrerPolicy(), m_frame->document()->url(),
(...skipping 29 matching lines...) Expand all
210 193
211 FrameLoader::~FrameLoader() { 194 FrameLoader::~FrameLoader() {
212 DCHECK(m_detached); 195 DCHECK(m_detached);
213 } 196 }
214 197
215 DEFINE_TRACE(FrameLoader) { 198 DEFINE_TRACE(FrameLoader) {
216 visitor->trace(m_frame); 199 visitor->trace(m_frame);
217 visitor->trace(m_progressTracker); 200 visitor->trace(m_progressTracker);
218 visitor->trace(m_documentLoader); 201 visitor->trace(m_documentLoader);
219 visitor->trace(m_provisionalDocumentLoader); 202 visitor->trace(m_provisionalDocumentLoader);
220 visitor->trace(m_currentItem);
221 visitor->trace(m_provisionalItem);
222 visitor->trace(m_deferredHistoryLoad); 203 visitor->trace(m_deferredHistoryLoad);
223 } 204 }
224 205
225 void FrameLoader::init() { 206 void FrameLoader::init() {
226 ResourceRequest initialRequest(KURL(ParsedURLString, emptyString)); 207 ResourceRequest initialRequest(KURL(ParsedURLString, emptyString));
227 initialRequest.setRequestContext(WebURLRequest::RequestContextInternal); 208 initialRequest.setRequestContext(WebURLRequest::RequestContextInternal);
228 initialRequest.setFrameType(m_frame->isMainFrame() 209 initialRequest.setFrameType(m_frame->isMainFrame()
229 ? WebURLRequest::FrameTypeTopLevel 210 ? WebURLRequest::FrameTypeTopLevel
230 : WebURLRequest::FrameTypeNested); 211 : WebURLRequest::FrameTypeNested);
231 m_provisionalDocumentLoader = 212 m_provisionalDocumentLoader =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 m_deferredHistoryLoad->m_item.get(), 251 m_deferredHistoryLoad->m_item.get(),
271 m_deferredHistoryLoad->m_historyLoadType); 252 m_deferredHistoryLoad->m_historyLoadType);
272 m_deferredHistoryLoad.clear(); 253 m_deferredHistoryLoad.clear();
273 } 254 }
274 m_frame->navigationScheduler().startTimer(); 255 m_frame->navigationScheduler().startTimer();
275 scheduleCheckCompleted(); 256 scheduleCheckCompleted();
276 } 257 }
277 } 258 }
278 259
279 void FrameLoader::saveScrollState() { 260 void FrameLoader::saveScrollState() {
280 if (!m_currentItem || !m_frame->view()) 261 if (!m_documentLoader || !m_documentLoader->historyItem() || !m_frame->view())
281 return; 262 return;
282 263
283 // Shouldn't clobber anything if we might still restore later. 264 // Shouldn't clobber anything if we might still restore later.
284 if (m_documentLoader && 265 if (needsHistoryItemRestore(m_documentLoader->loadType()) &&
285 needsHistoryItemRestore(m_documentLoader->loadType()) &&
286 !m_documentLoader->initialScrollState().wasScrolledByUser) 266 !m_documentLoader->initialScrollState().wasScrolledByUser)
287 return; 267 return;
288 268
269 HistoryItem* historyItem = m_documentLoader->historyItem();
289 if (ScrollableArea* layoutScrollableArea = 270 if (ScrollableArea* layoutScrollableArea =
290 m_frame->view()->layoutViewportScrollableArea()) 271 m_frame->view()->layoutViewportScrollableArea())
291 m_currentItem->setScrollOffset(layoutScrollableArea->getScrollOffset()); 272 historyItem->setScrollOffset(layoutScrollableArea->getScrollOffset());
292 m_currentItem->setVisualViewportScrollOffset(toScrollOffset( 273 historyItem->setVisualViewportScrollOffset(toScrollOffset(
293 m_frame->page()->visualViewport().visibleRect().location())); 274 m_frame->page()->visualViewport().visibleRect().location()));
294 275
295 if (m_frame->isMainFrame()) 276 if (m_frame->isMainFrame())
296 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor()); 277 historyItem->setPageScaleFactor(m_frame->page()->pageScaleFactor());
297 278
298 client()->didUpdateCurrentHistoryItem(); 279 client()->didUpdateCurrentHistoryItem();
299 } 280 }
300 281
301 void FrameLoader::dispatchUnloadEvent() { 282 void FrameLoader::dispatchUnloadEvent() {
302 FrameNavigationDisabler navigationDisabler(*m_frame); 283 FrameNavigationDisabler navigationDisabler(*m_frame);
303 284
304 // If the frame is unloading, the provisional loader should no longer be 285 // If the frame is unloading, the provisional loader should no longer be
305 // protected. It will be detached soon. 286 // protected. It will be detached soon.
306 m_protectProvisionalLoader = false; 287 m_protectProvisionalLoader = false;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 370
390 // detachChildren() potentially detaches the frame from the document. The 371 // detachChildren() potentially detaches the frame from the document. The
391 // loading cannot continue in that case. 372 // loading cannot continue in that case.
392 if (!m_frame->page()) 373 if (!m_frame->page())
393 return; 374 return;
394 375
395 client()->transitionToCommittedForNewPage(); 376 client()->transitionToCommittedForNewPage();
396 documentLoader->replaceDocumentWhileExecutingJavaScriptURL(init, source); 377 documentLoader->replaceDocumentWhileExecutingJavaScriptURL(init, source);
397 } 378 }
398 379
399 void FrameLoader::clearProvisionalHistoryItem() {
400 m_provisionalItem.clear();
401 }
402
403 void FrameLoader::setHistoryItemStateForCommit(
404 FrameLoadType loadType,
405 HistoryCommitType historyCommitType,
406 HistoryNavigationType navigationType) {
407 HistoryItem* oldItem = m_currentItem;
408 if (isBackForwardLoadType(loadType) && m_provisionalItem)
409 m_currentItem = m_provisionalItem.release();
410 else
411 m_currentItem = HistoryItem::create();
412 m_currentItem->setURL(m_documentLoader->urlForHistory());
413 m_currentItem->setDocumentState(m_frame->document()->formElementsState());
414 m_currentItem->setReferrer(SecurityPolicy::generateReferrer(
415 m_documentLoader->getRequest().getReferrerPolicy(), m_currentItem->url(),
416 m_documentLoader->getRequest().httpReferrer()));
417 m_currentItem->setFormInfoFromRequest(m_documentLoader->getRequest());
418
419 // Don't propagate state from the old item to the new item if there isn't an
420 // old item (obviously), or if this is a back/forward navigation, since we
421 // explicitly want to restore the state we just committed.
422 if (!oldItem || isBackForwardLoadType(loadType))
423 return;
424 // Don't propagate state from the old item if this is a different-document
425 // navigation, unless the before and after pages are logically related. This
426 // means they have the same url (ignoring fragment) and the new item was
427 // loaded via reload or client redirect.
428 if (navigationType == HistoryNavigationType::DifferentDocument &&
429 (historyCommitType != HistoryInertCommit ||
430 !equalIgnoringFragmentIdentifier(oldItem->url(), m_currentItem->url())))
431 return;
432 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber());
433 m_currentItem->setScrollOffset(oldItem->getScrollOffset());
434 m_currentItem->setDidSaveScrollOrScaleState(
435 oldItem->didSaveScrollOrScaleState());
436 m_currentItem->setVisualViewportScrollOffset(
437 oldItem->visualViewportScrollOffset());
438 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor());
439 m_currentItem->setScrollRestorationType(oldItem->scrollRestorationType());
440
441 // The item sequence number determines whether items are "the same", such
442 // back/forward navigation between items with the same item sequence number is
443 // a no-op. Only treat this as identical if the navigation did not create a
444 // back/forward entry and the url is identical or it was loaded via
445 // history.replaceState().
446 if (historyCommitType == HistoryInertCommit &&
447 (navigationType == HistoryNavigationType::HistoryApi ||
448 oldItem->url() == m_currentItem->url())) {
449 m_currentItem->setStateObject(oldItem->stateObject());
450 m_currentItem->setItemSequenceNumber(oldItem->itemSequenceNumber());
451 }
452 }
453
454 static HistoryCommitType loadTypeToCommitType(FrameLoadType type) {
455 switch (type) {
456 case FrameLoadTypeStandard:
457 return StandardCommit;
458 case FrameLoadTypeInitialInChildFrame:
459 case FrameLoadTypeInitialHistoryLoad:
460 return InitialCommitInChildFrame;
461 case FrameLoadTypeBackForward:
462 return BackForwardCommit;
463 default:
464 break;
465 }
466 return HistoryInertCommit;
467 }
468
469 void FrameLoader::receivedFirstData() {
470 FrameLoadType loadType = m_documentLoader->loadType();
471 HistoryCommitType historyCommitType = loadTypeToCommitType(loadType);
472 if (historyCommitType == StandardCommit &&
473 (m_documentLoader->urlForHistory().isEmpty() ||
474 (opener() && !m_currentItem &&
475 m_documentLoader->originalRequest().url().isEmpty())))
476 historyCommitType = HistoryInertCommit;
477 setHistoryItemStateForCommit(loadType, historyCommitType,
478 HistoryNavigationType::DifferentDocument);
479
480 if (!m_stateMachine.committedMultipleRealLoads() &&
481 loadType == FrameLoadTypeStandard) {
482 m_stateMachine.advanceTo(
483 FrameLoaderStateMachine::CommittedMultipleRealLoads);
484 }
485
486 client()->dispatchDidCommitLoad(m_currentItem.get(), historyCommitType);
487
488 // When the embedder gets notified (above) that the new navigation has
489 // committed, the embedder will drop the old Content Security Policy and
490 // therefore now is a good time to report to the embedder the Content Security
491 // Policies that have accumulated so far for the new navigation.
492 m_frame->securityContext()->contentSecurityPolicy()->reportAccumulatedHeaders(
493 client());
494 }
495
496 void FrameLoader::didInstallNewDocument() {
497 if (m_provisionalItem &&
498 isBackForwardLoadType(m_documentLoader->loadType())) {
499 m_frame->document()->setStateForNewFormElements(
500 m_provisionalItem->getDocumentState());
501 }
502 }
503
504 void FrameLoader::finishedParsing() { 380 void FrameLoader::finishedParsing() {
505 if (m_stateMachine.creatingInitialEmptyDocument()) 381 if (m_stateMachine.creatingInitialEmptyDocument())
506 return; 382 return;
507 383
508 m_progressTracker->finishedParsing(); 384 m_progressTracker->finishedParsing();
509 385
510 if (client()) { 386 if (client()) {
511 ScriptForbiddenScope forbidScripts; 387 ScriptForbiddenScope forbidScripts;
512 client()->dispatchDidFinishDocumentLoad(); 388 client()->dispatchDidFinishDocumentLoad();
513 } 389 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 564
689 void FrameLoader::updateForSameDocumentNavigation( 565 void FrameLoader::updateForSameDocumentNavigation(
690 const KURL& newURL, 566 const KURL& newURL,
691 SameDocumentNavigationSource sameDocumentNavigationSource, 567 SameDocumentNavigationSource sameDocumentNavigationSource,
692 PassRefPtr<SerializedScriptValue> data, 568 PassRefPtr<SerializedScriptValue> data,
693 HistoryScrollRestorationType scrollRestorationType, 569 HistoryScrollRestorationType scrollRestorationType,
694 FrameLoadType type, 570 FrameLoadType type,
695 Document* initiatingDocument) { 571 Document* initiatingDocument) {
696 TRACE_EVENT1("blink", "FrameLoader::updateForSameDocumentNavigation", "url", 572 TRACE_EVENT1("blink", "FrameLoader::updateForSameDocumentNavigation", "url",
697 newURL.getString().ascii().data()); 573 newURL.getString().ascii().data());
698 // Update the data source's request with the new URL to fake the URL change
699 m_frame->document()->setURL(newURL);
700 documentLoader()->setReplacesCurrentHistoryItem(type !=
701 FrameLoadTypeStandard);
702 documentLoader()->updateForSameDocumentNavigation(
703 newURL, sameDocumentNavigationSource);
704 574
705 // Generate start and stop notifications only when loader is completed so that 575 // Generate start and stop notifications only when loader is completed so that
706 // we don't fire them for fragment redirection that happens in window.onload 576 // we don't fire them for fragment redirection that happens in window.onload
707 // handler. See https://bugs.webkit.org/show_bug.cgi?id=31838 577 // handler. See https://bugs.webkit.org/show_bug.cgi?id=31838
708 // Do not fire the notifications if the frame is concurrently navigating away 578 // Do not fire the notifications if the frame is concurrently navigating away
709 // from the document, since a new document is already loading. 579 // from the document, since a new document is already loading.
710 if (m_frame->document()->loadEventFinished() && !m_provisionalDocumentLoader) 580 if (m_frame->document()->loadEventFinished() && !m_provisionalDocumentLoader)
711 client()->didStartLoading(NavigationWithinSameDocument); 581 client()->didStartLoading(NavigationWithinSameDocument);
712 582
713 HistoryCommitType historyCommitType = loadTypeToCommitType(type); 583 // Update the data source's request with the new URL to fake the URL change
714 if (!m_currentItem) 584 m_frame->document()->setURL(newURL);
715 historyCommitType = HistoryInertCommit; 585 documentLoader()->updateForSameDocumentNavigation(
716 if (m_frame->settings()->getHistoryEntryRequiresUserGesture() && 586 newURL, sameDocumentNavigationSource, std::move(data),
717 initiatingDocument && 587 scrollRestorationType, type, initiatingDocument);
718 !initiatingDocument->frame()->hasReceivedUserGesture()) {
719 historyCommitType = HistoryInertCommit;
720 }
721 588
722 setHistoryItemStateForCommit(
723 type, historyCommitType,
724 sameDocumentNavigationSource == SameDocumentNavigationHistoryApi
725 ? HistoryNavigationType::HistoryApi
726 : HistoryNavigationType::Fragment);
727 if (sameDocumentNavigationSource == SameDocumentNavigationHistoryApi) {
728 m_currentItem->setStateObject(std::move(data));
729 m_currentItem->setScrollRestorationType(scrollRestorationType);
730 }
731 client()->dispatchDidNavigateWithinPage(
732 m_currentItem.get(), historyCommitType, !!initiatingDocument);
733 client()->dispatchDidReceiveTitle(m_frame->document()->title()); 589 client()->dispatchDidReceiveTitle(m_frame->document()->title());
734 if (m_frame->document()->loadEventFinished() && !m_provisionalDocumentLoader) 590 if (m_frame->document()->loadEventFinished() && !m_provisionalDocumentLoader)
735 client()->didStopLoading(); 591 client()->didStopLoading();
736 } 592 }
737 593
738 void FrameLoader::detachDocumentLoader(Member<DocumentLoader>& loader) { 594 void FrameLoader::detachDocumentLoader(Member<DocumentLoader>& loader) {
739 if (!loader) 595 if (!loader)
740 return; 596 return;
741 597
742 FrameNavigationDisabler navigationDisabler(*m_frame); 598 FrameNavigationDisabler navigationDisabler(*m_frame);
743 loader->detachFromFrame(); 599 loader->detachFromFrame();
744 loader = nullptr; 600 loader = nullptr;
745 } 601 }
746 602
747 void FrameLoader::loadInSameDocument( 603 void FrameLoader::loadInSameDocument(
748 const KURL& url, 604 const KURL& url,
749 PassRefPtr<SerializedScriptValue> stateObject, 605 PassRefPtr<SerializedScriptValue> stateObject,
750 FrameLoadType frameLoadType, 606 FrameLoadType frameLoadType,
751 HistoryLoadType historyLoadType, 607 HistoryItem* historyItem,
752 ClientRedirectPolicy clientRedirect, 608 ClientRedirectPolicy clientRedirect,
753 Document* initiatingDocument) { 609 Document* initiatingDocument) {
754 // If we have a state object, we cannot also be a new navigation. 610 // If we have a state object, we cannot also be a new navigation.
755 DCHECK(!stateObject || frameLoadType == FrameLoadTypeBackForward); 611 DCHECK(!stateObject || frameLoadType == FrameLoadTypeBackForward);
756 612
757 // If we have a provisional request for a different document, a fragment 613 // If we have a provisional request for a different document, a fragment
758 // scroll should cancel it. 614 // scroll should cancel it.
759 detachDocumentLoader(m_provisionalDocumentLoader); 615 detachDocumentLoader(m_provisionalDocumentLoader);
760 616
761 if (!m_frame->page()) 617 if (!m_frame->page())
762 return; 618 return;
763 saveScrollState(); 619 saveScrollState();
764 620
765 KURL oldURL = m_frame->document()->url(); 621 KURL oldURL = m_frame->document()->url();
766 bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && 622 bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) &&
767 url.fragmentIdentifier() != oldURL.fragmentIdentifier(); 623 url.fragmentIdentifier() != oldURL.fragmentIdentifier();
768 if (hashChange) { 624 if (hashChange) {
769 // If we were in the autoscroll/middleClickAutoscroll mode we want to stop 625 // If we were in the autoscroll/middleClickAutoscroll mode we want to stop
770 // it before following the link to the anchor 626 // it before following the link to the anchor
771 m_frame->eventHandler().stopAutoscroll(); 627 m_frame->eventHandler().stopAutoscroll();
772 m_frame->domWindow()->enqueueHashchangeEvent(oldURL, url); 628 m_frame->domWindow()->enqueueHashchangeEvent(oldURL, url);
773 } 629 }
774 m_documentLoader->setIsClientRedirect(clientRedirect == 630 m_documentLoader->setIsClientRedirect(clientRedirect ==
775 ClientRedirectPolicy::ClientRedirect); 631 ClientRedirectPolicy::ClientRedirect);
632 if (historyItem)
633 m_documentLoader->setItemForHistoryNavigation(historyItem);
776 updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr, 634 updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr,
777 ScrollRestorationAuto, frameLoadType, 635 ScrollRestorationAuto, frameLoadType,
778 initiatingDocument); 636 initiatingDocument);
779 637
780 m_documentLoader->initialScrollState().wasScrolledByUser = false; 638 m_documentLoader->initialScrollState().wasScrolledByUser = false;
781 639
782 checkCompleted(); 640 checkCompleted();
783 641
784 m_frame->domWindow()->statePopped(stateObject 642 m_frame->domWindow()->statePopped(stateObject
785 ? std::move(stateObject) 643 ? std::move(stateObject)
786 : SerializedScriptValue::nullValue()); 644 : SerializedScriptValue::nullValue());
787 645
788 if (historyLoadType == HistorySameDocumentLoad) 646 if (historyItem)
789 restoreScrollPositionAndViewStateForLoadType(frameLoadType); 647 restoreScrollPositionAndViewStateForLoadType(frameLoadType);
790 648
791 // We need to scroll to the fragment whether or not a hash change occurred, 649 // We need to scroll to the fragment whether or not a hash change occurred,
792 // since the user might have scrolled since the previous navigation. 650 // since the user might have scrolled since the previous navigation.
793 processFragment(url, frameLoadType, NavigationWithinSameDocument); 651 processFragment(url, frameLoadType, NavigationWithinSameDocument);
794 takeObjectSnapshot(); 652 takeObjectSnapshot();
795 } 653 }
796 654
797 // static 655 // static
798 void FrameLoader::setReferrerForFrameRequest(FrameLoadRequest& frameRequest) { 656 void FrameLoader::setReferrerForFrameRequest(FrameLoadRequest& frameRequest) {
(...skipping 18 matching lines...) Expand all
817 675
818 request.setHTTPReferrer(referrer); 676 request.setHTTPReferrer(referrer);
819 request.addHTTPOriginIfNeeded(referrer.referrer); 677 request.addHTTPOriginIfNeeded(referrer.referrer);
820 } 678 }
821 679
822 FrameLoadType FrameLoader::determineFrameLoadType( 680 FrameLoadType FrameLoader::determineFrameLoadType(
823 const FrameLoadRequest& request) { 681 const FrameLoadRequest& request) {
824 if (m_frame->tree().parent() && 682 if (m_frame->tree().parent() &&
825 !m_stateMachine.committedFirstRealDocumentLoad()) 683 !m_stateMachine.committedFirstRealDocumentLoad())
826 return FrameLoadTypeInitialInChildFrame; 684 return FrameLoadTypeInitialInChildFrame;
827 if (!m_frame->tree().parent() && !client()->backForwardLength()) 685 if (!m_frame->tree().parent() && !client()->backForwardLength()) {
686 if (opener() && request.resourceRequest().url().isEmpty())
687 return FrameLoadTypeReplaceCurrentItem;
828 return FrameLoadTypeStandard; 688 return FrameLoadTypeStandard;
829 if (m_provisionalDocumentLoader && 689 }
830 request.substituteData().failingURL() ==
831 m_provisionalDocumentLoader->url() &&
832 m_provisionalDocumentLoader->loadType() == FrameLoadTypeBackForward)
833 return FrameLoadTypeBackForward;
834 if (request.resourceRequest().getCachePolicy() == 690 if (request.resourceRequest().getCachePolicy() ==
835 WebCachePolicy::ValidatingCacheData) 691 WebCachePolicy::ValidatingCacheData)
836 return FrameLoadTypeReload; 692 return FrameLoadTypeReload;
837 if (request.resourceRequest().getCachePolicy() == 693 if (request.resourceRequest().getCachePolicy() ==
838 WebCachePolicy::BypassingCache) 694 WebCachePolicy::BypassingCache)
839 return FrameLoadTypeReloadBypassingCache; 695 return FrameLoadTypeReloadBypassingCache;
840 // From the HTML5 spec for location.assign(): 696 // From the HTML5 spec for location.assign():
841 // "If the browsing context's session history contains only one Document, 697 // "If the browsing context's session history contains only one Document,
842 // and that was the about:blank Document created when the browsing context 698 // and that was the about:blank Document created when the browsing context
843 // was created, then the navigation must be done with replacement enabled." 699 // was created, then the navigation must be done with replacement enabled."
(...skipping 13 matching lines...) Expand all
857 if (request.substituteData().failingURL() == 713 if (request.substituteData().failingURL() ==
858 m_documentLoader->urlForHistory() && 714 m_documentLoader->urlForHistory() &&
859 m_documentLoader->loadType() == FrameLoadTypeReload) 715 m_documentLoader->loadType() == FrameLoadTypeReload)
860 return FrameLoadTypeReload; 716 return FrameLoadTypeReload;
861 717
862 if (m_frame->settings()->getHistoryEntryRequiresUserGesture() && 718 if (m_frame->settings()->getHistoryEntryRequiresUserGesture() &&
863 request.originDocument() && 719 request.originDocument() &&
864 !request.originDocument()->frame()->hasReceivedUserGesture()) 720 !request.originDocument()->frame()->hasReceivedUserGesture())
865 return FrameLoadTypeReplaceCurrentItem; 721 return FrameLoadTypeReplaceCurrentItem;
866 722
723 if (request.resourceRequest().url().isEmpty() &&
724 request.substituteData().failingURL().isEmpty()) {
725 return FrameLoadTypeReplaceCurrentItem;
726 }
727
867 return FrameLoadTypeStandard; 728 return FrameLoadTypeStandard;
868 } 729 }
869 730
870 bool FrameLoader::prepareRequestForThisFrame(FrameLoadRequest& request) { 731 bool FrameLoader::prepareRequestForThisFrame(FrameLoadRequest& request) {
871 // If no origin Document* was specified, skip remaining security checks and 732 // If no origin Document* was specified, skip remaining security checks and
872 // assume the caller has fully initialized the FrameLoadRequest. 733 // assume the caller has fully initialized the FrameLoadRequest.
873 if (!request.originDocument()) 734 if (!request.originDocument())
874 return true; 735 return true;
875 736
876 KURL url = request.resourceRequest().url(); 737 KURL url = request.resourceRequest().url();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 return; 868 return;
1008 } 869 }
1009 870
1010 FrameLoadRequest request(passedRequest); 871 FrameLoadRequest request(passedRequest);
1011 request.resourceRequest().setHasUserGesture( 872 request.resourceRequest().setHasUserGesture(
1012 UserGestureIndicator::processingUserGesture()); 873 UserGestureIndicator::processingUserGesture());
1013 874
1014 if (!prepareRequestForThisFrame(request)) 875 if (!prepareRequestForThisFrame(request))
1015 return; 876 return;
1016 877
1017 if (isBackForwardLoadType(frameLoadType)) {
1018 DCHECK(historyItem);
1019 m_provisionalItem = historyItem;
1020 }
1021
1022 // Form submissions appear to need their special-case of finding the target at 878 // Form submissions appear to need their special-case of finding the target at
1023 // schedule rather than at fire. 879 // schedule rather than at fire.
1024 Frame* targetFrame = request.form() 880 Frame* targetFrame = request.form()
1025 ? nullptr 881 ? nullptr
1026 : m_frame->findFrameForNavigation( 882 : m_frame->findFrameForNavigation(
1027 AtomicString(request.frameName()), *m_frame); 883 AtomicString(request.frameName()), *m_frame);
1028 884
1029 NavigationPolicy policy = navigationPolicyForRequest(request); 885 NavigationPolicy policy = navigationPolicyForRequest(request);
1030 if (targetFrame && targetFrame != m_frame && 886 if (targetFrame && targetFrame != m_frame &&
1031 shouldNavigateTargetFrame(policy)) { 887 shouldNavigateTargetFrame(policy)) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 RefPtr<SerializedScriptValue> stateObject = 935 RefPtr<SerializedScriptValue> stateObject =
1080 sameDocumentHistoryNavigation ? historyItem->stateObject() : nullptr; 936 sameDocumentHistoryNavigation ? historyItem->stateObject() : nullptr;
1081 937
1082 if (!sameDocumentHistoryNavigation) { 938 if (!sameDocumentHistoryNavigation) {
1083 m_documentLoader->setNavigationType(determineNavigationType( 939 m_documentLoader->setNavigationType(determineNavigationType(
1084 newLoadType, false, request.triggeringEvent())); 940 newLoadType, false, request.triggeringEvent()));
1085 if (shouldTreatURLAsSameAsCurrent(url)) 941 if (shouldTreatURLAsSameAsCurrent(url))
1086 newLoadType = FrameLoadTypeReplaceCurrentItem; 942 newLoadType = FrameLoadTypeReplaceCurrentItem;
1087 } 943 }
1088 944
1089 loadInSameDocument(url, stateObject, newLoadType, historyLoadType, 945 loadInSameDocument(url, stateObject, newLoadType, historyItem,
1090 request.clientRedirect(), request.originDocument()); 946 request.clientRedirect(), request.originDocument());
1091 return; 947 return;
1092 } 948 }
1093 949
1094 // PlzNavigate 950 // PlzNavigate
1095 // If the loader classifies this navigation as a different document navigation 951 // If the loader classifies this navigation as a different document navigation
1096 // while the browser intended the navigation to be same-document, it means 952 // while the browser intended the navigation to be same-document, it means
1097 // that a different navigation must have committed while the IPC was sent. 953 // that a different navigation must have committed while the IPC was sent.
1098 // This navigation is no more same-document. The navigation is simply dropped. 954 // This navigation is no more same-document. The navigation is simply dropped.
1099 if (request.resourceRequest().isSameDocumentNavigation()) 955 if (request.resourceRequest().isSameDocumentNavigation())
1100 return; 956 return;
1101 957
1102 startLoad(request, newLoadType, policy); 958 startLoad(request, newLoadType, policy, historyItem);
1103 } 959 }
1104 960
1105 SubstituteData FrameLoader::defaultSubstituteDataForURL(const KURL& url) { 961 SubstituteData FrameLoader::defaultSubstituteDataForURL(const KURL& url) {
1106 if (!shouldTreatURLAsSrcdocDocument(url)) 962 if (!shouldTreatURLAsSrcdocDocument(url))
1107 return SubstituteData(); 963 return SubstituteData();
1108 String srcdoc = m_frame->deprecatedLocalOwner()->fastGetAttribute(srcdocAttr); 964 String srcdoc = m_frame->deprecatedLocalOwner()->fastGetAttribute(srcdocAttr);
1109 DCHECK(!srcdoc.isNull()); 965 DCHECK(!srcdoc.isNull());
1110 CString encodedSrcdoc = srcdoc.utf8(); 966 CString encodedSrcdoc = srcdoc.utf8();
1111 return SubstituteData( 967 return SubstituteData(
1112 SharedBuffer::create(encodedSrcdoc.data(), encodedSrcdoc.length()), 968 SharedBuffer::create(encodedSrcdoc.data(), encodedSrcdoc.length()),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 detachDocumentLoader(m_provisionalDocumentLoader); 1005 detachDocumentLoader(m_provisionalDocumentLoader);
1150 1006
1151 m_checkTimer.stop(); 1007 m_checkTimer.stop();
1152 m_frame->navigationScheduler().cancel(); 1008 m_frame->navigationScheduler().cancel();
1153 1009
1154 // It's possible that the above actions won't have stopped loading if load 1010 // It's possible that the above actions won't have stopped loading if load
1155 // completion had been blocked on parsing or if we were in the middle of 1011 // completion had been blocked on parsing or if we were in the middle of
1156 // committing an empty document. In that case, emulate a failed navigation. 1012 // committing an empty document. In that case, emulate a failed navigation.
1157 if (!m_provisionalDocumentLoader && m_documentLoader && 1013 if (!m_provisionalDocumentLoader && m_documentLoader &&
1158 m_frame->isLoading()) { 1014 m_frame->isLoading()) {
1159 loadFailed(m_documentLoader.get(), 1015 m_documentLoader->loadFailed(
1160 ResourceError::cancelledError(m_documentLoader->url())); 1016 ResourceError::cancelledError(m_documentLoader->url()));
1161 } 1017 }
1162 1018
1163 m_inStopAllLoaders = false; 1019 m_inStopAllLoaders = false;
1164 takeObjectSnapshot(); 1020 takeObjectSnapshot();
1165 } 1021 }
1166 1022
1167 void FrameLoader::didAccessInitialDocument() { 1023 void FrameLoader::didAccessInitialDocument() {
1168 // We only need to notify the client for the main frame. 1024 // We only need to notify the client for the main frame.
1169 if (isLoadingMainFrame()) { 1025 if (isLoadingMainFrame()) {
1170 // Forbid script execution to prevent re-entering V8, since this is called 1026 // Forbid script execution to prevent re-entering V8, since this is called
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 // 'abort' listeners can also detach the frame. 1076 // 'abort' listeners can also detach the frame.
1221 if (!m_frame->client()) 1077 if (!m_frame->client())
1222 return false; 1078 return false;
1223 DCHECK_EQ(m_provisionalDocumentLoader, pdl); 1079 DCHECK_EQ(m_provisionalDocumentLoader, pdl);
1224 // No more events will be dispatched so detach the Document. 1080 // No more events will be dispatched so detach the Document.
1225 // TODO(yoav): Should we also be nullifying domWindow's document (or 1081 // TODO(yoav): Should we also be nullifying domWindow's document (or
1226 // domWindow) since the doc is now detached? 1082 // domWindow) since the doc is now detached?
1227 if (m_frame->document()) 1083 if (m_frame->document())
1228 m_frame->document()->shutdown(); 1084 m_frame->document()->shutdown();
1229 m_documentLoader = m_provisionalDocumentLoader.release(); 1085 m_documentLoader = m_provisionalDocumentLoader.release();
1086 if (m_documentLoader)
1087 m_documentLoader->markAsCommitted();
1230 takeObjectSnapshot(); 1088 takeObjectSnapshot();
1231 1089
1232 return true; 1090 return true;
1233 } 1091 }
1234 1092
1235 void FrameLoader::commitProvisionalLoad() { 1093 void FrameLoader::commitProvisionalLoad() {
1236 DCHECK(client()->hasWebView()); 1094 DCHECK(client()->hasWebView());
1237 1095
1238 // Check if the destination page is allowed to access the previous page's 1096 // Check if the destination page is allowed to access the previous page's
1239 // timing information. 1097 // timing information.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 1143
1286 void FrameLoader::restoreScrollPositionAndViewState() { 1144 void FrameLoader::restoreScrollPositionAndViewState() {
1287 if (!m_frame->page() || !documentLoader()) 1145 if (!m_frame->page() || !documentLoader())
1288 return; 1146 return;
1289 restoreScrollPositionAndViewStateForLoadType(documentLoader()->loadType()); 1147 restoreScrollPositionAndViewStateForLoadType(documentLoader()->loadType());
1290 } 1148 }
1291 1149
1292 void FrameLoader::restoreScrollPositionAndViewStateForLoadType( 1150 void FrameLoader::restoreScrollPositionAndViewStateForLoadType(
1293 FrameLoadType loadType) { 1151 FrameLoadType loadType) {
1294 FrameView* view = m_frame->view(); 1152 FrameView* view = m_frame->view();
1295 if (!view || !view->layoutViewportScrollableArea() || !m_currentItem || 1153 if (!view || !view->layoutViewportScrollableArea() ||
1296 !m_stateMachine.committedFirstRealDocumentLoad()) { 1154 !m_stateMachine.committedFirstRealDocumentLoad()) {
1297 return; 1155 return;
1298 } 1156 }
1299 if (!needsHistoryItemRestore(loadType)) 1157 if (!needsHistoryItemRestore(loadType))
1300 return; 1158 return;
1301 if (!m_currentItem->didSaveScrollOrScaleState()) 1159 HistoryItem* historyItem = m_documentLoader->historyItem();
1160 if (!historyItem || !historyItem->didSaveScrollOrScaleState())
1302 return; 1161 return;
1303 1162
1304 bool shouldRestoreScroll = 1163 bool shouldRestoreScroll =
1305 m_currentItem->scrollRestorationType() != ScrollRestorationManual; 1164 historyItem->scrollRestorationType() != ScrollRestorationManual;
1306 bool shouldRestoreScale = m_currentItem->pageScaleFactor(); 1165 bool shouldRestoreScale = historyItem->pageScaleFactor();
1307 1166
1308 // This tries to balance: 1167 // This tries to balance:
1309 // 1. restoring as soon as possible 1168 // 1. restoring as soon as possible
1310 // 2. not overriding user scroll (TODO(majidvp): also respect user scale) 1169 // 2. not overriding user scroll (TODO(majidvp): also respect user scale)
1311 // 3. detecting clamping to avoid repeatedly popping the scroll position down 1170 // 3. detecting clamping to avoid repeatedly popping the scroll position down
1312 // as the page height increases 1171 // as the page height increases
1313 // 4. ignore clamp detection if we are not restoring scroll or after load 1172 // 4. ignore clamp detection if we are not restoring scroll or after load
1314 // completes because that may be because the page will never reach its 1173 // completes because that may be because the page will never reach its
1315 // previous height 1174 // previous height
1316 bool canRestoreWithoutClamping = 1175 bool canRestoreWithoutClamping =
1317 view->layoutViewportScrollableArea()->clampScrollOffset( 1176 view->layoutViewportScrollableArea()->clampScrollOffset(
1318 m_currentItem->getScrollOffset()) == m_currentItem->getScrollOffset(); 1177 historyItem->getScrollOffset()) == historyItem->getScrollOffset();
1319 bool canRestoreWithoutAnnoyingUser = 1178 bool canRestoreWithoutAnnoyingUser =
1320 !documentLoader()->initialScrollState().wasScrolledByUser && 1179 !documentLoader()->initialScrollState().wasScrolledByUser &&
1321 (canRestoreWithoutClamping || !m_frame->isLoading() || 1180 (canRestoreWithoutClamping || !m_frame->isLoading() ||
1322 !shouldRestoreScroll); 1181 !shouldRestoreScroll);
1323 if (!canRestoreWithoutAnnoyingUser) 1182 if (!canRestoreWithoutAnnoyingUser)
1324 return; 1183 return;
1325 1184
1326 if (shouldRestoreScroll) { 1185 if (shouldRestoreScroll) {
1327 view->layoutViewportScrollableArea()->setScrollOffset( 1186 view->layoutViewportScrollableArea()->setScrollOffset(
1328 m_currentItem->getScrollOffset(), ProgrammaticScroll); 1187 historyItem->getScrollOffset(), ProgrammaticScroll);
1329 } 1188 }
1330 1189
1331 // For main frame restore scale and visual viewport position 1190 // For main frame restore scale and visual viewport position
1332 if (m_frame->isMainFrame()) { 1191 if (m_frame->isMainFrame()) {
1333 ScrollOffset visualViewportOffset( 1192 ScrollOffset visualViewportOffset(
1334 m_currentItem->visualViewportScrollOffset()); 1193 historyItem->visualViewportScrollOffset());
1335 1194
1336 // If the visual viewport's offset is (-1, -1) it means the history item 1195 // If the visual viewport's offset is (-1, -1) it means the history item
1337 // is an old version of HistoryItem so distribute the scroll between 1196 // is an old version of HistoryItem so distribute the scroll between
1338 // the main frame and the visual viewport as best as we can. 1197 // the main frame and the visual viewport as best as we can.
1339 if (visualViewportOffset.width() == -1 && 1198 if (visualViewportOffset.width() == -1 &&
1340 visualViewportOffset.height() == -1) { 1199 visualViewportOffset.height() == -1) {
1341 visualViewportOffset = 1200 visualViewportOffset =
1342 m_currentItem->getScrollOffset() - 1201 historyItem->getScrollOffset() -
1343 view->layoutViewportScrollableArea()->getScrollOffset(); 1202 view->layoutViewportScrollableArea()->getScrollOffset();
1344 } 1203 }
1345 1204
1346 VisualViewport& visualViewport = m_frame->page()->visualViewport(); 1205 VisualViewport& visualViewport = m_frame->page()->visualViewport();
1347 if (shouldRestoreScale && shouldRestoreScroll) { 1206 if (shouldRestoreScale && shouldRestoreScroll) {
1348 visualViewport.setScaleAndLocation(m_currentItem->pageScaleFactor(), 1207 visualViewport.setScaleAndLocation(historyItem->pageScaleFactor(),
1349 FloatPoint(visualViewportOffset)); 1208 FloatPoint(visualViewportOffset));
1350 } else if (shouldRestoreScale) { 1209 } else if (shouldRestoreScale) {
1351 visualViewport.setScale(m_currentItem->pageScaleFactor()); 1210 visualViewport.setScale(historyItem->pageScaleFactor());
1352 } else if (shouldRestoreScroll) { 1211 } else if (shouldRestoreScroll) {
1353 visualViewport.setLocation(FloatPoint(visualViewportOffset)); 1212 visualViewport.setLocation(FloatPoint(visualViewportOffset));
1354 } 1213 }
1355 1214
1356 if (ScrollingCoordinator* scrollingCoordinator = 1215 if (ScrollingCoordinator* scrollingCoordinator =
1357 m_frame->page()->scrollingCoordinator()) 1216 m_frame->page()->scrollingCoordinator())
1358 scrollingCoordinator->frameViewRootLayerDidChange(view); 1217 scrollingCoordinator->frameViewRootLayerDidChange(view);
1359 } 1218 }
1360 1219
1361 documentLoader()->initialScrollState().didRestoreFromHistory = true; 1220 documentLoader()->initialScrollState().didRestoreFromHistory = true;
(...skipping 14 matching lines...) Expand all
1376 toLocalFrame(parent)->loader().scheduleCheckCompleted(); 1235 toLocalFrame(parent)->loader().scheduleCheckCompleted();
1377 if (m_progressTracker) { 1236 if (m_progressTracker) {
1378 m_progressTracker->dispose(); 1237 m_progressTracker->dispose();
1379 m_progressTracker.clear(); 1238 m_progressTracker.clear();
1380 } 1239 }
1381 1240
1382 TRACE_EVENT_OBJECT_DELETED_WITH_ID("loading", "FrameLoader", this); 1241 TRACE_EVENT_OBJECT_DELETED_WITH_ID("loading", "FrameLoader", this);
1383 m_detached = true; 1242 m_detached = true;
1384 } 1243 }
1385 1244
1386 void FrameLoader::loadFailed(DocumentLoader* loader, 1245 void FrameLoader::detachProvisionalDocumentLoader(DocumentLoader* loader) {
1387 const ResourceError& error) { 1246 DCHECK_EQ(loader, m_provisionalDocumentLoader);
1388 if (!error.isCancellation() && m_frame->owner()) { 1247 detachDocumentLoader(m_provisionalDocumentLoader);
1389 // FIXME: For now, fallback content doesn't work cross process.
1390 if (m_frame->owner()->isLocal())
1391 m_frame->deprecatedLocalOwner()->renderFallbackContent();
1392 }
1393
1394 HistoryCommitType historyCommitType =
1395 loadTypeToCommitType(loader->loadType());
1396 if (loader == m_provisionalDocumentLoader) {
1397 if (!m_provisionalDocumentLoader->didStart())
1398 probe::frameClearedScheduledClientNavigation(m_frame);
1399 m_provisionalDocumentLoader->setSentDidFinishLoad();
1400 client()->dispatchDidFailProvisionalLoad(error, historyCommitType);
1401 if (loader != m_provisionalDocumentLoader)
1402 return;
1403 detachDocumentLoader(m_provisionalDocumentLoader);
1404 } else {
1405 DCHECK_EQ(loader, m_documentLoader);
1406 if (m_frame->document()->parser())
1407 m_frame->document()->parser()->stopParsing();
1408 if (!m_documentLoader->sentDidFinishLoad()) {
1409 m_documentLoader->setSentDidFinishLoad();
1410 client()->dispatchDidFailLoad(error, historyCommitType);
1411 }
1412 }
1413 checkCompleted();
1414 } 1248 }
1415 1249
1416 bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, 1250 bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission,
1417 const String& httpMethod, 1251 const String& httpMethod,
1418 FrameLoadType loadType, 1252 FrameLoadType loadType,
1419 const KURL& url) { 1253 const KURL& url) {
1420 // We don't do this if we are submitting a form with method other than "GET", 1254 // We don't do this if we are submitting a form with method other than "GET",
1421 // explicitly reloading, currently displaying a frameset, or if the URL does 1255 // explicitly reloading, currently displaying a frameset, or if the URL does
1422 // not have a fragment. 1256 // not have a fragment.
1423 return equalIgnoringCase(httpMethod, HTTPNames::GET) && 1257 return equalIgnoringCase(httpMethod, HTTPNames::GET) &&
(...skipping 25 matching lines...) Expand all
1449 ->view() 1283 ->view()
1450 ->setSafeToPropagateScrollToParent(false); 1284 ->setSafeToPropagateScrollToParent(false);
1451 } 1285 }
1452 1286
1453 // If scroll position is restored from history fragment or scroll 1287 // If scroll position is restored from history fragment or scroll
1454 // restoration type is manual, then we should not override it unless this 1288 // restoration type is manual, then we should not override it unless this
1455 // is a same document reload. 1289 // is a same document reload.
1456 bool shouldScrollToFragment = 1290 bool shouldScrollToFragment =
1457 (loadStartType == NavigationWithinSameDocument && 1291 (loadStartType == NavigationWithinSameDocument &&
1458 !isBackForwardLoadType(frameLoadType)) || 1292 !isBackForwardLoadType(frameLoadType)) ||
1459 (documentLoader() && 1293 (!documentLoader()->initialScrollState().didRestoreFromHistory &&
1460 !documentLoader()->initialScrollState().didRestoreFromHistory && 1294 !(documentLoader()->historyItem() &&
1461 !(m_currentItem && 1295 documentLoader()->historyItem()->scrollRestorationType() ==
1462 m_currentItem->scrollRestorationType() == ScrollRestorationManual)); 1296 ScrollRestorationManual));
1463 1297
1464 view->processUrlFragment(url, shouldScrollToFragment 1298 view->processUrlFragment(url, shouldScrollToFragment
1465 ? FrameView::UrlFragmentScroll 1299 ? FrameView::UrlFragmentScroll
1466 : FrameView::UrlFragmentDontScroll); 1300 : FrameView::UrlFragmentDontScroll);
1467 1301
1468 if (boundaryFrame && boundaryFrame->isLocalFrame()) 1302 if (boundaryFrame && boundaryFrame->isLocalFrame())
1469 toLocalFrame(boundaryFrame)->view()->setSafeToPropagateScrollToParent(true); 1303 toLocalFrame(boundaryFrame)->view()->setSafeToPropagateScrollToParent(true);
1470 } 1304 }
1471 1305
1472 bool FrameLoader::shouldClose(bool isReload) { 1306 bool FrameLoader::shouldClose(bool isReload) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 return shouldContinueForNavigationPolicy( 1442 return shouldContinueForNavigationPolicy(
1609 resourceRequest, frameLoadRequest.substituteData(), nullptr, 1443 resourceRequest, frameLoadRequest.substituteData(), nullptr,
1610 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(), 1444 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(),
1611 navigationType, navigationPolicy, type, 1445 navigationType, navigationPolicy, type,
1612 frameLoadRequest.clientRedirect() == ClientRedirectPolicy::ClientRedirect, 1446 frameLoadRequest.clientRedirect() == ClientRedirectPolicy::ClientRedirect,
1613 frameLoadRequest.form()); 1447 frameLoadRequest.form());
1614 } 1448 }
1615 1449
1616 void FrameLoader::startLoad(FrameLoadRequest& frameLoadRequest, 1450 void FrameLoader::startLoad(FrameLoadRequest& frameLoadRequest,
1617 FrameLoadType type, 1451 FrameLoadType type,
1618 NavigationPolicy navigationPolicy) { 1452 NavigationPolicy navigationPolicy,
1453 HistoryItem* historyItem) {
1619 DCHECK(client()->hasWebView()); 1454 DCHECK(client()->hasWebView());
1620 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest(); 1455 ResourceRequest& resourceRequest = frameLoadRequest.resourceRequest();
1621 NavigationType navigationType = determineNavigationType( 1456 NavigationType navigationType = determineNavigationType(
1622 type, resourceRequest.httpBody() || frameLoadRequest.form(), 1457 type, resourceRequest.httpBody() || frameLoadRequest.form(),
1623 frameLoadRequest.triggeringEvent()); 1458 frameLoadRequest.triggeringEvent());
1624 resourceRequest.setRequestContext( 1459 resourceRequest.setRequestContext(
1625 determineRequestContextFromNavigationType(navigationType)); 1460 determineRequestContextFromNavigationType(navigationType));
1626 resourceRequest.setFrameType(m_frame->isMainFrame() 1461 resourceRequest.setFrameType(m_frame->isMainFrame()
1627 ? WebURLRequest::FrameTypeTopLevel 1462 ? WebURLRequest::FrameTypeTopLevel
1628 : WebURLRequest::FrameTypeNested); 1463 : WebURLRequest::FrameTypeNested);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 navigationPolicy == NavigationPolicyHandledByClient) { 1504 navigationPolicy == NavigationPolicyHandledByClient) {
1670 m_frame->navigationScheduler().cancel(); 1505 m_frame->navigationScheduler().cancel();
1671 m_checkTimer.stop(); 1506 m_checkTimer.stop();
1672 } 1507 }
1673 1508
1674 if (frameLoadRequest.form()) 1509 if (frameLoadRequest.form())
1675 client()->dispatchWillSubmitForm(frameLoadRequest.form()); 1510 client()->dispatchWillSubmitForm(frameLoadRequest.form());
1676 1511
1677 m_provisionalDocumentLoader->appendRedirect( 1512 m_provisionalDocumentLoader->appendRedirect(
1678 m_provisionalDocumentLoader->getRequest().url()); 1513 m_provisionalDocumentLoader->getRequest().url());
1514
1515 if (isBackForwardLoadType(type)) {
1516 DCHECK(historyItem);
1517 m_provisionalDocumentLoader->setItemForHistoryNavigation(historyItem);
1518 }
1519
1679 // TODO(ananta): 1520 // TODO(ananta):
1680 // We should get rid of the dependency on the DocumentLoader in consumers of 1521 // We should get rid of the dependency on the DocumentLoader in consumers of
1681 // the didStartProvisionalLoad() notification. 1522 // the didStartProvisionalLoad() notification.
1682 client()->dispatchDidStartProvisionalLoad(m_provisionalDocumentLoader, 1523 client()->dispatchDidStartProvisionalLoad(m_provisionalDocumentLoader,
1683 resourceRequest); 1524 resourceRequest);
1684 DCHECK(m_provisionalDocumentLoader); 1525 DCHECK(m_provisionalDocumentLoader);
1685 1526
1686 if (navigationPolicy == NavigationPolicyCurrentTab) { 1527 if (navigationPolicy == NavigationPolicyCurrentTab) {
1687 m_provisionalDocumentLoader->startLoadingMainResource(); 1528 m_provisionalDocumentLoader->startLoadingMainResource();
1688 // This should happen after the request is sent, so that the state 1529 // This should happen after the request is sent, so that the state
(...skipping 13 matching lines...) Expand all
1702 takeObjectSnapshot(); 1543 takeObjectSnapshot();
1703 } 1544 }
1704 1545
1705 void FrameLoader::applyUserAgent(ResourceRequest& request) { 1546 void FrameLoader::applyUserAgent(ResourceRequest& request) {
1706 String userAgent = this->userAgent(); 1547 String userAgent = this->userAgent();
1707 DCHECK(!userAgent.isNull()); 1548 DCHECK(!userAgent.isNull());
1708 request.setHTTPUserAgent(AtomicString(userAgent)); 1549 request.setHTTPUserAgent(AtomicString(userAgent));
1709 } 1550 }
1710 1551
1711 bool FrameLoader::shouldTreatURLAsSameAsCurrent(const KURL& url) const { 1552 bool FrameLoader::shouldTreatURLAsSameAsCurrent(const KURL& url) const {
1712 return m_currentItem && url == m_currentItem->url(); 1553 return m_documentLoader->historyItem() &&
1554 url == m_documentLoader->historyItem()->url();
1713 } 1555 }
1714 1556
1715 bool FrameLoader::shouldTreatURLAsSrcdocDocument(const KURL& url) const { 1557 bool FrameLoader::shouldTreatURLAsSrcdocDocument(const KURL& url) const {
1716 if (!url.isAboutSrcdocURL()) 1558 if (!url.isAboutSrcdocURL())
1717 return false; 1559 return false;
1718 HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner(); 1560 HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner();
1719 if (!isHTMLIFrameElement(ownerElement)) 1561 if (!isHTMLIFrameElement(ownerElement))
1720 return false; 1562 return false;
1721 return ownerElement->fastHasAttribute(srcdocAttr); 1563 return ownerElement->fastHasAttribute(srcdocAttr);
1722 } 1564 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 FrameLoadType loadType, 1741 FrameLoadType loadType,
1900 NavigationType navigationType) { 1742 NavigationType navigationType) {
1901 DocumentLoader* loader = client()->createDocumentLoader( 1743 DocumentLoader* loader = client()->createDocumentLoader(
1902 m_frame, request, frameLoadRequest.substituteData().isValid() 1744 m_frame, request, frameLoadRequest.substituteData().isValid()
1903 ? frameLoadRequest.substituteData() 1745 ? frameLoadRequest.substituteData()
1904 : defaultSubstituteDataForURL(request.url()), 1746 : defaultSubstituteDataForURL(request.url()),
1905 frameLoadRequest.clientRedirect()); 1747 frameLoadRequest.clientRedirect());
1906 1748
1907 loader->setLoadType(loadType); 1749 loader->setLoadType(loadType);
1908 loader->setNavigationType(navigationType); 1750 loader->setNavigationType(navigationType);
1909 loader->setReplacesCurrentHistoryItem(loadType == 1751 // TODO(japhet): This is needed because the browser process DCHECKs if the
1910 FrameLoadTypeReplaceCurrentItem); 1752 // first entry we commit in a new frame has replacement set. It's unclear
1753 // whether the DCHECK is right, investigate removing this special case.
1754 bool replaceCurrentItem = loadType == FrameLoadTypeReplaceCurrentItem &&
1755 (!opener() || !request.url().isEmpty());
1756 loader->setReplacesCurrentHistoryItem(replaceCurrentItem);
1911 return loader; 1757 return loader;
1912 } 1758 }
1913 1759
1914 } // namespace blink 1760 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameLoader.h ('k') | third_party/WebKit/Source/core/loader/HistoryItem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698