summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-09 13:13:35 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-09 13:13:35 +0000
commit9c8ae8c661753f4a9eac82e0bcea016dadacf252 (patch)
treeacd3fbd4b97ace520b934d4d8f72132a018dd721 /chrome/browser
parent594730f547d4b93676ec060334c49295315e392e (diff)
downloadchromium_src-9c8ae8c661753f4a9eac82e0bcea016dadacf252.zip
chromium_src-9c8ae8c661753f4a9eac82e0bcea016dadacf252.tar.gz
chromium_src-9c8ae8c661753f4a9eac82e0bcea016dadacf252.tar.bz2
Do cookie checks in NetworkDelegate instead of the URLRequest::Delegate.
As a side effect, requests going through URLFetcher now also have to pass cookie checks. Requests from the URLFetcher can be optionally annotated with a render view, so the user can be notified about blocked cookies. This plumbing is done for the alternate nav url fetcher, and the template url fetcher. BUG=116322 TEST=manual/pyauto Review URL: https://chromiumcodereview.appspot.com/9572001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/alternate_nav_url_fetcher.cc9
-rw-r--r--chrome/browser/chromeos/imageburner/burn_manager.cc3
-rw-r--r--chrome/browser/extensions/api/webrequest/webrequest_api_unittest.cc29
-rw-r--r--chrome/browser/extensions/extension_warning_set.cc1
-rw-r--r--chrome/browser/io_thread.cc1
-rw-r--r--chrome/browser/net/chrome_network_delegate.cc59
-rw-r--r--chrome/browser/net/chrome_network_delegate.h17
-rw-r--r--chrome/browser/profiles/profile_io_data.cc1
-rw-r--r--chrome/browser/search_engines/template_url_fetcher.cc17
-rw-r--r--chrome/browser/search_engines/template_url_fetcher.h7
-rw-r--r--chrome/browser/search_engines/template_url_fetcher_unittest.cc4
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.h4
-rw-r--r--chrome/browser/ui/search_engines/search_engine_tab_helper.cc1
13 files changed, 138 insertions, 15 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);
}