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_
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 class ChromeExtensionsNetworkDelegate
;
24 template<class T
> class PrefMember
;
26 typedef PrefMember
<bool> BooleanPrefMember
;
32 namespace chrome_browser_net
{
33 class ConnectInterceptor
;
37 namespace content_settings
{
41 namespace domain_reliability
{
42 class DomainReliabilityMonitor
;
45 namespace extensions
{
46 class EventRouterForwarder
;
55 class URLBlacklistManager
;
58 // ChromeNetworkDelegate is the central point from within the chrome code to
59 // add hooks into the network stack.
60 class ChromeNetworkDelegate
: public net::NetworkDelegateImpl
{
62 // |enable_referrers| (and all of the other optional PrefMembers) should be
63 // initialized on the UI thread (see below) beforehand. This object's owner is
64 // responsible for cleaning them up at shutdown.
65 ChromeNetworkDelegate(extensions::EventRouterForwarder
* event_router
,
66 BooleanPrefMember
* enable_referrers
);
67 ~ChromeNetworkDelegate() override
;
69 // Pass through to ChromeExtensionsNetworkDelegate::set_extension_info_map().
70 void set_extension_info_map(extensions::InfoMap
* extension_info_map
);
72 #if defined(ENABLE_CONFIGURATION_POLICY)
73 void set_url_blacklist_manager(
74 const policy::URLBlacklistManager
* url_blacklist_manager
) {
75 url_blacklist_manager_
= url_blacklist_manager
;
79 // If |profile| is NULL or not set, events will be broadcast to all profiles,
80 // otherwise they will only be sent to the specified profile.
81 // Also pass through to ChromeExtensionsNetworkDelegate::set_profile().
82 void set_profile(void* profile
);
84 // |profile_path| is used to locate the "Downloads" folder on Chrome OS. If it
85 // is set, the location of the Downloads folder for the profile is added to
86 // the whitelist for accesses via file: scheme.
87 void set_profile_path(const base::FilePath
& profile_path
) {
88 profile_path_
= profile_path
;
91 // If |cookie_settings| is NULL or not set, all cookies are enabled,
92 // otherwise the settings are enforced on all observed network requests.
93 // Not inlined because we assign a scoped_refptr, which requires us to include
94 // the header file. Here we just forward-declare it.
95 void set_cookie_settings(content_settings::CookieSettings
* cookie_settings
);
97 // Causes requested URLs to be fed to |predictor| via ConnectInterceptor.
98 void set_predictor(chrome_browser_net::Predictor
* predictor
);
100 void set_enable_do_not_track(BooleanPrefMember
* enable_do_not_track
) {
101 enable_do_not_track_
= enable_do_not_track
;
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 // Binds the pref members to |pref_service| and moves them to the IO thread.
120 // |enable_referrers| cannot be NULL, the others can.
121 // This method should be called on the UI thread.
122 static void InitializePrefsOnUIThread(
123 BooleanPrefMember
* enable_referrers
,
124 BooleanPrefMember
* enable_do_not_track
,
125 BooleanPrefMember
* force_google_safe_search
,
126 BooleanPrefMember
* force_youtube_safety_mode
,
127 PrefService
* pref_service
);
129 // When called, all file:// URLs will now be accessible. If this is not
130 // called, then some platforms restrict access to file:// paths.
131 static void AllowAccessToAllFiles();
134 // NetworkDelegate implementation.
135 int OnBeforeURLRequest(net::URLRequest
* request
,
136 const net::CompletionCallback
& callback
,
137 GURL
* new_url
) override
;
138 int OnBeforeSendHeaders(net::URLRequest
* request
,
139 const net::CompletionCallback
& callback
,
140 net::HttpRequestHeaders
* headers
) override
;
141 void OnSendHeaders(net::URLRequest
* request
,
142 const net::HttpRequestHeaders
& headers
) override
;
143 int OnHeadersReceived(
144 net::URLRequest
* request
,
145 const net::CompletionCallback
& callback
,
146 const net::HttpResponseHeaders
* original_response_headers
,
147 scoped_refptr
<net::HttpResponseHeaders
>* override_response_headers
,
148 GURL
* allowed_unsafe_redirect_url
) override
;
149 void OnBeforeRedirect(net::URLRequest
* request
,
150 const GURL
& new_location
) override
;
151 void OnResponseStarted(net::URLRequest
* request
) override
;
152 void OnNetworkBytesReceived(const net::URLRequest
& request
,
153 int64_t bytes_received
) override
;
154 void OnCompleted(net::URLRequest
* request
, bool started
) override
;
155 void OnURLRequestDestroyed(net::URLRequest
* request
) override
;
156 void OnPACScriptError(int line_number
, const base::string16
& error
) override
;
157 net::NetworkDelegate::AuthRequiredResponse
OnAuthRequired(
158 net::URLRequest
* request
,
159 const net::AuthChallengeInfo
& auth_info
,
160 const AuthCallback
& callback
,
161 net::AuthCredentials
* credentials
) override
;
162 bool OnCanGetCookies(const net::URLRequest
& request
,
163 const net::CookieList
& cookie_list
) override
;
164 bool OnCanSetCookie(const net::URLRequest
& request
,
165 const std::string
& cookie_line
,
166 net::CookieOptions
* options
) override
;
167 bool OnCanAccessFile(const net::URLRequest
& request
,
168 const base::FilePath
& path
) const override
;
169 bool OnCanEnablePrivacyMode(
171 const GURL
& first_party_for_cookies
) const override
;
172 bool OnFirstPartyOnlyCookieExperimentEnabled() const override
;
173 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
174 const net::URLRequest
& request
,
175 const GURL
& target_url
,
176 const GURL
& referrer_url
) const override
;
178 void AccumulateContentLength(
179 int64 received_payload_byte_count
,
180 int64 original_payload_byte_count
);
182 scoped_ptr
<ChromeExtensionsNetworkDelegate
> extensions_delegate_
;
185 base::FilePath profile_path_
;
186 scoped_refptr
<content_settings::CookieSettings
> cookie_settings_
;
188 scoped_ptr
<chrome_browser_net::ConnectInterceptor
> connect_interceptor_
;
190 // Weak, owned by our owner.
191 BooleanPrefMember
* enable_referrers_
;
192 BooleanPrefMember
* enable_do_not_track_
;
193 BooleanPrefMember
* force_google_safe_search_
;
194 BooleanPrefMember
* force_youtube_safety_mode_
;
196 // Weak, owned by our owner.
197 #if defined(ENABLE_CONFIGURATION_POLICY)
198 const policy::URLBlacklistManager
* url_blacklist_manager_
;
200 domain_reliability::DomainReliabilityMonitor
* domain_reliability_monitor_
;
202 // When true, allow access to all file:// URLs.
203 static bool g_allow_file_access_
;
205 bool experimental_web_platform_features_enabled_
;
207 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate
);
210 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_