| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 info->GetWebContentsGetterForRequest(), | 444 info->GetWebContentsGetterForRequest(), |
| 445 request.url(), request.first_party_for_cookies(), | 445 request.url(), request.first_party_for_cookies(), |
| 446 cookie_line, *options, !allow)); | 446 cookie_line, *options, !allow)); |
| 447 } | 447 } |
| 448 | 448 |
| 449 return allow; | 449 return allow; |
| 450 } | 450 } |
| 451 | 451 |
| 452 bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, | 452 bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, |
| 453 const base::FilePath& path) const { | 453 const base::FilePath& path) const { |
| 454 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | |
| 455 return true; | |
| 456 #else | |
| 457 #if defined(OS_CHROMEOS) | 454 #if defined(OS_CHROMEOS) |
| 458 // If we're running Chrome for ChromeOS on Linux, we want to allow file | 455 // If we're running Chrome for ChromeOS on Linux, we want to allow file |
| 459 // access. | 456 // access. This is checked here to make IsAccessAllowed() unit-testable. |
| 460 if (!base::SysInfo::IsRunningOnChromeOS() || | 457 if (!base::SysInfo::IsRunningOnChromeOS() || |
| 461 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { | 458 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 462 return true; | 459 return true; |
| 463 } | 460 } |
| 461 #endif |
| 464 | 462 |
| 463 return IsAccessAllowed(path, profile_path_); |
| 464 } |
| 465 |
| 466 // static |
| 467 bool ChromeNetworkDelegate::IsAccessAllowed( |
| 468 const base::FilePath& path, |
| 469 const base::FilePath& profile_path) { |
| 470 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 471 return true; |
| 472 #else |
| 473 |
| 474 #if defined(OS_CHROMEOS) |
| 465 // Use a whitelist to only allow access to files residing in the list of | 475 // Use a whitelist to only allow access to files residing in the list of |
| 466 // directories below. | 476 // directories below. |
| 467 static const char* const kLocalAccessWhiteList[] = { | 477 static const char* const kLocalAccessWhiteList[] = { |
| 468 "/home/chronos/user/Downloads", | 478 "/home/chronos/user/Downloads", |
| 469 "/home/chronos/user/log", | 479 "/home/chronos/user/log", |
| 470 "/home/chronos/user/WebRTC Logs", | 480 "/home/chronos/user/WebRTC Logs", |
| 471 "/media", | 481 "/media", |
| 472 "/opt/oem", | 482 "/opt/oem", |
| 473 "/usr/share/chromeos-assets", | 483 "/usr/share/chromeos-assets", |
| 474 "/tmp", | 484 "/tmp", |
| 475 "/var/log", | 485 "/var/log", |
| 476 }; | 486 }; |
| 477 | 487 |
| 478 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under | 488 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under |
| 479 // the profile path ("/home/chronos/user' is a hard link to current primary | 489 // the profile path ("/home/chronos/user' is a hard link to current primary |
| 480 // logged in profile.) For the support of multi-profile sessions, we are | 490 // logged in profile.) For the support of multi-profile sessions, we are |
| 481 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such | 491 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such |
| 482 // access. | 492 // access. |
| 483 if (!profile_path_.empty()) { | 493 if (!profile_path.empty()) { |
| 484 const base::FilePath downloads = profile_path_.AppendASCII("Downloads"); | 494 const base::FilePath downloads = profile_path.AppendASCII("Downloads"); |
| 485 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path)) | 495 if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path)) |
| 486 return true; | 496 return true; |
| 487 const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs"); | 497 const base::FilePath webrtc_logs = profile_path.AppendASCII("WebRTC Logs"); |
| 488 if (webrtc_logs == path.StripTrailingSeparators() || | 498 if (webrtc_logs == path.StripTrailingSeparators() || |
| 489 webrtc_logs.IsParent(path)) { | 499 webrtc_logs.IsParent(path)) { |
| 490 return true; | 500 return true; |
| 491 } | 501 } |
| 492 } | 502 } |
| 493 #elif defined(OS_ANDROID) | 503 #elif defined(OS_ANDROID) |
| 494 // Access to files in external storage is allowed. | 504 // Access to files in external storage is allowed. |
| 495 base::FilePath external_storage_path; | 505 base::FilePath external_storage_path; |
| 496 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); | 506 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); |
| 497 if (external_storage_path.IsParent(path)) | 507 if (external_storage_path.IsParent(path)) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 if (!data_use_aggregator_) | 564 if (!data_use_aggregator_) |
| 555 return; | 565 return; |
| 556 | 566 |
| 557 if (is_data_usage_off_the_record_) { | 567 if (is_data_usage_off_the_record_) { |
| 558 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | 568 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
| 559 return; | 569 return; |
| 560 } | 570 } |
| 561 | 571 |
| 562 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); | 572 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
| 563 } | 573 } |
| OLD | NEW |