OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_impl.h" | 5 #include "content/browser/tab_contents/navigation_controller_impl.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" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "content/browser/browser_url_handler.h" | 13 #include "content/browser/browser_url_handler.h" |
14 #include "content/browser/child_process_security_policy.h" | 14 #include "content/browser/child_process_security_policy.h" |
15 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 15 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
16 #include "content/browser/renderer_host/render_view_host.h" // Temporary | 16 #include "content/browser/renderer_host/render_view_host.h" // Temporary |
17 #include "content/browser/site_instance.h" | 17 #include "content/browser/site_instance_impl.h" |
18 #include "content/browser/tab_contents/interstitial_page.h" | 18 #include "content/browser/tab_contents/interstitial_page.h" |
19 #include "content/browser/tab_contents/navigation_entry_impl.h" | 19 #include "content/browser/tab_contents/navigation_entry_impl.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
23 #include "content/public/browser/invalidate_type.h" | 23 #include "content/public/browser/invalidate_type.h" |
24 #include "content/public/browser/navigation_details.h" | 24 #include "content/public/browser/navigation_details.h" |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
27 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 ReloadInternal(false, pending_reload_); | 284 ReloadInternal(false, pending_reload_); |
285 pending_reload_ = NO_RELOAD; | 285 pending_reload_ = NO_RELOAD; |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 bool NavigationControllerImpl::IsInitialNavigation() { | 289 bool NavigationControllerImpl::IsInitialNavigation() { |
290 return last_document_loaded_.is_null(); | 290 return last_document_loaded_.is_null(); |
291 } | 291 } |
292 | 292 |
293 NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID( | 293 NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID( |
294 SiteInstance* instance, int32 page_id) const { | 294 content::SiteInstance* instance, |
| 295 int32 page_id) const { |
295 int index = GetEntryIndexWithPageID(instance, page_id); | 296 int index = GetEntryIndexWithPageID(instance, page_id); |
296 return (index != -1) ? entries_[index].get() : NULL; | 297 return (index != -1) ? entries_[index].get() : NULL; |
297 } | 298 } |
298 | 299 |
299 void NavigationControllerImpl::LoadEntry(NavigationEntryImpl* entry) { | 300 void NavigationControllerImpl::LoadEntry(NavigationEntryImpl* entry) { |
300 // Don't navigate to URLs disabled by policy. This prevents showing the URL | 301 // Don't navigate to URLs disabled by policy. This prevents showing the URL |
301 // on the Omnibar when it is also going to be blocked by | 302 // on the Omnibar when it is also going to be blocked by |
302 // ChildProcessSecurityPolicy::CanRequestURL. | 303 // ChildProcessSecurityPolicy::CanRequestURL. |
303 ChildProcessSecurityPolicy *policy = | 304 ChildProcessSecurityPolicy *policy = |
304 ChildProcessSecurityPolicy::GetInstance(); | 305 ChildProcessSecurityPolicy::GetInstance(); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 temp.append(base::IntToString(params.frame_id)); | 718 temp.append(base::IntToString(params.frame_id)); |
718 temp.append("#ids"); | 719 temp.append("#ids"); |
719 for (int i = 0; i < static_cast<int>(entries_.size()); ++i) { | 720 for (int i = 0; i < static_cast<int>(entries_.size()); ++i) { |
720 // Append entry metadata (e.g., 3_7x): | 721 // Append entry metadata (e.g., 3_7x): |
721 // 3: page_id | 722 // 3: page_id |
722 // 7: SiteInstance ID, or N for null | 723 // 7: SiteInstance ID, or N for null |
723 // x: appended if not from the current SiteInstance | 724 // x: appended if not from the current SiteInstance |
724 temp.append(base::IntToString(entries_[i]->GetPageID())); | 725 temp.append(base::IntToString(entries_[i]->GetPageID())); |
725 temp.append("_"); | 726 temp.append("_"); |
726 if (entries_[i]->site_instance()) | 727 if (entries_[i]->site_instance()) |
727 temp.append(base::IntToString(entries_[i]->site_instance()->id())); | 728 temp.append(base::IntToString(entries_[i]->site_instance()->GetId())); |
728 else | 729 else |
729 temp.append("N"); | 730 temp.append("N"); |
730 if (entries_[i]->site_instance() != tab_contents_->GetSiteInstance()) | 731 if (entries_[i]->site_instance() != tab_contents_->GetSiteInstance()) |
731 temp.append("x"); | 732 temp.append("x"); |
732 temp.append(","); | 733 temp.append(","); |
733 } | 734 } |
734 GURL url(temp); | 735 GURL url(temp); |
735 tab_contents_->GetRenderViewHost()->Send(new ViewMsg_TempCrashWithData(url))
; | 736 tab_contents_->GetRenderViewHost()->Send(new ViewMsg_TempCrashWithData(url))
; |
736 return content::NAVIGATION_TYPE_NAV_IGNORE; | 737 return content::NAVIGATION_TYPE_NAV_IGNORE; |
737 } | 738 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 void NavigationControllerImpl::CopyStateFromAndPrune( | 1001 void NavigationControllerImpl::CopyStateFromAndPrune( |
1001 NavigationController* temp) { | 1002 NavigationController* temp) { |
1002 NavigationControllerImpl* source = | 1003 NavigationControllerImpl* source = |
1003 static_cast<NavigationControllerImpl*>(temp); | 1004 static_cast<NavigationControllerImpl*>(temp); |
1004 // The SiteInstance and page_id of the last committed entry needs to be | 1005 // The SiteInstance and page_id of the last committed entry needs to be |
1005 // remembered at this point, in case there is only one committed entry | 1006 // remembered at this point, in case there is only one committed entry |
1006 // and it is pruned. We use a scoped_refptr to ensure the SiteInstance | 1007 // and it is pruned. We use a scoped_refptr to ensure the SiteInstance |
1007 // can't be freed during this time period. | 1008 // can't be freed during this time period. |
1008 NavigationEntryImpl* last_committed = | 1009 NavigationEntryImpl* last_committed = |
1009 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); | 1010 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); |
1010 scoped_refptr<SiteInstance> site_instance( | 1011 scoped_refptr<content::SiteInstance> site_instance( |
1011 last_committed ? last_committed->site_instance() : NULL); | 1012 last_committed ? last_committed->site_instance() : NULL); |
1012 int32 minimum_page_id = last_committed ? last_committed->GetPageID() : -1; | 1013 int32 minimum_page_id = last_committed ? last_committed->GetPageID() : -1; |
1013 int32 max_page_id = last_committed ? | 1014 int32 max_page_id = last_committed ? |
1014 tab_contents_->GetMaxPageIDForSiteInstance(site_instance.get()) : -1; | 1015 tab_contents_->GetMaxPageIDForSiteInstance(site_instance.get()) : -1; |
1015 | 1016 |
1016 // This code is intended for use when the last entry is the active entry. | 1017 // This code is intended for use when the last entry is the active entry. |
1017 DCHECK( | 1018 DCHECK( |
1018 (transient_entry_index_ != -1 && | 1019 (transient_entry_index_ != -1 && |
1019 transient_entry_index_ == GetEntryCount() - 1) || | 1020 transient_entry_index_ == GetEntryCount() - 1) || |
1020 (pending_entry_ && (pending_entry_index_ == -1 || | 1021 (pending_entry_ && (pending_entry_index_ == -1 || |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 void NavigationControllerImpl::DiscardTransientEntry() { | 1332 void NavigationControllerImpl::DiscardTransientEntry() { |
1332 if (transient_entry_index_ == -1) | 1333 if (transient_entry_index_ == -1) |
1333 return; | 1334 return; |
1334 entries_.erase(entries_.begin() + transient_entry_index_); | 1335 entries_.erase(entries_.begin() + transient_entry_index_); |
1335 if (last_committed_entry_index_ > transient_entry_index_) | 1336 if (last_committed_entry_index_ > transient_entry_index_) |
1336 last_committed_entry_index_--; | 1337 last_committed_entry_index_--; |
1337 transient_entry_index_ = -1; | 1338 transient_entry_index_ = -1; |
1338 } | 1339 } |
1339 | 1340 |
1340 int NavigationControllerImpl::GetEntryIndexWithPageID( | 1341 int NavigationControllerImpl::GetEntryIndexWithPageID( |
1341 SiteInstance* instance, int32 page_id) const { | 1342 content::SiteInstance* instance, int32 page_id) const { |
1342 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { | 1343 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { |
1343 if ((entries_[i]->site_instance() == instance) && | 1344 if ((entries_[i]->site_instance() == instance) && |
1344 (entries_[i]->GetPageID() == page_id)) | 1345 (entries_[i]->GetPageID() == page_id)) |
1345 return i; | 1346 return i; |
1346 } | 1347 } |
1347 return -1; | 1348 return -1; |
1348 } | 1349 } |
1349 | 1350 |
1350 NavigationEntry* NavigationControllerImpl::GetTransientEntry() const { | 1351 NavigationEntry* NavigationControllerImpl::GetTransientEntry() const { |
1351 if (transient_entry_index_ == -1) | 1352 if (transient_entry_index_ == -1) |
1352 return NULL; | 1353 return NULL; |
1353 return entries_[transient_entry_index_].get(); | 1354 return entries_[transient_entry_index_].get(); |
1354 } | 1355 } |
1355 | 1356 |
1356 void NavigationControllerImpl::InsertEntriesFrom( | 1357 void NavigationControllerImpl::InsertEntriesFrom( |
1357 const NavigationControllerImpl& source, | 1358 const NavigationControllerImpl& source, |
1358 int max_index) { | 1359 int max_index) { |
1359 DCHECK_LE(max_index, source.GetEntryCount()); | 1360 DCHECK_LE(max_index, source.GetEntryCount()); |
1360 size_t insert_index = 0; | 1361 size_t insert_index = 0; |
1361 for (int i = 0; i < max_index; i++) { | 1362 for (int i = 0; i < max_index; i++) { |
1362 // When cloning a tab, copy all entries except interstitial pages | 1363 // When cloning a tab, copy all entries except interstitial pages |
1363 if (source.entries_[i].get()->GetPageType() != | 1364 if (source.entries_[i].get()->GetPageType() != |
1364 content::PAGE_TYPE_INTERSTITIAL) { | 1365 content::PAGE_TYPE_INTERSTITIAL) { |
1365 entries_.insert(entries_.begin() + insert_index++, | 1366 entries_.insert(entries_.begin() + insert_index++, |
1366 linked_ptr<NavigationEntryImpl>( | 1367 linked_ptr<NavigationEntryImpl>( |
1367 new NavigationEntryImpl(*source.entries_[i]))); | 1368 new NavigationEntryImpl(*source.entries_[i]))); |
1368 } | 1369 } |
1369 } | 1370 } |
1370 } | 1371 } |
OLD | NEW |