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.
5 #include "android_webview/browser/net/aw_network_delegate.h"
7 #include "android_webview/browser/aw_cookie_access_policy.h"
8 #include "base/android/build_info.h"
9 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
10 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h"
11 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.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"
18 namespace android_webview {
20 AwNetworkDelegate::AwNetworkDelegate()
21 : data_reduction_proxy_params_(NULL),
22 data_reduction_proxy_auth_request_handler_(NULL) {
25 AwNetworkDelegate::~AwNetworkDelegate() {
28 int AwNetworkDelegate::OnBeforeURLRequest(
29 net::URLRequest* request,
30 const net::CompletionCallback& callback,
35 int AwNetworkDelegate::OnBeforeSendHeaders(
36 net::URLRequest* request,
37 const net::CompletionCallback& callback,
38 net::HttpRequestHeaders* headers) {
41 headers->SetHeaderIfMissing(
43 base::android::BuildInfo::GetInstance()->package_name());
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);
57 void AwNetworkDelegate::OnSendHeaders(net::URLRequest* request,
58 const net::HttpRequestHeaders& headers) {
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) {
70 void AwNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
71 const GURL& new_location) {
74 void AwNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
77 void AwNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
81 void AwNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
84 void AwNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
87 void AwNetworkDelegate::OnPACScriptError(int line_number,
88 const base::string16& error) {
91 net::NetworkDelegate::AuthRequiredResponse AwNetworkDelegate::OnAuthRequired(
92 net::URLRequest* request,
93 const net::AuthChallengeInfo& auth_info,
94 const AuthCallback& callback,
95 net::AuthCredentials* credentials) {
96 return AUTH_REQUIRED_RESPONSE_NO_ACTION;
99 bool AwNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
100 const net::CookieList& cookie_list) {
101 return AwCookieAccessPolicy::GetInstance()->OnCanGetCookies(request,
105 bool AwNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
106 const std::string& cookie_line,
107 net::CookieOptions* options) {
108 return AwCookieAccessPolicy::GetInstance()->OnCanSetCookie(request,
113 bool AwNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
114 const base::FilePath& path) const {
118 bool AwNetworkDelegate::OnCanThrottleRequest(
119 const net::URLRequest& request) const {
123 int AwNetworkDelegate::OnBeforeSocketStreamConnect(
124 net::SocketStream* stream,
125 const net::CompletionCallback& callback) {
129 } // namespace android_webview