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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 clear(); | 283 clear(); |
284 | 284 |
285 // detachChildren() potentially detaches the frame from the document. The | 285 // detachChildren() potentially detaches the frame from the document. The |
286 // loading cannot continue in that case. | 286 // loading cannot continue in that case. |
287 if (!m_frame->page()) | 287 if (!m_frame->page()) |
288 return; | 288 return; |
289 | 289 |
290 documentLoader->replaceDocumentWhileExecutingJavaScriptURL(init, source, own
erDocument); | 290 documentLoader->replaceDocumentWhileExecutingJavaScriptURL(init, source, own
erDocument); |
291 } | 291 } |
292 | 292 |
293 void FrameLoader::setHistoryItemStateForCommit(HistoryCommitType historyCommitTy
pe, bool isPushOrReplaceState, PassRefPtr<SerializedScriptValue> stateObject) | 293 void FrameLoader::setHistoryItemStateForCommit(HistoryCommitType historyCommitTy
pe, bool isPushOrReplaceState, bool shouldRestoreScroll, PassRefPtr<SerializedSc
riptValue> stateObject) |
294 { | 294 { |
295 if (m_provisionalItem) | 295 if (m_provisionalItem) |
296 m_currentItem = m_provisionalItem.release(); | 296 m_currentItem = m_provisionalItem.release(); |
297 | 297 |
298 if (!m_currentItem || historyCommitType == StandardCommit) { | 298 if (!m_currentItem || historyCommitType == StandardCommit) { |
299 m_currentItem = HistoryItem::create(); | 299 m_currentItem = HistoryItem::create(); |
300 } else if (!isPushOrReplaceState && m_documentLoader->url() != m_currentItem
->url()) { | 300 } else if (!isPushOrReplaceState && m_documentLoader->url() != m_currentItem
->url()) { |
301 m_currentItem->generateNewItemSequenceNumber(); | 301 m_currentItem->generateNewItemSequenceNumber(); |
302 if (!equalIgnoringFragmentIdentifier(m_documentLoader->url(), m_currentI
tem->url())) | 302 if (!equalIgnoringFragmentIdentifier(m_documentLoader->url(), m_currentI
tem->url())) |
303 m_currentItem->generateNewDocumentSequenceNumber(); | 303 m_currentItem->generateNewDocumentSequenceNumber(); |
304 } | 304 } |
305 | 305 |
306 m_currentItem->setURL(m_documentLoader->urlForHistory()); | 306 m_currentItem->setURL(m_documentLoader->urlForHistory()); |
307 m_currentItem->setDocumentState(m_frame->document()->formElementsState()); | 307 m_currentItem->setDocumentState(m_frame->document()->formElementsState()); |
308 m_currentItem->setTarget(m_frame->tree().uniqueName()); | 308 m_currentItem->setTarget(m_frame->tree().uniqueName()); |
309 if (isPushOrReplaceState) | 309 if (isPushOrReplaceState) { |
310 m_currentItem->setStateObject(stateObject); | 310 m_currentItem->setStateObject(stateObject); |
| 311 m_currentItem->setShouldRestoreScroll(shouldRestoreScroll); |
| 312 } |
311 m_currentItem->setReferrer(SecurityPolicy::generateReferrer(m_documentLoader
->request().referrerPolicy(), m_currentItem->url(), m_documentLoader->request().
httpReferrer())); | 313 m_currentItem->setReferrer(SecurityPolicy::generateReferrer(m_documentLoader
->request().referrerPolicy(), m_currentItem->url(), m_documentLoader->request().
httpReferrer())); |
312 m_currentItem->setFormInfoFromRequest(m_documentLoader->request()); | 314 m_currentItem->setFormInfoFromRequest(m_documentLoader->request()); |
313 } | 315 } |
314 | 316 |
315 static HistoryCommitType loadTypeToCommitType(FrameLoadType type) | 317 static HistoryCommitType loadTypeToCommitType(FrameLoadType type) |
316 { | 318 { |
317 switch (type) { | 319 switch (type) { |
318 case FrameLoadTypeStandard: | 320 case FrameLoadTypeStandard: |
319 return StandardCommit; | 321 return StandardCommit; |
320 case FrameLoadTypeInitialInChildFrame: | 322 case FrameLoadTypeInitialInChildFrame: |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 // accessible, so bail early. | 551 // accessible, so bail early. |
550 if (!client()) | 552 if (!client()) |
551 return false; | 553 return false; |
552 Settings* settings = m_frame->settings(); | 554 Settings* settings = m_frame->settings(); |
553 bool allowed = client()->allowPlugins(settings && settings->pluginsEnabled()
); | 555 bool allowed = client()->allowPlugins(settings && settings->pluginsEnabled()
); |
554 if (!allowed && reason == AboutToInstantiatePlugin) | 556 if (!allowed && reason == AboutToInstantiatePlugin) |
555 client()->didNotAllowPlugins(); | 557 client()->didNotAllowPlugins(); |
556 return allowed; | 558 return allowed; |
557 } | 559 } |
558 | 560 |
559 void FrameLoader::updateForSameDocumentNavigation(const KURL& newURL, SameDocume
ntNavigationSource sameDocumentNavigationSource, PassRefPtr<SerializedScriptValu
e> data, FrameLoadType type) | 561 void FrameLoader::updateForSameDocumentNavigation(const KURL& newURL, SameDocume
ntNavigationSource sameDocumentNavigationSource, PassRefPtr<SerializedScriptValu
e> data, bool shouldRestoreScroll, FrameLoadType type) |
560 { | 562 { |
561 saveScrollState(); | 563 saveScrollState(); |
562 | 564 |
563 // Update the data source's request with the new URL to fake the URL change | 565 // Update the data source's request with the new URL to fake the URL change |
564 m_frame->document()->setURL(newURL); | 566 m_frame->document()->setURL(newURL); |
565 documentLoader()->setReplacesCurrentHistoryItem(type != FrameLoadTypeStandar
d); | 567 documentLoader()->setReplacesCurrentHistoryItem(type != FrameLoadTypeStandar
d); |
566 documentLoader()->updateForSameDocumentNavigation(newURL, sameDocumentNaviga
tionSource); | 568 documentLoader()->updateForSameDocumentNavigation(newURL, sameDocumentNaviga
tionSource); |
567 | 569 |
568 // Generate start and stop notifications only when loader is completed so th
at we | 570 // Generate start and stop notifications only when loader is completed so th
at we |
569 // don't fire them for fragment redirection that happens in window.onload ha
ndler. | 571 // don't fire them for fragment redirection that happens in window.onload ha
ndler. |
570 // See https://bugs.webkit.org/show_bug.cgi?id=31838 | 572 // See https://bugs.webkit.org/show_bug.cgi?id=31838 |
571 if (m_frame->document()->loadEventFinished()) | 573 if (m_frame->document()->loadEventFinished()) |
572 client()->didStartLoading(NavigationWithinSameDocument); | 574 client()->didStartLoading(NavigationWithinSameDocument); |
573 | 575 |
574 HistoryCommitType historyCommitType = loadTypeToCommitType(type); | 576 HistoryCommitType historyCommitType = loadTypeToCommitType(type); |
575 if (!m_currentItem) | 577 if (!m_currentItem) |
576 historyCommitType = HistoryInertCommit; | 578 historyCommitType = HistoryInertCommit; |
577 | 579 |
578 setHistoryItemStateForCommit(historyCommitType, sameDocumentNavigationSource
== SameDocumentNavigationHistoryApi, data); | 580 setHistoryItemStateForCommit(historyCommitType, sameDocumentNavigationSource
== SameDocumentNavigationHistoryApi, shouldRestoreScroll, data); |
579 client()->dispatchDidNavigateWithinPage(m_currentItem.get(), historyCommitTy
pe); | 581 client()->dispatchDidNavigateWithinPage(m_currentItem.get(), historyCommitTy
pe); |
580 client()->dispatchDidReceiveTitle(m_frame->document()->title()); | 582 client()->dispatchDidReceiveTitle(m_frame->document()->title()); |
581 if (m_frame->document()->loadEventFinished()) | 583 if (m_frame->document()->loadEventFinished()) |
582 client()->didStopLoading(); | 584 client()->didStopLoading(); |
583 } | 585 } |
584 | 586 |
585 void FrameLoader::loadInSameDocument(const KURL& url, PassRefPtr<SerializedScrip
tValue> stateObject, FrameLoadType type, ClientRedirectPolicy clientRedirect) | 587 void FrameLoader::loadInSameDocument(const KURL& url, PassRefPtr<SerializedScrip
tValue> stateObject, FrameLoadType type, ClientRedirectPolicy clientRedirect) |
586 { | 588 { |
587 // If we have a state object, we cannot also be a new navigation. | 589 // If we have a state object, we cannot also be a new navigation. |
588 ASSERT(!stateObject || type == FrameLoadTypeBackForward); | 590 ASSERT(!stateObject || type == FrameLoadTypeBackForward); |
(...skipping 10 matching lines...) Expand all Loading... |
599 m_loadType = type; | 601 m_loadType = type; |
600 | 602 |
601 KURL oldURL = m_frame->document()->url(); | 603 KURL oldURL = m_frame->document()->url(); |
602 // If we were in the autoscroll/panScroll mode we want to stop it before fol
lowing the link to the anchor | 604 // If we were in the autoscroll/panScroll mode we want to stop it before fol
lowing the link to the anchor |
603 bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && url.fragme
ntIdentifier() != oldURL.fragmentIdentifier(); | 605 bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && url.fragme
ntIdentifier() != oldURL.fragmentIdentifier(); |
604 if (hashChange) { | 606 if (hashChange) { |
605 m_frame->eventHandler().stopAutoscroll(); | 607 m_frame->eventHandler().stopAutoscroll(); |
606 m_frame->localDOMWindow()->enqueueHashchangeEvent(oldURL, url); | 608 m_frame->localDOMWindow()->enqueueHashchangeEvent(oldURL, url); |
607 } | 609 } |
608 m_documentLoader->setIsClientRedirect(clientRedirect == ClientRedirect); | 610 m_documentLoader->setIsClientRedirect(clientRedirect == ClientRedirect); |
609 updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr,
type); | 611 updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr,
true, type); |
610 | 612 |
611 m_frame->view()->setWasScrolledByUser(false); | 613 m_frame->view()->setWasScrolledByUser(false); |
612 | 614 |
613 // We need to scroll to the fragment whether or not a hash change occurred,
since | 615 // We need to scroll to the fragment whether or not a hash change occurred,
since |
614 // the user might have scrolled since the previous navigation. | 616 // the user might have scrolled since the previous navigation. |
615 scrollToFragmentWithParentBoundary(url); | 617 scrollToFragmentWithParentBoundary(url); |
616 checkCompleted(); | 618 checkCompleted(); |
617 | 619 |
618 m_frame->localDOMWindow()->statePopped(stateObject ? stateObject : Serialize
dScriptValue::nullValue()); | 620 m_frame->localDOMWindow()->statePopped(stateObject ? stateObject : Serialize
dScriptValue::nullValue()); |
619 } | 621 } |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 | 1018 |
1017 void FrameLoader::restoreScrollPositionAndViewState() | 1019 void FrameLoader::restoreScrollPositionAndViewState() |
1018 { | 1020 { |
1019 FrameView* view = m_frame->view(); | 1021 FrameView* view = m_frame->view(); |
1020 if (!m_frame->page() || !view || !m_currentItem || !m_stateMachine.committed
FirstRealDocumentLoad()) | 1022 if (!m_frame->page() || !view || !m_currentItem || !m_stateMachine.committed
FirstRealDocumentLoad()) |
1021 return; | 1023 return; |
1022 | 1024 |
1023 if (!needsHistoryItemRestore(m_loadType)) | 1025 if (!needsHistoryItemRestore(m_loadType)) |
1024 return; | 1026 return; |
1025 | 1027 |
| 1028 if (!m_currentItem->shouldRestoreScroll()) |
| 1029 return; |
| 1030 |
1026 // This tries to balance 1. restoring as soon as possible, 2. detecting | 1031 // This tries to balance 1. restoring as soon as possible, 2. detecting |
1027 // clamping to avoid repeatedly popping the scroll position down as the | 1032 // clamping to avoid repeatedly popping the scroll position down as the |
1028 // page height increases, 3. ignore clamp detection after load completes | 1033 // page height increases, 3. ignore clamp detection after load completes |
1029 // because that may be because the page will never reach its previous | 1034 // because that may be because the page will never reach its previous |
1030 // height. | 1035 // height. |
1031 bool canRestoreWithoutClamping = view->clampOffsetAtScale(m_currentItem->scr
ollPoint(), 1) == m_currentItem->scrollPoint(); | 1036 bool canRestoreWithoutClamping = view->clampOffsetAtScale(m_currentItem->scr
ollPoint(), 1) == m_currentItem->scrollPoint(); |
1032 bool canRestoreWithoutAnnoyingUser = !view->wasScrolledByUser() && (canResto
reWithoutClamping || m_frame->isLoading()); | 1037 bool canRestoreWithoutAnnoyingUser = !view->wasScrolledByUser() && (canResto
reWithoutClamping || m_frame->isLoading()); |
1033 if (!canRestoreWithoutAnnoyingUser) | 1038 if (!canRestoreWithoutAnnoyingUser) |
1034 return; | 1039 return; |
1035 | 1040 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 // FIXME: We need a way to propagate insecure requests policy flags to | 1456 // FIXME: We need a way to propagate insecure requests policy flags to |
1452 // out-of-process frames. For now, we'll always use default behavior. | 1457 // out-of-process frames. For now, we'll always use default behavior. |
1453 if (!parentFrame->isLocalFrame()) | 1458 if (!parentFrame->isLocalFrame()) |
1454 return nullptr; | 1459 return nullptr; |
1455 | 1460 |
1456 ASSERT(toLocalFrame(parentFrame)->document()); | 1461 ASSERT(toLocalFrame(parentFrame)->document()); |
1457 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade()
; | 1462 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade()
; |
1458 } | 1463 } |
1459 | 1464 |
1460 } // namespace blink | 1465 } // namespace blink |
OLD | NEW |