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

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

Issue 2653673006: Move loadType() to DocumentLoader (Closed)
Patch Set: Move loadType() to DocumentLoader Created 3 years, 10 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 request.setSkipServiceWorker(frameLoadType == 176 request.setSkipServiceWorker(frameLoadType ==
177 FrameLoadTypeReloadBypassingCache 177 FrameLoadTypeReloadBypassingCache
178 ? WebURLRequest::SkipServiceWorker::All 178 ? WebURLRequest::SkipServiceWorker::All
179 : WebURLRequest::SkipServiceWorker::None); 179 : WebURLRequest::SkipServiceWorker::None);
180 return request; 180 return request;
181 } 181 }
182 182
183 FrameLoader::FrameLoader(LocalFrame* frame) 183 FrameLoader::FrameLoader(LocalFrame* frame)
184 : m_frame(frame), 184 : m_frame(frame),
185 m_progressTracker(ProgressTracker::create(frame)), 185 m_progressTracker(ProgressTracker::create(frame)),
186 m_loadType(FrameLoadTypeStandard),
187 m_inStopAllLoaders(false), 186 m_inStopAllLoaders(false),
188 m_checkTimer(TaskRunnerHelper::get(TaskType::Networking, frame), 187 m_checkTimer(TaskRunnerHelper::get(TaskType::Networking, frame),
189 this, 188 this,
190 &FrameLoader::checkTimerFired), 189 &FrameLoader::checkTimerFired),
191 m_forcedSandboxFlags(SandboxNone), 190 m_forcedSandboxFlags(SandboxNone),
192 m_dispatchingDidClearWindowObjectInMainWorld(false), 191 m_dispatchingDidClearWindowObjectInMainWorld(false),
193 m_protectProvisionalLoader(false), 192 m_protectProvisionalLoader(false),
194 m_isNavigationHandledByClient(false) { 193 m_isNavigationHandledByClient(false) {
195 DCHECK(m_frame); 194 DCHECK(m_frame);
196 TRACE_EVENT_OBJECT_CREATED_WITH_ID("loading", "FrameLoader", this); 195 TRACE_EVENT_OBJECT_CREATED_WITH_ID("loading", "FrameLoader", this);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 m_frame->navigationScheduler().startTimer(); 263 m_frame->navigationScheduler().startTimer();
265 scheduleCheckCompleted(); 264 scheduleCheckCompleted();
266 } 265 }
267 } 266 }
268 267
269 void FrameLoader::saveScrollState() { 268 void FrameLoader::saveScrollState() {
270 if (!m_currentItem || !m_frame->view()) 269 if (!m_currentItem || !m_frame->view())
271 return; 270 return;
272 271
273 // Shouldn't clobber anything if we might still restore later. 272 // Shouldn't clobber anything if we might still restore later.
274 if (needsHistoryItemRestore(m_loadType) && m_documentLoader && 273 if (m_documentLoader &&
274 needsHistoryItemRestore(m_documentLoader->loadType()) &&
275 !m_documentLoader->initialScrollState().wasScrolledByUser) 275 !m_documentLoader->initialScrollState().wasScrolledByUser)
276 return; 276 return;
277 277
278 if (ScrollableArea* layoutScrollableArea = 278 if (ScrollableArea* layoutScrollableArea =
279 m_frame->view()->layoutViewportScrollableArea()) 279 m_frame->view()->layoutViewportScrollableArea())
280 m_currentItem->setScrollOffset(layoutScrollableArea->getScrollOffset()); 280 m_currentItem->setScrollOffset(layoutScrollableArea->getScrollOffset());
281 m_currentItem->setVisualViewportScrollOffset(toScrollOffset( 281 m_currentItem->setVisualViewportScrollOffset(toScrollOffset(
282 m_frame->host()->visualViewport().visibleRect().location())); 282 m_frame->host()->visualViewport().visibleRect().location()));
283 283
284 if (m_frame->isMainFrame()) 284 if (m_frame->isMainFrame())
(...skipping 18 matching lines...) Expand all
303 // Calling document.open counts as committing the first real document load. 303 // Calling document.open counts as committing the first real document load.
304 if (!m_stateMachine.committedFirstRealDocumentLoad()) 304 if (!m_stateMachine.committedFirstRealDocumentLoad())
305 m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); 305 m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad);
306 306
307 // Only model a document.open() as part of a navigation if its parent is not 307 // Only model a document.open() as part of a navigation if its parent is not
308 // done or in the process of completing. 308 // done or in the process of completing.
309 if (Frame* parent = m_frame->tree().parent()) { 309 if (Frame* parent = m_frame->tree().parent()) {
310 if ((parent->isLocalFrame() && 310 if ((parent->isLocalFrame() &&
311 toLocalFrame(parent)->document()->loadEventStillNeeded()) || 311 toLocalFrame(parent)->document()->loadEventStillNeeded()) ||
312 (parent->isRemoteFrame() && parent->isLoading())) { 312 (parent->isRemoteFrame() && parent->isLoading())) {
313 m_progressTracker->progressStarted(); 313 m_progressTracker->progressStarted(m_documentLoader->loadType());
314 } 314 }
315 } 315 }
316 316
317 // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing 317 // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing
318 // away results from a subsequent window.document.open / window.document.write 318 // away results from a subsequent window.document.open / window.document.write
319 // call. Canceling redirection here works for all cases because document.open 319 // call. Canceling redirection here works for all cases because document.open
320 // implicitly precedes document.write. 320 // implicitly precedes document.write.
321 m_frame->navigationScheduler().cancel(); 321 m_frame->navigationScheduler().cancel();
322 } 322 }
323 323
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 default: 451 default:
452 break; 452 break;
453 } 453 }
454 return HistoryInertCommit; 454 return HistoryInertCommit;
455 } 455 }
456 456
457 void FrameLoader::receivedFirstData() { 457 void FrameLoader::receivedFirstData() {
458 if (m_stateMachine.creatingInitialEmptyDocument()) 458 if (m_stateMachine.creatingInitialEmptyDocument())
459 return; 459 return;
460 460
461 HistoryCommitType historyCommitType = loadTypeToCommitType(m_loadType); 461 FrameLoadType loadType = m_documentLoader->loadType();
462 HistoryCommitType historyCommitType = loadTypeToCommitType(loadType);
462 if (historyCommitType == StandardCommit && 463 if (historyCommitType == StandardCommit &&
463 (m_documentLoader->urlForHistory().isEmpty() || 464 (m_documentLoader->urlForHistory().isEmpty() ||
464 (opener() && !m_currentItem && 465 (opener() && !m_currentItem &&
465 m_documentLoader->originalRequest().url().isEmpty()))) 466 m_documentLoader->originalRequest().url().isEmpty())))
466 historyCommitType = HistoryInertCommit; 467 historyCommitType = HistoryInertCommit;
467 setHistoryItemStateForCommit(m_loadType, historyCommitType, 468 setHistoryItemStateForCommit(loadType, historyCommitType,
468 HistoryNavigationType::DifferentDocument); 469 HistoryNavigationType::DifferentDocument);
469 470
470 if (!m_stateMachine.committedMultipleRealLoads() && 471 if (!m_stateMachine.committedMultipleRealLoads() &&
471 m_loadType == FrameLoadTypeStandard) { 472 loadType == FrameLoadTypeStandard) {
472 m_stateMachine.advanceTo( 473 m_stateMachine.advanceTo(
473 FrameLoaderStateMachine::CommittedMultipleRealLoads); 474 FrameLoaderStateMachine::CommittedMultipleRealLoads);
474 } 475 }
475 476
476 client()->dispatchDidCommitLoad(m_currentItem.get(), historyCommitType); 477 client()->dispatchDidCommitLoad(m_currentItem.get(), historyCommitType);
477 478
478 // When the embedder gets notified (above) that the new navigation has 479 // When the embedder gets notified (above) that the new navigation has
479 // committed, the embedder will drop the old Content Security Policy and 480 // committed, the embedder will drop the old Content Security Policy and
480 // therefore now is a good time to report to the embedder the Content Security 481 // therefore now is a good time to report to the embedder the Content Security
481 // Policies that have accumulated so far for the new navigation. 482 // Policies that have accumulated so far for the new navigation.
(...skipping 27 matching lines...) Expand all
509 510
510 m_frame->document()->setReadyState(Document::Loading); 511 m_frame->document()->setReadyState(Document::Loading);
511 512
512 if (dispatchWindowObjectAvailable) 513 if (dispatchWindowObjectAvailable)
513 dispatchDidClearDocumentOfWindowObject(); 514 dispatchDidClearDocumentOfWindowObject();
514 515
515 m_frame->document()->initContentSecurityPolicy( 516 m_frame->document()->initContentSecurityPolicy(
516 m_documentLoader ? m_documentLoader->releaseContentSecurityPolicy() 517 m_documentLoader ? m_documentLoader->releaseContentSecurityPolicy()
517 : ContentSecurityPolicy::create()); 518 : ContentSecurityPolicy::create());
518 519
519 if (m_provisionalItem && isBackForwardLoadType(m_loadType)) { 520 if (m_provisionalItem &&
521 isBackForwardLoadType(m_documentLoader->loadType())) {
520 m_frame->document()->setStateForNewFormElements( 522 m_frame->document()->setStateForNewFormElements(
521 m_provisionalItem->getDocumentState()); 523 m_provisionalItem->getDocumentState());
522 } 524 }
523 } 525 }
524 526
525 void FrameLoader::didBeginDocument() { 527 void FrameLoader::didBeginDocument() {
526 DCHECK(m_frame); 528 DCHECK(m_frame);
527 DCHECK(m_frame->client()); 529 DCHECK(m_frame->client());
528 DCHECK(m_frame->document()); 530 DCHECK(m_frame->document());
529 DCHECK(m_frame->document()->fetcher()); 531 DCHECK(m_frame->document()->fetcher());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 637 }
636 638
637 checkCompleted(); 639 checkCompleted();
638 640
639 if (!m_frame->view()) 641 if (!m_frame->view())
640 return; 642 return;
641 643
642 // Check if the scrollbars are really needed for the content. If not, remove 644 // Check if the scrollbars are really needed for the content. If not, remove
643 // them, relayout, and repaint. 645 // them, relayout, and repaint.
644 m_frame->view()->restoreScrollbar(); 646 m_frame->view()->restoreScrollbar();
645 processFragment(m_frame->document()->url(), NavigationToDifferentDocument); 647 processFragment(m_frame->document()->url(), m_documentLoader->loadType(),
648 NavigationToDifferentDocument);
646 } 649 }
647 650
648 static bool allDescendantsAreComplete(Frame* frame) { 651 static bool allDescendantsAreComplete(Frame* frame) {
649 for (Frame* child = frame->tree().firstChild(); child; 652 for (Frame* child = frame->tree().firstChild(); child;
650 child = child->tree().traverseNext(frame)) { 653 child = child->tree().traverseNext(frame)) {
651 if (child->isLoading()) 654 if (child->isLoading())
652 return false; 655 return false;
653 } 656 }
654 return true; 657 return true;
655 } 658 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 // Finishing the load can detach the frame when running layout tests. 740 // Finishing the load can detach the frame when running layout tests.
738 if (!m_frame->client()) 741 if (!m_frame->client())
739 return; 742 return;
740 } 743 }
741 744
742 if (shouldSendCompleteNotification(m_frame, m_isNavigationHandledByClient)) { 745 if (shouldSendCompleteNotification(m_frame, m_isNavigationHandledByClient)) {
743 m_progressTracker->progressCompleted(); 746 m_progressTracker->progressCompleted();
744 // Retry restoring scroll offset since finishing loading disables content 747 // Retry restoring scroll offset since finishing loading disables content
745 // size clamping. 748 // size clamping.
746 restoreScrollPositionAndViewState(); 749 restoreScrollPositionAndViewState();
747 750 if (m_documentLoader)
yhirano 2017/01/25 06:30:43 Can you tell me when |m_documentLoader| is null?
Nate Chapin 2017/01/25 17:25:29 m_documentLoader is null: * In a narrow window dur
748 m_loadType = FrameLoadTypeStandard; 751 m_documentLoader->setLoadType(FrameLoadTypeStandard);
749 m_frame->domWindow()->finishedLoading(); 752 m_frame->domWindow()->finishedLoading();
750 } 753 }
751 754
752 Frame* parent = m_frame->tree().parent(); 755 Frame* parent = m_frame->tree().parent();
753 if (parent && parent->isLocalFrame()) 756 if (parent && parent->isLocalFrame())
754 toLocalFrame(parent)->loader().checkCompleted(); 757 toLocalFrame(parent)->loader().checkCompleted();
755 } 758 }
756 759
757 void FrameLoader::checkTimerFired(TimerBase*) { 760 void FrameLoader::checkTimerFired(TimerBase*) {
758 if (Page* page = m_frame->page()) { 761 if (Page* page = m_frame->page()) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 ClientRedirectPolicy clientRedirect, 856 ClientRedirectPolicy clientRedirect,
854 Document* initiatingDocument) { 857 Document* initiatingDocument) {
855 // If we have a state object, we cannot also be a new navigation. 858 // If we have a state object, we cannot also be a new navigation.
856 DCHECK(!stateObject || frameLoadType == FrameLoadTypeBackForward); 859 DCHECK(!stateObject || frameLoadType == FrameLoadTypeBackForward);
857 860
858 // If we have a provisional request for a different document, a fragment 861 // If we have a provisional request for a different document, a fragment
859 // scroll should cancel it. 862 // scroll should cancel it.
860 detachDocumentLoader(m_provisionalDocumentLoader); 863 detachDocumentLoader(m_provisionalDocumentLoader);
861 if (!m_frame->host()) 864 if (!m_frame->host())
862 return; 865 return;
863 AutoReset<FrameLoadType> loadTypeChange(&m_loadType, frameLoadType);
864 saveScrollState(); 866 saveScrollState();
865 867
866 KURL oldURL = m_frame->document()->url(); 868 KURL oldURL = m_frame->document()->url();
867 bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && 869 bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) &&
868 url.fragmentIdentifier() != oldURL.fragmentIdentifier(); 870 url.fragmentIdentifier() != oldURL.fragmentIdentifier();
869 if (hashChange) { 871 if (hashChange) {
870 // If we were in the autoscroll/middleClickAutoscroll mode we want to stop 872 // If we were in the autoscroll/middleClickAutoscroll mode we want to stop
871 // it before following the link to the anchor 873 // it before following the link to the anchor
872 m_frame->eventHandler().stopAutoscroll(); 874 m_frame->eventHandler().stopAutoscroll();
873 m_frame->domWindow()->enqueueHashchangeEvent(oldURL, url); 875 m_frame->domWindow()->enqueueHashchangeEvent(oldURL, url);
874 } 876 }
875 m_documentLoader->setIsClientRedirect(clientRedirect == 877 m_documentLoader->setIsClientRedirect(clientRedirect ==
876 ClientRedirectPolicy::ClientRedirect); 878 ClientRedirectPolicy::ClientRedirect);
877 updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr, 879 updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr,
878 ScrollRestorationAuto, frameLoadType, 880 ScrollRestorationAuto, frameLoadType,
879 initiatingDocument); 881 initiatingDocument);
880 882
881 m_documentLoader->initialScrollState().wasScrolledByUser = false; 883 m_documentLoader->initialScrollState().wasScrolledByUser = false;
882 884
883 checkCompleted(); 885 checkCompleted();
884 886
885 m_frame->domWindow()->statePopped(stateObject 887 m_frame->domWindow()->statePopped(stateObject
886 ? std::move(stateObject) 888 ? std::move(stateObject)
887 : SerializedScriptValue::nullValue()); 889 : SerializedScriptValue::nullValue());
888 890
889 if (historyLoadType == HistorySameDocumentLoad) 891 if (historyLoadType == HistorySameDocumentLoad)
890 restoreScrollPositionAndViewState(); 892 restoreScrollPositionAndViewStateForLoadType(frameLoadType);
891 893
892 // We need to scroll to the fragment whether or not a hash change occurred, 894 // We need to scroll to the fragment whether or not a hash change occurred,
893 // since the user might have scrolled since the previous navigation. 895 // since the user might have scrolled since the previous navigation.
894 processFragment(url, NavigationWithinSameDocument); 896 processFragment(url, frameLoadType, NavigationWithinSameDocument);
895 takeObjectSnapshot(); 897 takeObjectSnapshot();
896 } 898 }
897 899
898 // static 900 // static
899 void FrameLoader::setReferrerForFrameRequest(FrameLoadRequest& frameRequest) { 901 void FrameLoader::setReferrerForFrameRequest(FrameLoadRequest& frameRequest) {
900 ResourceRequest& request = frameRequest.resourceRequest(); 902 ResourceRequest& request = frameRequest.resourceRequest();
901 Document* originDocument = frameRequest.originDocument(); 903 Document* originDocument = frameRequest.originDocument();
902 904
903 if (!originDocument) 905 if (!originDocument)
904 return; 906 return;
(...skipping 18 matching lines...) Expand all
923 FrameLoadType FrameLoader::determineFrameLoadType( 925 FrameLoadType FrameLoader::determineFrameLoadType(
924 const FrameLoadRequest& request) { 926 const FrameLoadRequest& request) {
925 if (m_frame->tree().parent() && 927 if (m_frame->tree().parent() &&
926 !m_stateMachine.committedFirstRealDocumentLoad()) 928 !m_stateMachine.committedFirstRealDocumentLoad())
927 return FrameLoadTypeInitialInChildFrame; 929 return FrameLoadTypeInitialInChildFrame;
928 if (!m_frame->tree().parent() && !client()->backForwardLength()) 930 if (!m_frame->tree().parent() && !client()->backForwardLength())
929 return FrameLoadTypeStandard; 931 return FrameLoadTypeStandard;
930 if (m_provisionalDocumentLoader && 932 if (m_provisionalDocumentLoader &&
931 request.substituteData().failingURL() == 933 request.substituteData().failingURL() ==
932 m_provisionalDocumentLoader->url() && 934 m_provisionalDocumentLoader->url() &&
933 m_loadType == FrameLoadTypeBackForward) 935 m_provisionalDocumentLoader->loadType() == FrameLoadTypeBackForward)
934 return FrameLoadTypeBackForward; 936 return FrameLoadTypeBackForward;
935 if (request.resourceRequest().getCachePolicy() == 937 if (request.resourceRequest().getCachePolicy() ==
936 WebCachePolicy::ValidatingCacheData) 938 WebCachePolicy::ValidatingCacheData)
937 return FrameLoadTypeReload; 939 return FrameLoadTypeReload;
938 if (request.resourceRequest().getCachePolicy() == 940 if (request.resourceRequest().getCachePolicy() ==
939 WebCachePolicy::BypassingCache) 941 WebCachePolicy::BypassingCache)
940 return FrameLoadTypeReloadBypassingCache; 942 return FrameLoadTypeReloadBypassingCache;
941 // From the HTML5 spec for location.assign(): 943 // From the HTML5 spec for location.assign():
942 // "If the browsing context's session history contains only one Document, 944 // "If the browsing context's session history contains only one Document,
943 // and that was the about:blank Document created when the browsing context 945 // and that was the about:blank Document created when the browsing context
944 // was created, then the navigation must be done with replacement enabled." 946 // was created, then the navigation must be done with replacement enabled."
945 if (request.replacesCurrentItem() || 947 if (request.replacesCurrentItem() ||
946 (!m_stateMachine.committedMultipleRealLoads() && 948 (!m_stateMachine.committedMultipleRealLoads() &&
947 equalIgnoringCase(m_frame->document()->url(), blankURL()))) 949 equalIgnoringCase(m_frame->document()->url(), blankURL())))
948 return FrameLoadTypeReplaceCurrentItem; 950 return FrameLoadTypeReplaceCurrentItem;
949 951
950 if (request.resourceRequest().url() == m_documentLoader->urlForHistory()) { 952 if (request.resourceRequest().url() == m_documentLoader->urlForHistory()) {
951 if (request.resourceRequest().httpMethod() == HTTPNames::POST) 953 if (request.resourceRequest().httpMethod() == HTTPNames::POST)
952 return FrameLoadTypeStandard; 954 return FrameLoadTypeStandard;
953 if (!request.originDocument()) 955 if (!request.originDocument())
954 return FrameLoadTypeReloadMainResource; 956 return FrameLoadTypeReloadMainResource;
955 return FrameLoadTypeReplaceCurrentItem; 957 return FrameLoadTypeReplaceCurrentItem;
956 } 958 }
957 959
958 if (request.substituteData().failingURL() == 960 if (request.substituteData().failingURL() ==
959 m_documentLoader->urlForHistory() && 961 m_documentLoader->urlForHistory() &&
960 m_loadType == FrameLoadTypeReload) 962 m_documentLoader->loadType() == FrameLoadTypeReload)
961 return FrameLoadTypeReload; 963 return FrameLoadTypeReload;
962 964
963 if (m_frame->settings()->getHistoryEntryRequiresUserGesture() && 965 if (m_frame->settings()->getHistoryEntryRequiresUserGesture() &&
964 request.originDocument() && 966 request.originDocument() &&
965 !request.originDocument()->hasReceivedUserGesture()) 967 !request.originDocument()->hasReceivedUserGesture())
966 return FrameLoadTypeReplaceCurrentItem; 968 return FrameLoadTypeReplaceCurrentItem;
967 969
968 return FrameLoadTypeStandard; 970 return FrameLoadTypeStandard;
969 } 971 }
970 972
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 DOMWindow* window = m_frame->domWindow(); 1367 DOMWindow* window = m_frame->domWindow();
1366 window->setStatus(String()); 1368 window->setStatus(String());
1367 window->setDefaultStatus(String()); 1369 window->setDefaultStatus(String());
1368 } 1370 }
1369 } 1371 }
1370 1372
1371 bool FrameLoader::isLoadingMainFrame() const { 1373 bool FrameLoader::isLoadingMainFrame() const {
1372 return m_frame->isMainFrame(); 1374 return m_frame->isMainFrame();
1373 } 1375 }
1374 1376
1375 FrameLoadType FrameLoader::loadType() const { 1377 void FrameLoader::restoreScrollPositionAndViewState() {
1376 return m_loadType; 1378 if (!m_frame->page() || !documentLoader())
1379 return;
1380 restoreScrollPositionAndViewStateForLoadType(documentLoader()->loadType());
1377 } 1381 }
1378 1382
1379 void FrameLoader::restoreScrollPositionAndViewState() { 1383 void FrameLoader::restoreScrollPositionAndViewStateForLoadType(
1384 FrameLoadType loadType) {
1380 FrameView* view = m_frame->view(); 1385 FrameView* view = m_frame->view();
1381 if (!m_frame->page() || !view || !view->layoutViewportScrollableArea() || 1386 if (!view || !view->layoutViewportScrollableArea() || !m_currentItem ||
1382 !m_currentItem || !m_stateMachine.committedFirstRealDocumentLoad() || 1387 !m_stateMachine.committedFirstRealDocumentLoad()) {
1383 !documentLoader()) {
1384 return; 1388 return;
1385 } 1389 }
1386 1390 if (!needsHistoryItemRestore(loadType))
1387 if (!needsHistoryItemRestore(m_loadType))
1388 return; 1391 return;
1389 1392
1390 bool shouldRestoreScroll = 1393 bool shouldRestoreScroll =
1391 m_currentItem->scrollRestorationType() != ScrollRestorationManual; 1394 m_currentItem->scrollRestorationType() != ScrollRestorationManual;
1392 bool shouldRestoreScale = m_currentItem->pageScaleFactor(); 1395 bool shouldRestoreScale = m_currentItem->pageScaleFactor();
1393 1396
1394 // This tries to balance: 1397 // This tries to balance:
1395 // 1. restoring as soon as possible 1398 // 1. restoring as soon as possible
1396 // 2. not overriding user scroll (TODO(majidvp): also respect user scale) 1399 // 2. not overriding user scroll (TODO(majidvp): also respect user scale)
1397 // 3. detecting clamping to avoid repeatedly popping the scroll position down 1400 // 3. detecting clamping to avoid repeatedly popping the scroll position down
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 } 1472 }
1470 1473
1471 void FrameLoader::loadFailed(DocumentLoader* loader, 1474 void FrameLoader::loadFailed(DocumentLoader* loader,
1472 const ResourceError& error) { 1475 const ResourceError& error) {
1473 if (!error.isCancellation() && m_frame->owner()) { 1476 if (!error.isCancellation() && m_frame->owner()) {
1474 // FIXME: For now, fallback content doesn't work cross process. 1477 // FIXME: For now, fallback content doesn't work cross process.
1475 if (m_frame->owner()->isLocal()) 1478 if (m_frame->owner()->isLocal())
1476 m_frame->deprecatedLocalOwner()->renderFallbackContent(); 1479 m_frame->deprecatedLocalOwner()->renderFallbackContent();
1477 } 1480 }
1478 1481
1479 HistoryCommitType historyCommitType = loadTypeToCommitType(m_loadType); 1482 HistoryCommitType historyCommitType =
1483 loadTypeToCommitType(loader->loadType());
1480 if (loader == m_provisionalDocumentLoader) { 1484 if (loader == m_provisionalDocumentLoader) {
1481 m_provisionalDocumentLoader->setSentDidFinishLoad(); 1485 m_provisionalDocumentLoader->setSentDidFinishLoad();
1482 client()->dispatchDidFailProvisionalLoad(error, historyCommitType); 1486 client()->dispatchDidFailProvisionalLoad(error, historyCommitType);
1483 if (loader != m_provisionalDocumentLoader) 1487 if (loader != m_provisionalDocumentLoader)
1484 return; 1488 return;
1485 detachDocumentLoader(m_provisionalDocumentLoader); 1489 detachDocumentLoader(m_provisionalDocumentLoader);
1486 } else { 1490 } else {
1487 DCHECK_EQ(loader, m_documentLoader); 1491 DCHECK_EQ(loader, m_documentLoader);
1488 if (m_frame->document()->parser()) 1492 if (m_frame->document()->parser())
1489 m_frame->document()->parser()->stopParsing(); 1493 m_frame->document()->parser()->stopParsing();
(...skipping 15 matching lines...) Expand all
1505 return (!isFormSubmission || equalIgnoringCase(httpMethod, HTTPNames::GET)) && 1509 return (!isFormSubmission || equalIgnoringCase(httpMethod, HTTPNames::GET)) &&
1506 !isReloadLoadType(loadType) && loadType != FrameLoadTypeBackForward && 1510 !isReloadLoadType(loadType) && loadType != FrameLoadTypeBackForward &&
1507 url.hasFragmentIdentifier() && 1511 url.hasFragmentIdentifier() &&
1508 equalIgnoringFragmentIdentifier(m_frame->document()->url(), url) 1512 equalIgnoringFragmentIdentifier(m_frame->document()->url(), url)
1509 // We don't want to just scroll if a link from within a frameset is 1513 // We don't want to just scroll if a link from within a frameset is
1510 // trying to reload the frameset into _top. 1514 // trying to reload the frameset into _top.
1511 && !m_frame->document()->isFrameSet(); 1515 && !m_frame->document()->isFrameSet();
1512 } 1516 }
1513 1517
1514 void FrameLoader::processFragment(const KURL& url, 1518 void FrameLoader::processFragment(const KURL& url,
1519 FrameLoadType frameLoadType,
1515 LoadStartType loadStartType) { 1520 LoadStartType loadStartType) {
1516 FrameView* view = m_frame->view(); 1521 FrameView* view = m_frame->view();
1517 if (!view) 1522 if (!view)
1518 return; 1523 return;
1519 1524
1520 // Leaking scroll position to a cross-origin ancestor would permit the 1525 // Leaking scroll position to a cross-origin ancestor would permit the
1521 // so-called "framesniffing" attack. 1526 // so-called "framesniffing" attack.
1522 Frame* boundaryFrame = 1527 Frame* boundaryFrame =
1523 url.hasFragmentIdentifier() 1528 url.hasFragmentIdentifier()
1524 ? m_frame->findUnsafeParentScrollPropagationBoundary() 1529 ? m_frame->findUnsafeParentScrollPropagationBoundary()
1525 : 0; 1530 : 0;
1526 1531
1527 // FIXME: Handle RemoteFrames 1532 // FIXME: Handle RemoteFrames
1528 if (boundaryFrame && boundaryFrame->isLocalFrame()) { 1533 if (boundaryFrame && boundaryFrame->isLocalFrame()) {
1529 toLocalFrame(boundaryFrame) 1534 toLocalFrame(boundaryFrame)
1530 ->view() 1535 ->view()
1531 ->setSafeToPropagateScrollToParent(false); 1536 ->setSafeToPropagateScrollToParent(false);
1532 } 1537 }
1533 1538
1534 // If scroll position is restored from history fragment or scroll 1539 // If scroll position is restored from history fragment or scroll
1535 // restoration type is manual, then we should not override it unless this 1540 // restoration type is manual, then we should not override it unless this
1536 // is a same document reload. 1541 // is a same document reload.
1537 bool shouldScrollToFragment = 1542 bool shouldScrollToFragment =
1538 (loadStartType == NavigationWithinSameDocument && 1543 (loadStartType == NavigationWithinSameDocument &&
1539 !isBackForwardLoadType(m_loadType)) || 1544 !isBackForwardLoadType(frameLoadType)) ||
1540 (documentLoader() && 1545 (documentLoader() &&
1541 !documentLoader()->initialScrollState().didRestoreFromHistory && 1546 !documentLoader()->initialScrollState().didRestoreFromHistory &&
1542 !(m_currentItem && 1547 !(m_currentItem &&
1543 m_currentItem->scrollRestorationType() == ScrollRestorationManual)); 1548 m_currentItem->scrollRestorationType() == ScrollRestorationManual));
1544 1549
1545 view->processUrlFragment(url, shouldScrollToFragment 1550 view->processUrlFragment(url, shouldScrollToFragment
1546 ? FrameView::UrlFragmentScroll 1551 ? FrameView::UrlFragmentScroll
1547 : FrameView::UrlFragmentDontScroll); 1552 : FrameView::UrlFragmentDontScroll);
1548 1553
1549 if (boundaryFrame && boundaryFrame->isLocalFrame()) 1554 if (boundaryFrame && boundaryFrame->isLocalFrame())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 return shouldClose; 1593 return shouldClose;
1589 } 1594 }
1590 1595
1591 bool FrameLoader::shouldContinueForNavigationPolicy( 1596 bool FrameLoader::shouldContinueForNavigationPolicy(
1592 const ResourceRequest& request, 1597 const ResourceRequest& request,
1593 const SubstituteData& substituteData, 1598 const SubstituteData& substituteData,
1594 DocumentLoader* loader, 1599 DocumentLoader* loader,
1595 ContentSecurityPolicyDisposition shouldCheckMainWorldContentSecurityPolicy, 1600 ContentSecurityPolicyDisposition shouldCheckMainWorldContentSecurityPolicy,
1596 NavigationType type, 1601 NavigationType type,
1597 NavigationPolicy policy, 1602 NavigationPolicy policy,
1598 bool replacesCurrentHistoryItem, 1603 FrameLoadType frameLoadType,
1599 bool isClientRedirect, 1604 bool isClientRedirect,
1600 HTMLFormElement* form) { 1605 HTMLFormElement* form) {
1601 m_isNavigationHandledByClient = false; 1606 m_isNavigationHandledByClient = false;
1602 1607
1603 // Don't ask if we are loading an empty URL. 1608 // Don't ask if we are loading an empty URL.
1604 if (request.url().isEmpty() || substituteData.isValid()) 1609 if (request.url().isEmpty() || substituteData.isValid())
1605 return true; 1610 return true;
1606 1611
1607 // If we're loading content into |m_frame| (NavigationPolicyCurrentTab), check 1612 // If we're loading content into |m_frame| (NavigationPolicyCurrentTab), check
1608 // against the parent's Content Security Policy and kill the load if that 1613 // against the parent's Content Security Policy and kill the load if that
(...skipping 16 matching lines...) Expand all
1625 } 1630 }
1626 } 1631 }
1627 1632
1628 bool isFormSubmission = type == NavigationTypeFormSubmitted || 1633 bool isFormSubmission = type == NavigationTypeFormSubmitted ||
1629 type == NavigationTypeFormResubmitted; 1634 type == NavigationTypeFormResubmitted;
1630 if (isFormSubmission && 1635 if (isFormSubmission &&
1631 !m_frame->document()->contentSecurityPolicy()->allowFormAction( 1636 !m_frame->document()->contentSecurityPolicy()->allowFormAction(
1632 request.url())) 1637 request.url()))
1633 return false; 1638 return false;
1634 1639
1640 bool replacesCurrentHistoryItem =
1641 frameLoadType == FrameLoadTypeReplaceCurrentItem;
1635 policy = client()->decidePolicyForNavigation(request, loader, type, policy, 1642 policy = client()->decidePolicyForNavigation(request, loader, type, policy,
1636 replacesCurrentHistoryItem, 1643 replacesCurrentHistoryItem,
1637 isClientRedirect, form); 1644 isClientRedirect, form);
1638 if (policy == NavigationPolicyCurrentTab) 1645 if (policy == NavigationPolicyCurrentTab)
1639 return true; 1646 return true;
1640 if (policy == NavigationPolicyIgnore) 1647 if (policy == NavigationPolicyIgnore)
1641 return false; 1648 return false;
1642 if (policy == NavigationPolicyHandledByClient) { 1649 if (policy == NavigationPolicyHandledByClient) {
1643 m_isNavigationHandledByClient = true; 1650 m_isNavigationHandledByClient = true;
1644 // Mark the frame as loading since the embedder is handling the navigation. 1651 // Mark the frame as loading since the embedder is handling the navigation.
1645 m_progressTracker->progressStarted(); 1652 m_progressTracker->progressStarted(frameLoadType);
1646 1653
1647 m_frame->navigationScheduler().cancel(); 1654 m_frame->navigationScheduler().cancel();
1648 1655
1649 // If this is a form submit, dispatch that a form is being submitted 1656 // If this is a form submit, dispatch that a form is being submitted
1650 // since the embedder is handling the navigation. 1657 // since the embedder is handling the navigation.
1651 if (form) 1658 if (form)
1652 client()->dispatchWillSubmitForm(form); 1659 client()->dispatchWillSubmitForm(form);
1653 1660
1654 return false; 1661 return false;
1655 } 1662 }
(...skipping 23 matching lines...) Expand all
1679 ? WebURLRequest::FrameTypeTopLevel 1686 ? WebURLRequest::FrameTypeTopLevel
1680 : WebURLRequest::FrameTypeNested); 1687 : WebURLRequest::FrameTypeNested);
1681 1688
1682 // Record the latest requiredCSP value that will be used when sending this 1689 // Record the latest requiredCSP value that will be used when sending this
1683 // request. 1690 // request.
1684 recordLatestRequiredCSP(); 1691 recordLatestRequiredCSP();
1685 modifyRequestForCSP(resourceRequest, nullptr); 1692 modifyRequestForCSP(resourceRequest, nullptr);
1686 if (!shouldContinueForNavigationPolicy( 1693 if (!shouldContinueForNavigationPolicy(
1687 resourceRequest, frameLoadRequest.substituteData(), nullptr, 1694 resourceRequest, frameLoadRequest.substituteData(), nullptr,
1688 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(), 1695 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(),
1689 navigationType, navigationPolicy, 1696 navigationType, navigationPolicy, type,
1690 type == FrameLoadTypeReplaceCurrentItem,
1691 frameLoadRequest.clientRedirect() == 1697 frameLoadRequest.clientRedirect() ==
1692 ClientRedirectPolicy::ClientRedirect, 1698 ClientRedirectPolicy::ClientRedirect,
1693 frameLoadRequest.form())) 1699 frameLoadRequest.form()))
1694 return; 1700 return;
1695 1701
1696 m_frame->document()->cancelParsing(); 1702 m_frame->document()->cancelParsing();
1697 detachDocumentLoader(m_provisionalDocumentLoader); 1703 detachDocumentLoader(m_provisionalDocumentLoader);
1698 1704
1699 // beforeunload fired above, and detaching a DocumentLoader can fire events, 1705 // beforeunload fired above, and detaching a DocumentLoader can fire events,
1700 // which can detach this frame. 1706 // which can detach this frame.
1701 if (!m_frame->host()) 1707 if (!m_frame->host())
1702 return; 1708 return;
1703 1709
1704 m_provisionalDocumentLoader = client()->createDocumentLoader( 1710 m_provisionalDocumentLoader = client()->createDocumentLoader(
1705 m_frame, resourceRequest, 1711 m_frame, resourceRequest,
1706 frameLoadRequest.substituteData().isValid() 1712 frameLoadRequest.substituteData().isValid()
1707 ? frameLoadRequest.substituteData() 1713 ? frameLoadRequest.substituteData()
1708 : defaultSubstituteDataForURL(resourceRequest.url()), 1714 : defaultSubstituteDataForURL(resourceRequest.url()),
1709 frameLoadRequest.clientRedirect()); 1715 frameLoadRequest.clientRedirect());
1716 m_provisionalDocumentLoader->setLoadType(type);
1710 m_provisionalDocumentLoader->setNavigationType(navigationType); 1717 m_provisionalDocumentLoader->setNavigationType(navigationType);
1711 m_provisionalDocumentLoader->setReplacesCurrentHistoryItem( 1718 m_provisionalDocumentLoader->setReplacesCurrentHistoryItem(
1712 type == FrameLoadTypeReplaceCurrentItem); 1719 type == FrameLoadTypeReplaceCurrentItem);
1713 m_frame->navigationScheduler().cancel(); 1720 m_frame->navigationScheduler().cancel();
1714 m_checkTimer.stop(); 1721 m_checkTimer.stop();
1715 1722
1716 m_loadType = type;
1717
1718 if (frameLoadRequest.form()) 1723 if (frameLoadRequest.form())
1719 client()->dispatchWillSubmitForm(frameLoadRequest.form()); 1724 client()->dispatchWillSubmitForm(frameLoadRequest.form());
1720 1725
1721 m_progressTracker->progressStarted(); 1726 m_progressTracker->progressStarted(type);
1722 m_provisionalDocumentLoader->appendRedirect( 1727 m_provisionalDocumentLoader->appendRedirect(
1723 m_provisionalDocumentLoader->getRequest().url()); 1728 m_provisionalDocumentLoader->getRequest().url());
1724 client()->dispatchDidStartProvisionalLoad(); 1729 client()->dispatchDidStartProvisionalLoad();
1725 DCHECK(m_provisionalDocumentLoader); 1730 DCHECK(m_provisionalDocumentLoader);
1726 m_provisionalDocumentLoader->startLoadingMainResource(); 1731 m_provisionalDocumentLoader->startLoadingMainResource();
1727 1732
1728 takeObjectSnapshot(); 1733 takeObjectSnapshot();
1729 } 1734 }
1730 1735
1731 void FrameLoader::applyUserAgent(ResourceRequest& request) { 1736 void FrameLoader::applyUserAgent(ResourceRequest& request) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 m_documentLoader ? m_documentLoader->url() : String()); 1910 m_documentLoader ? m_documentLoader->url() : String());
1906 return tracedValue; 1911 return tracedValue;
1907 } 1912 }
1908 1913
1909 inline void FrameLoader::takeObjectSnapshot() const { 1914 inline void FrameLoader::takeObjectSnapshot() const {
1910 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this, 1915 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this,
1911 toTracedValue()); 1916 toTracedValue());
1912 } 1917 }
1913 1918
1914 } // namespace blink 1919 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698