diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_init.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 7 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 35 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 9 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 80 | ||||
-rw-r--r-- | chrome/browser/profile.h | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 14 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 2 |
8 files changed, 121 insertions, 38 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index ba95e1f..a83bf12 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -45,7 +45,6 @@ #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "grit/theme_resources.h" -#include "net/base/cookie_monster.h" #include "webkit/glue/webkit_glue.h" #if defined(OS_WIN) @@ -404,9 +403,6 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, } } - if (command_line_.HasSwitch(switches::kEnableFileCookies)) - net::CookieMonster::EnableFileScheme(); - if (command_line_.HasSwitch(switches::kUserAgent)) { webkit_glue::SetUserAgent(WideToUTF8( command_line_.GetSwitchValue(switches::kUserAgent))); diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 8c9736c..6660a73 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -49,6 +49,7 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/net_resources.h" +#include "net/base/cookie_monster.h" #include "net/base/net_module.h" #include "net/http/http_network_session.h" @@ -365,6 +366,12 @@ int BrowserMain(const MainFunctionParams& parameters) { CheckForWin2000(); } + if (parsed_command_line.HasSwitch(switches::kEnableFileCookies)) { + // Enable cookie storage for file:// URLs. Must do this before the first + // Profile (and therefore the first CookieMonster) is created. + net::CookieMonster::EnableFileScheme(); + } + // Initialize histogram statistics gathering system. StatisticsRecorder statistics; diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 85a33c9..1c18ed4 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -16,6 +16,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" +#include "chrome/common/url_constants.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_cache.h" #include "net/http/http_network_layer.h" @@ -155,6 +156,26 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia( } // static +ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForExtensions( + Profile* profile, const FilePath& cookie_store_path) { + DCHECK(!profile->IsOffTheRecord()); + ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); + + // All we care about for extensions is the cookie store. + DCHECK(!cookie_store_path.empty()); + context->cookie_db_.reset(new SQLitePersistentCookieStore( + cookie_store_path.ToWStringHack(), + g_browser_process->db_thread()->message_loop())); + context->cookie_store_ = new net::CookieMonster(context->cookie_db_.get()); + + // Enable cookies for extension URLs only. + const char* schemes[] = {chrome::kExtensionScheme}; + context->cookie_store_->SetCookieableSchemes(schemes, 1); + + return context; +} + +// static ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord( Profile* profile) { DCHECK(profile->IsOffTheRecord()); @@ -184,6 +205,20 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia( } // static +ChromeURLRequestContext* +ChromeURLRequestContext::CreateOffTheRecordForExtensions(Profile* profile) { + DCHECK(profile->IsOffTheRecord()); + ChromeURLRequestContext* context = new ChromeURLRequestContext(profile); + context->cookie_store_ = new net::CookieMonster; + + // Enable cookies for extension URLs only. + const char* schemes[] = {chrome::kExtensionScheme}; + context->cookie_store_->SetCookieableSchemes(schemes, 1); + + return context; +} + +// static ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia( Profile* profile, const FilePath& disk_cache_path, bool off_the_record) { URLRequestContext* original_context = diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 6f392a7..55af609 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -38,6 +38,11 @@ class ChromeURLRequestContext : public URLRequestContext, static ChromeURLRequestContext* CreateOriginalForMedia(Profile *profile, const FilePath& disk_cache_path); + // Create an instance for an original profile for extensions. This is expected + // to get called on UI thread. + static ChromeURLRequestContext* CreateOriginalForExtensions(Profile *profile, + const FilePath& cookie_store_path); + // Create an instance for use with an OTR profile. This is expected to get // called on the UI thread. static ChromeURLRequestContext* CreateOffTheRecord(Profile* profile); @@ -46,6 +51,10 @@ class ChromeURLRequestContext : public URLRequestContext, static ChromeURLRequestContext* CreateOffTheRecordForMedia(Profile* profile, const FilePath& disk_cache_path); + // Create an instance of request context for OTR profile for extensions. + static ChromeURLRequestContext* CreateOffTheRecordForExtensions( + Profile* profile); + // Clean up UI thread resources. This is expected to get called on the UI // thread before the instance is deleted on the IO thread. void CleanupOnUIThread(); diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 9406216..1c76c49 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -34,6 +34,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/net/cookie_monster_sqlite.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -49,6 +50,16 @@ static const int kCreateSessionServiceDelayMS = 500; // Profile::GetDefaultRequestContext. URLRequestContext* Profile::default_request_context_; +static void CleanupRequestContext(ChromeURLRequestContext* context) { + if (context) { + context->CleanupOnUIThread(); + + // Clean up request context on IO thread. + g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE, + context); + } +} + // static void Profile::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); @@ -89,6 +100,7 @@ class OffTheRecordProfileImpl : public Profile, explicit OffTheRecordProfileImpl(Profile* real_profile) : profile_(real_profile), media_request_context_(NULL), + extensions_request_context_(NULL), start_time_(Time::Now()) { request_context_ = ChromeURLRequestContext::CreateOffTheRecord(this); request_context_->AddRef(); @@ -105,15 +117,9 @@ class OffTheRecordProfileImpl : public Profile, } virtual ~OffTheRecordProfileImpl() { - if (request_context_) { - request_context_->CleanupOnUIThread(); - - // Clean up request context on IO thread. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(request_context_, - &base::RefCountedThreadSafe<URLRequestContext>::Release)); - request_context_ = NULL; - } + CleanupRequestContext(request_context_); + CleanupRequestContext(media_request_context_); + CleanupRequestContext(extensions_request_context_); NotificationService::current()->RemoveObserver( this, NotificationType::BROWSER_CLOSED, @@ -251,6 +257,18 @@ class OffTheRecordProfileImpl : public Profile, return media_request_context_; } + URLRequestContext* GetRequestContextForExtensions() { + if (!extensions_request_context_) { + extensions_request_context_ = + ChromeURLRequestContext::CreateOffTheRecordForExtensions(this); + extensions_request_context_->AddRef(); + + DCHECK(extensions_request_context_->cookie_store()); + } + + return extensions_request_context_; + } + virtual SessionService* GetSessionService() { // Don't save any sessions when off the record. return NULL; @@ -358,6 +376,8 @@ class OffTheRecordProfileImpl : public Profile, // The context for requests for media resources. ChromeURLRequestContext* media_request_context_; + ChromeURLRequestContext* extensions_request_context_; + // The download manager that only stores downloaded items in memory. scoped_refptr<DownloadManager> download_manager_; @@ -382,6 +402,7 @@ ProfileImpl::ProfileImpl(const FilePath& path) : path_(path), request_context_(NULL), media_request_context_(NULL), + extensions_request_context_(NULL), history_service_created_(false), created_web_data_service_(false), created_download_manager_(false), @@ -508,28 +529,12 @@ ProfileImpl::~ProfileImpl() { spellchecker_->Release(); } - if (request_context_) { - request_context_->CleanupOnUIThread(); - - if (default_request_context_ == request_context_) - default_request_context_ = NULL; - - // Clean up request context on IO thread. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(request_context_, - &base::RefCountedThreadSafe<URLRequestContext>::Release)); - request_context_ = NULL; - } - - if (media_request_context_) { - media_request_context_->CleanupOnUIThread(); + if (default_request_context_ == request_context_) + default_request_context_ = NULL; - // Clean up request context on IO thread. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(media_request_context_, - &base::RefCountedThreadSafe<URLRequestContext>::Release)); - media_request_context_ = NULL; - } + CleanupRequestContext(request_context_); + CleanupRequestContext(media_request_context_); + CleanupRequestContext(extensions_request_context_); // HistoryService may call into the BookmarkModel, as such we need to // delete HistoryService before the BookmarkModel. The destructor for @@ -709,6 +714,21 @@ URLRequestContext* ProfileImpl::GetRequestContextForMedia() { return media_request_context_; } +URLRequestContext* ProfileImpl::GetRequestContextForExtensions() { + if (!extensions_request_context_) { + FilePath cookie_path = GetPath(); + cookie_path = cookie_path.Append(chrome::kExtensionsCookieFilename); + + extensions_request_context_ = + ChromeURLRequestContext::CreateOriginalForExtensions(this, cookie_path); + extensions_request_context_->AddRef(); + + DCHECK(extensions_request_context_->cookie_store()); + } + + return extensions_request_context_; +} + HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { if (!history_service_created_) { history_service_created_ = true; diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index a83d76a..6ec129c 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -32,6 +32,7 @@ class PrefService; class SessionService; class SpellChecker; class SSLHostState; +class SQLitePersistentCookieStore; class TabRestoreService; class TemplateURLFetcher; class TemplateURLModel; @@ -189,6 +190,10 @@ class Profile { // profile. virtual URLRequestContext* GetRequestContextForMedia() = 0; + // Returns the request context used for extension-related requests. This + // is only used for a separate cookie store currently. + virtual URLRequestContext* GetRequestContextForExtensions() = 0; + // Returns the session service for this profile. This may return NULL. If // this profile supports a session service (it isn't off the record), and // the session service hasn't yet been created, this forces creation of @@ -311,6 +316,7 @@ class ProfileImpl : public Profile, virtual bool HasCreatedDownloadManager() const; virtual URLRequestContext* GetRequestContext(); virtual URLRequestContext* GetRequestContextForMedia(); + virtual URLRequestContext* GetRequestContextForExtensions(); virtual SessionService* GetSessionService(); virtual void ShutdownSessionService(); virtual bool HasSessionService() const; @@ -378,6 +384,8 @@ class ProfileImpl : public Profile, ChromeURLRequestContext* media_request_context_; + ChromeURLRequestContext* extensions_request_context_; + scoped_refptr<DownloadManager> download_manager_; scoped_refptr<HistoryService> history_service_; scoped_refptr<WebDataService> web_data_service_; diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 594163f..5d26559 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -27,6 +27,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/render_messages.h" +#include "chrome/common/url_constants.h" #include "net/base/cookie_monster.h" #include "net/base/mime_util.h" #include "net/base/load_flags.h" @@ -125,6 +126,7 @@ ResourceMessageFilter::ResourceMessageFilter( ALLOW_THIS_IN_INITIALIZER_LIST(resolve_proxy_msg_helper_(this, NULL)), request_context_(profile->GetRequestContext()), media_request_context_(profile->GetRequestContextForMedia()), + extensions_request_context_(profile->GetRequestContextForExtensions()), profile_(profile), render_widget_helper_(render_widget_helper), audio_renderer_host_(audio_renderer_host), @@ -384,15 +386,19 @@ void ResourceMessageFilter::OnMsgCreateWidget(int opener_id, void ResourceMessageFilter::OnSetCookie(const GURL& url, const GURL& policy_url, const std::string& cookie) { - if (request_context_->cookie_policy()->CanSetCookie(url, policy_url)) - request_context_->cookie_store()->SetCookie(url, cookie); + URLRequestContext* context = url.SchemeIs(chrome::kExtensionScheme) ? + extensions_request_context_.get() : request_context_.get(); + if (context->cookie_policy()->CanSetCookie(url, policy_url)) + context->cookie_store()->SetCookie(url, cookie); } void ResourceMessageFilter::OnGetCookies(const GURL& url, const GURL& policy_url, std::string* cookies) { - if (request_context_->cookie_policy()->CanGetCookies(url, policy_url)) - *cookies = request_context_->cookie_store()->GetCookies(url); + URLRequestContext* context = url.SchemeIs(chrome::kExtensionScheme) ? + extensions_request_context_.get() : request_context_.get(); + if (context->cookie_policy()->CanGetCookies(url, policy_url)) + *cookies = context->cookie_store()->GetCookies(url); } void ResourceMessageFilter::OnGetDataDir(std::wstring* data_dir) { diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 8a406f0..2f6629d 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -255,6 +255,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, // A request context specific for media resources. scoped_refptr<URLRequestContext> media_request_context_; + scoped_refptr<URLRequestContext> extensions_request_context_; + // A pointer to the profile associated with this filter. // // DANGER! Do not dereference this pointer! This class lives on the I/O thread |