1 // Copyright 2014 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 #ifndef NET_BASE_LAYERED_NETWORK_DELEGATE_H_
6 #define NET_BASE_LAYERED_NETWORK_DELEGATE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "net/base/completion_callback.h"
11 #include "net/base/network_delegate.h"
12 #include "net/cookies/canonical_cookie.h"
23 class HttpRequestHeaders
;
24 class HttpResponseHeaders
;
30 // WrappingNetworkDelegate takes a |network_delegate| and extends it. When
31 // On*() is called, the On*Internal() method of this is first called and then
32 // the On*() of |network_delegate| is called. On*Internal() methods have no
33 // return values, and cannot prevent calling into the nested network delegate.
34 class NET_EXPORT LayeredNetworkDelegate
: public NetworkDelegate
{
36 explicit LayeredNetworkDelegate(
37 scoped_ptr
<NetworkDelegate
> nested_network_delegate
);
38 ~LayeredNetworkDelegate() override
;
40 // NetworkDelegate implementation:
41 int OnBeforeURLRequest(URLRequest
* request
,
42 const CompletionCallback
& callback
,
44 void OnResolveProxy(const GURL
& url
,
46 const ProxyService
& proxy_service
,
47 ProxyInfo
* result
) final
;
48 void OnProxyFallback(const ProxyServer
& bad_proxy
, int net_error
) final
;
49 int OnBeforeSendHeaders(URLRequest
* request
,
50 const CompletionCallback
& callback
,
51 HttpRequestHeaders
* headers
) final
;
52 void OnBeforeSendProxyHeaders(URLRequest
* request
,
53 const ProxyInfo
& proxy_info
,
54 HttpRequestHeaders
* headers
) final
;
55 void OnSendHeaders(URLRequest
* request
,
56 const HttpRequestHeaders
& headers
) final
;
57 int OnHeadersReceived(
59 const CompletionCallback
& callback
,
60 const HttpResponseHeaders
* original_response_headers
,
61 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
62 GURL
* allowed_unsafe_redirect_url
) final
;
63 void OnBeforeRedirect(URLRequest
* request
, const GURL
& new_location
) final
;
64 void OnResponseStarted(URLRequest
* request
) final
;
65 void OnRawBytesRead(const URLRequest
& request
, int bytes_read
) final
;
66 void OnCompleted(URLRequest
* request
, bool started
) final
;
67 void OnURLRequestDestroyed(URLRequest
* request
) final
;
68 void OnPACScriptError(int line_number
, const base::string16
& error
) final
;
69 AuthRequiredResponse
OnAuthRequired(URLRequest
* request
,
70 const AuthChallengeInfo
& auth_info
,
71 const AuthCallback
& callback
,
72 AuthCredentials
* credentials
) final
;
73 bool OnCanGetCookies(const URLRequest
& request
,
74 const CookieList
& cookie_list
) final
;
75 bool OnCanSetCookie(const URLRequest
& request
,
76 const std::string
& cookie_line
,
77 CookieOptions
* options
) final
;
78 bool OnCanAccessFile(const URLRequest
& request
,
79 const base::FilePath
& path
) const final
;
80 bool OnCanThrottleRequest(const URLRequest
& request
) const final
;
81 bool OnCanEnablePrivacyMode(const GURL
& url
,
82 const GURL
& first_party_for_cookies
) const final
;
83 bool OnFirstPartyOnlyCookieExperimentEnabled() const final
;
84 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
85 const URLRequest
& request
,
86 const GURL
& target_url
,
87 const GURL
& referrer_url
) const final
;
90 virtual void OnBeforeURLRequestInternal(URLRequest
* request
,
91 const CompletionCallback
& callback
,
94 virtual void OnResolveProxyInternal(const GURL
& url
,
96 const ProxyService
& proxy_service
,
99 virtual void OnProxyFallbackInternal(const ProxyServer
& bad_proxy
,
102 virtual void OnBeforeSendHeadersInternal(URLRequest
* request
,
103 const CompletionCallback
& callback
,
104 HttpRequestHeaders
* headers
);
106 virtual void OnBeforeSendProxyHeadersInternal(URLRequest
* request
,
107 const ProxyInfo
& proxy_info
,
108 HttpRequestHeaders
* headers
);
110 virtual void OnSendHeadersInternal(URLRequest
* request
,
111 const HttpRequestHeaders
& headers
);
113 virtual void OnHeadersReceivedInternal(
115 const CompletionCallback
& callback
,
116 const HttpResponseHeaders
* original_response_headers
,
117 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
118 GURL
* allowed_unsafe_redirect_url
);
120 virtual void OnBeforeRedirectInternal(URLRequest
* request
,
121 const GURL
& new_location
);
123 virtual void OnResponseStartedInternal(URLRequest
* request
);
125 virtual void OnRawBytesReadInternal(const URLRequest
& request
,
128 virtual void OnCompletedInternal(URLRequest
* request
, bool started
);
130 virtual void OnURLRequestDestroyedInternal(URLRequest
* request
);
132 virtual void OnPACScriptErrorInternal(int line_number
,
133 const base::string16
& error
);
135 virtual void OnCanGetCookiesInternal(const URLRequest
& request
,
136 const CookieList
& cookie_list
);
138 virtual void OnCanSetCookieInternal(const URLRequest
& request
,
139 const std::string
& cookie_line
,
140 CookieOptions
* options
);
142 virtual void OnAuthRequiredInternal(URLRequest
* request
,
143 const AuthChallengeInfo
& auth_info
,
144 const AuthCallback
& callback
,
145 AuthCredentials
* credentials
);
147 virtual void OnCanAccessFileInternal(const URLRequest
& request
,
148 const base::FilePath
& path
) const;
150 virtual void OnCanThrottleRequestInternal(const URLRequest
& request
) const;
152 virtual void OnCanEnablePrivacyModeInternal(
154 const GURL
& first_party_for_cookies
) const;
156 virtual void OnFirstPartyOnlyCookieExperimentEnabledInternal() const;
158 virtual void OnCancelURLRequestWithPolicyViolatingReferrerHeaderInternal(
159 const URLRequest
& request
,
160 const GURL
& target_url
,
161 const GURL
& referrer_url
) const;
164 scoped_ptr
<NetworkDelegate
> nested_network_delegate_
;
169 #endif // NET_BASE_LAYERED_NETWORK_DELEGATE_H_