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" | 10 #include "base/path_service.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/extensions/shell_window_registry.h" | 12 #include "chrome/browser/extensions/shell_window_registry.h" |
13 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
14 #include "chrome/browser/ui/chrome_select_file_policy.h" | 14 #include "chrome/browser/ui/chrome_select_file_policy.h" |
15 #include "chrome/browser/ui/extensions/shell_window.h" | 15 #include "chrome/browser/ui/extensions/shell_window.h" |
16 #include "chrome/common/extensions/api/file_system.h" | 16 #include "chrome/common/extensions/api/file_system.h" |
17 #include "chrome/common/extensions/permissions/api_permission.h" | 17 #include "chrome/common/extensions/permissions/api_permission.h" |
18 #include "content/public/browser/child_process_security_policy.h" | 18 #include "content/public/browser/child_process_security_policy.h" |
19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "webkit/fileapi/file_system_util.h" | 22 #include "webkit/fileapi/file_system_util.h" |
23 #include "webkit/fileapi/isolated_context.h" | 23 #include "webkit/fileapi/isolated_context.h" |
24 | 24 |
| 25 using fileapi::IsolatedContext; |
| 26 |
25 const char kInvalidParameters[] = "Invalid parameters"; | 27 const char kInvalidParameters[] = "Invalid parameters"; |
26 const char kSecurityError[] = "Security error"; | 28 const char kSecurityError[] = "Security error"; |
27 const char kInvalidCallingPage[] = "Invalid calling page"; | 29 const char kInvalidCallingPage[] = "Invalid calling page"; |
28 const char kUserCancelled[] = "User cancelled"; | 30 const char kUserCancelled[] = "User cancelled"; |
29 const char kWritableFileError[] = "Invalid file for writing"; | 31 const char kWritableFileError[] = "Invalid file for writing"; |
30 const char kRequiresFileSystemWriteError[] = | 32 const char kRequiresFileSystemWriteError[] = |
31 "Operation requires fileSystemWrite permission"; | 33 "Operation requires fileSystemWrite permission"; |
32 const char kUnknownChooseFileType[] = "Unknown type"; | 34 const char kUnknownChooseFileType[] = "Unknown type"; |
33 | 35 |
34 const char kOpenFileOption[] = "openFile"; | 36 const char kOpenFileOption[] = "openFile"; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // Only return the display path if the process has read access to the | 97 // Only return the display path if the process has read access to the |
96 // filesystem. | 98 // filesystem. |
97 content::ChildProcessSecurityPolicy* policy = | 99 content::ChildProcessSecurityPolicy* policy = |
98 content::ChildProcessSecurityPolicy::GetInstance(); | 100 content::ChildProcessSecurityPolicy::GetInstance(); |
99 if (!policy->CanReadFileSystem(render_view_host->GetProcess()->GetID(), | 101 if (!policy->CanReadFileSystem(render_view_host->GetProcess()->GetID(), |
100 filesystem_id)) { | 102 filesystem_id)) { |
101 *error = kSecurityError; | 103 *error = kSecurityError; |
102 return false; | 104 return false; |
103 } | 105 } |
104 | 106 |
105 fileapi::IsolatedContext* context = fileapi::IsolatedContext::GetInstance(); | 107 IsolatedContext* context = IsolatedContext::GetInstance(); |
106 FilePath relative_path = FilePath::FromUTF8Unsafe(filesystem_path); | 108 FilePath relative_path = FilePath::FromUTF8Unsafe(filesystem_path); |
107 FilePath virtual_path = context->CreateVirtualPath(filesystem_id, | 109 FilePath virtual_path = context->CreateVirtualRootPath(filesystem_id) |
108 relative_path); | 110 .Append(relative_path); |
109 if (!context->CrackIsolatedPath(virtual_path, | 111 if (!context->CrackIsolatedPath(virtual_path, |
110 &filesystem_id, | 112 &filesystem_id, |
111 NULL, | 113 NULL, |
112 file_path)) { | 114 file_path)) { |
113 *error = kInvalidParameters; | 115 *error = kInvalidParameters; |
114 return false; | 116 return false; |
115 } | 117 } |
116 | 118 |
117 return true; | 119 return true; |
118 } | 120 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return; | 171 return; |
170 } | 172 } |
171 | 173 |
172 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 174 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
173 base::Bind(&FileSystemEntryFunction::HandleWritableFileError, this)); | 175 base::Bind(&FileSystemEntryFunction::HandleWritableFileError, this)); |
174 } | 176 } |
175 | 177 |
176 void FileSystemEntryFunction::RegisterFileSystemAndSendResponse( | 178 void FileSystemEntryFunction::RegisterFileSystemAndSendResponse( |
177 const FilePath& path, EntryType entry_type) { | 179 const FilePath& path, EntryType entry_type) { |
178 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 180 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
179 std::set<FilePath> filesets; | |
180 filesets.insert(path); | |
181 | 181 |
182 fileapi::IsolatedContext* isolated_context = | 182 fileapi::IsolatedContext* isolated_context = |
183 fileapi::IsolatedContext::GetInstance(); | 183 fileapi::IsolatedContext::GetInstance(); |
184 DCHECK(isolated_context); | 184 DCHECK(isolated_context); |
185 std::string filesystem_id = isolated_context->RegisterIsolatedFileSystem( | 185 |
186 filesets); | 186 std::string registered_name; |
| 187 std::string filesystem_id = isolated_context->RegisterFileSystemForFile( |
| 188 path, ®istered_name); |
187 | 189 |
188 content::ChildProcessSecurityPolicy* policy = | 190 content::ChildProcessSecurityPolicy* policy = |
189 content::ChildProcessSecurityPolicy::GetInstance(); | 191 content::ChildProcessSecurityPolicy::GetInstance(); |
190 int renderer_id = render_view_host_->GetProcess()->GetID(); | 192 int renderer_id = render_view_host_->GetProcess()->GetID(); |
191 if (entry_type == WRITABLE) | 193 if (entry_type == WRITABLE) |
192 policy->GrantReadWriteFileSystem(renderer_id, filesystem_id); | 194 policy->GrantReadWriteFileSystem(renderer_id, filesystem_id); |
193 else | 195 else |
194 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 196 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
195 | 197 |
196 // We only need file level access for reading FileEntries. Saving FileEntries | 198 // We only need file level access for reading FileEntries. Saving FileEntries |
197 // just needs the file system to have read/write access, which is granted | 199 // just needs the file system to have read/write access, which is granted |
198 // above if required. | 200 // above if required. |
199 if (!policy->CanReadFile(renderer_id, path)) | 201 if (!policy->CanReadFile(renderer_id, path)) |
200 policy->GrantReadFile(renderer_id, path); | 202 policy->GrantReadFile(renderer_id, path); |
201 | 203 |
202 DictionaryValue* dict = new DictionaryValue(); | 204 DictionaryValue* dict = new DictionaryValue(); |
203 result_.reset(dict); | 205 result_.reset(dict); |
204 dict->SetString("fileSystemId", filesystem_id); | 206 dict->SetString("fileSystemId", filesystem_id); |
205 dict->SetString("baseName", path.BaseName().AsUTF8Unsafe()); | 207 dict->SetString("baseName", registered_name); |
206 SendResponse(true); | 208 SendResponse(true); |
207 } | 209 } |
208 | 210 |
209 void FileSystemEntryFunction::HandleWritableFileError() { | 211 void FileSystemEntryFunction::HandleWritableFileError() { |
210 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 212 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
211 error_ = kWritableFileError; | 213 error_ = kWritableFileError; |
212 SendResponse(false); | 214 SendResponse(false); |
213 } | 215 } |
214 | 216 |
215 bool FileSystemGetWritableFileEntryFunction::RunImpl() { | 217 bool FileSystemGetWritableFileEntryFunction::RunImpl() { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 391 |
390 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 392 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
391 error_ = kRequiresFileSystemWriteError; | 393 error_ = kRequiresFileSystemWriteError; |
392 return false; | 394 return false; |
393 } | 395 } |
394 | 396 |
395 return ShowPicker(FilePath(), picker_type, entry_type); | 397 return ShowPicker(FilePath(), picker_type, entry_type); |
396 } | 398 } |
397 | 399 |
398 } // namespace extensions | 400 } // namespace extensions |
OLD | NEW |