diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-27 17:47:37 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-27 17:47:37 +0000 |
commit | 3d7474fffebf62e0bbd2fe3f03996af3f28b8180 (patch) | |
tree | 9cdd26d0eb2c245da54447262e043fc620fdaaf6 /content | |
parent | 291fb3ed59e445c03756fa678c0935fc7140cdcf (diff) | |
download | chromium_src-3d7474fffebf62e0bbd2fe3f03996af3f28b8180.zip chromium_src-3d7474fffebf62e0bbd2fe3f03996af3f28b8180.tar.gz chromium_src-3d7474fffebf62e0bbd2fe3f03996af3f28b8180.tar.bz2 |
Removal of Profile from content part 1.
BUG=76788
TEST=no change visible
Review URL: http://codereview.chromium.org/7464009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
39 files changed, 486 insertions, 266 deletions
diff --git a/content/browser/browser_context.h b/content/browser/browser_context.h new file mode 100644 index 0000000..2793aa7 --- /dev/null +++ b/content/browser/browser_context.h @@ -0,0 +1,118 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_BROWSER_CONTEXT_H_ +#define CONTENT_BROWSER_BROWSER_CONTEXT_H_ +#pragma once + +#include "base/hash_tables.h" + +namespace net { +class URLRequestContextGetter; +} + +namespace quota { +class QuotaManager; +} + +namespace webkit_database { +class DatabaseTracker; +} + +class ChromeBlobStorageContext; +class DownloadManager; +class FilePath; +class GeolocationContentSettingsMap; +class GeolocationPermissionContext; +class HostZoomMap; +class SSLHostState; +class WebKitContext; + +namespace content { + +class ResourceContext; + +// This class holds the context needed for a browsing session. + +class BrowserContext { + public: + // Returns the path of the directory where this context's data is stored. + virtual FilePath GetPath() = 0; + + // Return whether this context is incognito. Default is false. + // This doesn't belong here; http://crbug.com/89628 + virtual bool IsOffTheRecord() = 0; + + // Returns a pointer to the DatabaseTracker instance for this context. + virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0; + + // Retrieves a pointer to the SSLHostState associated with this context. + // The SSLHostState is lazily created the first time that this method is + // called. + virtual SSLHostState* GetSSLHostState() = 0; + + // Returns the DownloadManager associated with this context. + virtual DownloadManager* GetDownloadManager() = 0; + virtual bool HasCreatedDownloadManager() const = 0; + + virtual quota::QuotaManager* GetQuotaManager() = 0; + + // Returns the request context information associated with this context. Call + // this only on the UI thread, since it can send notifications that should + // happen on the UI thread. + virtual net::URLRequestContextGetter* GetRequestContext() = 0; + + // Returns the request context appropriate for the given renderer. If the + // renderer process doesn't have an associated installed app, or if the + // installed app's is_storage_isolated() returns false, this is equivalent to + // calling GetRequestContext(). + // TODO(creis): After isolated app storage is no longer an experimental + // feature, consider making this the default contract for GetRequestContext. + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( + int renderer_child_id) = 0; + + // Returns the request context for media resources asociated with this + // context. + virtual net::URLRequestContextGetter* GetRequestContextForMedia() = 0; + + // Returns the resource context. + virtual const ResourceContext& GetResourceContext() = 0; + + // Returns the Hostname <-> Zoom Level map for this context. + virtual HostZoomMap* GetHostZoomMap() = 0; + + // Returns the geolocation settings map for this context. + virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() = 0; + + // Returns the geolocation permission context for this context. + virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0; + + // Returns true if the last time this context was open it was exited cleanly. + // This doesn't belong here; http://crbug.com/76788 + virtual bool DidLastSessionExitCleanly() = 0; + + // Returns the WebKitContext assigned to this context. + virtual WebKitContext* GetWebKitContext() = 0; + + // Returns a pointer to the ChromeBlobStorageContext instance for this + // context. + virtual ChromeBlobStorageContext* GetBlobStorageContext() = 0; +}; + +} // namespace content + +#if defined(COMPILER_GCC) +namespace __gnu_cxx { + +template<> +struct hash<content::BrowserContext*> { + std::size_t operator()(content::BrowserContext* const& p) const { + return reinterpret_cast<std::size_t>(p); + } +}; + +} // namespace __gnu_cxx +#endif + +#endif // CONTENT_BROWSER_BROWSER_CONTEXT_H_ diff --git a/content/browser/browser_url_handler.cc b/content/browser/browser_url_handler.cc index e6e76a0..65c176c8 100644 --- a/content/browser/browser_url_handler.cc +++ b/content/browser/browser_url_handler.cc @@ -11,7 +11,8 @@ #include "googleurl/src/gurl.h" // Handles rewriting view-source URLs for what we'll actually load. -static bool HandleViewSource(GURL* url, Profile* profile) { +static bool HandleViewSource(GURL* url, + content::BrowserContext* browser_context) { if (url->SchemeIs(chrome::kViewSourceScheme)) { // Load the inner URL instead. *url = GURL(url->path()); @@ -43,7 +44,8 @@ static bool HandleViewSource(GURL* url, Profile* profile) { } // Turns a non view-source URL into the corresponding view-source URL. -static bool ReverseViewSource(GURL* url, Profile* profile) { +static bool ReverseViewSource(GURL* url, + content::BrowserContext* browser_context) { // No action necessary if the URL is already view-source: if (url->SchemeIs(chrome::kViewSourceScheme)) return false; @@ -89,11 +91,13 @@ void BrowserURLHandler::AddHandlerPair(URLHandler handler, url_handlers_.push_back(HandlerPair(handler, reverse_handler)); } -void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile, - bool* reverse_on_redirect) { +void BrowserURLHandler::RewriteURLIfNecessary( + GURL* url, + content::BrowserContext* browser_context, + bool* reverse_on_redirect) { for (size_t i = 0; i < url_handlers_.size(); ++i) { URLHandler handler = *url_handlers_[i].first; - if (handler && handler(url, profile)) { + if (handler && handler(url, browser_context)) { *reverse_on_redirect = (url_handlers_[i].second != NULL); return; } @@ -101,17 +105,17 @@ void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile, } bool BrowserURLHandler::ReverseURLRewrite( - GURL* url, const GURL& original, Profile* profile) { + GURL* url, const GURL& original, content::BrowserContext* browser_context) { for (size_t i = 0; i < url_handlers_.size(); ++i) { URLHandler reverse_rewriter = *url_handlers_[i].second; if (reverse_rewriter) { GURL test_url(original); URLHandler handler = *url_handlers_[i].first; if (!handler) { - if (reverse_rewriter(url, profile)) + if (reverse_rewriter(url, browser_context)) return true; - } else if (handler(&test_url, profile)) { - return reverse_rewriter(url, profile); + } else if (handler(&test_url, browser_context)) { + return reverse_rewriter(url, browser_context); } } } diff --git a/content/browser/browser_url_handler.h b/content/browser/browser_url_handler.h index dc86a72..881c080 100644 --- a/content/browser/browser_url_handler.h +++ b/content/browser/browser_url_handler.h @@ -20,7 +20,10 @@ #include "base/memory/singleton.h" class GURL; -class Profile; + +namespace content { +class BrowserContext; +} // BrowserURLHandler manages the list of all special URLs and manages // dispatching the URL handling to registered handlers. @@ -30,7 +33,8 @@ class BrowserURLHandler { // If a handler handles |url|, it should : // - optionally modify |url| to the URL that should be sent to the renderer // If the URL is not handled by a handler, it should return false. - typedef bool (*URLHandler)(GURL* url, Profile* profile); + typedef bool (*URLHandler)(GURL* url, + content::BrowserContext* browser_context); // Returns the singleton instance. static BrowserURLHandler* GetInstance(); @@ -39,12 +43,13 @@ class BrowserURLHandler { // the given URL, and modifies it in place. // If the original URL needs to be adjusted if the modified URL is redirected, // this function sets |reverse_on_redirect| to true. - void RewriteURLIfNecessary(GURL* url, Profile* profile, + void RewriteURLIfNecessary(GURL* url, + content::BrowserContext* browser_context, bool* reverse_on_redirect); // Reverses the rewriting that was done for |original| using the new |url|. bool ReverseURLRewrite(GURL* url, const GURL& original, - Profile* profile); + content::BrowserContext* browser_context); // Add the specified handler pair to the list of URL handlers. void AddHandlerPair(URLHandler handler, URLHandler reverse_handler); diff --git a/content/browser/browser_url_handler_unittest.cc b/content/browser/browser_url_handler_unittest.cc index fec59e5..9168522 100644 --- a/content/browser/browser_url_handler_unittest.cc +++ b/content/browser/browser_url_handler_unittest.cc @@ -11,7 +11,7 @@ class BrowserURLHandlerTest : public testing::Test { }; // Test URL rewriter that rewrites all "foo://" URLs to "bar://bar". -static bool FooRewriter(GURL* url, Profile* profile) { +static bool FooRewriter(GURL* url, content::BrowserContext* browser_context) { if (url->scheme() == "foo") { *url = GURL("bar://bar"); return true; @@ -20,7 +20,7 @@ static bool FooRewriter(GURL* url, Profile* profile) { } // Test URL rewriter that rewrites all "bar://" URLs to "foo://foo". -static bool BarRewriter(GURL* url, Profile* profile) { +static bool BarRewriter(GURL* url, content::BrowserContext* browser_context) { if (url->scheme() == "bar") { *url = GURL("foo://foo"); return true; diff --git a/content/browser/browsing_instance.cc b/content/browser/browsing_instance.cc index 65666d4..ae603cf 100644 --- a/content/browser/browsing_instance.cc +++ b/content/browser/browsing_instance.cc @@ -6,7 +6,7 @@ #include "base/command_line.h" #include "base/logging.h" -#include "chrome/browser/profiles/profile.h" +#include "content/browser/browser_context.h" #include "content/browser/content_browser_client.h" #include "content/browser/site_instance.h" #include "content/browser/webui/web_ui_factory.h" @@ -15,11 +15,11 @@ #include "content/common/url_constants.h" // static -BrowsingInstance::ProfileSiteInstanceMap - BrowsingInstance::profile_site_instance_map_; +BrowsingInstance::ContextSiteInstanceMap + BrowsingInstance::context_site_instance_map_; -BrowsingInstance::BrowsingInstance(Profile* profile) - : profile_(profile) { +BrowsingInstance::BrowsingInstance(content::BrowserContext* browser_context) + : browser_context_(browser_context) { } bool BrowsingInstance::ShouldUseProcessPerSite(const GURL& url) { @@ -37,12 +37,12 @@ bool BrowsingInstance::ShouldUseProcessPerSite(const GURL& url) { // process creation logic in RenderProcessHost, so we do not need to worry // about it here. - if (content::GetContentClient()->browser()->ShouldUseProcessPerSite(profile_, - url)) + if (content::GetContentClient()->browser()-> + ShouldUseProcessPerSite(browser_context_, url)) return true; // DevTools pages have WebUI type but should not reuse the same host. - if (content::WebUIFactory::Get()->UseWebUIForURL(profile_, url) && + if (content::WebUIFactory::Get()->UseWebUIForURL(browser_context_, url) && !url.SchemeIs(chrome::kChromeDevToolsScheme)) { return true; } @@ -52,31 +52,34 @@ bool BrowsingInstance::ShouldUseProcessPerSite(const GURL& url) { } BrowsingInstance::SiteInstanceMap* BrowsingInstance::GetSiteInstanceMap( - Profile* profile, const GURL& url) { - if (!ShouldUseProcessPerSite(SiteInstance::GetEffectiveURL(profile, url))) { + content::BrowserContext* browser_context, const GURL& url) { + if (!ShouldUseProcessPerSite(SiteInstance::GetEffectiveURL(browser_context, + url))) { // Not using process-per-site, so use a map specific to this instance. return &site_instance_map_; } // Otherwise, process-per-site is in use, at least for this URL. Look up the - // global map for this profile, creating an entry if necessary. - return &profile_site_instance_map_[profile]; + // global map for this context, creating an entry if necessary. + return &context_site_instance_map_[browser_context]; } bool BrowsingInstance::HasSiteInstance(const GURL& url) { std::string site = - SiteInstance::GetSiteForURL(profile_, url).possibly_invalid_spec(); + SiteInstance::GetSiteForURL(browser_context_, url) + .possibly_invalid_spec(); - SiteInstanceMap* map = GetSiteInstanceMap(profile_, url); + SiteInstanceMap* map = GetSiteInstanceMap(browser_context_, url); SiteInstanceMap::iterator i = map->find(site); return (i != map->end()); } SiteInstance* BrowsingInstance::GetSiteInstanceForURL(const GURL& url) { std::string site = - SiteInstance::GetSiteForURL(profile_, url).possibly_invalid_spec(); + SiteInstance::GetSiteForURL(browser_context_, url) + .possibly_invalid_spec(); - SiteInstanceMap* map = GetSiteInstanceMap(profile_, url); + SiteInstanceMap* map = GetSiteInstanceMap(browser_context_, url); SiteInstanceMap::iterator i = map->find(site); if (i != map->end()) { return i->second; @@ -100,7 +103,8 @@ void BrowsingInstance::RegisterSiteInstance(SiteInstance* site_instance) { // tabs are navigated there at the same time. (We don't call SetSite or // register them until DidNavigate.) If there is a previously existing // SiteInstance for this site, we just won't register the new one. - SiteInstanceMap* map = GetSiteInstanceMap(profile_, site_instance->site()); + SiteInstanceMap* map = GetSiteInstanceMap(browser_context_, + site_instance->site()); SiteInstanceMap::iterator i = map->find(site); if (i == map->end()) { // Not previously registered, so register it. @@ -118,15 +122,15 @@ void BrowsingInstance::UnregisterSiteInstance(SiteInstance* site_instance) { // comments in RegisterSiteInstance.) // We look for the site instance in both the local site_instance_map_ and also - // the static profile_site_instance_map_ - this is because the logic in + // the static context_site_instance_map_ - this is because the logic in // ShouldUseProcessPerSite() can produce different results over the lifetime // of Chrome (e.g. installation of apps with web extents can change our // process-per-site policy for a given domain), so we don't know which map // the site was put into when it was originally registered. if (!RemoveSiteInstanceFromMap(&site_instance_map_, site, site_instance)) { - // Wasn't in our local map, so look in the static per-profile map. + // Wasn't in our local map, so look in the static per-browser context map. RemoveSiteInstanceFromMap( - &profile_site_instance_map_[profile_], site, site_instance); + &context_site_instance_map_[browser_context_], site, site_instance); } } diff --git a/content/browser/browsing_instance.h b/content/browser/browsing_instance.h index f26eb55..31a1cf4 100644 --- a/content/browser/browsing_instance.h +++ b/content/browser/browsing_instance.h @@ -8,11 +8,15 @@ #include "base/hash_tables.h" #include "base/memory/ref_counted.h" +#include "chrome/browser/profiles/profile.h" class GURL; -class Profile; class SiteInstance; +namespace content { +class BrowserContext; +} + /////////////////////////////////////////////////////////////////////////////// // // BrowsingInstance class @@ -35,7 +39,7 @@ class SiteInstance; // Thus, they must be rendered in the same process. // // If the process-per-site model is in use, then we ensure that there is only -// one SiteInstance per site for the entire profile, not just for each +// one SiteInstance per site for the entire browser context, not just for each // BrowsingInstance. This reduces the number of renderer processes we create. // (This is currently only true if --process-per-site is specified at the // command line.) @@ -55,16 +59,22 @@ class SiteInstance; class BrowsingInstance : public base::RefCounted<BrowsingInstance> { public: // Create a new BrowsingInstance. - explicit BrowsingInstance(Profile* profile); + explicit BrowsingInstance(content::BrowserContext* context); // Returns whether the process-per-site model is in use (globally or just for // the given url), in which case we should ensure there is only one - // SiteInstance per site for the entire profile, not just for this + // SiteInstance per site for the entire browser context, not just for this // BrowsingInstance. virtual bool ShouldUseProcessPerSite(const GURL& url); - // Get the profile to which this BrowsingInstance belongs. - Profile* profile() { return profile_; } + // Get the browser context to which this BrowsingInstance belongs. + content::BrowserContext* browser_context() { return browser_context_; } + + // Returns the profile. + // TEMPORARY; http://crbug.com/76788 + Profile* profile() { + return Profile::FromBrowserContext(browser_context()); + } // Returns whether this BrowsingInstance has registered a SiteInstance for // the site of the given URL. @@ -95,26 +105,28 @@ class BrowsingInstance : public base::RefCounted<BrowsingInstance> { // Map of site to SiteInstance, to ensure we only have one SiteInstance per typedef base::hash_map<std::string, SiteInstance*> SiteInstanceMap; - // Map of Profile to SiteInstanceMap, for use in the process-per-site model. - // process-per-site model. - typedef base::hash_map<Profile*, SiteInstanceMap> ProfileSiteInstanceMap; + // Map of BrowserContext to SiteInstanceMap, for use in the process-per-site + // model. + typedef base::hash_map<content::BrowserContext*, SiteInstanceMap> + ContextSiteInstanceMap; // Returns a pointer to the relevant SiteInstanceMap for this object. If the // process-per-site model is in use, or if process-per-site-instance is in // use and |url| matches a site for which we always use one process (e.g., // the new tab page), then this returns the SiteInstanceMap for the entire - // profile. If not, this returns the BrowsingInstance's own private + // browser context. If not, this returns the BrowsingInstance's own private // SiteInstanceMap. - SiteInstanceMap* GetSiteInstanceMap(Profile* profile, const GURL& url); + SiteInstanceMap* GetSiteInstanceMap(content::BrowserContext* browser_context, + const GURL& url); // Utility routine which removes the passed SiteInstance from the passed // SiteInstanceMap. bool RemoveSiteInstanceFromMap(SiteInstanceMap* map, const std::string& site, SiteInstance* site_instance); - // Common profile to which all SiteInstances in this BrowsingInstance + // Common browser context to which all SiteInstances in this BrowsingInstance // must belong. - Profile* const profile_; + content::BrowserContext* const browser_context_; // Map of site to SiteInstance, to ensure we only have one SiteInstance per // site. The site string should be the possibly_invalid_spec() of a GURL @@ -124,8 +136,8 @@ class BrowsingInstance : public base::RefCounted<BrowsingInstance> { // This field is only used if we are not using process-per-site. SiteInstanceMap site_instance_map_; - // Global map of Profile to SiteInstanceMap, for process-per-site. - static ProfileSiteInstanceMap profile_site_instance_map_; + // Global map of BrowserContext to SiteInstanceMap, for process-per-site. + static ContextSiteInstanceMap context_site_instance_map_; DISALLOW_COPY_AND_ASSIGN(BrowsingInstance); }; diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h index a04cee0..ec5a13e 100644 --- a/content/browser/content_browser_client.h +++ b/content/browser/content_browser_client.h @@ -22,7 +22,6 @@ class FilePath; class GURL; class MHTMLGenerationManager; class PluginProcessHost; -class Profile; class QuotaPermissionContext; class RenderViewHost; class ResourceDispatcherHost; @@ -54,6 +53,7 @@ class Clipboard; namespace content { +class BrowserContext; class ResourceContext; class WebUIFactory; @@ -91,11 +91,12 @@ class ContentBrowserClient { // Get the effective URL for the given actual URL, to allow an embedder to // group different url schemes in the same SiteInstance. - virtual GURL GetEffectiveURL(Profile* profile, const GURL& url) = 0; + virtual GURL GetEffectiveURL(BrowserContext* browser_context, + const GURL& url) = 0; // Returns whether all instances of the specified effective URL should be // rendered by the same process, rather than using process-per-site-instance. - virtual bool ShouldUseProcessPerSite(Profile* profile, + virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context, const GURL& effective_url) = 0; // Returns whether a specified URL is to be considered the same as any @@ -242,7 +243,8 @@ class ContentBrowserClient { virtual bool IsFastShutdownPossible() = 0; // Returns the WebKit preferences that are used by the renderer. - virtual WebPreferences GetWebkitPrefs(Profile* profile, bool is_web_ui) = 0; + virtual WebPreferences GetWebkitPrefs(BrowserContext* browser_context, + bool is_web_ui) = 0; // Inspector setting was changed and should be persisted. virtual void UpdateInspectorSetting(RenderViewHost* rvh, diff --git a/content/browser/javascript_dialogs.h b/content/browser/javascript_dialogs.h index 74297b4..cc17a71 100644 --- a/content/browser/javascript_dialogs.h +++ b/content/browser/javascript_dialogs.h @@ -9,9 +9,7 @@ #include "base/string16.h" #include "ui/gfx/native_widget_types.h" -class ExtensionHost; class GURL; -class Profile; class TabContents; namespace IPC { diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index 9d5c3e5..50d2113 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -38,8 +38,8 @@ WebUIFactory* MockContentBrowserClient::GetWebUIFactory() { return EmptyWebUIFactory::Get(); } -GURL MockContentBrowserClient::GetEffectiveURL(Profile* profile, - const GURL& url) { +GURL MockContentBrowserClient::GetEffectiveURL( + content::BrowserContext* browser_context, const GURL& url) { return GURL(); } @@ -196,8 +196,9 @@ bool MockContentBrowserClient::IsFastShutdownPossible() { return true; } -WebPreferences MockContentBrowserClient::GetWebkitPrefs(Profile* profile, - bool is_web_ui) { +WebPreferences MockContentBrowserClient::GetWebkitPrefs( + content::BrowserContext* browser_context, + bool is_web_ui) { return WebPreferences(); } diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index 157f9d3..121c076 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -23,7 +23,8 @@ class MockContentBrowserClient : public ContentBrowserClient { virtual void PluginProcessHostCreated(PluginProcessHost* host) OVERRIDE; virtual void WorkerProcessHostCreated(WorkerProcessHost* host) OVERRIDE; virtual WebUIFactory* GetWebUIFactory() OVERRIDE; - virtual GURL GetEffectiveURL(Profile* profile, const GURL& url) OVERRIDE; + virtual GURL GetEffectiveURL(content::BrowserContext* browser_context, + const GURL& url) OVERRIDE; virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE; virtual std::string GetCanonicalEncodingNameByAliasName( const std::string& alias_name) OVERRIDE; @@ -96,8 +97,9 @@ class MockContentBrowserClient : public ContentBrowserClient { virtual DevToolsManager* GetDevToolsManager() OVERRIDE; virtual net::NetLog* GetNetLog() OVERRIDE; virtual bool IsFastShutdownPossible() OVERRIDE; - virtual WebPreferences GetWebkitPrefs(Profile* profile, - bool is_web_ui) OVERRIDE; + virtual WebPreferences GetWebkitPrefs( + content::BrowserContext* browser_context, + bool is_web_ui) OVERRIDE; virtual void UpdateInspectorSetting(RenderViewHost* rvh, const std::string& key, const std::string& value) OVERRIDE; diff --git a/content/browser/renderer_host/browser_render_process_host.cc b/content/browser/renderer_host/browser_render_process_host.cc index d93f0f2..2292867 100644 --- a/content/browser/renderer_host/browser_render_process_host.cc +++ b/content/browser/renderer_host/browser_render_process_host.cc @@ -26,9 +26,9 @@ #include "base/string_util.h" #include "base/threading/thread.h" #include "base/threading/thread_restrictions.h" -#include "chrome/browser/profiles/profile.h" #include "content/browser/appcache/appcache_dispatcher_host.h" #include "content/browser/browser_child_process_host.h" +#include "content/browser/browser_context.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/content_browser_client.h" #include "content/browser/device_orientation/message_filter.h" @@ -151,11 +151,11 @@ namespace { class RendererURLRequestContextSelector : public ResourceMessageFilter::URLRequestContextSelector { public: - RendererURLRequestContextSelector(Profile* profile, + RendererURLRequestContextSelector(content::BrowserContext* browser_context, int render_child_id) - : request_context_(profile->GetRequestContextForRenderProcess( + : request_context_(browser_context->GetRequestContextForRenderProcess( render_child_id)), - media_request_context_(profile->GetRequestContextForMedia()) { + media_request_context_(browser_context->GetRequestContextForMedia()) { } virtual net::URLRequestContext* GetRequestContext( @@ -178,15 +178,16 @@ class RendererURLRequestContextSelector } // namespace -BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) - : RenderProcessHost(profile), - visible_widgets_(0), - backgrounded_(true), - ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( - base::TimeDelta::FromSeconds(5), - this, &BrowserRenderProcessHost::ClearTransportDIBCache)), - accessibility_enabled_(false), - is_initialized_(false) { +BrowserRenderProcessHost::BrowserRenderProcessHost( + content::BrowserContext* browser_context) + : RenderProcessHost(browser_context), + visible_widgets_(0), + backgrounded_(true), + ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( + base::TimeDelta::FromSeconds(5), + this, &BrowserRenderProcessHost::ClearTransportDIBCache)), + accessibility_enabled_(false), + is_initialized_(false) { widget_helper_ = new RenderWidgetHelper(); ChildProcessSecurityPolicy::GetInstance()->Add(id()); @@ -197,7 +198,7 @@ BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) // requests them. // This is for the filesystem sandbox. ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( - id(), profile->GetPath().Append( + id(), browser_context->GetPath().Append( fileapi::SandboxMountPointProvider::kNewFileSystemDirectory), base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_CREATE | @@ -214,14 +215,14 @@ BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) // This is so that we can read and move stuff out of the old filesystem // sandbox. ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( - id(), profile->GetPath().Append( + id(), browser_context->GetPath().Append( fileapi::SandboxMountPointProvider::kOldFileSystemDirectory), base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_WRITE_ATTRIBUTES | base::PLATFORM_FILE_ENUMERATE); // This is so that we can rename the old sandbox out of the way so that we // know we've taken care of it. ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( - id(), profile->GetPath().Append( + id(), browser_context->GetPath().Append( fileapi::SandboxMountPointProvider::kRenamedOldFileSystemDirectory), base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE); @@ -343,57 +344,59 @@ void BrowserRenderProcessHost::CreateMessageFilters() { new RenderMessageFilter( id(), PluginService::GetInstance(), - profile(), - profile()->GetRequestContextForRenderProcess(id()), + browser_context(), + browser_context()->GetRequestContextForRenderProcess(id()), widget_helper_)); channel_->AddFilter(render_message_filter); ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( id(), ChildProcessInfo::RENDER_PROCESS, - &profile()->GetResourceContext(), - new RendererURLRequestContextSelector(profile(), id()), + &browser_context()->GetResourceContext(), + new RendererURLRequestContextSelector(browser_context(), id()), content::GetContentClient()->browser()->GetResourceDispatcherHost()); channel_->AddFilter(resource_message_filter); channel_->AddFilter(new AudioInputRendererHost()); - channel_->AddFilter(new AudioRendererHost(&profile()->GetResourceContext())); + channel_->AddFilter( + new AudioRendererHost(&browser_context()->GetResourceContext())); channel_->AddFilter(new VideoCaptureHost()); channel_->AddFilter( - new AppCacheDispatcherHost(&profile()->GetResourceContext(), id())); + new AppCacheDispatcherHost(&browser_context()->GetResourceContext(), + id())); channel_->AddFilter(new ClipboardMessageFilter()); channel_->AddFilter( - new DOMStorageMessageFilter(id(), profile()->GetWebKitContext())); + new DOMStorageMessageFilter(id(), browser_context()->GetWebKitContext())); channel_->AddFilter( - new IndexedDBDispatcherHost(id(), profile()->GetWebKitContext())); + new IndexedDBDispatcherHost(id(), browser_context()->GetWebKitContext())); channel_->AddFilter( GeolocationDispatcherHost::New( - id(), profile()->GetGeolocationPermissionContext())); + id(), browser_context()->GetGeolocationPermissionContext())); channel_->AddFilter(new GpuMessageFilter(id(), widget_helper_.get())); channel_->AddFilter(new media_stream::MediaStreamDispatcherHost(id())); - channel_->AddFilter(new PepperFileMessageFilter(id(), profile())); + channel_->AddFilter(new PepperFileMessageFilter(id(), browser_context())); channel_->AddFilter( - new PepperMessageFilter(&profile()->GetResourceContext())); + new PepperMessageFilter(&browser_context()->GetResourceContext())); channel_->AddFilter(new speech_input::SpeechInputDispatcherHost(id())); channel_->AddFilter( - new FileSystemDispatcherHost(&profile()->GetResourceContext())); + new FileSystemDispatcherHost(&browser_context()->GetResourceContext())); channel_->AddFilter(new device_orientation::MessageFilter()); channel_->AddFilter( - new BlobMessageFilter(id(), profile()->GetBlobStorageContext())); + new BlobMessageFilter(id(), browser_context()->GetBlobStorageContext())); channel_->AddFilter(new FileUtilitiesMessageFilter(id())); channel_->AddFilter(new MimeRegistryMessageFilter()); channel_->AddFilter(new DatabaseMessageFilter( - profile()->GetDatabaseTracker())); + browser_context()->GetDatabaseTracker())); SocketStreamDispatcherHost* socket_stream_dispatcher_host = new SocketStreamDispatcherHost( - new RendererURLRequestContextSelector(profile(), id()), - &profile()->GetResourceContext()); + new RendererURLRequestContextSelector(browser_context(), id()), + &browser_context()->GetResourceContext()); channel_->AddFilter(socket_stream_dispatcher_host); channel_->AddFilter( new WorkerMessageFilter( id(), - &profile()->GetResourceContext(), + &browser_context()->GetResourceContext(), content::GetContentClient()->browser()->GetResourceDispatcherHost(), NewCallbackWithReturnValue( widget_helper_.get(), &RenderWidgetHelper::GetNextRoutingID))); @@ -405,7 +408,7 @@ void BrowserRenderProcessHost::CreateMessageFilters() { channel_->AddFilter(new TraceMessageFilter()); channel_->AddFilter(new ResolveProxyMsgHelper(NULL)); channel_->AddFilter(new QuotaDispatcherHost( - id(), profile()->GetQuotaManager(), + id(), browser_context()->GetQuotaManager(), content::GetContentClient()->browser()->CreateQuotaPermissionContext())); } @@ -599,7 +602,7 @@ void BrowserRenderProcessHost::PropagateBrowserCommandLineToRenderer( arraysize(kSwitchNames)); // Disable databases in incognito mode. - if (profile()->IsOffTheRecord() && + if (browser_context()->IsOffTheRecord() && !browser_cmd.HasSwitch(switches::kDisableDatabases)) { renderer_cmd->AppendSwitch(switches::kDisableDatabases); } @@ -729,8 +732,8 @@ bool BrowserRenderProcessHost::Send(IPC::Message* msg) { } bool BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { - // If we're about to be deleted, we can no longer trust that our profile is - // valid, so we ignore incoming messages. + // If we're about to be deleted, we can no longer trust that our browser + // context is valid, so we ignore incoming messages. if (deleting_soon_) return false; diff --git a/content/browser/renderer_host/browser_render_process_host.h b/content/browser/renderer_host/browser_render_process_host.h index 9bc9047..9b49481 100644 --- a/content/browser/renderer_host/browser_render_process_host.h +++ b/content/browser/renderer_host/browser_render_process_host.h @@ -42,7 +42,7 @@ class SharedMemory; class BrowserRenderProcessHost : public RenderProcessHost, public ChildProcessLauncher::Client { public: - explicit BrowserRenderProcessHost(Profile* profile); + explicit BrowserRenderProcessHost(content::BrowserContext* browser_context); virtual ~BrowserRenderProcessHost(); // RenderProcessHost implementation (public portion). diff --git a/content/browser/renderer_host/mock_render_process_host.cc b/content/browser/renderer_host/mock_render_process_host.cc index 4b27ce3..87ec8de 100644 --- a/content/browser/renderer_host/mock_render_process_host.cc +++ b/content/browser/renderer_host/mock_render_process_host.cc @@ -6,11 +6,12 @@ #include "content/browser/child_process_security_policy.h" -MockRenderProcessHost::MockRenderProcessHost(Profile* profile) - : RenderProcessHost(profile), - transport_dib_(NULL), - bad_msg_count_(0), - factory_(NULL) { +MockRenderProcessHost::MockRenderProcessHost( + content::BrowserContext* browser_context) + : RenderProcessHost(browser_context), + transport_dib_(NULL), + bad_msg_count_(0), + factory_(NULL) { // Child process security operations can't be unit tested unless we add // ourselves as an existing child process. ChildProcessSecurityPolicy::GetInstance()->Add(id()); @@ -127,8 +128,8 @@ MockRenderProcessHostFactory::~MockRenderProcessHostFactory() { } RenderProcessHost* MockRenderProcessHostFactory::CreateRenderProcessHost( - Profile* profile) const { - MockRenderProcessHost* host = new MockRenderProcessHost(profile); + content::BrowserContext* browser_context) const { + MockRenderProcessHost* host = new MockRenderProcessHost(browser_context); if (host) { processes_.push_back(host); host->SetFactory(this); diff --git a/content/browser/renderer_host/mock_render_process_host.h b/content/browser/renderer_host/mock_render_process_host.h index a785129..7afb95a 100644 --- a/content/browser/renderer_host/mock_render_process_host.h +++ b/content/browser/renderer_host/mock_render_process_host.h @@ -22,7 +22,7 @@ class URLRequestContextGetter; // IPC messages are sent into the message sink for inspection by tests. class MockRenderProcessHost : public RenderProcessHost { public: - explicit MockRenderProcessHost(Profile* profile); + explicit MockRenderProcessHost(content::BrowserContext* browser_context); virtual ~MockRenderProcessHost(); // Provides access to all IPC messages that would have been sent to the @@ -84,7 +84,8 @@ class MockRenderProcessHostFactory : public RenderProcessHostFactory { MockRenderProcessHostFactory(); virtual ~MockRenderProcessHostFactory(); - virtual RenderProcessHost* CreateRenderProcessHost(Profile* profile) const; + virtual RenderProcessHost* CreateRenderProcessHost( + content::BrowserContext* browser_context) const OVERRIDE; // Removes the given MockRenderProcessHost from the MockRenderProcessHost list // without deleting it. When a test deletes a MockRenderProcessHost, we need diff --git a/content/browser/renderer_host/pepper_file_message_filter.cc b/content/browser/renderer_host/pepper_file_message_filter.cc index 1d2660d..b1b9e19 100644 --- a/content/browser/renderer_host/pepper_file_message_filter.cc +++ b/content/browser/renderer_host/pepper_file_message_filter.cc @@ -9,7 +9,7 @@ #include "base/file_util.h" #include "base/platform_file.h" #include "base/process_util.h" -#include "chrome/browser/profiles/profile.h" +#include "content/browser/browser_context.h" #include "content/browser/browser_thread.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/renderer_host/browser_render_process_host.h" @@ -35,10 +35,11 @@ const int kWritePermissions = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_EXCLUSIVE_WRITE | base::PLATFORM_FILE_WRITE_ATTRIBUTES; -PepperFileMessageFilter::PepperFileMessageFilter(int child_id, - Profile* profile) - : child_id_(child_id) { - pepper_path_ = profile->GetPath().Append(FILE_PATH_LITERAL("Pepper Data")); +PepperFileMessageFilter::PepperFileMessageFilter( + int child_id, content::BrowserContext* browser_context) + : child_id_(child_id) { + pepper_path_ = + browser_context->GetPath().Append(FILE_PATH_LITERAL("Pepper Data")); } PepperFileMessageFilter::~PepperFileMessageFilter() { diff --git a/content/browser/renderer_host/pepper_file_message_filter.h b/content/browser/renderer_host/pepper_file_message_filter.h index a241b44..6fa662c 100644 --- a/content/browser/renderer_host/pepper_file_message_filter.h +++ b/content/browser/renderer_host/pepper_file_message_filter.h @@ -18,7 +18,9 @@ #include "ipc/ipc_platform_file.h" #include "webkit/plugins/ppapi/dir_contents.h" -class Profile; +namespace content { +class BrowserContext; +} namespace webkit { namespace ppapi { @@ -29,7 +31,8 @@ class PepperFilePath; // A message filter for Pepper-specific File I/O messages. class PepperFileMessageFilter : public BrowserMessageFilter { public: - PepperFileMessageFilter(int child_id, Profile* profile); + PepperFileMessageFilter(int child_id, + content::BrowserContext* browser_context); // BrowserMessageFilter methods: virtual void OverrideThreadForMessage(const IPC::Message& message, diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index 8812e61..de6d129 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -15,7 +15,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/download/download_types.h" #include "chrome/browser/download/download_util.h" -#include "chrome/browser/profiles/profile.h" +#include "content/browser/browser_context.h" #include "content/browser/browser_thread.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/content_browser_client.h" @@ -270,18 +270,18 @@ class DoomEntriesHelper { RenderMessageFilter::RenderMessageFilter( int render_process_id, PluginService* plugin_service, - Profile* profile, + content::BrowserContext* browser_context, net::URLRequestContextGetter* request_context, RenderWidgetHelper* render_widget_helper) : resource_dispatcher_host_( content::GetContentClient()->browser()->GetResourceDispatcherHost()), plugin_service_(plugin_service), - profile_(profile), + browser_context_(browser_context), request_context_(request_context), - resource_context_(profile->GetResourceContext()), + resource_context_(browser_context->GetResourceContext()), render_widget_helper_(render_widget_helper), - incognito_(profile->IsOffTheRecord()), - webkit_context_(profile->GetWebKitContext()), + incognito_(browser_context->IsOffTheRecord()), + webkit_context_(browser_context->GetWebKitContext()), render_process_id_(render_process_id) { DCHECK(request_context_); diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h index 11a28d6..8cdd496 100644 --- a/content/browser/renderer_host/render_message_filter.h +++ b/content/browser/renderer_host/render_message_filter.h @@ -28,7 +28,6 @@ struct FontDescriptor; class HostContentSettingsMap; -class Profile; class RenderWidgetHelper; struct ViewHostMsg_CreateWindow_Params; struct ViewHostMsg_CreateWorker_Params; @@ -38,6 +37,7 @@ struct WebScreenInfo; } namespace content { +class BrowserContext; class ResourceContext; } @@ -71,7 +71,7 @@ class RenderMessageFilter : public BrowserMessageFilter { // Create the filter. RenderMessageFilter(int render_process_id, PluginService* plugin_service, - Profile* profile, + content::BrowserContext* browser_context, net::URLRequestContextGetter* request_context, RenderWidgetHelper* render_widget_helper); @@ -235,9 +235,9 @@ class RenderMessageFilter : public BrowserMessageFilter { ResourceDispatcherHost* resource_dispatcher_host_; PluginService* plugin_service_; - // The Profile associated with our renderer process. This should only be - // accessed on the UI thread! - Profile* profile_; + // The browser context associated with our renderer process. This should only + // be accessed on the UI thread! + content::BrowserContext* browser_context_; // Contextual information to be used for requests created here. scoped_refptr<net::URLRequestContextGetter> request_context_; diff --git a/content/browser/renderer_host/render_process_host.cc b/content/browser/renderer_host/render_process_host.cc index f942e04..93eac4d 100644 --- a/content/browser/renderer_host/render_process_host.cc +++ b/content/browser/renderer_host/render_process_host.cc @@ -6,6 +6,7 @@ #include "base/rand_util.h" #include "base/sys_info.h" +#include "chrome/browser/profiles/profile.h" #include "content/browser/browser_thread.h" #include "content/browser/child_process_security_policy.h" #include "content/common/child_process_info.h" @@ -59,10 +60,11 @@ size_t GetMaxRendererProcessCount() { } // Returns true if the given host is suitable for launching a new view -// associated with the given profile. -static bool IsSuitableHost(RenderProcessHost* host, Profile* profile, +// associated with the given browser context. +static bool IsSuitableHost(RenderProcessHost* host, + content::BrowserContext* browser_context, RenderProcessHost::Type type) { - if (host->profile() != profile) + if (host->browser_context() != browser_context) return false; RenderProcessHost::Type host_type = RenderProcessHost::TYPE_NORMAL; @@ -90,14 +92,14 @@ void RenderProcessHost::SetMaxRendererProcessCount(size_t count) { max_renderer_count_override = count; } -RenderProcessHost::RenderProcessHost(Profile* profile) +RenderProcessHost::RenderProcessHost(content::BrowserContext* browser_context) : max_page_id_(-1), fast_shutdown_started_(false), deleting_soon_(false), is_extension_process_(false), pending_views_(0), id_(ChildProcessInfo::GenerateChildProcessUniqueId()), - profile_(profile), + browser_context_(browser_context), sudden_termination_allowed_(true), ignore_input_events_(false) { all_hosts.AddWithID(this, id()); @@ -183,17 +185,17 @@ bool RenderProcessHost::ShouldTryToUseExistingProcessHost() { // NOTE: Sometimes it's necessary to create more render processes than // GetMaxRendererProcessCount(), for instance when we want to create - // a renderer process for a profile that has no existing renderers. - // This is OK in moderation, since the GetMaxRendererProcessCount() - // is conservative. + // a renderer process for a browser context that has no existing + // renderers. This is OK in moderation, since the + // GetMaxRendererProcessCount() is conservative. return run_renderer_in_process() || (renderer_process_count >= GetMaxRendererProcessCount()); } // static -RenderProcessHost* RenderProcessHost::GetExistingProcessHost(Profile* profile, - Type type) { +RenderProcessHost* RenderProcessHost::GetExistingProcessHost( + content::BrowserContext* browser_context, Type type) { // First figure out which existing renderers we can use. std::vector<RenderProcessHost*> suitable_renderers; suitable_renderers.reserve(all_hosts.size()); @@ -201,7 +203,7 @@ RenderProcessHost* RenderProcessHost::GetExistingProcessHost(Profile* profile, iterator iter(AllHostsIterator()); while (!iter.IsAtEnd()) { if (run_renderer_in_process() || - IsSuitableHost(iter.GetCurrentValue(), profile, type)) + IsSuitableHost(iter.GetCurrentValue(), browser_context, type)) suitable_renderers.push_back(iter.GetCurrentValue()); iter.Advance(); diff --git a/content/browser/renderer_host/render_process_host.h b/content/browser/renderer_host/render_process_host.h index 5035cd4..0b3b3e9 100644 --- a/content/browser/renderer_host/render_process_host.h +++ b/content/browser/renderer_host/render_process_host.h @@ -13,17 +13,21 @@ #include "base/process.h" #include "base/process_util.h" #include "base/time.h" +#include "chrome/browser/profiles/profile.h" #include "ipc/ipc_channel_proxy.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/surface/transport_dib.h" -class Profile; struct ViewMsg_SwapOut_Params; namespace base { class SharedMemory; } +namespace content { +class BrowserContext; +} + namespace net { class URLRequestContextGetter; } @@ -64,11 +68,17 @@ class RenderProcessHost : public IPC::Channel::Sender, bool was_extension_renderer; }; - explicit RenderProcessHost(Profile* profile); + explicit RenderProcessHost(content::BrowserContext* browser_context); virtual ~RenderProcessHost(); - // Returns the user profile associated with this renderer process. - Profile* profile() const { return profile_; } + // Returns the user browser context associated with this renderer process. + content::BrowserContext* browser_context() const { return browser_context_; } + + // Returns the profile. + // TEMPORARY; http://crbug.com/76788 + Profile* profile() const { + return Profile::FromBrowserContext(browser_context()); + } // Returns the unique ID for this child process. This can be used later in // a call to FromID() to get back to this object (this is used to avoid @@ -262,12 +272,13 @@ class RenderProcessHost : public IPC::Channel::Sender, // RenderProcessHost rather than creating a new one. static bool ShouldTryToUseExistingProcessHost(); - // Get an existing RenderProcessHost associated with the given profile, if - // possible. The renderer process is chosen randomly from suitable renderers - // that share the same profile and type. + // Get an existing RenderProcessHost associated with the given browser + // context, if possible. The renderer process is chosen randomly from + // suitable renderers that share the same context and type. // Returns NULL if no suitable renderer process is available, in which case // the caller is free to create a new renderer. - static RenderProcessHost* GetExistingProcessHost(Profile* profile, Type type); + static RenderProcessHost* GetExistingProcessHost( + content::BrowserContext* browser_context, Type type); // Overrides the default heuristic for limiting the max renderer process // count. This is useful for unit testing process limit behaviors. @@ -305,7 +316,7 @@ class RenderProcessHost : public IPC::Channel::Sender, // The globally-unique identifier for this RPH. int id_; - Profile* profile_; + content::BrowserContext* browser_context_; // set of listeners that expect the renderer process to close std::set<int> listeners_expecting_close_; @@ -337,7 +348,7 @@ class RenderProcessHostFactory { public: virtual ~RenderProcessHostFactory() {} virtual RenderProcessHost* CreateRenderProcessHost( - Profile* profile) const = 0; + content::BrowserContext* browser_context) const = 0; }; #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_ diff --git a/content/browser/renderer_host/render_view_host_delegate.h b/content/browser/renderer_host/render_view_host_delegate.h index 8d4ea10..c1ae931 100644 --- a/content/browser/renderer_host/render_view_host_delegate.h +++ b/content/browser/renderer_host/render_view_host_delegate.h @@ -27,7 +27,6 @@ class BookmarkNode; struct ContextMenuParams; class GURL; struct NativeWebKeyboardEvent; -class Profile; struct RendererPreferences; class RenderProcessHost; class RenderViewHost; @@ -40,6 +39,10 @@ struct WebMenuItem; class WebKeyboardEvent; struct WebPreferences; +namespace content { +class BrowserContext; +} + namespace gfx { class Point; class Rect; @@ -295,7 +298,8 @@ class RenderViewHostDelegate : public IPC::Channel::Listener { // Return a dummy RendererPreferences object that will be used by the renderer // associated with the owning RenderViewHost. - virtual RendererPreferences GetRendererPrefs(Profile* profile) const = 0; + virtual RendererPreferences GetRendererPrefs( + content::BrowserContext* browser_context) const = 0; // Returns a WebPreferences object that will be used by the renderer // associated with the owning render view host. diff --git a/content/browser/site_instance.cc b/content/browser/site_instance.cc index 442c807..cd68b7b 100644 --- a/content/browser/site_instance.cc +++ b/content/browser/site_instance.cc @@ -71,15 +71,16 @@ RenderProcessHost* SiteInstance::GetProcess() { // See if we should reuse an old process if (RenderProcessHost::ShouldTryToUseExistingProcessHost()) process_ = RenderProcessHost::GetExistingProcessHost( - browsing_instance_->profile(), GetRendererType()); + browsing_instance_->browser_context(), GetRendererType()); // Otherwise (or if that fails), create a new one. if (!process_) { if (render_process_host_factory_) { process_ = render_process_host_factory_->CreateRenderProcessHost( - browsing_instance_->profile()); + browsing_instance_->browser_context()); } else { - process_ = new BrowserRenderProcessHost(browsing_instance_->profile()); + process_ = + new BrowserRenderProcessHost(browsing_instance_->browser_context()); } } @@ -102,7 +103,7 @@ void SiteInstance::SetSite(const GURL& url) { // Remember that this SiteInstance has been used to load a URL, even if the // URL is invalid. has_site_ = true; - site_ = GetSiteForURL(browsing_instance_->profile(), url); + site_ = GetSiteForURL(browsing_instance_->browser_context(), url); // Now that we have a site, register it with the BrowsingInstance. This // ensures that we won't create another SiteInstance for this site within @@ -126,28 +127,32 @@ bool SiteInstance::HasWrongProcessForURL(const GURL& url) const { // If the effective URL is an extension (e.g., for hosted apps) but the // process is not (or vice versa), make sure we notice and fix it. - GURL effective_url = GetEffectiveURL(browsing_instance_->profile(), url); + GURL effective_url = GetEffectiveURL(browsing_instance_->browser_context(), + url); return effective_url.SchemeIs(chrome::kExtensionScheme) != process_->is_extension_process(); } /*static*/ -SiteInstance* SiteInstance::CreateSiteInstance(Profile* profile) { - return new SiteInstance(new BrowsingInstance(profile)); +SiteInstance* SiteInstance::CreateSiteInstance( + content::BrowserContext* browser_context) { + return new SiteInstance(new BrowsingInstance(browser_context)); } /*static*/ -SiteInstance* SiteInstance::CreateSiteInstanceForURL(Profile* profile, - const GURL& url) { +SiteInstance* SiteInstance::CreateSiteInstanceForURL( + content::BrowserContext* browser_context, const GURL& url) { // This BrowsingInstance may be deleted if it returns an existing // SiteInstance. - scoped_refptr<BrowsingInstance> instance(new BrowsingInstance(profile)); + scoped_refptr<BrowsingInstance> instance( + new BrowsingInstance(browser_context)); return instance->GetSiteInstanceForURL(url); } /*static*/ -GURL SiteInstance::GetSiteForURL(Profile* profile, const GURL& real_url) { - GURL url = GetEffectiveURL(profile, real_url); +GURL SiteInstance::GetSiteForURL(content::BrowserContext* browser_context, + const GURL& real_url) { + GURL url = GetEffectiveURL(browser_context, real_url); // URLs with no host should have an empty site. GURL site; @@ -181,10 +186,10 @@ GURL SiteInstance::GetSiteForURL(Profile* profile, const GURL& real_url) { } /*static*/ -bool SiteInstance::IsSameWebSite(Profile* profile, +bool SiteInstance::IsSameWebSite(content::BrowserContext* browser_context, const GURL& real_url1, const GURL& real_url2) { - GURL url1 = GetEffectiveURL(profile, real_url1); - GURL url2 = GetEffectiveURL(profile, real_url2); + GURL url1 = GetEffectiveURL(browser_context, real_url1); + GURL url2 = GetEffectiveURL(browser_context, real_url2); // We infer web site boundaries based on the registered domain name of the // top-level page and the scheme. We do not pay attention to the port if @@ -209,8 +214,10 @@ bool SiteInstance::IsSameWebSite(Profile* profile, } /*static*/ -GURL SiteInstance::GetEffectiveURL(Profile* profile, const GURL& url) { - return content::GetContentClient()->browser()->GetEffectiveURL(profile, url); +GURL SiteInstance::GetEffectiveURL(content::BrowserContext* browser_context, + const GURL& url) { + return content::GetContentClient()->browser()-> + GetEffectiveURL(browser_context, url); } /*static*/ diff --git a/content/browser/site_instance.h b/content/browser/site_instance.h index 4d3692c..84a0bdc 100644 --- a/content/browser/site_instance.h +++ b/content/browser/site_instance.h @@ -13,6 +13,10 @@ class BrowsingInstance; +namespace content { +class BrowserContext; +} + /////////////////////////////////////////////////////////////////////////////// // // SiteInstance class @@ -36,8 +40,8 @@ class BrowsingInstance; // SiteInstance is used. // // In --process-per-site, we consolidate all SiteInstances for a given site, -// throughout the entire profile. This ensures that only one process will be -// dedicated to each site. +// throughout the entire browser context. This ensures that only one process +// will be dedicated to each site. // // Each NavigationEntry for a TabContents points to the SiteInstance that // rendered it. Each RenderViewHost also points to the SiteInstance that it is @@ -119,18 +123,19 @@ class SiteInstance : public base::RefCounted<SiteInstance>, // // TODO(creis): This may be an argument to build a pass_refptr<T> class, as // Darin suggests. - static SiteInstance* CreateSiteInstance(Profile* profile); + static SiteInstance* CreateSiteInstance( + content::BrowserContext* browser_context); // Factory method to get the appropriate SiteInstance for the given URL, in // a new BrowsingInstance. Use this instead of CreateSiteInstance when you // know the URL, since it allows special site grouping rules to be applied // (for example, to group chrome-ui pages into the same instance). - static SiteInstance* CreateSiteInstanceForURL(Profile* profile, - const GURL& url); + static SiteInstance* CreateSiteInstanceForURL( + content::BrowserContext* browser_context, const GURL& url); // Returns the site for the given URL, which includes only the scheme and // registered domain. Returns an empty GURL if the URL has no host. - static GURL GetSiteForURL(Profile* profile, const GURL& url); + static GURL GetSiteForURL(content::BrowserContext* context, const GURL& url); // Return whether both URLs are part of the same web site, for the purpose of // assigning them to processes accordingly. The decision is currently based @@ -139,7 +144,7 @@ class SiteInstance : public base::RefCounted<SiteInstance>, // the same process if they can communicate with other via JavaScript. // (e.g., docs.google.com and mail.google.com have DOM access to each other // if they both set their document.domain properties to google.com.) - static bool IsSameWebSite(Profile* profile, + static bool IsSameWebSite(content::BrowserContext* browser_context, const GURL& url1, const GURL& url2); // Returns the renderer type for this URL. @@ -158,7 +163,8 @@ class SiteInstance : public base::RefCounted<SiteInstance>, explicit SiteInstance(BrowsingInstance* browsing_instance); // Get the effective URL for the given actual URL. - static GURL GetEffectiveURL(Profile* profile, const GURL& url); + static GURL GetEffectiveURL(content::BrowserContext* browser_context, + const GURL& url); // Returns the type of renderer process this instance belongs in, for grouping // purposes. diff --git a/content/browser/site_instance_unittest.cc b/content/browser/site_instance_unittest.cc index f286d14..c34e9c3 100644 --- a/content/browser/site_instance_unittest.cc +++ b/content/browser/site_instance_unittest.cc @@ -28,10 +28,11 @@ const char kSameAsAnyInstanceURL[] = "about:internets"; class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { public: - virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { + virtual bool UseWebUIForURL(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE { return HasWebUIScheme(url); } - virtual bool HasWebUIScheme(const GURL& url) const { + virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { return url.SchemeIs(chrome::kChromeUIScheme); } }; @@ -42,7 +43,7 @@ class SiteInstanceTestBrowserClient : public content::MockContentBrowserClient { return &factory_; } - virtual bool ShouldUseProcessPerSite(Profile* profile, + virtual bool ShouldUseProcessPerSite(content::BrowserContext* browser_context, const GURL& effective_url) OVERRIDE { return false; } @@ -52,7 +53,8 @@ class SiteInstanceTestBrowserClient : public content::MockContentBrowserClient { url == GURL(chrome::kAboutCrashURL); } - virtual GURL GetEffectiveURL(Profile* profile, const GURL& url) OVERRIDE { + virtual GURL GetEffectiveURL(content::BrowserContext* browser_context, + const GURL& url) OVERRIDE { return url; } diff --git a/content/browser/ssl/ssl_policy_backend.cc b/content/browser/ssl/ssl_policy_backend.cc index 82c4653..77689a9 100644 --- a/content/browser/ssl/ssl_policy_backend.cc +++ b/content/browser/ssl/ssl_policy_backend.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,7 +9,7 @@ #include "content/browser/tab_contents/navigation_controller.h" SSLPolicyBackend::SSLPolicyBackend(NavigationController* controller) - : ssl_host_state_(controller->profile()->GetSSLHostState()) { + : ssl_host_state_(controller->browser_context()->GetSSLHostState()) { DCHECK(controller); } diff --git a/content/browser/tab_contents/interstitial_page.cc b/content/browser/tab_contents/interstitial_page.cc index d4ba3dd..b711e4c 100644 --- a/content/browser/tab_contents/interstitial_page.cc +++ b/content/browser/tab_contents/interstitial_page.cc @@ -401,7 +401,8 @@ void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host, tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TITLE); } -RendererPreferences InterstitialPage::GetRendererPrefs(Profile* profile) const { +RendererPreferences InterstitialPage::GetRendererPrefs( + content::BrowserContext* browser_context) const { return renderer_preferences_; } diff --git a/content/browser/tab_contents/interstitial_page.h b/content/browser/tab_contents/interstitial_page.h index 1c4dec2..e8b3663 100644 --- a/content/browser/tab_contents/interstitial_page.h +++ b/content/browser/tab_contents/interstitial_page.h @@ -127,7 +127,8 @@ class InterstitialPage : public NotificationObserver, virtual void UpdateTitle(RenderViewHost* render_view_host, int32 page_id, const string16& title) OVERRIDE; - virtual RendererPreferences GetRendererPrefs(Profile* profile) const OVERRIDE; + virtual RendererPreferences GetRendererPrefs( + content::BrowserContext* browser_context) const OVERRIDE; // Invoked with the NavigationEntry that is going to be added to the // navigation controller. diff --git a/content/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc index 3ffbad2..6276678 100644 --- a/content/browser/tab_contents/navigation_controller.cc +++ b/content/browser/tab_contents/navigation_controller.cc @@ -9,7 +9,7 @@ #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/profiles/profile.h" +#include "content/browser/browser_context.h" #include "content/browser/browser_url_handler.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" @@ -110,9 +110,9 @@ bool NavigationController::check_for_repost_ = true; NavigationController::NavigationController( TabContents* contents, - Profile* profile, + content::BrowserContext* browser_context, SessionStorageNamespace* session_storage_namespace) - : profile_(profile), + : browser_context_(browser_context), pending_entry_(NULL), last_committed_entry_index_(-1), pending_entry_index_(-1), @@ -123,10 +123,10 @@ NavigationController::NavigationController( needs_reload_(false), session_storage_namespace_(session_storage_namespace), pending_reload_(NO_RELOAD) { - DCHECK(profile_); + DCHECK(browser_context_); if (!session_storage_namespace_) { session_storage_namespace_ = new SessionStorageNamespace( - profile_->GetWebKitContext()); + browser_context_->GetWebKitContext()); } } @@ -221,7 +221,7 @@ bool NavigationController::IsInitialNavigation() { // static NavigationEntry* NavigationController::CreateNavigationEntry( const GURL& url, const GURL& referrer, PageTransition::Type transition, - Profile* profile) { + content::BrowserContext* browser_context) { // Allow the browser URL handler to rewrite the URL. This will, for example, // remove "view-source:" from the beginning of the URL to get the URL that // will actually be loaded. This real URL won't be shown to the user, just @@ -229,7 +229,7 @@ NavigationEntry* NavigationController::CreateNavigationEntry( GURL loaded_url(url); bool reverse_on_redirect = false; BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( - &loaded_url, profile, &reverse_on_redirect); + &loaded_url, browser_context, &reverse_on_redirect); NavigationEntry* entry = new NavigationEntry( NULL, // The site instance for tabs is sent on navigation @@ -456,7 +456,7 @@ void NavigationController::UpdateVirtualURLToURL( NavigationEntry* entry, const GURL& new_url) { GURL new_virtual_url(new_url); if (BrowserURLHandler::GetInstance()->ReverseURLRewrite( - &new_virtual_url, entry->virtual_url(), profile_)) { + &new_virtual_url, entry->virtual_url(), browser_context_)) { entry->set_virtual_url(new_virtual_url); } } @@ -478,7 +478,7 @@ void NavigationController::LoadURL(const GURL& url, const GURL& referrer, needs_reload_ = false; NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition, - profile_); + browser_context_); LoadEntry(entry); } diff --git a/content/browser/tab_contents/navigation_controller.h b/content/browser/tab_contents/navigation_controller.h index a4132ce..b2d254a 100644 --- a/content/browser/tab_contents/navigation_controller.h +++ b/content/browser/tab_contents/navigation_controller.h @@ -14,18 +14,19 @@ #include "base/memory/linked_ptr.h" #include "base/time.h" #include "googleurl/src/gurl.h" +#include "chrome/browser/profiles/profile.h" #include "content/browser/ssl/ssl_manager.h" #include "content/common/navigation_types.h" #include "content/common/page_transition_types.h" class NavigationEntry; -class Profile; class SessionStorageNamespace; class SiteInstance; class TabContents; struct ViewHostMsg_FrameNavigate_Params; namespace content { +class BrowserContext; struct LoadCommittedDetails; } @@ -46,18 +47,24 @@ class NavigationController { // --------------------------------------------------------------------------- NavigationController(TabContents* tab_contents, - Profile* profile, + content::BrowserContext* browser_context, SessionStorageNamespace* session_storage_namespace); ~NavigationController(); - // Returns the profile for this controller. It can never be NULL. - Profile* profile() const { - return profile_; + // Returns the browser context for this controller. It can never be NULL. + content::BrowserContext* browser_context() const { + return browser_context_; + } + + // Sets the browser context for this controller. + void set_browser_context(content::BrowserContext* browser_context) { + browser_context_ = browser_context; } - // Sets the profile for this controller. - void set_profile(Profile* profile) { - profile_ = profile; + // Returns the profile. + // TEMPORARY; http://crbug.com/76788 + Profile* profile() const { + return Profile::FromBrowserContext(browser_context()); } // Initializes this NavigationController with the given saved navigations, @@ -319,10 +326,11 @@ class NavigationController { // Creates navigation entry and translates the virtual url to a real one. // Used when navigating to a new URL using LoadURL. - static NavigationEntry* CreateNavigationEntry(const GURL& url, - const GURL& referrer, - PageTransition::Type transition, - Profile* profile); + static NavigationEntry* CreateNavigationEntry( + const GURL& url, + const GURL& referrer, + PageTransition::Type transition, + content::BrowserContext* browser_context); private: class RestoreHelper; @@ -410,8 +418,8 @@ class NavigationController { // --------------------------------------------------------------------------- - // The user profile associated with this controller - Profile* profile_; + // The user browser context associated with this controller. + content::BrowserContext* browser_context_; // List of NavigationEntry for this tab typedef std::vector<linked_ptr<NavigationEntry> > NavigationEntries; diff --git a/content/browser/tab_contents/render_view_host_manager.cc b/content/browser/tab_contents/render_view_host_manager.cc index 3386f24..003f359 100644 --- a/content/browser/tab_contents/render_view_host_manager.cc +++ b/content/browser/tab_contents/render_view_host_manager.cc @@ -56,14 +56,14 @@ RenderViewHostManager::~RenderViewHostManager() { } } -void RenderViewHostManager::Init(Profile* profile, +void RenderViewHostManager::Init(content::BrowserContext* browser_context, SiteInstance* site_instance, int routing_id) { // Create a RenderViewHost, once we have an instance. It is important to // immediately give this SiteInstance to a RenderViewHost so that it is // ref counted. if (!site_instance) - site_instance = SiteInstance::CreateSiteInstance(profile); + site_instance = SiteInstance::CreateSiteInstance(browser_context); render_view_host_ = RenderViewHostFactory::Create( site_instance, render_view_delegate_, routing_id, delegate_-> GetControllerForRenderManager().session_storage_namespace()); @@ -346,15 +346,17 @@ bool RenderViewHostManager::ShouldSwapProcessesForNavigation( // site, which might already be committed to a Web UI URL (such as the NTP). const GURL& current_url = (cur_entry) ? cur_entry->url() : render_view_host_->site_instance()->site(); - Profile* profile = delegate_->GetControllerForRenderManager().profile(); + content::BrowserContext* browser_context = + delegate_->GetControllerForRenderManager().browser_context(); const content::WebUIFactory* web_ui_factory = content::WebUIFactory::Get(); - if (web_ui_factory->UseWebUIForURL(profile, current_url)) { + if (web_ui_factory->UseWebUIForURL(browser_context, current_url)) { // Force swap if it's not an acceptable URL for Web UI. - if (!web_ui_factory->IsURLAcceptableForWebUI(profile, new_entry->url())) + if (!web_ui_factory->IsURLAcceptableForWebUI(browser_context, + new_entry->url())) return true; } else { // Force swap if it's a Web UI URL. - if (web_ui_factory->UseWebUIForURL(profile, new_entry->url())) + if (web_ui_factory->UseWebUIForURL(browser_context, new_entry->url())) return true; } @@ -393,7 +395,7 @@ SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( const GURL& dest_url = entry.url(); NavigationController& controller = delegate_->GetControllerForRenderManager(); - Profile* profile = controller.profile(); + content::BrowserContext* browser_context = controller.browser_context(); // If the entry has an instance already we should use it, unless the URL // is part of an app that has been installed or uninstalled since the last @@ -437,8 +439,9 @@ SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( // want to use the curr_instance if it has no site, since it will have a // RenderProcessHost of TYPE_NORMAL. Create a new SiteInstance for this // URL instead (with the correct process type). - if (content::WebUIFactory::Get()->UseWebUIForURL(profile, dest_url)) { - return SiteInstance::CreateSiteInstanceForURL(profile, dest_url); + if (content::WebUIFactory::Get()->UseWebUIForURL(browser_context, + dest_url)) { + return SiteInstance::CreateSiteInstanceForURL(browser_context, dest_url); } // Normally the "site" on the SiteInstance is set lazily when the load @@ -487,7 +490,7 @@ SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( // Use the current SiteInstance for same site navigations, as long as the // process type is correct. (The URL may have been installed as an app since // the last time we visited it.) - if (SiteInstance::IsSameWebSite(profile, current_url, dest_url) && + if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && !curr_instance->HasWrongProcessForURL(dest_url)) { return curr_instance; } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { @@ -497,7 +500,7 @@ SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( // Pages), keeping them in the same process. When you navigate away from // that page, we want to explicity ignore that BrowsingInstance and group // this page into the appropriate SiteInstance for its URL. - return SiteInstance::CreateSiteInstanceForURL(profile, dest_url); + return SiteInstance::CreateSiteInstanceForURL(browser_context, dest_url); } else { // Start the new renderer in a new SiteInstance, but in the current // BrowsingInstance. It is important to immediately give this new diff --git a/content/browser/tab_contents/render_view_host_manager.h b/content/browser/tab_contents/render_view_host_manager.h index cd6d865..d074546 100644 --- a/content/browser/tab_contents/render_view_host_manager.h +++ b/content/browser/tab_contents/render_view_host_manager.h @@ -14,13 +14,16 @@ #include "content/common/notification_registrar.h" #include "content/browser/site_instance.h" -class WebUI; class InterstitialPage; class NavigationController; class NavigationEntry; -class Profile; -class RenderWidgetHostView; class RenderViewHost; +class RenderWidgetHostView; +class WebUI; + +namespace content { +class BrowserContext; +} // Manages RenderViewHosts for a TabContents. Normally there is only one and // it is easy to do. But we can also have transitions of processes (and hence @@ -87,11 +90,11 @@ class RenderViewHostManager virtual ~RenderViewHostManager(); // For arguments, see TabContents constructor. - void Init(Profile* profile, + void Init(content::BrowserContext* browser_context, SiteInstance* site_instance, int routing_id); - // Returns the currently actuive RenderViewHost. + // Returns the currently active RenderViewHost. // // This will be non-NULL between Init() and Shutdown(). You may want to NULL // check it in many cases, however. Windows can send us messages during the diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 090dd08..fe1abaf 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -16,7 +16,7 @@ #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_request_limiter.h" #include "chrome/browser/download/download_util.h" -#include "chrome/browser/profiles/profile.h" +#include "content/browser/browser_context.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/content_browser_client.h" #include "content/browser/debugger/devtools_manager.h" @@ -122,7 +122,7 @@ BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { #endif ViewMsg_Navigate_Type::Value GetNavigationType( - Profile* profile, const NavigationEntry& entry, + content::BrowserContext* browser_context, const NavigationEntry& entry, NavigationController::ReloadType reload_type) { switch (reload_type) { case NavigationController::RELOAD: @@ -134,7 +134,7 @@ ViewMsg_Navigate_Type::Value GetNavigationType( } if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION && - profile->DidLastSessionExitCleanly()) + browser_context->DidLastSessionExitCleanly()) return ViewMsg_Navigate_Type::RESTORE; return ViewMsg_Navigate_Type::NORMAL; @@ -153,7 +153,7 @@ void MakeNavigateParams(const NavigationEntry& entry, params->transition = entry.transition_type(); params->state = entry.content_state(); params->navigation_type = - GetNavigationType(controller.profile(), entry, reload_type); + GetNavigationType(controller.browser_context(), entry, reload_type); params->request_time = base::Time::Now(); } @@ -162,14 +162,14 @@ void MakeNavigateParams(const NavigationEntry& entry, // TabContents ---------------------------------------------------------------- -TabContents::TabContents(Profile* profile, +TabContents::TabContents(content::BrowserContext* browser_context, SiteInstance* site_instance, int routing_id, const TabContents* base_tab_contents, SessionStorageNamespace* session_storage_namespace) : delegate_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(controller_( - this, profile, session_storage_namespace)), + this, browser_context, session_storage_namespace)), ALLOW_THIS_IN_INITIALIZER_LIST(view_( TabContentsView::Create(this))), ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)), @@ -198,7 +198,7 @@ TabContents::TabContents(Profile* profile, temporary_zoom_settings_(false), content_restrictions_(0) { - render_manager_.Init(profile, site_instance, routing_id); + render_manager_.Init(browser_context, site_instance, routing_id); // We have the initial size of the view be based on the size of the passed in // tab contents (normally a tab from the same window). @@ -538,7 +538,7 @@ bool TabContents::NavigateToEntry( // Double check that here. int enabled_bindings = dest_render_view_host->enabled_bindings(); bool is_allowed_in_web_ui_renderer = content::GetContentClient()-> - browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(), + browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(), entry.url()); CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) || is_allowed_in_web_ui_renderer); @@ -593,9 +593,10 @@ TabContents* TabContents::Clone() { // We create a new SiteInstance so that the new tab won't share processes // with the old one. This can be changed in the future if we need it to share // processes for some reason. - TabContents* tc = new TabContents(profile(), - SiteInstance::CreateSiteInstance(profile()), - MSG_ROUTING_NONE, this, NULL); + TabContents* tc = new TabContents( + browser_context(), + SiteInstance::CreateSiteInstance(browser_context()), + MSG_ROUTING_NONE, this, NULL); tc->controller().CopyStateFrom(controller_); return tc; } @@ -606,7 +607,7 @@ void TabContents::ShowPageInfo(const GURL& url, if (!delegate_) return; - delegate_->ShowPageInfo(profile(), url, ssl, show_history); + delegate_->ShowPageInfo(browser_context(), url, ssl, show_history); } ConstrainedWindow* TabContents::CreateConstrainedDialog( @@ -720,7 +721,7 @@ void TabContents::WillClose(ConstrainedWindow* window) { void TabContents::OnSavePage() { // If we can not save the page, try to download it. if (!SavePackage::IsSavableContents(contents_mime_type())) { - DownloadManager* dlm = profile()->GetDownloadManager(); + DownloadManager* dlm = browser_context()->GetDownloadManager(); const GURL& current_page_url = GetURL(); if (dlm && current_page_url.is_valid()) { dlm->DownloadUrl(current_page_url, GURL(), "", this); @@ -752,7 +753,7 @@ bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, } void TabContents::OnSaveURL(const GURL& url) { - DownloadManager* dlm = profile()->GetDownloadManager(); + DownloadManager* dlm = browser_context()->GetDownloadManager(); dlm->DownloadUrl(url, GetURL(), "", this); } @@ -800,7 +801,7 @@ void TabContents::SystemDragEnded() { } double TabContents::GetZoomLevel() const { - HostZoomMap* zoom_map = profile()->GetHostZoomMap(); + HostZoomMap* zoom_map = browser_context()->GetHostZoomMap(); if (!zoom_map) return 0; @@ -1122,7 +1123,8 @@ WebUI* TabContents::GetWebUIForCurrentState() { } WebUI::TypeID TabContents::GetWebUITypeForCurrentState() { - return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL()); + return content::WebUIFactory::Get()->GetWebUIType(browser_context(), + GetURL()); } void TabContents::DidNavigateMainFramePostCommit( @@ -1310,7 +1312,8 @@ TabContents::GetRendererManagementDelegate() { return &render_manager_; } -RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const { +RendererPreferences TabContents::GetRendererPrefs( + content::BrowserContext* browser_context) const { return renderer_preferences_; } @@ -1686,7 +1689,7 @@ void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh, WebPreferences TabContents::GetWebkitPrefs() { WebPreferences web_prefs = content::GetContentClient()->browser()->GetWebkitPrefs( - render_view_host()->process()->profile(), false); + render_view_host()->process()->browser_context(), false); // Force accelerated compositing and 2d canvas off for chrome:, about: and // chrome-devtools: pages. diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 4e04552..a2eb522 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -15,6 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "base/string16.h" +#include "chrome/browser/profiles/profile.h" #include "content/browser/download/save_package.h" #include "content/browser/javascript_dialogs.h" #include "content/browser/renderer_host/render_view_host_delegate.h" @@ -40,7 +41,6 @@ class Rect; class DownloadItem; class LoadNotificationDetails; -class Profile; struct RendererPreferences; class RenderViewHost; class SessionStorageNamespace; @@ -80,7 +80,7 @@ class TabContents : public PageNavigator, // tab contentses to share the same session storage (part of the WebStorage // spec) space. This is useful when restoring tabs, but most callers should // pass in NULL which will cause a new SessionStorageNamespace to be created. - TabContents(Profile* profile, + TabContents(content::BrowserContext* browser_context, SiteInstance* site_instance, int routing_id, const TabContents* base_tab_contents, @@ -102,9 +102,17 @@ class TabContents : public PageNavigator, NavigationController& controller() { return controller_; } const NavigationController& controller() const { return controller_; } - // Returns the user profile associated with this TabContents (via the + // Returns the user browser context associated with this TabContents (via the // NavigationController). - Profile* profile() const { return controller_.profile(); } + content::BrowserContext* browser_context() const { + return controller_.browser_context(); + } + + // Returns the profile. + // TEMPORARY; http://crbug.com/76788 + Profile* profile() const { + return Profile::FromBrowserContext(browser_context()); + } // Returns the SavePackage which manages the page saving job. May be NULL. SavePackage* save_package() const { return save_package_.get(); } @@ -664,7 +672,8 @@ class TabContents : public PageNavigator, virtual void RunBeforeUnloadConfirm(const RenderViewHost* rvh, const string16& message, IPC::Message* reply_msg) OVERRIDE; - virtual RendererPreferences GetRendererPrefs(Profile* profile) const OVERRIDE; + virtual RendererPreferences GetRendererPrefs( + content::BrowserContext* browser_context) const OVERRIDE; virtual WebPreferences GetWebkitPrefs() OVERRIDE; virtual void OnUserGesture() OVERRIDE; virtual void OnIgnoredUIEvent() OVERRIDE; diff --git a/content/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc index 784450a..334ba63 100644 --- a/content/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -145,7 +145,7 @@ bool TabContentsDelegate::ExecuteContextMenuCommand(int command) { return false; } -void TabContentsDelegate::ShowPageInfo(Profile* profile, +void TabContentsDelegate::ShowPageInfo(content::BrowserContext* browser_context, const GURL& url, const NavigationEntry::SSLStatus& ssl, bool show_history) { diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h index 52bc318..af2056e 100644 --- a/content/browser/tab_contents/tab_contents_delegate.h +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -17,6 +17,7 @@ #include "webkit/glue/window_open_disposition.h" namespace content { +class BrowserContext; class JavaScriptDialogCreator; } @@ -35,7 +36,6 @@ class DownloadItem; class GURL; class HtmlDialogUIDelegate; struct NativeWebKeyboardEvent; -class Profile; class RenderViewHost; class TabContents; @@ -215,7 +215,7 @@ class TabContentsDelegate { // |url| is the url of the page/frame the info applies to, |ssl| is the SSL // information for that page/frame. If |show_history| is true, a section // showing how many times that URL has been visited is added to the page info. - virtual void ShowPageInfo(Profile* profile, + virtual void ShowPageInfo(content::BrowserContext* browser_context, const GURL& url, const NavigationEntry::SSLStatus& ssl, bool show_history); diff --git a/content/browser/webui/empty_web_ui_factory.cc b/content/browser/webui/empty_web_ui_factory.cc index fd29847..4e4b8eb 100644 --- a/content/browser/webui/empty_web_ui_factory.cc +++ b/content/browser/webui/empty_web_ui_factory.cc @@ -17,13 +17,13 @@ WebUI* EmptyWebUIFactory::CreateWebUIForURL(TabContents* source, return NULL; } -WebUI::TypeID EmptyWebUIFactory::GetWebUIType(Profile* profile, - const GURL& url) const { +WebUI::TypeID EmptyWebUIFactory::GetWebUIType( + content::BrowserContext* browser_context, const GURL& url) const { return WebUI::kNoWebUI; } -bool EmptyWebUIFactory::UseWebUIForURL(Profile* profile, - const GURL& url) const { +bool EmptyWebUIFactory::UseWebUIForURL( + content::BrowserContext* browser_context, const GURL& url) const { return false; } @@ -31,8 +31,9 @@ bool EmptyWebUIFactory::HasWebUIScheme(const GURL& url) const { return false; } -bool EmptyWebUIFactory::IsURLAcceptableForWebUI(Profile* profile, - const GURL& url) const { +bool EmptyWebUIFactory::IsURLAcceptableForWebUI( + content::BrowserContext* browser_context, + const GURL& url) const { return false; } diff --git a/content/browser/webui/empty_web_ui_factory.h b/content/browser/webui/empty_web_ui_factory.h index 6ca8fca..ce5c0d1 100644 --- a/content/browser/webui/empty_web_ui_factory.h +++ b/content/browser/webui/empty_web_ui_factory.h @@ -17,13 +17,14 @@ class EmptyWebUIFactory : public content::WebUIFactory { static EmptyWebUIFactory* GetInstance(); virtual WebUI* CreateWebUIForURL(TabContents* source, - const GURL& url) const; - virtual WebUI::TypeID GetWebUIType(Profile* profile, - const GURL& url) const; - virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const; - virtual bool HasWebUIScheme(const GURL& url) const; - virtual bool IsURLAcceptableForWebUI(Profile* profile, - const GURL& url) const; + const GURL& url) const OVERRIDE; + virtual WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE; + virtual bool UseWebUIForURL(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE; + virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE; + virtual bool IsURLAcceptableForWebUI(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE; protected: EmptyWebUIFactory(); diff --git a/content/browser/webui/web_ui_factory.h b/content/browser/webui/web_ui_factory.h index a1c6560..74c20df 100644 --- a/content/browser/webui/web_ui_factory.h +++ b/content/browser/webui/web_ui_factory.h @@ -8,12 +8,13 @@ #include "content/browser/webui/web_ui.h" -class Profile; class TabContents; class GURL; namespace content { +class BrowserContext; + // Interface for an object which controls which URLs are considered WebUI URLs // and creates WebUI instances for given URLs. class WebUIFactory { @@ -26,11 +27,12 @@ class WebUIFactory { // Gets the WebUI type for the given URL. This will return kNoWebUI if the // corresponding call to CreateWebUIForURL would fail, or something non-NULL // if CreateWebUIForURL would succeed. - virtual WebUI::TypeID GetWebUIType(Profile* profile, + virtual WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context, const GURL& url) const = 0; // Shorthand for the above, but returns a simple yes/no. - virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const = 0; + virtual bool UseWebUIForURL(content::BrowserContext* browser_context, + const GURL& url) const = 0; // Returns true if the url has a scheme for WebUI. This differs from the above // in that it only checks the scheme; it is faster and can be used to @@ -40,7 +42,7 @@ class WebUIFactory { // Returns true if the given URL can be loaded by Web UI system. This allows // URLs with WebUI types (as above) and also URLs that can be loaded by // normal tabs such as javascript: URLs or about:hang. - virtual bool IsURLAcceptableForWebUI(Profile* profile, + virtual bool IsURLAcceptableForWebUI(content::BrowserContext* browser_context, const GURL& url) const = 0; virtual ~WebUIFactory() {} diff --git a/content/content_browser.gypi b/content/content_browser.gypi index c81d6bf..122e161 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -53,6 +53,7 @@ 'browser/appcache/chrome_appcache_service.h', 'browser/browser_child_process_host.cc', 'browser/browser_child_process_host.h', + 'browser/browser_context.h', 'browser/browser_message_filter.cc', 'browser/browser_message_filter.h', 'browser/browser_thread.cc', |