blob: b8567f2b0686b3fdb95fef599b8196169c5c6d63 [file] [log] [blame]
[email protected]43032342011-03-21 14:10:311// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]0dd3a0ab2011-02-18 08:17:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d202a7c2012-01-04 07:53:475#ifndef CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_IMPL_H_
6#define CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_IMPL_H_
[email protected]0dd3a0ab2011-02-18 08:17:447#pragma once
8
9#include "build/build_config.h"
[email protected]3c15fcbc2011-12-29 16:43:1710#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/linked_ptr.h"
[email protected]0dd3a0ab2011-02-18 08:17:4412#include "base/time.h"
[email protected]74b962a2011-06-03 21:22:5413#include "content/browser/ssl/ssl_manager.h"
[email protected]71fde352011-12-29 03:29:5614#include "content/public/browser/navigation_controller.h"
[email protected]e6e646d2011-12-01 00:50:1115#include "content/public/browser/navigation_type.h"
[email protected]0dd3a0ab2011-02-18 08:17:4416
[email protected]0dd3a0ab2011-02-18 08:17:4417class SiteInstance;
[email protected]fbc5e5f92012-01-02 06:08:3218class TabContents;
[email protected]0dd3a0ab2011-02-18 08:17:4419struct ViewHostMsg_FrameNavigate_Params;
20
[email protected]8286f51a2011-05-31 17:39:1321namespace content {
[email protected]10f417c52011-12-28 21:04:2322class NavigationEntryImpl;
[email protected]8286f51a2011-05-31 17:39:1323struct LoadCommittedDetails;
24}
25
[email protected]d202a7c2012-01-04 07:53:4726class CONTENT_EXPORT NavigationControllerImpl
[email protected]3c15fcbc2011-12-29 16:43:1727 : public NON_EXPORTED_BASE(content::NavigationController) {
[email protected]0dd3a0ab2011-02-18 08:17:4428 public:
[email protected]d202a7c2012-01-04 07:53:4729 NavigationControllerImpl(TabContents* tab_contents,
30 content::BrowserContext* browser_context,
31 SessionStorageNamespace* session_storage_namespace);
32 virtual ~NavigationControllerImpl();
[email protected]0dd3a0ab2011-02-18 08:17:4433
[email protected]71fde352011-12-29 03:29:5634 // NavigationController implementation:
[email protected]fbc5e5f92012-01-02 06:08:3235 virtual content::WebContents* GetWebContents() const OVERRIDE;
[email protected]71fde352011-12-29 03:29:5636 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
[email protected]cdcb1dee2012-01-04 00:46:2037 virtual void SetBrowserContext(
38 content::BrowserContext* browser_context) OVERRIDE;
[email protected]71fde352011-12-29 03:29:5639 virtual void Restore(
40 int selected_navigation,
41 bool from_last_session,
42 std::vector<content::NavigationEntry*>* entries) OVERRIDE;
43 virtual content::NavigationEntry* GetActiveEntry() const OVERRIDE;
44 virtual content::NavigationEntry* GetVisibleEntry() const OVERRIDE;
45 virtual int GetCurrentEntryIndex() const OVERRIDE;
46 virtual content::NavigationEntry* GetLastCommittedEntry() const OVERRIDE;
47 virtual int GetLastCommittedEntryIndex() const OVERRIDE;
48 virtual bool CanViewSource() const OVERRIDE;
49 virtual int GetEntryCount() const OVERRIDE;
50 virtual content::NavigationEntry* GetEntryAtIndex(int index) const OVERRIDE;
51 virtual content::NavigationEntry* GetEntryAtOffset(int offset) const OVERRIDE;
52 virtual void DiscardNonCommittedEntries() OVERRIDE;
53 virtual content::NavigationEntry* GetPendingEntry() const OVERRIDE;
54 virtual int GetPendingEntryIndex() const OVERRIDE;
55 virtual content::NavigationEntry* GetTransientEntry() const OVERRIDE;
56 virtual void LoadURL(const GURL& url,
57 const content::Referrer& referrer,
58 content::PageTransition type,
59 const std::string& extra_headers) OVERRIDE;
60 virtual void LoadURLFromRenderer(const GURL& url,
61 const content::Referrer& referrer,
62 content::PageTransition type,
63 const std::string& extra_headers) OVERRIDE;
64 virtual void TransferURL(
65 const GURL& url,
66 const content::Referrer& referrer,
67 content::PageTransition transition,
68 const std::string& extra_headers,
69 const content::GlobalRequestID& transferred_global_request_id,
70 bool is_renderer_initiated) OVERRIDE;
71 virtual void LoadIfNecessary() OVERRIDE;
72 virtual bool CanGoBack() const OVERRIDE;
73 virtual bool CanGoForward() const OVERRIDE;
74 virtual void GoBack() OVERRIDE;
75 virtual void GoForward() OVERRIDE;
76 virtual void GoToIndex(int index) OVERRIDE;
77 virtual void GoToOffset(int offset) OVERRIDE;
78 virtual void RemoveEntryAtIndex(int index) OVERRIDE;
79 virtual SSLManager* GetSSLManager() OVERRIDE;
80 virtual SessionStorageNamespace* GetSessionStorageNamespace() const OVERRIDE;
81 virtual void SetMaxRestoredPageID(int32 max_id) OVERRIDE;
82 virtual int32 GetMaxRestoredPageID() const OVERRIDE;
83 virtual bool NeedsReload() const OVERRIDE;
84 virtual void CancelPendingReload() OVERRIDE;
85 virtual void ContinuePendingReload() OVERRIDE;
86 virtual bool IsInitialNavigation() OVERRIDE;
87 virtual void Reload(bool check_for_repost) OVERRIDE;
88 virtual void ReloadIgnoringCache(bool check_for_repost) OVERRIDE;
89 virtual void NotifyEntryChanged(const content::NavigationEntry* entry,
90 int index) OVERRIDE;
[email protected]cdcb1dee2012-01-04 00:46:2091 virtual void CopyStateFrom(
92 const content::NavigationController& source) OVERRIDE;
[email protected]71fde352011-12-29 03:29:5693 virtual void CopyStateFromAndPrune(
94 content::NavigationController* source) OVERRIDE;
95 virtual void PruneAllButActive() OVERRIDE;
[email protected]0dd3a0ab2011-02-18 08:17:4496
[email protected]0dd3a0ab2011-02-18 08:17:4497 // Returns the index of the specified entry, or -1 if entry is not contained
98 // in this NavigationController.
[email protected]10f417c52011-12-28 21:04:2399 int GetIndexOfEntry(const content::NavigationEntryImpl* entry) const;
[email protected]0dd3a0ab2011-02-18 08:17:44100
101 // Return the index of the entry with the corresponding instance and page_id,
102 // or -1 if not found.
103 int GetEntryIndexWithPageID(SiteInstance* instance,
104 int32 page_id) const;
105
106 // Return the entry with the corresponding instance and page_id, or NULL if
107 // not found.
[email protected]10f417c52011-12-28 21:04:23108 content::NavigationEntryImpl* GetEntryWithPageID(SiteInstance* instance,
109 int32 page_id) const;
[email protected]0dd3a0ab2011-02-18 08:17:44110
[email protected]0dd3a0ab2011-02-18 08:17:44111 // Transient entry -----------------------------------------------------------
112
113 // Adds an entry that is returned by GetActiveEntry(). The entry is
114 // transient: any navigation causes it to be removed and discarded.
115 // The NavigationController becomes the owner of |entry| and deletes it when
116 // it discards it. This is useful with interstitial page that need to be
117 // represented as an entry, but should go away when the user navigates away
118 // from them.
119 // Note that adding a transient entry does not change the active contents.
[email protected]10f417c52011-12-28 21:04:23120 void AddTransientEntry(content::NavigationEntryImpl* entry);
[email protected]0dd3a0ab2011-02-18 08:17:44121
[email protected]0dd3a0ab2011-02-18 08:17:44122 // TabContents ---------------------------------------------------------------
123
[email protected]0dd3a0ab2011-02-18 08:17:44124 TabContents* tab_contents() const {
125 // This currently returns the active tab contents which should be renamed to
126 // tab_contents.
127 return tab_contents_;
128 }
129
130 // Called when a document has been loaded in a frame.
131 void DocumentLoadedInFrame();
132
133 // For use by TabContents ----------------------------------------------------
134
135 // Handles updating the navigation state after the renderer has navigated.
[email protected]9a7e68c2011-05-26 17:35:50136 // This is used by the TabContents.
[email protected]0dd3a0ab2011-02-18 08:17:44137 //
138 // If a new entry is created, it will return true and will have filled the
139 // given details structure and broadcast the NOTIFY_NAV_ENTRY_COMMITTED
140 // notification. The caller can then use the details without worrying about
141 // listening for the notification.
142 //
143 // In the case that nothing has changed, the details structure is undefined
144 // and it will return false.
[email protected]0dd3a0ab2011-02-18 08:17:44145 bool RendererDidNavigate(const ViewHostMsg_FrameNavigate_Params& params,
[email protected]8286f51a2011-05-31 17:39:13146 content::LoadCommittedDetails* details);
[email protected]0dd3a0ab2011-02-18 08:17:44147
148 // Notifies us that we just became active. This is used by the TabContents
149 // so that we know to load URLs that were pending as "lazy" loads.
150 void SetActive(bool is_active);
151
[email protected]0dd3a0ab2011-02-18 08:17:44152 // Returns true if the given URL would be an in-page navigation (i.e. only
153 // the reference fragment is different) from the "last committed entry". We do
154 // not compare it against the "active entry" since the active entry can be
155 // pending and in page navigations only happen on committed pages. If there
156 // is no last committed entry, then nothing will be in-page.
157 //
158 // Special note: if the URLs are the same, it does NOT count as an in-page
159 // navigation. Neither does an input URL that has no ref, even if the rest is
160 // the same. This may seem weird, but when we're considering whether a
161 // navigation happened without loading anything, the same URL would be a
162 // reload, while only a different ref would be in-page (pages can't clear
163 // refs without reload, only change to "#" which we don't count as empty).
164 bool IsURLInPageNavigation(const GURL& url) const;
165
[email protected]0dd3a0ab2011-02-18 08:17:44166 // Random data ---------------------------------------------------------------
167
[email protected]0dd3a0ab2011-02-18 08:17:44168 // Maximum number of entries before we start removing entries from the front.
[email protected]f3112a52011-09-30 23:47:49169 static void set_max_entry_count_for_testing(size_t max_entry_count) {
[email protected]9b51970d2011-12-09 23:10:23170 max_entry_count_for_testing_ = max_entry_count;
[email protected]0dd3a0ab2011-02-18 08:17:44171 }
[email protected]9b51970d2011-12-09 23:10:23172 static size_t max_entry_count();
[email protected]0dd3a0ab2011-02-18 08:17:44173
[email protected]0dd3a0ab2011-02-18 08:17:44174 private:
175 class RestoreHelper;
176 friend class RestoreHelper;
177 friend class TabContents; // For invoking OnReservedPageIDRange.
178
179 // Classifies the given renderer navigation (see the NavigationType enum).
[email protected]610cbb82011-10-18 16:35:08180 content::NavigationType ClassifyNavigation(
[email protected]0dd3a0ab2011-02-18 08:17:44181 const ViewHostMsg_FrameNavigate_Params& params) const;
182
183 // Causes the controller to load the specified entry. The function assumes
184 // ownership of the pointer since it is put in the navigation list.
185 // NOTE: Do not pass an entry that the controller already owns!
[email protected]10f417c52011-12-28 21:04:23186 void LoadEntry(content::NavigationEntryImpl* entry);
[email protected]0dd3a0ab2011-02-18 08:17:44187
188 // Handlers for the different types of navigation types. They will actually
189 // handle the navigations corresponding to the different NavClasses above.
190 // They will NOT broadcast the commit notification, that should be handled by
191 // the caller.
192 //
193 // RendererDidNavigateAutoSubframe is special, it may not actually change
194 // anything if some random subframe is loaded. It will return true if anything
195 // changed, or false if not.
196 //
197 // The functions taking |did_replace_entry| will fill into the given variable
198 // whether the last entry has been replaced or not.
199 // See LoadCommittedDetails.did_replace_entry.
200 void RendererDidNavigateToNewPage(
201 const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry);
202 void RendererDidNavigateToExistingPage(
203 const ViewHostMsg_FrameNavigate_Params& params);
204 void RendererDidNavigateToSamePage(
205 const ViewHostMsg_FrameNavigate_Params& params);
206 void RendererDidNavigateInPage(
207 const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry);
208 void RendererDidNavigateNewSubframe(
209 const ViewHostMsg_FrameNavigate_Params& params);
210 bool RendererDidNavigateAutoSubframe(
211 const ViewHostMsg_FrameNavigate_Params& params);
212
213 // Helper function for code shared between Reload() and ReloadIgnoringCache().
214 void ReloadInternal(bool check_for_repost, ReloadType reload_type);
215
216 // Actually issues the navigation held in pending_entry.
217 void NavigateToPendingEntry(ReloadType reload_type);
218
219 // Allows the derived class to issue notifications that a load has been
220 // committed. This will fill in the active entry to the details structure.
[email protected]93f230e02011-06-01 14:40:00221 void NotifyNavigationEntryCommitted(content::LoadCommittedDetails* details);
[email protected]0dd3a0ab2011-02-18 08:17:44222
223 // Updates the virtual URL of an entry to match a new URL, for cases where
224 // the real renderer URL is derived from the virtual URL, like view-source:
[email protected]10f417c52011-12-28 21:04:23225 void UpdateVirtualURLToURL(content::NavigationEntryImpl* entry,
226 const GURL& new_url);
[email protected]0dd3a0ab2011-02-18 08:17:44227
228 // Invoked after session/tab restore or cloning a tab. Resets the transition
229 // type of the entries, updates the max page id and creates the active
230 // contents. See RestoreFromState for a description of from_last_session.
231 void FinishRestore(int selected_index, bool from_last_session);
232
233 // Inserts a new entry or replaces the current entry with a new one, removing
234 // all entries after it. The new entry will become the active one.
[email protected]10f417c52011-12-28 21:04:23235 void InsertOrReplaceEntry(content::NavigationEntryImpl* entry, bool replace);
[email protected]0dd3a0ab2011-02-18 08:17:44236
[email protected]6a13a6c2011-12-20 21:47:12237 // Removes the entry at |index|, as long as it is not the current entry.
[email protected]43032342011-03-21 14:10:31238 void RemoveEntryAtIndexInternal(int index);
239
[email protected]0dd3a0ab2011-02-18 08:17:44240 // Discards the pending and transient entries.
241 void DiscardNonCommittedEntriesInternal();
242
243 // Discards the transient entry.
244 void DiscardTransientEntry();
245
246 // Returns true if the navigation is redirect.
247 bool IsRedirect(const ViewHostMsg_FrameNavigate_Params& params);
248
249 // Returns true if the navigation is likley to be automatic rather than
250 // user-initiated.
251 bool IsLikelyAutoNavigation(base::TimeTicks now);
252
[email protected]0dd3a0ab2011-02-18 08:17:44253 // Inserts up to |max_index| entries from |source| into this. This does NOT
254 // adjust any of the members that reference entries_
255 // (last_committed_entry_index_, pending_entry_index_ or
256 // transient_entry_index_).
[email protected]d202a7c2012-01-04 07:53:47257 void InsertEntriesFrom(const NavigationControllerImpl& source, int max_index);
[email protected]0dd3a0ab2011-02-18 08:17:44258
259 // ---------------------------------------------------------------------------
260
[email protected]3d7474ff2011-07-27 17:47:37261 // The user browser context associated with this controller.
262 content::BrowserContext* browser_context_;
[email protected]0dd3a0ab2011-02-18 08:17:44263
264 // List of NavigationEntry for this tab
[email protected]10f417c52011-12-28 21:04:23265 typedef std::vector<linked_ptr<content::NavigationEntryImpl> >
266 NavigationEntries;
[email protected]0dd3a0ab2011-02-18 08:17:44267 NavigationEntries entries_;
268
269 // An entry we haven't gotten a response for yet. This will be discarded
270 // when we navigate again. It's used only so we know what the currently
271 // displayed tab is.
272 //
273 // This may refer to an item in the entries_ list if the pending_entry_index_
274 // == -1, or it may be its own entry that should be deleted. Be careful with
275 // the memory management.
[email protected]10f417c52011-12-28 21:04:23276 content::NavigationEntryImpl* pending_entry_;
[email protected]0dd3a0ab2011-02-18 08:17:44277
278 // currently visible entry
279 int last_committed_entry_index_;
280
281 // index of pending entry if it is in entries_, or -1 if pending_entry_ is a
282 // new entry (created by LoadURL).
283 int pending_entry_index_;
284
285 // The index for the entry that is shown until a navigation occurs. This is
286 // used for interstitial pages. -1 if there are no such entry.
287 // Note that this entry really appears in the list of entries, but only
288 // temporarily (until the next navigation). Any index pointing to an entry
289 // after the transient entry will become invalid if you navigate forward.
290 int transient_entry_index_;
291
292 // The tab contents associated with the controller. Possibly NULL during
293 // setup.
294 TabContents* tab_contents_;
295
296 // The max restored page ID in this controller, if it was restored. We must
297 // store this so that TabContents can tell any renderer in charge of one of
298 // the restored entries to update its max page ID.
299 int32 max_restored_page_id_;
300
301 // Manages the SSL security UI
302 SSLManager ssl_manager_;
303
304 // Whether we need to be reloaded when made active.
305 bool needs_reload_;
306
[email protected]0dd3a0ab2011-02-18 08:17:44307 // The time ticks at which the last document was loaded.
308 base::TimeTicks last_document_loaded_;
309
310 // The session storage id that any (indirectly) owned RenderView should use.
311 scoped_refptr<SessionStorageNamespace> session_storage_namespace_;
312
[email protected]0dd3a0ab2011-02-18 08:17:44313 // The maximum number of entries that a navigation controller can store.
[email protected]9b51970d2011-12-09 23:10:23314 static size_t max_entry_count_for_testing_;
[email protected]0dd3a0ab2011-02-18 08:17:44315
316 // If a repost is pending, its type (RELOAD or RELOAD_IGNORING_CACHE),
317 // NO_RELOAD otherwise.
318 ReloadType pending_reload_;
319
[email protected]d202a7c2012-01-04 07:53:47320 DISALLOW_COPY_AND_ASSIGN(NavigationControllerImpl);
[email protected]0dd3a0ab2011-02-18 08:17:44321};
322
[email protected]d202a7c2012-01-04 07:53:47323#endif // CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_IMPL_H_