OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /* | |
6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | |
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | |
8 * (http://www.torchmobile.com/) | |
9 * | |
10 * Redistribution and use in source and binary forms, with or without | |
11 * modification, are permitted provided that the following conditions | |
12 * are met: | |
13 * | |
14 * 1. Redistributions of source code must retain the above copyright | |
15 * notice, this list of conditions and the following disclaimer. | |
16 * 2. Redistributions in binary form must reproduce the above copyright | |
17 * notice, this list of conditions and the following disclaimer in the | |
18 * documentation and/or other materials provided with the distribution. | |
19 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
20 * its contributors may be used to endorse or promote products derived | |
21 * from this software without specific prior written permission. | |
22 * | |
23 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
26 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
33 */ | |
34 | |
35 #ifndef CONTENT_RENDERER_HISTORY_CONTROLLER_H_ | |
36 #define CONTENT_RENDERER_HISTORY_CONTROLLER_H_ | |
37 | |
38 #include <memory> | |
39 #include <utility> | |
40 | |
41 #include "base/containers/hash_tables.h" | |
42 #include "base/macros.h" | |
43 #include "content/common/content_export.h" | |
44 #include "content/renderer/history_entry.h" | |
45 #include "third_party/WebKit/public/web/WebHistoryCommitType.h" | |
46 #include "third_party/WebKit/public/web/WebHistoryItem.h" | |
47 | |
48 namespace blink { | |
49 class WebFrame; | |
50 class WebLocalFrame; | |
51 enum class WebCachePolicy; | |
52 } | |
53 | |
54 namespace content { | |
55 class RenderFrameImpl; | |
56 class RenderViewImpl; | |
57 struct NavigationParams; | |
58 | |
59 // A guide to history state in the renderer: | |
60 // | |
61 // HistoryController: Owned by RenderView, is the entry point for interacting | |
62 // with history. Handles most of the operations to modify history state, | |
63 // navigate to an existing back/forward entry, etc. | |
64 // | |
65 // HistoryEntry: Represents a single entry in the back/forward list, | |
66 // encapsulating all frames in the page it represents. It provides access | |
67 // to each frame's state via lookups by frame id or frame name. | |
68 // HistoryNode: Represents a single frame in a HistoryEntry. Owned by a | |
69 // HistoryEntry. HistoryNodes form a tree that mirrors the frame tree in | |
70 // the corresponding page. | |
71 // HistoryNodes represent the structure of the page, but don't hold any | |
72 // per-frame state except a list of child frames. | |
73 // WebHistoryItem (lives in blink): The state for a given frame. Can persist | |
74 // across navigations. WebHistoryItem is reference counted, and each | |
75 // HistoryNode holds a reference to its single corresponding | |
76 // WebHistoryItem. Can be referenced by multiple HistoryNodes and can | |
77 // therefore exist in multiple HistoryEntry instances. | |
78 // | |
79 // Suppose we have the following page, foo.com, which embeds foo.com/a in an | |
80 // iframe: | |
81 // | |
82 // HistoryEntry 0: | |
83 // HistoryNode 0_0 (WebHistoryItem A (url: foo.com)) | |
84 // HistoryNode 0_1: (WebHistoryItem B (url: foo.com/a)) | |
85 // | |
86 // Now we navigate the top frame to bar.com, which embeds bar.com/b and | |
87 // bar.com/c in iframes, and bar.com/b in turn embeds bar.com/d. We will | |
88 // create a new HistoryEntry with a tree containing 4 new HistoryNodes. The | |
89 // state will be: | |
90 // | |
91 // HistoryEntry 1: | |
92 // HistoryNode 1_0 (WebHistoryItem C (url: bar.com)) | |
93 // HistoryNode 1_1: (WebHistoryItem D (url: bar.com/b)) | |
94 // HistoryNode 1_3: (WebHistoryItem F (url: bar.com/d)) | |
95 // HistoryNode 1_2: (WebHistoryItem E (url: bar.com/c)) | |
96 // | |
97 // | |
98 // Finally, we navigate the first subframe from bar.com/b to bar.com/e, which | |
99 // embeds bar.com/f. We will create a new HistoryEntry and new HistoryNode for | |
100 // each frame. Any frame that navigates (bar.com/e and its child, bar.com/f) | |
101 // will receive a new WebHistoryItem. However, 2 frames were not navigated | |
102 // (bar.com and bar.com/c), so those two frames will reuse the existing | |
103 // WebHistoryItem: | |
104 // | |
105 // HistoryEntry 2: | |
106 // HistoryNode 2_0 (WebHistoryItem C (url: bar.com)) *REUSED* | |
107 // HistoryNode 2_1: (WebHistoryItem G (url: bar.com/e)) | |
108 // HistoryNode 2_3: (WebHistoryItem H (url: bar.com/f)) | |
109 // HistoryNode 2_2: (WebHistoryItem E (url: bar.com/c)) *REUSED* | |
110 // | |
111 class CONTENT_EXPORT HistoryController { | |
112 public: | |
113 explicit HistoryController(RenderViewImpl* render_view); | |
114 ~HistoryController(); | |
115 | |
116 void set_provisional_entry(std::unique_ptr<HistoryEntry> entry) { | |
117 provisional_entry_ = std::move(entry); | |
118 } | |
119 | |
120 // Return true if the main frame ended up loading a request as part of the | |
121 // history navigation. | |
122 bool GoToEntry(blink::WebLocalFrame* main_frame, | |
123 std::unique_ptr<HistoryEntry> entry, | |
124 std::unique_ptr<NavigationParams> navigation_params, | |
125 blink::WebCachePolicy cache_policy); | |
126 | |
127 void UpdateForCommit(RenderFrameImpl* frame, | |
128 const blink::WebHistoryItem& item, | |
129 blink::WebHistoryCommitType commit_type, | |
130 bool navigation_within_page); | |
131 | |
132 HistoryEntry* GetCurrentEntry(); | |
133 blink::WebHistoryItem GetItemForNewChildFrame(RenderFrameImpl* frame) const; | |
134 void RemoveChildrenForRedirect(RenderFrameImpl* frame); | |
135 | |
136 private: | |
137 typedef std::vector<std::pair<blink::WebFrame*, blink::WebHistoryItem> > | |
138 HistoryFrameLoadVector; | |
139 void RecursiveGoToEntry(blink::WebFrame* frame, | |
140 HistoryFrameLoadVector& sameDocumentLoads, | |
141 HistoryFrameLoadVector& differentDocumentLoads); | |
142 | |
143 void UpdateForInitialLoadInChildFrame(RenderFrameImpl* frame, | |
144 const blink::WebHistoryItem& item); | |
145 void CreateNewBackForwardItem(RenderFrameImpl* frame, | |
146 const blink::WebHistoryItem& item, | |
147 bool clone_children_of_target); | |
148 | |
149 RenderViewImpl* render_view_; | |
150 | |
151 // A HistoryEntry representing the currently-loaded page. | |
152 std::unique_ptr<HistoryEntry> current_entry_; | |
153 // A HistoryEntry representing the page that is being loaded, or an empty | |
154 // scoped_ptr if no page is being loaded. | |
155 std::unique_ptr<HistoryEntry> provisional_entry_; | |
156 | |
157 // The NavigationParams corresponding to the last back/forward load that was | |
158 // initiated by |GoToEntry|. This is kept around so that it can be passed into | |
159 // existing frames affected by a history navigation in GoToEntry(), and can be | |
160 // passed into frames created after the commit that resulted from the | |
161 // navigation in GetItemForNewChildFrame(). | |
162 // | |
163 // This is reset in UpdateForCommit if we see a commit from a different | |
164 // navigation, to avoid using stale parameters. | |
165 std::unique_ptr<NavigationParams> navigation_params_; | |
166 | |
167 DISALLOW_COPY_AND_ASSIGN(HistoryController); | |
168 }; | |
169 | |
170 } // namespace content | |
171 | |
172 #endif // CONTENT_RENDERER_HISTORY_CONTROLLER_H_ | |
OLD | NEW |