blob: 782d3ab7734fcc773a8045b740d6b16c413d6dea [file] [log] [blame]
megjablonc1751452014-12-09 19:46:471// 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.
4
5#include "net/base/layered_network_delegate.h"
6
dchengc7eeda422015-12-26 03:56:487#include <utility>
8
Matt Menked38efd92018-08-14 20:39:459#include "base/memory/ptr_util.h"
10
megjablonc1751452014-12-09 19:46:4711namespace net {
12
13LayeredNetworkDelegate::LayeredNetworkDelegate(
danakj7f767e62016-04-16 23:20:2314 std::unique_ptr<NetworkDelegate> nested_network_delegate)
Matt Menked38efd92018-08-14 20:39:4515 : owned_nested_network_delegate_(std::move(nested_network_delegate)),
16 nested_network_delegate_(owned_nested_network_delegate_.get()) {}
megjablonc1751452014-12-09 19:46:4717
Chris Watkins68b15032017-12-01 03:07:1318LayeredNetworkDelegate::~LayeredNetworkDelegate() = default;
megjablonc1751452014-12-09 19:46:4719
Matt Menked38efd92018-08-14 20:39:4520std::unique_ptr<NetworkDelegate>
21LayeredNetworkDelegate::CreatePassThroughNetworkDelegate(
22 NetworkDelegate* unowned_nested_network_delegate) {
23 return base::WrapUnique<NetworkDelegate>(
24 new LayeredNetworkDelegate(unowned_nested_network_delegate));
25}
26
David Benjamind1f287bf2018-06-12 01:57:2027int LayeredNetworkDelegate::OnBeforeURLRequest(URLRequest* request,
28 CompletionOnceCallback callback,
29 GURL* new_url) {
30 OnBeforeURLRequestInternal(request, new_url);
31 return nested_network_delegate_->NotifyBeforeURLRequest(
32 request, std::move(callback), new_url);
megjablonc1751452014-12-09 19:46:4733}
34
David Benjamind1f287bf2018-06-12 01:57:2035void LayeredNetworkDelegate::OnBeforeURLRequestInternal(URLRequest* request,
36 GURL* new_url) {}
megjablonc1751452014-12-09 19:46:4737
ryansturm2343cb62016-06-15 01:09:0038int LayeredNetworkDelegate::OnBeforeStartTransaction(
megjablonc1751452014-12-09 19:46:4739 URLRequest* request,
David Benjamind1f287bf2018-06-12 01:57:2040 CompletionOnceCallback callback,
megjablonc1751452014-12-09 19:46:4741 HttpRequestHeaders* headers) {
David Benjamind1f287bf2018-06-12 01:57:2042 OnBeforeStartTransactionInternal(request, headers);
ryansturm2343cb62016-06-15 01:09:0043 return nested_network_delegate_->NotifyBeforeStartTransaction(
David Benjamind1f287bf2018-06-12 01:57:2044 request, std::move(callback), headers);
megjablonc1751452014-12-09 19:46:4745}
46
ryansturm2343cb62016-06-15 01:09:0047void LayeredNetworkDelegate::OnBeforeStartTransactionInternal(
megjablonc1751452014-12-09 19:46:4748 URLRequest* request,
ryansturm2343cb62016-06-15 01:09:0049 HttpRequestHeaders* headers) {}
megjablonc1751452014-12-09 19:46:4750
ryansturm49a8cb12016-06-15 16:51:0951void LayeredNetworkDelegate::OnBeforeSendHeaders(
megjablonc1751452014-12-09 19:46:4752 URLRequest* request,
53 const ProxyInfo& proxy_info,
ryansturm49a8cb12016-06-15 16:51:0954 const ProxyRetryInfoMap& proxy_retry_info,
megjablonc1751452014-12-09 19:46:4755 HttpRequestHeaders* headers) {
ryansturm49a8cb12016-06-15 16:51:0956 OnBeforeSendHeadersInternal(request, proxy_info, proxy_retry_info, headers);
57 nested_network_delegate_->NotifyBeforeSendHeaders(request, proxy_info,
58 proxy_retry_info, headers);
megjablonc1751452014-12-09 19:46:4759}
60
ryansturm49a8cb12016-06-15 16:51:0961void LayeredNetworkDelegate::OnBeforeSendHeadersInternal(
megjablonc1751452014-12-09 19:46:4762 URLRequest* request,
63 const ProxyInfo& proxy_info,
ryansturm49a8cb12016-06-15 16:51:0964 const ProxyRetryInfoMap& proxy_retry_info,
65 HttpRequestHeaders* headers) {}
megjablonc1751452014-12-09 19:46:4766
ryansturm2343cb62016-06-15 01:09:0067void LayeredNetworkDelegate::OnStartTransaction(
megjablonc1751452014-12-09 19:46:4768 URLRequest* request,
69 const HttpRequestHeaders& headers) {
ryansturm2343cb62016-06-15 01:09:0070 OnStartTransactionInternal(request, headers);
71 nested_network_delegate_->NotifyStartTransaction(request, headers);
megjablonc1751452014-12-09 19:46:4772}
73
ryansturm2343cb62016-06-15 01:09:0074void LayeredNetworkDelegate::OnStartTransactionInternal(
75 URLRequest* request,
76 const HttpRequestHeaders& headers) {}
77
megjablonc1751452014-12-09 19:46:4778int LayeredNetworkDelegate::OnHeadersReceived(
79 URLRequest* request,
David Benjamind1f287bf2018-06-12 01:57:2080 CompletionOnceCallback callback,
megjablonc1751452014-12-09 19:46:4781 const HttpResponseHeaders* original_response_headers,
82 scoped_refptr<HttpResponseHeaders>* override_response_headers,
83 GURL* allowed_unsafe_redirect_url) {
David Benjamind1f287bf2018-06-12 01:57:2084 OnHeadersReceivedInternal(request, original_response_headers,
megjablonc1751452014-12-09 19:46:4785 override_response_headers,
86 allowed_unsafe_redirect_url);
87 return nested_network_delegate_->NotifyHeadersReceived(
David Benjamind1f287bf2018-06-12 01:57:2088 request, std::move(callback), original_response_headers,
89 override_response_headers, allowed_unsafe_redirect_url);
megjablonc1751452014-12-09 19:46:4790}
91
92void LayeredNetworkDelegate::OnHeadersReceivedInternal(
93 URLRequest* request,
megjablonc1751452014-12-09 19:46:4794 const HttpResponseHeaders* original_response_headers,
95 scoped_refptr<HttpResponseHeaders>* override_response_headers,
96 GURL* allowed_unsafe_redirect_url) {
97}
98
99void LayeredNetworkDelegate::OnBeforeRedirect(URLRequest* request,
100 const GURL& new_location) {
101 OnBeforeRedirectInternal(request, new_location);
102 nested_network_delegate_->NotifyBeforeRedirect(request, new_location);
103}
104
105void LayeredNetworkDelegate::OnBeforeRedirectInternal(
106 URLRequest* request,
107 const GURL& new_location) {
108}
109
maksim.sisov0f4aa142016-09-05 05:55:28110void LayeredNetworkDelegate::OnResponseStarted(URLRequest* request,
111 int net_error) {
Eric Romanb9fb9f42018-09-01 03:37:46112 OnResponseStartedInternal(request, net_error);
maksim.sisov0f4aa142016-09-05 05:55:28113 nested_network_delegate_->NotifyResponseStarted(request, net_error);
megjablonc1751452014-12-09 19:46:47114}
115
Eric Romanb9fb9f42018-09-01 03:37:46116void LayeredNetworkDelegate::OnResponseStartedInternal(URLRequest* request,
117 int net_error) {}
megjablonc1751452014-12-09 19:46:47118
sclittlea133de02015-11-10 23:54:21119void LayeredNetworkDelegate::OnNetworkBytesReceived(URLRequest* request,
sclittlece72c482015-08-24 20:20:59120 int64_t bytes_received) {
121 OnNetworkBytesReceivedInternal(request, bytes_received);
122 nested_network_delegate_->NotifyNetworkBytesReceived(request, bytes_received);
megjablonc1751452014-12-09 19:46:47123}
124
sclittlece72c482015-08-24 20:20:59125void LayeredNetworkDelegate::OnNetworkBytesReceivedInternal(
sclittlea133de02015-11-10 23:54:21126 URLRequest* request,
sclittlece72c482015-08-24 20:20:59127 int64_t bytes_received) {}
megjablonc1751452014-12-09 19:46:47128
sclittlea133de02015-11-10 23:54:21129void LayeredNetworkDelegate::OnNetworkBytesSent(URLRequest* request,
sclittle28d558b2015-09-28 21:40:52130 int64_t bytes_sent) {
131 OnNetworkBytesSentInternal(request, bytes_sent);
132 nested_network_delegate_->NotifyNetworkBytesSent(request, bytes_sent);
133}
134
sclittlea133de02015-11-10 23:54:21135void LayeredNetworkDelegate::OnNetworkBytesSentInternal(URLRequest* request,
136 int64_t bytes_sent) {}
sclittle28d558b2015-09-28 21:40:52137
maksim.sisov0f4aa142016-09-05 05:55:28138void LayeredNetworkDelegate::OnCompleted(URLRequest* request,
139 bool started,
140 int net_error) {
Matt Menke28cab822018-06-20 20:52:37141 OnCompletedInternal(request, started, net_error);
maksim.sisov0f4aa142016-09-05 05:55:28142 nested_network_delegate_->NotifyCompleted(request, started, net_error);
megjablonc1751452014-12-09 19:46:47143}
144
145void LayeredNetworkDelegate::OnCompletedInternal(URLRequest* request,
Matt Menke28cab822018-06-20 20:52:37146 bool started,
147 int net_error) {}
megjablonc1751452014-12-09 19:46:47148
149void LayeredNetworkDelegate::OnURLRequestDestroyed(URLRequest* request) {
150 OnURLRequestDestroyedInternal(request);
151 nested_network_delegate_->NotifyURLRequestDestroyed(request);
152}
153
154void LayeredNetworkDelegate::OnURLRequestDestroyedInternal(
155 URLRequest* request) {
156}
157
158void LayeredNetworkDelegate::OnPACScriptError(int line_number,
159 const base::string16& error) {
160 OnPACScriptErrorInternal(line_number, error);
161 nested_network_delegate_->NotifyPACScriptError(line_number, error);
162}
163
164void LayeredNetworkDelegate::OnPACScriptErrorInternal(
165 int line_number,
166 const base::string16& error) {
167}
168
169NetworkDelegate::AuthRequiredResponse LayeredNetworkDelegate::OnAuthRequired(
170 URLRequest* request,
171 const AuthChallengeInfo& auth_info,
David Benjamind1f287bf2018-06-12 01:57:20172 AuthCallback callback,
megjablonc1751452014-12-09 19:46:47173 AuthCredentials* credentials) {
David Benjamind1f287bf2018-06-12 01:57:20174 OnAuthRequiredInternal(request, auth_info, credentials);
175 return nested_network_delegate_->NotifyAuthRequired(
176 request, auth_info, std::move(callback), credentials);
megjablonc1751452014-12-09 19:46:47177}
178
179void LayeredNetworkDelegate::OnAuthRequiredInternal(
180 URLRequest* request,
181 const AuthChallengeInfo& auth_info,
David Benjamind1f287bf2018-06-12 01:57:20182 AuthCredentials* credentials) {}
megjablonc1751452014-12-09 19:46:47183
184bool LayeredNetworkDelegate::OnCanGetCookies(const URLRequest& request,
Clark DuValle8737642018-08-31 17:26:34185 const CookieList& cookie_list,
186 bool allowed_from_caller) {
187 return nested_network_delegate_->CanGetCookies(
188 request, cookie_list,
189 OnCanGetCookiesInternal(request, cookie_list, allowed_from_caller));
megjablonc1751452014-12-09 19:46:47190}
191
Clark DuValle8737642018-08-31 17:26:34192bool LayeredNetworkDelegate::OnCanGetCookiesInternal(
megjablonc1751452014-12-09 19:46:47193 const URLRequest& request,
Clark DuValle8737642018-08-31 17:26:34194 const CookieList& cookie_list,
195 bool allowed_from_caller) {
196 return allowed_from_caller;
197}
megjablonc1751452014-12-09 19:46:47198
199bool LayeredNetworkDelegate::OnCanSetCookie(const URLRequest& request,
Victor Costan70f85512017-11-20 16:14:46200 const net::CanonicalCookie& cookie,
Clark DuValle8737642018-08-31 17:26:34201 CookieOptions* options,
202 bool allowed_from_caller) {
203 return nested_network_delegate_->CanSetCookie(
204 request, cookie, options,
205 OnCanSetCookieInternal(request, cookie, options, allowed_from_caller));
megjablonc1751452014-12-09 19:46:47206}
207
Clark DuValle8737642018-08-31 17:26:34208bool LayeredNetworkDelegate::OnCanSetCookieInternal(
megjablonc1751452014-12-09 19:46:47209 const URLRequest& request,
Victor Costan70f85512017-11-20 16:14:46210 const net::CanonicalCookie& cookie,
Clark DuValle8737642018-08-31 17:26:34211 CookieOptions* options,
212 bool allowed_from_caller) {
213 return allowed_from_caller;
214}
megjablonc1751452014-12-09 19:46:47215
satoruxddac0442017-05-29 06:06:18216bool LayeredNetworkDelegate::OnCanAccessFile(
217 const URLRequest& request,
218 const base::FilePath& original_path,
219 const base::FilePath& absolute_path) const {
220 OnCanAccessFileInternal(request, original_path, absolute_path);
221 return nested_network_delegate_->CanAccessFile(request, original_path,
222 absolute_path);
megjablonc1751452014-12-09 19:46:47223}
224
225void LayeredNetworkDelegate::OnCanAccessFileInternal(
226 const URLRequest& request,
satoruxddac0442017-05-29 06:06:18227 const base::FilePath& original_path,
228 const base::FilePath& absolute_path) const {}
megjablonc1751452014-12-09 19:46:47229
megjablonc1751452014-12-09 19:46:47230bool LayeredNetworkDelegate::OnCanEnablePrivacyMode(
231 const GURL& url,
Mike Westb85da8ed2017-08-10 14:16:46232 const GURL& site_for_cookies) const {
Clark DuValle8737642018-08-31 17:26:34233 return OnCanEnablePrivacyModeInternal(url, site_for_cookies) ||
234 nested_network_delegate_->CanEnablePrivacyMode(url, site_for_cookies);
megjablonc1751452014-12-09 19:46:47235}
236
Clark DuValle8737642018-08-31 17:26:34237bool LayeredNetworkDelegate::OnCanEnablePrivacyModeInternal(
megjablonc1751452014-12-09 19:46:47238 const GURL& url,
Clark DuValle8737642018-08-31 17:26:34239 const GURL& site_for_cookies) const {
240 return false;
241}
megjablonc1751452014-12-09 19:46:47242
estark7625d812015-10-12 20:10:41243bool LayeredNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const {
244 OnAreExperimentalCookieFeaturesEnabledInternal();
245 return nested_network_delegate_->AreExperimentalCookieFeaturesEnabled();
mkwst0513c9d2015-04-01 05:53:15246}
247
estark7625d812015-10-12 20:10:41248void LayeredNetworkDelegate::OnAreExperimentalCookieFeaturesEnabledInternal()
249 const {}
mkwst0513c9d2015-04-01 05:53:15250
megjablonc1751452014-12-09 19:46:47251bool LayeredNetworkDelegate::
252 OnCancelURLRequestWithPolicyViolatingReferrerHeader(
253 const URLRequest& request,
254 const GURL& target_url,
255 const GURL& referrer_url) const {
Matt Menke10e6cade2018-06-20 12:54:20256 return OnCancelURLRequestWithPolicyViolatingReferrerHeaderInternal(
257 request, target_url, referrer_url) ||
258 nested_network_delegate_
259 ->CancelURLRequestWithPolicyViolatingReferrerHeader(
260 request, target_url, referrer_url);
megjablonc1751452014-12-09 19:46:47261}
262
Matt Menke10e6cade2018-06-20 12:54:20263bool LayeredNetworkDelegate::
megjablonc1751452014-12-09 19:46:47264 OnCancelURLRequestWithPolicyViolatingReferrerHeaderInternal(
265 const URLRequest& request,
266 const GURL& target_url,
267 const GURL& referrer_url) const {
Matt Menke10e6cade2018-06-20 12:54:20268 return false;
megjablonc1751452014-12-09 19:46:47269}
270
juliatuttlefcf47202017-05-23 15:53:02271bool LayeredNetworkDelegate::OnCanQueueReportingReport(
272 const url::Origin& origin) const {
273 OnCanQueueReportingReportInternal(origin);
274 return nested_network_delegate_->CanQueueReportingReport(origin);
275}
276
277void LayeredNetworkDelegate::OnCanQueueReportingReportInternal(
278 const url::Origin& origin) const {}
279
Douglas Creager7b07ea42018-02-27 21:08:08280void LayeredNetworkDelegate::OnCanSendReportingReports(
281 std::set<url::Origin> origins,
282 base::OnceCallback<void(std::set<url::Origin>)> result_callback) const {
283 OnCanSendReportingReportsInternal(origins);
284 nested_network_delegate_->CanSendReportingReports(std::move(origins),
285 std::move(result_callback));
juliatuttlefcf47202017-05-23 15:53:02286}
287
Douglas Creager7b07ea42018-02-27 21:08:08288void LayeredNetworkDelegate::OnCanSendReportingReportsInternal(
289 const std::set<url::Origin>& origins) const {}
juliatuttlefcf47202017-05-23 15:53:02290
291bool LayeredNetworkDelegate::OnCanSetReportingClient(
292 const url::Origin& origin,
293 const GURL& endpoint) const {
294 OnCanSetReportingClientInternal(origin, endpoint);
295 return nested_network_delegate_->CanSetReportingClient(origin, endpoint);
296}
297
298void LayeredNetworkDelegate::OnCanSetReportingClientInternal(
299 const url::Origin& origin,
300 const GURL& endpoint) const {}
301
302bool LayeredNetworkDelegate::OnCanUseReportingClient(
303 const url::Origin& origin,
304 const GURL& endpoint) const {
305 OnCanUseReportingClientInternal(origin, endpoint);
306 return nested_network_delegate_->CanUseReportingClient(origin, endpoint);
307}
308
309void LayeredNetworkDelegate::OnCanUseReportingClientInternal(
310 const url::Origin& origin,
311 const GURL& endpoint) const {}
312
Matt Menked38efd92018-08-14 20:39:45313LayeredNetworkDelegate::LayeredNetworkDelegate(
314 NetworkDelegate* unowned_nested_network_delegate)
315 : nested_network_delegate_(unowned_nested_network_delegate) {}
316
megjablonc1751452014-12-09 19:46:47317} // namespace net