summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc4
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.cc29
-rw-r--r--net/url_request/url_request.cc4
-rw-r--r--net/url_request/url_request.h6
4 files changed, 34 insertions, 9 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 9bf7714..8e407f7 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -400,7 +400,7 @@ const std::string& ChromeURLRequestContext::GetUserAgent(
bool ChromeURLRequestContext::interceptCookie(const URLRequest* request,
std::string* cookie) {
const URLRequest::UserData* d =
- request->GetUserData((void*)&Blacklist::kRequestDataKey);
+ request->GetUserData(&Blacklist::kRequestDataKey);
if (d) {
const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
if (match->attributes() & Blacklist::kDontStoreCookies) {
@@ -417,7 +417,7 @@ bool ChromeURLRequestContext::interceptCookie(const URLRequest* request,
bool ChromeURLRequestContext::allowSendingCookies(const URLRequest* request)
const {
const URLRequest::UserData* d =
- request->GetUserData((void*)&Blacklist::kRequestDataKey);
+ request->GetUserData(&Blacklist::kRequestDataKey);
if (d) {
const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
if (match->attributes() & Blacklist::kDontSendCookies)
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc
index a7b034f..0ea39ca 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc
@@ -393,8 +393,23 @@ void ResourceDispatcherHost::BeginRequest(
Blacklist::Match* match = context && context->blacklist() ?
context->blacklist()->findMatch(request_data.url) : NULL;
if (match && match->IsBlocked(request_data.url)) {
- // TODO(idanan): Send a ResourceResponse to replace the blocked resource.
+ // TODO(idanan): Send a ResourceResponse to replace the blocked resource
+ // instead of the FAILED return code below.
delete match;
+ URLRequestStatus status(URLRequestStatus::FAILED, net::ERR_ABORTED);
+ if (sync_result) {
+ SyncLoadResult result;
+ result.status = status;
+ ViewHostMsg_SyncLoad::WriteReplyParams(sync_result, result);
+ receiver_->Send(sync_result);
+ } else {
+ // Tell the renderer that this request was disallowed.
+ receiver_->Send(new ViewMsg_Resource_RequestComplete(
+ route_id,
+ request_id,
+ status,
+ std::string())); // No connection, security info not needed.
+ }
return;
}
@@ -426,7 +441,7 @@ void ResourceDispatcherHost::BeginRequest(
// Construct the request.
URLRequest* request = new URLRequest(request_data.url, this);
if (match) {
- request->SetUserData((void*)&Blacklist::kRequestDataKey, match);
+ request->SetUserData(&Blacklist::kRequestDataKey, match);
}
request->set_method(request_data.method);
request->set_first_party_for_cookies(request_data.first_party_for_cookies);
@@ -1045,6 +1060,16 @@ bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) {
response->response_head.app_cache_id = WebAppCacheContext::kNoAppCacheId;
request->GetMimeType(&response->response_head.mime_type);
+ const URLRequest::UserData* d =
+ request->GetUserData(&Blacklist::kRequestDataKey);
+ if (d) {
+ const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
+ if (match->attributes() & Blacklist::kBlockByType) {
+ if (match->MatchType(response->response_head.mime_type))
+ return false; // TODO(idanan): Generate a replacement response.
+ }
+ }
+
if (request->ssl_info().cert) {
int cert_id =
CertStore::GetSharedInstance()->StoreCert(
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index 18437ad..0f8ec34 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -475,14 +475,14 @@ int64 URLRequest::GetExpectedContentSize() const {
return expected_content_size;
}
-URLRequest::UserData* URLRequest::GetUserData(void* key) const {
+URLRequest::UserData* URLRequest::GetUserData(const void* key) const {
UserDataMap::const_iterator found = user_data_.find(key);
if (found != user_data_.end())
return found->second.get();
return NULL;
}
-void URLRequest::SetUserData(void* key, UserData* data) {
+void URLRequest::SetUserData(const void* key, UserData* data) {
user_data_[key] = linked_ptr<UserData>(data);
}
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index 84da0cc..b52fa3b 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -212,8 +212,8 @@ class URLRequest {
// Multiple user data values can be stored under different keys.
// This request will TAKE OWNERSHIP of the given data pointer, and will
// delete the object if it is changed or the request is destroyed.
- UserData* GetUserData(void* key) const;
- void SetUserData(void* key, UserData* data);
+ UserData* GetUserData(const void* key) const;
+ void SetUserData(const void* key, UserData* data);
// Registers a new protocol handler for the given scheme. If the scheme is
// already handled, this will overwrite the given factory. To delete the
@@ -570,7 +570,7 @@ class URLRequest {
bool is_pending_;
// Externally-defined data accessible by key
- typedef std::map<void*, linked_ptr<UserData> > UserDataMap;
+ typedef std::map<const void*, linked_ptr<UserData> > UserDataMap;
UserDataMap user_data_;
// Whether to enable performance profiling on the job serving this request.