Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / renderer / history_controller.h
blob4f90fc04e2e6007a26e12264c22ffa256291bb7b
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.
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/)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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"
47 namespace blink {
48 class WebFrame;
49 class WebLocalFrame;
52 namespace content {
53 class RenderFrameImpl;
54 class RenderViewImpl;
55 struct NavigationParams;
57 // A guide to history state in the renderer:
59 // HistoryController: Owned by RenderView, is the entry point for interacting
60 // with history. Handles most of the operations to modify history state,
61 // navigate to an existing back/forward entry, etc.
63 // HistoryEntry: Represents a single entry in the back/forward list,
64 // encapsulating all frames in the page it represents. It provides access
65 // to each frame's state via lookups by frame id or frame name.
66 // HistoryNode: Represents a single frame in a HistoryEntry. Owned by a
67 // HistoryEntry. HistoryNodes form a tree that mirrors the frame tree in
68 // the corresponding page.
69 // HistoryNodes represent the structure of the page, but don't hold any
70 // per-frame state except a list of child frames.
71 // WebHistoryItem (lives in blink): The state for a given frame. Can persist
72 // across navigations. WebHistoryItem is reference counted, and each
73 // HistoryNode holds a reference to its single corresponding
74 // WebHistoryItem. Can be referenced by multiple HistoryNodes and can
75 // therefore exist in multiple HistoryEntry instances.
77 // Suppose we have the following page, foo.com, which embeds foo.com/a in an
78 // iframe:
80 // HistoryEntry 0:
81 // HistoryNode 0_0 (WebHistoryItem A (url: foo.com))
82 // HistoryNode 0_1: (WebHistoryItem B (url: foo.com/a))
84 // Now we navigate the top frame to bar.com, which embeds bar.com/b and
85 // bar.com/c in iframes, and bar.com/b in turn embeds bar.com/d. We will
86 // create a new HistoryEntry with a tree containing 4 new HistoryNodes. The
87 // state will be:
89 // HistoryEntry 1:
90 // HistoryNode 1_0 (WebHistoryItem C (url: bar.com))
91 // HistoryNode 1_1: (WebHistoryItem D (url: bar.com/b))
92 // HistoryNode 1_3: (WebHistoryItem F (url: bar.com/d))
93 // HistoryNode 1_2: (WebHistoryItem E (url: bar.com/c))
96 // Finally, we navigate the first subframe from bar.com/b to bar.com/e, which
97 // embeds bar.com/f. We will create a new HistoryEntry and new HistoryNode for
98 // each frame. Any frame that navigates (bar.com/e and its child, bar.com/f)
99 // will receive a new WebHistoryItem. However, 2 frames were not navigated
100 // (bar.com and bar.com/c), so those two frames will reuse the existing
101 // WebHistoryItem:
103 // HistoryEntry 2:
104 // HistoryNode 2_0 (WebHistoryItem C (url: bar.com)) *REUSED*
105 // HistoryNode 2_1: (WebHistoryItem G (url: bar.com/e))
106 // HistoryNode 2_3: (WebHistoryItem H (url: bar.com/f))
107 // HistoryNode 2_2: (WebHistoryItem E (url: bar.com/c)) *REUSED*
109 class CONTENT_EXPORT HistoryController {
110 public:
111 explicit HistoryController(RenderViewImpl* render_view);
112 ~HistoryController();
114 void set_provisional_entry(scoped_ptr<HistoryEntry> entry) {
115 provisional_entry_ = entry.Pass();
118 void GoToEntry(blink::WebLocalFrame* main_frame,
119 scoped_ptr<HistoryEntry> entry,
120 scoped_ptr<NavigationParams> navigation_params,
121 blink::WebURLRequest::CachePolicy cache_policy);
123 void UpdateForCommit(RenderFrameImpl* frame,
124 const blink::WebHistoryItem& item,
125 blink::WebHistoryCommitType commit_type,
126 bool navigation_within_page);
128 HistoryEntry* GetCurrentEntry();
129 blink::WebHistoryItem GetItemForNewChildFrame(RenderFrameImpl* frame) const;
130 void RemoveChildrenForRedirect(RenderFrameImpl* frame);
132 private:
133 typedef std::vector<std::pair<blink::WebFrame*, blink::WebHistoryItem> >
134 HistoryFrameLoadVector;
135 void RecursiveGoToEntry(blink::WebFrame* frame,
136 HistoryFrameLoadVector& sameDocumentLoads,
137 HistoryFrameLoadVector& differentDocumentLoads);
139 void UpdateForInitialLoadInChildFrame(RenderFrameImpl* frame,
140 const blink::WebHistoryItem& item);
141 void CreateNewBackForwardItem(RenderFrameImpl* frame,
142 const blink::WebHistoryItem& item,
143 bool clone_children_of_target);
145 RenderViewImpl* render_view_;
147 // A HistoryEntry representing the currently-loaded page.
148 scoped_ptr<HistoryEntry> current_entry_;
149 // A HistoryEntry representing the page that is being loaded, or an empty
150 // scoped_ptr if no page is being loaded.
151 scoped_ptr<HistoryEntry> provisional_entry_;
152 // The NavigationParams corresponding to the last load that was initiated by
153 // |GoToEntry|. This is kept around so that it can be passed into existing
154 // frames modified during a history navigation in GoToEntry(), and can be
155 // passed into frames created after the commit that resulted from the
156 // navigation in GetItemForNewChildFrame().
157 scoped_ptr<NavigationParams> navigation_params_;
159 DISALLOW_COPY_AND_ASSIGN(HistoryController);
162 } // namespace content
164 #endif // CONTENT_RENDERER_HISTORY_CONTROLLER_H_