[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / net / chrome_network_delegate.h
blob10ff0dad29eb66d9d86f1b4209dfd2a58b83a261
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 PrefService;
22 template<class T> class PrefMember;
24 typedef PrefMember<bool> BooleanPrefMember;
26 namespace base {
27 class Value;
30 namespace chrome_browser_net {
31 class ConnectInterceptor;
32 class Predictor;
35 namespace content_settings {
36 class CookieSettings;
39 namespace domain_reliability {
40 class DomainReliabilityMonitor;
43 namespace extensions {
44 class EventRouterForwarder;
45 class InfoMap;
48 namespace net {
49 class URLRequest;
52 namespace policy {
53 class URLBlacklistManager;
56 // ChromeNetworkDelegate is the central point from within the chrome code to
57 // add hooks into the network stack.
58 class ChromeNetworkDelegate : public net::NetworkDelegateImpl {
59 public:
60 // |enable_referrers| (and all of the other optional PrefMembers) should be
61 // initialized on the UI thread (see below) beforehand. This object's owner is
62 // responsible for cleaning them up at shutdown.
63 ChromeNetworkDelegate(extensions::EventRouterForwarder* event_router,
64 BooleanPrefMember* enable_referrers);
65 ~ChromeNetworkDelegate() override;
67 // Pass through to ChromeExtensionsNetworkDelegate::set_extension_info_map().
68 void set_extension_info_map(extensions::InfoMap* extension_info_map);
70 #if defined(ENABLE_CONFIGURATION_POLICY)
71 void set_url_blacklist_manager(
72 const policy::URLBlacklistManager* url_blacklist_manager) {
73 url_blacklist_manager_ = url_blacklist_manager;
75 #endif
77 // If |profile| is NULL or not set, events will be broadcast to all profiles,
78 // otherwise they will only be sent to the specified profile.
79 // Also pass through to ChromeExtensionsNetworkDelegate::set_profile().
80 void set_profile(void* profile);
82 // |profile_path| is used to locate the "Downloads" folder on Chrome OS. If it
83 // is set, the location of the Downloads folder for the profile is added to
84 // the whitelist for accesses via file: scheme.
85 void set_profile_path(const base::FilePath& profile_path) {
86 profile_path_ = profile_path;
89 // If |cookie_settings| is NULL or not set, all cookies are enabled,
90 // otherwise the settings are enforced on all observed network requests.
91 // Not inlined because we assign a scoped_refptr, which requires us to include
92 // the header file. Here we just forward-declare it.
93 void set_cookie_settings(content_settings::CookieSettings* cookie_settings);
95 // Causes requested URLs to be fed to |predictor| via ConnectInterceptor.
96 void set_predictor(chrome_browser_net::Predictor* predictor);
98 void set_enable_do_not_track(BooleanPrefMember* enable_do_not_track) {
99 enable_do_not_track_ = enable_do_not_track;
102 void set_force_google_safe_search(
103 BooleanPrefMember* force_google_safe_search) {
104 force_google_safe_search_ = force_google_safe_search;
107 void set_force_youtube_safety_mode(
108 BooleanPrefMember* force_youtube_safety_mode) {
109 force_youtube_safety_mode_ = force_youtube_safety_mode;
112 void set_domain_reliability_monitor(
113 domain_reliability::DomainReliabilityMonitor* monitor) {
114 domain_reliability_monitor_ = monitor;
117 // Binds the pref members to |pref_service| and moves them to the IO thread.
118 // |enable_referrers| cannot be NULL, the others can.
119 // This method should be called on the UI thread.
120 static void InitializePrefsOnUIThread(
121 BooleanPrefMember* enable_referrers,
122 BooleanPrefMember* enable_do_not_track,
123 BooleanPrefMember* force_google_safe_search,
124 BooleanPrefMember* force_youtube_safety_mode,
125 PrefService* pref_service);
127 // When called, all file:// URLs will now be accessible. If this is not
128 // called, then some platforms restrict access to file:// paths.
129 static void AllowAccessToAllFiles();
131 private:
132 // NetworkDelegate implementation.
133 int OnBeforeURLRequest(net::URLRequest* request,
134 const net::CompletionCallback& callback,
135 GURL* new_url) override;
136 int OnBeforeSendHeaders(net::URLRequest* request,
137 const net::CompletionCallback& callback,
138 net::HttpRequestHeaders* headers) override;
139 void OnSendHeaders(net::URLRequest* request,
140 const net::HttpRequestHeaders& headers) override;
141 int OnHeadersReceived(
142 net::URLRequest* request,
143 const net::CompletionCallback& callback,
144 const net::HttpResponseHeaders* original_response_headers,
145 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
146 GURL* allowed_unsafe_redirect_url) override;
147 void OnBeforeRedirect(net::URLRequest* request,
148 const GURL& new_location) override;
149 void OnResponseStarted(net::URLRequest* request) override;
150 void OnRawBytesRead(const net::URLRequest& request, int bytes_read) override;
151 void OnCompleted(net::URLRequest* request, bool started) override;
152 void OnURLRequestDestroyed(net::URLRequest* request) override;
153 void OnPACScriptError(int line_number, const base::string16& error) override;
154 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired(
155 net::URLRequest* request,
156 const net::AuthChallengeInfo& auth_info,
157 const AuthCallback& callback,
158 net::AuthCredentials* credentials) override;
159 bool OnCanGetCookies(const net::URLRequest& request,
160 const net::CookieList& cookie_list) override;
161 bool OnCanSetCookie(const net::URLRequest& request,
162 const std::string& cookie_line,
163 net::CookieOptions* options) override;
164 bool OnCanAccessFile(const net::URLRequest& request,
165 const base::FilePath& path) const override;
166 bool OnCanEnablePrivacyMode(
167 const GURL& url,
168 const GURL& first_party_for_cookies) const override;
169 bool OnFirstPartyOnlyCookieExperimentEnabled() const override;
170 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
171 const net::URLRequest& request,
172 const GURL& target_url,
173 const GURL& referrer_url) const override;
175 void AccumulateContentLength(
176 int64 received_payload_byte_count,
177 int64 original_payload_byte_count);
179 scoped_ptr<ChromeExtensionsNetworkDelegate> extensions_delegate_;
181 void* profile_;
182 base::FilePath profile_path_;
183 scoped_refptr<content_settings::CookieSettings> cookie_settings_;
185 scoped_ptr<chrome_browser_net::ConnectInterceptor> connect_interceptor_;
187 // Weak, owned by our owner.
188 BooleanPrefMember* enable_referrers_;
189 BooleanPrefMember* enable_do_not_track_;
190 BooleanPrefMember* force_google_safe_search_;
191 BooleanPrefMember* force_youtube_safety_mode_;
193 // Weak, owned by our owner.
194 #if defined(ENABLE_CONFIGURATION_POLICY)
195 const policy::URLBlacklistManager* url_blacklist_manager_;
196 #endif
197 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_;
199 // When true, allow access to all file:// URLs.
200 static bool g_allow_file_access_;
202 bool experimental_web_platform_features_enabled_;
204 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate);
207 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_