blob: 9404e25244a1d7044351b1ae4dcf91be8415849b [file] [log] [blame]
[email protected]9045b8822012-01-13 20:35:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ac039522010-06-15 16:39:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/net/chrome_network_delegate.h"
6
7#include "base/logging.h"
[email protected]d8e4f132012-09-06 04:28:058#include "base/base_paths.h"
9#include "base/path_service.h"
[email protected]c5aa8262012-08-21 11:19:5410#include "chrome/browser/api/prefs/pref_member.h"
[email protected]6baff0b52012-03-06 01:30:1811#include "chrome/browser/browser_process.h"
[email protected]9c8ae8c2012-03-09 13:13:3512#include "chrome/browser/content_settings/cookie_settings.h"
13#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]8523ba52011-05-22 19:00:5814#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]aa84a7e2012-03-15 21:29:0615#include "chrome/browser/extensions/api/proxy/proxy_api.h"
[email protected]2b33dcd02012-03-18 01:34:1616#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]5a38dfd2012-07-23 23:22:1017#include "chrome/browser/extensions/event_router_forwarder.h"
[email protected]c357acb42011-06-09 20:52:4218#include "chrome/browser/extensions/extension_info_map.h"
[email protected]6baff0b52012-03-06 01:30:1819#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]a9e0d1412012-08-20 22:13:0120#include "chrome/browser/net/load_time_stats.h"
[email protected]6f4b4b42012-08-27 21:59:0721#include "chrome/browser/performance_monitor/performance_monitor.h"
[email protected]fb8fdf12012-08-21 16:28:2022#include "chrome/browser/prefs/pref_service.h"
[email protected]6baff0b52012-03-06 01:30:1823#include "chrome/browser/profiles/profile_manager.h"
[email protected]8523ba52011-05-22 19:00:5824#include "chrome/browser/task_manager/task_manager.h"
[email protected]0a8db0d2011-04-13 15:15:4025#include "chrome/common/pref_names.h"
[email protected]a1d4ab072012-06-07 13:21:1526#include "chrome/common/url_constants.h"
[email protected]c38831a12011-10-28 12:44:4927#include "content/public/browser/browser_thread.h"
[email protected]9c1662b2012-03-06 15:44:3328#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3529#include "content/public/browser/resource_request_info.h"
[email protected]82b42302011-04-20 16:28:1630#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1431#include "net/base/net_errors.h"
[email protected]6a5f77c32011-09-04 19:19:5932#include "net/base/net_log.h"
[email protected]5b9bc352012-07-18 13:13:3433#include "net/cookies/canonical_cookie.h"
34#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4435#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1636#include "net/http/http_response_headers.h"
[email protected]aa28181e2012-06-13 00:53:5837#include "net/socket_stream/socket_stream.h"
[email protected]d05ef99c2011-02-01 21:38:1638#include "net/url_request/url_request.h"
39
[email protected]e9c41d22012-08-17 00:08:1540#if !defined(OS_ANDROID)
41#include "chrome/browser/managed_mode_url_filter.h"
42#endif
43
[email protected]4c219e22012-05-05 19:41:0444#if defined(OS_CHROMEOS)
45#include "base/chromeos/chromeos_version.h"
46#endif
47
[email protected]3e598ff12011-09-06 11:22:3448#if defined(ENABLE_CONFIGURATION_POLICY)
49#include "chrome/browser/policy/url_blacklist_manager.h"
50#endif
51
[email protected]631bb742011-11-02 11:29:3952using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1153using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2554using content::ResourceRequestInfo;
[email protected]631bb742011-11-02 11:29:3955
[email protected]d8e4f132012-09-06 04:28:0556// By default we don't allow access to all file:// urls on ChromeOS and
57// Android.
58#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:0459bool ChromeNetworkDelegate::g_allow_file_access_ = false;
60#else
61bool ChromeNetworkDelegate::g_allow_file_access_ = true;
62#endif
63
[email protected]c4a7df82012-08-09 22:48:4664// This remains false unless the --disable-extensions-http-throttling
65// flag is passed to the browser.
66bool ChromeNetworkDelegate::g_never_throttle_requests_ = false;
67
[email protected]d05ef99c2011-02-01 21:38:1668namespace {
69
[email protected]8202d0c2011-02-23 08:31:1470// If the |request| failed due to problems with a proxy, forward the error to
71// the proxy extension API.
[email protected]0651b812011-02-24 00:22:5072void ForwardProxyErrors(net::URLRequest* request,
[email protected]5a38dfd2012-07-23 23:22:1073 extensions::EventRouterForwarder* event_router,
[email protected]673514522011-07-13 18:17:1874 void* profile) {
[email protected]8202d0c2011-02-23 08:31:1475 if (request->status().status() == net::URLRequestStatus::FAILED) {
[email protected]d0cc35b2011-09-08 12:02:0576 switch (request->status().error()) {
[email protected]8202d0c2011-02-23 08:31:1477 case net::ERR_PROXY_AUTH_UNSUPPORTED:
78 case net::ERR_PROXY_CONNECTION_FAILED:
79 case net::ERR_TUNNEL_CONNECTION_FAILED:
[email protected]c454fe672012-03-12 21:18:0180 extensions::ProxyEventRouter::GetInstance()->OnProxyError(
[email protected]d0cc35b2011-09-08 12:02:0581 event_router, profile, request->status().error());
[email protected]8202d0c2011-02-23 08:31:1482 }
83 }
84}
85
[email protected]6baff0b52012-03-06 01:30:1886enum RequestStatus { REQUEST_STARTED, REQUEST_DONE };
87
88// Notifies the ExtensionProcessManager that a request has started or stopped
89// for a particular RenderView.
90void NotifyEPMRequestStatus(RequestStatus status,
91 void* profile_id,
92 int process_id,
93 int render_view_id) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
95 Profile* profile = reinterpret_cast<Profile*>(profile_id);
96 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
97 return;
98
[email protected]e5775a52012-03-17 04:59:5799 ExtensionProcessManager* extension_process_manager =
100 profile->GetExtensionProcessManager();
101 // This may be NULL in unit tests.
102 if (!extension_process_manager)
103 return;
104
[email protected]6baff0b52012-03-06 01:30:18105 // Will be NULL if the request was not issued on behalf of a renderer (e.g. a
106 // system-level request).
[email protected]d3e898e2012-03-14 03:45:08107 RenderViewHost* render_view_host =
108 RenderViewHost::FromID(process_id, render_view_id);
[email protected]e5775a52012-03-17 04:59:57109 if (render_view_host) {
[email protected]6baff0b52012-03-06 01:30:18110 if (status == REQUEST_STARTED) {
[email protected]d3e898e2012-03-14 03:45:08111 extension_process_manager->OnNetworkRequestStarted(render_view_host);
[email protected]6baff0b52012-03-06 01:30:18112 } else if (status == REQUEST_DONE) {
[email protected]d3e898e2012-03-14 03:45:08113 extension_process_manager->OnNetworkRequestDone(render_view_host);
[email protected]6baff0b52012-03-06 01:30:18114 } else {
115 NOTREACHED();
116 }
117 }
118}
119
120void ForwardRequestStatus(
121 RequestStatus status, net::URLRequest* request, void* profile_id) {
[email protected]ea114722012-03-12 01:11:25122 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
123 if (!info)
124 return;
125
[email protected]6baff0b52012-03-06 01:30:18126 int process_id, render_view_id;
[email protected]ea114722012-03-12 01:11:25127 if (info->GetAssociatedRenderView(&process_id, &render_view_id)) {
[email protected]6baff0b52012-03-06 01:30:18128 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
129 base::Bind(&NotifyEPMRequestStatus,
130 status, profile_id, process_id, render_view_id));
131 }
132}
133
[email protected]d05ef99c2011-02-01 21:38:16134} // namespace
[email protected]ac039522010-06-15 16:39:44135
[email protected]0651b812011-02-24 00:22:50136ChromeNetworkDelegate::ChromeNetworkDelegate(
[email protected]5a38dfd2012-07-23 23:22:10137 extensions::EventRouterForwarder* event_router,
[email protected]c357acb42011-06-09 20:52:42138 ExtensionInfoMap* extension_info_map,
[email protected]6a5f77c32011-09-04 19:19:59139 const policy::URLBlacklistManager* url_blacklist_manager,
[email protected]e9c41d22012-08-17 00:08:15140 const ManagedModeURLFilter* managed_mode_url_filter,
[email protected]673514522011-07-13 18:17:18141 void* profile,
[email protected]9c8ae8c2012-03-09 13:13:35142 CookieSettings* cookie_settings,
[email protected]5a07c192012-07-30 20:18:22143 BooleanPrefMember* enable_referrers,
[email protected]a9e0d1412012-08-20 22:13:01144 chrome_browser_net::LoadTimeStats* load_time_stats)
[email protected]3ce02412011-03-01 12:01:15145 : event_router_(event_router),
[email protected]673514522011-07-13 18:17:18146 profile_(profile),
[email protected]9c8ae8c2012-03-09 13:13:35147 cookie_settings_(cookie_settings),
[email protected]c357acb42011-06-09 20:52:42148 extension_info_map_(extension_info_map),
[email protected]6a5f77c32011-09-04 19:19:59149 enable_referrers_(enable_referrers),
[email protected]5a07c192012-07-30 20:18:22150 url_blacklist_manager_(url_blacklist_manager),
[email protected]e9c41d22012-08-17 00:08:15151 managed_mode_url_filter_(managed_mode_url_filter),
[email protected]a9e0d1412012-08-20 22:13:01152 load_time_stats_(load_time_stats) {
[email protected]4b50cb52011-03-10 00:29:37153 DCHECK(event_router);
[email protected]0a8db0d2011-04-13 15:15:40154 DCHECK(enable_referrers);
[email protected]9c8ae8c2012-03-09 13:13:35155 DCHECK(!profile || cookie_settings);
[email protected]0651b812011-02-24 00:22:50156}
157
[email protected]ac039522010-06-15 16:39:44158ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
159
[email protected]c4a7df82012-08-09 22:48:46160// static
[email protected]a1d4ab072012-06-07 13:21:15161void ChromeNetworkDelegate::NeverThrottleRequests() {
[email protected]c4a7df82012-08-09 22:48:46162 g_never_throttle_requests_ = true;
[email protected]a1d4ab072012-06-07 13:21:15163}
164
[email protected]0a8db0d2011-04-13 15:15:40165// static
166void ChromeNetworkDelegate::InitializeReferrersEnabled(
167 BooleanPrefMember* enable_referrers,
168 PrefService* pref_service) {
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
170 enable_referrers->Init(prefs::kEnableReferrers, pref_service, NULL);
171 enable_referrers->MoveToThread(BrowserThread::IO);
172}
173
[email protected]4c219e22012-05-05 19:41:04174// static
175void ChromeNetworkDelegate::AllowAccessToAllFiles() {
176 g_allow_file_access_ = true;
177}
178
[email protected]4875ba12011-03-30 22:31:51179int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12180 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47181 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12182 GURL* new_url) {
[email protected]3e598ff12011-09-06 11:22:34183#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]6a5f77c32011-09-04 19:19:59184 // TODO(joaodasilva): This prevents extensions from seeing URLs that are
185 // blocked. However, an extension might redirect the request to another URL,
186 // which is not blocked.
187 if (url_blacklist_manager_ &&
188 url_blacklist_manager_->IsURLBlocked(request->url())) {
189 // URL access blocked by policy.
[email protected]6a5f77c32011-09-04 19:19:59190 request->net_log().AddEvent(
[email protected]2fa08912012-06-14 20:56:26191 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
192 net::NetLog::StringCallback("url",
193 &request->url().possibly_invalid_spec()));
[email protected]6a5f77c32011-09-04 19:19:59194 return net::ERR_NETWORK_ACCESS_DENIED;
195 }
[email protected]3e598ff12011-09-06 11:22:34196#endif
[email protected]6a5f77c32011-09-04 19:19:59197
[email protected]e9c41d22012-08-17 00:08:15198#if !defined(OS_ANDROID)
199 if (managed_mode_url_filter_ &&
200 !managed_mode_url_filter_->IsURLWhitelisted(request->url())) {
201 // Block for now.
202 return net::ERR_NETWORK_ACCESS_DENIED;
203 }
204#endif
205
[email protected]6baff0b52012-03-06 01:30:18206 ForwardRequestStatus(REQUEST_STARTED, request, profile_);
207
[email protected]0a8db0d2011-04-13 15:15:40208 if (!enable_referrers_->GetValue())
209 request->set_referrer(std::string());
[email protected]05cc4e72011-03-08 21:29:48210 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRequest(
[email protected]673514522011-07-13 18:17:18211 profile_, extension_info_map_.get(), request, callback, new_url);
[email protected]d05ef99c2011-02-01 21:38:16212}
213
[email protected]4875ba12011-03-30 22:31:51214int ChromeNetworkDelegate::OnBeforeSendHeaders(
[email protected]636eccd2011-06-28 12:28:01215 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47216 const net::CompletionCallback& callback,
[email protected]4c76d7c2011-04-15 19:14:12217 net::HttpRequestHeaders* headers) {
[email protected]4875ba12011-03-30 22:31:51218 return ExtensionWebRequestEventRouter::GetInstance()->OnBeforeSendHeaders(
[email protected]673514522011-07-13 18:17:18219 profile_, extension_info_map_.get(), request, callback, headers);
[email protected]ac039522010-06-15 16:39:44220}
[email protected]8202d0c2011-02-23 08:31:14221
[email protected]5796dc942011-07-14 19:26:10222void ChromeNetworkDelegate::OnSendHeaders(
223 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15224 const net::HttpRequestHeaders& headers) {
[email protected]5796dc942011-07-14 19:26:10225 ExtensionWebRequestEventRouter::GetInstance()->OnSendHeaders(
226 profile_, extension_info_map_.get(), request, headers);
[email protected]82b42302011-04-20 16:28:16227}
228
[email protected]ea8141e2011-10-05 13:12:51229int ChromeNetworkDelegate::OnHeadersReceived(
230 net::URLRequest* request,
[email protected]084262c2011-12-01 21:12:47231 const net::CompletionCallback& callback,
[email protected]ea8141e2011-10-05 13:12:51232 net::HttpResponseHeaders* original_response_headers,
233 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) {
234 return ExtensionWebRequestEventRouter::GetInstance()->OnHeadersReceived(
235 profile_, extension_info_map_.get(), request, callback,
236 original_response_headers, override_response_headers);
237}
238
[email protected]31b2e5f2011-04-20 16:58:32239void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
240 const GURL& new_location) {
241 ExtensionWebRequestEventRouter::GetInstance()->OnBeforeRedirect(
[email protected]673514522011-07-13 18:17:18242 profile_, extension_info_map_.get(), request, new_location);
[email protected]31b2e5f2011-04-20 16:58:32243}
244
245
[email protected]8202d0c2011-02-23 08:31:14246void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
[email protected]62fecae2011-04-21 11:08:24247 ExtensionWebRequestEventRouter::GetInstance()->OnResponseStarted(
[email protected]673514522011-07-13 18:17:18248 profile_, extension_info_map_.get(), request);
249 ForwardProxyErrors(request, event_router_.get(), profile_);
[email protected]8202d0c2011-02-23 08:31:14250}
251
[email protected]8523ba52011-05-22 19:00:58252void ChromeNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
253 int bytes_read) {
[email protected]6f4b4b42012-08-27 21:59:07254 performance_monitor::PerformanceMonitor::GetInstance()->BytesReadOnIOThread(
255 request, bytes_read);
256
[email protected]44879ed2012-04-06 01:11:02257#if defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58258 TaskManager::GetInstance()->model()->NotifyBytesRead(request, bytes_read);
[email protected]44879ed2012-04-06 01:11:02259#endif // defined(ENABLE_TASK_MANAGER)
[email protected]8523ba52011-05-22 19:00:58260}
261
[email protected]9045b8822012-01-13 20:35:35262void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
263 bool started) {
[email protected]a83dd332011-07-13 10:41:01264 if (request->status().status() == net::URLRequestStatus::SUCCESS ||
265 request->status().status() == net::URLRequestStatus::HANDLED_EXTERNALLY) {
[email protected]48944382011-04-23 13:28:16266 bool is_redirect = request->response_headers() &&
267 net::HttpResponseHeaders::IsRedirectResponseCode(
268 request->response_headers()->response_code());
269 if (!is_redirect) {
270 ExtensionWebRequestEventRouter::GetInstance()->OnCompleted(
[email protected]673514522011-07-13 18:17:18271 profile_, extension_info_map_.get(), request);
[email protected]48944382011-04-23 13:28:16272 }
[email protected]a83dd332011-07-13 10:41:01273 } else if (request->status().status() == net::URLRequestStatus::FAILED ||
274 request->status().status() == net::URLRequestStatus::CANCELED) {
[email protected]05b6ab42011-04-23 13:46:04275 ExtensionWebRequestEventRouter::GetInstance()->OnErrorOccurred(
[email protected]9045b8822012-01-13 20:35:35276 profile_, extension_info_map_.get(), request, started);
[email protected]a83dd332011-07-13 10:41:01277 } else {
278 NOTREACHED();
[email protected]48944382011-04-23 13:28:16279 }
[email protected]673514522011-07-13 18:17:18280 ForwardProxyErrors(request, event_router_.get(), profile_);
[email protected]6baff0b52012-03-06 01:30:18281
282 ForwardRequestStatus(REQUEST_DONE, request, profile_);
[email protected]8202d0c2011-02-23 08:31:14283}
[email protected]4b50cb52011-03-10 00:29:37284
[email protected]4875ba12011-03-30 22:31:51285void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
286 ExtensionWebRequestEventRouter::GetInstance()->OnURLRequestDestroyed(
[email protected]673514522011-07-13 18:17:18287 profile_, request);
[email protected]4875ba12011-03-30 22:31:51288}
289
[email protected]82a37672011-05-03 12:02:41290void ChromeNetworkDelegate::OnPACScriptError(int line_number,
291 const string16& error) {
[email protected]c454fe672012-03-12 21:18:01292 extensions::ProxyEventRouter::GetInstance()->OnPACScriptError(
[email protected]673514522011-07-13 18:17:18293 event_router_.get(), profile_, line_number, error);
[email protected]82a37672011-05-03 12:02:41294}
[email protected]7efc582d2011-08-03 20:46:35295
[email protected]c2911d72011-10-03 22:16:36296net::NetworkDelegate::AuthRequiredResponse
297ChromeNetworkDelegate::OnAuthRequired(
[email protected]7efc582d2011-08-03 20:46:35298 net::URLRequest* request,
[email protected]c2911d72011-10-03 22:16:36299 const net::AuthChallengeInfo& auth_info,
300 const AuthCallback& callback,
301 net::AuthCredentials* credentials) {
[email protected]90449ab2011-10-11 15:36:45302 return ExtensionWebRequestEventRouter::GetInstance()->OnAuthRequired(
303 profile_, extension_info_map_.get(), request, auth_info,
304 callback, credentials);
[email protected]7efc582d2011-08-03 20:46:35305}
[email protected]9c8ae8c2012-03-09 13:13:35306
[email protected]4c219e22012-05-05 19:41:04307bool ChromeNetworkDelegate::OnCanGetCookies(
308 const net::URLRequest& request,
[email protected]9c8ae8c2012-03-09 13:13:35309 const net::CookieList& cookie_list) {
310 // NULL during tests, or when we're running in the system context.
311 if (!cookie_settings_)
312 return true;
313
314 bool allow = cookie_settings_->IsReadingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04315 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35316
317 int render_process_id = -1;
318 int render_view_id = -1;
319 if (content::ResourceRequestInfo::GetRenderViewForRequest(
[email protected]4c219e22012-05-05 19:41:04320 &request, &render_process_id, &render_view_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35321 BrowserThread::PostTask(
322 BrowserThread::UI, FROM_HERE,
323 base::Bind(&TabSpecificContentSettings::CookiesRead,
324 render_process_id, render_view_id,
[email protected]4c219e22012-05-05 19:41:04325 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43326 cookie_list, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35327 }
328
329 return allow;
330}
331
[email protected]4c219e22012-05-05 19:41:04332bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
333 const std::string& cookie_line,
334 net::CookieOptions* options) {
[email protected]9c8ae8c2012-03-09 13:13:35335 // NULL during tests, or when we're running in the system context.
336 if (!cookie_settings_)
337 return true;
338
339 bool allow = cookie_settings_->IsSettingCookieAllowed(
[email protected]4c219e22012-05-05 19:41:04340 request.url(), request.first_party_for_cookies());
[email protected]9c8ae8c2012-03-09 13:13:35341
[email protected]9c8ae8c2012-03-09 13:13:35342 int render_process_id = -1;
343 int render_view_id = -1;
344 if (content::ResourceRequestInfo::GetRenderViewForRequest(
[email protected]4c219e22012-05-05 19:41:04345 &request, &render_process_id, &render_view_id)) {
[email protected]9c8ae8c2012-03-09 13:13:35346 BrowserThread::PostTask(
347 BrowserThread::UI, FROM_HERE,
348 base::Bind(&TabSpecificContentSettings::CookieChanged,
349 render_process_id, render_view_id,
[email protected]4c219e22012-05-05 19:41:04350 request.url(), request.first_party_for_cookies(),
[email protected]fd473d12012-04-05 11:38:43351 cookie_line, *options, !allow));
[email protected]9c8ae8c2012-03-09 13:13:35352 }
353
354 return allow;
355}
[email protected]4c219e22012-05-05 19:41:04356
357bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
358 const FilePath& path) const {
359 if (g_allow_file_access_)
360 return true;
361
[email protected]d8e4f132012-09-06 04:28:05362#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
363 return true;
364#else
[email protected]4c219e22012-05-05 19:41:04365#if defined(OS_CHROMEOS)
[email protected]d8e4f132012-09-06 04:28:05366 // If we're running Chrome for ChromeOS on Linux, we want to allow file
367 // access.
368 if (!base::chromeos::IsRunningOnChromeOS())
369 return true;
370
371 // Use a whitelist to only allow access to files residing in the list of
372 // directories below.
[email protected]4c219e22012-05-05 19:41:04373 static const char* const kLocalAccessWhiteList[] = {
374 "/home/chronos/user/Downloads",
375 "/home/chronos/user/log",
376 "/media",
377 "/opt/oem",
378 "/usr/share/chromeos-assets",
379 "/tmp",
380 "/var/log",
381 };
[email protected]d8e4f132012-09-06 04:28:05382#elif defined(OS_ANDROID)
383 // Access to files in external storage is allowed.
384 FilePath external_storage_path;
385 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
386 if (external_storage_path.IsParent(path))
[email protected]4c219e22012-05-05 19:41:04387 return true;
388
[email protected]d8e4f132012-09-06 04:28:05389 // Whitelist of other allowed directories.
390 static const char* const kLocalAccessWhiteList[] = {
391 "/sdcard",
392 "/mnt/sdcard",
393 };
394#endif
395
[email protected]4c219e22012-05-05 19:41:04396 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
397 const FilePath white_listed_path(kLocalAccessWhiteList[i]);
398 // FilePath::operator== should probably handle trailing separators.
399 if (white_listed_path == path.StripTrailingSeparators() ||
400 white_listed_path.IsParent(path)) {
401 return true;
402 }
403 }
[email protected]d8e4f132012-09-06 04:28:05404
[email protected]4c219e22012-05-05 19:41:04405 return false;
[email protected]d8e4f132012-09-06 04:28:05406#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
[email protected]4c219e22012-05-05 19:41:04407}
[email protected]a1d4ab072012-06-07 13:21:15408
409bool ChromeNetworkDelegate::OnCanThrottleRequest(
410 const net::URLRequest& request) const {
[email protected]c4a7df82012-08-09 22:48:46411 if (g_never_throttle_requests_) {
[email protected]a1d4ab072012-06-07 13:21:15412 return false;
413 }
414
[email protected]c4a7df82012-08-09 22:48:46415 return request.first_party_for_cookies().scheme() ==
[email protected]a1d4ab072012-06-07 13:21:15416 chrome::kExtensionScheme;
417}
[email protected]aa28181e2012-06-13 00:53:58418
419int ChromeNetworkDelegate::OnBeforeSocketStreamConnect(
420 net::SocketStream* socket,
421 const net::CompletionCallback& callback) {
422#if defined(ENABLE_CONFIGURATION_POLICY)
423 if (url_blacklist_manager_ &&
424 url_blacklist_manager_->IsURLBlocked(socket->url())) {
425 // URL access blocked by policy.
[email protected]aa28181e2012-06-13 00:53:58426 socket->net_log()->AddEvent(
[email protected]2fa08912012-06-14 20:56:26427 net::NetLog::TYPE_CHROME_POLICY_ABORTED_REQUEST,
428 net::NetLog::StringCallback("url",
429 &socket->url().possibly_invalid_spec()));
[email protected]aa28181e2012-06-13 00:53:58430 return net::ERR_NETWORK_ACCESS_DENIED;
431 }
432#endif
433 return net::OK;
434}
[email protected]5a07c192012-07-30 20:18:22435
[email protected]a9e0d1412012-08-20 22:13:01436void ChromeNetworkDelegate::OnRequestWaitStateChange(
[email protected]5a07c192012-07-30 20:18:22437 const net::URLRequest& request,
[email protected]a9e0d1412012-08-20 22:13:01438 RequestWaitState state) {
439 if (load_time_stats_)
440 load_time_stats_->OnRequestWaitStateChange(request, state);
[email protected]5a07c192012-07-30 20:18:22441}