Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: content/browser/tab_contents/tab_contents.cc

Issue 9146028: Define the public interface for content browser SiteInstance. This interface is implemented by th... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (delegate) 192 if (delegate)
193 delegate->AddNavigationHeaders(params->url, &params->extra_headers); 193 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
194 } 194 }
195 195
196 } // namespace 196 } // namespace
197 197
198 namespace content { 198 namespace content {
199 199
200 WebContents* WebContents::Create( 200 WebContents* WebContents::Create(
201 BrowserContext* browser_context, 201 BrowserContext* browser_context,
202 SiteInstance* site_instance, 202 content::SiteInstance* site_instance,
203 int routing_id, 203 int routing_id,
204 const WebContents* base_tab_contents, 204 const WebContents* base_tab_contents,
205 SessionStorageNamespace* session_storage_namespace) { 205 SessionStorageNamespace* session_storage_namespace) {
206 return new TabContents(browser_context, 206 return new TabContents(browser_context,
207 site_instance, 207 site_instance,
208 routing_id, 208 routing_id,
209 static_cast<const TabContents*>(base_tab_contents), 209 static_cast<const TabContents*>(base_tab_contents),
210 session_storage_namespace); 210 session_storage_namespace);
211 } 211 }
212 } 212 }
213 213
214 // TabContents ---------------------------------------------------------------- 214 // TabContents ----------------------------------------------------------------
215 215
216 TabContents::TabContents(content::BrowserContext* browser_context, 216 TabContents::TabContents(content::BrowserContext* browser_context,
217 SiteInstance* site_instance, 217 content::SiteInstance* site_instance,
218 int routing_id, 218 int routing_id,
219 const TabContents* base_tab_contents, 219 const TabContents* base_tab_contents,
220 SessionStorageNamespace* session_storage_namespace) 220 SessionStorageNamespace* session_storage_namespace)
221 : delegate_(NULL), 221 : delegate_(NULL),
222 ALLOW_THIS_IN_INITIALIZER_LIST(controller_( 222 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
223 this, browser_context, session_storage_namespace)), 223 this, browser_context, session_storage_namespace)),
224 ALLOW_THIS_IN_INITIALIZER_LIST(view_( 224 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
225 content::GetContentClient()->browser()->CreateWebContentsView(this))), 225 content::GetContentClient()->browser()->CreateWebContentsView(this))),
226 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)), 226 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
227 is_loading_(false), 227 is_loading_(false),
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 496
497 // |page_title_when_no_navigation_entry_| is finally used 497 // |page_title_when_no_navigation_entry_| is finally used
498 // if no title cannot be retrieved. 498 // if no title cannot be retrieved.
499 return page_title_when_no_navigation_entry_; 499 return page_title_when_no_navigation_entry_;
500 } 500 }
501 501
502 int32 TabContents::GetMaxPageID() { 502 int32 TabContents::GetMaxPageID() {
503 return GetMaxPageIDForSiteInstance(GetSiteInstance()); 503 return GetMaxPageIDForSiteInstance(GetSiteInstance());
504 } 504 }
505 505
506 int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) { 506 int32 TabContents::GetMaxPageIDForSiteInstance(
507 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end()) 507 content::SiteInstance* site_instance) {
508 max_page_ids_[site_instance->id()] = -1; 508 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
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 content::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 content::SiteInstance* TabContents::GetSiteInstance() const {
528 return render_manager_.current_host()->site_instance(); 529 return render_manager_.current_host()->site_instance();
529 } 530 }
530 531
531 SiteInstance* TabContents::GetPendingSiteInstance() const { 532 content::SiteInstance* TabContents::GetPendingSiteInstance() const {
532 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ? 533 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
533 render_manager_.pending_render_view_host() : 534 render_manager_.pending_render_view_host() :
534 render_manager_.current_host(); 535 render_manager_.current_host();
535 return dest_rvh->site_instance(); 536 return dest_rvh->site_instance();
536 } 537 }
537 538
538 bool TabContents::IsLoading() const { 539 bool TabContents::IsLoading() const {
539 return is_loading_; 540 return is_loading_;
540 } 541 }
541 542
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 content::SiteInstance::CreateSiteInstance(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
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 content::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 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 render_manager_.RenderViewDeleted(rvh); 1734 render_manager_.RenderViewDeleted(rvh);
1733 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); 1735 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
1734 } 1736 }
1735 1737
1736 void TabContents::DidNavigate(RenderViewHost* rvh, 1738 void TabContents::DidNavigate(RenderViewHost* rvh,
1737 const ViewHostMsg_FrameNavigate_Params& params) { 1739 const ViewHostMsg_FrameNavigate_Params& params) {
1738 if (content::PageTransitionIsMainFrame(params.transition)) 1740 if (content::PageTransitionIsMainFrame(params.transition))
1739 render_manager_.DidNavigateMainFrame(rvh); 1741 render_manager_.DidNavigateMainFrame(rvh);
1740 1742
1741 // Update the site of the SiteInstance if it doesn't have one yet. 1743 // Update the site of the SiteInstance if it doesn't have one yet.
1742 if (!GetSiteInstance()->has_site()) 1744 if (!GetSiteInstance()->HasSite())
1743 GetSiteInstance()->SetSite(params.url); 1745 GetSiteInstance()->SetSite(params.url);
1744 1746
1745 // Need to update MIME type here because it's referred to in 1747 // Need to update MIME type here because it's referred to in
1746 // UpdateNavigationCommands() called by RendererDidNavigate() to 1748 // UpdateNavigationCommands() called by RendererDidNavigate() to
1747 // determine whether or not to enable the encoding menu. 1749 // determine whether or not to enable the encoding menu.
1748 // It's updated only for the main frame. For a subframe, 1750 // It's updated only for the main frame. For a subframe,
1749 // RenderView::UpdateURL does not set params.contents_mime_type. 1751 // RenderView::UpdateURL does not set params.contents_mime_type.
1750 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) 1752 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1751 // TODO(jungshik): Add a test for the encoding menu to avoid 1753 // TODO(jungshik): Add a test for the encoding menu to avoid
1752 // regressing it again. 1754 // regressing it again.
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
2279 encoding_ = content::GetContentClient()->browser()-> 2281 encoding_ = content::GetContentClient()->browser()->
2280 GetCanonicalEncodingNameByAliasName(encoding); 2282 GetCanonicalEncodingNameByAliasName(encoding);
2281 } 2283 }
2282 2284
2283 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { 2285 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2284 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); 2286 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
2285 // Can be NULL during tests. 2287 // Can be NULL during tests.
2286 if (rwh_view) 2288 if (rwh_view)
2287 rwh_view->SetSize(GetView()->GetContainerSize()); 2289 rwh_view->SetSize(GetView()->GetContainerSize());
2288 } 2290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698