Chromium Code Reviews| 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 #include "content/browser/tab_contents/navigation_controller.h" | 5 #include "content/browser/tab_contents/navigation_controller.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" // Temporary | 9 #include "base/string_number_conversions.h" // Temporary |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 26 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
| 28 #include "content/public/common/content_constants.h" | 28 #include "content/public/common/content_constants.h" |
| 29 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
| 30 #include "net/base/mime_util.h" | 30 #include "net/base/mime_util.h" |
| 31 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
| 32 #include "webkit/glue/webkit_glue.h" | 32 #include "webkit/glue/webkit_glue.h" |
| 33 | 33 |
| 34 using content::BrowserContext; | |
| 34 using content::GlobalRequestID; | 35 using content::GlobalRequestID; |
| 35 using content::NavigationEntry; | 36 using content::NavigationEntry; |
| 36 using content::NavigationEntryImpl; | 37 using content::NavigationEntryImpl; |
| 37 using content::UserMetricsAction; | 38 using content::UserMetricsAction; |
| 38 using content::WebContents; | 39 using content::WebContents; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 const int kInvalidateAll = 0xFFFFFFFF; | 43 const int kInvalidateAll = 0xFFFFFFFF; |
| 43 | 44 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 } // namespace | 109 } // namespace |
| 109 | 110 |
| 110 // NavigationController --------------------------------------------------- | 111 // NavigationController --------------------------------------------------- |
| 111 | 112 |
| 112 const size_t kMaxEntryCountForTestingNotSet = -1; | 113 const size_t kMaxEntryCountForTestingNotSet = -1; |
| 113 | 114 |
| 114 // static | 115 // static |
| 115 size_t NavigationController::max_entry_count_for_testing_ = | 116 size_t NavigationController::max_entry_count_for_testing_ = |
| 116 kMaxEntryCountForTestingNotSet; | 117 kMaxEntryCountForTestingNotSet; |
| 117 | 118 |
| 119 // Should Reload check for post data? The default is true, but is set to false | |
| 120 // when testing. | |
| 121 static bool g_check_for_repost = true; | |
| 122 | |
| 123 namespace content { | |
| 118 // static | 124 // static |
| 119 bool NavigationController::check_for_repost_ = true; | 125 NavigationEntry* NavigationController::CreateNavigationEntry( |
| 120 | |
| 121 // static | |
| 122 NavigationEntry* content::NavigationController::CreateNavigationEntry( | |
| 123 const GURL& url, | 126 const GURL& url, |
| 124 const content::Referrer& referrer, | 127 const Referrer& referrer, |
| 125 content::PageTransition transition, | 128 PageTransition transition, |
| 126 bool is_renderer_initiated, | 129 bool is_renderer_initiated, |
| 127 const std::string& extra_headers, | 130 const std::string& extra_headers, |
| 128 content::BrowserContext* browser_context) { | 131 BrowserContext* browser_context) { |
| 129 // Allow the browser URL handler to rewrite the URL. This will, for example, | 132 // Allow the browser URL handler to rewrite the URL. This will, for example, |
| 130 // remove "view-source:" from the beginning of the URL to get the URL that | 133 // remove "view-source:" from the beginning of the URL to get the URL that |
| 131 // will actually be loaded. This real URL won't be shown to the user, just | 134 // will actually be loaded. This real URL won't be shown to the user, just |
| 132 // used internally. | 135 // used internally. |
| 133 GURL loaded_url(url); | 136 GURL loaded_url(url); |
| 134 bool reverse_on_redirect = false; | 137 bool reverse_on_redirect = false; |
| 135 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 138 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 136 &loaded_url, browser_context, &reverse_on_redirect); | 139 &loaded_url, browser_context, &reverse_on_redirect); |
| 137 | 140 |
| 138 NavigationEntryImpl* entry = new NavigationEntryImpl( | 141 NavigationEntryImpl* entry = new NavigationEntryImpl( |
| 139 NULL, // The site instance for tabs is sent on navigation | 142 NULL, // The site instance for tabs is sent on navigation |
| 140 // (TabContents::GetSiteInstance). | 143 // (TabContents::GetSiteInstance). |
| 141 -1, | 144 -1, |
| 142 loaded_url, | 145 loaded_url, |
| 143 referrer, | 146 referrer, |
| 144 string16(), | 147 string16(), |
| 145 transition, | 148 transition, |
| 146 is_renderer_initiated); | 149 is_renderer_initiated); |
| 147 entry->SetVirtualURL(url); | 150 entry->SetVirtualURL(url); |
| 148 entry->set_user_typed_url(url); | 151 entry->set_user_typed_url(url); |
| 149 entry->set_update_virtual_url_with_url(reverse_on_redirect); | 152 entry->set_update_virtual_url_with_url(reverse_on_redirect); |
| 150 entry->set_extra_headers(extra_headers); | 153 entry->set_extra_headers(extra_headers); |
| 151 return entry; | 154 return entry; |
| 152 } | 155 } |
| 153 | 156 |
| 157 // static | |
| 158 void NavigationController::DisablePromptOnRepost() { | |
|
Jói
2012/01/04 11:06:33
Possible follow-up: Should this be DisablePromptO
| |
| 159 g_check_for_repost = false; | |
| 160 } | |
| 161 | |
| 162 } // namespace content | |
| 163 | |
| 154 NavigationController::NavigationController( | 164 NavigationController::NavigationController( |
| 155 TabContents* contents, | 165 TabContents* contents, |
| 156 content::BrowserContext* browser_context, | 166 BrowserContext* browser_context, |
| 157 SessionStorageNamespace* session_storage_namespace) | 167 SessionStorageNamespace* session_storage_namespace) |
| 158 : browser_context_(browser_context), | 168 : browser_context_(browser_context), |
| 159 pending_entry_(NULL), | 169 pending_entry_(NULL), |
| 160 last_committed_entry_index_(-1), | 170 last_committed_entry_index_(-1), |
| 161 pending_entry_index_(-1), | 171 pending_entry_index_(-1), |
| 162 transient_entry_index_(-1), | 172 transient_entry_index_(-1), |
| 163 tab_contents_(contents), | 173 tab_contents_(contents), |
| 164 max_restored_page_id_(-1), | 174 max_restored_page_id_(-1), |
| 165 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), | 175 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), |
| 166 needs_reload_(false), | 176 needs_reload_(false), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 179 content::NotificationService::current()->Notify( | 189 content::NotificationService::current()->Notify( |
| 180 content::NOTIFICATION_TAB_CLOSED, | 190 content::NOTIFICATION_TAB_CLOSED, |
| 181 content::Source<content::NavigationController>(this), | 191 content::Source<content::NavigationController>(this), |
| 182 content::NotificationService::NoDetails()); | 192 content::NotificationService::NoDetails()); |
| 183 } | 193 } |
| 184 | 194 |
| 185 WebContents* NavigationController::GetWebContents() const { | 195 WebContents* NavigationController::GetWebContents() const { |
| 186 return tab_contents_; | 196 return tab_contents_; |
| 187 } | 197 } |
| 188 | 198 |
| 189 content::BrowserContext* NavigationController::GetBrowserContext() const { | 199 BrowserContext* NavigationController::GetBrowserContext() const { |
| 190 return browser_context_; | 200 return browser_context_; |
| 191 } | 201 } |
| 192 | 202 |
| 203 void NavigationController::SetBrowserContext(BrowserContext* browser_context) { | |
| 204 browser_context_ = browser_context; | |
| 205 } | |
| 206 | |
| 193 void NavigationController::Restore( | 207 void NavigationController::Restore( |
| 194 int selected_navigation, | 208 int selected_navigation, |
| 195 bool from_last_session, | 209 bool from_last_session, |
| 196 std::vector<NavigationEntry*>* entries) { | 210 std::vector<NavigationEntry*>* entries) { |
| 197 // Verify that this controller is unused and that the input is valid. | 211 // Verify that this controller is unused and that the input is valid. |
| 198 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); | 212 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); |
| 199 DCHECK(selected_navigation >= 0 && | 213 DCHECK(selected_navigation >= 0 && |
| 200 selected_navigation < static_cast<int>(entries->size())); | 214 selected_navigation < static_cast<int>(entries->size())); |
| 201 | 215 |
| 202 needs_reload_ = true; | 216 needs_reload_ = true; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 225 return; | 239 return; |
| 226 | 240 |
| 227 DiscardNonCommittedEntriesInternal(); | 241 DiscardNonCommittedEntriesInternal(); |
| 228 int current_index = GetCurrentEntryIndex(); | 242 int current_index = GetCurrentEntryIndex(); |
| 229 // If we are no where, then we can't reload. TODO(darin): We should add a | 243 // If we are no where, then we can't reload. TODO(darin): We should add a |
| 230 // CanReload method. | 244 // CanReload method. |
| 231 if (current_index == -1) { | 245 if (current_index == -1) { |
| 232 return; | 246 return; |
| 233 } | 247 } |
| 234 | 248 |
| 235 if (check_for_repost_ && check_for_repost && | 249 if (g_check_for_repost && check_for_repost && |
| 236 GetEntryAtIndex(current_index)->GetHasPostData()) { | 250 GetEntryAtIndex(current_index)->GetHasPostData()) { |
| 237 // The user is asking to reload a page with POST data. Prompt to make sure | 251 // The user is asking to reload a page with POST data. Prompt to make sure |
| 238 // they really want to do this. If they do, the dialog will call us back | 252 // they really want to do this. If they do, the dialog will call us back |
| 239 // with check_for_repost = false. | 253 // with check_for_repost = false. |
| 240 content::NotificationService::current()->Notify( | 254 content::NotificationService::current()->Notify( |
| 241 content::NOTIFICATION_REPOST_WARNING_SHOWN, | 255 content::NOTIFICATION_REPOST_WARNING_SHOWN, |
| 242 content::Source<content::NavigationController>(this), | 256 content::Source<content::NavigationController>(this), |
| 243 content::NotificationService::NoDetails()); | 257 content::NotificationService::NoDetails()); |
| 244 | 258 |
| 245 pending_reload_ = reload_type; | 259 pending_reload_ = reload_type; |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 return (i == entries_.end()) ? -1 : static_cast<int>(i - entries_.begin()); | 964 return (i == entries_.end()) ? -1 : static_cast<int>(i - entries_.begin()); |
| 951 } | 965 } |
| 952 | 966 |
| 953 bool NavigationController::IsURLInPageNavigation(const GURL& url) const { | 967 bool NavigationController::IsURLInPageNavigation(const GURL& url) const { |
| 954 NavigationEntry* last_committed = GetLastCommittedEntry(); | 968 NavigationEntry* last_committed = GetLastCommittedEntry(); |
| 955 if (!last_committed) | 969 if (!last_committed) |
| 956 return false; | 970 return false; |
| 957 return AreURLsInPageNavigation(last_committed->GetURL(), url); | 971 return AreURLsInPageNavigation(last_committed->GetURL(), url); |
| 958 } | 972 } |
| 959 | 973 |
| 960 void NavigationController::CopyStateFrom(const NavigationController& source) { | 974 void NavigationController::CopyStateFrom( |
| 975 const content::NavigationController& temp) { | |
| 976 const NavigationController& source = | |
| 977 static_cast<const NavigationController&>(temp); | |
| 961 // Verify that we look new. | 978 // Verify that we look new. |
| 962 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); | 979 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); |
| 963 | 980 |
| 964 if (source.GetEntryCount() == 0) | 981 if (source.GetEntryCount() == 0) |
| 965 return; // Nothing new to do. | 982 return; // Nothing new to do. |
| 966 | 983 |
| 967 needs_reload_ = true; | 984 needs_reload_ = true; |
| 968 InsertEntriesFrom(source, source.GetEntryCount()); | 985 InsertEntriesFrom(source, source.GetEntryCount()); |
| 969 | 986 |
| 970 session_storage_namespace_ = source.session_storage_namespace_->Clone(); | 987 session_storage_namespace_ = source.session_storage_namespace_->Clone(); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1227 // notification below instead. | 1244 // notification below instead. |
| 1228 tab_contents_->NotifyNavigationStateChanged(kInvalidateAll); | 1245 tab_contents_->NotifyNavigationStateChanged(kInvalidateAll); |
| 1229 | 1246 |
| 1230 content::NotificationService::current()->Notify( | 1247 content::NotificationService::current()->Notify( |
| 1231 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 1248 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 1232 content::Source<content::NavigationController>(this), | 1249 content::Source<content::NavigationController>(this), |
| 1233 notification_details); | 1250 notification_details); |
| 1234 } | 1251 } |
| 1235 | 1252 |
| 1236 // static | 1253 // static |
| 1237 void NavigationController::DisablePromptOnRepost() { | |
| 1238 check_for_repost_ = false; | |
| 1239 } | |
| 1240 | |
| 1241 // static | |
| 1242 size_t NavigationController::max_entry_count() { | 1254 size_t NavigationController::max_entry_count() { |
| 1243 if (max_entry_count_for_testing_ != kMaxEntryCountForTestingNotSet) | 1255 if (max_entry_count_for_testing_ != kMaxEntryCountForTestingNotSet) |
| 1244 return max_entry_count_for_testing_; | 1256 return max_entry_count_for_testing_; |
| 1245 return content::kMaxSessionHistoryEntries; | 1257 return content::kMaxSessionHistoryEntries; |
| 1246 } | 1258 } |
| 1247 | 1259 |
| 1248 void NavigationController::SetActive(bool is_active) { | 1260 void NavigationController::SetActive(bool is_active) { |
| 1249 if (is_active && needs_reload_) | 1261 if (is_active && needs_reload_) |
| 1250 LoadIfNecessary(); | 1262 LoadIfNecessary(); |
| 1251 } | 1263 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1324 for (int i = 0; i < max_index; i++) { | 1336 for (int i = 0; i < max_index; i++) { |
| 1325 // When cloning a tab, copy all entries except interstitial pages | 1337 // When cloning a tab, copy all entries except interstitial pages |
| 1326 if (source.entries_[i].get()->GetPageType() != | 1338 if (source.entries_[i].get()->GetPageType() != |
| 1327 content::PAGE_TYPE_INTERSTITIAL) { | 1339 content::PAGE_TYPE_INTERSTITIAL) { |
| 1328 entries_.insert(entries_.begin() + insert_index++, | 1340 entries_.insert(entries_.begin() + insert_index++, |
| 1329 linked_ptr<NavigationEntryImpl>( | 1341 linked_ptr<NavigationEntryImpl>( |
| 1330 new NavigationEntryImpl(*source.entries_[i]))); | 1342 new NavigationEntryImpl(*source.entries_[i]))); |
| 1331 } | 1343 } |
| 1332 } | 1344 } |
| 1333 } | 1345 } |
| OLD | NEW |