| 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/extensions/api/file_system/file_system_api.h" | 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 6 | 6 |
| 7 #if defined(OS_MACOSX) |
| 8 #include "base/mac/foundation_util.h" |
| 9 #endif |
| 10 |
| 7 #include "base/bind.h" | 11 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 14 #include "base/logging.h" |
| 11 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 12 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/shell_window_registry.h" | 17 #include "chrome/browser/extensions/shell_window_registry.h" |
| 14 #include "chrome/browser/platform_util.h" | 18 #include "chrome/browser/platform_util.h" |
| 15 #include "chrome/browser/ui/chrome_select_file_policy.h" | 19 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 16 #include "chrome/browser/ui/extensions/shell_window.h" | 20 #include "chrome/browser/ui/extensions/shell_window.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 39 const char kOpenWritableFileOption[] ="openWritableFile"; | 43 const char kOpenWritableFileOption[] ="openWritableFile"; |
| 40 const char kSaveFileOption[] = "saveFile"; | 44 const char kSaveFileOption[] = "saveFile"; |
| 41 | 45 |
| 42 namespace file_system = extensions::api::file_system; | 46 namespace file_system = extensions::api::file_system; |
| 43 namespace ChooseFile = file_system::ChooseFile; | 47 namespace ChooseFile = file_system::ChooseFile; |
| 44 | 48 |
| 45 namespace { | 49 namespace { |
| 46 | 50 |
| 47 struct RewritePair { | 51 struct RewritePair { |
| 48 int path_key; | 52 int path_key; |
| 49 const char* output; | 53 const char* output; // NULL indicates that this display name should be |
| 54 // retrieved from the system. |
| 50 }; | 55 }; |
| 51 | 56 |
| 52 const RewritePair g_rewrite_pairs[] = { | 57 const RewritePair g_rewrite_pairs[] = { |
| 58 #if defined(OS_MACOSX) |
| 59 {base::DIR_DESKTOP, NULL}, |
| 60 {base::DIR_DOCUMENTS, NULL}, |
| 61 {base::DIR_DOWNLOADS, NULL}, |
| 62 #endif |
| 53 #if defined(OS_WIN) | 63 #if defined(OS_WIN) |
| 54 {base::DIR_PROFILE, "~"}, | 64 {base::DIR_PROFILE, "~"}, |
| 55 #elif defined(OS_POSIX) | 65 #elif defined(OS_POSIX) |
| 56 {base::DIR_HOME, "~"}, | 66 {base::DIR_HOME, "~"}, |
| 57 #endif | 67 #endif |
| 58 }; | 68 }; |
| 59 | 69 |
| 60 FilePath PrettifyPath(const FilePath& file_path) { | 70 FilePath PrettifyPath(const FilePath& file_path) { |
| 61 #if defined(OS_WIN) || defined(OS_POSIX) | 71 #if defined(OS_WIN) || defined(OS_POSIX) |
| 62 for (size_t i = 0; i < arraysize(g_rewrite_pairs); ++i) { | 72 for (size_t i = 0; i < arraysize(g_rewrite_pairs); ++i) { |
| 63 FilePath candidate_path; | 73 FilePath candidate_path; |
| 64 if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) | 74 if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) |
| 65 continue; // We don't DCHECK this value, as Get will return false even | 75 continue; // We don't DCHECK this value, as Get will return false even |
| 66 // if the path_key gives a blank string as a result. | 76 // if the path_key gives a blank string as a result. |
| 67 | 77 |
| 68 FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output); | 78 FilePath output; |
| 79 if (!g_rewrite_pairs[i].output) { |
| 80 #if defined(OS_MACOSX) |
| 81 if (!candidate_path.IsParent(file_path)) |
| 82 continue; |
| 83 |
| 84 std::string display_name; |
| 85 base::mac::GetDisplayNameForPath(candidate_path, &display_name); |
| 86 output = FilePath::FromUTF8Unsafe(display_name); |
| 87 #else |
| 88 NOTREACHED(); |
| 89 #endif |
| 90 } else { |
| 91 output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output); |
| 92 } |
| 93 |
| 69 if (candidate_path.AppendRelativePath(file_path, &output)) { | 94 if (candidate_path.AppendRelativePath(file_path, &output)) { |
| 70 // The output path must not be absolute, as it might collide with the | 95 // The output path must not be absolute, as it might collide with the |
| 71 // real filesystem. | 96 // real filesystem. |
| 72 DCHECK(!output.IsAbsolute()); | 97 DCHECK(!output.IsAbsolute()); |
| 73 return output; | 98 return output; |
| 74 } | 99 } |
| 75 } | 100 } |
| 76 #endif | 101 #endif |
| 77 | 102 |
| 78 return file_path; | 103 return file_path; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 454 |
| 430 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 455 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
| 431 error_ = kRequiresFileSystemWriteError; | 456 error_ = kRequiresFileSystemWriteError; |
| 432 return false; | 457 return false; |
| 433 } | 458 } |
| 434 | 459 |
| 435 return ShowPicker(suggested_name, picker_type, entry_type); | 460 return ShowPicker(suggested_name, picker_type, entry_type); |
| 436 } | 461 } |
| 437 | 462 |
| 438 } // namespace extensions | 463 } // namespace extensions |
| OLD | NEW |