OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef NET_BASE_LAYERED_NETWORK_DELEGATE_H_ |
| 6 #define NET_BASE_LAYERED_NETWORK_DELEGATE_H_ |
| 7 |
| 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" |
| 13 |
| 14 class GURL; |
| 15 |
| 16 namespace base { |
| 17 class FilePath; |
| 18 } |
| 19 |
| 20 namespace net { |
| 21 |
| 22 class CookieOptions; |
| 23 class HttpRequestHeaders; |
| 24 class HttpResponseHeaders; |
| 25 class ProxyInfo; |
| 26 class ProxyServer; |
| 27 class ProxyService; |
| 28 class URLRequest; |
| 29 |
| 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; |
| 39 |
| 40 // NetworkDelegate implementation: |
| 41 int OnBeforeURLRequest(URLRequest* request, |
| 42 const CompletionCallback& callback, |
| 43 GURL* new_url) final override; |
| 44 void OnResolveProxy(const GURL& url, |
| 45 int load_flags, |
| 46 const ProxyService& proxy_service, |
| 47 ProxyInfo* result) final override; |
| 48 void OnProxyFallback(const ProxyServer& bad_proxy, |
| 49 int net_error) final override; |
| 50 int OnBeforeSendHeaders(URLRequest* request, |
| 51 const CompletionCallback& callback, |
| 52 HttpRequestHeaders* headers) final override; |
| 53 void OnBeforeSendProxyHeaders(URLRequest* request, |
| 54 const ProxyInfo& proxy_info, |
| 55 HttpRequestHeaders* headers) final override; |
| 56 void OnSendHeaders(URLRequest* request, |
| 57 const HttpRequestHeaders& headers) final override; |
| 58 int OnHeadersReceived( |
| 59 URLRequest* request, |
| 60 const CompletionCallback& callback, |
| 61 const HttpResponseHeaders* original_response_headers, |
| 62 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
| 63 GURL* allowed_unsafe_redirect_url) final override; |
| 64 void OnBeforeRedirect(URLRequest* request, |
| 65 const GURL& new_location) final override; |
| 66 void OnResponseStarted(URLRequest* request) final override; |
| 67 void OnRawBytesRead(const URLRequest& request, int bytes_read) final override; |
| 68 void OnCompleted(URLRequest* request, bool started) final override; |
| 69 void OnURLRequestDestroyed(URLRequest* request) final override; |
| 70 void OnPACScriptError(int line_number, |
| 71 const base::string16& error) final override; |
| 72 AuthRequiredResponse OnAuthRequired( |
| 73 URLRequest* request, |
| 74 const AuthChallengeInfo& auth_info, |
| 75 const AuthCallback& callback, |
| 76 AuthCredentials* credentials) final override; |
| 77 bool OnCanGetCookies(const URLRequest& request, |
| 78 const CookieList& cookie_list) final override; |
| 79 bool OnCanSetCookie(const URLRequest& request, |
| 80 const std::string& cookie_line, |
| 81 CookieOptions* options) final override; |
| 82 bool OnCanAccessFile(const URLRequest& request, |
| 83 const base::FilePath& path) const final override; |
| 84 bool OnCanThrottleRequest(const URLRequest& request) const final override; |
| 85 bool OnCanEnablePrivacyMode( |
| 86 const GURL& url, |
| 87 const GURL& first_party_for_cookies) const final override; |
| 88 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
| 89 const URLRequest& request, |
| 90 const GURL& target_url, |
| 91 const GURL& referrer_url) const final override; |
| 92 |
| 93 protected: |
| 94 virtual void OnBeforeURLRequestInternal(URLRequest* request, |
| 95 const CompletionCallback& callback, |
| 96 GURL* new_url); |
| 97 |
| 98 virtual void OnResolveProxyInternal(const GURL& url, |
| 99 int load_flags, |
| 100 const ProxyService& proxy_service, |
| 101 ProxyInfo* result); |
| 102 |
| 103 virtual void OnProxyFallbackInternal(const ProxyServer& bad_proxy, |
| 104 int net_error); |
| 105 |
| 106 virtual void OnBeforeSendHeadersInternal(URLRequest* request, |
| 107 const CompletionCallback& callback, |
| 108 HttpRequestHeaders* headers); |
| 109 |
| 110 virtual void OnBeforeSendProxyHeadersInternal(URLRequest* request, |
| 111 const ProxyInfo& proxy_info, |
| 112 HttpRequestHeaders* headers); |
| 113 |
| 114 virtual void OnSendHeadersInternal(URLRequest* request, |
| 115 const HttpRequestHeaders& headers); |
| 116 |
| 117 virtual void OnHeadersReceivedInternal( |
| 118 URLRequest* request, |
| 119 const CompletionCallback& callback, |
| 120 const HttpResponseHeaders* original_response_headers, |
| 121 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
| 122 GURL* allowed_unsafe_redirect_url); |
| 123 |
| 124 virtual void OnBeforeRedirectInternal(URLRequest* request, |
| 125 const GURL& new_location); |
| 126 |
| 127 virtual void OnResponseStartedInternal(URLRequest* request); |
| 128 |
| 129 virtual void OnRawBytesReadInternal(const URLRequest& request, |
| 130 int bytes_read); |
| 131 |
| 132 virtual void OnCompletedInternal(URLRequest* request, bool started); |
| 133 |
| 134 virtual void OnURLRequestDestroyedInternal(URLRequest* request); |
| 135 |
| 136 virtual void OnPACScriptErrorInternal(int line_number, |
| 137 const base::string16& error); |
| 138 |
| 139 virtual void OnCanGetCookiesInternal(const URLRequest& request, |
| 140 const CookieList& cookie_list); |
| 141 |
| 142 virtual void OnCanSetCookieInternal(const URLRequest& request, |
| 143 const std::string& cookie_line, |
| 144 CookieOptions* options); |
| 145 |
| 146 virtual void OnAuthRequiredInternal(URLRequest* request, |
| 147 const AuthChallengeInfo& auth_info, |
| 148 const AuthCallback& callback, |
| 149 AuthCredentials* credentials); |
| 150 |
| 151 virtual void OnCanAccessFileInternal(const URLRequest& request, |
| 152 const base::FilePath& path) const; |
| 153 |
| 154 virtual void OnCanThrottleRequestInternal(const URLRequest& request) const; |
| 155 |
| 156 virtual void OnCanEnablePrivacyModeInternal( |
| 157 const GURL& url, |
| 158 const GURL& first_party_for_cookies) const; |
| 159 |
| 160 virtual void OnCancelURLRequestWithPolicyViolatingReferrerHeaderInternal( |
| 161 const URLRequest& request, |
| 162 const GURL& target_url, |
| 163 const GURL& referrer_url) const; |
| 164 |
| 165 private: |
| 166 scoped_ptr<NetworkDelegate> nested_network_delegate_; |
| 167 }; |
| 168 |
| 169 } // namespace net |
| 170 |
| 171 #endif // NET_BASE_LAYERED_NETWORK_DELEGATE_H_ |
OLD | NEW |