Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / net / chrome_network_delegate.h
blob3717a33737ec86115b73275e4a02f14835812db7
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 <stdint.h>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/values.h"
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h"
19 #include "net/base/network_delegate_impl.h"
21 #if !defined(OS_IOS)
22 #include "components/data_use_measurement/content/data_use_measurement.h"
23 #endif
25 class ChromeExtensionsNetworkDelegate;
26 class PrefService;
28 template<class T> class PrefMember;
30 typedef PrefMember<bool> BooleanPrefMember;
32 namespace base {
33 class Value;
36 namespace chrome_browser_net {
37 class ConnectInterceptor;
38 class Predictor;
41 namespace content_settings {
42 class CookieSettings;
45 namespace domain_reliability {
46 class DomainReliabilityMonitor;
49 namespace extensions {
50 class EventRouterForwarder;
51 class InfoMap;
54 namespace net {
55 class URLRequest;
58 namespace policy {
59 class URLBlacklistManager;
62 // ChromeNetworkDelegate is the central point from within the chrome code to
63 // add hooks into the network stack.
64 class ChromeNetworkDelegate : public net::NetworkDelegateImpl {
65 public:
66 // |enable_referrers| (and all of the other optional PrefMembers) should be
67 // initialized on the UI thread (see below) beforehand. This object's owner is
68 // responsible for cleaning them up at shutdown.
69 ChromeNetworkDelegate(extensions::EventRouterForwarder* event_router,
70 BooleanPrefMember* enable_referrers);
71 ~ChromeNetworkDelegate() override;
73 // Pass through to ChromeExtensionsNetworkDelegate::set_extension_info_map().
74 void set_extension_info_map(extensions::InfoMap* extension_info_map);
76 #if defined(ENABLE_CONFIGURATION_POLICY)
77 void set_url_blacklist_manager(
78 const policy::URLBlacklistManager* url_blacklist_manager) {
79 url_blacklist_manager_ = url_blacklist_manager;
81 #endif
83 // If |profile| is NULL or not set, events will be broadcast to all profiles,
84 // otherwise they will only be sent to the specified profile.
85 // Also pass through to ChromeExtensionsNetworkDelegate::set_profile().
86 void set_profile(void* profile);
88 // |profile_path| is used to locate the "Downloads" folder on Chrome OS. If it
89 // is set, the location of the Downloads folder for the profile is added to
90 // the whitelist for accesses via file: scheme.
91 void set_profile_path(const base::FilePath& profile_path) {
92 profile_path_ = profile_path;
95 // If |cookie_settings| is NULL or not set, all cookies are enabled,
96 // otherwise the settings are enforced on all observed network requests.
97 // Not inlined because we assign a scoped_refptr, which requires us to include
98 // the header file. Here we just forward-declare it.
99 void set_cookie_settings(content_settings::CookieSettings* cookie_settings);
101 // Causes requested URLs to be fed to |predictor| via ConnectInterceptor.
102 void set_predictor(chrome_browser_net::Predictor* predictor);
104 void set_enable_do_not_track(BooleanPrefMember* enable_do_not_track) {
105 enable_do_not_track_ = enable_do_not_track;
108 void set_force_google_safe_search(
109 BooleanPrefMember* force_google_safe_search) {
110 force_google_safe_search_ = force_google_safe_search;
113 void set_force_youtube_safety_mode(
114 BooleanPrefMember* force_youtube_safety_mode) {
115 force_youtube_safety_mode_ = force_youtube_safety_mode;
118 void set_domain_reliability_monitor(
119 domain_reliability::DomainReliabilityMonitor* monitor) {
120 domain_reliability_monitor_ = monitor;
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_google_safe_search,
130 BooleanPrefMember* force_youtube_safety_mode,
131 PrefService* pref_service);
133 // When called, all file:// URLs will now be accessible. If this is not
134 // called, then some platforms restrict access to file:// paths.
135 static void AllowAccessToAllFiles();
137 private:
138 // NetworkDelegate implementation.
139 int OnBeforeURLRequest(net::URLRequest* request,
140 const net::CompletionCallback& callback,
141 GURL* new_url) override;
142 int OnBeforeSendHeaders(net::URLRequest* request,
143 const net::CompletionCallback& callback,
144 net::HttpRequestHeaders* headers) override;
145 void OnSendHeaders(net::URLRequest* request,
146 const net::HttpRequestHeaders& headers) override;
147 int OnHeadersReceived(
148 net::URLRequest* request,
149 const net::CompletionCallback& callback,
150 const net::HttpResponseHeaders* original_response_headers,
151 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
152 GURL* allowed_unsafe_redirect_url) override;
153 void OnBeforeRedirect(net::URLRequest* request,
154 const GURL& new_location) override;
155 void OnResponseStarted(net::URLRequest* request) override;
156 void OnNetworkBytesReceived(const net::URLRequest& request,
157 int64_t bytes_received) override;
158 void OnCompleted(net::URLRequest* request, bool started) override;
159 void OnURLRequestDestroyed(net::URLRequest* request) override;
160 void OnURLRequestJobOrphaned(net::URLRequest* request) override;
161 void OnPACScriptError(int line_number, const base::string16& error) override;
162 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired(
163 net::URLRequest* request,
164 const net::AuthChallengeInfo& auth_info,
165 const AuthCallback& callback,
166 net::AuthCredentials* credentials) override;
167 bool OnCanGetCookies(const net::URLRequest& request,
168 const net::CookieList& cookie_list) override;
169 bool OnCanSetCookie(const net::URLRequest& request,
170 const std::string& cookie_line,
171 net::CookieOptions* options) override;
172 bool OnCanAccessFile(const net::URLRequest& request,
173 const base::FilePath& path) const override;
174 bool OnCanEnablePrivacyMode(
175 const GURL& url,
176 const GURL& first_party_for_cookies) const override;
177 bool OnFirstPartyOnlyCookieExperimentEnabled() const override;
178 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
179 const net::URLRequest& request,
180 const GURL& target_url,
181 const GURL& referrer_url) const override;
183 void AccumulateContentLength(
184 int64 received_payload_byte_count,
185 int64 original_payload_byte_count);
187 scoped_ptr<ChromeExtensionsNetworkDelegate> extensions_delegate_;
189 void* profile_;
190 base::FilePath profile_path_;
191 scoped_refptr<content_settings::CookieSettings> cookie_settings_;
193 scoped_ptr<chrome_browser_net::ConnectInterceptor> connect_interceptor_;
195 // Weak, owned by our owner.
196 BooleanPrefMember* enable_referrers_;
197 BooleanPrefMember* enable_do_not_track_;
198 BooleanPrefMember* force_google_safe_search_;
199 BooleanPrefMember* force_youtube_safety_mode_;
201 // Weak, owned by our owner.
202 #if defined(ENABLE_CONFIGURATION_POLICY)
203 const policy::URLBlacklistManager* url_blacklist_manager_;
204 #endif
205 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_;
207 // When true, allow access to all file:// URLs.
208 static bool g_allow_file_access_;
210 // Component to measure data use.
211 #if !defined(OS_IOS)
212 data_use_measurement::DataUseMeasurement data_use_measurement_;
213 #endif
215 bool experimental_web_platform_features_enabled_;
217 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate);
220 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_