Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / net / base / layered_network_delegate.h
blob87c1d86cff597f8d5c90b827ab1807a8d78aebd8
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"
14 class GURL;
16 namespace base {
17 class FilePath;
20 namespace net {
22 class CookieOptions;
23 class HttpRequestHeaders;
24 class HttpResponseHeaders;
25 class ProxyInfo;
26 class ProxyServer;
27 class ProxyService;
28 class URLRequest;
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 {
35 public:
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,
43 GURL* new_url) final;
44 void OnResolveProxy(const GURL& url,
45 int load_flags,
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(
58 URLRequest* request,
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;
89 protected:
90 virtual void OnBeforeURLRequestInternal(URLRequest* request,
91 const CompletionCallback& callback,
92 GURL* new_url);
94 virtual void OnResolveProxyInternal(const GURL& url,
95 int load_flags,
96 const ProxyService& proxy_service,
97 ProxyInfo* result);
99 virtual void OnProxyFallbackInternal(const ProxyServer& bad_proxy,
100 int net_error);
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(
114 URLRequest* request,
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,
126 int bytes_read);
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(
153 const GURL& url,
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;
163 private:
164 scoped_ptr<NetworkDelegate> nested_network_delegate_;
167 } // namespace net
169 #endif // NET_BASE_LAYERED_NETWORK_DELEGATE_H_