1/* 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Apple Inc. ("Apple") nor the names of 15 * its contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30#ifndef HistoryController_h 31#define HistoryController_h 32 33#include "FrameLoaderTypes.h" 34#include "SerializedScriptValue.h" 35#include <wtf/Noncopyable.h> 36#include <wtf/RefPtr.h> 37#include <wtf/text/WTFString.h> 38 39namespace WebCore { 40 41class Frame; 42class HistoryItem; 43class SerializedScriptValue; 44class StringWithDirection; 45 46class HistoryController { 47 WTF_MAKE_NONCOPYABLE(HistoryController); 48 WTF_MAKE_FAST_ALLOCATED; 49public: 50 enum HistoryUpdateType { UpdateAll, UpdateAllExceptBackForwardList }; 51 52 explicit HistoryController(Frame&); 53 ~HistoryController(); 54 55 void saveScrollPositionAndViewStateToItem(HistoryItem*); 56 void clearScrollPositionAndViewState(); 57 void restoreScrollPositionAndViewState(); 58 59 void updateBackForwardListForFragmentScroll(); 60 61 void saveDocumentState(); 62 void saveDocumentAndScrollState(); 63 void restoreDocumentState(); 64 65 void invalidateCurrentItemCachedPage(); 66 67 void updateForBackForwardNavigation(); 68 void updateForReload(); 69 void updateForStandardLoad(HistoryUpdateType updateType = UpdateAll); 70 void updateForRedirectWithLockedBackForwardList(); 71 void updateForClientRedirect(); 72 void updateForCommit(); 73 void updateForSameDocumentNavigation(); 74 void updateForFrameLoadCompleted(); 75 76 HistoryItem* currentItem() const { return m_currentItem.get(); } 77 void setCurrentItem(HistoryItem*); 78 void setCurrentItemTitle(const StringWithDirection&); 79 bool currentItemShouldBeReplaced() const; 80 void replaceCurrentItem(HistoryItem*); 81 82 HistoryItem* previousItem() const { return m_previousItem.get(); } 83 void clearPreviousItem(); 84 85 HistoryItem* provisionalItem() const { return m_provisionalItem.get(); } 86 void setProvisionalItem(HistoryItem*); 87 88 void pushState(PassRefPtr<SerializedScriptValue>, const String& title, const String& url); 89 void replaceState(PassRefPtr<SerializedScriptValue>, const String& title, const String& url); 90 91 void setDefersLoading(bool); 92 93private: 94 friend class Page; 95 bool shouldStopLoadingForHistoryItem(HistoryItem*) const; 96 void goToItem(HistoryItem*, FrameLoadType); 97 98 void initializeItem(HistoryItem*); 99 PassRefPtr<HistoryItem> createItem(); 100 PassRefPtr<HistoryItem> createItemTree(Frame& targetFrame, bool clipAtTarget); 101 102 void recursiveSetProvisionalItem(HistoryItem*, HistoryItem*); 103 void recursiveGoToItem(HistoryItem*, HistoryItem*, FrameLoadType); 104 bool isReplaceLoadTypeWithProvisionalItem(FrameLoadType); 105 bool isReloadTypeWithProvisionalItem(FrameLoadType); 106 void recursiveUpdateForCommit(); 107 void recursiveUpdateForSameDocumentNavigation(); 108 bool itemsAreClones(HistoryItem*, HistoryItem*) const; 109 bool currentFramesMatchItem(HistoryItem*) const; 110 void updateBackForwardListClippedAtTarget(bool doClip); 111 void updateCurrentItem(); 112 113 Frame& m_frame; 114 115 RefPtr<HistoryItem> m_currentItem; 116 RefPtr<HistoryItem> m_previousItem; 117 RefPtr<HistoryItem> m_provisionalItem; 118 119 bool m_frameLoadComplete; 120 121 bool m_defersLoading; 122 RefPtr<HistoryItem> m_deferredItem; 123 FrameLoadType m_deferredFrameLoadType; 124}; 125 126} // namespace WebCore 127 128#endif // HistoryController_h 129