| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/base_paths.h" |
| 9 #include "base/path_service.h" |
| 8 #include "chrome/browser/api/prefs/pref_member.h" | 10 #include "chrome/browser/api/prefs/pref_member.h" |
| 9 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/content_settings/cookie_settings.h" | 12 #include "chrome/browser/content_settings/cookie_settings.h" |
| 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 12 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 13 #include "chrome/browser/extensions/api/proxy/proxy_api.h" | 15 #include "chrome/browser/extensions/api/proxy/proxy_api.h" |
| 14 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 16 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 15 #include "chrome/browser/extensions/event_router_forwarder.h" | 17 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 16 #include "chrome/browser/extensions/extension_info_map.h" | 18 #include "chrome/browser/extensions/extension_info_map.h" |
| 17 #include "chrome/browser/extensions/extension_process_manager.h" | 19 #include "chrome/browser/extensions/extension_process_manager.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 44 #endif | 46 #endif |
| 45 | 47 |
| 46 #if defined(ENABLE_CONFIGURATION_POLICY) | 48 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 47 #include "chrome/browser/policy/url_blacklist_manager.h" | 49 #include "chrome/browser/policy/url_blacklist_manager.h" |
| 48 #endif | 50 #endif |
| 49 | 51 |
| 50 using content::BrowserThread; | 52 using content::BrowserThread; |
| 51 using content::RenderViewHost; | 53 using content::RenderViewHost; |
| 52 using content::ResourceRequestInfo; | 54 using content::ResourceRequestInfo; |
| 53 | 55 |
| 54 // By default we don't allow access to all file:// urls on ChromeOS but we do on | 56 // By default we don't allow access to all file:// urls on ChromeOS and |
| 55 // other platforms. | 57 // Android. |
| 56 #if defined(OS_CHROMEOS) | 58 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 57 bool ChromeNetworkDelegate::g_allow_file_access_ = false; | 59 bool ChromeNetworkDelegate::g_allow_file_access_ = false; |
| 58 #else | 60 #else |
| 59 bool ChromeNetworkDelegate::g_allow_file_access_ = true; | 61 bool ChromeNetworkDelegate::g_allow_file_access_ = true; |
| 60 #endif | 62 #endif |
| 61 | 63 |
| 62 // This remains false unless the --disable-extensions-http-throttling | 64 // This remains false unless the --disable-extensions-http-throttling |
| 63 // flag is passed to the browser. | 65 // flag is passed to the browser. |
| 64 bool ChromeNetworkDelegate::g_never_throttle_requests_ = false; | 66 bool ChromeNetworkDelegate::g_never_throttle_requests_ = false; |
| 65 | 67 |
| 66 namespace { | 68 namespace { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 352 } |
| 351 | 353 |
| 352 return allow; | 354 return allow; |
| 353 } | 355 } |
| 354 | 356 |
| 355 bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, | 357 bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, |
| 356 const FilePath& path) const { | 358 const FilePath& path) const { |
| 357 if (g_allow_file_access_) | 359 if (g_allow_file_access_) |
| 358 return true; | 360 return true; |
| 359 | 361 |
| 362 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 363 return true; |
| 364 #else |
| 360 #if defined(OS_CHROMEOS) | 365 #if defined(OS_CHROMEOS) |
| 361 // ChromeOS uses a whitelist to only allow access to files residing in the | 366 // If we're running Chrome for ChromeOS on Linux, we want to allow file |
| 362 // list of directories below. | 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. |
| 363 static const char* const kLocalAccessWhiteList[] = { | 373 static const char* const kLocalAccessWhiteList[] = { |
| 364 "/home/chronos/user/Downloads", | 374 "/home/chronos/user/Downloads", |
| 365 "/home/chronos/user/log", | 375 "/home/chronos/user/log", |
| 366 "/media", | 376 "/media", |
| 367 "/opt/oem", | 377 "/opt/oem", |
| 368 "/usr/share/chromeos-assets", | 378 "/usr/share/chromeos-assets", |
| 369 "/tmp", | 379 "/tmp", |
| 370 "/var/log", | 380 "/var/log", |
| 371 }; | 381 }; |
| 382 #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)) |
| 387 return true; |
| 372 | 388 |
| 373 // If we're running Chrome for ChromeOS on Linux, we want to allow file | 389 // Whitelist of other allowed directories. |
| 374 // access. | 390 static const char* const kLocalAccessWhiteList[] = { |
| 375 if (!base::chromeos::IsRunningOnChromeOS()) | 391 "/sdcard", |
| 376 return true; | 392 "/mnt/sdcard", |
| 393 }; |
| 394 #endif |
| 377 | 395 |
| 378 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) { | 396 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) { |
| 379 const FilePath white_listed_path(kLocalAccessWhiteList[i]); | 397 const FilePath white_listed_path(kLocalAccessWhiteList[i]); |
| 380 // FilePath::operator== should probably handle trailing separators. | 398 // FilePath::operator== should probably handle trailing separators. |
| 381 if (white_listed_path == path.StripTrailingSeparators() || | 399 if (white_listed_path == path.StripTrailingSeparators() || |
| 382 white_listed_path.IsParent(path)) { | 400 white_listed_path.IsParent(path)) { |
| 383 return true; | 401 return true; |
| 384 } | 402 } |
| 385 } | 403 } |
| 404 |
| 386 return false; | 405 return false; |
| 387 #else | 406 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 388 return true; | |
| 389 #endif // defined(OS_CHROMEOS) | |
| 390 } | 407 } |
| 391 | 408 |
| 392 bool ChromeNetworkDelegate::OnCanThrottleRequest( | 409 bool ChromeNetworkDelegate::OnCanThrottleRequest( |
| 393 const net::URLRequest& request) const { | 410 const net::URLRequest& request) const { |
| 394 if (g_never_throttle_requests_) { | 411 if (g_never_throttle_requests_) { |
| 395 return false; | 412 return false; |
| 396 } | 413 } |
| 397 | 414 |
| 398 return request.first_party_for_cookies().scheme() == | 415 return request.first_party_for_cookies().scheme() == |
| 399 chrome::kExtensionScheme; | 416 chrome::kExtensionScheme; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 415 #endif | 432 #endif |
| 416 return net::OK; | 433 return net::OK; |
| 417 } | 434 } |
| 418 | 435 |
| 419 void ChromeNetworkDelegate::OnRequestWaitStateChange( | 436 void ChromeNetworkDelegate::OnRequestWaitStateChange( |
| 420 const net::URLRequest& request, | 437 const net::URLRequest& request, |
| 421 RequestWaitState state) { | 438 RequestWaitState state) { |
| 422 if (load_time_stats_) | 439 if (load_time_stats_) |
| 423 load_time_stats_->OnRequestWaitStateChange(request, state); | 440 load_time_stats_->OnRequestWaitStateChange(request, state); |
| 424 } | 441 } |
| OLD | NEW |