Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: chrome/browser/net/chrome_network_delegate.cc

Issue 10911283: Implement 'Do Not Track' header (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/net/chrome_network_delegate.h" 5 #include "chrome/browser/net/chrome_network_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "chrome/browser/api/prefs/pref_member.h" 10 #include "chrome/browser/api/prefs/pref_member.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #else 62 #else
63 bool ChromeNetworkDelegate::g_allow_file_access_ = true; 63 bool ChromeNetworkDelegate::g_allow_file_access_ = true;
64 #endif 64 #endif
65 65
66 // This remains false unless the --disable-extensions-http-throttling 66 // This remains false unless the --disable-extensions-http-throttling
67 // flag is passed to the browser. 67 // flag is passed to the browser.
68 bool ChromeNetworkDelegate::g_never_throttle_requests_ = false; 68 bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
69 69
70 namespace { 70 namespace {
71 71
72 const char kDNTHeader[] = "DNT";
73
72 // If the |request| failed due to problems with a proxy, forward the error to 74 // If the |request| failed due to problems with a proxy, forward the error to
73 // the proxy extension API. 75 // the proxy extension API.
74 void ForwardProxyErrors(net::URLRequest* request, 76 void ForwardProxyErrors(net::URLRequest* request,
75 extensions::EventRouterForwarder* event_router, 77 extensions::EventRouterForwarder* event_router,
76 void* profile) { 78 void* profile) {
77 if (request->status().status() == net::URLRequestStatus::FAILED) { 79 if (request->status().status() == net::URLRequestStatus::FAILED) {
78 switch (request->status().error()) { 80 switch (request->status().error()) {
79 case net::ERR_PROXY_AUTH_UNSUPPORTED: 81 case net::ERR_PROXY_AUTH_UNSUPPORTED:
80 case net::ERR_PROXY_CONNECTION_FAILED: 82 case net::ERR_PROXY_CONNECTION_FAILED:
81 case net::ERR_TUNNEL_CONNECTION_FAILED: 83 case net::ERR_TUNNEL_CONNECTION_FAILED:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } // namespace 138 } // namespace
137 139
138 ChromeNetworkDelegate::ChromeNetworkDelegate( 140 ChromeNetworkDelegate::ChromeNetworkDelegate(
139 extensions::EventRouterForwarder* event_router, 141 extensions::EventRouterForwarder* event_router,
140 ExtensionInfoMap* extension_info_map, 142 ExtensionInfoMap* extension_info_map,
141 const policy::URLBlacklistManager* url_blacklist_manager, 143 const policy::URLBlacklistManager* url_blacklist_manager,
142 const ManagedModeURLFilter* managed_mode_url_filter, 144 const ManagedModeURLFilter* managed_mode_url_filter,
143 void* profile, 145 void* profile,
144 CookieSettings* cookie_settings, 146 CookieSettings* cookie_settings,
145 BooleanPrefMember* enable_referrers, 147 BooleanPrefMember* enable_referrers,
148 BooleanPrefMember* enable_do_not_track,
146 chrome_browser_net::LoadTimeStats* load_time_stats) 149 chrome_browser_net::LoadTimeStats* load_time_stats)
147 : event_router_(event_router), 150 : event_router_(event_router),
148 profile_(profile), 151 profile_(profile),
149 cookie_settings_(cookie_settings), 152 cookie_settings_(cookie_settings),
150 extension_info_map_(extension_info_map), 153 extension_info_map_(extension_info_map),
151 enable_referrers_(enable_referrers), 154 enable_referrers_(enable_referrers),
155 enable_do_not_track_(enable_do_not_track),
152 url_blacklist_manager_(url_blacklist_manager), 156 url_blacklist_manager_(url_blacklist_manager),
153 managed_mode_url_filter_(managed_mode_url_filter), 157 managed_mode_url_filter_(managed_mode_url_filter),
154 load_time_stats_(load_time_stats) { 158 load_time_stats_(load_time_stats) {
155 DCHECK(event_router); 159 DCHECK(event_router);
156 DCHECK(enable_referrers); 160 DCHECK(enable_referrers);
157 DCHECK(!profile || cookie_settings); 161 DCHECK(!profile || cookie_settings);
158 } 162 }
159 163
160 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} 164 ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
161 165
162 // static 166 // static
163 void ChromeNetworkDelegate::NeverThrottleRequests() { 167 void ChromeNetworkDelegate::NeverThrottleRequests() {
164 g_never_throttle_requests_ = true; 168 g_never_throttle_requests_ = true;
165 } 169 }
166 170
167 // static 171 // static
168 void ChromeNetworkDelegate::InitializeReferrersEnabled( 172 void ChromeNetworkDelegate::InitializePrefsOnUIThread(
169 BooleanPrefMember* enable_referrers, 173 BooleanPrefMember* enable_referrers,
174 BooleanPrefMember* enable_do_not_track,
170 PrefService* pref_service) { 175 PrefService* pref_service) {
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
172 enable_referrers->Init(prefs::kEnableReferrers, pref_service, NULL); 177 enable_referrers->Init(prefs::kEnableReferrers, pref_service, NULL);
173 enable_referrers->MoveToThread(BrowserThread::IO); 178 enable_referrers->MoveToThread(BrowserThread::IO);
179 if (enable_do_not_track) {
180 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service, NULL);
181 enable_do_not_track->MoveToThread(BrowserThread::IO);
182 }
174 } 183 }
175 184
176 // static 185 // static
177 void ChromeNetworkDelegate::AllowAccessToAllFiles() { 186 void ChromeNetworkDelegate::AllowAccessToAllFiles() {
178 g_allow_file_access_ = true; 187 g_allow_file_access_ = true;
179 } 188 }
180 189
181 int ChromeNetworkDelegate::OnBeforeURLRequest( 190 int ChromeNetworkDelegate::OnBeforeURLRequest(
182 net::URLRequest* request, 191 net::URLRequest* request,
183 const net::CompletionCallback& callback, 192 const net::CompletionCallback& callback,
(...skipping 18 matching lines...) Expand all
202 !managed_mode_url_filter_->IsURLWhitelisted(request->url())) { 211 !managed_mode_url_filter_->IsURLWhitelisted(request->url())) {
203 // Block for now. 212 // Block for now.
204 return net::ERR_NETWORK_ACCESS_DENIED; 213 return net::ERR_NETWORK_ACCESS_DENIED;
205 } 214 }
206 #endif 215 #endif
207 216
208 ForwardRequestStatus(REQUEST_STARTED, request, profile_); 217 ForwardRequestStatus(REQUEST_STARTED, request, profile_);
209 218
210 if (!enable_referrers_->GetValue()) 219 if (!enable_referrers_->GetValue())
211 request->set_referrer(std::string()); 220 request->set_referrer(std::string());
221 if (enable_do_not_track_ && enable_do_not_track_->GetValue())
222 request->SetExtraRequestHeaderByName(kDNTHeader, "1", true /* override */);
212 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( 223 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest(
213 profile_, extension_info_map_.get(), request, callback, new_url); 224 profile_, extension_info_map_.get(), request, callback, new_url);
214 } 225 }
215 226
216 int ChromeNetworkDelegate::OnBeforeSendHeaders( 227 int ChromeNetworkDelegate::OnBeforeSendHeaders(
217 net::URLRequest* request, 228 net::URLRequest* request,
218 const net::CompletionCallback& callback, 229 const net::CompletionCallback& callback,
219 net::HttpRequestHeaders* headers) { 230 net::HttpRequestHeaders* headers) {
220 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders( 231 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders(
221 profile_, extension_info_map_.get(), request, callback, headers); 232 profile_, extension_info_map_.get(), request, callback, headers);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 #endif 447 #endif
437 return net::OK; 448 return net::OK;
438 } 449 }
439 450
440 void ChromeNetworkDelegate::OnRequestWaitStateChange( 451 void ChromeNetworkDelegate::OnRequestWaitStateChange(
441 const net::URLRequest& request, 452 const net::URLRequest& request,
442 RequestWaitState state) { 453 RequestWaitState state) {
443 if (load_time_stats_) 454 if (load_time_stats_)
444 load_time_stats_->OnRequestWaitStateChange(request, state); 455 load_time_stats_->OnRequestWaitStateChange(request, state);
445 } 456 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.h ('k') | chrome/browser/net/chrome_network_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698