| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_IMPL_H_ | |
| 6 #define CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_IMPL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "build/build_config.h" | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/linked_ptr.h" | |
| 12 #include "base/time.h" | |
| 13 #include "content/browser/ssl/ssl_manager.h" | |
| 14 #include "content/public/browser/navigation_controller.h" | |
| 15 #include "content/public/browser/navigation_type.h" | |
| 16 | |
| 17 class SessionStorageNamespaceImpl; | |
| 18 struct ViewHostMsg_FrameNavigate_Params; | |
| 19 class WebContentsImpl; | |
| 20 | |
| 21 namespace content { | |
| 22 class NavigationEntryImpl; | |
| 23 struct LoadCommittedDetails; | |
| 24 class SiteInstance; | |
| 25 } | |
| 26 | |
| 27 class CONTENT_EXPORT NavigationControllerImpl | |
| 28 : public NON_EXPORTED_BASE(content::NavigationController) { | |
| 29 public: | |
| 30 NavigationControllerImpl( | |
| 31 WebContentsImpl* tab_contents, | |
| 32 content::BrowserContext* browser_context, | |
| 33 SessionStorageNamespaceImpl* session_storage_namespace); | |
| 34 virtual ~NavigationControllerImpl(); | |
| 35 | |
| 36 // NavigationController implementation: | |
| 37 virtual content::WebContents* GetWebContents() const OVERRIDE; | |
| 38 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; | |
| 39 virtual void SetBrowserContext( | |
| 40 content::BrowserContext* browser_context) OVERRIDE; | |
| 41 virtual void Restore( | |
| 42 int selected_navigation, | |
| 43 bool from_last_session, | |
| 44 std::vector<content::NavigationEntry*>* entries) OVERRIDE; | |
| 45 virtual content::NavigationEntry* GetActiveEntry() const OVERRIDE; | |
| 46 virtual content::NavigationEntry* GetVisibleEntry() const OVERRIDE; | |
| 47 virtual int GetCurrentEntryIndex() const OVERRIDE; | |
| 48 virtual content::NavigationEntry* GetLastCommittedEntry() const OVERRIDE; | |
| 49 virtual int GetLastCommittedEntryIndex() const OVERRIDE; | |
| 50 virtual bool CanViewSource() const OVERRIDE; | |
| 51 virtual int GetEntryCount() const OVERRIDE; | |
| 52 virtual content::NavigationEntry* GetEntryAtIndex(int index) const OVERRIDE; | |
| 53 virtual content::NavigationEntry* GetEntryAtOffset(int offset) const OVERRIDE; | |
| 54 virtual void DiscardNonCommittedEntries() OVERRIDE; | |
| 55 virtual content::NavigationEntry* GetPendingEntry() const OVERRIDE; | |
| 56 virtual int GetPendingEntryIndex() const OVERRIDE; | |
| 57 virtual content::NavigationEntry* GetTransientEntry() const OVERRIDE; | |
| 58 virtual void LoadURL(const GURL& url, | |
| 59 const content::Referrer& referrer, | |
| 60 content::PageTransition type, | |
| 61 const std::string& extra_headers) OVERRIDE; | |
| 62 virtual void LoadURLFromRenderer(const GURL& url, | |
| 63 const content::Referrer& referrer, | |
| 64 content::PageTransition type, | |
| 65 const std::string& extra_headers) OVERRIDE; | |
| 66 virtual void TransferURL( | |
| 67 const GURL& url, | |
| 68 const content::Referrer& referrer, | |
| 69 content::PageTransition transition, | |
| 70 const std::string& extra_headers, | |
| 71 const content::GlobalRequestID& transferred_global_request_id, | |
| 72 bool is_renderer_initiated) OVERRIDE; | |
| 73 virtual void LoadIfNecessary() OVERRIDE; | |
| 74 virtual bool CanGoBack() const OVERRIDE; | |
| 75 virtual bool CanGoForward() const OVERRIDE; | |
| 76 virtual void GoBack() OVERRIDE; | |
| 77 virtual void GoForward() OVERRIDE; | |
| 78 virtual void GoToIndex(int index) OVERRIDE; | |
| 79 virtual void GoToOffset(int offset) OVERRIDE; | |
| 80 virtual void RemoveEntryAtIndex(int index) OVERRIDE; | |
| 81 virtual content::SessionStorageNamespace* | |
| 82 GetSessionStorageNamespace() const OVERRIDE; | |
| 83 virtual void SetMaxRestoredPageID(int32 max_id) OVERRIDE; | |
| 84 virtual int32 GetMaxRestoredPageID() const OVERRIDE; | |
| 85 virtual bool NeedsReload() const OVERRIDE; | |
| 86 virtual void CancelPendingReload() OVERRIDE; | |
| 87 virtual void ContinuePendingReload() OVERRIDE; | |
| 88 virtual bool IsInitialNavigation() OVERRIDE; | |
| 89 virtual void Reload(bool check_for_repost) OVERRIDE; | |
| 90 virtual void ReloadIgnoringCache(bool check_for_repost) OVERRIDE; | |
| 91 virtual void NotifyEntryChanged(const content::NavigationEntry* entry, | |
| 92 int index) OVERRIDE; | |
| 93 virtual void CopyStateFrom( | |
| 94 const content::NavigationController& source) OVERRIDE; | |
| 95 virtual void CopyStateFromAndPrune( | |
| 96 content::NavigationController* source) OVERRIDE; | |
| 97 virtual void PruneAllButActive() OVERRIDE; | |
| 98 | |
| 99 // Returns the index of the specified entry, or -1 if entry is not contained | |
| 100 // in this NavigationController. | |
| 101 int GetIndexOfEntry(const content::NavigationEntryImpl* entry) const; | |
| 102 | |
| 103 // Return the index of the entry with the corresponding instance and page_id, | |
| 104 // or -1 if not found. | |
| 105 int GetEntryIndexWithPageID(content::SiteInstance* instance, | |
| 106 int32 page_id) const; | |
| 107 | |
| 108 // Return the entry with the corresponding instance and page_id, or NULL if | |
| 109 // not found. | |
| 110 content::NavigationEntryImpl* GetEntryWithPageID( | |
| 111 content::SiteInstance* instance, | |
| 112 int32 page_id) const; | |
| 113 | |
| 114 // Transient entry ----------------------------------------------------------- | |
| 115 | |
| 116 // Adds an entry that is returned by GetActiveEntry(). The entry is | |
| 117 // transient: any navigation causes it to be removed and discarded. | |
| 118 // The NavigationController becomes the owner of |entry| and deletes it when | |
| 119 // it discards it. This is useful with interstitial page that need to be | |
| 120 // represented as an entry, but should go away when the user navigates away | |
| 121 // from them. | |
| 122 // Note that adding a transient entry does not change the active contents. | |
| 123 void AddTransientEntry(content::NavigationEntryImpl* entry); | |
| 124 | |
| 125 // WebContentsImpl ----------------------------------------------------------- | |
| 126 | |
| 127 WebContentsImpl* tab_contents() const { | |
| 128 // This currently returns the active tab contents which should be renamed to | |
| 129 // tab_contents. | |
| 130 return tab_contents_; | |
| 131 } | |
| 132 | |
| 133 // Called when a document has been loaded in a frame. | |
| 134 void DocumentLoadedInFrame(); | |
| 135 | |
| 136 // For use by WebContentsImpl ------------------------------------------------ | |
| 137 | |
| 138 // Handles updating the navigation state after the renderer has navigated. | |
| 139 // This is used by the WebContentsImpl. | |
| 140 // | |
| 141 // If a new entry is created, it will return true and will have filled the | |
| 142 // given details structure and broadcast the NOTIFY_NAV_ENTRY_COMMITTED | |
| 143 // notification. The caller can then use the details without worrying about | |
| 144 // listening for the notification. | |
| 145 // | |
| 146 // In the case that nothing has changed, the details structure is undefined | |
| 147 // and it will return false. | |
| 148 bool RendererDidNavigate(const ViewHostMsg_FrameNavigate_Params& params, | |
| 149 content::LoadCommittedDetails* details); | |
| 150 | |
| 151 // Notifies us that we just became active. This is used by the WebContentsImpl | |
| 152 // so that we know to load URLs that were pending as "lazy" loads. | |
| 153 void SetActive(bool is_active); | |
| 154 | |
| 155 // Returns true if the given URL would be an in-page navigation (i.e. only | |
| 156 // the reference fragment is different) from the "last committed entry". We do | |
| 157 // not compare it against the "active entry" since the active entry can be | |
| 158 // pending and in page navigations only happen on committed pages. If there | |
| 159 // is no last committed entry, then nothing will be in-page. | |
| 160 // | |
| 161 // Special note: if the URLs are the same, it does NOT count as an in-page | |
| 162 // navigation. Neither does an input URL that has no ref, even if the rest is | |
| 163 // the same. This may seem weird, but when we're considering whether a | |
| 164 // navigation happened without loading anything, the same URL would be a | |
| 165 // reload, while only a different ref would be in-page (pages can't clear | |
| 166 // refs without reload, only change to "#" which we don't count as empty). | |
| 167 bool IsURLInPageNavigation(const GURL& url) const; | |
| 168 | |
| 169 // Random data --------------------------------------------------------------- | |
| 170 | |
| 171 SSLManager* ssl_manager() { return &ssl_manager_; } | |
| 172 | |
| 173 // Maximum number of entries before we start removing entries from the front. | |
| 174 static void set_max_entry_count_for_testing(size_t max_entry_count) { | |
| 175 max_entry_count_for_testing_ = max_entry_count; | |
| 176 } | |
| 177 static size_t max_entry_count(); | |
| 178 | |
| 179 private: | |
| 180 class RestoreHelper; | |
| 181 friend class RestoreHelper; | |
| 182 friend class WebContentsImpl; // For invoking OnReservedPageIDRange. | |
| 183 | |
| 184 // Classifies the given renderer navigation (see the NavigationType enum). | |
| 185 content::NavigationType ClassifyNavigation( | |
| 186 const ViewHostMsg_FrameNavigate_Params& params) const; | |
| 187 | |
| 188 // Causes the controller to load the specified entry. The function assumes | |
| 189 // ownership of the pointer since it is put in the navigation list. | |
| 190 // NOTE: Do not pass an entry that the controller already owns! | |
| 191 void LoadEntry(content::NavigationEntryImpl* entry); | |
| 192 | |
| 193 // Handlers for the different types of navigation types. They will actually | |
| 194 // handle the navigations corresponding to the different NavClasses above. | |
| 195 // They will NOT broadcast the commit notification, that should be handled by | |
| 196 // the caller. | |
| 197 // | |
| 198 // RendererDidNavigateAutoSubframe is special, it may not actually change | |
| 199 // anything if some random subframe is loaded. It will return true if anything | |
| 200 // changed, or false if not. | |
| 201 // | |
| 202 // The functions taking |did_replace_entry| will fill into the given variable | |
| 203 // whether the last entry has been replaced or not. | |
| 204 // See LoadCommittedDetails.did_replace_entry. | |
| 205 void RendererDidNavigateToNewPage( | |
| 206 const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry); | |
| 207 void RendererDidNavigateToExistingPage( | |
| 208 const ViewHostMsg_FrameNavigate_Params& params); | |
| 209 void RendererDidNavigateToSamePage( | |
| 210 const ViewHostMsg_FrameNavigate_Params& params); | |
| 211 void RendererDidNavigateInPage( | |
| 212 const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry); | |
| 213 void RendererDidNavigateNewSubframe( | |
| 214 const ViewHostMsg_FrameNavigate_Params& params); | |
| 215 bool RendererDidNavigateAutoSubframe( | |
| 216 const ViewHostMsg_FrameNavigate_Params& params); | |
| 217 | |
| 218 // Helper function for code shared between Reload() and ReloadIgnoringCache(). | |
| 219 void ReloadInternal(bool check_for_repost, ReloadType reload_type); | |
| 220 | |
| 221 // Actually issues the navigation held in pending_entry. | |
| 222 void NavigateToPendingEntry(ReloadType reload_type); | |
| 223 | |
| 224 // Allows the derived class to issue notifications that a load has been | |
| 225 // committed. This will fill in the active entry to the details structure. | |
| 226 void NotifyNavigationEntryCommitted(content::LoadCommittedDetails* details); | |
| 227 | |
| 228 // Updates the virtual URL of an entry to match a new URL, for cases where | |
| 229 // the real renderer URL is derived from the virtual URL, like view-source: | |
| 230 void UpdateVirtualURLToURL(content::NavigationEntryImpl* entry, | |
| 231 const GURL& new_url); | |
| 232 | |
| 233 // Invoked after session/tab restore or cloning a tab. Resets the transition | |
| 234 // type of the entries, updates the max page id and creates the active | |
| 235 // contents. See RestoreFromState for a description of from_last_session. | |
| 236 void FinishRestore(int selected_index, bool from_last_session); | |
| 237 | |
| 238 // Inserts a new entry or replaces the current entry with a new one, removing | |
| 239 // all entries after it. The new entry will become the active one. | |
| 240 void InsertOrReplaceEntry(content::NavigationEntryImpl* entry, bool replace); | |
| 241 | |
| 242 // Removes the entry at |index|, as long as it is not the current entry. | |
| 243 void RemoveEntryAtIndexInternal(int index); | |
| 244 | |
| 245 // Discards the pending and transient entries. | |
| 246 void DiscardNonCommittedEntriesInternal(); | |
| 247 | |
| 248 // Discards the transient entry. | |
| 249 void DiscardTransientEntry(); | |
| 250 | |
| 251 // If we have the maximum number of entries, remove the oldest one in | |
| 252 // preparation to add another. | |
| 253 void PruneOldestEntryIfFull(); | |
| 254 | |
| 255 // Returns true if the navigation is redirect. | |
| 256 bool IsRedirect(const ViewHostMsg_FrameNavigate_Params& params); | |
| 257 | |
| 258 // Returns true if the navigation is likley to be automatic rather than | |
| 259 // user-initiated. | |
| 260 bool IsLikelyAutoNavigation(base::TimeTicks now); | |
| 261 | |
| 262 // Inserts up to |max_index| entries from |source| into this. This does NOT | |
| 263 // adjust any of the members that reference entries_ | |
| 264 // (last_committed_entry_index_, pending_entry_index_ or | |
| 265 // transient_entry_index_). | |
| 266 void InsertEntriesFrom(const NavigationControllerImpl& source, int max_index); | |
| 267 | |
| 268 // --------------------------------------------------------------------------- | |
| 269 | |
| 270 // The user browser context associated with this controller. | |
| 271 content::BrowserContext* browser_context_; | |
| 272 | |
| 273 // List of NavigationEntry for this tab | |
| 274 typedef std::vector<linked_ptr<content::NavigationEntryImpl> > | |
| 275 NavigationEntries; | |
| 276 NavigationEntries entries_; | |
| 277 | |
| 278 // An entry we haven't gotten a response for yet. This will be discarded | |
| 279 // when we navigate again. It's used only so we know what the currently | |
| 280 // displayed tab is. | |
| 281 // | |
| 282 // This may refer to an item in the entries_ list if the pending_entry_index_ | |
| 283 // == -1, or it may be its own entry that should be deleted. Be careful with | |
| 284 // the memory management. | |
| 285 content::NavigationEntryImpl* pending_entry_; | |
| 286 | |
| 287 // currently visible entry | |
| 288 int last_committed_entry_index_; | |
| 289 | |
| 290 // index of pending entry if it is in entries_, or -1 if pending_entry_ is a | |
| 291 // new entry (created by LoadURL). | |
| 292 int pending_entry_index_; | |
| 293 | |
| 294 // The index for the entry that is shown until a navigation occurs. This is | |
| 295 // used for interstitial pages. -1 if there are no such entry. | |
| 296 // Note that this entry really appears in the list of entries, but only | |
| 297 // temporarily (until the next navigation). Any index pointing to an entry | |
| 298 // after the transient entry will become invalid if you navigate forward. | |
| 299 int transient_entry_index_; | |
| 300 | |
| 301 // The tab contents associated with the controller. Possibly NULL during | |
| 302 // setup. | |
| 303 WebContentsImpl* tab_contents_; | |
| 304 | |
| 305 // The max restored page ID in this controller, if it was restored. We must | |
| 306 // store this so that WebContentsImpl can tell any renderer in charge of one | |
| 307 // of the restored entries to update its max page ID. | |
| 308 int32 max_restored_page_id_; | |
| 309 | |
| 310 // Manages the SSL security UI | |
| 311 SSLManager ssl_manager_; | |
| 312 | |
| 313 // Whether we need to be reloaded when made active. | |
| 314 bool needs_reload_; | |
| 315 | |
| 316 // The time ticks at which the last document was loaded. | |
| 317 base::TimeTicks last_document_loaded_; | |
| 318 | |
| 319 // The session storage id that any (indirectly) owned RenderView should use. | |
| 320 scoped_refptr<SessionStorageNamespaceImpl> session_storage_namespace_; | |
| 321 | |
| 322 // The maximum number of entries that a navigation controller can store. | |
| 323 static size_t max_entry_count_for_testing_; | |
| 324 | |
| 325 // If a repost is pending, its type (RELOAD or RELOAD_IGNORING_CACHE), | |
| 326 // NO_RELOAD otherwise. | |
| 327 ReloadType pending_reload_; | |
| 328 | |
| 329 DISALLOW_COPY_AND_ASSIGN(NavigationControllerImpl); | |
| 330 }; | |
| 331 | |
| 332 #endif // CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_IMPL_H_ | |
| OLD | NEW |