Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / net / chrome_network_delegate.h
blob9a24194a775e98325d28fb6ac392efcd68b52a28
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_google_safe_search(
100 BooleanPrefMember* force_google_safe_search) {
101 force_google_safe_search_ = force_google_safe_search;
104 void set_force_youtube_safety_mode(
105 BooleanPrefMember* force_youtube_safety_mode) {
106 force_youtube_safety_mode_ = force_youtube_safety_mode;
109 void set_domain_reliability_monitor(
110 domain_reliability::DomainReliabilityMonitor* monitor) {
111 domain_reliability_monitor_ = monitor;
114 // Binds the pref members to |pref_service| and moves them to the IO thread.
115 // |enable_referrers| cannot be NULL, the others can.
116 // This method should be called on the UI thread.
117 static void InitializePrefsOnUIThread(
118 BooleanPrefMember* enable_referrers,
119 BooleanPrefMember* enable_do_not_track,
120 BooleanPrefMember* force_google_safe_search,
121 BooleanPrefMember* force_youtube_safety_mode,
122 PrefService* pref_service);
124 // When called, all file:// URLs will now be accessible. If this is not
125 // called, then some platforms restrict access to file:// paths.
126 static void AllowAccessToAllFiles();
128 private:
129 // NetworkDelegate implementation.
130 int OnBeforeURLRequest(net::URLRequest* request,
131 const net::CompletionCallback& callback,
132 GURL* new_url) override;
133 int OnBeforeSendHeaders(net::URLRequest* request,
134 const net::CompletionCallback& callback,
135 net::HttpRequestHeaders* headers) override;
136 void OnSendHeaders(net::URLRequest* request,
137 const net::HttpRequestHeaders& headers) override;
138 int OnHeadersReceived(
139 net::URLRequest* request,
140 const net::CompletionCallback& callback,
141 const net::HttpResponseHeaders* original_response_headers,
142 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
143 GURL* allowed_unsafe_redirect_url) override;
144 void OnBeforeRedirect(net::URLRequest* request,
145 const GURL& new_location) override;
146 void OnResponseStarted(net::URLRequest* request) override;
147 void OnRawBytesRead(const net::URLRequest& request, int bytes_read) override;
148 void OnCompleted(net::URLRequest* request, bool started) override;
149 void OnURLRequestDestroyed(net::URLRequest* request) override;
150 void OnPACScriptError(int line_number, const base::string16& error) override;
151 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired(
152 net::URLRequest* request,
153 const net::AuthChallengeInfo& auth_info,
154 const AuthCallback& callback,
155 net::AuthCredentials* credentials) override;
156 bool OnCanGetCookies(const net::URLRequest& request,
157 const net::CookieList& cookie_list) override;
158 bool OnCanSetCookie(const net::URLRequest& request,
159 const std::string& cookie_line,
160 net::CookieOptions* options) override;
161 bool OnCanAccessFile(const net::URLRequest& request,
162 const base::FilePath& path) const override;
163 bool OnCanEnablePrivacyMode(
164 const GURL& url,
165 const GURL& first_party_for_cookies) const override;
166 bool OnFirstPartyOnlyCookieExperimentEnabled() const override;
167 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
168 const net::URLRequest& request,
169 const GURL& target_url,
170 const GURL& referrer_url) const override;
172 void AccumulateContentLength(
173 int64 received_payload_byte_count,
174 int64 original_payload_byte_count);
176 scoped_ptr<ChromeExtensionsNetworkDelegate> extensions_delegate_;
178 void* profile_;
179 base::FilePath profile_path_;
180 scoped_refptr<CookieSettings> cookie_settings_;
182 scoped_ptr<chrome_browser_net::ConnectInterceptor> connect_interceptor_;
184 // Weak, owned by our owner.
185 BooleanPrefMember* enable_referrers_;
186 BooleanPrefMember* enable_do_not_track_;
187 BooleanPrefMember* force_google_safe_search_;
188 BooleanPrefMember* force_youtube_safety_mode_;
190 // Weak, owned by our owner.
191 #if defined(ENABLE_CONFIGURATION_POLICY)
192 const policy::URLBlacklistManager* url_blacklist_manager_;
193 #endif
194 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_;
196 // When true, allow access to all file:// URLs.
197 static bool g_allow_file_access_;
199 bool experimental_web_platform_features_enabled_;
201 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate);
204 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_