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.
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/)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
35 #ifndef CONTENT_RENDERER_HISTORY_CONTROLLER_H_
36 #define CONTENT_RENDERER_HISTORY_CONTROLLER_H_
38 #include "base/containers/hash_tables.h"
39 #include "base/memory/scoped_ptr.h"
40 #include "base/memory/scoped_vector.h"
41 #include "content/common/content_export.h"
42 #include "content/renderer/history_entry.h"
43 #include "third_party/WebKit/public/platform/WebURLRequest.h"
44 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
45 #include "third_party/WebKit/public/web/WebHistoryItem.h"
52 class RenderFrameImpl
;
54 struct NavigationParams
;
56 // A guide to history state in the renderer:
58 // HistoryController: Owned by RenderView, is the entry point for interacting
59 // with history. Handles most of the operations to modify history state,
60 // navigate to an existing back/forward entry, etc.
62 // HistoryEntry: Represents a single entry in the back/forward list,
63 // encapsulating all frames in the page it represents. It provides access
64 // to each frame's state via lookups by frame id or frame name.
65 // HistoryNode: Represents a single frame in a HistoryEntry. Owned by a
66 // HistoryEntry. HistoryNodes form a tree that mirrors the frame tree in
67 // the corresponding page.
68 // HistoryNodes represent the structure of the page, but don't hold any
69 // per-frame state except a list of child frames.
70 // WebHistoryItem (lives in blink): The state for a given frame. Can persist
71 // across navigations. WebHistoryItem is reference counted, and each
72 // HistoryNode holds a reference to its single corresponding
73 // WebHistoryItem. Can be referenced by multiple HistoryNodes and can
74 // therefore exist in multiple HistoryEntry instances.
76 // Suppose we have the following page, foo.com, which embeds foo.com/a in an
80 // HistoryNode 0_0 (WebHistoryItem A (url: foo.com))
81 // HistoryNode 0_1: (WebHistoryItem B (url: foo.com/a))
83 // Now we navigate the top frame to bar.com, which embeds bar.com/b and
84 // bar.com/c in iframes, and bar.com/b in turn embeds bar.com/d. We will
85 // create a new HistoryEntry with a tree containing 4 new HistoryNodes. The
89 // HistoryNode 1_0 (WebHistoryItem C (url: bar.com))
90 // HistoryNode 1_1: (WebHistoryItem D (url: bar.com/b))
91 // HistoryNode 1_3: (WebHistoryItem F (url: bar.com/d))
92 // HistoryNode 1_2: (WebHistoryItem E (url: bar.com/c))
95 // Finally, we navigate the first subframe from bar.com/b to bar.com/e, which
96 // embeds bar.com/f. We will create a new HistoryEntry and new HistoryNode for
97 // each frame. Any frame that navigates (bar.com/e and its child, bar.com/f)
98 // will receive a new WebHistoryItem. However, 2 frames were not navigated
99 // (bar.com and bar.com/c), so those two frames will reuse the existing
103 // HistoryNode 2_0 (WebHistoryItem C (url: bar.com)) *REUSED*
104 // HistoryNode 2_1: (WebHistoryItem G (url: bar.com/e))
105 // HistoryNode 2_3: (WebHistoryItem H (url: bar.com/f))
106 // HistoryNode 2_2: (WebHistoryItem E (url: bar.com/c)) *REUSED*
108 class CONTENT_EXPORT HistoryController
{
110 explicit HistoryController(RenderViewImpl
* render_view
);
111 ~HistoryController();
113 void GoToEntry(scoped_ptr
<HistoryEntry
> entry
,
114 scoped_ptr
<NavigationParams
> navigation_params
,
115 blink::WebURLRequest::CachePolicy cache_policy
);
117 void UpdateForCommit(RenderFrameImpl
* frame
,
118 const blink::WebHistoryItem
& item
,
119 blink::WebHistoryCommitType commit_type
,
120 bool navigation_within_page
);
122 HistoryEntry
* GetCurrentEntry();
123 blink::WebHistoryItem
GetItemForNewChildFrame(RenderFrameImpl
* frame
) const;
124 void RemoveChildrenForRedirect(RenderFrameImpl
* frame
);
127 typedef std::vector
<std::pair
<blink::WebFrame
*, blink::WebHistoryItem
> >
128 HistoryFrameLoadVector
;
129 void RecursiveGoToEntry(blink::WebFrame
* frame
,
130 HistoryFrameLoadVector
& sameDocumentLoads
,
131 HistoryFrameLoadVector
& differentDocumentLoads
);
133 void UpdateForInitialLoadInChildFrame(RenderFrameImpl
* frame
,
134 const blink::WebHistoryItem
& item
);
135 void CreateNewBackForwardItem(RenderFrameImpl
* frame
,
136 const blink::WebHistoryItem
& item
,
137 bool clone_children_of_target
);
139 RenderViewImpl
* render_view_
;
141 // A HistoryEntry representing the currently-loaded page.
142 scoped_ptr
<HistoryEntry
> current_entry_
;
143 // A HistoryEntry representing the page that is being loaded, or an empty
144 // scoped_ptr if no page is being loaded.
145 scoped_ptr
<HistoryEntry
> provisional_entry_
;
146 // The NavigationParams corresponding to the last load that was initiated by
147 // |GoToEntry|. This is kept around so that it can be passed into existing
148 // frames modified during a history navigation in GoToEntry(), and can be
149 // passed into frames created after the commit that resulted from the
150 // navigation in GetItemForNewChildFrame().
151 scoped_ptr
<NavigationParams
> navigation_params_
;
153 DISALLOW_COPY_AND_ASSIGN(HistoryController
);
156 } // namespace content
158 #endif // CONTENT_RENDERER_HISTORY_CONTROLLER_H_