blob: 6cf7c96edf25951034645045d70742c8de3fa3d9 [file] [log] [blame]
[email protected]9045b8822012-01-13 20:35:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0651b812011-02-24 00:22:502// 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/network_delegate.h"
6
7#include "base/logging.h"
vadimt844c15572014-11-04 22:55:578#include "base/profiler/scoped_tracker.h"
[email protected]9c8ae8c2012-03-09 13:13:359#include "net/base/load_flags.h"
[email protected]c6c6e5652013-10-29 02:40:3010#include "net/base/net_errors.h"
[email protected]597a1ab2014-06-26 08:12:2711#include "net/proxy/proxy_info.h"
[email protected]9c8ae8c2012-03-09 13:13:3512#include "net/url_request/url_request.h"
[email protected]0651b812011-02-24 00:22:5013
14namespace net {
15
[email protected]084262c2011-12-01 21:12:4716int NetworkDelegate::NotifyBeforeURLRequest(
17 URLRequest* request, const CompletionCallback& callback,
18 GURL* new_url) {
[email protected]0651b812011-02-24 00:22:5019 DCHECK(CalledOnValidThread());
20 DCHECK(request);
[email protected]084262c2011-12-01 21:12:4721 DCHECK(!callback.is_null());
pkasting941842c2015-04-11 01:51:3022 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/475753 is fixed.
vadimt844c15572014-11-04 22:55:5723 tracked_objects::ScopedTracker tracking_profile(
24 FROM_HERE_WITH_EXPLICIT_FUNCTION(
pkasting941842c2015-04-11 01:51:3025 "475753 NetworkDelegate::OnBeforeURLRequest"));
[email protected]4c76d7c2011-04-15 19:14:1226 return OnBeforeURLRequest(request, callback, new_url);
[email protected]0651b812011-02-24 00:22:5027}
28
[email protected]12731792014-08-14 11:45:5429void NetworkDelegate::NotifyResolveProxy(
30 const GURL& url,
31 int load_flags,
32 const ProxyService& proxy_service,
33 ProxyInfo* result) {
[email protected]a702da72014-07-09 05:23:5434 DCHECK(CalledOnValidThread());
35 DCHECK(result);
[email protected]12731792014-08-14 11:45:5436 OnResolveProxy(url, load_flags, proxy_service, result);
[email protected]a702da72014-07-09 05:23:5437}
38
[email protected]f09f9682014-08-10 01:21:3939void NetworkDelegate::NotifyProxyFallback(
40 const ProxyServer& bad_proxy,
[email protected]d0483b192014-08-15 23:50:1741 int net_error) {
[email protected]f09f9682014-08-10 01:21:3942 DCHECK(CalledOnValidThread());
[email protected]d0483b192014-08-15 23:50:1743 OnProxyFallback(bad_proxy, net_error);
[email protected]f09f9682014-08-10 01:21:3944}
45
[email protected]084262c2011-12-01 21:12:4746int NetworkDelegate::NotifyBeforeSendHeaders(
47 URLRequest* request, const CompletionCallback& callback,
48 HttpRequestHeaders* headers) {
[email protected]0651b812011-02-24 00:22:5049 DCHECK(CalledOnValidThread());
50 DCHECK(headers);
[email protected]084262c2011-12-01 21:12:4751 DCHECK(!callback.is_null());
[email protected]636eccd2011-06-28 12:28:0152 return OnBeforeSendHeaders(request, callback, headers);
[email protected]0651b812011-02-24 00:22:5053}
54
[email protected]597a1ab2014-06-26 08:12:2755void NetworkDelegate::NotifyBeforeSendProxyHeaders(
56 URLRequest* request,
57 const ProxyInfo& proxy_info,
58 HttpRequestHeaders* headers) {
59 DCHECK(CalledOnValidThread());
60 DCHECK(headers);
61 OnBeforeSendProxyHeaders(request, proxy_info, headers);
62}
63
[email protected]5796dc942011-07-14 19:26:1064void NetworkDelegate::NotifySendHeaders(URLRequest* request,
65 const HttpRequestHeaders& headers) {
[email protected]82b42302011-04-20 16:28:1666 DCHECK(CalledOnValidThread());
[email protected]5796dc942011-07-14 19:26:1067 OnSendHeaders(request, headers);
[email protected]82b42302011-04-20 16:28:1668}
69
[email protected]ea8141e2011-10-05 13:12:5170int NetworkDelegate::NotifyHeadersReceived(
71 URLRequest* request,
[email protected]084262c2011-12-01 21:12:4772 const CompletionCallback& callback,
[email protected]507af8f2012-10-20 00:42:3273 const HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:1674 scoped_refptr<HttpResponseHeaders>* override_response_headers,
75 GURL* allowed_unsafe_redirect_url) {
[email protected]ea8141e2011-10-05 13:12:5176 DCHECK(CalledOnValidThread());
77 DCHECK(original_response_headers);
[email protected]084262c2011-12-01 21:12:4778 DCHECK(!callback.is_null());
[email protected]5f714132014-03-26 10:41:1679 return OnHeadersReceived(request,
80 callback,
81 original_response_headers,
82 override_response_headers,
83 allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:5184}
85
[email protected]0651b812011-02-24 00:22:5086void NetworkDelegate::NotifyResponseStarted(URLRequest* request) {
87 DCHECK(CalledOnValidThread());
88 DCHECK(request);
89 OnResponseStarted(request);
90}
91
sclittlea133de02015-11-10 23:54:2192void NetworkDelegate::NotifyNetworkBytesReceived(URLRequest* request,
sclittlece72c482015-08-24 20:20:5993 int64_t bytes_received) {
[email protected]8523ba52011-05-22 19:00:5894 DCHECK(CalledOnValidThread());
sclittlece72c482015-08-24 20:20:5995 DCHECK_GT(bytes_received, 0);
96 OnNetworkBytesReceived(request, bytes_received);
[email protected]8523ba52011-05-22 19:00:5897}
98
sclittlea133de02015-11-10 23:54:2199void NetworkDelegate::NotifyNetworkBytesSent(URLRequest* request,
sclittle28d558b2015-09-28 21:40:52100 int64_t bytes_sent) {
101 DCHECK(CalledOnValidThread());
102 DCHECK_GT(bytes_sent, 0);
103 OnNetworkBytesSent(request, bytes_sent);
104}
105
[email protected]31b2e5f2011-04-20 16:58:32106void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request,
107 const GURL& new_location) {
108 DCHECK(CalledOnValidThread());
109 DCHECK(request);
110 OnBeforeRedirect(request, new_location);
111}
112
[email protected]9045b8822012-01-13 20:35:35113void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) {
[email protected]0651b812011-02-24 00:22:50114 DCHECK(CalledOnValidThread());
115 DCHECK(request);
pkasting941842c2015-04-11 01:51:30116 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/475753 is fixed.
vadimt844c15572014-11-04 22:55:57117 tracked_objects::ScopedTracker tracking_profile(
pkasting941842c2015-04-11 01:51:30118 FROM_HERE_WITH_EXPLICIT_FUNCTION("475753 NetworkDelegate::OnCompleted"));
[email protected]9045b8822012-01-13 20:35:35119 OnCompleted(request, started);
[email protected]0651b812011-02-24 00:22:50120}
121
[email protected]4875ba12011-03-30 22:31:51122void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) {
[email protected]5aa20132011-04-27 23:11:34123 DCHECK(CalledOnValidThread());
[email protected]4875ba12011-03-30 22:31:51124 DCHECK(request);
[email protected]5aa20132011-04-27 23:11:34125 OnURLRequestDestroyed(request);
126}
127
davidbena3ef4382015-09-14 22:36:10128void NetworkDelegate::NotifyURLRequestJobOrphaned(URLRequest* request) {
129 DCHECK(CalledOnValidThread());
130 DCHECK(request);
131 OnURLRequestJobOrphaned(request);
132}
133
[email protected]82a37672011-05-03 12:02:41134void NetworkDelegate::NotifyPACScriptError(int line_number,
[email protected]42cba2fb2013-03-29 19:58:57135 const base::string16& error) {
[email protected]82a37672011-05-03 12:02:41136 DCHECK(CalledOnValidThread());
137 OnPACScriptError(line_number, error);
138}
139
[email protected]c2911d72011-10-03 22:16:36140NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired(
141 URLRequest* request,
142 const AuthChallengeInfo& auth_info,
143 const AuthCallback& callback,
144 AuthCredentials* credentials) {
[email protected]7efc582d2011-08-03 20:46:35145 DCHECK(CalledOnValidThread());
[email protected]c2911d72011-10-03 22:16:36146 return OnAuthRequired(request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35147}
148
[email protected]4c219e22012-05-05 19:41:04149bool NetworkDelegate::CanGetCookies(const URLRequest& request,
150 const CookieList& cookie_list) {
[email protected]9c8ae8c2012-03-09 13:13:35151 DCHECK(CalledOnValidThread());
ttuttle859dc7a2015-04-23 19:42:29152 DCHECK(!(request.load_flags() & LOAD_DO_NOT_SEND_COOKIES));
[email protected]4c219e22012-05-05 19:41:04153 return OnCanGetCookies(request, cookie_list);
[email protected]9c8ae8c2012-03-09 13:13:35154}
155
[email protected]f33e6872013-05-07 07:00:37156bool NetworkDelegate::CanSetCookie(const URLRequest& request,
157 const std::string& cookie_line,
158 CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35159 DCHECK(CalledOnValidThread());
ttuttle859dc7a2015-04-23 19:42:29160 DCHECK(!(request.load_flags() & LOAD_DO_NOT_SAVE_COOKIES));
[email protected]4c219e22012-05-05 19:41:04161 return OnCanSetCookie(request, cookie_line, options);
162}
163
164bool NetworkDelegate::CanAccessFile(const URLRequest& request,
[email protected]a3ef4832013-02-02 05:12:33165 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04166 DCHECK(CalledOnValidThread());
167 return OnCanAccessFile(request, path);
[email protected]9c8ae8c2012-03-09 13:13:35168}
169
[email protected]e6d017652013-05-17 18:01:40170bool NetworkDelegate::CanEnablePrivacyMode(
171 const GURL& url,
172 const GURL& first_party_for_cookies) const {
173 DCHECK(CalledOnValidThread());
174 return OnCanEnablePrivacyMode(url, first_party_for_cookies);
175}
176
estark7625d812015-10-12 20:10:41177bool NetworkDelegate::AreExperimentalCookieFeaturesEnabled() const {
178 return OnAreExperimentalCookieFeaturesEnabled();
mkwst0513c9d2015-04-01 05:53:15179}
180
jochen0e3b3a62014-09-16 18:31:23181bool NetworkDelegate::CancelURLRequestWithPolicyViolatingReferrerHeader(
182 const URLRequest& request,
183 const GURL& target_url,
184 const GURL& referrer_url) const {
185 DCHECK(CalledOnValidThread());
186 return OnCancelURLRequestWithPolicyViolatingReferrerHeader(
187 request, target_url, referrer_url);
188}
189
[email protected]0651b812011-02-24 00:22:50190} // namespace net