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
3 // found in the LICENSE file.
4
5 #include "android_webview/browser/net/aw_network_delegate.h"
6
7 #include "android_webview/browser/aw_cookie_access_policy.h"
8 #include "base/android/build_info.h"
9 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
10 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.h"
12 #include "net/base/net_errors.h"
13 #include "net/base/completion_callback.h"
14 #include "net/proxy/proxy_info.h"
15 #include "net/proxy/proxy_server.h"
16 #include "net/url_request/url_request.h"
17
18 namespace android_webview {
19
AwNetworkDelegate()20 AwNetworkDelegate::AwNetworkDelegate()
21 : data_reduction_proxy_params_(NULL),
22 data_reduction_proxy_auth_request_handler_(NULL) {
23 }
24
~AwNetworkDelegate()25 AwNetworkDelegate::~AwNetworkDelegate() {
26 }
27
OnBeforeURLRequest(net::URLRequest * request,const net::CompletionCallback & callback,GURL * new_url)28 int AwNetworkDelegate::OnBeforeURLRequest(
29 net::URLRequest* request,
30 const net::CompletionCallback& callback,
31 GURL* new_url) {
32 return net::OK;
33 }
34
OnBeforeSendHeaders(net::URLRequest * request,const net::CompletionCallback & callback,net::HttpRequestHeaders * headers)35 int AwNetworkDelegate::OnBeforeSendHeaders(
36 net::URLRequest* request,
37 const net::CompletionCallback& callback,
38 net::HttpRequestHeaders* headers) {
39
40 DCHECK(headers);
41 headers->SetHeaderIfMissing(
42 "X-Requested-With",
43 base::android::BuildInfo::GetInstance()->package_name());
44 return net::OK;
45 }
46
OnBeforeSendProxyHeaders(net::URLRequest * request,const net::ProxyInfo & proxy_info,net::HttpRequestHeaders * headers)47 void AwNetworkDelegate::OnBeforeSendProxyHeaders(
48 net::URLRequest* request,
49 const net::ProxyInfo& proxy_info,
50 net::HttpRequestHeaders* headers) {
51 if (data_reduction_proxy_auth_request_handler_) {
52 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
53 request, proxy_info.proxy_server(), headers);
54 }
55 }
56
OnSendHeaders(net::URLRequest * request,const net::HttpRequestHeaders & headers)57 void AwNetworkDelegate::OnSendHeaders(net::URLRequest* request,
58 const net::HttpRequestHeaders& headers) {
59 }
60
OnHeadersReceived(net::URLRequest * request,const net::CompletionCallback & callback,const net::HttpResponseHeaders * original_response_headers,scoped_refptr<net::HttpResponseHeaders> * override_response_headers,GURL * allowed_unsafe_redirect_url)61 int AwNetworkDelegate::OnHeadersReceived(
62 net::URLRequest* request,
63 const net::CompletionCallback& callback,
64 const net::HttpResponseHeaders* original_response_headers,
65 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
66 GURL* allowed_unsafe_redirect_url) {
67
68 data_reduction_proxy::MaybeBypassProxyAndPrepareToRetry(
69 data_reduction_proxy_params_,
70 request,
71 original_response_headers,
72 override_response_headers,
73 NULL /* returned bypass type */);
74
75 return net::OK;
76 }
77
OnBeforeRedirect(net::URLRequest * request,const GURL & new_location)78 void AwNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
79 const GURL& new_location) {
80 }
81
OnResponseStarted(net::URLRequest * request)82 void AwNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
83 }
84
OnRawBytesRead(const net::URLRequest & request,int bytes_read)85 void AwNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
86 int bytes_read) {
87 }
88
OnCompleted(net::URLRequest * request,bool started)89 void AwNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
90 }
91
OnURLRequestDestroyed(net::URLRequest * request)92 void AwNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
93 }
94
OnPACScriptError(int line_number,const base::string16 & error)95 void AwNetworkDelegate::OnPACScriptError(int line_number,
96 const base::string16& error) {
97 }
98
OnAuthRequired(net::URLRequest * request,const net::AuthChallengeInfo & auth_info,const AuthCallback & callback,net::AuthCredentials * credentials)99 net::NetworkDelegate::AuthRequiredResponse AwNetworkDelegate::OnAuthRequired(
100 net::URLRequest* request,
101 const net::AuthChallengeInfo& auth_info,
102 const AuthCallback& callback,
103 net::AuthCredentials* credentials) {
104 return AUTH_REQUIRED_RESPONSE_NO_ACTION;
105 }
106
OnCanGetCookies(const net::URLRequest & request,const net::CookieList & cookie_list)107 bool AwNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
108 const net::CookieList& cookie_list) {
109 return AwCookieAccessPolicy::GetInstance()->OnCanGetCookies(request,
110 cookie_list);
111 }
112
OnCanSetCookie(const net::URLRequest & request,const std::string & cookie_line,net::CookieOptions * options)113 bool AwNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
114 const std::string& cookie_line,
115 net::CookieOptions* options) {
116 return AwCookieAccessPolicy::GetInstance()->OnCanSetCookie(request,
117 cookie_line,
118 options);
119 }
120
OnCanAccessFile(const net::URLRequest & request,const base::FilePath & path) const121 bool AwNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
122 const base::FilePath& path) const {
123 return true;
124 }
125
OnCanThrottleRequest(const net::URLRequest & request) const126 bool AwNetworkDelegate::OnCanThrottleRequest(
127 const net::URLRequest& request) const {
128 return false;
129 }
130
OnBeforeSocketStreamConnect(net::SocketStream * stream,const net::CompletionCallback & callback)131 int AwNetworkDelegate::OnBeforeSocketStreamConnect(
132 net::SocketStream* stream,
133 const net::CompletionCallback& callback) {
134 return net::OK;
135 }
136
137 } // namespace android_webview
138