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/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "content/browser/child_process_security_policy.h" | 16 #include "content/browser/child_process_security_policy.h" |
17 #include "content/browser/debugger/devtools_manager_impl.h" | 17 #include "content/browser/debugger/devtools_manager_impl.h" |
18 #include "content/browser/download/download_stats.h" | 18 #include "content/browser/download/download_stats.h" |
19 #include "content/browser/download/save_package.h" | 19 #include "content/browser/download/save_package.h" |
20 #include "content/browser/host_zoom_map.h" | 20 #include "content/browser/host_zoom_map.h" |
21 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 21 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
22 #include "content/browser/intents/web_intents_dispatcher_impl.h" | 22 #include "content/browser/intents/web_intents_dispatcher_impl.h" |
23 #include "content/browser/load_from_memory_cache_details.h" | 23 #include "content/browser/load_from_memory_cache_details.h" |
24 #include "content/browser/load_notification_details.h" | 24 #include "content/browser/load_notification_details.h" |
25 #include "content/browser/renderer_host/render_process_host_impl.h" | 25 #include "content/browser/renderer_host/render_process_host_impl.h" |
26 #include "content/browser/renderer_host/render_view_host.h" | 26 #include "content/browser/renderer_host/render_view_host.h" |
27 #include "content/browser/renderer_host/render_widget_host_view.h" | 27 #include "content/browser/renderer_host/render_widget_host_view.h" |
28 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 28 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
29 #include "content/browser/renderer_host/resource_request_details.h" | 29 #include "content/browser/renderer_host/resource_request_details.h" |
30 #include "content/browser/site_instance.h" | 30 #include "content/browser/site_instance_impl.h" |
31 #include "content/browser/tab_contents/interstitial_page.h" | 31 #include "content/browser/tab_contents/interstitial_page.h" |
32 #include "content/browser/tab_contents/navigation_entry_impl.h" | 32 #include "content/browser/tab_contents/navigation_entry_impl.h" |
33 #include "content/browser/tab_contents/provisional_load_details.h" | 33 #include "content/browser/tab_contents/provisional_load_details.h" |
34 #include "content/browser/tab_contents/title_updated_details.h" | 34 #include "content/browser/tab_contents/title_updated_details.h" |
35 #include "content/browser/webui/web_ui_impl.h" | 35 #include "content/browser/webui/web_ui_impl.h" |
36 #include "content/common/intents_messages.h" | 36 #include "content/common/intents_messages.h" |
37 #include "content/common/view_messages.h" | 37 #include "content/common/view_messages.h" |
38 #include "content/public/browser/browser_context.h" | 38 #include "content/public/browser/browser_context.h" |
39 #include "content/public/browser/content_browser_client.h" | 39 #include "content/public/browser/content_browser_client.h" |
40 #include "content/public/browser/devtools_agent_host_registry.h" | 40 #include "content/public/browser/devtools_agent_host_registry.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 using content::DevToolsAgentHostRegistry; | 114 using content::DevToolsAgentHostRegistry; |
115 using content::DevToolsManagerImpl; | 115 using content::DevToolsManagerImpl; |
116 using content::DownloadItem; | 116 using content::DownloadItem; |
117 using content::DownloadManager; | 117 using content::DownloadManager; |
118 using content::GlobalRequestID; | 118 using content::GlobalRequestID; |
119 using content::NavigationController; | 119 using content::NavigationController; |
120 using content::NavigationEntry; | 120 using content::NavigationEntry; |
121 using content::NavigationEntryImpl; | 121 using content::NavigationEntryImpl; |
122 using content::OpenURLParams; | 122 using content::OpenURLParams; |
123 using content::RenderViewHostDelegate; | 123 using content::RenderViewHostDelegate; |
| 124 using content::SiteInstance; |
124 using content::SSLStatus; | 125 using content::SSLStatus; |
125 using content::UserMetricsAction; | 126 using content::UserMetricsAction; |
126 using content::WebContents; | 127 using content::WebContents; |
127 using content::WebContentsObserver; | 128 using content::WebContentsObserver; |
128 using content::WebUI; | 129 using content::WebUI; |
129 using content::WebUIController; | 130 using content::WebUIController; |
130 | 131 |
131 namespace { | 132 namespace { |
132 | 133 |
133 // Amount of time we wait between when a key event is received and the renderer | 134 // Amount of time we wait between when a key event is received and the renderer |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 // |page_title_when_no_navigation_entry_| is finally used | 498 // |page_title_when_no_navigation_entry_| is finally used |
498 // if no title cannot be retrieved. | 499 // if no title cannot be retrieved. |
499 return page_title_when_no_navigation_entry_; | 500 return page_title_when_no_navigation_entry_; |
500 } | 501 } |
501 | 502 |
502 int32 TabContents::GetMaxPageID() { | 503 int32 TabContents::GetMaxPageID() { |
503 return GetMaxPageIDForSiteInstance(GetSiteInstance()); | 504 return GetMaxPageIDForSiteInstance(GetSiteInstance()); |
504 } | 505 } |
505 | 506 |
506 int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) { | 507 int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) { |
507 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end()) | 508 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end()) |
508 max_page_ids_[site_instance->id()] = -1; | 509 max_page_ids_[site_instance->GetId()] = -1; |
509 | 510 |
510 return max_page_ids_[site_instance->id()]; | 511 return max_page_ids_[site_instance->GetId()]; |
511 } | 512 } |
512 | 513 |
513 void TabContents::UpdateMaxPageID(int32 page_id) { | 514 void TabContents::UpdateMaxPageID(int32 page_id) { |
514 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id); | 515 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id); |
515 } | 516 } |
516 | 517 |
517 void TabContents::UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance, | 518 void TabContents::UpdateMaxPageIDForSiteInstance( |
518 int32 page_id) { | 519 SiteInstance* site_instance, int32 page_id) { |
519 if (GetMaxPageIDForSiteInstance(site_instance) < page_id) | 520 if (GetMaxPageIDForSiteInstance(site_instance) < page_id) |
520 max_page_ids_[site_instance->id()] = page_id; | 521 max_page_ids_[site_instance->GetId()] = page_id; |
521 } | 522 } |
522 | 523 |
523 void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) { | 524 void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) { |
524 max_page_ids_ = tab_contents->max_page_ids_; | 525 max_page_ids_ = tab_contents->max_page_ids_; |
525 } | 526 } |
526 | 527 |
527 SiteInstance* TabContents::GetSiteInstance() const { | 528 SiteInstance* TabContents::GetSiteInstance() const { |
528 return render_manager_.current_host()->site_instance(); | 529 return render_manager_.current_host()->site_instance(); |
529 } | 530 } |
530 | 531 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 render_manager_.Stop(); | 666 render_manager_.Stop(); |
666 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation()); | 667 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation()); |
667 } | 668 } |
668 | 669 |
669 WebContents* TabContents::Clone() { | 670 WebContents* TabContents::Clone() { |
670 // We create a new SiteInstance so that the new tab won't share processes | 671 // We create a new SiteInstance so that the new tab won't share processes |
671 // with the old one. This can be changed in the future if we need it to share | 672 // with the old one. This can be changed in the future if we need it to share |
672 // processes for some reason. | 673 // processes for some reason. |
673 TabContents* tc = new TabContents( | 674 TabContents* tc = new TabContents( |
674 GetBrowserContext(), | 675 GetBrowserContext(), |
675 SiteInstance::CreateSiteInstance(GetBrowserContext()), | 676 SiteInstance::Create(GetBrowserContext()), |
676 MSG_ROUTING_NONE, this, NULL); | 677 MSG_ROUTING_NONE, this, NULL); |
677 tc->GetControllerImpl().CopyStateFrom(controller_); | 678 tc->GetControllerImpl().CopyStateFrom(controller_); |
678 return tc; | 679 return tc; |
679 } | 680 } |
680 | 681 |
681 void TabContents::ShowPageInfo(const GURL& url, | 682 void TabContents::ShowPageInfo(const GURL& url, |
682 const SSLStatus& ssl, | 683 const SSLStatus& ssl, |
683 bool show_history) { | 684 bool show_history) { |
684 if (!delegate_) | 685 if (!delegate_) |
685 return; | 686 return; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 FOR_EACH_OBSERVER(WebContentsObserver, | 872 FOR_EACH_OBSERVER(WebContentsObserver, |
872 observers_, | 873 observers_, |
873 NavigateToPendingEntry(entry.GetURL(), reload_type)); | 874 NavigateToPendingEntry(entry.GetURL(), reload_type)); |
874 | 875 |
875 if (delegate_) | 876 if (delegate_) |
876 delegate_->DidNavigateToPendingEntry(this); | 877 delegate_->DidNavigateToPendingEntry(this); |
877 | 878 |
878 return true; | 879 return true; |
879 } | 880 } |
880 | 881 |
881 void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance, | 882 void TabContents::SetHistoryLengthAndPrune( |
882 int history_length, | 883 const SiteInstance* site_instance, |
883 int32 minimum_page_id) { | 884 int history_length, |
| 885 int32 minimum_page_id) { |
884 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site | 886 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site |
885 // navigations. Callers should ensure that this is the case. | 887 // navigations. Callers should ensure that this is the case. |
886 if (render_manager_.pending_render_view_host()) { | 888 if (render_manager_.pending_render_view_host()) { |
887 NOTREACHED(); | 889 NOTREACHED(); |
888 return; | 890 return; |
889 } | 891 } |
890 RenderViewHost* rvh = GetRenderViewHost(); | 892 RenderViewHost* rvh = GetRenderViewHost(); |
891 if (!rvh) { | 893 if (!rvh) { |
892 NOTREACHED(); | 894 NOTREACHED(); |
893 return; | 895 return; |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 entry->SetTransitionType( | 1391 entry->SetTransitionType( |
1390 content::PageTransitionFromInt( | 1392 content::PageTransitionFromInt( |
1391 entry->GetTransitionType() | | 1393 entry->GetTransitionType() | |
1392 content::PAGE_TRANSITION_FORWARD_BACK)); | 1394 content::PAGE_TRANSITION_FORWARD_BACK)); |
1393 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD); | 1395 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD); |
1394 | 1396 |
1395 // If the entry is being restored and doesn't have a SiteInstance yet, fill | 1397 // If the entry is being restored and doesn't have a SiteInstance yet, fill |
1396 // it in now that we know. This allows us to find the entry when it commits. | 1398 // it in now that we know. This allows us to find the entry when it commits. |
1397 if (!entry->site_instance() && | 1399 if (!entry->site_instance() && |
1398 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) { | 1400 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) { |
1399 entry->set_site_instance(GetPendingSiteInstance()); | 1401 entry->set_site_instance( |
| 1402 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance())); |
1400 } | 1403 } |
1401 } | 1404 } |
1402 } | 1405 } |
1403 | 1406 |
1404 void TabContents::OnUpdateZoomLimits(int minimum_percent, | 1407 void TabContents::OnUpdateZoomLimits(int minimum_percent, |
1405 int maximum_percent, | 1408 int maximum_percent, |
1406 bool remember) { | 1409 bool remember) { |
1407 minimum_zoom_percent_ = minimum_percent; | 1410 minimum_zoom_percent_ = minimum_percent; |
1408 maximum_zoom_percent_ = maximum_percent; | 1411 maximum_zoom_percent_ = maximum_percent; |
1409 temporary_zoom_settings_ = !remember; | 1412 temporary_zoom_settings_ = !remember; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 render_manager_.RenderViewDeleted(rvh); | 1731 render_manager_.RenderViewDeleted(rvh); |
1729 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); | 1732 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); |
1730 } | 1733 } |
1731 | 1734 |
1732 void TabContents::DidNavigate(RenderViewHost* rvh, | 1735 void TabContents::DidNavigate(RenderViewHost* rvh, |
1733 const ViewHostMsg_FrameNavigate_Params& params) { | 1736 const ViewHostMsg_FrameNavigate_Params& params) { |
1734 if (content::PageTransitionIsMainFrame(params.transition)) | 1737 if (content::PageTransitionIsMainFrame(params.transition)) |
1735 render_manager_.DidNavigateMainFrame(rvh); | 1738 render_manager_.DidNavigateMainFrame(rvh); |
1736 | 1739 |
1737 // Update the site of the SiteInstance if it doesn't have one yet. | 1740 // Update the site of the SiteInstance if it doesn't have one yet. |
1738 if (!GetSiteInstance()->has_site()) | 1741 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite()) |
1739 GetSiteInstance()->SetSite(params.url); | 1742 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url); |
1740 | 1743 |
1741 // Need to update MIME type here because it's referred to in | 1744 // Need to update MIME type here because it's referred to in |
1742 // UpdateNavigationCommands() called by RendererDidNavigate() to | 1745 // UpdateNavigationCommands() called by RendererDidNavigate() to |
1743 // determine whether or not to enable the encoding menu. | 1746 // determine whether or not to enable the encoding menu. |
1744 // It's updated only for the main frame. For a subframe, | 1747 // It's updated only for the main frame. For a subframe, |
1745 // RenderView::UpdateURL does not set params.contents_mime_type. | 1748 // RenderView::UpdateURL does not set params.contents_mime_type. |
1746 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) | 1749 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
1747 // TODO(jungshik): Add a test for the encoding menu to avoid | 1750 // TODO(jungshik): Add a test for the encoding menu to avoid |
1748 // regressing it again. | 1751 // regressing it again. |
1749 if (content::PageTransitionIsMainFrame(params.transition)) | 1752 if (content::PageTransitionIsMainFrame(params.transition)) |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2275 encoding_ = content::GetContentClient()->browser()-> | 2278 encoding_ = content::GetContentClient()->browser()-> |
2276 GetCanonicalEncodingNameByAliasName(encoding); | 2279 GetCanonicalEncodingNameByAliasName(encoding); |
2277 } | 2280 } |
2278 | 2281 |
2279 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2282 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
2280 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); | 2283 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
2281 // Can be NULL during tests. | 2284 // Can be NULL during tests. |
2282 if (rwh_view) | 2285 if (rwh_view) |
2283 rwh_view->SetSize(GetView()->GetContainerSize()); | 2286 rwh_view->SetSize(GetView()->GetContainerSize()); |
2284 } | 2287 } |
OLD | NEW |