11320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Copyright 2014 The Chromium Authors. All rights reserved.
21320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Use of this source code is governed by a BSD-style license that can be
31320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// found in the LICENSE file.
41320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef NET_BASE_PROXY_DELEGATE_H_
61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define NET_BASE_PROXY_DELEGATE_H_
71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/macros.h"
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "net/base/net_export.h"
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass GURL;
121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace net {
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass HttpRequestHeaders;
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass HttpResponseHeaders;
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass HostPortPair;
181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass ProxyInfo;
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass ProxyServer;
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass ProxyService;
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass URLRequest;
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Delegate for setting up a connection.
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass NET_EXPORT ProxyDelegate {
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public:
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ProxyDelegate() {
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual ~ProxyDelegate() {
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called as the proxy is being resolved for |url|. Allows the delegate to
331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // override the proxy resolution decision made by ProxyService. The delegate
341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // may override the decision by modifying the ProxyInfo |result|.
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnResolveProxy(const GURL& url,
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              int load_flags,
371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              const ProxyService& proxy_service,
381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              ProxyInfo* result) = 0;
391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called when use of |bad_proxy| fails due to |net_error|. |net_error| is
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // the network error encountered, if any, and OK if the fallback was
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // for a reason other than a network error (e.g. the proxy service was
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // explicitly directed to skip a proxy).
441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnFallback(const ProxyServer& bad_proxy,
451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          int net_error) = 0;
461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called after a proxy connection. Allows the delegate to read/write
481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // |headers| before they get sent out. |headers| is valid only until
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // OnCompleted or OnURLRequestDestroyed is called for this request.
501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnBeforeSendHeaders(URLRequest* request,
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                   const ProxyInfo& proxy_info,
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                   HttpRequestHeaders* headers) = 0;
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called immediately before a proxy tunnel request is sent.
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Provides the embedder an opportunity to add extra request headers.
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnBeforeTunnelRequest(const HostPortPair& proxy_server,
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     HttpRequestHeaders* extra_headers) = 0;
581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called after the response headers for the tunnel request are received.
601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnTunnelHeadersReceived(
611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const HostPortPair& origin,
621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const HostPortPair& proxy_server,
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const HttpResponseHeaders& response_headers) = 0;
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci private:
661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  DISALLOW_COPY_AND_ASSIGN(ProxyDelegate);
671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci};
681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif  // NET_BASE_PROXY_DELEGATE_H_
72