OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ | 5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ |
6 #define CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ | 6 #define CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 #include "content/browser/ssl/ssl_manager.h" | 17 #include "content/browser/ssl/ssl_manager.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 #include "content/public/browser/global_request_id.h" | 19 #include "content/public/browser/global_request_id.h" |
20 #include "content/public/browser/navigation_type.h" | 20 #include "content/public/browser/navigation_type.h" |
21 #include "content/public/common/page_transition_types.h" | 21 #include "content/public/common/page_transition_types.h" |
22 #include "content/public/common/referrer.h" | 22 #include "content/public/common/referrer.h" |
23 | 23 |
24 class NavigationEntry; | |
25 class SessionStorageNamespace; | 24 class SessionStorageNamespace; |
26 class SiteInstance; | 25 class SiteInstance; |
27 class TabContents; | 26 class TabContents; |
28 struct ViewHostMsg_FrameNavigate_Params; | 27 struct ViewHostMsg_FrameNavigate_Params; |
29 | 28 |
30 namespace content { | 29 namespace content { |
31 class BrowserContext; | 30 class BrowserContext; |
32 class NavigationEntry; | 31 class NavigationEntry; |
| 32 class NavigationEntryImpl; |
33 struct LoadCommittedDetails; | 33 struct LoadCommittedDetails; |
34 struct Referrer; | 34 struct Referrer; |
35 } | 35 } |
36 | 36 |
37 // A NavigationController maintains the back-forward list for a single tab and | 37 // A NavigationController maintains the back-forward list for a single tab and |
38 // manages all navigation within that list. | 38 // manages all navigation within that list. |
39 // | 39 // |
40 // The NavigationController also owns all TabContents for the tab. This is to | 40 // The NavigationController also owns all TabContents for the tab. This is to |
41 // make sure that we have at most one TabContents instance per type. | 41 // make sure that we have at most one TabContents instance per type. |
42 class CONTENT_EXPORT NavigationController { | 42 class CONTENT_EXPORT NavigationController { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 122 } |
123 | 123 |
124 content::NavigationEntry* GetEntryAtIndex(int index) const; | 124 content::NavigationEntry* GetEntryAtIndex(int index) const; |
125 | 125 |
126 // Returns the entry at the specified offset from current. Returns NULL | 126 // Returns the entry at the specified offset from current. Returns NULL |
127 // if out of bounds. | 127 // if out of bounds. |
128 content::NavigationEntry* GetEntryAtOffset(int offset) const; | 128 content::NavigationEntry* GetEntryAtOffset(int offset) const; |
129 | 129 |
130 // Returns the index of the specified entry, or -1 if entry is not contained | 130 // Returns the index of the specified entry, or -1 if entry is not contained |
131 // in this NavigationController. | 131 // in this NavigationController. |
132 int GetIndexOfEntry(const NavigationEntry* entry) const; | 132 int GetIndexOfEntry(const content::NavigationEntryImpl* entry) const; |
133 | 133 |
134 // Return the index of the entry with the corresponding instance and page_id, | 134 // Return the index of the entry with the corresponding instance and page_id, |
135 // or -1 if not found. | 135 // or -1 if not found. |
136 int GetEntryIndexWithPageID(SiteInstance* instance, | 136 int GetEntryIndexWithPageID(SiteInstance* instance, |
137 int32 page_id) const; | 137 int32 page_id) const; |
138 | 138 |
139 // Return the entry with the corresponding instance and page_id, or NULL if | 139 // Return the entry with the corresponding instance and page_id, or NULL if |
140 // not found. | 140 // not found. |
141 NavigationEntry* GetEntryWithPageID(SiteInstance* instance, | 141 content::NavigationEntryImpl* GetEntryWithPageID(SiteInstance* instance, |
142 int32 page_id) const; | 142 int32 page_id) const; |
143 | 143 |
144 // Pending entry ------------------------------------------------------------- | 144 // Pending entry ------------------------------------------------------------- |
145 | 145 |
146 // Discards the pending and transient entries if any. | 146 // Discards the pending and transient entries if any. |
147 void DiscardNonCommittedEntries(); | 147 void DiscardNonCommittedEntries(); |
148 | 148 |
149 // Returns the pending entry corresponding to the navigation that is | 149 // Returns the pending entry corresponding to the navigation that is |
150 // currently in progress, or null if there is none. | 150 // currently in progress, or null if there is none. |
151 content::NavigationEntry* GetPendingEntry() const; | 151 content::NavigationEntry* GetPendingEntry() const; |
152 | 152 |
153 // Returns the index of the pending entry or -1 if the pending entry | 153 // Returns the index of the pending entry or -1 if the pending entry |
154 // corresponds to a new navigation (created via LoadURL). | 154 // corresponds to a new navigation (created via LoadURL). |
155 int pending_entry_index() const { | 155 int pending_entry_index() const { |
156 return pending_entry_index_; | 156 return pending_entry_index_; |
157 } | 157 } |
158 | 158 |
159 // Transient entry ----------------------------------------------------------- | 159 // Transient entry ----------------------------------------------------------- |
160 | 160 |
161 // Adds an entry that is returned by GetActiveEntry(). The entry is | 161 // Adds an entry that is returned by GetActiveEntry(). The entry is |
162 // transient: any navigation causes it to be removed and discarded. | 162 // transient: any navigation causes it to be removed and discarded. |
163 // The NavigationController becomes the owner of |entry| and deletes it when | 163 // The NavigationController becomes the owner of |entry| and deletes it when |
164 // it discards it. This is useful with interstitial page that need to be | 164 // it discards it. This is useful with interstitial page that need to be |
165 // represented as an entry, but should go away when the user navigates away | 165 // represented as an entry, but should go away when the user navigates away |
166 // from them. | 166 // from them. |
167 // Note that adding a transient entry does not change the active contents. | 167 // Note that adding a transient entry does not change the active contents. |
168 void AddTransientEntry(NavigationEntry* entry); | 168 void AddTransientEntry(content::NavigationEntryImpl* entry); |
169 | 169 |
170 // Returns the transient entry if any. Note that the returned entry is owned | 170 // Returns the transient entry if any. Note that the returned entry is owned |
171 // by the navigation controller and may be deleted at any time. | 171 // by the navigation controller and may be deleted at any time. |
172 content::NavigationEntry* GetTransientEntry() const; | 172 content::NavigationEntry* GetTransientEntry() const; |
173 | 173 |
174 // New navigations ----------------------------------------------------------- | 174 // New navigations ----------------------------------------------------------- |
175 | 175 |
176 // Loads the specified URL, specifying extra http headers to add to the | 176 // Loads the specified URL, specifying extra http headers to add to the |
177 // request. Extra headers are separated by \n. | 177 // request. Extra headers are separated by \n. |
178 void LoadURL(const GURL& url, | 178 void LoadURL(const GURL& url, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 // Creates navigation entry and translates the virtual url to a real one. | 347 // Creates navigation entry and translates the virtual url to a real one. |
348 // Used when navigating to a new URL using LoadURL. Extra headers are | 348 // Used when navigating to a new URL using LoadURL. Extra headers are |
349 // separated by \n. | 349 // separated by \n. |
350 static content::NavigationEntry* CreateNavigationEntry( | 350 static content::NavigationEntry* CreateNavigationEntry( |
351 const GURL& url, | 351 const GURL& url, |
352 const content::Referrer& referrer, | 352 const content::Referrer& referrer, |
353 content::PageTransition transition, | 353 content::PageTransition transition, |
354 bool is_renderer_initiated, | 354 bool is_renderer_initiated, |
355 const std::string& extra_headers, | 355 const std::string& extra_headers, |
356 content::BrowserContext* browser_context); | 356 content::BrowserContext* browser_context); |
357 static NavigationEntry* CreateNavigationEntryImpl( | 357 static content::NavigationEntryImpl* CreateNavigationEntryImpl( |
358 const GURL& url, | 358 const GURL& url, |
359 const content::Referrer& referrer, | 359 const content::Referrer& referrer, |
360 content::PageTransition transition, | 360 content::PageTransition transition, |
361 bool is_renderer_initiated, | 361 bool is_renderer_initiated, |
362 const std::string& extra_headers, | 362 const std::string& extra_headers, |
363 content::BrowserContext* browser_context); | 363 content::BrowserContext* browser_context); |
364 | 364 |
365 private: | 365 private: |
366 class RestoreHelper; | 366 class RestoreHelper; |
367 friend class RestoreHelper; | 367 friend class RestoreHelper; |
368 friend class TabContents; // For invoking OnReservedPageIDRange. | 368 friend class TabContents; // For invoking OnReservedPageIDRange. |
369 | 369 |
370 // Classifies the given renderer navigation (see the NavigationType enum). | 370 // Classifies the given renderer navigation (see the NavigationType enum). |
371 content::NavigationType ClassifyNavigation( | 371 content::NavigationType ClassifyNavigation( |
372 const ViewHostMsg_FrameNavigate_Params& params) const; | 372 const ViewHostMsg_FrameNavigate_Params& params) const; |
373 | 373 |
374 // Causes the controller to load the specified entry. The function assumes | 374 // Causes the controller to load the specified entry. The function assumes |
375 // ownership of the pointer since it is put in the navigation list. | 375 // ownership of the pointer since it is put in the navigation list. |
376 // NOTE: Do not pass an entry that the controller already owns! | 376 // NOTE: Do not pass an entry that the controller already owns! |
377 void LoadEntry(NavigationEntry* entry); | 377 void LoadEntry(content::NavigationEntryImpl* entry); |
378 | 378 |
379 // Handlers for the different types of navigation types. They will actually | 379 // Handlers for the different types of navigation types. They will actually |
380 // handle the navigations corresponding to the different NavClasses above. | 380 // handle the navigations corresponding to the different NavClasses above. |
381 // They will NOT broadcast the commit notification, that should be handled by | 381 // They will NOT broadcast the commit notification, that should be handled by |
382 // the caller. | 382 // the caller. |
383 // | 383 // |
384 // RendererDidNavigateAutoSubframe is special, it may not actually change | 384 // RendererDidNavigateAutoSubframe is special, it may not actually change |
385 // anything if some random subframe is loaded. It will return true if anything | 385 // anything if some random subframe is loaded. It will return true if anything |
386 // changed, or false if not. | 386 // changed, or false if not. |
387 // | 387 // |
(...skipping 18 matching lines...) Expand all Loading... |
406 | 406 |
407 // Actually issues the navigation held in pending_entry. | 407 // Actually issues the navigation held in pending_entry. |
408 void NavigateToPendingEntry(ReloadType reload_type); | 408 void NavigateToPendingEntry(ReloadType reload_type); |
409 | 409 |
410 // Allows the derived class to issue notifications that a load has been | 410 // Allows the derived class to issue notifications that a load has been |
411 // committed. This will fill in the active entry to the details structure. | 411 // committed. This will fill in the active entry to the details structure. |
412 void NotifyNavigationEntryCommitted(content::LoadCommittedDetails* details); | 412 void NotifyNavigationEntryCommitted(content::LoadCommittedDetails* details); |
413 | 413 |
414 // Updates the virtual URL of an entry to match a new URL, for cases where | 414 // Updates the virtual URL of an entry to match a new URL, for cases where |
415 // the real renderer URL is derived from the virtual URL, like view-source: | 415 // the real renderer URL is derived from the virtual URL, like view-source: |
416 void UpdateVirtualURLToURL(NavigationEntry* entry, const GURL& new_url); | 416 void UpdateVirtualURLToURL(content::NavigationEntryImpl* entry, |
| 417 const GURL& new_url); |
417 | 418 |
418 // Invoked after session/tab restore or cloning a tab. Resets the transition | 419 // Invoked after session/tab restore or cloning a tab. Resets the transition |
419 // type of the entries, updates the max page id and creates the active | 420 // type of the entries, updates the max page id and creates the active |
420 // contents. See RestoreFromState for a description of from_last_session. | 421 // contents. See RestoreFromState for a description of from_last_session. |
421 void FinishRestore(int selected_index, bool from_last_session); | 422 void FinishRestore(int selected_index, bool from_last_session); |
422 | 423 |
423 // Inserts a new entry or replaces the current entry with a new one, removing | 424 // Inserts a new entry or replaces the current entry with a new one, removing |
424 // all entries after it. The new entry will become the active one. | 425 // all entries after it. The new entry will become the active one. |
425 void InsertOrReplaceEntry(NavigationEntry* entry, bool replace); | 426 void InsertOrReplaceEntry(content::NavigationEntryImpl* entry, bool replace); |
426 | 427 |
427 // Removes the entry at |index|, as long as it is not the current entry. | 428 // Removes the entry at |index|, as long as it is not the current entry. |
428 void RemoveEntryAtIndexInternal(int index); | 429 void RemoveEntryAtIndexInternal(int index); |
429 | 430 |
430 // Discards the pending and transient entries. | 431 // Discards the pending and transient entries. |
431 void DiscardNonCommittedEntriesInternal(); | 432 void DiscardNonCommittedEntriesInternal(); |
432 | 433 |
433 // Discards the transient entry. | 434 // Discards the transient entry. |
434 void DiscardTransientEntry(); | 435 void DiscardTransientEntry(); |
435 | 436 |
436 // Returns true if the navigation is redirect. | 437 // Returns true if the navigation is redirect. |
437 bool IsRedirect(const ViewHostMsg_FrameNavigate_Params& params); | 438 bool IsRedirect(const ViewHostMsg_FrameNavigate_Params& params); |
438 | 439 |
439 // Returns true if the navigation is likley to be automatic rather than | 440 // Returns true if the navigation is likley to be automatic rather than |
440 // user-initiated. | 441 // user-initiated. |
441 bool IsLikelyAutoNavigation(base::TimeTicks now); | 442 bool IsLikelyAutoNavigation(base::TimeTicks now); |
442 | 443 |
443 // Inserts up to |max_index| entries from |source| into this. This does NOT | 444 // Inserts up to |max_index| entries from |source| into this. This does NOT |
444 // adjust any of the members that reference entries_ | 445 // adjust any of the members that reference entries_ |
445 // (last_committed_entry_index_, pending_entry_index_ or | 446 // (last_committed_entry_index_, pending_entry_index_ or |
446 // transient_entry_index_). | 447 // transient_entry_index_). |
447 void InsertEntriesFrom(const NavigationController& source, int max_index); | 448 void InsertEntriesFrom(const NavigationController& source, int max_index); |
448 | 449 |
449 // --------------------------------------------------------------------------- | 450 // --------------------------------------------------------------------------- |
450 | 451 |
451 // The user browser context associated with this controller. | 452 // The user browser context associated with this controller. |
452 content::BrowserContext* browser_context_; | 453 content::BrowserContext* browser_context_; |
453 | 454 |
454 // List of NavigationEntry for this tab | 455 // List of NavigationEntry for this tab |
455 typedef std::vector<linked_ptr<NavigationEntry> > NavigationEntries; | 456 typedef std::vector<linked_ptr<content::NavigationEntryImpl> > |
| 457 NavigationEntries; |
456 NavigationEntries entries_; | 458 NavigationEntries entries_; |
457 | 459 |
458 // An entry we haven't gotten a response for yet. This will be discarded | 460 // An entry we haven't gotten a response for yet. This will be discarded |
459 // when we navigate again. It's used only so we know what the currently | 461 // when we navigate again. It's used only so we know what the currently |
460 // displayed tab is. | 462 // displayed tab is. |
461 // | 463 // |
462 // This may refer to an item in the entries_ list if the pending_entry_index_ | 464 // This may refer to an item in the entries_ list if the pending_entry_index_ |
463 // == -1, or it may be its own entry that should be deleted. Be careful with | 465 // == -1, or it may be its own entry that should be deleted. Be careful with |
464 // the memory management. | 466 // the memory management. |
465 NavigationEntry* pending_entry_; | 467 content::NavigationEntryImpl* pending_entry_; |
466 | 468 |
467 // currently visible entry | 469 // currently visible entry |
468 int last_committed_entry_index_; | 470 int last_committed_entry_index_; |
469 | 471 |
470 // index of pending entry if it is in entries_, or -1 if pending_entry_ is a | 472 // index of pending entry if it is in entries_, or -1 if pending_entry_ is a |
471 // new entry (created by LoadURL). | 473 // new entry (created by LoadURL). |
472 int pending_entry_index_; | 474 int pending_entry_index_; |
473 | 475 |
474 // The index for the entry that is shown until a navigation occurs. This is | 476 // The index for the entry that is shown until a navigation occurs. This is |
475 // used for interstitial pages. -1 if there are no such entry. | 477 // used for interstitial pages. -1 if there are no such entry. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 static size_t max_entry_count_for_testing_; | 509 static size_t max_entry_count_for_testing_; |
508 | 510 |
509 // If a repost is pending, its type (RELOAD or RELOAD_IGNORING_CACHE), | 511 // If a repost is pending, its type (RELOAD or RELOAD_IGNORING_CACHE), |
510 // NO_RELOAD otherwise. | 512 // NO_RELOAD otherwise. |
511 ReloadType pending_reload_; | 513 ReloadType pending_reload_; |
512 | 514 |
513 DISALLOW_COPY_AND_ASSIGN(NavigationController); | 515 DISALLOW_COPY_AND_ASSIGN(NavigationController); |
514 }; | 516 }; |
515 | 517 |
516 #endif // CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ | 518 #endif // CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ |
OLD | NEW |