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 CHROME_BROWSER_NET_CHROME_EXTENSIONS_NETWORK_DELEGATE_H_
6#define CHROME_BROWSER_NET_CHROME_EXTENSIONS_NETWORK_DELEGATE_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "base/memory/ref_counted.h"
11#include "net/base/network_delegate.h"
12
13namespace extensions {
14class EventRouterForwarder;
15class InfoMap;
16}
17
18// ChromeExtensionsNetworkDelegate is the extensions-only portion of
19// ChromeNetworkDelegate. When extensions are disabled, do nothing.
20class ChromeExtensionsNetworkDelegate : public net::NetworkDelegate {
21 public:
22  static ChromeExtensionsNetworkDelegate* Create(
23      extensions::EventRouterForwarder* event_router);
24
25  virtual ~ChromeExtensionsNetworkDelegate();
26
27  // Not inlined because we assign a scoped_refptr, which requires us to include
28  // the header file.
29  void set_extension_info_map(extensions::InfoMap* extension_info_map);
30
31  // If |profile| is NULL or not set, events will be broadcast to all profiles,
32  // otherwise they will only be sent to the specified profile.
33  void set_profile(void* profile) {
34    profile_ = profile;
35  }
36
37  // If the |request| failed due to problems with a proxy, forward the error to
38  // the proxy extension API.
39  virtual void ForwardProxyErrors(net::URLRequest* request);
40
41  // Notifies the extensions::ProcessManager for the associated RenderFrame, if
42  // any, that a request has started or stopped.
43  virtual void ForwardStartRequestStatus(net::URLRequest* request);
44  virtual void ForwardDoneRequestStatus(net::URLRequest* request);
45
46  // NetworkDelegate implementation.
47  virtual int OnBeforeURLRequest(net::URLRequest* request,
48                                 const net::CompletionCallback& callback,
49                                 GURL* new_url) OVERRIDE;
50  virtual int OnBeforeSendHeaders(net::URLRequest* request,
51                                  const net::CompletionCallback& callback,
52                                  net::HttpRequestHeaders* headers) OVERRIDE;
53  virtual void OnSendHeaders(net::URLRequest* request,
54                             const net::HttpRequestHeaders& headers) OVERRIDE;
55  virtual int OnHeadersReceived(
56      net::URLRequest* request,
57      const net::CompletionCallback& callback,
58      const net::HttpResponseHeaders* original_response_headers,
59      scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
60      GURL* allowed_unsafe_redirect_url) OVERRIDE;
61  virtual void OnBeforeRedirect(net::URLRequest* request,
62                                const GURL& new_location) OVERRIDE;
63  virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
64  virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE;
65  virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE;
66  virtual void OnPACScriptError(int line_number,
67                                const base::string16& error) OVERRIDE;
68  virtual net::NetworkDelegate::AuthRequiredResponse OnAuthRequired(
69      net::URLRequest* request,
70      const net::AuthChallengeInfo& auth_info,
71      const AuthCallback& callback,
72      net::AuthCredentials* credentials) OVERRIDE;
73
74 protected:
75  ChromeExtensionsNetworkDelegate();
76
77  void* profile_;
78
79#if defined(ENABLE_EXTENSIONS)
80  scoped_refptr<extensions::InfoMap> extension_info_map_;
81#endif
82
83  DISALLOW_COPY_AND_ASSIGN(ChromeExtensionsNetworkDelegate);
84};
85
86#endif  // CHROME_BROWSER_NET_CHROME_EXTENSIONS_NETWORK_DELEGATE_H_
87