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" |
28 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
29 #include "content/public/common/content_constants.h" | 29 #include "content/public/common/content_constants.h" |
30 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
31 #include "net/base/mime_util.h" | 31 #include "net/base/mime_util.h" |
32 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
33 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
34 | 34 |
35 using content::BrowserContext; | 35 using content::BrowserContext; |
36 using content::GlobalRequestID; | 36 using content::GlobalRequestID; |
37 using content::NavigationController; | 37 using content::NavigationController; |
38 using content::NavigationEntry; | 38 using content::NavigationEntry; |
39 using content::NavigationEntryImpl; | 39 using content::NavigationEntryImpl; |
| 40 using content::SiteInstance; |
40 using content::UserMetricsAction; | 41 using content::UserMetricsAction; |
41 using content::WebContents; | 42 using content::WebContents; |
42 | 43 |
43 namespace { | 44 namespace { |
44 | 45 |
45 const int kInvalidateAll = 0xFFFFFFFF; | 46 const int kInvalidateAll = 0xFFFFFFFF; |
46 | 47 |
47 // Invoked when entries have been pruned, or removed. For example, if the | 48 // Invoked when entries have been pruned, or removed. For example, if the |
48 // current entries are [google, digg, yahoo], with the current entry google, | 49 // current entries are [google, digg, yahoo], with the current entry google, |
49 // and the user types in cnet, then digg and yahoo are pruned. | 50 // and the user types in cnet, then digg and yahoo are pruned. |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 ReloadInternal(false, pending_reload_); | 285 ReloadInternal(false, pending_reload_); |
285 pending_reload_ = NO_RELOAD; | 286 pending_reload_ = NO_RELOAD; |
286 } | 287 } |
287 } | 288 } |
288 | 289 |
289 bool NavigationControllerImpl::IsInitialNavigation() { | 290 bool NavigationControllerImpl::IsInitialNavigation() { |
290 return last_document_loaded_.is_null(); | 291 return last_document_loaded_.is_null(); |
291 } | 292 } |
292 | 293 |
293 NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID( | 294 NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID( |
294 SiteInstance* instance, int32 page_id) const { | 295 SiteInstance* instance, 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 // the URL. | 807 // the URL. |
807 update_virtual_url = true; | 808 update_virtual_url = true; |
808 } | 809 } |
809 | 810 |
810 new_entry->SetURL(params.url); | 811 new_entry->SetURL(params.url); |
811 if (update_virtual_url) | 812 if (update_virtual_url) |
812 UpdateVirtualURLToURL(new_entry, params.url); | 813 UpdateVirtualURLToURL(new_entry, params.url); |
813 new_entry->SetReferrer(params.referrer); | 814 new_entry->SetReferrer(params.referrer); |
814 new_entry->SetPageID(params.page_id); | 815 new_entry->SetPageID(params.page_id); |
815 new_entry->SetTransitionType(params.transition); | 816 new_entry->SetTransitionType(params.transition); |
816 new_entry->set_site_instance(tab_contents_->GetSiteInstance()); | 817 new_entry->set_site_instance( |
| 818 static_cast<SiteInstanceImpl*>(tab_contents_->GetSiteInstance())); |
817 new_entry->SetHasPostData(params.is_post); | 819 new_entry->SetHasPostData(params.is_post); |
818 | 820 |
819 InsertOrReplaceEntry(new_entry, *did_replace_entry); | 821 InsertOrReplaceEntry(new_entry, *did_replace_entry); |
820 } | 822 } |
821 | 823 |
822 void NavigationControllerImpl::RendererDidNavigateToExistingPage( | 824 void NavigationControllerImpl::RendererDidNavigateToExistingPage( |
823 const ViewHostMsg_FrameNavigate_Params& params) { | 825 const ViewHostMsg_FrameNavigate_Params& params) { |
824 // We should only get here for main frame navigations. | 826 // We should only get here for main frame navigations. |
825 DCHECK(content::PageTransitionIsMainFrame(params.transition)); | 827 DCHECK(content::PageTransitionIsMainFrame(params.transition)); |
826 | 828 |
827 // This is a back/forward navigation. The existing page for the ID is | 829 // This is a back/forward navigation. The existing page for the ID is |
828 // guaranteed to exist by ClassifyNavigation, and we just need to update it | 830 // guaranteed to exist by ClassifyNavigation, and we just need to update it |
829 // with new information from the renderer. | 831 // with new information from the renderer. |
830 int entry_index = GetEntryIndexWithPageID(tab_contents_->GetSiteInstance(), | 832 int entry_index = GetEntryIndexWithPageID(tab_contents_->GetSiteInstance(), |
831 params.page_id); | 833 params.page_id); |
832 DCHECK(entry_index >= 0 && | 834 DCHECK(entry_index >= 0 && |
833 entry_index < static_cast<int>(entries_.size())); | 835 entry_index < static_cast<int>(entries_.size())); |
834 NavigationEntryImpl* entry = entries_[entry_index].get(); | 836 NavigationEntryImpl* entry = entries_[entry_index].get(); |
835 | 837 |
836 // The URL may have changed due to redirects. The site instance will normally | 838 // The URL may have changed due to redirects. The site instance will normally |
837 // be the same except during session restore, when no site instance will be | 839 // be the same except during session restore, when no site instance will be |
838 // assigned. | 840 // assigned. |
839 entry->SetURL(params.url); | 841 entry->SetURL(params.url); |
840 if (entry->update_virtual_url_with_url()) | 842 if (entry->update_virtual_url_with_url()) |
841 UpdateVirtualURLToURL(entry, params.url); | 843 UpdateVirtualURLToURL(entry, params.url); |
842 DCHECK(entry->site_instance() == NULL || | 844 DCHECK(entry->site_instance() == NULL || |
843 entry->site_instance() == tab_contents_->GetSiteInstance()); | 845 entry->site_instance() == tab_contents_->GetSiteInstance()); |
844 entry->set_site_instance(tab_contents_->GetSiteInstance()); | 846 entry->set_site_instance( |
| 847 static_cast<SiteInstanceImpl*>(tab_contents_->GetSiteInstance())); |
845 | 848 |
846 entry->SetHasPostData(params.is_post); | 849 entry->SetHasPostData(params.is_post); |
847 | 850 |
848 // The entry we found in the list might be pending if the user hit | 851 // The entry we found in the list might be pending if the user hit |
849 // back/forward/reload. This load should commit it (since it's already in the | 852 // back/forward/reload. This load should commit it (since it's already in the |
850 // list, we can just discard the pending pointer). We should also discard the | 853 // list, we can just discard the pending pointer). We should also discard the |
851 // pending entry if it corresponds to a different navigation, since that one | 854 // pending entry if it corresponds to a different navigation, since that one |
852 // is now likely canceled. If it is not canceled, we will treat it as a new | 855 // is now likely canceled. If it is not canceled, we will treat it as a new |
853 // navigation when it arrives, which is also ok. | 856 // navigation when it arrives, which is also ok. |
854 // | 857 // |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 | 1244 |
1242 if (!tab_contents_->NavigateToPendingEntry(reload_type)) | 1245 if (!tab_contents_->NavigateToPendingEntry(reload_type)) |
1243 DiscardNonCommittedEntries(); | 1246 DiscardNonCommittedEntries(); |
1244 | 1247 |
1245 // If the entry is being restored and doesn't have a SiteInstance yet, fill | 1248 // If the entry is being restored and doesn't have a SiteInstance yet, fill |
1246 // it in now that we know. This allows us to find the entry when it commits. | 1249 // it in now that we know. This allows us to find the entry when it commits. |
1247 // This works for browser-initiated navigations. We handle renderer-initiated | 1250 // This works for browser-initiated navigations. We handle renderer-initiated |
1248 // navigations to restored entries in TabContents::OnGoToEntryAtOffset. | 1251 // navigations to restored entries in TabContents::OnGoToEntryAtOffset. |
1249 if (pending_entry_ && !pending_entry_->site_instance() && | 1252 if (pending_entry_ && !pending_entry_->site_instance() && |
1250 pending_entry_->restore_type() != NavigationEntryImpl::RESTORE_NONE) { | 1253 pending_entry_->restore_type() != NavigationEntryImpl::RESTORE_NONE) { |
1251 pending_entry_->set_site_instance(tab_contents_->GetPendingSiteInstance()); | 1254 pending_entry_->set_site_instance(static_cast<SiteInstanceImpl*>( |
| 1255 tab_contents_->GetPendingSiteInstance())); |
1252 pending_entry_->set_restore_type(NavigationEntryImpl::RESTORE_NONE); | 1256 pending_entry_->set_restore_type(NavigationEntryImpl::RESTORE_NONE); |
1253 } | 1257 } |
1254 } | 1258 } |
1255 | 1259 |
1256 void NavigationControllerImpl::NotifyNavigationEntryCommitted( | 1260 void NavigationControllerImpl::NotifyNavigationEntryCommitted( |
1257 content::LoadCommittedDetails* details) { | 1261 content::LoadCommittedDetails* details) { |
1258 details->entry = GetActiveEntry(); | 1262 details->entry = GetActiveEntry(); |
1259 content::NotificationDetails notification_details = | 1263 content::NotificationDetails notification_details = |
1260 content::Details<content::LoadCommittedDetails>(details); | 1264 content::Details<content::LoadCommittedDetails>(details); |
1261 | 1265 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 for (int i = 0; i < max_index; i++) { | 1365 for (int i = 0; i < max_index; i++) { |
1362 // When cloning a tab, copy all entries except interstitial pages | 1366 // When cloning a tab, copy all entries except interstitial pages |
1363 if (source.entries_[i].get()->GetPageType() != | 1367 if (source.entries_[i].get()->GetPageType() != |
1364 content::PAGE_TYPE_INTERSTITIAL) { | 1368 content::PAGE_TYPE_INTERSTITIAL) { |
1365 entries_.insert(entries_.begin() + insert_index++, | 1369 entries_.insert(entries_.begin() + insert_index++, |
1366 linked_ptr<NavigationEntryImpl>( | 1370 linked_ptr<NavigationEntryImpl>( |
1367 new NavigationEntryImpl(*source.entries_[i]))); | 1371 new NavigationEntryImpl(*source.entries_[i]))); |
1368 } | 1372 } |
1369 } | 1373 } |
1370 } | 1374 } |
OLD | NEW |