OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/custom_handlers/protocol_handler_registry.h" | 8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
9 #include "chrome/browser/extensions/extension_event_router_forwarder.h" | 9 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
10 #include "chrome/browser/extensions/extension_proxy_api.h" | 10 #include "chrome/browser/extensions/extension_proxy_api.h" |
11 #include "chrome/browser/extensions/extension_webrequest_api.h" | 11 #include "chrome/browser/extensions/extension_webrequest_api.h" |
| 12 #include "chrome/browser/prefs/pref_member.h" |
12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
13 #include "net/http/http_request_headers.h" | 14 #include "net/http/http_request_headers.h" |
14 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // If the |request| failed due to problems with a proxy, forward the error to | 19 // If the |request| failed due to problems with a proxy, forward the error to |
19 // the proxy extension API. | 20 // the proxy extension API. |
20 void ForwardProxyErrors(net::URLRequest* request, | 21 void ForwardProxyErrors(net::URLRequest* request, |
21 ExtensionEventRouterForwarder* event_router, | 22 ExtensionEventRouterForwarder* event_router, |
22 ProfileId profile_id) { | 23 ProfileId profile_id) { |
23 if (request->status().status() == net::URLRequestStatus::FAILED) { | 24 if (request->status().status() == net::URLRequestStatus::FAILED) { |
24 switch (request->status().os_error()) { | 25 switch (request->status().os_error()) { |
25 case net::ERR_PROXY_AUTH_UNSUPPORTED: | 26 case net::ERR_PROXY_AUTH_UNSUPPORTED: |
26 case net::ERR_PROXY_CONNECTION_FAILED: | 27 case net::ERR_PROXY_CONNECTION_FAILED: |
27 case net::ERR_TUNNEL_CONNECTION_FAILED: | 28 case net::ERR_TUNNEL_CONNECTION_FAILED: |
28 ExtensionProxyEventRouter::GetInstance()->OnProxyError( | 29 ExtensionProxyEventRouter::GetInstance()->OnProxyError( |
29 event_router, profile_id, request->status().os_error()); | 30 event_router, profile_id, request->status().os_error()); |
30 } | 31 } |
31 } | 32 } |
32 } | 33 } |
33 | 34 |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 ChromeNetworkDelegate::ChromeNetworkDelegate( | 37 ChromeNetworkDelegate::ChromeNetworkDelegate( |
37 ExtensionEventRouterForwarder* event_router, | 38 ExtensionEventRouterForwarder* event_router, |
38 ProfileId profile_id, | 39 ProfileId profile_id, |
| 40 BooleanPrefMember* enable_referrers, |
39 ProtocolHandlerRegistry* protocol_handler_registry) | 41 ProtocolHandlerRegistry* protocol_handler_registry) |
40 : event_router_(event_router), | 42 : event_router_(event_router), |
41 profile_id_(profile_id), | 43 profile_id_(profile_id), |
| 44 enable_referrers_(enable_referrers), |
42 protocol_handler_registry_(protocol_handler_registry) { | 45 protocol_handler_registry_(protocol_handler_registry) { |
43 DCHECK(event_router); | 46 DCHECK(event_router); |
44 } | 47 } |
45 | 48 |
46 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} | 49 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
47 | 50 |
48 int ChromeNetworkDelegate::OnBeforeURLRequest( | 51 int ChromeNetworkDelegate::OnBeforeURLRequest( |
49 net::URLRequest* request, net::CompletionCallback* callback) { | 52 net::URLRequest* request, net::CompletionCallback* callback) { |
| 53 if (!enable_referrers_.get() || !enable_referrers_->GetValue()) |
| 54 request->set_referrer(std::string()); |
50 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( | 55 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( |
51 profile_id_, event_router_.get(), request, callback); | 56 profile_id_, event_router_.get(), request, callback); |
52 } | 57 } |
53 | 58 |
54 int ChromeNetworkDelegate::OnBeforeSendHeaders( | 59 int ChromeNetworkDelegate::OnBeforeSendHeaders( |
55 uint64 request_id, | 60 uint64 request_id, |
56 net::HttpRequestHeaders* headers, | 61 net::HttpRequestHeaders* headers, |
57 net::CompletionCallback* callback) { | 62 net::CompletionCallback* callback) { |
58 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders( | 63 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders( |
59 profile_id_, event_router_.get(), request_id, headers, callback); | 64 profile_id_, event_router_.get(), request_id, headers, callback); |
(...skipping 12 matching lines...) Expand all Loading... |
72 ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed( | 77 ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed( |
73 profile_id_, request); | 78 profile_id_, request); |
74 } | 79 } |
75 | 80 |
76 net::URLRequestJob* ChromeNetworkDelegate::OnMaybeCreateURLRequestJob( | 81 net::URLRequestJob* ChromeNetworkDelegate::OnMaybeCreateURLRequestJob( |
77 net::URLRequest* request) { | 82 net::URLRequest* request) { |
78 if (!protocol_handler_registry_) | 83 if (!protocol_handler_registry_) |
79 return NULL; | 84 return NULL; |
80 return protocol_handler_registry_->MaybeCreateJob(request); | 85 return protocol_handler_registry_->MaybeCreateJob(request); |
81 } | 86 } |
OLD | NEW |