blob: 0901ed257942d71014772fb72f978ac6cb6d6f7e [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
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 Computer, 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 "bindings/v8/SerializedScriptValue.h"
34#include "core/loader/FrameLoaderTypes.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);
48public:
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010049 explicit HistoryController(Frame*);
50 ~HistoryController();
51
52 void saveScrollPositionAndViewStateToItem(HistoryItem*);
53 void clearScrollPositionAndViewState();
54 void restoreScrollPositionAndViewState();
55
56 void updateBackForwardListForFragmentScroll();
57
58 void saveDocumentState();
59 void saveDocumentAndScrollState();
60 void restoreDocumentState();
61
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010062 void updateForCommit();
63 void updateForSameDocumentNavigation();
64 void updateForFrameLoadCompleted();
65
66 HistoryItem* currentItem() const { return m_currentItem.get(); }
67 void setCurrentItem(HistoryItem*);
68 void setCurrentItemTitle(const StringWithDirection&);
69 bool currentItemShouldBeReplaced() const;
70
71 HistoryItem* previousItem() const { return m_previousItem.get(); }
72
73 HistoryItem* provisionalItem() const { return m_provisionalItem.get(); }
74 void setProvisionalItem(HistoryItem*);
75
76 void pushState(PassRefPtr<SerializedScriptValue>, const String& title, const String& url);
77 void replaceState(PassRefPtr<SerializedScriptValue>, const String& title, const String& url);
78
79 void setDefersLoading(bool);
80
81private:
82 friend class Page;
83 bool shouldStopLoadingForHistoryItem(HistoryItem*) const;
Torne (Richard Coles)81a51572013-05-13 16:52:28 +010084 void goToItem(HistoryItem*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010085
86 void initializeItem(HistoryItem*);
87 PassRefPtr<HistoryItem> createItem();
88 PassRefPtr<HistoryItem> createItemTree(Frame* targetFrame, bool clipAtTarget);
89
Torne (Richard Coles)81a51572013-05-13 16:52:28 +010090 void updateForBackForwardNavigation();
91 void updateForReload();
92 void updateForStandardLoad();
93 void updateForRedirectWithLockedBackForwardList();
94 void updateForInitialLoadInChildFrame();
95
96 void recursiveSetProvisionalItem(HistoryItem*, HistoryItem*);
97 void recursiveGoToItem(HistoryItem*, HistoryItem*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010098 bool isReplaceLoadTypeWithProvisionalItem(FrameLoadType);
99 bool isReloadTypeWithProvisionalItem(FrameLoadType);
100 void recursiveUpdateForCommit();
101 void recursiveUpdateForSameDocumentNavigation();
102 bool itemsAreClones(HistoryItem*, HistoryItem*) const;
103 bool currentFramesMatchItem(HistoryItem*) const;
104 void updateBackForwardListClippedAtTarget(bool doClip);
105 void updateCurrentItem();
106
107 Frame* m_frame;
108
109 RefPtr<HistoryItem> m_currentItem;
110 RefPtr<HistoryItem> m_previousItem;
111 RefPtr<HistoryItem> m_provisionalItem;
112
113 bool m_frameLoadComplete;
114
115 bool m_defersLoading;
116 RefPtr<HistoryItem> m_deferredItem;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100117};
118
119} // namespace WebCore
120
121#endif // HistoryController_h