OLD | NEW |
1 // Copyright (c) 2010 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/extensions/extension_proxy_api.h" |
8 #include "chrome/browser/extensions/extension_webrequest_api.h" | 9 #include "chrome/browser/extensions/extension_webrequest_api.h" |
9 #include "chrome/browser/net/chrome_url_request_context.h" | 10 #include "chrome/browser/net/chrome_url_request_context.h" |
| 11 #include "net/base/net_errors.h" |
10 #include "net/http/http_request_headers.h" | 12 #include "net/http/http_request_headers.h" |
11 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 // Get the event router from the request context. Currently only | 17 // Get the event router from the request context. Currently only |
16 // ChromeURLRequestContexts use a network delegate, so the cast is guaranteed to | 18 // ChromeURLRequestContexts use a network delegate, so the cast is guaranteed to |
17 // work. | 19 // work. |
18 const ExtensionIOEventRouter* GetIOEventRouter( | 20 const ExtensionIOEventRouter* GetIOEventRouter( |
19 net::URLRequestContext* context) { | 21 net::URLRequestContext* context) { |
20 return static_cast<ChromeURLRequestContext*>(context)-> | 22 return static_cast<ChromeURLRequestContext*>(context)-> |
21 extension_io_event_router(); | 23 extension_io_event_router(); |
22 } | 24 } |
23 | 25 |
| 26 // If the |request| failed due to problems with a proxy, forward the error to |
| 27 // the proxy extension API. |
| 28 void ForwardProxyErrors(net::URLRequest* request) { |
| 29 if (request->status().status() == net::URLRequestStatus::FAILED) { |
| 30 switch (request->status().os_error()) { |
| 31 case net::ERR_PROXY_AUTH_UNSUPPORTED: |
| 32 case net::ERR_PROXY_CONNECTION_FAILED: |
| 33 case net::ERR_TUNNEL_CONNECTION_FAILED: |
| 34 ExtensionProxyEventRouter::GetInstance()->OnProxyError( |
| 35 GetIOEventRouter(request->context()), |
| 36 request->status().os_error()); |
| 37 } |
| 38 } |
| 39 } |
| 40 |
24 } // namespace | 41 } // namespace |
25 | 42 |
26 ChromeNetworkDelegate::ChromeNetworkDelegate() {} | 43 ChromeNetworkDelegate::ChromeNetworkDelegate() {} |
27 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} | 44 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
28 | 45 |
29 void ChromeNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request) { | 46 void ChromeNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request) { |
30 ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( | 47 ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest( |
31 GetIOEventRouter(request->context()), request->url(), request->method()); | 48 GetIOEventRouter(request->context()), request->url(), request->method()); |
32 } | 49 } |
33 | 50 |
34 void ChromeNetworkDelegate::OnSendHttpRequest( | 51 void ChromeNetworkDelegate::OnSendHttpRequest( |
35 net::HttpRequestHeaders* headers) { | 52 net::HttpRequestHeaders* headers) { |
36 DCHECK(headers); | 53 DCHECK(headers); |
37 | 54 |
38 // TODO(willchan): Add Chrome-side hooks to listen / mutate requests here. | 55 // TODO(willchan): Add Chrome-side hooks to listen / mutate requests here. |
39 } | 56 } |
| 57 |
| 58 void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) { |
| 59 ForwardProxyErrors(request); |
| 60 } |
| 61 |
| 62 void ChromeNetworkDelegate::OnReadCompleted(net::URLRequest* request, |
| 63 int bytes_read) { |
| 64 ForwardProxyErrors(request); |
| 65 } |
OLD | NEW |