Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: chrome/browser/net/chrome_network_delegate.cc

Issue 10905114: Restrict file access on android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/url_request/url_request_file_job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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)
willchan no longer on Chromium 2012/09/06 00:20:15 How about doing: #if !defined(OS_CHROME) && !defi
nilesh 2012/09/06 00:26:14 Done.
360 #if defined(OS_CHROMEOS) 363 #if defined(OS_CHROMEOS)
361 // ChromeOS uses a whitelist to only allow access to files residing in the 364 // If we're running Chrome for ChromeOS on Linux, we want to allow file
362 // list of directories below. 365 // access.
366 if (!base::chromeos::IsRunningOnChromeOS())
367 return true;
368
369 // Use a whitelist to only allow access to files residing in the list of
370 // directories below.
363 static const char* const kLocalAccessWhiteList[] = { 371 static const char* const kLocalAccessWhiteList[] = {
364 "/home/chronos/user/Downloads", 372 "/home/chronos/user/Downloads",
365 "/home/chronos/user/log", 373 "/home/chronos/user/log",
366 "/media", 374 "/media",
367 "/opt/oem", 375 "/opt/oem",
368 "/usr/share/chromeos-assets", 376 "/usr/share/chromeos-assets",
369 "/tmp", 377 "/tmp",
370 "/var/log", 378 "/var/log",
371 }; 379 };
380 #endif
willchan no longer on Chromium 2012/09/06 00:20:15 Combine the #endif and #if into a #elif?
nilesh 2012/09/06 00:26:14 Done.
381 #if defined(OS_ANDROID)
382 // Access to files in external storage is allowed.
383 FilePath external_storage_path;
384 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
385 if (external_storage_path.IsParent(path))
386 return true;
372 387
373 // If we're running Chrome for ChromeOS on Linux, we want to allow file 388 // Whitelist of other allowed directories.
374 // access. 389 static const char* const kLocalAccessWhiteList[] = {
375 if (!base::chromeos::IsRunningOnChromeOS()) 390 "/sdcard",
376 return true; 391 "/mnt/sdcard",
392 };
393 #endif
377 394
378 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) { 395 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
379 const FilePath white_listed_path(kLocalAccessWhiteList[i]); 396 const FilePath white_listed_path(kLocalAccessWhiteList[i]);
380 // FilePath::operator== should probably handle trailing separators. 397 // FilePath::operator== should probably handle trailing separators.
381 if (white_listed_path == path.StripTrailingSeparators() || 398 if (white_listed_path == path.StripTrailingSeparators() ||
382 white_listed_path.IsParent(path)) { 399 white_listed_path.IsParent(path)) {
383 return true; 400 return true;
384 } 401 }
385 } 402 }
403
386 return false; 404 return false;
387 #else 405 #else
388 return true; 406 return true;
389 #endif // defined(OS_CHROMEOS) 407 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID)
390 } 408 }
391 409
392 bool ChromeNetworkDelegate::OnCanThrottleRequest( 410 bool ChromeNetworkDelegate::OnCanThrottleRequest(
393 const net::URLRequest& request) const { 411 const net::URLRequest& request) const {
394 if (g_never_throttle_requests_) { 412 if (g_never_throttle_requests_) {
395 return false; 413 return false;
396 } 414 }
397 415
398 return request.first_party_for_cookies().scheme() == 416 return request.first_party_for_cookies().scheme() ==
399 chrome::kExtensionScheme; 417 chrome::kExtensionScheme;
(...skipping 15 matching lines...) Expand all
415 #endif 433 #endif
416 return net::OK; 434 return net::OK;
417 } 435 }
418 436
419 void ChromeNetworkDelegate::OnRequestWaitStateChange( 437 void ChromeNetworkDelegate::OnRequestWaitStateChange(
420 const net::URLRequest& request, 438 const net::URLRequest& request,
421 RequestWaitState state) { 439 RequestWaitState state) {
422 if (load_time_stats_) 440 if (load_time_stats_)
423 load_time_stats_->OnRequestWaitStateChange(request, state); 441 load_time_stats_->OnRequestWaitStateChange(request, state);
424 } 442 }
OLDNEW
« no previous file with comments | « no previous file | net/url_request/url_request_file_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698