| 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); |
| 47 DCHECK(enable_referrers); |
| 44 } | 48 } |
| 45 | 49 |
| 46 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} | 50 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
| 47 | 51 |
| 48 int ChromeNetworkDelegate::OnBeforeURLRequest( | 52 int ChromeNetworkDelegate::OnBeforeURLRequest( |
| 49 net::URLRequest* request, net::CompletionCallback* callback) { | 53 net::URLRequest* request, net::CompletionCallback* callback) { |
| 54 if (!enable_referrers_->GetValue()) |
| 55 request->set_referrer(std::string()); |
| 50 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( | 56 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( |
| 51 profile_id_, event_router_.get(), request, callback); | 57 profile_id_, event_router_.get(), request, callback); |
| 52 } | 58 } |
| 53 | 59 |
| 54 int ChromeNetworkDelegate::OnBeforeSendHeaders( | 60 int ChromeNetworkDelegate::OnBeforeSendHeaders( |
| 55 uint64 request_id, | 61 uint64 request_id, |
| 56 net::HttpRequestHeaders* headers, | 62 net::HttpRequestHeaders* headers, |
| 57 net::CompletionCallback* callback) { | 63 net::CompletionCallback* callback) { |
| 58 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders( | 64 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders( |
| 59 profile_id_, event_router_.get(), request_id, headers, callback); | 65 profile_id_, event_router_.get(), request_id, headers, callback); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 72 ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed( | 78 ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed( |
| 73 profile_id_, request); | 79 profile_id_, request); |
| 74 } | 80 } |
| 75 | 81 |
| 76 net::URLRequestJob* ChromeNetworkDelegate::OnMaybeCreateURLRequestJob( | 82 net::URLRequestJob* ChromeNetworkDelegate::OnMaybeCreateURLRequestJob( |
| 77 net::URLRequest* request) { | 83 net::URLRequest* request) { |
| 78 if (!protocol_handler_registry_) | 84 if (!protocol_handler_registry_) |
| 79 return NULL; | 85 return NULL; |
| 80 return protocol_handler_registry_->MaybeCreateJob(request); | 86 return protocol_handler_registry_->MaybeCreateJob(request); |
| 81 } | 87 } |
| OLD | NEW |