⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 127221 in webkit


Ignore:
Timestamp:
Aug 30, 2012, 6:14:53 PM (14 years ago)
Author:
tkent@chromium.org
Message:

Merge 126839 - REGRESSION(r109480): Form state for iframe content is not restored
​https://bugs.webkit.org/show_bug.cgi?id=90870

Reviewed by Jochen Eisinger.

Source/WebCore:

Since r109480, we have restored form state only for documents
loaded by FrameLoader::loadItem(). However we should restore form
state for documents in sub-frames of documents loaded by
FrameLoader::loadItem().

Test: fast/loader/form-state-restore-with-frames.html

  • history/HistoryItem.cpp:

(WebCore::HistoryItem::isAncestorOf):
Added. A function to search descendants for the specified
HistoryItem. This is used by isAssociatedToRequestedHistoryItem().

  • history/HistoryItem.h:

(HistoryItem): Declare isAncestorOf().

  • loader/HistoryController.cpp:

(WebCore::HistoryController::saveDocumentState):
Don't save form state for detached document.
This is needed because saveDocumentState() is called twice; before
document detach and after document detach. We need to avoid the
latter call because formElementsState() for a detached document
produces an empty state.
(WebCore::isAssociatedToRequestedHistoryItem):
Added. This function checks the current HistoryItem is associated
to the HistoryItem specified to FrameLoader::loadItem().
(WebCore::HistoryController::restoreDocumentState):
Uses isAssociatedToRequestedHistoryItem().

LayoutTests:

  • fast/loader/form-state-restore-with-frames.html: Added.
  • fast/loader/form-state-restore-with-frames-expected.txt: Added.
  • fast/loader/resources/form-state-restore-with-frames-1.html: Added.

TBR=​tkent@chromium.org
Review URL: ​https://chromiumcodereview.appspot.com/10918017

Location:
branches/chromium/1229
Files:
3 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/chromium/1229/Source/WebCore/history/HistoryItem.cpp

    r116617 r127221  
    533533}
    534534
     535bool HistoryItem::isAncestorOf(const HistoryItem* item) const
     536{
     537    for (size_t i = 0; i < m_children.size(); ++i) {
     538        HistoryItem* child = m_children[i].get();
     539        if (child == item)
     540            return true;
     541        if (child->isAncestorOf(item))
     542            return true;
     543    }
     544    return false;
     545}
     546
    535547// We do same-document navigation if going to a different item and if either of the following is true:
    536548// - The other item corresponds to the same document (for history entries created via pushState or fragment changes).
  • branches/chromium/1229/Source/WebCore/history/HistoryItem.h

    r123438 r127221  
    172172    bool hasChildren() const;
    173173    void clearChildren();
     174    bool isAncestorOf(const HistoryItem*) const;
    174175   
    175176    bool shouldDoSameDocumentNavigationTo(HistoryItem* otherItem) const;
  • branches/chromium/1229/Source/WebCore/loader/HistoryController.cpp

    r123823 r127221  
    164164    ASSERT(document);
    165165   
    166     if (item->isCurrentDocument(document)) {
     166    if (item->isCurrentDocument(document) && document->attached()) {
    167167        LOG(Loading, "WebCoreLoading %s: saving form state to %p", m_frame->tree()->uniqueName().string().utf8().data(), item);
    168168        item->setDocumentState(document->formElementsState());
    … …  
    178178        frame->loader()->history()->saveScrollPositionAndViewStateToItem(frame->loader()->history()->currentItem());
    179179    }
     180}
     181
     182static inline bool isAssociatedToRequestedHistoryItem(const HistoryItem* current, Frame* frame, const HistoryItem* requested)
     183{
     184    if (requested == current)
     185        return true;
     186    if (requested)
     187        return false;
     188    while ((frame = frame->tree()->parent())) {
     189        requested = frame->loader()->requestedHistoryItem();
     190        if (!requested)
     191            continue;
     192        if (requested->isAncestorOf(current))
     193            return true;
     194    }
     195    return false;
    180196}
    181197
    … …  
    202218    if (!itemToRestore)
    203219        return;
    204     if (m_frame->loader()->requestedHistoryItem() == m_currentItem.get() && !m_frame->loader()->documentLoader()->isClientRedirect()) {
     220    if (isAssociatedToRequestedHistoryItem(itemToRestore, m_frame, m_frame->loader()->requestedHistoryItem()) && !m_frame->loader()->documentLoader()->isClientRedirect()) {
    205221        LOG(Loading, "WebCoreLoading %s: restoring form state from %p", m_frame->tree()->uniqueName().string().utf8().data(), itemToRestore);
    206222        doc->setStateForNewFormElements(itemToRestore->documentState());
Note: See TracChangeset for help on using the changeset viewer.