Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/browser/navigation_controller.h

Issue 479: DidNavigate refactor of doom (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NAVIGATION_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_NAVIGATION_CONTROLLER_H_
6 #define CHROME_BROWSER_NAVIGATION_CONTROLLER_H_ 6 #define CHROME_BROWSER_NAVIGATION_CONTROLLER_H_
7 7
8 #include <hash_map> 8 #include <map>
9 9
10 #include "base/linked_ptr.h" 10 #include "base/linked_ptr.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "chrome/browser/alternate_nav_url_fetcher.h" 12 #include "chrome/browser/alternate_nav_url_fetcher.h"
13 #include "chrome/browser/session_service.h" 13 #include "chrome/browser/session_service.h"
14 #include "chrome/browser/site_instance.h" 14 #include "chrome/browser/site_instance.h"
15 #include "chrome/browser/ssl_manager.h" 15 #include "chrome/browser/ssl_manager.h"
16 #include "chrome/browser/tab_contents_type.h" 16 #include "chrome/browser/tab_contents_type.h"
17 17
18 class GURL; 18 class GURL;
19 class Profile; 19 class Profile;
20 class TabContents; 20 class TabContents;
21 class WebContents; 21 class WebContents;
22 class TabContentsCollector; 22 class TabContentsCollector;
23 struct TabNavigation; 23 struct TabNavigation;
24 struct ViewHostMsg_FrameNavigate_Params;
24 25
25 namespace printing { 26 // A NavigationController maintains the back-forward list for a single tab and
26 class PrintViewManager; 27 // manages all navigation within that list.
27 }
28
29 ////////////////////////////////////////////////////////////////////////////////
30 //
31 // NavigationController class
32 //
33 // A NavigationController maintains navigation data. We have one
34 // NavigationController instance per tab.
35 // 28 //
36 // The NavigationController also owns all TabContents for the tab. This is to 29 // The NavigationController also owns all TabContents for the tab. This is to
37 // make sure that we have at most one TabContents instance per type. 30 // make sure that we have at most one TabContents instance per type.
38 //
39 ////////////////////////////////////////////////////////////////////////////////
40 class NavigationController { 31 class NavigationController {
41 public: 32 public:
33 // Notification details ------------------------------------------------------
34
42 // Provides the details for a NOTIFY_NAV_ENTRY_CHANGED notification. 35 // Provides the details for a NOTIFY_NAV_ENTRY_CHANGED notification.
43 struct EntryChangedDetails { 36 struct EntryChangedDetails {
44 // The changed navigation entry after it has been updated. 37 // The changed navigation entry after it has been updated.
45 const NavigationEntry* changed_entry; 38 const NavigationEntry* changed_entry;
46 39
47 // Indicates the current index in the back/forward list of the entry. 40 // Indicates the current index in the back/forward list of the entry.
48 int index; 41 int index;
49 }; 42 };
50 43
44 // Provides the details for a NOTIFY_NAV_ENTRY_COMMITTED notification.
51 struct LoadCommittedDetails { 45 struct LoadCommittedDetails {
52 // By default, the entry will be filled according to a new main frame 46 // By default, the entry will be filled according to a new main frame
53 // navigation. 47 // navigation.
54 LoadCommittedDetails() 48 LoadCommittedDetails()
55 : entry(NULL), 49 : entry(NULL),
56 is_auto(false), 50 is_auto(false),
57 is_in_page(false), 51 is_in_page(false),
58 is_main_frame(true) { 52 is_main_frame(true) {
59 } 53 }
60 54
(...skipping 20 matching lines...) Expand all
81 75
82 // Returns whether the user probably felt like they navigated somewhere new. 76 // Returns whether the user probably felt like they navigated somewhere new.
83 // We often need this logic for showing or hiding something, and this 77 // We often need this logic for showing or hiding something, and this
84 // returns true only for main frame loads that the user initiated, that go 78 // returns true only for main frame loads that the user initiated, that go
85 // to a new page. 79 // to a new page.
86 bool is_user_initiated_main_frame_load() const { 80 bool is_user_initiated_main_frame_load() const {
87 return !is_auto && !is_in_page && is_main_frame; 81 return !is_auto && !is_in_page && is_main_frame;
88 } 82 }
89 }; 83 };
90 84
85 // ---------------------------------------------------------------------------
86
91 NavigationController(TabContents* initial_contents, Profile* profile); 87 NavigationController(TabContents* initial_contents, Profile* profile);
88
92 // Creates a NavigationController from the specified history. Processing 89 // Creates a NavigationController from the specified history. Processing
93 // for this is asynchronous and handled via the RestoreHelper (in 90 // for this is asynchronous and handled via the RestoreHelper (in
94 // navigation_controller.cc). 91 // navigation_controller.cc).
95 NavigationController( 92 NavigationController(
96 Profile* profile, 93 Profile* profile,
97 const std::vector<TabNavigation>& navigations, 94 const std::vector<TabNavigation>& navigations,
98 int selected_navigation, 95 int selected_navigation,
99 HWND parent); 96 HWND parent);
100 ~NavigationController(); 97 ~NavigationController();
101 98
102 // Same as Reload, but doesn't check if current entry has POST data. 99 // Begin the destruction sequence for this NavigationController and all its
103 void ReloadDontCheckForRepost(); 100 // registered tabs. The sequence is as follows:
101 // 1. All tabs are asked to Destroy themselves.
102 // 2. When each tab is finished Destroying, it will notify the controller.
103 // 3. Once all tabs are Destroyed, the NavigationController deletes itself.
104 // This ensures that all the TabContents outlive the NavigationController.
105 void Destroy();
106
107 // Clone the receiving navigation controller. Only the active tab contents is
108 // duplicated. It is created as a child of the provided HWND.
109 NavigationController* Clone(HWND hwnd);
110
111 // Returns the profile for this controller. It can never be NULL.
112 Profile* profile() const {
113 return profile_;
114 }
115
116 // Active entry --------------------------------------------------------------
104 117
105 // Returns the active entry, which is the pending entry if a navigation is in 118 // Returns the active entry, which is the pending entry if a navigation is in
106 // progress or the last committed entry otherwise. NOTE: This can be NULL!! 119 // progress or the last committed entry otherwise. NOTE: This can be NULL!!
107 // 120 //
108 // If you are trying to get the current state of the NavigationControllerBase, 121 // If you are trying to get the current state of the NavigationControllerBase,
109 // this is the method you will typically want to call. 122 // this is the method you will typically want to call.
110 // 123 //
111 NavigationEntry* GetActiveEntry() const; 124 NavigationEntry* GetActiveEntry() const;
112 125
113 // Returns the index from which we would go back/forward or reload. This is 126 // Returns the index from which we would go back/forward or reload. This is
114 // the last_committed_entry_index_ if pending_entry_index_ is -1. Otherwise, 127 // the last_committed_entry_index_ if pending_entry_index_ is -1. Otherwise,
115 // it is the pending_entry_index_. 128 // it is the pending_entry_index_.
116 int GetCurrentEntryIndex() const; 129 int GetCurrentEntryIndex() const;
117 130
118 // Returns the pending entry corresponding to the navigation that is 131 // Returns the last committed entry, which may be null if there are no
119 // currently in progress, or null if there is none.
120 NavigationEntry* GetPendingEntry() const {
121 return pending_entry_;
122 }
123
124 // Returns the index of the pending entry or -1 if the pending entry
125 // corresponds to a new navigation (created via LoadURL).
126 int GetPendingEntryIndex() const {
127 return pending_entry_index_;
128 }
129
130 // Returns the last committed entry, which may be null if there are no
131 // committed entries. 132 // committed entries.
132 NavigationEntry* GetLastCommittedEntry() const; 133 NavigationEntry* GetLastCommittedEntry() const;
133 134
134 // Returns the index of the last committed entry. 135 // Returns the index of the last committed entry.
135 int GetLastCommittedEntryIndex() const { 136 int GetLastCommittedEntryIndex() const {
136 return last_committed_entry_index_; 137 return last_committed_entry_index_;
137 } 138 }
138 139
140 // Navigation list -----------------------------------------------------------
141
139 // Returns the number of entries in the NavigationControllerBase, excluding 142 // Returns the number of entries in the NavigationControllerBase, excluding
140 // the pending entry if there is one. 143 // the pending entry if there is one.
141 int GetEntryCount() const { 144 int GetEntryCount() const {
142 return static_cast<int>(entries_.size()); 145 return static_cast<int>(entries_.size());
143 } 146 }
144 147
145 NavigationEntry* GetEntryAtIndex(int index) const { 148 NavigationEntry* GetEntryAtIndex(int index) const {
146 return entries_.at(index).get(); 149 return entries_.at(index).get();
147 } 150 }
148 151
149 // Returns the entry at the specified offset from current. Returns NULL 152 // Returns the entry at the specified offset from current. Returns NULL
150 // if out of bounds. 153 // if out of bounds.
151 NavigationEntry* GetEntryAtOffset(int offset) const; 154 NavigationEntry* GetEntryAtOffset(int offset) const;
152 155
153 bool CanStop() const; 156 // Returns the index of the specified entry, or -1 if entry is not contained
157 // in this NavigationControllerBase.
158 int GetIndexOfEntry(const NavigationEntry* entry) const;
154 159
155 // Return whether this controller can go back. 160 // Return the index of the entry with the corresponding type, instance, and
156 bool CanGoBack() const; 161 // page_id, or -1 if not found. Use a NULL instance if the type is not
157 162 // TAB_CONTENTS_WEB.
158 // Return whether this controller can go forward. 163 int GetEntryIndexWithPageID(TabContentsType type,
159 bool CanGoForward() const; 164 SiteInstance* instance,
160 165 int32 page_id) const;
161 // Causes the controller to go back.
162 void GoBack();
163
164 // Causes the controller to go forward.
165 void GoForward();
166
167 // Causes the controller to go to the specified index.
168 void GoToIndex(int index);
169
170 // Causes the controller to go to the specified offset from current. Does
171 // nothing if out of bounds.
172 void GoToOffset(int offset);
173
174 // Causes the controller to stop a pending navigation if any.
175 void Stop();
176
177 // Causes the controller to reload the current entry. Will prompt the user if
178 // reloading a URL with POST data and the active WebContents isn't showing the
179 // POST interstitial page.
180 void Reload();
181 166
182 // Return the entry with the corresponding type, instance, and page_id, or 167 // Return the entry with the corresponding type, instance, and page_id, or
183 // NULL if not found. Use a NULL instance if the type is not 168 // NULL if not found. Use a NULL instance if the type is not
184 // TAB_CONTENTS_WEB. 169 // TAB_CONTENTS_WEB.
185 NavigationEntry* GetEntryWithPageID(TabContentsType type, 170 NavigationEntry* GetEntryWithPageID(TabContentsType type,
186 SiteInstance* instance, 171 SiteInstance* instance,
187 int32 page_id) const; 172 int32 page_id) const;
188 173
189 // Causes the controller to load the specified entry. The controller 174 // Pending entry -------------------------------------------------------------
190 // assumes ownership of the entry.
191 // NOTE: Do not pass an entry that the controller already owns!
192 void LoadEntry(NavigationEntry* entry);
193 175
194 // Ensure the given NavigationEntry has a valid state, so that WebKit does 176 // Commits the current pending entry and issues the NOTIFY_NAV_ENTRY_COMMIT
195 // not get confused. 177 // notification. No changes are made to the entry during this process, it is
196 static void SetContentStateIfEmpty(NavigationEntry* entry); 178 // just moved from pending to committed. This is an alternative to
179 // RendererDidNavigate for simple TabContents types.
180 //
181 // When the pending entry is a new navigation, it will have a page ID of -1.
182 // The caller should leave this as-is. CommitPendingEntry will generate a
183 // new page ID for you and update the TabContents with that ID.
184 void CommitPendingEntry();
197 185
198 // Begin the destruction sequence for this NavigationController and all its 186 // Calling this may cause the active tab contents to switch if the current
199 // registered tabs. The sequence is as follows: 187 // entry corresponds to a different tab contents type.
200 // 1. All tabs are asked to Destroy themselves. 188 void DiscardPendingEntry();
201 // 2. When each tab is finished Destroying, it will notify the controller. 189
202 // 3. Once all tabs are Destroyed, the NavigationController deletes itself. 190 // Returns the pending entry corresponding to the navigation that is
203 // This ensures that all the TabContents outlive the NavigationController. 191 // currently in progress, or null if there is none.
204 void Destroy(); 192 NavigationEntry* GetPendingEntry() const {
193 return pending_entry_;
194 }
195
196 // Returns the index of the pending entry or -1 if the pending entry
197 // corresponds to a new navigation (created via LoadURL).
198 int GetPendingEntryIndex() const {
199 return pending_entry_index_;
200 }
201
202 // New navigations -----------------------------------------------------------
203
204 // Loads the specified URL.
205 void LoadURL(const GURL& url, PageTransition::Type type);
206
207 // Load the specified URL the next time it becomes active.
208 void LoadURLLazily(const GURL& url, PageTransition::Type type,
209 const std::wstring& title, SkBitmap* icon);
210
211 // Loads the current page if this NavigationController was restored from
212 // history and the current page has not loaded yet.
213 void LoadIfNecessary();
214
215 // Renavigation --------------------------------------------------------------
216
217 // Navigation relative to the "current entry"
218 bool CanGoBack() const;
219 bool CanGoForward() const;
220 void GoBack();
221 void GoForward();
222
223 // Navigates to the specified absolute index.
224 void GoToIndex(int index);
225
226 // Navigates to the specified offset from the "current entry". Does nothing if
227 // the offset is out of bounds.
228 void GoToOffset(int offset);
229
230 // Reloads the current entry. The user will be prompted if the URL has POST
231 // data and the active WebContents isn't showing the POST interstitial page.
232 void Reload();
233
234 // Same as Reload, but doesn't check if current entry has POST data.
235 void ReloadDontCheckForRepost();
236
237 // TabContents ---------------------------------------------------------------
205 238
206 // Notifies the controller that a TabContents that it owns has been destroyed. 239 // Notifies the controller that a TabContents that it owns has been destroyed.
207 // This is part of the NavigationController's Destroy sequence. 240 // This is part of the NavigationController's Destroy sequence.
208 void TabContentsWasDestroyed(TabContentsType type); 241 void TabContentsWasDestroyed(TabContentsType type);
209 242
243 // Returns the TabContents cached on this controller for the given type or
244 // NULL if there is none.
245 TabContents* GetTabContents(TabContentsType type);
246
210 // Returns the currently-active TabContents associated with this controller. 247 // Returns the currently-active TabContents associated with this controller.
211 // You should use GetActiveEntry instead of this in most cases. 248 // You should use GetActiveEntry instead of this in most cases.
212 TabContents* active_contents() const { 249 TabContents* active_contents() const {
213 return active_contents_; 250 return active_contents_;
214 } 251 }
215 252
216 // This can never be null. 253 // For use by TabContents ----------------------------------------------------
217 Profile* profile() const {
218 return profile_;
219 }
220 254
221 // Returns the TabContents cached on this controller for the given type or 255 // Handles updating the navigation state after the renderer has navigated.
222 // NULL if there is none. 256 // This is used by the WebContents. Simpler tab contents types can use
223 TabContents* GetTabContents(TabContentsType type); 257 // CommitPendingEntry below.
258 //
259 // If a new entry is created, it will return true and will have filled the
260 // given details structure and broadcast the NOTIFY_NAV_ENTRY_COMMITTED
261 // notification. The caller can then use the details without worrying about
262 // listening for the notification.
263 //
264 // In the case that nothing has changed, the details structure is undefined
265 // and it will return false.
266 bool RendererDidNavigate(const ViewHostMsg_FrameNavigate_Params& params,
267 bool is_interstitial,
268 LoadCommittedDetails* details);
224 269
225 // Causes the controller to load the specified URL. 270 // Inserts a new entry by making a copy of the given navigation entry. This is
226 void LoadURL(const GURL& url, PageTransition::Type type); 271 // used by interstitials to create dummy entries that they will be in charge
272 // of removing later.
273 void AddDummyEntryForInterstitial(const NavigationEntry& clone_me);
227 274
228 // Causes the controller to load the specified URL the next time it becomes 275 // Removes the last entry in the list. This is used by the interstitial code
229 // active. 276 // to delete the dummy entry created by AddDummyEntryForInterstitial. If the
230 void LoadURLLazily(const GURL& url, PageTransition::Type type, 277 // last entry is the currently committed one, a ENTRY_COMMITTED notification
231 const std::wstring& title, SkBitmap* icon); 278 // will be broadcast.
279 void RemoveLastEntryForInterstitial();
280
281 // Notifies us that we just became active. This is used by the TabContents
282 // so that we know to load URLs that were pending as "lazy" loads.
283 void SetActive(bool is_active);
284
285 // Broadcasts the NOTIFY_NAV_ENTRY_CHANGED notification for the given entry
286 // (which must be at the given index). This will keep things in sync like
287 // the saved session.
288 void NotifyEntryChanged(const NavigationEntry* entry, int index);
289
290 // Returns true if the given URL would be an in-page navigation (i.e. only
291 // the reference fragment is different) from the "last committed entry". We do
292 // not compare it against the "active entry" since the active entry can be
293 // pending and in page navigations only happen on committed pages. If there
294 // is no last committed entry, then nothing will be in-page.
295 //
296 // Special note: if the URLs are the same, it does NOT count as an in-page
297 // navigation. Neither does an input URL that has no ref, even if the rest is
298 // the same. This may seem weird, but when we're considering whether a
299 // navigation happened without loading anything, the same URL would be a
300 // reload, while only a different ref would be in-page (pages can't clear
301 // refs without reload, only change to "#" which we don't count as empty).
302 bool IsURLInPageNavigation(const GURL& url) const;
303
304 // Random data ---------------------------------------------------------------
232 305
233 // Returns true if this NavigationController is is configured to load a URL 306 // Returns true if this NavigationController is is configured to load a URL
234 // lazily. If true, use GetLazyTitle() and GetLazyFavIcon() to discover the 307 // lazily. If true, use GetLazyTitle() and GetLazyFavIcon() to discover the
235 // titles and favicons. Since no request was made, this is the only info 308 // titles and favicons. Since no request was made, this is the only info
236 // we have about this page. This feature is used by web application clusters. 309 // we have about this page. This feature is used by web application clusters.
237 bool LoadingURLLazily(); 310 bool LoadingURLLazily();
238 const std::wstring& GetLazyTitle() const; 311 const std::wstring& GetLazyTitle() const;
239 const SkBitmap& GetLazyFavIcon() const; 312 const SkBitmap& GetLazyFavIcon() const;
240 313
314 // TODO(brettw) bug 1324500: move this out of here.
241 void SetAlternateNavURLFetcher( 315 void SetAlternateNavURLFetcher(
242 AlternateNavURLFetcher* alternate_nav_url_fetcher); 316 AlternateNavURLFetcher* alternate_nav_url_fetcher);
243 317
244 // --------------------------------------------------------------------------
245 // For use by TabContents implementors:
246
247 // Used to inform the NavigationControllerBase of a navigation being committed
248 // for a tab. The controller takes ownership of the entry. Any entry located
249 // forward to the current entry will be deleted. The new entry becomes the
250 // current entry.
251 //
252 // The details are populated by the caller except for the new NavigationEntry
253 // pointer and the previous URL. We will fill these in before using it to
254 // broadcast notifications, so it can also be used by the caller.
255 //
256 // TODO(brettw) bug 1343146: The NavigationController should internally make
257 // the entry and the notification details.
258 void DidNavigateToEntry(NavigationEntry* entry,
259 LoadCommittedDetails* details);
260
261 // Calling this may cause the active tab contents to switch if the current
262 // entry corresponds to a different tab contents type.
263 void DiscardPendingEntry();
264
265 // Inserts an entry after the current position, removing all entries after it.
266 // The new entry will become the active one.
267 void InsertEntry(NavigationEntry* entry);
268
269 // Returns the identifier used by session restore. 318 // Returns the identifier used by session restore.
270 const SessionID& session_id() const { return session_id_; } 319 const SessionID& session_id() const { return session_id_; }
271 320
272 // Identifier of the window we're in. 321 // Identifier of the window we're in.
273 void SetWindowID(const SessionID& id); 322 void SetWindowID(const SessionID& id);
274 const SessionID& window_id() const { return window_id_; } 323 const SessionID& window_id() const { return window_id_; }
275 324
276 SSLManager* ssl_manager() { return &ssl_manager_; } 325 SSLManager* ssl_manager() { return &ssl_manager_; }
277 326
278 // Broadcasts the NOTIFY_NAV_ENTRY_CHANGED notification for the
279 // navigation corresponding to the given page. This will keep things in sync
280 // like saved session.
281 void NotifyEntryChangedByPageID(TabContentsType type,
282 SiteInstance* instance,
283 int32 page_id);
284
285 void SetActive(bool is_active);
286
287 // If this NavigationController was restored from history and the selected
288 // page has not loaded, it is loaded.
289 void LoadIfNecessary();
290
291 // Clone the receiving navigation controller. Only the active tab contents is
292 // duplicated. It is created as a child of the provided HWND.
293 NavigationController* Clone(HWND hwnd);
294
295 // Returns true if a reload happens when activated (SetActive(true) is 327 // Returns true if a reload happens when activated (SetActive(true) is
296 // invoked). This is true for session/tab restore and cloned tabs. 328 // invoked). This is true for session/tab restore and cloned tabs.
297 bool needs_reload() const { return needs_reload_; } 329 bool needs_reload() const { return needs_reload_; }
298 330
331 // Returns the largest restored page ID seen in this navigation controller,
332 // if it was restored from a previous session. (-1 otherwise)
333 int max_restored_page_id() const { return max_restored_page_id_; }
334
299 // Disables checking for a repost and prompting the user. This is used during 335 // Disables checking for a repost and prompting the user. This is used during
300 // testing. 336 // testing.
301 static void DisablePromptOnRepost(); 337 static void DisablePromptOnRepost();
302 338
303 // Returns the largest restored page ID seen in this navigation controller,
304 // if it was restored from a previous session. (-1 otherwise)
305 int max_restored_page_id() const { return max_restored_page_id_; }
306
307 // Returns the index of the specified entry, or -1 if entry is not contained
308 // in this NavigationControllerBase.
309 int GetIndexOfEntry(const NavigationEntry* entry) const;
310
311 // Removes the last committed entry.
312 void RemoveLastEntry();
313
314 private: 339 private:
315 FRIEND_TEST(NavigationControllerTest, EnforceMaxNavigationCount); 340 FRIEND_TEST(NavigationControllerTest, EnforceMaxNavigationCount);
316
317 class RestoreHelper; 341 class RestoreHelper;
318 friend class RestoreHelper; 342 friend class RestoreHelper;
343 friend class TabContents; // For invoking OnReservedPageIDRange.
319 344
320 // For invoking OnReservedPageIDRange. 345 // Indicates different types of navigations that can occur that we will handle
321 friend class TabContents; 346 // separately. This is computed by ClassifyNavigation.
322 // For invoking GetMaxPageID. 347 enum NavClass {
323 friend class WebContents; 348 // A new page was navigated in the main frame.
324 // For invoking GetMaxPageID. 349 NAV_NEW_PAGE,
325 friend class printing::PrintViewManager;
326 350
327 // Returns the largest page ID seen. When PageIDs come in larger than 351 // Renavigating to an existing navigation entry. The entry is guaranteed to
328 // this (via DidNavigateToEntry), we know that we've navigated to a new page. 352 // exist in the list, or else it would be a new page or IGNORE navigation.
329 int GetMaxPageID() const; 353 NAV_EXISTING_PAGE,
354
355 // The same page has been reloaded as a result of the user requesting
356 // navigation to that same page (like pressing Enter in the URL bar). This
357 // is not the same as an in-page navigation because we'll actually have a
358 // pending entry for the load, which is then meaningless.
359 NAV_SAME_PAGE,
360
361 // In page navigations are when the reference fragment changes. This will
362 // be in the main frame only (we won't even get notified of in-page
363 // subframe navigations). It may be for any page, not necessarily the last
364 // committed one (for example, whey going back to a page with a ref).
365 NAV_IN_PAGE,
366
367 // A new subframe was manually navigated by the user. We will create a new
368 // NavigationEntry so they can go back to the previous subframe content
369 // using the back button.
370 NAV_NEW_SUBFRAME,
371
372 // A subframe in the page was automatically loaded or navigated to such that
373 // a new navigation entry should not be created. There are two cases:
374 // 1. Stuff like iframes containing ads that the page loads automatically.
375 // The user doesn't want to see these, so we just update the existing
376 // navigation entry.
377 // 2. Going back/forward to previous subframe navigations. We don't create
378 // a new entry here either, just update the last committed entry.
379 // These two cases are actually pretty different, they just happen to
380 // require almost the same code to handle.
381 NAV_AUTO_SUBFRAME,
382
383 // Nothing happened. This happens when we get information about a page we
384 // don't know anything about. It can also happen when an iframe in a popup
385 // navigated to about:blank is navigated. Nothing needs to be done.
386 NAV_IGNORE,
387 };
388
389 // Classifies the given renderer navigation (see the NavigationType enum).
390 NavClass ClassifyNavigation(
391 const ViewHostMsg_FrameNavigate_Params& params) const;
392
393 // Causes the controller to load the specified entry. The function assumes
394 // ownership of the pointer since it is put in the navigation list.
395 // NOTE: Do not pass an entry that the controller already owns!
396 void LoadEntry(NavigationEntry* entry);
397
398 // Handlers for the different types of navigation types. They will actually
399 // handle the navigations corresponding to the different NavClasses above.
400 // They will NOT broadcast the commit notification, that should be handled by
401 // the caller.
402 //
403 // RendererDidNavigateAutoSubframe is special, it may not actually change
404 // anything if some random subframe is loaded. It will return true if anything
405 // changed, or false if not.
406 void RendererDidNavigateToNewPage(
407 const ViewHostMsg_FrameNavigate_Params& params);
408 void RendererDidNavigateToExistingPage(
409 const ViewHostMsg_FrameNavigate_Params& params);
410 void RendererDidNavigateToSamePage(
411 const ViewHostMsg_FrameNavigate_Params& params);
412 void RendererDidNavigateInPage(
413 const ViewHostMsg_FrameNavigate_Params& params);
414 void RendererDidNavigateNewSubframe(
415 const ViewHostMsg_FrameNavigate_Params& params);
416 bool RendererDidNavigateAutoSubframe(
417 const ViewHostMsg_FrameNavigate_Params& params);
330 418
331 // Actually issues the navigation held in pending_entry. 419 // Actually issues the navigation held in pending_entry.
332 void NavigateToPendingEntry(bool reload); 420 void NavigateToPendingEntry(bool reload);
333 421
334 // Allows the derived class to issue notifications that a load has been 422 // Allows the derived class to issue notifications that a load has been
335 // committed. This will fill in the active entry to the details structure. 423 // committed. This will fill in the active entry to the details structure.
336 void NotifyNavigationEntryCommitted(LoadCommittedDetails* details); 424 void NotifyNavigationEntryCommitted(LoadCommittedDetails* details);
337 425
338 // Invoked when entries have been pruned, or removed. For example, if the
339 // current entries are [google, digg, yahoo], with the current entry google,
340 // and the user types in cnet, then digg and yahoo are pruned.
341 void NotifyPrunedEntries();
342
343 // Invoked when the index of the active entry may have changed. 426 // Invoked when the index of the active entry may have changed.
344 // The prev_commited_index parameter specifies the previous value 427 // The prev_commited_index parameter specifies the previous value
345 // of the last commited index before this navigation event happened 428 // of the last commited index before this navigation event happened
346 void IndexOfActiveEntryChanged(int prev_commited_index); 429 void IndexOfActiveEntryChanged(int prev_commited_index);
347 430
348 // Returns the TabContents for the |entry|'s type. If the TabContents 431 // Returns the TabContents for the |entry|'s type. If the TabContents
349 // doesn't yet exist, it is created. If a new TabContents is created, its 432 // doesn't yet exist, it is created. If a new TabContents is created, its
350 // parent is |parent|. Becomes part of |entry|'s SiteInstance. 433 // parent is |parent|. Becomes part of |entry|'s SiteInstance.
351 TabContents* GetTabContentsCreateIfNecessary(HWND parent, 434 TabContents* GetTabContentsCreateIfNecessary(HWND parent,
352 const NavigationEntry& entry); 435 const NavigationEntry& entry);
353 436
354 // Register the provided tab contents. This tab contents will be owned 437 // Register the provided tab contents. This tab contents will be owned
355 // and deleted by this navigation controller 438 // and deleted by this navigation controller
356 void RegisterTabContents(TabContents* some_contents); 439 void RegisterTabContents(TabContents* some_contents);
357 440
358 // Broadcasts a notification that the given entry changed.
359 void NotifyEntryChanged(const NavigationEntry* entry, int index);
360
361 // Removes the entry at the specified index. Note that you should not remove 441 // Removes the entry at the specified index. Note that you should not remove
362 // the pending entry or the last committed entry. 442 // the pending entry or the last committed entry.
363 void RemoveEntryAtIndex(int index); 443 void RemoveEntryAtIndex(int index);
364 444
365 // Sets the max restored page ID this NavigationController has seen, if it 445 // Sets the max restored page ID this NavigationController has seen, if it
366 // was restored from a previous session. 446 // was restored from a previous session.
367 void set_max_restored_page_id(int max_id) { max_restored_page_id_ = max_id; } 447 void set_max_restored_page_id(int max_id) { max_restored_page_id_ = max_id; }
368 448
369 NavigationEntry* CreateNavigationEntry(const GURL& url, 449 NavigationEntry* CreateNavigationEntry(const GURL& url,
370 PageTransition::Type transition); 450 PageTransition::Type transition);
371 451
372 // Invokes ScheduleTabContentsCollection for all TabContents but the active 452 // Invokes ScheduleTabContentsCollection for all TabContents but the active
373 // one. 453 // one.
374 void ScheduleTabContentsCollectionForInactiveTabs(); 454 void ScheduleTabContentsCollectionForInactiveTabs();
375 455
376 // Schedule the TabContents currently allocated for |tc| for collection. 456 // Schedule the TabContents currently allocated for |tc| for collection.
377 // The TabContents will be destroyed later from a different event. 457 // The TabContents will be destroyed later from a different event.
378 void ScheduleTabContentsCollection(TabContentsType t); 458 void ScheduleTabContentsCollection(TabContentsType t);
379 459
380 // Cancel the collection of the TabContents allocated for |tc|. This method 460 // Cancel the collection of the TabContents allocated for |tc|. This method
381 // is used when we keep using a TabContents because a provisional load failed. 461 // is used when we keep using a TabContents because a provisional load failed.
382 void CancelTabContentsCollection(TabContentsType t); 462 void CancelTabContentsCollection(TabContentsType t);
383 463
384 // Invoked after session/tab restore or cloning a tab. Resets the transition 464 // Invoked after session/tab restore or cloning a tab. Resets the transition
385 // type of the entries, updates the max page id and creates the active 465 // type of the entries, updates the max page id and creates the active
386 // contents. 466 // contents.
387 void FinishRestore(HWND parent_hwnd, int selected_index); 467 void FinishRestore(HWND parent_hwnd, int selected_index);
388 468
469 // Inserts an entry after the current position, removing all entries after it.
470 // The new entry will become the active one.
471 void InsertEntry(NavigationEntry* entry);
472
389 // Discards the pending entry without updating active_contents_ 473 // Discards the pending entry without updating active_contents_
390 void DiscardPendingEntryInternal(); 474 void DiscardPendingEntryInternal();
391 475
392 // Return the index of the entry with the corresponding type, instance, and 476 // ---------------------------------------------------------------------------
393 // page_id, or -1 if not found. Use a NULL instance if the type is not
394 // TAB_CONTENTS_WEB.
395 int GetEntryIndexWithPageID(TabContentsType type,
396 SiteInstance* instance,
397 int32 page_id) const;
398 477
399 // The user profile associated with this controller 478 // The user profile associated with this controller
400 Profile* profile_; 479 Profile* profile_;
401 480
402 // List of NavigationEntry for this tab 481 // List of NavigationEntry for this tab
403 typedef std::vector<linked_ptr<NavigationEntry> > NavigationEntries; 482 typedef std::vector<linked_ptr<NavigationEntry> > NavigationEntries;
404 NavigationEntries entries_; 483 NavigationEntries entries_;
405 484
406 // An entry we haven't gotten a response for yet. This will be discarded 485 // An entry we haven't gotten a response for yet. This will be discarded
407 // when we navigate again. It's used only so we know what the currently 486 // when we navigate again. It's used only so we know what the currently
408 // displayed tab is. 487 // displayed tab is.
409 // 488 //
410 // This may refer to an item in the entries_ list if the pending_entry_index_ 489 // This may refer to an item in the entries_ list if the pending_entry_index_
411 // == -1, or it may be its own entry that should be deleted. Be careful with 490 // == -1, or it may be its own entry that should be deleted. Be careful with
412 // the memory management. 491 // the memory management.
413 NavigationEntry* pending_entry_; 492 NavigationEntry* pending_entry_;
414 493
415 // currently visible entry 494 // currently visible entry
416 int last_committed_entry_index_; 495 int last_committed_entry_index_;
417 496
418 // index of pending entry if it is in entries_, or -1 if pending_entry_ is a 497 // index of pending entry if it is in entries_, or -1 if pending_entry_ is a
419 // new entry (created by LoadURL). 498 // new entry (created by LoadURL).
420 int pending_entry_index_; 499 int pending_entry_index_;
421 500
422 // Tab contents. One entry per type used. The tab controller owns 501 // Tab contents. One entry per type used. The tab controller owns
423 // every tab contents used. 502 // every tab contents used.
424 typedef stdext::hash_map<TabContentsType, TabContents*> TabContentsMap; 503 typedef std::map<TabContentsType, TabContents*> TabContentsMap;
425 TabContentsMap tab_contents_map_; 504 TabContentsMap tab_contents_map_;
426 505
427 // A map of TabContentsType -> TabContentsCollector containing all the 506 // A map of TabContentsType -> TabContentsCollector containing all the
428 // pending collectors. 507 // pending collectors.
429 typedef stdext::hash_map<TabContentsType, TabContentsCollector*> 508 typedef stdext::hash_map<TabContentsType, TabContentsCollector*>
430 TabContentsCollectorMap; 509 TabContentsCollectorMap;
431 TabContentsCollectorMap tab_contents_collector_map_; 510 TabContentsCollectorMap tab_contents_collector_map_;
432 511
433 // The tab contents that is currently active. 512 // The tab contents that is currently active.
434 TabContents* active_contents_; 513 TabContents* active_contents_;
(...skipping 29 matching lines...) Expand all
464 // when testing. 543 // when testing.
465 static bool check_for_repost_; 544 static bool check_for_repost_;
466 545
467 // The maximum number of entries that a navigation controller can store. 546 // The maximum number of entries that a navigation controller can store.
468 size_t max_entry_count_; 547 size_t max_entry_count_;
469 548
470 DISALLOW_COPY_AND_ASSIGN(NavigationController); 549 DISALLOW_COPY_AND_ASSIGN(NavigationController);
471 }; 550 };
472 551
473 #endif // CHROME_BROWSER_NAVIGATION_CONTROLLER_H_ 552 #endif // CHROME_BROWSER_NAVIGATION_CONTROLLER_H_
474
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698