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 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | |
11 #include "base/utf_string_conversions.h" | |
10 #include "chrome/browser/extensions/shell_window_registry.h" | 12 #include "chrome/browser/extensions/shell_window_registry.h" |
11 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
12 #include "chrome/browser/ui/extensions/shell_window.h" | 14 #include "chrome/browser/ui/extensions/shell_window.h" |
13 #include "chrome/common/extensions/api/file_system.h" | 15 #include "chrome/common/extensions/api/file_system.h" |
14 #include "chrome/common/extensions/permissions/api_permission.h" | 16 #include "chrome/common/extensions/permissions/api_permission.h" |
15 #include "content/public/browser/child_process_security_policy.h" | 17 #include "content/public/browser/child_process_security_policy.h" |
16 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
19 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
30 | 32 |
31 const char kOpenFileOption[] = "openFile"; | 33 const char kOpenFileOption[] = "openFile"; |
32 const char kOpenWritableFileOption[] ="openWritableFile"; | 34 const char kOpenWritableFileOption[] ="openWritableFile"; |
33 const char kSaveFileOption[] = "saveFile"; | 35 const char kSaveFileOption[] = "saveFile"; |
34 | 36 |
35 namespace file_system = extensions::api::file_system; | 37 namespace file_system = extensions::api::file_system; |
36 namespace ChooseFile = file_system::ChooseFile; | 38 namespace ChooseFile = file_system::ChooseFile; |
37 | 39 |
38 namespace { | 40 namespace { |
39 | 41 |
42 /*struct RewritePair { | |
benwells
2012/07/06 00:34:36
We should uncomment this and use to simplify g_rew
thorogood
2012/07/06 06:34:16
Done. Although this was mostly left over; I actual
| |
43 int path_key; | |
44 const char* output; | |
45 };*/ | |
46 | |
47 const struct { | |
48 int path_key; | |
49 const char* output; | |
50 } g_rewrite_pairs[] = { | |
51 #if defined(OS_WIN) | |
52 {base::DIR_PROFILE, "HOME"}, | |
benwells
2012/07/06 00:34:36
Can we make HOME a bit ... prettier?
I'm open to
thorogood
2012/07/06 06:34:16
Probably - I'm not sure of a consistent way to get
| |
53 #endif | |
54 {-1, NULL} | |
55 }; | |
56 | |
57 void PrettifyPath(FilePath& file_path) { | |
58 for (int i = 0; g_rewrite_pairs[i].output; ++i) { | |
59 FilePath candidate_path; | |
60 if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) { | |
benwells
2012/07/06 00:34:36
Should failure here be an error?
thorogood
2012/07/06 06:34:16
Probably not. Get() returns false if it's just an
| |
61 continue; | |
62 } | |
63 | |
64 FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output); | |
65 if (candidate_path.AppendRelativePath(file_path, &output)) { | |
66 DCHECK(!output.IsAbsolute()); | |
67 file_path = output; | |
68 return; // Only prettify the first hit. | |
69 } | |
70 } | |
71 } | |
72 | |
40 bool g_skip_picker_for_test = false; | 73 bool g_skip_picker_for_test = false; |
41 FilePath* g_path_to_be_picked_for_test; | 74 FilePath* g_path_to_be_picked_for_test; |
42 | 75 |
43 bool GetFilePathOfFileEntry(const std::string& filesystem_name, | 76 bool GetFilePathOfFileEntry(const std::string& filesystem_name, |
44 const std::string& filesystem_path, | 77 const std::string& filesystem_path, |
45 const content::RenderViewHost* render_view_host, | 78 const content::RenderViewHost* render_view_host, |
46 FilePath* file_path, | 79 FilePath* file_path, |
47 std::string* error) { | 80 std::string* error) { |
48 std::string filesystem_id; | 81 std::string filesystem_id; |
49 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { | 82 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 std::string filesystem_name; | 132 std::string filesystem_name; |
100 std::string filesystem_path; | 133 std::string filesystem_path; |
101 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 134 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
102 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 135 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
103 | 136 |
104 FilePath file_path; | 137 FilePath file_path; |
105 if (!GetFilePathOfFileEntry(filesystem_name, filesystem_path, | 138 if (!GetFilePathOfFileEntry(filesystem_name, filesystem_path, |
106 render_view_host_, &file_path, &error_)) | 139 render_view_host_, &file_path, &error_)) |
107 return false; | 140 return false; |
108 | 141 |
142 PrettifyPath(file_path); | |
109 result_.reset(base::Value::CreateStringValue(file_path.value())); | 143 result_.reset(base::Value::CreateStringValue(file_path.value())); |
110 return true; | 144 return true; |
111 } | 145 } |
112 | 146 |
113 bool FileSystemEntryFunction::HasFileSystemWritePermission() { | 147 bool FileSystemEntryFunction::HasFileSystemWritePermission() { |
114 const extensions::Extension* extension = GetExtension(); | 148 const extensions::Extension* extension = GetExtension(); |
115 if (!extension) | 149 if (!extension) |
116 return false; | 150 return false; |
117 | 151 |
118 return extension->HasAPIPermission(APIPermission::kFileSystemWrite); | 152 return extension->HasAPIPermission(APIPermission::kFileSystemWrite); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 | 380 |
347 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 381 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
348 error_ = kRequiresFileSystemWriteError; | 382 error_ = kRequiresFileSystemWriteError; |
349 return false; | 383 return false; |
350 } | 384 } |
351 | 385 |
352 return ShowPicker(FilePath(), picker_type, entry_type); | 386 return ShowPicker(FilePath(), picker_type, entry_type); |
353 } | 387 } |
354 | 388 |
355 } // namespace extensions | 389 } // namespace extensions |
OLD | NEW |