Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / net / chrome_network_delegate.h
blob88c34595c863e87b8fe9c1b1816aba89574bdb79
1 // Copyright (c) 2012 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 CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_
6 #define CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/values.h"
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h"
17 #include "net/base/network_delegate_impl.h"
19 class ChromeExtensionsNetworkDelegate;
20 class CookieSettings;
21 class PrefService;
23 template<class T> class PrefMember;
25 typedef PrefMember<bool> BooleanPrefMember;
27 namespace base {
28 class Value;
31 namespace chrome_browser_net {
32 class ConnectInterceptor;
33 class Predictor;
36 namespace domain_reliability {
37 class DomainReliabilityMonitor;
40 namespace extensions {
41 class EventRouterForwarder;
42 class InfoMap;
45 namespace net {
46 class URLRequest;
49 namespace policy {
50 class URLBlacklistManager;
53 // ChromeNetworkDelegate is the central point from within the chrome code to
54 // add hooks into the network stack.
55 class ChromeNetworkDelegate : public net::NetworkDelegateImpl {
56 public:
57 // |enable_referrers| (and all of the other optional PrefMembers) should be
58 // initialized on the UI thread (see below) beforehand. This object's owner is
59 // responsible for cleaning them up at shutdown.
60 ChromeNetworkDelegate(extensions::EventRouterForwarder* event_router,
61 BooleanPrefMember* enable_referrers);
62 ~ChromeNetworkDelegate() override;
64 // Pass through to ChromeExtensionsNetworkDelegate::set_extension_info_map().
65 void set_extension_info_map(extensions::InfoMap* extension_info_map);
67 #if defined(ENABLE_CONFIGURATION_POLICY)
68 void set_url_blacklist_manager(
69 const policy::URLBlacklistManager* url_blacklist_manager) {
70 url_blacklist_manager_ = url_blacklist_manager;
72 #endif
74 // If |profile| is NULL or not set, events will be broadcast to all profiles,
75 // otherwise they will only be sent to the specified profile.
76 // Also pass through to ChromeExtensionsNetworkDelegate::set_profile().
77 void set_profile(void* profile);
79 // |profile_path| is used to locate the "Downloads" folder on Chrome OS. If it
80 // is set, the location of the Downloads folder for the profile is added to
81 // the whitelist for accesses via file: scheme.
82 void set_profile_path(const base::FilePath& profile_path) {
83 profile_path_ = profile_path;
86 // If |cookie_settings| is NULL or not set, all cookies are enabled,
87 // otherwise the settings are enforced on all observed network requests.
88 // Not inlined because we assign a scoped_refptr, which requires us to include
89 // the header file. Here we just forward-declare it.
90 void set_cookie_settings(CookieSettings* cookie_settings);
92 // Causes requested URLs to be fed to |predictor| via ConnectInterceptor.
93 void set_predictor(chrome_browser_net::Predictor* predictor);
95 void set_enable_do_not_track(BooleanPrefMember* enable_do_not_track) {
96 enable_do_not_track_ = enable_do_not_track;
99 void set_force_safe_search(
100 BooleanPrefMember* force_safe_search) {
101 force_safe_search_ = force_safe_search;
104 void set_force_google_safe_search(
105 BooleanPrefMember* force_google_safe_search) {
106 force_google_safe_search_ = force_google_safe_search;
109 void set_force_youtube_safety_mode(
110 BooleanPrefMember* force_youtube_safety_mode) {
111 force_youtube_safety_mode_ = force_youtube_safety_mode;
114 void set_domain_reliability_monitor(
115 domain_reliability::DomainReliabilityMonitor* monitor) {
116 domain_reliability_monitor_ = monitor;
119 // Causes |OnCanThrottleRequest| to always return false, for all
120 // instances of this object.
121 static void NeverThrottleRequests();
123 // Binds the pref members to |pref_service| and moves them to the IO thread.
124 // |enable_referrers| cannot be NULL, the others can.
125 // This method should be called on the UI thread.
126 static void InitializePrefsOnUIThread(
127 BooleanPrefMember* enable_referrers,
128 BooleanPrefMember* enable_do_not_track,
129 BooleanPrefMember* force_safe_search,
130 BooleanPrefMember* force_google_safe_search,
131 BooleanPrefMember* force_youtube_safety_mode,
132 PrefService* pref_service);
134 // When called, all file:// URLs will now be accessible. If this is not
135 // called, then some platforms restrict access to file:// paths.
136 static void AllowAccessToAllFiles();
138 private:
139 friend class ChromeNetworkDelegateThrottlingTest;
141 // NetworkDelegate implementation.
142 int OnBeforeURLRequest(net::URLRequest* request,
143 const net::CompletionCallback& callback,
144 GURL* new_url) override;
145 int OnBeforeSendHeaders(net::URLRequest* request,
146 const net::CompletionCallback& callback,
147 net::HttpRequestHeaders* headers) override;
148 void OnSendHeaders(net::URLRequest* request,
149 const net::HttpRequestHeaders& headers) override;
150 int OnHeadersReceived(
151 net::URLRequest* request,
152 const net::CompletionCallback& callback,
153 const net::HttpResponseHeaders* original_response_headers,
154 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
155 GURL* allowed_unsafe_redirect_url) override;
156 void OnBeforeRedirect(net::URLRequest* request,
157 const GURL& new_location) override;
158 void OnResponseStarted(net::URLRequest* request) override;
159 void OnRawBytesRead(const net::URLRequest& request, int bytes_read) override;
160 void OnCompleted(net::URLRequest* request, bool started) override;
161 void OnURLRequestDestroyed(net::URLRequest* request) override;
162 void OnPACScriptError(int line_number, const base::string16& error) override;
163 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired(
164 net::URLRequest* request,
165 const net::AuthChallengeInfo& auth_info,
166 const AuthCallback& callback,
167 net::AuthCredentials* credentials) override;
168 bool OnCanGetCookies(const net::URLRequest& request,
169 const net::CookieList& cookie_list) override;
170 bool OnCanSetCookie(const net::URLRequest& request,
171 const std::string& cookie_line,
172 net::CookieOptions* options) override;
173 bool OnCanAccessFile(const net::URLRequest& request,
174 const base::FilePath& path) const override;
175 bool OnCanThrottleRequest(const net::URLRequest& request) const override;
176 bool OnCanEnablePrivacyMode(
177 const GURL& url,
178 const GURL& first_party_for_cookies) const override;
179 bool OnFirstPartyOnlyCookieExperimentEnabled() const override;
180 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
181 const net::URLRequest& request,
182 const GURL& target_url,
183 const GURL& referrer_url) const override;
185 void AccumulateContentLength(
186 int64 received_payload_byte_count,
187 int64 original_payload_byte_count);
189 scoped_ptr<ChromeExtensionsNetworkDelegate> extensions_delegate_;
191 void* profile_;
192 base::FilePath profile_path_;
193 scoped_refptr<CookieSettings> cookie_settings_;
195 scoped_ptr<chrome_browser_net::ConnectInterceptor> connect_interceptor_;
197 // Weak, owned by our owner.
198 BooleanPrefMember* enable_referrers_;
199 BooleanPrefMember* enable_do_not_track_;
200 BooleanPrefMember* force_safe_search_;
201 BooleanPrefMember* force_google_safe_search_;
202 BooleanPrefMember* force_youtube_safety_mode_;
204 // Weak, owned by our owner.
205 #if defined(ENABLE_CONFIGURATION_POLICY)
206 const policy::URLBlacklistManager* url_blacklist_manager_;
207 #endif
208 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_;
210 // When true, allow access to all file:// URLs.
211 static bool g_allow_file_access_;
213 // True if OnCanThrottleRequest should always return false.
215 // Note: This needs to be static as the instance of
216 // ChromeNetworkDelegate used may change over time, and we need to
217 // set this variable once at start-up time. It is effectively
218 // static anyway since it is based on a command-line flag.
219 static bool g_never_throttle_requests_;
221 bool experimental_web_platform_features_enabled_;
223 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate);
226 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_