summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chrome_content_browser_client.cc82
-rw-r--r--chrome/browser/chrome_content_browser_client.h15
-rw-r--r--chrome/browser/download/download_manager.cc8
-rw-r--r--chrome/browser/download/download_manager.h5
-rw-r--r--chrome/browser/download/download_util.cc9
-rw-r--r--chrome/browser/download/download_util.h16
-rw-r--r--chrome/browser/download/save_file_manager.cc12
-rw-r--r--chrome/browser/download/save_file_manager.h13
-rw-r--r--chrome/browser/download/save_package.cc5
-rw-r--r--chrome/browser/download/save_package.h8
-rw-r--r--chrome/browser/extensions/user_script_listener_unittest.cc4
-rw-r--r--content/browser/appcache/chrome_appcache_service.cc4
-rw-r--r--content/browser/content_browser_client.cc23
-rw-r--r--content/browser/content_browser_client.h26
-rw-r--r--content/browser/renderer_host/render_message_filter.cc5
-rw-r--r--content/browser/renderer_host/render_message_filter.h12
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.cc61
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.h26
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_request_info.cc4
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_request_info.h10
-rw-r--r--content/browser/renderer_host/resource_queue_unittest.cc4
-rw-r--r--net/base/cookie_monster.cc2
-rw-r--r--net/url_request/url_request.cc12
-rw-r--r--net/url_request/url_request.h23
-rw-r--r--net/url_request/url_request_http_job.cc123
-rw-r--r--net/url_request/url_request_http_job.h4
-rw-r--r--net/url_request/url_request_test_util.cc57
-rw-r--r--net/url_request/url_request_test_util.h52
-rw-r--r--net/url_request/url_request_unittest.cc30
29 files changed, 357 insertions, 298 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index be93cc2..b7ce694 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -29,9 +29,13 @@
#include "chrome/common/pref_names.h"
#include "content/browser/renderer_host/browser_render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h"
+#include "content/browser/renderer_host/render_view_host_notification_task.h"
#include "content/browser/resource_context.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/worker_host/worker_process_host.h"
+#include "net/base/cookie_monster.h"
+#include "net/base/cookie_options.h"
+#include "net/base/static_cookie_policy.h"
#if defined(OS_LINUX)
#include "base/linux_util.h"
@@ -183,13 +187,87 @@ std::string ChromeContentBrowserClient::GetApplicationLocale() {
}
bool ChromeContentBrowserClient::AllowAppCache(
- const GURL& manifest_url, const content::ResourceContext* context) {
- ContentSetting setting = context->host_content_settings_map()->
+ const GURL& manifest_url, const content::ResourceContext& context) {
+ ContentSetting setting = context.host_content_settings_map()->
GetContentSetting(manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, "");
DCHECK(setting != CONTENT_SETTING_DEFAULT);
return setting != CONTENT_SETTING_BLOCK;
}
+bool ChromeContentBrowserClient::AllowGetCookie(
+ const GURL& url,
+ const GURL& first_party,
+ const net::CookieList& cookie_list,
+ const content::ResourceContext& context,
+ int render_process_id,
+ int render_view_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ bool allow = true;
+ if (context.host_content_settings_map()->BlockThirdPartyCookies()) {
+ bool strict = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kBlockReadingThirdPartyCookies);
+ net::StaticCookiePolicy policy(strict ?
+ net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES :
+ net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
+ int rv = policy.CanGetCookies(url, first_party);
+ DCHECK_NE(net::ERR_IO_PENDING, rv);
+ if (rv != net::OK)
+ allow = false;
+ }
+
+ if (allow) {
+ ContentSetting setting = context.host_content_settings_map()->
+ GetContentSetting(url, CONTENT_SETTINGS_TYPE_COOKIES, "");
+ allow = setting == CONTENT_SETTING_ALLOW ||
+ setting == CONTENT_SETTING_SESSION_ONLY;
+ }
+
+ CallRenderViewHostContentSettingsDelegate(
+ render_process_id, render_view_id,
+ &RenderViewHostDelegate::ContentSettings::OnCookiesRead,
+ url, cookie_list, !allow);
+ return allow;
+}
+
+bool ChromeContentBrowserClient::AllowSetCookie(
+ const GURL& url,
+ const GURL& first_party,
+ const std::string& cookie_line,
+ const content::ResourceContext& context,
+ int render_process_id,
+ int render_view_id,
+ net::CookieOptions* options) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ bool allow = true;
+ if (context.host_content_settings_map()->BlockThirdPartyCookies()) {
+ bool strict = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kBlockReadingThirdPartyCookies);
+ net::StaticCookiePolicy policy(strict ?
+ net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES :
+ net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
+ int rv = policy.CanSetCookie(url, first_party, cookie_line);
+ if (rv != net::OK)
+ allow = false;
+ }
+
+ if (allow) {
+ ContentSetting setting = context.host_content_settings_map()->
+ GetContentSetting(url, CONTENT_SETTINGS_TYPE_COOKIES, "");
+
+ if (setting == CONTENT_SETTING_SESSION_ONLY)
+ options->set_force_session();
+
+ allow = setting == CONTENT_SETTING_ALLOW ||
+ setting == CONTENT_SETTING_SESSION_ONLY;
+ }
+
+ CallRenderViewHostContentSettingsDelegate(
+ render_process_id, render_view_id,
+ &RenderViewHostDelegate::ContentSettings::OnCookieChanged,
+ url, cookie_line, *options, !allow);
+ return allow;
+}
+
#if defined(OS_LINUX)
int ChromeContentBrowserClient::GetCrashSignalFD(
const std::string& process_type) {
diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h
index 050def3..ee81fd3 100644
--- a/chrome/browser/chrome_content_browser_client.h
+++ b/chrome/browser/chrome_content_browser_client.h
@@ -27,7 +27,20 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
int child_process_id);
virtual std::string GetApplicationLocale();
virtual bool AllowAppCache(const GURL& manifest_url,
- const content::ResourceContext* context);
+ const content::ResourceContext& context);
+ virtual bool AllowGetCookie(const GURL& url,
+ const GURL& first_party,
+ const net::CookieList& cookie_list,
+ const content::ResourceContext& context,
+ int render_process_id,
+ int render_view_id);
+ virtual bool AllowSetCookie(const GURL& url,
+ const GURL& first_party,
+ const std::string& cookie_line,
+ const content::ResourceContext& context,
+ int render_process_id,
+ int render_view_id,
+ net::CookieOptions* options);
#if defined(OS_LINUX)
// Can return an optional fd for crash handling, otherwise returns -1.
virtual int GetCrashSignalFD(const std::string& process_type);
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 7062dc5..fb80f8f 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -27,7 +27,6 @@
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/history/download_create_info.h"
-#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_util.h"
@@ -130,8 +129,6 @@ void DownloadManager::Shutdown() {
download_history_.reset();
download_prefs_.reset();
- request_context_getter_ = NULL;
-
shutdown_needed_ = false;
}
@@ -224,7 +221,6 @@ bool DownloadManager::Init(Profile* profile) {
shutdown_needed_ = true;
profile_ = profile;
- request_context_getter_ = profile_->GetRequestContext();
download_history_.reset(new DownloadHistory(profile));
download_history_->Load(
NewCallback(this, &DownloadManager::OnQueryDownloadEntriesComplete));
@@ -904,6 +900,8 @@ void DownloadManager::DownloadUrlToFile(const GURL& url,
const DownloadSaveInfo& save_info,
TabContents* tab_contents) {
DCHECK(tab_contents);
+ // We send a pointer to content::ResourceContext, instead of the usual
+ // reference, so that a copy of the object isn't made.
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
NewRunnableFunction(&download_util::DownloadUrl,
url,
@@ -913,7 +911,7 @@ void DownloadManager::DownloadUrlToFile(const GURL& url,
g_browser_process->resource_dispatcher_host(),
tab_contents->GetRenderProcessHost()->id(),
tab_contents->render_view_host()->routing_id(),
- request_context_getter_));
+ &tab_contents->profile()->GetResourceContext()));
}
void DownloadManager::AddObserver(Observer* observer) {
diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h
index 5af8932..f213a74 100644
--- a/chrome/browser/download/download_manager.h
+++ b/chrome/browser/download/download_manager.h
@@ -57,10 +57,6 @@ class TabContents;
struct DownloadCreateInfo;
struct DownloadSaveInfo;
-namespace net {
-class URLRequestContextGetter;
-}
-
// Browser's download manager: manages all downloads and destination view.
class DownloadManager
: public base::RefCountedThreadSafe<DownloadManager,
@@ -375,7 +371,6 @@ class DownloadManager
// The current active profile.
Profile* profile_;
- scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
scoped_ptr<DownloadHistory> download_history_;
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 720d03a..90fe73d 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -35,7 +35,6 @@
#include "chrome/browser/extensions/extension_install_ui.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/history/download_create_info.h"
-#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"
@@ -798,20 +797,16 @@ void DownloadUrl(
ResourceDispatcherHost* rdh,
int render_process_host_id,
int render_view_id,
- net::URLRequestContextGetter* request_context_getter) {
+ const content::ResourceContext* context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- net::URLRequestContext* context =
- request_context_getter->GetURLRequestContext();
- context->set_referrer_charset(referrer_charset);
-
rdh->BeginDownload(url,
referrer,
save_info,
true, // Show "Save as" UI.
render_process_host_id,
render_view_id,
- context);
+ *context);
}
void CancelDownloadRequest(ResourceDispatcherHost* rdh,
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 170b05c..d933d22 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -19,11 +19,6 @@
#include "views/view.h"
#endif
-namespace gfx {
-class Canvas;
-class Image;
-}
-
class BaseDownloadItemModel;
class DictionaryValue;
class DownloadItem;
@@ -36,8 +31,13 @@ class SkBitmap;
struct DownloadCreateInfo;
struct DownloadSaveInfo;
-namespace net {
-class URLRequestContextGetter;
+namespace content {
+class ResourceContext;
+}
+
+namespace gfx {
+class Canvas;
+class Image;
}
namespace download_util {
@@ -238,7 +238,7 @@ void DownloadUrl(const GURL& url,
ResourceDispatcherHost* rdh,
int render_process_host_id,
int render_view_id,
- net::URLRequestContextGetter* request_context_getter);
+ const content::ResourceContext* context);
// Tells the resource dispatcher host to cancel a download request.
// Must be called on the IO thread.
diff --git a/chrome/browser/download/save_file_manager.cc b/chrome/browser/download/save_file_manager.cc
index 874e7e7..d5df502 100644
--- a/chrome/browser/download/save_file_manager.cc
+++ b/chrome/browser/download/save_file_manager.cc
@@ -25,8 +25,6 @@
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
#include "net/base/io_buffer.h"
-#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_context_getter.h"
SaveFileManager::SaveFileManager(ResourceDispatcherHost* rdh)
: next_id_(0),
@@ -123,7 +121,7 @@ void SaveFileManager::SaveURL(
int render_view_id,
SaveFileCreateInfo::SaveFileSource save_source,
const FilePath& file_full_path,
- net::URLRequestContextGetter* request_context_getter,
+ const content::ResourceContext& context,
SavePackage* save_package) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -140,7 +138,7 @@ void SaveFileManager::SaveURL(
referrer,
render_process_host_id,
render_view_id,
- make_scoped_refptr(request_context_getter)));
+ &context));
} else {
// We manually start the save job.
SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path,
@@ -364,15 +362,13 @@ void SaveFileManager::OnSaveURL(
const GURL& referrer,
int render_process_host_id,
int render_view_id,
- net::URLRequestContextGetter* request_context_getter) {
+ const content::ResourceContext* context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- net::URLRequestContext* context =
- request_context_getter->GetURLRequestContext();
resource_dispatcher_host_->BeginSaveFile(url,
referrer,
render_process_host_id,
render_view_id,
- context);
+ *context);
}
void SaveFileManager::OnRequireSaveJobFromOtherSource(
diff --git a/chrome/browser/download/save_file_manager.h b/chrome/browser/download/save_file_manager.h
index f508d67..60a831c 100644
--- a/chrome/browser/download/save_file_manager.h
+++ b/chrome/browser/download/save_file_manager.h
@@ -66,9 +66,6 @@
#include "base/memory/ref_counted.h"
#include "chrome/browser/download/save_types.h"
-namespace net {
-class IOBuffer;
-}
class FilePath;
class GURL;
class SaveFile;
@@ -76,8 +73,12 @@ class SavePackage;
class ResourceDispatcherHost;
class Task;
+namespace content {
+class ResourceContext;
+}
+
namespace net {
-class URLRequestContextGetter;
+class IOBuffer;
}
class SaveFileManager
@@ -99,7 +100,7 @@ class SaveFileManager
int render_view_id,
SaveFileCreateInfo::SaveFileSource save_source,
const FilePath& file_full_path,
- net::URLRequestContextGetter* request_context_getter,
+ const content::ResourceContext& context,
SavePackage* save_package);
// Notifications sent from the IO thread and run on the file thread:
@@ -213,7 +214,7 @@ class SaveFileManager
const GURL& referrer,
int render_process_host_id,
int render_view_id,
- net::URLRequestContextGetter* request_context_getter);
+ const content::ResourceContext* context);
// Handler for a notification sent to the IO thread for generating save id.
void OnRequireSaveJobFromOtherSource(SaveFileCreateInfo* info);
// Call ResourceDispatcherHost's CancelRequest method to execute cancel
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index 77ef215..8b3dc36 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -53,7 +53,6 @@
#include "net/url_request/url_request_context.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClient.h"
#include "ui/base/l10n/l10n_util.h"
-#include "net/url_request/url_request_context_getter.h"
using base::Time;
using WebKit::WebPageSerializerClient;
@@ -311,8 +310,6 @@ bool SavePackage::Init() {
return false;
}
- request_context_getter_ = profile->GetRequestContext();
-
// Create the fake DownloadItem and display the view.
DownloadManager* download_manager =
tab_contents()->profile()->GetDownloadManager();
@@ -866,7 +863,7 @@ void SavePackage::SaveNextFile(bool process_all_remaining_items) {
routing_id(),
save_item->save_source(),
save_item->full_path(),
- request_context_getter_.get(),
+ tab_contents()->profile()->GetResourceContext(),
this);
} while (process_all_remaining_items && waiting_item_queue_.size());
}
diff --git a/chrome/browser/download/save_package.h b/chrome/browser/download/save_package.h
index 2c13abb..eaa7eec 100644
--- a/chrome/browser/download/save_package.h
+++ b/chrome/browser/download/save_package.h
@@ -38,10 +38,6 @@ class Thread;
class Time;
}
-namespace net {
-class URLRequestContextGetter;
-}
-
// The SavePackage object manages the process of saving a page as only-html or
// complete-html and providing the information for displaying saving status.
@@ -264,10 +260,6 @@ class SavePackage : public base::RefCountedThreadSafe<SavePackage>,
// saved_success_items_ is map of all saving job which are successfully saved.
SavedItemMap saved_success_items_;
- // The request context which provides application-specific context for
- // net::URLRequest instances.
- scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
-
// Non-owning pointer for handling file writing on the file thread.
SaveFileManager* file_manager_;
diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc
index 894a397..74b42d99 100644
--- a/chrome/browser/extensions/user_script_listener_unittest.cc
+++ b/chrome/browser/extensions/user_script_listener_unittest.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/extensions/user_script_listener.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_file_util.h"
+#include "content/browser/mock_resource_context.h"
#include "content/browser/renderer_host/global_request_id.h"
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "content/browser/renderer_host/resource_handler.h"
@@ -89,7 +90,8 @@ class DummyResourceHandler : public ResourceHandler {
ResourceDispatcherHostRequestInfo* CreateRequestInfo(int request_id) {
return new ResourceDispatcherHostRequestInfo(
new DummyResourceHandler(), ChildProcessInfo::RENDER_PROCESS, 0, 0,
- request_id, ResourceType::MAIN_FRAME, 0, false, false, false);
+ request_id, ResourceType::MAIN_FRAME, 0, false, false, false,
+ &content::MockResourceContext::GetInstance());
}
// A simple test net::URLRequestJob. We don't care what it does, only that
diff --git a/content/browser/appcache/chrome_appcache_service.cc b/content/browser/appcache/chrome_appcache_service.cc
index b829a92..e873524 100644
--- a/content/browser/appcache/chrome_appcache_service.cc
+++ b/content/browser/appcache/chrome_appcache_service.cc
@@ -85,14 +85,14 @@ bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// We don't prompt for read access.
return content::GetContentClient()->browser()->AllowAppCache(
- manifest_url, resource_context_);
+ manifest_url, *resource_context_);
}
int ChromeAppCacheService::CanCreateAppCache(
const GURL& manifest_url, net::CompletionCallback* callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
return content::GetContentClient()->browser()->AllowAppCache(
- manifest_url, resource_context_) ? net::OK : net::ERR_ACCESS_DENIED;
+ manifest_url, *resource_context_) ? net::OK : net::ERR_ACCESS_DENIED;
}
void ChromeAppCacheService::Observe(NotificationType type,
diff --git a/content/browser/content_browser_client.cc b/content/browser/content_browser_client.cc
index 2f6d597..84603af 100644
--- a/content/browser/content_browser_client.cc
+++ b/content/browser/content_browser_client.cc
@@ -53,7 +53,28 @@ std::string ContentBrowserClient::GetApplicationLocale() {
}
bool ContentBrowserClient::AllowAppCache(
- const GURL& manifest_url, const content::ResourceContext* context) {
+ const GURL& manifest_url, const content::ResourceContext& context) {
+ return true;
+}
+
+bool ContentBrowserClient::AllowGetCookie(
+ const GURL& url,
+ const GURL& first_party,
+ const net::CookieList& cookie_list,
+ const content::ResourceContext& context,
+ int render_process_id,
+ int render_view_id) {
+ return true;
+}
+
+bool ContentBrowserClient::AllowSetCookie(
+ const GURL& url,
+ const GURL& first_party,
+ const std::string& cookie_line,
+ const content::ResourceContext& context,
+ int render_process_id,
+ int render_view_id,
+ net::CookieOptions* options) {
return true;
}
diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h
index 145952b..c41027e 100644
--- a/content/browser/content_browser_client.h
+++ b/content/browser/content_browser_client.h
@@ -18,6 +18,11 @@ class RenderViewHost;
class TabContents;
class WorkerProcessHost;
+namespace net {
+class CookieList;
+class CookieOptions;
+}
+
namespace content {
class ResourceContext;
@@ -65,7 +70,26 @@ class ContentBrowserClient {
// Allow the embedder to control if an AppCache can be used for the given url.
// This is called on the IO thread.
virtual bool AllowAppCache(const GURL& manifest_url,
- const content::ResourceContext* context);
+ const content::ResourceContext& context);
+
+ // Allow the embedder to control if the given cookie can be read.
+ // This is called on the IO thread.
+ virtual bool AllowGetCookie(const GURL& url,
+ const GURL& first_party,
+ const net::CookieList& cookie_list,
+ const content::ResourceContext& context,
+ int render_process_id,
+ int render_view_id);
+
+ // Allow the embedder to control if the given cookie can be set.
+ // This is called on the IO thread.
+ virtual bool AllowSetCookie(const GURL& url,
+ const GURL& first_party,
+ const std::string& cookie_line,
+ const content::ResourceContext& context,
+ int render_process_id,
+ int render_view_id,
+ net::CookieOptions* options);
#if defined(OS_LINUX)
// Can return an optional fd for crash handling, otherwise returns -1.
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index 1cc7ec9..0f88b99 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -281,6 +281,7 @@ RenderMessageFilter::RenderMessageFilter(
extension_info_map_(profile->GetExtensionInfoMap()),
content_settings_(profile->GetHostContentSettingsMap()),
request_context_(request_context),
+ resource_context_(profile->GetResourceContext()),
extensions_request_context_(profile->GetRequestContextForExtensions()),
render_widget_helper_(render_widget_helper),
notification_prefs_(
@@ -656,8 +657,6 @@ void RenderMessageFilter::OnGenerateRoutingID(int* route_id) {
void RenderMessageFilter::OnDownloadUrl(const IPC::Message& message,
const GURL& url,
const GURL& referrer) {
- net::URLRequestContext* context = request_context_->GetURLRequestContext();
-
// Don't show "Save As" UI.
bool prompt_for_save_location = false;
resource_dispatcher_host_->BeginDownload(url,
@@ -666,7 +665,7 @@ void RenderMessageFilter::OnDownloadUrl(const IPC::Message& message,
prompt_for_save_location,
render_process_id_,
message.routing_id(),
- context);
+ resource_context_);
download_util::RecordDownloadCount(
download_util::INITIATED_BY_RENDERER_COUNT);
}
diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h
index 322053e..420d9a8 100644
--- a/content/browser/renderer_host/render_message_filter.h
+++ b/content/browser/renderer_host/render_message_filter.h
@@ -41,13 +41,18 @@ namespace WebKit {
struct WebScreenInfo;
}
-namespace gfx {
-class Rect;
+namespace content {
+class ResourceContext;
}
+
namespace base {
class SharedMemory;
}
+namespace gfx {
+class Rect;
+}
+
namespace net {
class CookieStore;
class URLRequestContextGetter;
@@ -240,6 +245,9 @@ class RenderMessageFilter : public BrowserMessageFilter {
// Contextual information to be used for requests created here.
scoped_refptr<net::URLRequestContextGetter> request_context_;
+ // The ResourceContext which is to be used on the IO thread.
+ const content::ResourceContext& resource_context_;
+
// A request context that holds a cookie store for chrome-extension URLs.
scoped_refptr<net::URLRequestContextGetter> extensions_request_context_;
diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc
index 1ef2fc8..ce775c7 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host.cc
@@ -40,6 +40,7 @@
#include "content/browser/cert_store.h"
#include "content/browser/child_process_security_policy.h"
#include "content/browser/chrome_blob_storage_context.h"
+#include "content/browser/content_browser_client.h"
#include "content/browser/cross_site_request_manager.h"
#include "content/browser/in_process_webkit/webkit_thread.h"
#include "content/browser/plugin_service.h"
@@ -567,7 +568,8 @@ void ResourceDispatcherHost::BeginRequest(
upload_size,
false, // is download
ResourceType::IsFrame(request_data.resource_type), // allow_download
- request_data.has_user_gesture);
+ request_data.has_user_gesture,
+ &resource_context);
SetRequestInfo(request, extra_info); // Request takes ownership.
chrome_browser_net::SetOriginPIDForRequest(
request_data.origin_pid, request);
@@ -697,7 +699,11 @@ ResourceHandler* ResourceDispatcherHost::CreateSafeBrowsingResourceHandler(
ResourceDispatcherHostRequestInfo*
ResourceDispatcherHost::CreateRequestInfoForBrowserRequest(
- ResourceHandler* handler, int child_id, int route_id, bool download) {
+ ResourceHandler* handler,
+ int child_id,
+ int route_id,
+ bool download,
+ const content::ResourceContext& context) {
return new ResourceDispatcherHostRequestInfo(handler,
ChildProcessInfo::RENDER_PROCESS,
child_id,
@@ -707,7 +713,8 @@ ResourceDispatcherHost::CreateRequestInfoForBrowserRequest(
0, // upload_size
download, // is_download
download, // allow_download
- false); // has_user_gesture
+ false, // has_user_gesture
+ &context);
}
void ResourceDispatcherHost::OnClosePageACK(
@@ -744,7 +751,7 @@ void ResourceDispatcherHost::BeginDownload(
bool prompt_for_save_location,
int child_id,
int route_id,
- net::URLRequestContext* request_context) {
+ const content::ResourceContext& context) {
if (is_shutdown_)
return;
@@ -789,12 +796,13 @@ void ResourceDispatcherHost::BeginDownload(
request->set_method("GET");
request->set_referrer(MaybeStripReferrer(referrer).spec());
- request->set_context(request_context);
+ request->set_context(context.request_context());
request->set_load_flags(request->load_flags() |
net::LOAD_IS_DOWNLOAD);
ResourceDispatcherHostRequestInfo* extra_info =
- CreateRequestInfoForBrowserRequest(handler, child_id, route_id, true);
+ CreateRequestInfoForBrowserRequest(
+ handler, child_id, route_id, true, context);
SetRequestInfo(request, extra_info); // Request takes ownership.
BeginRequestInternal(request);
@@ -806,7 +814,7 @@ void ResourceDispatcherHost::BeginSaveFile(
const GURL& referrer,
int child_id,
int route_id,
- net::URLRequestContext* request_context) {
+ const content::ResourceContext& context) {
if (is_shutdown_)
return;
@@ -832,11 +840,12 @@ void ResourceDispatcherHost::BeginSaveFile(
// So far, for saving page, we need fetch content from cache, in the
// future, maybe we can use a configuration to configure this behavior.
request->set_load_flags(net::LOAD_PREFERRING_CACHE);
- request->set_context(request_context);
+ request->set_context(context.request_context());
// Since we're just saving some resources we need, disallow downloading.
ResourceDispatcherHostRequestInfo* extra_info =
- CreateRequestInfoForBrowserRequest(handler, child_id, route_id, false);
+ CreateRequestInfoForBrowserRequest(
+ handler, child_id, route_id, false, context);
SetRequestInfo(request, extra_info); // Request takes ownership.
BeginRequestInternal(request);
@@ -1128,41 +1137,37 @@ void ResourceDispatcherHost::OnSSLCertificateError(
SSLManager::OnSSLCertificateError(this, request, cert_error, cert);
}
-void ResourceDispatcherHost::OnGetCookies(
- net::URLRequest* request,
- bool blocked_by_policy) {
+bool ResourceDispatcherHost::CanGetCookies(net::URLRequest* request) {
VLOG(1) << "OnGetCookies: " << request->url().spec();
-
int render_process_id, render_view_id;
if (!RenderViewForRequest(request, &render_process_id, &render_view_id))
- return;
+ return false;
net::URLRequestContext* context = request->context();
-
net::CookieMonster* cookie_monster =
context->cookie_store()->GetCookieMonster();
net::CookieList cookie_list =
cookie_monster->GetAllCookiesForURL(request->url());
- CallRenderViewHostContentSettingsDelegate(
- render_process_id, render_view_id,
- &RenderViewHostDelegate::ContentSettings::OnCookiesRead,
- request->url(), cookie_list, blocked_by_policy);
+ ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
+
+ return content::GetContentClient()->browser()->AllowGetCookie(
+ request->url(), request->first_party_for_cookies(), cookie_list,
+ *info->context(), render_process_id, render_view_id);
}
-void ResourceDispatcherHost::OnSetCookie(net::URLRequest* request,
- const std::string& cookie_line,
- const net::CookieOptions& options,
- bool blocked_by_policy) {
+bool ResourceDispatcherHost::CanSetCookie(net::URLRequest* request,
+ const std::string& cookie_line,
+ net::CookieOptions* options) {
VLOG(1) << "OnSetCookie: " << request->url().spec();
int render_process_id, render_view_id;
if (!RenderViewForRequest(request, &render_process_id, &render_view_id))
- return;
+ return false;
- CallRenderViewHostContentSettingsDelegate(
- render_process_id, render_view_id,
- &RenderViewHostDelegate::ContentSettings::OnCookieChanged,
- request->url(), cookie_line, options, blocked_by_policy);
+ ResourceDispatcherHostRequestInfo* info = InfoForRequest(request);
+ return content::GetContentClient()->browser()->AllowSetCookie(
+ request->url(), request->first_party_for_cookies(), cookie_line,
+ *info->context(), render_process_id, render_view_id, options);
}
void ResourceDispatcherHost::OnResponseStarted(net::URLRequest* request) {
diff --git a/content/browser/renderer_host/resource_dispatcher_host.h b/content/browser/renderer_host/resource_dispatcher_host.h
index 96438d9..a8b621e 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.h
+++ b/content/browser/renderer_host/resource_dispatcher_host.h
@@ -46,9 +46,9 @@ struct GlobalRequestID;
struct ResourceHostMsg_Request;
struct ViewMsg_ClosePage_Params;
-namespace net {
-class URLRequestContext;
-} // namespace net
+namespace content {
+class ResourceContext;
+}
namespace webkit_blob {
class DeletableFileReference;
@@ -80,7 +80,7 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate {
bool prompt_for_save_location,
int process_unique_id,
int route_id,
- net::URLRequestContext* request_context);
+ const content::ResourceContext& context);
// Initiates a save file from the browser process (as opposed to a resource
// request from the renderer or another child process).
@@ -88,7 +88,7 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate {
const GURL& referrer,
int process_unique_id,
int route_id,
- net::URLRequestContext* request_context);
+ const content::ResourceContext& context);
// Cancels the given request if it still exists. We ignore cancels from the
// renderer in the event of a download.
@@ -179,12 +179,10 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate {
virtual void OnSSLCertificateError(net::URLRequest* request,
int cert_error,
net::X509Certificate* cert);
- virtual void OnGetCookies(net::URLRequest* request,
- bool blocked_by_policy);
- virtual void OnSetCookie(net::URLRequest* request,
- const std::string& cookie_line,
- const net::CookieOptions& options,
- bool blocked_by_policy);
+ virtual bool CanGetCookies(net::URLRequest* request);
+ virtual bool CanSetCookie(net::URLRequest* request,
+ const std::string& cookie_line,
+ net::CookieOptions* options);
virtual void OnResponseStarted(net::URLRequest* request);
virtual void OnReadCompleted(net::URLRequest* request, int bytes_read);
void OnResponseCompleted(net::URLRequest* request);
@@ -392,7 +390,11 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate {
// (a download or a page save). |download| should be true if the request
// is a file download.
ResourceDispatcherHostRequestInfo* CreateRequestInfoForBrowserRequest(
- ResourceHandler* handler, int child_id, int route_id, bool download);
+ ResourceHandler* handler,
+ int child_id,
+ int route_id,
+ bool download,
+ const content::ResourceContext& context);
// Returns true if |request| is in |pending_requests_|.
bool IsValidRequest(net::URLRequest* request);
diff --git a/content/browser/renderer_host/resource_dispatcher_host_request_info.cc b/content/browser/renderer_host/resource_dispatcher_host_request_info.cc
index a88a13d..81df581 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_request_info.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_request_info.cc
@@ -19,7 +19,8 @@ ResourceDispatcherHostRequestInfo::ResourceDispatcherHostRequestInfo(
uint64 upload_size,
bool is_download,
bool allow_download,
- bool has_user_gesture)
+ bool has_user_gesture,
+ const content::ResourceContext* context)
: resource_handler_(handler),
cross_site_handler_(NULL),
process_type_(process_type),
@@ -37,6 +38,7 @@ ResourceDispatcherHostRequestInfo::ResourceDispatcherHostRequestInfo(
last_upload_position_(0),
waiting_for_upload_progress_ack_(false),
memory_cost_(0),
+ context_(context),
is_paused_(false),
called_on_response_started_(false),
has_started_reading_(false),
diff --git a/content/browser/renderer_host/resource_dispatcher_host_request_info.h b/content/browser/renderer_host/resource_dispatcher_host_request_info.h
index c89acdd..8abc58a 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_request_info.h
+++ b/content/browser/renderer_host/resource_dispatcher_host_request_info.h
@@ -21,6 +21,10 @@ class ResourceDispatcherHost;
class ResourceHandler;
class SSLClientAuthHandler;
+namespace content {
+class ResourceContext;
+}
+
namespace webkit_blob {
class BlobData;
}
@@ -40,7 +44,8 @@ class ResourceDispatcherHostRequestInfo : public net::URLRequest::UserData {
uint64 upload_size,
bool is_download,
bool allow_download,
- bool has_user_gesture);
+ bool has_user_gesture,
+ const content::ResourceContext* context);
virtual ~ResourceDispatcherHostRequestInfo();
// Top-level ResourceHandler servicing this request.
@@ -150,6 +155,8 @@ class ResourceDispatcherHostRequestInfo : public net::URLRequest::UserData {
}
void set_requested_blob_data(webkit_blob::BlobData* data);
+ const content::ResourceContext* context() const { return context_; }
+
private:
friend class ResourceDispatcherHost;
@@ -203,6 +210,7 @@ class ResourceDispatcherHostRequestInfo : public net::URLRequest::UserData {
bool waiting_for_upload_progress_ack_;
int memory_cost_;
scoped_refptr<webkit_blob::BlobData> requested_blob_data_;
+ const content::ResourceContext* context_;
// "Private" data accessible only to ResourceDispatcherHost (use the
// accessors above for consistency).
diff --git a/content/browser/renderer_host/resource_queue_unittest.cc b/content/browser/renderer_host/resource_queue_unittest.cc
index cf6e669..2a73c22 100644
--- a/content/browser/renderer_host/resource_queue_unittest.cc
+++ b/content/browser/renderer_host/resource_queue_unittest.cc
@@ -5,6 +5,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "content/browser/browser_thread.h"
+#include "content/browser/mock_resource_context.h"
#include "content/browser/renderer_host/global_request_id.h"
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "content/browser/renderer_host/resource_handler.h"
@@ -75,7 +76,8 @@ class DummyResourceHandler : public ResourceHandler {
ResourceDispatcherHostRequestInfo* GetRequestInfo(int request_id) {
return new ResourceDispatcherHostRequestInfo(
new DummyResourceHandler(), ChildProcessInfo::RENDER_PROCESS, 0, 0,
- request_id, ResourceType::MAIN_FRAME, 0, false, false, false);
+ request_id, ResourceType::MAIN_FRAME, 0, false, false, false,
+ &content::MockResourceContext::GetInstance());
}
void InitializeQueue(ResourceQueue* queue, ResourceQueueDelegate* delegate) {
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc
index 6fe9bef..6dcd722 100644
--- a/net/base/cookie_monster.cc
+++ b/net/base/cookie_monster.cc
@@ -305,7 +305,7 @@ Time CanonExpiration(const CookieMonster::ParsedCookie& pc,
Time expiration_time = CanonExpirationInternal(pc, current);
if (options.force_session()) {
- // Only override the expiry adte if it's in the future. If the expiry date
+ // Only override the expiry date if it's in the future. If the expiry date
// is before the creation date, the cookie is supposed to be deleted.
if (expiration_time.is_null() || expiration_time > current)
return Time();
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index cb6a4ed..3c805d7 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -100,14 +100,14 @@ void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request,
request->Cancel();
}
-void URLRequest::Delegate::OnGetCookies(URLRequest* request,
- bool blocked_by_policy) {
+bool URLRequest::Delegate::CanGetCookies(URLRequest* request) {
+ return true;
}
-void URLRequest::Delegate::OnSetCookie(URLRequest* request,
- const std::string& cookie_line,
- const CookieOptions& options,
- bool blocked_by_policy) {
+bool URLRequest::Delegate::CanSetCookie(URLRequest* request,
+ const std::string& cookie_line,
+ CookieOptions* options) {
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index 80f1edd..c43aa45 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -188,18 +188,17 @@ class URLRequest : public base::NonThreadSafe {
int cert_error,
X509Certificate* cert);
- // Called when reading cookies. |blocked_by_policy| is true if access to
- // cookies was denied due to content settings. This method will never be
- // invoked when LOAD_DO_NOT_SEND_COOKIES is specified.
- virtual void OnGetCookies(URLRequest* request, bool blocked_by_policy);
-
- // Called when a cookie is set. |blocked_by_policy| is true if the cookie
- // was rejected due to content settings. This method will never be invoked
- // when LOAD_DO_NOT_SAVE_COOKIES is specified.
- virtual void OnSetCookie(URLRequest* request,
- const std::string& cookie_line,
- const CookieOptions& options,
- bool blocked_by_policy);
+ // 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(URLRequest* request);
+
+ // 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(URLRequest* request,
+ const std::string& cookie_line,
+ CookieOptions* options);
// After calling Start(), the delegate will receive an OnResponseStarted
// callback when the request has completed. If an error occurred, the
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index 8504260..e6b07e8c 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -16,7 +16,6 @@
#include "base/string_util.h"
#include "base/time.h"
#include "net/base/cert_status_flags.h"
-#include "net/base/cookie_policy.h"
#include "net/base/cookie_store.h"
#include "net/base/filter.h"
#include "net/base/host_port_pair.h"
@@ -427,17 +426,18 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {
// be notifying our consumer asynchronously via OnStartCompleted.
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
- int policy = OK;
+ // If the request was destroyed, then there is no more work to do.
+ if (!request_)
+ return;
- if (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) {
- policy = ERR_FAILED;
- } else if (request_->context()->cookie_policy()) {
- policy = request_->context()->cookie_policy()->CanGetCookies(
- request_->url(),
- request_->first_party_for_cookies());
+ bool allow = true;
+ if (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES ||
+ (request_->delegate() &&
+ !request_->delegate()->CanGetCookies(request_))) {
+ allow = false;
}
- OnCanGetCookiesCompleted(policy);
+ OnCanGetCookiesCompleted(allow);
}
void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete() {
@@ -468,18 +468,23 @@ void URLRequestHttpJob::SaveNextCookie() {
// be notifying our consumer asynchronously via OnStartCompleted.
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
- int policy = OK;
-
+ bool allow = true;
+ CookieOptions options;
if (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) {
- policy = ERR_FAILED;
- } else if (request_->context()->cookie_policy()) {
- policy = request_->context()->cookie_policy()->CanSetCookie(
- request_->url(),
- request_->first_party_for_cookies(),
- response_cookies_[response_cookies_save_index_]);
+ allow = false;
+ } else if (request_->delegate() && request_->context()->cookie_store()) {
+ CookieOptions options;
+ options.set_include_httponly();
+ if (request_->delegate()->CanSetCookie(
+ request_,
+ response_cookies_[response_cookies_save_index_], &options)) {
+ request_->context()->cookie_store()->SetCookieWithOptions(
+ request_->url(), response_cookies_[response_cookies_save_index_],
+ options);
+ }
}
- OnCanSetCookieCompleted(policy);
+ OnCanSetCookieCompleted();
}
void URLRequestHttpJob::FetchResponseCookies(
@@ -583,69 +588,33 @@ void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() {
}
}
-void URLRequestHttpJob::OnCanGetCookiesCompleted(int policy) {
- // If the request was destroyed, then there is no more work to do.
- if (request_ && request_->delegate()) {
- if (request_->context()->cookie_store()) {
- if (policy == ERR_ACCESS_DENIED) {
- request_->delegate()->OnGetCookies(request_, true);
- } else if (policy == OK) {
- request_->delegate()->OnGetCookies(request_, false);
- CookieOptions options;
- options.set_include_httponly();
- std::string cookies =
- request_->context()->cookie_store()->GetCookiesWithOptions(
- request_->url(), options);
- if (!cookies.empty()) {
- request_info_.extra_headers.SetHeader(
- HttpRequestHeaders::kCookie, cookies);
- }
- }
- }
- // We may have been canceled within OnGetCookies.
- if (GetStatus().is_success()) {
- StartTransaction();
- } else {
- NotifyCanceled();
+void URLRequestHttpJob::OnCanGetCookiesCompleted(bool allow) {
+ if (request_->context()->cookie_store() && allow) {
+ CookieOptions options;
+ options.set_include_httponly();
+ std::string cookies =
+ request_->context()->cookie_store()->GetCookiesWithOptions(
+ request_->url(), options);
+ if (!cookies.empty()) {
+ request_info_.extra_headers.SetHeader(
+ HttpRequestHeaders::kCookie, cookies);
}
}
+ // We may have been canceled within CanGetCookies.
+ if (GetStatus().is_success()) {
+ StartTransaction();
+ } else {
+ NotifyCanceled();
+ }
}
-void URLRequestHttpJob::OnCanSetCookieCompleted(int policy) {
- // If the request was destroyed, then there is no more work to do.
- if (request_ && request_->delegate()) {
- if (request_->context()->cookie_store()) {
- if (policy == ERR_ACCESS_DENIED) {
- CookieOptions options;
- options.set_include_httponly();
- request_->delegate()->OnSetCookie(
- request_,
- response_cookies_[response_cookies_save_index_],
- options,
- true);
- } else if (policy == OK || policy == OK_FOR_SESSION_ONLY) {
- // OK to save the current response cookie now.
- CookieOptions options;
- options.set_include_httponly();
- if (policy == OK_FOR_SESSION_ONLY)
- options.set_force_session();
- request_->context()->cookie_store()->SetCookieWithOptions(
- request_->url(), response_cookies_[response_cookies_save_index_],
- options);
- request_->delegate()->OnSetCookie(
- request_,
- response_cookies_[response_cookies_save_index_],
- options,
- false);
- }
- }
- response_cookies_save_index_++;
- // We may have been canceled within OnSetCookie.
- if (GetStatus().is_success()) {
- SaveNextCookie();
- } else {
- NotifyCanceled();
- }
+void URLRequestHttpJob::OnCanSetCookieCompleted() {
+ response_cookies_save_index_++;
+ // We may have been canceled within OnSetCookie.
+ if (GetStatus().is_success()) {
+ SaveNextCookie();
+ } else {
+ NotifyCanceled();
}
}
diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h
index 7ac5c97..960db8e 100644
--- a/net/url_request/url_request_http_job.h
+++ b/net/url_request/url_request_http_job.h
@@ -53,8 +53,8 @@ class URLRequestHttpJob : public URLRequestJob {
// Process the Strict-Transport-Security header, if one exists.
void ProcessStrictTransportSecurityHeader();
- void OnCanGetCookiesCompleted(int result);
- void OnCanSetCookieCompleted(int result);
+ void OnCanGetCookiesCompleted(bool allow);
+ void OnCanSetCookieCompleted();
void OnStartCompleted(int result);
void OnReadCompleted(int result);
diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc
index f8ab98a..4f4fa65 100644
--- a/net/url_request/url_request_test_util.cc
+++ b/net/url_request/url_request_test_util.cc
@@ -11,32 +11,6 @@
#include "net/base/host_port_pair.h"
#include "net/http/http_network_session.h"
-TestCookiePolicy::TestCookiePolicy(int options_bit_mask)
- : options_(options_bit_mask) {
-}
-
-TestCookiePolicy::~TestCookiePolicy() {}
-
-int TestCookiePolicy::CanGetCookies(const GURL& url,
- const GURL& first_party) const {
- if (options_ & NO_GET_COOKIES)
- return net::ERR_ACCESS_DENIED;
-
- return net::OK;
-}
-
-int TestCookiePolicy::CanSetCookie(const GURL& url,
- const GURL& first_party,
- const std::string& cookie_line) const {
- if (options_ & NO_SET_COOKIE)
- return net::ERR_ACCESS_DENIED;
-
- if (options_ & FORCE_SESSION)
- return net::OK_FOR_SESSION_ONLY;
-
- return net::OK;
-}
-
TestURLRequestContext::TestURLRequestContext()
: ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) {
context_storage_.set_host_resolver(
@@ -113,6 +87,7 @@ 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),
@@ -161,26 +136,40 @@ void TestDelegate::OnSSLCertificateError(net::URLRequest* request,
request->Cancel();
}
-void TestDelegate::OnGetCookies(net::URLRequest* request,
- bool blocked_by_policy) {
- if (blocked_by_policy) {
+bool TestDelegate::CanGetCookies(net::URLRequest* request) {
+ bool allow = true;
+ if (cookie_options_bit_mask_ & NO_GET_COOKIES)
+ allow = false;
+
+ if (!allow) {
blocked_get_cookies_count_++;
if (cancel_in_getcookiesblocked_)
request->Cancel();
}
+
+ return allow;
}
-void TestDelegate::OnSetCookie(net::URLRequest* request,
- const std::string& cookie_line,
- const net::CookieOptions& options,
- bool blocked_by_policy) {
- if (blocked_by_policy) {
+bool TestDelegate::CanSetCookie(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_++;
if (cancel_in_setcookieblocked_)
request->Cancel();
} else {
set_cookie_count_++;
}
+
+ return allow;
}
void TestDelegate::OnResponseStarted(net::URLRequest* request) {
diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h
index f312da6..777d060 100644
--- a/net/url_request/url_request_test_util.h
+++ b/net/url_request/url_request_test_util.h
@@ -19,7 +19,6 @@
#include "base/utf_string_conversions.h"
#include "net/base/cert_verifier.h"
#include "net/base/cookie_monster.h"
-#include "net/base/cookie_policy.h"
#include "net/base/host_resolver.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -45,29 +44,6 @@ class HostPortPair;
//-----------------------------------------------------------------------------
-class TestCookiePolicy : public net::CookiePolicy {
- public:
- enum Options {
- NO_GET_COOKIES = 1 << 0,
- NO_SET_COOKIE = 1 << 1,
- FORCE_SESSION = 1 << 2,
- };
-
- explicit TestCookiePolicy(int options_bit_mask);
- virtual ~TestCookiePolicy();
-
- // net::CookiePolicy:
- virtual int CanGetCookies(const GURL& url, const GURL& first_party) const;
- virtual int CanSetCookie(const GURL& url,
- const GURL& first_party,
- const std::string& cookie_line) const;
-
- private:
- int options_;
-};
-
-//-----------------------------------------------------------------------------
-
class TestURLRequestContext : public net::URLRequestContext {
public:
TestURLRequestContext();
@@ -96,6 +72,12 @@ 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();
@@ -116,6 +98,7 @@ 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_username(const string16& u) { username_ = u; }
void set_password(const string16& p) { password_ = p; }
@@ -135,19 +118,19 @@ class TestDelegate : public net::URLRequest::Delegate {
// net::URLRequest::Delegate:
virtual void OnReceivedRedirect(net::URLRequest* request, const GURL& new_url,
- bool* defer_redirect);
+ bool* defer_redirect) OVERRIDE;
virtual void OnAuthRequired(net::URLRequest* request,
- net::AuthChallengeInfo* auth_info);
+ net::AuthChallengeInfo* auth_info) OVERRIDE;
virtual void OnSSLCertificateError(net::URLRequest* request,
int cert_error,
- net::X509Certificate* cert);
- virtual void OnGetCookies(net::URLRequest* request, bool blocked_by_policy);
- virtual void OnSetCookie(net::URLRequest* request,
- const std::string& cookie_line,
- const net::CookieOptions& options,
- bool blocked_by_policy);
- virtual void OnResponseStarted(net::URLRequest* request);
- virtual void OnReadCompleted(net::URLRequest* request, int bytes_read);
+ net::X509Certificate* cert) OVERRIDE;
+ virtual bool CanGetCookies(net::URLRequest* request) OVERRIDE;
+ virtual bool CanSetCookie(net::URLRequest* request,
+ const std::string& cookie_line,
+ net::CookieOptions* options) OVERRIDE;
+ virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
+ virtual void OnReadCompleted(net::URLRequest* request,
+ int bytes_read) OVERRIDE;
private:
static const int kBufferSize = 4096;
@@ -164,6 +147,7 @@ class TestDelegate : public net::URLRequest::Delegate {
bool quit_on_complete_;
bool quit_on_redirect_;
bool allow_certificate_errors_;
+ int cookie_options_bit_mask_;
string16 username_;
string16 password_;
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 1c0987f..ba6de05 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -1655,10 +1655,8 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
// Verify that the cookie isn't sent.
{
- TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES);
- context->set_cookie_policy(&cookie_policy);
-
TestDelegate d;
+ d.set_cookie_options(TestDelegate::NO_GET_COOKIES);
TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
req.set_context(context);
req.Start();
@@ -1667,8 +1665,6 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
== std::string::npos);
- context->set_cookie_policy(NULL);
-
EXPECT_EQ(1, d.blocked_get_cookies_count());
EXPECT_EQ(0, d.blocked_set_cookie_count());
}
@@ -1695,10 +1691,8 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
// Try to set-up another cookie and update the previous cookie.
{
- TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE);
- context->set_cookie_policy(&cookie_policy);
-
TestDelegate d;
+ d.set_cookie_options(TestDelegate::NO_SET_COOKIE);
URLRequest req(test_server.GetURL(
"set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
req.set_context(context);
@@ -1706,8 +1700,6 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
MessageLoop::current()->Run();
- context->set_cookie_policy(NULL);
-
EXPECT_EQ(0, d.blocked_get_cookies_count());
EXPECT_EQ(2, d.blocked_set_cookie_count());
}
@@ -1786,10 +1778,8 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
// Verify that the cookie isn't sent.
{
- TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES);
- context->set_cookie_policy(&cookie_policy);
-
TestDelegate d;
+ d.set_cookie_options(TestDelegate::NO_GET_COOKIES);
TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
req.set_context(context);
req.Start();
@@ -1798,8 +1788,6 @@ TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
== std::string::npos);
- context->set_cookie_policy(NULL);
-
EXPECT_EQ(1, d.blocked_get_cookies_count());
EXPECT_EQ(0, d.blocked_set_cookie_count());
}
@@ -1826,10 +1814,8 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
// Try to set-up another cookie and update the previous cookie.
{
- TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE);
- context->set_cookie_policy(&cookie_policy);
-
TestDelegate d;
+ d.set_cookie_options(TestDelegate::NO_SET_COOKIE);
URLRequest req(test_server.GetURL(
"set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
req.set_context(context);
@@ -1837,8 +1823,6 @@ TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
MessageLoop::current()->Run();
- context->set_cookie_policy(NULL);
-
EXPECT_EQ(0, d.blocked_get_cookies_count());
EXPECT_EQ(2, d.blocked_set_cookie_count());
}
@@ -1867,12 +1851,10 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) {
scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext());
- TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION);
- context->set_cookie_policy(&cookie_policy);
-
// Set up a cookie.
{
TestDelegate d;
+ d.set_cookie_options(TestDelegate::FORCE_SESSION);
URLRequest req(test_server.GetURL(
"set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d);
req.set_context(context);
@@ -1889,8 +1871,6 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) {
context->cookie_store()->GetCookieMonster()->GetAllCookies();
EXPECT_EQ(1U, cookies.size());
EXPECT_FALSE(cookies[0].IsPersistent());
-
- context->set_cookie_policy(NULL);
}
// In this test, we do a POST which the server will 302 redirect.