blob: 745336f14253305d435e55bcf9abc06f86f6c541 [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
sclittlece72c482015-08-24 20:20:5992void NetworkDelegate::NotifyNetworkBytesReceived(const URLRequest& request,
93 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
[email protected]31b2e5f2011-04-20 16:58:3299void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request,
100 const GURL& new_location) {
101 DCHECK(CalledOnValidThread());
102 DCHECK(request);
103 OnBeforeRedirect(request, new_location);
104}
105
[email protected]9045b8822012-01-13 20:35:35106void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) {
[email protected]0651b812011-02-24 00:22:50107 DCHECK(CalledOnValidThread());
108 DCHECK(request);
pkasting941842c2015-04-11 01:51:30109 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/475753 is fixed.
vadimt844c15572014-11-04 22:55:57110 tracked_objects::ScopedTracker tracking_profile(
pkasting941842c2015-04-11 01:51:30111 FROM_HERE_WITH_EXPLICIT_FUNCTION("475753 NetworkDelegate::OnCompleted"));
[email protected]9045b8822012-01-13 20:35:35112 OnCompleted(request, started);
[email protected]0651b812011-02-24 00:22:50113}
114
[email protected]4875ba12011-03-30 22:31:51115void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) {
[email protected]5aa20132011-04-27 23:11:34116 DCHECK(CalledOnValidThread());
[email protected]4875ba12011-03-30 22:31:51117 DCHECK(request);
[email protected]5aa20132011-04-27 23:11:34118 OnURLRequestDestroyed(request);
119}
120
davidbena3ef4382015-09-14 22:36:10121void NetworkDelegate::NotifyURLRequestJobOrphaned(URLRequest* request) {
122 DCHECK(CalledOnValidThread());
123 DCHECK(request);
124 OnURLRequestJobOrphaned(request);
125}
126
[email protected]82a37672011-05-03 12:02:41127void NetworkDelegate::NotifyPACScriptError(int line_number,
[email protected]42cba2fb2013-03-29 19:58:57128 const base::string16& error) {
[email protected]82a37672011-05-03 12:02:41129 DCHECK(CalledOnValidThread());
130 OnPACScriptError(line_number, error);
131}
132
[email protected]c2911d72011-10-03 22:16:36133NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired(
134 URLRequest* request,
135 const AuthChallengeInfo& auth_info,
136 const AuthCallback& callback,
137 AuthCredentials* credentials) {
[email protected]7efc582d2011-08-03 20:46:35138 DCHECK(CalledOnValidThread());
[email protected]c2911d72011-10-03 22:16:36139 return OnAuthRequired(request, auth_info, callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35140}
141
[email protected]4c219e22012-05-05 19:41:04142bool NetworkDelegate::CanGetCookies(const URLRequest& request,
143 const CookieList& cookie_list) {
[email protected]9c8ae8c2012-03-09 13:13:35144 DCHECK(CalledOnValidThread());
ttuttle859dc7a2015-04-23 19:42:29145 DCHECK(!(request.load_flags() & LOAD_DO_NOT_SEND_COOKIES));
[email protected]4c219e22012-05-05 19:41:04146 return OnCanGetCookies(request, cookie_list);
[email protected]9c8ae8c2012-03-09 13:13:35147}
148
[email protected]f33e6872013-05-07 07:00:37149bool NetworkDelegate::CanSetCookie(const URLRequest& request,
150 const std::string& cookie_line,
151 CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35152 DCHECK(CalledOnValidThread());
ttuttle859dc7a2015-04-23 19:42:29153 DCHECK(!(request.load_flags() & LOAD_DO_NOT_SAVE_COOKIES));
[email protected]4c219e22012-05-05 19:41:04154 return OnCanSetCookie(request, cookie_line, options);
155}
156
157bool NetworkDelegate::CanAccessFile(const URLRequest& request,
[email protected]a3ef4832013-02-02 05:12:33158 const base::FilePath& path) const {
[email protected]4c219e22012-05-05 19:41:04159 DCHECK(CalledOnValidThread());
160 return OnCanAccessFile(request, path);
[email protected]9c8ae8c2012-03-09 13:13:35161}
162
[email protected]e6d017652013-05-17 18:01:40163bool NetworkDelegate::CanEnablePrivacyMode(
164 const GURL& url,
165 const GURL& first_party_for_cookies) const {
166 DCHECK(CalledOnValidThread());
167 return OnCanEnablePrivacyMode(url, first_party_for_cookies);
168}
169
mkwst0513c9d2015-04-01 05:53:15170bool NetworkDelegate::FirstPartyOnlyCookieExperimentEnabled() const {
171 return OnFirstPartyOnlyCookieExperimentEnabled();
172}
173
jochen0e3b3a62014-09-16 18:31:23174bool NetworkDelegate::CancelURLRequestWithPolicyViolatingReferrerHeader(
175 const URLRequest& request,
176 const GURL& target_url,
177 const GURL& referrer_url) const {
178 DCHECK(CalledOnValidThread());
179 return OnCancelURLRequestWithPolicyViolatingReferrerHeader(
180 request, target_url, referrer_url);
181}
182
[email protected]0651b812011-02-24 00:22:50183} // namespace net