diff options
37 files changed, 600 insertions, 243 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc index 08b12f6..e346278 100644 --- a/chrome/browser/alternate_nav_url_fetcher.cc +++ b/chrome/browser/alternate_nav_url_fetcher.cc @@ -14,6 +14,8 @@ #include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_service.h" #include "content/public/common/url_fetcher.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" #include "grit/theme_resources_standard.h" @@ -191,7 +193,12 @@ void AlternateNavURLFetcher::StartFetch(NavigationController* controller) { GURL(alternate_nav_url_), content::URLFetcher::HEAD, this)); fetcher_->SetRequestContext( controller_->GetBrowserContext()->GetRequestContext()); - fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); + + content::WebContents* web_contents = controller_->GetWebContents(); + fetcher_->AssociateWithRenderView( + web_contents->GetURL(), + web_contents->GetRenderProcessHost()->GetID(), + web_contents->GetRenderViewHost()->GetRoutingID()); fetcher_->Start(); } diff --git a/chrome/browser/chromeos/imageburner/burn_manager.cc b/chrome/browser/chromeos/imageburner/burn_manager.cc index 31264fa..2cd99b2 100644 --- a/chrome/browser/chromeos/imageburner/burn_manager.cc +++ b/chrome/browser/chromeos/imageburner/burn_manager.cc @@ -295,8 +295,9 @@ void BurnManager::FetchConfigFile(Delegate* delegate) { config_fetcher_.reset(content::URLFetcher::Create( config_file_url_, content::URLFetcher::GET, this)); - config_fetcher_->StartWithRequestContextGetter( + config_fetcher_->SetRequestContext( g_browser_process->system_request_context()); + config_fetcher_->Start(); } void BurnManager::OnURLFetchComplete(const content::URLFetcher* source) { diff --git a/chrome/browser/extensions/api/webrequest/webrequest_api_unittest.cc b/chrome/browser/extensions/api/webrequest/webrequest_api_unittest.cc index 4b73729..f04bf79 100644 --- a/chrome/browser/extensions/api/webrequest/webrequest_api_unittest.cc +++ b/chrome/browser/extensions/api/webrequest/webrequest_api_unittest.cc @@ -10,9 +10,11 @@ #include "base/file_util.h" #include "base/json/json_string_value_serializer.h" #include "base/memory/weak_ptr.h" +#include "base/message_loop.h" #include "base/path_service.h" #include "base/stl_util.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/content_settings/cookie_settings.h" #include "chrome/browser/extensions/api/webrequest/webrequest_api.h" #include "chrome/browser/extensions/api/webrequest/webrequest_api_constants.h" #include "chrome/browser/extensions/api/webrequest/webrequest_api_helpers.h" @@ -24,6 +26,7 @@ #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_pref_service.h" #include "chrome/test/base/testing_profile.h" +#include "content/test/test_browser_thread.h" #include "net/base/auth.h" #include "net/base/net_util.h" #include "net/url_request/url_request_test_util.h" @@ -95,18 +98,26 @@ class TestIPCSender : public IPC::Message::Sender { }; class ExtensionWebRequestTest : public testing::Test { + public: + ExtensionWebRequestTest() + : ui_thread_(content::BrowserThread::UI, &message_loop_), + io_thread_(content::BrowserThread::IO, &message_loop_) {} + protected: - virtual void SetUp() { + virtual void SetUp() OVERRIDE { event_router_ = new ExtensionEventRouterForwarder(); enable_referrers_.Init( prefs::kEnableReferrers, profile_.GetTestingPrefService(), NULL); network_delegate_.reset(new ChromeNetworkDelegate( - event_router_.get(), NULL, NULL, &profile_, &enable_referrers_)); + event_router_.get(), NULL, NULL, &profile_, + CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_)); context_ = new TestURLRequestContext(); context_->set_network_delegate(network_delegate_.get()); } - MessageLoopForIO io_loop_; + MessageLoopForIO message_loop_; + content::TestBrowserThread ui_thread_; + content::TestBrowserThread io_thread_; TestingProfile profile_; TestDelegate delegate_; BooleanPrefMember enable_referrers_; @@ -404,18 +415,26 @@ struct HeaderModificationTest { class ExtensionWebRequestHeaderModificationTest : public testing::TestWithParam<HeaderModificationTest> { + public: + ExtensionWebRequestHeaderModificationTest() + : ui_thread_(content::BrowserThread::UI, &message_loop_), + io_thread_(content::BrowserThread::IO, &message_loop_) {} + protected: virtual void SetUp() { event_router_ = new ExtensionEventRouterForwarder(); enable_referrers_.Init( prefs::kEnableReferrers, profile_.GetTestingPrefService(), NULL); network_delegate_.reset(new ChromeNetworkDelegate( - event_router_.get(), NULL, NULL, &profile_, &enable_referrers_)); + event_router_.get(), NULL, NULL, &profile_, + CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_)); context_ = new TestURLRequestContext(); context_->set_network_delegate(network_delegate_.get()); } - MessageLoopForIO io_loop_; + MessageLoopForIO message_loop_; + content::TestBrowserThread ui_thread_; + content::TestBrowserThread io_thread_; TestingProfile profile_; TestDelegate delegate_; BooleanPrefMember enable_referrers_; diff --git a/chrome/browser/extensions/extension_warning_set.cc b/chrome/browser/extensions/extension_warning_set.cc index 7743743..95225ae 100644 --- a/chrome/browser/extensions/extension_warning_set.cc +++ b/chrome/browser/extensions/extension_warning_set.cc @@ -144,6 +144,7 @@ void ExtensionWarningSet::NotifyWarningsOnUI( CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); Profile* profile = reinterpret_cast<Profile*>(profile_id); if (!profile || + !g_browser_process->profile_manager() || !g_browser_process->profile_manager()->IsValidProfile(profile)) { return; } diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 0288173..498a4e4 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -392,6 +392,7 @@ void IOThread::Init() { NULL, NULL, NULL, + NULL, &system_enable_referrers_)); globals_->host_resolver.reset( CreateGlobalHostResolver(net_log_)); diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc index c0e350f..ea86b3d 100644 --- a/chrome/browser/net/chrome_network_delegate.cc +++ b/chrome/browser/net/chrome_network_delegate.cc @@ -6,6 +6,8 @@ #include "base/logging.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/content_settings/cookie_settings.h" +#include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/extensions/api/webrequest/webrequest_api.h" #include "chrome/browser/extensions/extension_event_router_forwarder.h" @@ -19,6 +21,8 @@ #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_view_host.h" +#include "content/public/browser/resource_request_info.h" +#include "net/base/cookie_monster.h" #include "net/base/host_port_pair.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" @@ -99,14 +103,17 @@ ChromeNetworkDelegate::ChromeNetworkDelegate( ExtensionInfoMap* extension_info_map, const policy::URLBlacklistManager* url_blacklist_manager, void* profile, + CookieSettings* cookie_settings, BooleanPrefMember* enable_referrers) : event_router_(event_router), profile_(profile), + cookie_settings_(cookie_settings), extension_info_map_(extension_info_map), enable_referrers_(enable_referrers), url_blacklist_manager_(url_blacklist_manager) { DCHECK(event_router); DCHECK(enable_referrers); + DCHECK(!profile || cookie_settings); } ChromeNetworkDelegate::~ChromeNetworkDelegate() {} @@ -234,3 +241,55 @@ ChromeNetworkDelegate::OnAuthRequired( profile_, extension_info_map_.get(), request, auth_info, callback, credentials); } + +bool ChromeNetworkDelegate::CanGetCookies( + const net::URLRequest* request, + const net::CookieList& cookie_list) { + // NULL during tests, or when we're running in the system context. + if (!cookie_settings_) + return true; + + bool allow = cookie_settings_->IsReadingCookieAllowed( + request->url(), request->first_party_for_cookies()); + + int render_process_id = -1; + int render_view_id = -1; + if (content::ResourceRequestInfo::GetRenderViewForRequest( + request, &render_process_id, &render_view_id)) { + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&TabSpecificContentSettings::CookiesRead, + render_process_id, render_view_id, + request->url(), cookie_list, !allow)); + } + + return allow; +} + +bool ChromeNetworkDelegate::CanSetCookie( + const net::URLRequest* request, + const std::string& cookie_line, + net::CookieOptions* options) { + // NULL during tests, or when we're running in the system context. + if (!cookie_settings_) + return true; + + bool allow = cookie_settings_->IsSettingCookieAllowed( + request->url(), request->first_party_for_cookies()); + + if (cookie_settings_->IsCookieSessionOnly(request->url())) + options->set_force_session(); + + int render_process_id = -1; + int render_view_id = -1; + if (content::ResourceRequestInfo::GetRenderViewForRequest( + request, &render_process_id, &render_view_id)) { + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&TabSpecificContentSettings::CookieChanged, + render_process_id, render_view_id, + request->url(), cookie_line, *options, !allow)); + } + + return allow; +} diff --git a/chrome/browser/net/chrome_network_delegate.h b/chrome/browser/net/chrome_network_delegate.h index 74b7146..a582c38 100644 --- a/chrome/browser/net/chrome_network_delegate.h +++ b/chrome/browser/net/chrome_network_delegate.h @@ -11,6 +11,7 @@ #include "base/memory/ref_counted.h" #include "net/base/network_delegate.h" +class CookieSettings; class ExtensionEventRouterForwarder; class ExtensionInfoMap; class PrefService; @@ -26,16 +27,18 @@ class URLBlacklistManager; // add hooks into the network stack. class ChromeNetworkDelegate : public net::NetworkDelegate { public: - // If |profile| is NULL, events will be broadcasted to all profiles, otherwise - // they will only be sent to the specified profile. + // If |profile| is NULL, events will be broadcasted to all profiles, + // otherwise they will only be sent to the specified profile. // |enable_referrers| should be initialized on the UI thread (see below) - // beforehand. This object's owner is responsible for cleaning it up - // at shutdown. + // beforehand. This object's owner is responsible for cleaning it up at + // shutdown. If |cookie_settings| is NULL, all cookies are enabled, + // otherwise, the settings are enforced on all observed network requests. ChromeNetworkDelegate( ExtensionEventRouterForwarder* event_router, ExtensionInfoMap* extension_info_map, const policy::URLBlacklistManager* url_blacklist_manager, void* profile, + CookieSettings* cookie_settings, BooleanPrefMember* enable_referrers); virtual ~ChromeNetworkDelegate(); @@ -74,9 +77,15 @@ class ChromeNetworkDelegate : public net::NetworkDelegate { const net::AuthChallengeInfo& auth_info, const AuthCallback& callback, net::AuthCredentials* credentials) OVERRIDE; + virtual bool CanGetCookies(const net::URLRequest* request, + const net::CookieList& cookie_list) OVERRIDE; + virtual bool CanSetCookie(const net::URLRequest* request, + const std::string& cookie_line, + net::CookieOptions* options) OVERRIDE; scoped_refptr<ExtensionEventRouterForwarder> event_router_; void* profile_; + scoped_refptr<CookieSettings> cookie_settings_; scoped_refptr<ExtensionInfoMap> extension_info_map_; diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 2d950c9..305a7f3 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -450,6 +450,7 @@ void ProfileIOData::LazyInitialize() const { profile_params_->extension_info_map, url_blacklist_manager_.get(), profile_params_->profile, + profile_params_->cookie_settings, &enable_referrers_)); fraudulent_certificate_reporter_.reset( diff --git a/chrome/browser/search_engines/template_url_fetcher.cc b/chrome/browser/search_engines/template_url_fetcher.cc index d943699..0be74e7 100644 --- a/chrome/browser/search_engines/template_url_fetcher.cc +++ b/chrome/browser/search_engines/template_url_fetcher.cc @@ -18,6 +18,9 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_source.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/web_contents.h" #include "content/public/common/url_fetcher.h" #include "content/public/common/url_fetcher_delegate.h" #include "net/base/load_flags.h" @@ -33,6 +36,7 @@ class TemplateURLFetcher::RequestDelegate const string16& keyword, const GURL& osdd_url, const GURL& favicon_url, + content::WebContents* web_contents, TemplateURLFetcherCallbacks* callbacks, ProviderType provider_type); @@ -78,6 +82,7 @@ TemplateURLFetcher::RequestDelegate::RequestDelegate( const string16& keyword, const GURL& osdd_url, const GURL& favicon_url, + content::WebContents* web_contents, TemplateURLFetcherCallbacks* callbacks, ProviderType provider_type) : ALLOW_THIS_IN_INITIALIZER_LIST(url_fetcher_(content::URLFetcher::Create( @@ -101,7 +106,14 @@ TemplateURLFetcher::RequestDelegate::RequestDelegate( } url_fetcher_->SetRequestContext(fetcher->profile()->GetRequestContext()); - url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); + // Can be NULL during tests. + if (web_contents) { + url_fetcher_->AssociateWithRenderView( + web_contents->GetURL(), + web_contents->GetRenderProcessHost()->GetID(), + web_contents->GetRenderViewHost()->GetRoutingID()); + } + url_fetcher_->Start(); } @@ -240,6 +252,7 @@ void TemplateURLFetcher::ScheduleDownload( const string16& keyword, const GURL& osdd_url, const GURL& favicon_url, + content::WebContents* web_contents, TemplateURLFetcherCallbacks* callbacks, ProviderType provider_type) { DCHECK(osdd_url.is_valid()); @@ -281,7 +294,7 @@ void TemplateURLFetcher::ScheduleDownload( } requests_->push_back( - new RequestDelegate(this, keyword, osdd_url, favicon_url, + new RequestDelegate(this, keyword, osdd_url, favicon_url, web_contents, owned_callbacks.release(), provider_type)); } diff --git a/chrome/browser/search_engines/template_url_fetcher.h b/chrome/browser/search_engines/template_url_fetcher.h index d82ef0a..647e925 100644 --- a/chrome/browser/search_engines/template_url_fetcher.h +++ b/chrome/browser/search_engines/template_url_fetcher.h @@ -15,6 +15,10 @@ class Profile; class TemplateURL; class TemplateURLFetcherCallbacks; +namespace content { +class WebContents; +} + // TemplateURLFetcher is responsible for downloading OpenSearch description // documents, creating a TemplateURL from the OSDD, and adding the TemplateURL // to the TemplateURLService. Downloading is done in the background. @@ -33,9 +37,12 @@ class TemplateURLFetcher { // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, // it is downloaded. If successful and the result can be parsed, a TemplateURL // is added to the TemplateURLService. Takes ownership of |callbacks|. + // |web_contents| specifies which WebContents displays the page the OSDD is + // downloaded for. |web_contents| must not be NULL, except for during tests. void ScheduleDownload(const string16& keyword, const GURL& osdd_url, const GURL& favicon_url, + content::WebContents* web_contents, TemplateURLFetcherCallbacks* callbacks, ProviderType provider_type); diff --git a/chrome/browser/search_engines/template_url_fetcher_unittest.cc b/chrome/browser/search_engines/template_url_fetcher_unittest.cc index 1745678f..c8e0e5a 100644 --- a/chrome/browser/search_engines/template_url_fetcher_unittest.cc +++ b/chrome/browser/search_engines/template_url_fetcher_unittest.cc @@ -147,8 +147,8 @@ void TemplateURLFetcherTest::StartDownload( GURL osdd_url = test_server_.GetURL("files/" + osdd_file_name); GURL favicon_url; test_util_.profile()->GetTemplateURLFetcher()->ScheduleDownload( - keyword, osdd_url, favicon_url, new TemplateURLFetcherTestCallbacks(this), - provider_type); + keyword, osdd_url, favicon_url, NULL, + new TemplateURLFetcherTestCallbacks(this), provider_type); } void TemplateURLFetcherTest::WaitForDownloadToFinish() { diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index 24b4513..a61104d 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -73,6 +73,10 @@ struct WebPluginAction; // void Start(const GURL* url, net::URLRequestContextGetter* context) { // fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); // fetcher_->SetRequestContext(context); +// fetcher_->AssociateWithRenderView( +// proxy_->GetRenderViewHost()->GetSiteInstance()->GetSite(), +// proxy_->GetRenderViewHost()->GetProcess()->GetID(), +// proxy_->GetRenderViewHost()->GetRoutingID()); // fetcher_->Start(); // } // diff --git a/chrome/browser/ui/search_engines/search_engine_tab_helper.cc b/chrome/browser/ui/search_engines/search_engine_tab_helper.cc index 0b8c5b3..8bb3110 100644 --- a/chrome/browser/ui/search_engines/search_engine_tab_helper.cc +++ b/chrome/browser/ui/search_engines/search_engine_tab_helper.cc @@ -125,6 +125,7 @@ void SearchEngineTabHelper::OnPageHasOSDD( keyword, doc_url, base_entry->GetFavicon().url, + web_contents(), new TemplateURLFetcherUICallbacks(this, web_contents()), provider_type); } diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher.cc b/chrome/service/cloud_print/cloud_print_url_fetcher.cc index b19a7c2..137fa7e 100644 --- a/chrome/service/cloud_print/cloud_print_url_fetcher.cc +++ b/chrome/service/cloud_print/cloud_print_url_fetcher.cc @@ -124,7 +124,8 @@ void CloudPrintURLFetcher::OnURLFetchComplete( // reached. Try again. Set up the request headers again because the token // may have changed. SetupRequestHeaders(); - request_->StartWithRequestContextGetter(GetRequestContextGetter()); + request_->SetRequestContext(GetRequestContextGetter()); + request_->Start(); } } } diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc index 0f26b2c..c440872 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.cc +++ b/content/browser/renderer_host/resource_dispatcher_host.cc @@ -1435,36 +1435,6 @@ void ResourceDispatcherHost::OnSSLCertificateError( SSLManager::OnSSLCertificateError(this, request, ssl_info, is_hsts_host); } -bool ResourceDispatcherHost::CanGetCookies( - const net::URLRequest* request, - const net::CookieList& cookie_list) const { - VLOG(1) << "OnGetCookies: " << request->url().spec(); - int render_process_id, render_view_id; - if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) - return false; - - const ResourceRequestInfoImpl* info = InfoForRequest(request); - - return content::GetContentClient()->browser()->AllowGetCookie( - request->url(), request->first_party_for_cookies(), cookie_list, - info->GetContext(), render_process_id, render_view_id); -} - -bool ResourceDispatcherHost::CanSetCookie(const net::URLRequest* request, - const std::string& cookie_line, - net::CookieOptions* options) const { - VLOG(1) << "OnSetCookie: " << request->url().spec(); - - int render_process_id, render_view_id; - if (!RenderViewForRequest(request, &render_process_id, &render_view_id)) - return false; - - const ResourceRequestInfoImpl* info = InfoForRequest(request); - return content::GetContentClient()->browser()->AllowSetCookie( - request->url(), request->first_party_for_cookies(), cookie_line, - info->GetContext(), render_process_id, render_view_id, options); -} - void ResourceDispatcherHost::OnResponseStarted(net::URLRequest* request) { VLOG(1) << "OnResponseStarted: " << request->url().spec(); ResourceRequestInfoImpl* info = InfoForRequest(request); diff --git a/content/browser/renderer_host/resource_dispatcher_host.h b/content/browser/renderer_host/resource_dispatcher_host.h index f6213e4..fb38569 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.h +++ b/content/browser/renderer_host/resource_dispatcher_host.h @@ -184,11 +184,6 @@ class CONTENT_EXPORT ResourceDispatcherHost : public net::URLRequest::Delegate { virtual void OnSSLCertificateError(net::URLRequest* request, const net::SSLInfo& ssl_info, bool fatal) OVERRIDE; - virtual bool CanGetCookies(const net::URLRequest* request, - const net::CookieList& cookie_list) const OVERRIDE; - virtual bool CanSetCookie(const net::URLRequest* request, - const std::string& cookie_line, - net::CookieOptions* options) const OVERRIDE; virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; virtual void OnReadCompleted(net::URLRequest* request, int bytes_read) OVERRIDE; diff --git a/content/browser/renderer_host/resource_request_info_impl.cc b/content/browser/renderer_host/resource_request_info_impl.cc index 817815a..92c9240 100644 --- a/content/browser/renderer_host/resource_request_info_impl.cc +++ b/content/browser/renderer_host/resource_request_info_impl.cc @@ -7,6 +7,7 @@ #include "content/browser/renderer_host/resource_handler.h" #include "content/browser/ssl/ssl_client_auth_handler.h" #include "content/browser/worker_host/worker_service_impl.h" +#include "content/common/net/url_request_user_data.h" #include "content/public/browser/resource_dispatcher_host_login_delegate.h" #include "net/url_request/url_request.h" #include "webkit/blob/blob_data.h" @@ -47,6 +48,21 @@ void ResourceRequestInfo::AllocateForTesting( info->AssociateWithRequest(request); } +// static +bool ResourceRequestInfo::GetRenderViewForRequest( + const net::URLRequest* request, + int* render_process_id, + int* render_view_id) { + URLRequestUserData* user_data = static_cast<URLRequestUserData*>( + request->GetUserData(URLRequestUserData::kUserDataKey)); + if (!user_data) + return false; + *render_process_id = user_data->render_process_id(); + *render_view_id = user_data->render_view_id(); + return true; +} + + ResourceRequestInfoImpl::ResourceRequestInfoImpl( ResourceHandler* handler, ProcessType process_type, @@ -171,6 +187,13 @@ bool ResourceRequestInfoImpl::GetAssociatedRenderView( void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest* request) { request->SetUserData(NULL, this); + int render_process_id; + int render_view_id; + if (GetAssociatedRenderView(&render_process_id, &render_view_id)) { + request->SetUserData( + URLRequestUserData::kUserDataKey, + new URLRequestUserData(render_process_id, render_view_id)); + } } void ResourceRequestInfoImpl::set_resource_handler( diff --git a/content/common/net/url_fetcher_impl.cc b/content/common/net/url_fetcher_impl.cc index be44289..f17d887 100644 --- a/content/common/net/url_fetcher_impl.cc +++ b/content/common/net/url_fetcher_impl.cc @@ -20,6 +20,7 @@ #include "base/string_util.h" #include "base/threading/thread.h" #include "base/timer.h" +#include "content/common/net/url_request_user_data.h" #include "content/public/common/url_fetcher_delegate.h" #include "content/public/common/url_fetcher_factory.h" #include "googleurl/src/gurl.h" @@ -243,6 +244,9 @@ class URLFetcherImpl::Core // Read buffer scoped_refptr<net::URLRequestContextGetter> request_context_getter_; // Cookie/cache info for the request + int render_process_id_; // The RenderView associated with the + int render_view_id_; // request + GURL first_party_for_cookies_; // The first party URL for the request net::ResponseCookies cookies_; // Response cookies net::HttpRequestHeaders extra_request_headers_; scoped_refptr<net::HttpResponseHeaders> response_headers_; @@ -543,6 +547,8 @@ URLFetcherImpl::Core::Core(URLFetcherImpl* fetcher, load_flags_(net::LOAD_NORMAL), response_code_(RESPONSE_CODE_INVALID), buffer_(new net::IOBuffer(kBufferSize)), + render_process_id_(-1), + render_view_id_(-1), was_fetched_via_proxy_(false), is_chunked_upload_(false), num_retries_(0), @@ -757,6 +763,9 @@ void URLFetcherImpl::Core::RetryOrCompleteUrlFetch() { backoff_delay = base::TimeDelta(); } request_context_getter_ = NULL; + render_process_id_ = -1; + render_view_id_ = -1; + first_party_for_cookies_ = GURL(); bool posted = delegate_loop_proxy_->PostTask( FROM_HERE, base::Bind(&Core::OnCompletedURLRequest, this, backoff_delay)); @@ -804,6 +813,13 @@ void URLFetcherImpl::Core::StartURLRequest() { request_->set_load_flags(flags); request_->set_context(request_context_getter_->GetURLRequestContext()); request_->set_referrer(referrer_); + request_->set_first_party_for_cookies(first_party_for_cookies_.is_empty() ? + original_url_ : first_party_for_cookies_); + if (render_process_id_ != -1 && render_view_id_ != -1) { + request_->SetUserData( + URLRequestUserData::kUserDataKey, + new URLRequestUserData(render_process_id_, render_view_id_)); + } switch (request_type_) { case GET: @@ -883,6 +899,9 @@ void URLFetcherImpl::Core::CancelURLRequest() { // delete the object, but we cannot delay the destruction of the request // context. request_context_getter_ = NULL; + render_process_id_ = -1; + render_view_id_ = -1; + first_party_for_cookies_ = GURL(); was_cancelled_ = true; file_writer_.reset(); } @@ -1015,6 +1034,20 @@ void URLFetcherImpl::SetRequestContext( core_->request_context_getter_ = request_context_getter; } +void URLFetcherImpl::AssociateWithRenderView( + const GURL& first_party_for_cookies, + int render_process_id, + int render_view_id) { + DCHECK(core_->first_party_for_cookies_.is_empty()); + DCHECK_EQ(core_->render_process_id_, -1); + DCHECK_EQ(core_->render_view_id_, -1); + DCHECK_GE(render_process_id, 0); + DCHECK_GE(render_view_id, 0); + core_->first_party_for_cookies_ = first_party_for_cookies; + core_->render_process_id_ = render_process_id; + core_->render_view_id_ = render_view_id; +} + void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) { core_->automatically_retry_on_5xx_ = retry; } @@ -1066,12 +1099,6 @@ void URLFetcherImpl::Start() { core_->Start(); } -void URLFetcherImpl::StartWithRequestContextGetter( - net::URLRequestContextGetter* request_context_getter) { - SetRequestContext(request_context_getter); - core_->Start(); -} - const GURL& URLFetcherImpl::GetOriginalURL() const { return core_->original_url_; } diff --git a/content/common/net/url_fetcher_impl.h b/content/common/net/url_fetcher_impl.h index 47e97f5..a63faa2 100644 --- a/content/common/net/url_fetcher_impl.h +++ b/content/common/net/url_fetcher_impl.h @@ -51,6 +51,9 @@ class CONTENT_EXPORT URLFetcherImpl : public content::URLFetcher{ net::HttpRequestHeaders* headers) OVERRIDE; virtual void SetRequestContext( net::URLRequestContextGetter* request_context_getter) OVERRIDE; + virtual void AssociateWithRenderView(const GURL& first_party_for_cookies, + int render_process_id, + int render_view_id) OVERRIDE; virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE; virtual void SetMaxRetries(int max_retries) OVERRIDE; virtual int GetMaxRetries() const OVERRIDE; @@ -61,8 +64,6 @@ class CONTENT_EXPORT URLFetcherImpl : public content::URLFetcher{ virtual net::HostPortPair GetSocketAddress() const OVERRIDE; virtual bool WasFetchedViaProxy() const OVERRIDE; virtual void Start() OVERRIDE; - virtual void StartWithRequestContextGetter( - net::URLRequestContextGetter* request_context_getter) OVERRIDE; virtual const GURL& GetOriginalURL() const OVERRIDE; virtual const GURL& GetURL() const OVERRIDE; virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; diff --git a/content/common/net/url_fetcher_impl_unittest.cc b/content/common/net/url_fetcher_impl_unittest.cc index 8b722a4..b70db14 100644 --- a/content/common/net/url_fetcher_impl_unittest.cc +++ b/content/common/net/url_fetcher_impl_unittest.cc @@ -381,8 +381,9 @@ void URLFetcherProtectTest::OnURLFetchComplete( static int count = 0; count++; if (count < 20) { - fetcher_->StartWithRequestContextGetter(new TestURLRequestContextGetter( - io_message_loop_proxy())); + fetcher_->SetRequestContext( + new TestURLRequestContextGetter(io_message_loop_proxy())); + fetcher_->Start(); } else { // We have already sent 20 requests continuously. And we expect that // it takes more than 1 second due to the overload protection settings. @@ -492,8 +493,9 @@ void URLFetcherMultipleAttemptTest::OnURLFetchComplete( EXPECT_FALSE(data.empty()); if (!data.empty() && data_.empty()) { data_ = data; - fetcher_->StartWithRequestContextGetter( + fetcher_->SetRequestContext( new TestURLRequestContextGetter(io_message_loop_proxy())); + fetcher_->Start(); } else { EXPECT_EQ(data, data_); delete fetcher_; // Have to delete this here and not in the destructor, diff --git a/content/common/net/url_request_user_data.cc b/content/common/net/url_request_user_data.cc new file mode 100644 index 0000000..a2529f8 --- /dev/null +++ b/content/common/net/url_request_user_data.cc @@ -0,0 +1,16 @@ +// Copyright (c) 2012 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. + +#include "content/common/net/url_request_user_data.h" + +URLRequestUserData::URLRequestUserData(int render_process_id, + int render_view_id) + : render_process_id_(render_process_id), + render_view_id_(render_view_id) {} + +URLRequestUserData::~URLRequestUserData() {} + +// static +const void* URLRequestUserData::kUserDataKey = + static_cast<const void*>(&URLRequestUserData::kUserDataKey); diff --git a/content/common/net/url_request_user_data.h b/content/common/net/url_request_user_data.h new file mode 100644 index 0000000..b12d729 --- /dev/null +++ b/content/common/net/url_request_user_data.h @@ -0,0 +1,28 @@ +// Copyright (c) 2012 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_COMMON_NET_URL_REQUEST_USER_DATA_H_ +#define CONTENT_COMMON_NET_URL_REQUEST_USER_DATA_H_ +#pragma once + +#include "base/supports_user_data.h" + +// Used to annotate all URLRequests for which the request can be associated +// with a given render view. +class URLRequestUserData : public base::SupportsUserData::Data { + public: + URLRequestUserData(int render_process_id, int render_view_id); + virtual ~URLRequestUserData(); + + int render_process_id() const { return render_process_id_; } + int render_view_id() const { return render_view_id_; } + + static const void* kUserDataKey; + + private: + int render_process_id_; + int render_view_id_; +}; + +#endif // CONTENT_COMMON_NET_URL_REQUEST_USER_DATA_H_ diff --git a/content/content_common.gypi b/content/content_common.gypi index b984fb1..4522e29 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -242,6 +242,8 @@ 'common/navigation_gesture.h', 'common/net/url_fetcher_impl.cc', 'common/net/url_fetcher_impl.h', + 'common/net/url_request_user_data.cc', + 'common/net/url_request_user_data.h', 'common/np_channel_base.cc', 'common/np_channel_base.h', 'common/npobject_base.h', diff --git a/content/public/browser/resource_request_info.h b/content/public/browser/resource_request_info.h index 1339d42..33c6899 100644 --- a/content/public/browser/resource_request_info.h +++ b/content/public/browser/resource_request_info.h @@ -33,6 +33,15 @@ class ResourceRequestInfo { net::URLRequest* request, ResourceContext* context); + // Returns the associated RenderView for a given process. Returns false, if + // there is no associated RenderView. This method does not rely on the + // request being allocated by the ResourceDispatcherHost, but works for all + // URLRequests that are associated with a RenderView. + CONTENT_EXPORT static bool GetRenderViewForRequest( + const net::URLRequest* request, + int* render_process_id, + int* render_view_id); + // Returns the associated ResourceContext. virtual ResourceContext* GetContext() const = 0; diff --git a/content/public/common/url_fetcher.h b/content/public/common/url_fetcher.h index 571a34b..9fbc533 100644 --- a/content/public/common/url_fetcher.h +++ b/content/public/common/url_fetcher.h @@ -156,6 +156,12 @@ class CONTENT_EXPORT URLFetcher { virtual void SetRequestContext( net::URLRequestContextGetter* request_context_getter) = 0; + // Mark URLRequests started by the URLFetcher to stem from the given render + // view. + virtual void AssociateWithRenderView(const GURL& first_party_for_cookies, + int render_process_id, + int render_view_id) = 0; + // If |retry| is false, 5xx responses will be propagated to the observer, // if it is true URLFetcher will automatically re-execute the request, // after backoff_delay() elapses. URLFetcher has it set to true by default. @@ -192,10 +198,6 @@ class CONTENT_EXPORT URLFetcher { // settings. virtual void Start() = 0; - // Restarts the URLFetcher with a new URLRequestContextGetter. - virtual void StartWithRequestContextGetter( - net::URLRequestContextGetter* request_context_getter) = 0; - // Return the URL that we were asked to fetch. virtual const GURL& GetOriginalURL() const = 0; diff --git a/content/test/test_url_fetcher_factory.cc b/content/test/test_url_fetcher_factory.cc index 02f1933..9602ede 100644 --- a/content/test/test_url_fetcher_factory.cc +++ b/content/test/test_url_fetcher_factory.cc @@ -88,6 +88,12 @@ void TestURLFetcher::SetRequestContext( net::URLRequestContextGetter* request_context_getter) { } +void TestURLFetcher::AssociateWithRenderView( + const GURL& first_party_for_cookies, + int render_process_id, + int render_view_id) { +} + void TestURLFetcher::SetAutomaticallyRetryOn5xx(bool retry) { } @@ -124,11 +130,6 @@ void TestURLFetcher::Start() { // Overriden to do nothing. It is assumed the caller will notify the delegate. } -void TestURLFetcher::StartWithRequestContextGetter( - net::URLRequestContextGetter* request_context_getter) { - NOTIMPLEMENTED(); -} - const GURL& TestURLFetcher::GetOriginalURL() const { return original_url_; } diff --git a/content/test/test_url_fetcher_factory.h b/content/test/test_url_fetcher_factory.h index e19653b..38fbdd5 100644 --- a/content/test/test_url_fetcher_factory.h +++ b/content/test/test_url_fetcher_factory.h @@ -80,6 +80,9 @@ class TestURLFetcher : public content::URLFetcher { net::HttpRequestHeaders* headers) OVERRIDE; virtual void SetRequestContext( net::URLRequestContextGetter* request_context_getter) OVERRIDE; + virtual void AssociateWithRenderView(const GURL& first_party_for_cookies, + int render_process_id, + int render_view_id) OVERRIDE; virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE; virtual void SetMaxRetries(int max_retries) OVERRIDE; virtual int GetMaxRetries() const OVERRIDE; @@ -90,8 +93,6 @@ class TestURLFetcher : public content::URLFetcher { virtual net::HostPortPair GetSocketAddress() const OVERRIDE; virtual bool WasFetchedViaProxy() const OVERRIDE; virtual void Start() OVERRIDE; - virtual void StartWithRequestContextGetter( - net::URLRequestContextGetter* request_context_getter) OVERRIDE; // URL we were created with. Because of how we're using URLFetcher GetURL() // always returns an empty URL. Chances are you'll want to use diff --git a/net/base/network_delegate.cc b/net/base/network_delegate.cc index 87ecf39..6b857cf 100644 --- a/net/base/network_delegate.cc +++ b/net/base/network_delegate.cc @@ -5,6 +5,8 @@ #include "net/base/network_delegate.h" #include "base/logging.h" +#include "net/base/load_flags.h" +#include "net/url_request/url_request.h" namespace net { @@ -90,4 +92,21 @@ NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired( return OnAuthRequired(request, auth_info, callback, credentials); } +bool NetworkDelegate::NotifyReadingCookies( + const URLRequest* request, + const CookieList& cookie_list) { + DCHECK(CalledOnValidThread()); + DCHECK(!(request->load_flags() & net::LOAD_DO_NOT_SEND_COOKIES)); + return CanGetCookies(request, cookie_list); +} + +bool NetworkDelegate::NotifySettingCookie( + const URLRequest* request, + const std::string& cookie_line, + CookieOptions* options) { + DCHECK(CalledOnValidThread()); + DCHECK(!(request->load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES)); + return CanSetCookie(request, cookie_line, options); +} + } // namespace net diff --git a/net/base/network_delegate.h b/net/base/network_delegate.h index baa6723..34909ea 100644 --- a/net/base/network_delegate.h +++ b/net/base/network_delegate.h @@ -6,6 +6,8 @@ #define NET_BASE_NETWORK_DELEGATE_H_ #pragma once +#include <string> + #include "base/callback.h" #include "base/string16.h" #include "base/threading/non_thread_safe.h" @@ -26,6 +28,8 @@ namespace net { // NOTE: It is not okay to add any compile-time dependencies on symbols outside // of net/base here, because we have a net_base library. Forward declarations // are ok. +class CookieList; +class CookieOptions; class HttpRequestHeaders; class HttpResponseHeaders; class URLRequest; @@ -73,6 +77,11 @@ class NetworkDelegate : public base::NonThreadSafe { const AuthChallengeInfo& auth_info, const AuthCallback& callback, AuthCredentials* credentials); + bool NotifyReadingCookies(const URLRequest* request, + const CookieList& cookie_list); + bool NotifySettingCookie(const URLRequest* request, + const std::string& cookie_line, + CookieOptions* options); private: // This is the interface for subclasses of NetworkDelegate to implement. This @@ -169,6 +178,20 @@ class NetworkDelegate : public base::NonThreadSafe { const AuthChallengeInfo& auth_info, const AuthCallback& callback, AuthCredentials* credentials) = 0; + + // Called when reading cookies to allow the network delegate to block access + // to the cookie. This method will never be invoked when + // LOAD_DO_NOT_SEND_COOKIES is specified. + virtual bool CanGetCookies(const URLRequest* request, + const CookieList& cookie_list) = 0; + + // Called when a cookie is set to allow the network delegate to block access + // to the cookie. This method will never be invoked when + // LOAD_DO_NOT_SAVE_COOKIES is specified. + virtual bool CanSetCookie(const URLRequest* request, + const std::string& cookie_line, + CookieOptions* options) = 0; + }; } // namespace net diff --git a/net/proxy/network_delegate_error_observer_unittest.cc b/net/proxy/network_delegate_error_observer_unittest.cc index b64e9bf..f4b4ba7 100644 --- a/net/proxy/network_delegate_error_observer_unittest.cc +++ b/net/proxy/network_delegate_error_observer_unittest.cc @@ -63,6 +63,17 @@ class TestNetworkDelegate : public net::NetworkDelegate { AuthCredentials* credentials) OVERRIDE { return AUTH_REQUIRED_RESPONSE_NO_ACTION; } + virtual bool CanGetCookies( + const URLRequest* request, + const CookieList& cookie_list) OVERRIDE { + return true; + } + virtual bool CanSetCookie( + const URLRequest* request, + const std::string& cookie_line, + CookieOptions* options) OVERRIDE { + return true; + } bool got_pac_error_; }; diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 144029f..ba7870f 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -123,17 +123,6 @@ void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, request->Cancel(); } -bool URLRequest::Delegate::CanGetCookies(const URLRequest* request, - const CookieList& cookie_list) const { - return true; -} - -bool URLRequest::Delegate::CanSetCookie(const URLRequest* request, - const std::string& cookie_line, - CookieOptions* options) const { - return true; -} - /////////////////////////////////////////////////////////////////////////////// // URLRequest @@ -837,15 +826,22 @@ void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info, } bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { - if (delegate_) - return delegate_->CanGetCookies(this, cookie_list); + DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); + if (context_ && context_->network_delegate()) { + return context_->network_delegate()->NotifyReadingCookies(this, + cookie_list); + } return false; } bool URLRequest::CanSetCookie(const std::string& cookie_line, CookieOptions* options) const { - if (delegate_) - return delegate_->CanSetCookie(this, cookie_line, options); + DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES)); + if (context_ && context_->network_delegate()) { + return context_->network_delegate()->NotifySettingCookie(this, + cookie_line, + options); + } return false; } diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 2c54cbc..3875efd 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -260,19 +260,6 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), const SSLInfo& ssl_info, bool fatal); - // Called when reading cookies to allow the delegate to block access to the - // cookie. This method will never be invoked when LOAD_DO_NOT_SEND_COOKIES - // is specified. - virtual bool CanGetCookies(const URLRequest* request, - const CookieList& cookie_list) const; - - // Called when a cookie is set to allow the delegate to block access to the - // cookie. This method will never be invoked when LOAD_DO_NOT_SAVE_COOKIES - // is specified. - virtual bool CanSetCookie(const URLRequest* request, - const std::string& cookie_line, - CookieOptions* options) const; - // After calling Start(), the delegate will receive an OnResponseStarted // callback when the request has completed. If an error occurred, the // request->status() will be set. On success, all redirects have been diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc index 10bb2e5..dc5fa05 100644 --- a/net/url_request/url_request_test_util.cc +++ b/net/url_request/url_request_test_util.cc @@ -191,13 +191,9 @@ TestDelegate::TestDelegate() quit_on_complete_(true), quit_on_redirect_(false), allow_certificate_errors_(false), - cookie_options_bit_mask_(0), response_started_count_(0), received_bytes_count_(0), received_redirect_count_(0), - blocked_get_cookies_count_(0), - blocked_set_cookie_count_(0), - set_cookie_count_(0), received_data_before_response_(false), request_failed_(false), have_certificate_errors_(false), @@ -244,39 +240,6 @@ void TestDelegate::OnSSLCertificateError(net::URLRequest* request, request->Cancel(); } -bool TestDelegate::CanGetCookies(const net::URLRequest* request, - const net::CookieList& cookie_list) const { - bool allow = true; - if (cookie_options_bit_mask_ & NO_GET_COOKIES) - allow = false; - - if (!allow) { - blocked_get_cookies_count_++; - } - - return allow; -} - -bool TestDelegate::CanSetCookie(const net::URLRequest* request, - const std::string& cookie_line, - net::CookieOptions* options) const { - bool allow = true; - if (cookie_options_bit_mask_ & NO_SET_COOKIE) - allow = false; - - if (cookie_options_bit_mask_ & FORCE_SESSION) - options->set_force_session(); - - - if (!allow) { - blocked_set_cookie_count_++; - } else { - set_cookie_count_++; - } - - return allow; -} - void TestDelegate::OnResponseStarted(net::URLRequest* request) { // It doesn't make sense for the request to have IO pending at this point. DCHECK(!request->status().is_io_pending()); @@ -342,11 +305,15 @@ void TestDelegate::OnResponseCompleted(net::URLRequest* request) { } TestNetworkDelegate::TestNetworkDelegate() - : last_error_(0), - error_count_(0), - created_requests_(0), - destroyed_requests_(0), - completed_requests_(0) { + : last_error_(0), + error_count_(0), + created_requests_(0), + destroyed_requests_(0), + completed_requests_(0), + cookie_options_bit_mask_(0), + blocked_get_cookies_count_(0), + blocked_set_cookie_count_(0), + set_cookie_count_(0) { } TestNetworkDelegate::~TestNetworkDelegate() { @@ -524,6 +491,38 @@ net::NetworkDelegate::AuthRequiredResponse TestNetworkDelegate::OnAuthRequired( return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; } +bool TestNetworkDelegate::CanGetCookies(const net::URLRequest* request, + const net::CookieList& cookie_list) { + bool allow = true; + if (cookie_options_bit_mask_ & NO_GET_COOKIES) + allow = false; + + if (!allow) { + blocked_get_cookies_count_++; + } + + return allow; +} + +bool TestNetworkDelegate::CanSetCookie(const net::URLRequest* request, + const std::string& cookie_line, + net::CookieOptions* options) { + bool allow = true; + if (cookie_options_bit_mask_ & NO_SET_COOKIE) + allow = false; + + if (cookie_options_bit_mask_ & FORCE_SESSION) + options->set_force_session(); + + if (!allow) { + blocked_set_cookie_count_++; + } else { + set_cookie_count_++; + } + + return allow; +} + // static std::string ScopedCustomUrlRequestTestHttpHost::value_("127.0.0.1"); diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h index 258c448..95e744f 100644 --- a/net/url_request/url_request_test_util.h +++ b/net/url_request/url_request_test_util.h @@ -109,12 +109,6 @@ class TestURLRequest : public net::URLRequest { class TestDelegate : public net::URLRequest::Delegate { public: - enum Options { - NO_GET_COOKIES = 1 << 0, - NO_SET_COOKIE = 1 << 1, - FORCE_SESSION = 1 << 2, - }; - TestDelegate(); virtual ~TestDelegate(); @@ -129,7 +123,6 @@ class TestDelegate : public net::URLRequest::Delegate { void set_allow_certificate_errors(bool val) { allow_certificate_errors_ = val; } - void set_cookie_options(int o) {cookie_options_bit_mask_ = o; } void set_credentials(const net::AuthCredentials& credentials) { credentials_ = credentials; } @@ -139,9 +132,6 @@ class TestDelegate : public net::URLRequest::Delegate { int bytes_received() const { return static_cast<int>(data_received_.size()); } int response_started_count() const { return response_started_count_; } int received_redirect_count() const { return received_redirect_count_; } - int blocked_get_cookies_count() const { return blocked_get_cookies_count_; } - int blocked_set_cookie_count() const { return blocked_set_cookie_count_; } - int set_cookie_count() const { return set_cookie_count_; } bool received_data_before_response() const { return received_data_before_response_; } @@ -163,11 +153,6 @@ class TestDelegate : public net::URLRequest::Delegate { virtual void OnSSLCertificateError(net::URLRequest* request, const net::SSLInfo& ssl_info, bool fatal) OVERRIDE; - virtual bool CanGetCookies(const net::URLRequest* request, - const net::CookieList& cookie_list) const OVERRIDE; - virtual bool CanSetCookie(const net::URLRequest* request, - const std::string& cookie_line, - net::CookieOptions* options) const OVERRIDE; virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; virtual void OnReadCompleted(net::URLRequest* request, int bytes_read) OVERRIDE; @@ -185,16 +170,12 @@ class TestDelegate : public net::URLRequest::Delegate { bool quit_on_complete_; bool quit_on_redirect_; bool allow_certificate_errors_; - int cookie_options_bit_mask_; net::AuthCredentials credentials_; // tracks status of callbacks int response_started_count_; int received_bytes_count_; int received_redirect_count_; - mutable int blocked_get_cookies_count_; - mutable int blocked_set_cookie_count_; - mutable int set_cookie_count_; bool received_data_before_response_; bool request_failed_; bool have_certificate_errors_; @@ -210,14 +191,25 @@ class TestDelegate : public net::URLRequest::Delegate { class TestNetworkDelegate : public net::NetworkDelegate { public: + enum Options { + NO_GET_COOKIES = 1 << 0, + NO_SET_COOKIE = 1 << 1, + FORCE_SESSION = 1 << 2, + }; + TestNetworkDelegate(); virtual ~TestNetworkDelegate(); + void set_cookie_options(int o) {cookie_options_bit_mask_ = o; } + int last_error() const { return last_error_; } int error_count() const { return error_count_; } int created_requests() const { return created_requests_; } int destroyed_requests() const { return destroyed_requests_; } int completed_requests() const { return completed_requests_; } + int blocked_get_cookies_count() const { return blocked_get_cookies_count_; } + int blocked_set_cookie_count() const { return blocked_set_cookie_count_; } + int set_cookie_count() const { return set_cookie_count_; } protected: // net::NetworkDelegate: @@ -249,6 +241,11 @@ class TestNetworkDelegate : public net::NetworkDelegate { const net::AuthChallengeInfo& auth_info, const AuthCallback& callback, net::AuthCredentials* credentials) OVERRIDE; + virtual bool CanGetCookies(const net::URLRequest* request, + const net::CookieList& cookie_list) OVERRIDE; + virtual bool CanSetCookie(const net::URLRequest* request, + const std::string& cookie_line, + net::CookieOptions* options) OVERRIDE; void InitRequestStatesIfNew(int request_id); @@ -257,6 +254,10 @@ class TestNetworkDelegate : public net::NetworkDelegate { int created_requests_; int destroyed_requests_; int completed_requests_; + int cookie_options_bit_mask_; + int blocked_get_cookies_count_; + int blocked_set_cookie_count_; + int set_cookie_count_; // net::NetworkDelegate callbacks happen in a particular order (e.g. // OnBeforeURLRequest is always called before OnBeforeSendHeaders). diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index caeaf71..c0cbbf6 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -2569,18 +2569,22 @@ TEST_F(URLRequestTest, DelayedCookieCallback) { // Set up a cookie. { + TestNetworkDelegate network_delegate; + context->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); req.set_context(context); req.Start(); MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); - EXPECT_EQ(1, d.set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); + EXPECT_EQ(1, network_delegate.set_cookie_count()); } // Verify that the cookie is set. { + TestNetworkDelegate network_delegate; + context->set_network_delegate(&network_delegate); TestDelegate d; TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(context); @@ -2589,8 +2593,8 @@ TEST_F(URLRequestTest, DelayedCookieCallback) { EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") != std::string::npos); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } } @@ -2600,17 +2604,21 @@ TEST_F(URLRequestTest, DoNotSendCookies) { // Set up a cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); req.set_context(default_context_); req.Start(); MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } // Verify that the cookie is set. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(default_context_); @@ -2619,12 +2627,14 @@ TEST_F(URLRequestTest, DoNotSendCookies) { EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") != std::string::npos); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); @@ -2636,9 +2646,11 @@ TEST_F(URLRequestTest, DoNotSendCookies) { == std::string::npos); // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } + + default_context_->set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSaveCookies) { @@ -2647,19 +2659,23 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { // Set up a cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); req.set_context(default_context_); req.Start(); MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); - EXPECT_EQ(1, d.set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); + EXPECT_EQ(1, network_delegate.set_cookie_count()); } // Try to set-up another cookie and update the previous cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); @@ -2670,13 +2686,15 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { MessageLoop::current()->Run(); // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); - EXPECT_EQ(0, d.set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.set_cookie_count()); } // Verify the cookies weren't saved or updated. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(default_context_); @@ -2688,10 +2706,12 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") != std::string::npos); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); - EXPECT_EQ(0, d.set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.set_cookie_count()); } + + default_context_->set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { @@ -2700,18 +2720,22 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { // Set up a cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); req.set_context(default_context_); req.Start(); MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } // Verify that the cookie is set. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(default_context_); @@ -2721,14 +2745,16 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") != std::string::npos); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } // Verify that the cookie isn't sent. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; - d.set_cookie_options(TestDelegate::NO_GET_COOKIES); + network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(default_context_); req.Start(); @@ -2737,9 +2763,11 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") == std::string::npos); - EXPECT_EQ(1, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } + + default_context_->set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { @@ -2748,20 +2776,24 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { // Set up a cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); req.set_context(default_context_); req.Start(); MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } // Try to set-up another cookie and update the previous cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; - d.set_cookie_options(TestDelegate::NO_SET_COOKIE); + network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); req.set_context(default_context_); @@ -2769,13 +2801,15 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(2, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); } // Verify the cookies weren't saved or updated. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(default_context_); @@ -2787,9 +2821,11 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") != std::string::npos); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } + + default_context_->set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { @@ -2798,16 +2834,20 @@ TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { // Set up an empty cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie"), &d); req.set_context(default_context_); req.Start(); MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); - EXPECT_EQ(0, d.set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.set_cookie_count()); } + + default_context_->set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { @@ -2816,18 +2856,22 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { // Set up a cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); req.set_context(default_context_); req.Start(); MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } // Verify that the cookie is set. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(default_context_); @@ -2837,14 +2881,16 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") != std::string::npos); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } // Verify that the cookie isn't sent. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; - d.set_cookie_options(TestDelegate::NO_GET_COOKIES); + network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(default_context_); req.Start(); @@ -2853,9 +2899,11 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") == std::string::npos); - EXPECT_EQ(1, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } + + default_context_->set_network_delegate(&default_network_delegate_); } TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { @@ -2864,20 +2912,24 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { // Set up a cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); req.set_context(default_context_); req.Start(); MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } // Try to set-up another cookie and update the previous cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; - d.set_cookie_options(TestDelegate::NO_SET_COOKIE); + network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); URLRequest req(test_server.GetURL( "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); req.set_context(default_context_); @@ -2885,12 +2937,14 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(2, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); } // Verify the cookies weren't saved or updated. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); req.set_context(default_context_); @@ -2902,9 +2956,11 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") != std::string::npos); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } + + default_context_->set_network_delegate(&default_network_delegate_); } void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { @@ -2920,8 +2976,10 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) { // Set up a cookie. { + TestNetworkDelegate network_delegate; + default_context_->set_network_delegate(&network_delegate); TestDelegate d; - d.set_cookie_options(TestDelegate::FORCE_SESSION); + network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION); URLRequest req(test_server.GetURL( "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); req.set_context(default_context_); @@ -2929,9 +2987,10 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) { MessageLoop::current()->Run(); - EXPECT_EQ(0, d.blocked_get_cookies_count()); - EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); } + default_context_->set_network_delegate(&default_network_delegate_); // Now, check the cookie store. bool was_run = false; diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc index bd8ddc8..d7475bc 100644 --- a/webkit/appcache/appcache_update_job.cc +++ b/webkit/appcache/appcache_update_job.cc @@ -105,6 +105,7 @@ AppCacheUpdateJob::URLFetcher::~URLFetcher() { void AppCacheUpdateJob::URLFetcher::Start() { request_->set_context(job_->service_->request_context()); + request_->set_first_party_for_cookies(job_->manifest_url_); request_->set_load_flags(request_->load_flags() | net::LOAD_DISABLE_INTERCEPT); if (existing_response_headers_) diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index fdb63d7..5227d91 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -52,6 +52,7 @@ #include "net/base/mime_util.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" +#include "net/base/network_delegate.h" #include "net/base/static_cookie_policy.h" #include "net/base/upload_data.h" #include "net/http/http_cache.h" @@ -100,10 +101,84 @@ struct TestShellRequestContextParams { bool no_proxy; }; +//----------------------------------------------------------------------------- + +bool g_accept_all_cookies = false; + +class TestShellNetworkDelegate : public net::NetworkDelegate { + public: + virtual ~TestShellNetworkDelegate() {} + + private: + // net::NetworkDelegate implementation. + virtual int OnBeforeURLRequest(net::URLRequest* request, + const net::CompletionCallback& callback, + GURL* new_url) OVERRIDE { + return net::OK; + } + virtual int OnBeforeSendHeaders(net::URLRequest* request, + const net::CompletionCallback& callback, + net::HttpRequestHeaders* headers) OVERRIDE { + return net::OK; + } + virtual void OnSendHeaders(net::URLRequest* request, + const net::HttpRequestHeaders& headers) OVERRIDE {} + virtual int OnHeadersReceived( + net::URLRequest* request, + const net::CompletionCallback& callback, + net::HttpResponseHeaders* original_response_headers, + scoped_refptr<net::HttpResponseHeaders>* + override_response_headers) OVERRIDE { + return net::OK; + } + virtual void OnBeforeRedirect(net::URLRequest* request, + const GURL& new_location) OVERRIDE {} + virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE {} + virtual void OnRawBytesRead(const net::URLRequest& request, + int bytes_read) OVERRIDE {} + virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE {} + virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE {} + + virtual void OnPACScriptError(int line_number, + const string16& error) OVERRIDE { + } + virtual AuthRequiredResponse OnAuthRequired( + net::URLRequest* request, + const net::AuthChallengeInfo& auth_info, + const AuthCallback& callback, + net::AuthCredentials* credentials) OVERRIDE { + return AUTH_REQUIRED_RESPONSE_NO_ACTION; + } + virtual bool CanGetCookies( + const net::URLRequest* request, + const net::CookieList& cookie_list) OVERRIDE { + StaticCookiePolicy::Type policy_type = g_accept_all_cookies ? + StaticCookiePolicy::ALLOW_ALL_COOKIES : + StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES; + + StaticCookiePolicy policy(policy_type); + int rv = policy.CanGetCookies( + request->url(), request->first_party_for_cookies()); + return rv == net::OK; + } + virtual bool CanSetCookie(const net::URLRequest* request, + const std::string& cookie_line, + net::CookieOptions* options) OVERRIDE { + StaticCookiePolicy::Type policy_type = g_accept_all_cookies ? + StaticCookiePolicy::ALLOW_ALL_COOKIES : + StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES; + + StaticCookiePolicy policy(policy_type); + int rv = policy.CanSetCookie( + request->url(), request->first_party_for_cookies()); + return rv == net::OK; + } +}; + TestShellRequestContextParams* g_request_context_params = NULL; TestShellRequestContext* g_request_context = NULL; +TestShellNetworkDelegate* g_network_delegate = NULL; base::Thread* g_cache_thread = NULL; -bool g_accept_all_cookies = false; struct FileOverHTTPParams { FileOverHTTPParams(std::string in_file_path_template, GURL in_http_prefix) @@ -141,6 +216,9 @@ class IOThread : public base::Thread { g_request_context->AddRef(); + g_network_delegate = new TestShellNetworkDelegate(); + g_request_context->set_network_delegate(g_network_delegate); + SimpleAppCacheSystem::InitializeOnIOThread(g_request_context); SimpleSocketStreamBridge::InitializeOnIOThread(g_request_context); SimpleFileWriter::InitializeOnIOThread(g_request_context); @@ -159,9 +237,15 @@ class IOThread : public base::Thread { SimpleAppCacheSystem::CleanupOnIOThread(); if (g_request_context) { + g_request_context->set_network_delegate(NULL); g_request_context->Release(); g_request_context = NULL; } + + if (g_network_delegate) { + delete g_network_delegate; + g_network_delegate = NULL; + } } }; @@ -476,32 +560,6 @@ class RequestProxy : public net::URLRequest::Delegate, request->ContinueDespiteLastError(); } - virtual bool CanGetCookies( - const net::URLRequest* request, - const net::CookieList& cookie_list) const OVERRIDE { - StaticCookiePolicy::Type policy_type = g_accept_all_cookies ? - StaticCookiePolicy::ALLOW_ALL_COOKIES : - StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES; - - StaticCookiePolicy policy(policy_type); - int rv = policy.CanGetCookies( - request->url(), request->first_party_for_cookies()); - return rv == net::OK; - } - - virtual bool CanSetCookie(const net::URLRequest* request, - const std::string& cookie_line, - net::CookieOptions* options) const OVERRIDE { - StaticCookiePolicy::Type policy_type = g_accept_all_cookies ? - StaticCookiePolicy::ALLOW_ALL_COOKIES : - StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES; - - StaticCookiePolicy policy(policy_type); - int rv = policy.CanSetCookie( - request->url(), request->first_party_for_cookies()); - return rv == net::OK; - } - virtual void OnReadCompleted(net::URLRequest* request, int bytes_read) OVERRIDE { if (request->status().is_success() && bytes_read > 0) { @@ -924,6 +982,7 @@ void SimpleResourceLoaderBridge::Init( DCHECK(!g_request_context_params); DCHECK(!g_request_context); + DCHECK(!g_network_delegate); DCHECK(!g_io_thread); g_request_context_params = new TestShellRequestContextParams( @@ -941,6 +1000,7 @@ void SimpleResourceLoaderBridge::Shutdown() { g_cache_thread = NULL; DCHECK(!g_request_context) << "should have been nulled by thread dtor"; + DCHECK(!g_network_delegate) << "should have been nulled by thread dtor"; } else { delete g_request_context_params; g_request_context_params = NULL; |