OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 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.t
orchmobile.com/) | 3 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 14 matching lines...) Expand all Loading... |
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 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 | 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. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #ifndef HistoryController_h | 30 #ifndef HistoryController_h |
31 #define HistoryController_h | 31 #define HistoryController_h |
32 | 32 |
33 #include "core/history/HistoryItem.h" | 33 #include "core/history/HistoryItem.h" |
34 #include "core/loader/FrameLoaderTypes.h" | 34 #include "core/loader/FrameLoaderTypes.h" |
| 35 #include "wtf/HashMap.h" |
35 #include "wtf/Noncopyable.h" | 36 #include "wtf/Noncopyable.h" |
36 #include "wtf/RefPtr.h" | 37 #include "wtf/RefPtr.h" |
37 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
38 | 39 |
39 namespace WebCore { | 40 namespace WebCore { |
40 | 41 |
41 class Frame; | 42 class Frame; |
| 43 class HistoryEntry; |
| 44 class Page; |
42 class SerializedScriptValue; | 45 class SerializedScriptValue; |
43 | 46 |
| 47 |
| 48 // A guide to history state in Blink: |
| 49 // |
| 50 // HistoryController: Owned by Page, is the entry point for interacting with his
tory. |
| 51 // Handles most of the operations to modify history state, navigate to an ex
isting |
| 52 // back/forward entry, etc. |
| 53 // HistoryEntry: Represents a single entry in the back/forward list, encapsulati
ng |
| 54 // all frames in the page it represents. It provides access to each frame's |
| 55 // state via lookups by frame id or frame name. |
| 56 // HistoryNode: Represents a single frame in a HistoryEntry. Owned by a HistoryE
ntry. HistoryNodes |
| 57 // form a tree that mirrors the FrameTree in the corresponding page. HistoryNode
s represent |
| 58 // the structure of the page, but don't hold any per-frame state except a list o
f child frames. |
| 59 // HistoryItem (lives in a separate file): The state for a given frame. Can pers
ist across |
| 60 // navigations. HistoryItem is reference counted, and each HistoryNode holds
a reference |
| 61 // to its single corresponding HistoryItem. Can be referenced by multiple Hi
storyNodes and |
| 62 // can therefore exist in multiple HistoryEntry instances. |
| 63 // |
| 64 // Suppose we have the following page, foo.com, which embeds foo.com/a in an ifr
ame: |
| 65 // |
| 66 // HistoryEntry 0: |
| 67 // HistoryNode 0_0 (HistoryItem A (url: foo.com)) |
| 68 // HistoryNode 0_1: (HistoryItem B (url: foo.com/a)) |
| 69 // |
| 70 // Now we navigation the top frame to bar.com, which embeds bar.com/b and bar.co
m/c in iframes, |
| 71 // and bar.com/b in turn embeds bar.com/d. We will create a new HistoryEntry wit
h a tree |
| 72 // containing 4 new HistoryNodes. The state will be: |
| 73 // |
| 74 // HistoryEntry 1: |
| 75 // HistoryNode 1_0 (HistoryItem C (url: bar.com)) |
| 76 // HistoryNode 1_1: (HistoryItem D (url: bar.com/b)) |
| 77 // HistoryNode 1_3: (HistoryItem F (url: bar.com/d)) |
| 78 // HistoryNode 1_2: (HistoryItem E (url: bar.com/c)) |
| 79 // |
| 80 // |
| 81 // Finally, we navigate the first subframe from bar.com/b to bar.com/e, which em
beds bar.com/f. |
| 82 // We will create a new HistoryEntry and new HistoryNode for each frame. Any fra
me that |
| 83 // navigates (bar.com/e and its child, bar.com/f) will receive a new HistoryItem
. However, |
| 84 // 2 frames were not navigated (bar.com and bar.com/c), so those two frames will
reuse the |
| 85 // existing HistoryItem: |
| 86 // |
| 87 // HistoryEntry 2: |
| 88 // HistoryNode 2_0 (HistoryItem C (url: bar.com)) *REUSED* |
| 89 // HistoryNode 2_1: (HistoryItem G (url: bar.com/e)) |
| 90 // HistoryNode 2_3: (HistoryItem H (url: bar.com/f)) |
| 91 // HistoryNode 2_2: (HistoryItem E (url: bar.com/c)) *REUSED* |
| 92 // |
| 93 |
| 94 class HistoryNode { |
| 95 public: |
| 96 static PassOwnPtr<HistoryNode> create(HistoryEntry*, HistoryItem*); |
| 97 ~HistoryNode() { } |
| 98 |
| 99 HistoryNode* addChild(PassRefPtr<HistoryItem>); |
| 100 PassOwnPtr<HistoryNode> cloneAndReplace(HistoryEntry*, HistoryItem* newItem,
HistoryItem* oldItem, bool clipAtTarget, Frame*); |
| 101 HistoryItem* value() { return m_value.get(); } |
| 102 void updateValue(PassRefPtr<HistoryItem> item) { m_value = item; } |
| 103 const Vector<OwnPtr<HistoryNode> >& children() const { return m_children; } |
| 104 |
| 105 private: |
| 106 HistoryNode(HistoryEntry*, HistoryItem*); |
| 107 |
| 108 HistoryEntry* m_entry; |
| 109 Vector<OwnPtr<HistoryNode> > m_children; |
| 110 RefPtr<HistoryItem> m_value; |
| 111 }; |
| 112 |
| 113 class HistoryEntry { |
| 114 public: |
| 115 static PassOwnPtr<HistoryEntry> create(HistoryItem* root); |
| 116 PassOwnPtr<HistoryEntry> cloneAndReplace(HistoryItem* newItem, HistoryItem*
oldItem, bool clipAtTarget, Page*); |
| 117 |
| 118 HistoryNode* historyNodeForFrame(Frame*); |
| 119 HistoryItem* itemForFrame(Frame*); |
| 120 HistoryItem* root() const { return m_root->value(); } |
| 121 HistoryNode* rootHistoryNode() const { return m_root.get(); } |
| 122 |
| 123 private: |
| 124 friend class HistoryNode; |
| 125 |
| 126 HistoryEntry() { } |
| 127 explicit HistoryEntry(HistoryItem* root); |
| 128 |
| 129 OwnPtr<HistoryNode> m_root; |
| 130 HashMap<uint64_t, HistoryNode*> m_framesToItems; |
| 131 HashMap<String, HistoryNode*> m_uniqueNamesToItems; |
| 132 }; |
| 133 |
44 class HistoryController { | 134 class HistoryController { |
45 WTF_MAKE_NONCOPYABLE(HistoryController); | 135 WTF_MAKE_NONCOPYABLE(HistoryController); |
46 public: | 136 public: |
47 explicit HistoryController(Frame*); | 137 explicit HistoryController(Page*); |
48 ~HistoryController(); | 138 ~HistoryController(); |
49 | 139 |
| 140 // Should only be called by embedder. To request a back/forward |
| 141 // navigation, call FrameLoaderClient::navigateBackForward(). |
| 142 void goToItem(HistoryItem*); |
| 143 |
50 void clearScrollPositionAndViewState(); | 144 void clearScrollPositionAndViewState(); |
51 void restoreScrollPositionAndViewState(); | 145 void restoreScrollPositionAndViewState(Frame*); |
52 | 146 |
53 void updateBackForwardListForFragmentScroll(); | 147 void updateBackForwardListForFragmentScroll(Frame*); |
54 | 148 |
55 void saveDocumentAndScrollState(); | 149 void saveDocumentAndScrollState(Frame*); |
56 void restoreDocumentState(); | 150 void restoreDocumentState(Frame*); |
57 | 151 |
58 void updateForCommit(); | 152 void updateForCommit(Frame*); |
59 void updateForSameDocumentNavigation(); | 153 void updateForSameDocumentNavigation(Frame*); |
60 | 154 |
61 HistoryItem* currentItem() const { return m_currentItem.get(); } | 155 PassRefPtr<HistoryItem> currentItemForExport(Frame*); |
62 void setCurrentItem(HistoryItem*); | 156 PassRefPtr<HistoryItem> previousItemForExport(Frame*); |
63 bool currentItemShouldBeReplaced() const; | 157 PassRefPtr<HistoryItem> provisionalItemForExport(Frame*); |
64 | 158 |
65 HistoryItem* previousItem() const { return m_previousItem.get(); } | 159 HistoryItem* currentItem(Frame*) const; |
| 160 bool currentItemShouldBeReplaced(Frame*) const; |
66 | 161 |
67 HistoryItem* provisionalItem() const { return m_provisionalItem.get(); } | 162 HistoryItem* previousItem(Frame*) const; |
68 void setProvisionalItem(HistoryItem*); | 163 void clearProvisionalEntry(); |
69 | 164 |
70 void pushState(PassRefPtr<SerializedScriptValue>, const String& url); | 165 bool inSameDocumentLoad() const { return !m_sameDocumentLoadsInProgress.isEm
pty() && m_differentDocumentLoadsInProgress.isEmpty(); } |
71 void replaceState(PassRefPtr<SerializedScriptValue>, const String& url); | 166 |
| 167 void pushState(Frame*, PassRefPtr<SerializedScriptValue>, const String& url)
; |
| 168 void replaceState(Frame*, PassRefPtr<SerializedScriptValue>, const String& u
rl); |
72 | 169 |
73 void setDefersLoading(bool); | 170 void setDefersLoading(bool); |
74 | 171 |
75 private: | 172 private: |
76 friend class Page; | 173 void goToEntry(PassOwnPtr<HistoryEntry>); |
77 bool shouldStopLoadingForHistoryItem(HistoryItem*) const; | 174 void recursiveGoToEntry(Frame*); |
78 void goToItem(HistoryItem*); | |
79 | 175 |
80 void initializeItem(HistoryItem*); | 176 void initializeItem(HistoryItem*, Frame*); |
81 PassRefPtr<HistoryItem> createItem(); | 177 PassRefPtr<HistoryItem> createItem(Frame*); |
82 PassRefPtr<HistoryItem> createItemTree(Frame* targetFrame, bool clipAtTarget
); | 178 void createItemTree(Frame* targetFrame, bool clipAtTarget); |
83 | 179 |
84 void updateForStandardLoad(); | 180 void updateForStandardLoad(Frame*); |
85 void updateForInitialLoadInChildFrame(); | 181 void updateForInitialLoadInChildFrame(Frame*); |
86 | 182 |
87 void recursiveSetProvisionalItem(HistoryItem*, HistoryItem*); | 183 void createNewBackForwardItem(Frame*, bool doClip); |
88 void recursiveGoToItem(HistoryItem*, HistoryItem*); | 184 void updateWithoutCreatingNewBackForwardItem(Frame*); |
89 void recursiveUpdateForCommit(); | |
90 void recursiveUpdateForSameDocumentNavigation(); | |
91 bool itemsAreClones(HistoryItem*, HistoryItem*) const; | |
92 bool currentFramesMatchItem(HistoryItem*) const; | |
93 | 185 |
94 void createNewBackForwardItem(bool doClip); | 186 Page* m_page; |
95 void updateWithoutCreatingNewBackForwardItem(); | |
96 | 187 |
97 void clearProvisionalItemsInAllFrames(); | 188 OwnPtr<HistoryEntry> m_currentEntry; |
| 189 OwnPtr<HistoryEntry> m_previousEntry; |
| 190 OwnPtr<HistoryEntry> m_provisionalEntry; |
98 | 191 |
99 Frame* m_frame; | 192 typedef HashMap<Frame*, HistoryItem*> HistoryFrameLoadSet; |
100 | 193 HistoryFrameLoadSet m_sameDocumentLoadsInProgress; |
101 RefPtr<HistoryItem> m_currentItem; | 194 HistoryFrameLoadSet m_differentDocumentLoadsInProgress; |
102 RefPtr<HistoryItem> m_previousItem; | |
103 RefPtr<HistoryItem> m_provisionalItem; | |
104 | 195 |
105 bool m_defersLoading; | 196 bool m_defersLoading; |
106 RefPtr<HistoryItem> m_deferredItem; | 197 RefPtr<HistoryItem> m_deferredItem; |
107 }; | 198 }; |
108 | 199 |
109 } // namespace WebCore | 200 } // namespace WebCore |
110 | 201 |
111 #endif // HistoryController_h | 202 #endif // HistoryController_h |
OLD | NEW |