OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> | 5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> |
6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. |
7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> | 7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> |
8 * Copyright (C) 2011 Google Inc. All rights reserved. | 8 * Copyright (C) 2011 Google Inc. All rights reserved. |
9 * | 9 * |
10 * Redistribution and use in source and binary forms, with or without | 10 * Redistribution and use in source and binary forms, with or without |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 if (ScrollableArea* layoutScrollableArea = m_frame->view()->layoutViewportSc rollableArea()) | 243 if (ScrollableArea* layoutScrollableArea = m_frame->view()->layoutViewportSc rollableArea()) |
244 m_currentItem->setScrollPoint(layoutScrollableArea->scrollPosition()); | 244 m_currentItem->setScrollPoint(layoutScrollableArea->scrollPosition()); |
245 m_currentItem->setPinchViewportScrollPoint(m_frame->host()->pinchViewport(). visibleRect().location()); | 245 m_currentItem->setPinchViewportScrollPoint(m_frame->host()->pinchViewport(). visibleRect().location()); |
246 | 246 |
247 if (m_frame->isMainFrame()) | 247 if (m_frame->isMainFrame()) |
248 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor()); | 248 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor()); |
249 | 249 |
250 client()->didUpdateCurrentHistoryItem(); | 250 client()->didUpdateCurrentHistoryItem(); |
251 } | 251 } |
252 | 252 |
253 void FrameLoader::setScrollRestorationType(HistoryScrollRestorationType scrollRe storation) | |
Nate Chapin
2015/07/27 23:46:55
I don't think this method is sufficiently reusable
majidvp
2015/07/28 12:19:06
Acknowledged.
majidvp
2015/07/28 15:44:11
Done.
| |
254 { | |
255 if (!m_currentItem) | |
256 return; | |
257 | |
258 m_currentItem->setScrollRestorationType(scrollRestoration); | |
259 client()->didUpdateCurrentHistoryItem(); | |
Nate Chapin
2015/07/27 23:46:55
Is this actually necessary?
majidvp
2015/07/28 12:19:06
It causes a navigation sync with browser to be
sc
| |
260 } | |
261 | |
253 void FrameLoader::dispatchUnloadEvent() | 262 void FrameLoader::dispatchUnloadEvent() |
254 { | 263 { |
255 saveScrollState(); | 264 saveScrollState(); |
256 | 265 |
257 if (m_frame->document() && !SVGImage::isInSVGImage(m_frame->document())) | 266 if (m_frame->document() && !SVGImage::isInSVGImage(m_frame->document())) |
258 m_frame->document()->dispatchUnloadEvents(); | 267 m_frame->document()->dispatchUnloadEvents(); |
259 | 268 |
260 if (Page* page = m_frame->page()) | 269 if (Page* page = m_frame->page()) |
261 page->undoStack().didUnloadFrame(*m_frame); | 270 page->undoStack().didUnloadFrame(*m_frame); |
262 } | 271 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 // Don't propagate state from the old item if this is a different-document n avigation, unless the before | 379 // Don't propagate state from the old item if this is a different-document n avigation, unless the before |
371 // and after pages are logically related. This means they have the same url (ignoring fragment) and | 380 // and after pages are logically related. This means they have the same url (ignoring fragment) and |
372 // the new item was loaded via reload or client redirect. | 381 // the new item was loaded via reload or client redirect. |
373 if (navigationType == HistoryNavigationType::DifferentDocument && (historyCo mmitType != HistoryInertCommit || !equalIgnoringFragmentIdentifier(oldItem->url( ), m_currentItem->url()))) | 382 if (navigationType == HistoryNavigationType::DifferentDocument && (historyCo mmitType != HistoryInertCommit || !equalIgnoringFragmentIdentifier(oldItem->url( ), m_currentItem->url()))) |
374 return; | 383 return; |
375 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber()); | 384 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber()); |
376 m_currentItem->setScrollPoint(oldItem->scrollPoint()); | 385 m_currentItem->setScrollPoint(oldItem->scrollPoint()); |
377 m_currentItem->setPinchViewportScrollPoint(oldItem->pinchViewportScrollPoint ()); | 386 m_currentItem->setPinchViewportScrollPoint(oldItem->pinchViewportScrollPoint ()); |
378 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor()); | 387 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor()); |
379 m_currentItem->setStateObject(oldItem->stateObject()); | 388 m_currentItem->setStateObject(oldItem->stateObject()); |
389 m_currentItem->setScrollRestorationType(oldItem->scrollRestorationType()); | |
390 | |
380 // The item sequence number determines whether items are "the same", such ba ck/forward navigation | 391 // The item sequence number determines whether items are "the same", such ba ck/forward navigation |
381 // between items with the same item sequence number is a no-op. Only treat t his as identical if the | 392 // between items with the same item sequence number is a no-op. Only treat t his as identical if the |
382 // navigation did not create a back/forward entry and the url is identical o r it was loaded via | 393 // navigation did not create a back/forward entry and the url is identical o r it was loaded via |
383 // history.replaceState(). | 394 // history.replaceState(). |
384 if (historyCommitType == HistoryInertCommit && (navigationType == HistoryNav igationType::HistoryApi || oldItem->url() == m_currentItem->url())) | 395 if (historyCommitType == HistoryInertCommit && (navigationType == HistoryNav igationType::HistoryApi || oldItem->url() == m_currentItem->url())) |
385 m_currentItem->setItemSequenceNumber(oldItem->itemSequenceNumber()); | 396 m_currentItem->setItemSequenceNumber(oldItem->itemSequenceNumber()); |
386 } | 397 } |
387 | 398 |
388 static HistoryCommitType loadTypeToCommitType(FrameLoadType type) | 399 static HistoryCommitType loadTypeToCommitType(FrameLoadType type) |
389 { | 400 { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 m_frame->navigationScheduler().startTimer(); | 575 m_frame->navigationScheduler().startTimer(); |
565 | 576 |
566 if (m_frame->view()) | 577 if (m_frame->view()) |
567 m_frame->view()->handleLoadCompleted(); | 578 m_frame->view()->handleLoadCompleted(); |
568 | 579 |
569 if (shouldSendCompleteNotifications(m_frame)) { | 580 if (shouldSendCompleteNotifications(m_frame)) { |
570 m_loadType = FrameLoadTypeStandard; | 581 m_loadType = FrameLoadTypeStandard; |
571 m_progressTracker->progressCompleted(); | 582 m_progressTracker->progressCompleted(); |
572 // Retry restoring scroll offset since finishing loading disables conten t | 583 // Retry restoring scroll offset since finishing loading disables conten t |
573 // size clamping. | 584 // size clamping. |
585 // TODO(majidvp): Remove this call as it appears to be a no-op because | |
586 // we set load type to |FrameLoadTypeStandard| just above. | |
574 restoreScrollPositionAndViewState(); | 587 restoreScrollPositionAndViewState(); |
575 m_frame->localDOMWindow()->finishedLoading(); | 588 m_frame->localDOMWindow()->finishedLoading(); |
576 | 589 |
577 // Report mobile vs. desktop page statistics. This will only report on A ndroid. | 590 // Report mobile vs. desktop page statistics. This will only report on A ndroid. |
578 if (m_frame->isMainFrame()) | 591 if (m_frame->isMainFrame()) |
579 m_frame->document()->viewportDescription().reportMobilePageStats(m_f rame); | 592 m_frame->document()->viewportDescription().reportMobilePageStats(m_f rame); |
580 client()->dispatchDidFinishLoad(); | 593 client()->dispatchDidFinishLoad(); |
581 } | 594 } |
582 | 595 |
583 Frame* parent = m_frame->tree().parent(); | 596 Frame* parent = m_frame->tree().parent(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && url.fragme ntIdentifier() != oldURL.fragmentIdentifier(); | 696 bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && url.fragme ntIdentifier() != oldURL.fragmentIdentifier(); |
684 if (hashChange) { | 697 if (hashChange) { |
685 m_frame->eventHandler().stopAutoscroll(); | 698 m_frame->eventHandler().stopAutoscroll(); |
686 m_frame->localDOMWindow()->enqueueHashchangeEvent(oldURL, url); | 699 m_frame->localDOMWindow()->enqueueHashchangeEvent(oldURL, url); |
687 } | 700 } |
688 m_documentLoader->setIsClientRedirect(clientRedirect == ClientRedirect); | 701 m_documentLoader->setIsClientRedirect(clientRedirect == ClientRedirect); |
689 updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr, ScrollRestorationAuto, type); | 702 updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr, ScrollRestorationAuto, type); |
690 | 703 |
691 m_frame->view()->setWasScrolledByUser(false); | 704 m_frame->view()->setWasScrolledByUser(false); |
692 | 705 |
693 // We need to scroll to the fragment whether or not a hash change occurred, since | |
694 // the user might have scrolled since the previous navigation. | |
695 processFragment(url, NavigationWithinSameDocument); | |
696 checkCompleted(); | 706 checkCompleted(); |
697 | 707 |
698 m_frame->localDOMWindow()->statePopped(stateObject ? stateObject : Serialize dScriptValue::nullValue()); | 708 m_frame->localDOMWindow()->statePopped(stateObject ? stateObject : Serialize dScriptValue::nullValue()); |
699 } | 709 } |
700 | 710 |
701 void FrameLoader::setReferrerForFrameRequest(ResourceRequest& request, ShouldSen dReferrer shouldSendReferrer, Document* originDocument) | 711 void FrameLoader::setReferrerForFrameRequest(ResourceRequest& request, ShouldSen dReferrer shouldSendReferrer, Document* originDocument) |
702 { | 712 { |
703 if (!originDocument) | 713 if (!originDocument) |
704 return; | 714 return; |
705 // FIXME: This should be an assertion, but there's some plugin code in the c hromium repo | 715 // FIXME: This should be an assertion, but there's some plugin code in the c hromium repo |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 m_documentLoader->setNavigationType(determineNavigationType( | 917 m_documentLoader->setNavigationType(determineNavigationType( |
908 newLoadType, false, request.triggeringEvent())); | 918 newLoadType, false, request.triggeringEvent())); |
909 if (shouldTreatURLAsSameAsCurrent(url)) | 919 if (shouldTreatURLAsSameAsCurrent(url)) |
910 newLoadType = FrameLoadTypeReplaceCurrentItem; | 920 newLoadType = FrameLoadTypeReplaceCurrentItem; |
911 } | 921 } |
912 | 922 |
913 loadInSameDocument(url, stateObject, newLoadType, request.clientRedirect ()); | 923 loadInSameDocument(url, stateObject, newLoadType, request.clientRedirect ()); |
914 | 924 |
915 if (sameDocumentHistoryNavigation) | 925 if (sameDocumentHistoryNavigation) |
916 restoreScrollPositionAndViewState(); | 926 restoreScrollPositionAndViewState(); |
927 | |
928 // We need to scroll to the fragment whether or not a hash change occurr ed, since | |
929 // the user might have scrolled since the previous navigation. | |
930 processFragment(url, NavigationWithinSameDocument); | |
917 return; | 931 return; |
918 } | 932 } |
919 | 933 |
920 // Perform navigation to a different document. | 934 // Perform navigation to a different document. |
921 bool sameURL = url == m_documentLoader->urlForHistory(); | 935 bool sameURL = url == m_documentLoader->urlForHistory(); |
922 startLoad(request, newLoadType, policy); | 936 startLoad(request, newLoadType, policy); |
923 | 937 |
924 // Example of this case are sites that reload the same URL with a different cookie | 938 // Example of this case are sites that reload the same URL with a different cookie |
925 // driving the generated content, or a master frame with links that drive a target | 939 // driving the generated content, or a master frame with links that drive a target |
926 // frame, where the user has clicked on the same link repeatedly. | 940 // frame, where the user has clicked on the same link repeatedly. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 | 1115 |
1102 void FrameLoader::restoreScrollPositionAndViewState() | 1116 void FrameLoader::restoreScrollPositionAndViewState() |
1103 { | 1117 { |
1104 FrameView* view = m_frame->view(); | 1118 FrameView* view = m_frame->view(); |
1105 if (!m_frame->page() || !view || !m_currentItem || !m_stateMachine.committed FirstRealDocumentLoad()) | 1119 if (!m_frame->page() || !view || !m_currentItem || !m_stateMachine.committed FirstRealDocumentLoad()) |
1106 return; | 1120 return; |
1107 | 1121 |
1108 if (!needsHistoryItemRestore(m_loadType)) | 1122 if (!needsHistoryItemRestore(m_loadType)) |
1109 return; | 1123 return; |
1110 | 1124 |
1111 if (m_currentItem->scrollRestorationType() == ScrollRestorationManual) | 1125 if (m_currentItem->scrollRestorationType() == ScrollRestorationManual) { |
1126 documentLoader()->initialScrollState().didRestoreFromHistory = true; | |
1112 return; | 1127 return; |
1128 } | |
1113 | 1129 |
1114 // This tries to balance 1. restoring as soon as possible, 2. detecting | 1130 // This tries to balance 1. restoring as soon as possible, 2. detecting |
1115 // clamping to avoid repeatedly popping the scroll position down as the | 1131 // clamping to avoid repeatedly popping the scroll position down as the |
1116 // page height increases, 3. ignore clamp detection after load completes | 1132 // page height increases, 3. ignore clamp detection after load completes |
1117 // because that may be because the page will never reach its previous | 1133 // because that may be because the page will never reach its previous |
1118 // height. | 1134 // height. |
1119 bool canRestoreWithoutClamping = view->clampOffsetAtScale(m_currentItem->scr ollPoint(), 1) == m_currentItem->scrollPoint(); | 1135 bool canRestoreWithoutClamping = view->clampOffsetAtScale(m_currentItem->scr ollPoint(), 1) == m_currentItem->scrollPoint(); |
1120 bool canRestoreWithoutAnnoyingUser = !view->wasScrolledByUser() && (canResto reWithoutClamping || m_frame->isLoading()); | 1136 bool canRestoreWithoutAnnoyingUser = !view->wasScrolledByUser() && (canResto reWithoutClamping || m_frame->isLoading()); |
1121 if (!canRestoreWithoutAnnoyingUser) | 1137 if (!canRestoreWithoutAnnoyingUser) |
1122 return; | 1138 return; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 if (!view) | 1245 if (!view) |
1230 return; | 1246 return; |
1231 | 1247 |
1232 // Leaking scroll position to a cross-origin ancestor would permit the so-ca lled "framesniffing" attack. | 1248 // Leaking scroll position to a cross-origin ancestor would permit the so-ca lled "framesniffing" attack. |
1233 RefPtrWillBeRawPtr<Frame> boundaryFrame = url.hasFragmentIdentifier() ? m_fr ame->findUnsafeParentScrollPropagationBoundary() : 0; | 1249 RefPtrWillBeRawPtr<Frame> boundaryFrame = url.hasFragmentIdentifier() ? m_fr ame->findUnsafeParentScrollPropagationBoundary() : 0; |
1234 | 1250 |
1235 // FIXME: Handle RemoteFrames | 1251 // FIXME: Handle RemoteFrames |
1236 if (boundaryFrame && boundaryFrame->isLocalFrame()) | 1252 if (boundaryFrame && boundaryFrame->isLocalFrame()) |
1237 toLocalFrame(boundaryFrame.get())->view()->setSafeToPropagateScrollToPar ent(false); | 1253 toLocalFrame(boundaryFrame.get())->view()->setSafeToPropagateScrollToPar ent(false); |
1238 | 1254 |
1239 view->processUrlFragment(url, | 1255 // If scroll position is restored from history fragment then we should not o verride it unless |
1240 loadStartType == NavigationToDifferentDocument && documentLoader()->init ialScrollState().didRestoreFromHistory ? | 1256 // this is a same document reload. |
1241 FrameView::UrlFragmentDontScroll : FrameView::UrlFragmentScroll); | 1257 bool shouldScrollToFragment = (loadStartType == NavigationWithinSameDocument && !isBackForwardLoadType(m_loadType)) |
1258 || !documentLoader()->initialScrollState().didRestoreFromHistory; | |
1259 | |
1260 view->processUrlFragment(url, shouldScrollToFragment ? | |
1261 FrameView::UrlFragmentScroll : FrameView::UrlFragmentDontScroll); | |
1242 | 1262 |
1243 if (boundaryFrame && boundaryFrame->isLocalFrame()) | 1263 if (boundaryFrame && boundaryFrame->isLocalFrame()) |
1244 toLocalFrame(boundaryFrame.get())->view()->setSafeToPropagateScrollToPar ent(true); | 1264 toLocalFrame(boundaryFrame.get())->view()->setSafeToPropagateScrollToPar ent(true); |
1245 } | 1265 } |
1246 | 1266 |
1247 bool FrameLoader::shouldClose() | 1267 bool FrameLoader::shouldClose() |
1248 { | 1268 { |
1249 Page* page = m_frame->page(); | 1269 Page* page = m_frame->page(); |
1250 if (!page || !page->chromeClient().canOpenBeforeUnloadConfirmPanel()) | 1270 if (!page || !page->chromeClient().canOpenBeforeUnloadConfirmPanel()) |
1251 return true; | 1271 return true; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1494 // FIXME: We need a way to propagate insecure requests policy flags to | 1514 // FIXME: We need a way to propagate insecure requests policy flags to |
1495 // out-of-process frames. For now, we'll always use default behavior. | 1515 // out-of-process frames. For now, we'll always use default behavior. |
1496 if (!parentFrame->isLocalFrame()) | 1516 if (!parentFrame->isLocalFrame()) |
1497 return nullptr; | 1517 return nullptr; |
1498 | 1518 |
1499 ASSERT(toLocalFrame(parentFrame)->document()); | 1519 ASSERT(toLocalFrame(parentFrame)->document()); |
1500 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ; | 1520 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade() ; |
1501 } | 1521 } |
1502 | 1522 |
1503 } // namespace blink | 1523 } // namespace blink |
OLD | NEW |