| 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/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/shell_window_registry.h" | 13 #include "chrome/browser/extensions/shell_window_registry.h" |
| 14 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
| 15 #include "chrome/browser/ui/chrome_select_file_policy.h" | 15 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 16 #include "chrome/browser/ui/extensions/shell_window.h" | 16 #include "chrome/browser/ui/extensions/shell_window.h" |
| 17 #include "chrome/common/extensions/api/file_system.h" | 17 #include "chrome/common/extensions/api/file_system.h" |
| 18 #include "chrome/common/extensions/permissions/api_permission.h" | 18 #include "chrome/common/extensions/permissions/api_permission.h" |
| 19 #include "content/public/browser/child_process_security_policy.h" | 19 #include "content/public/browser/child_process_security_policy.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "webkit/fileapi/file_system_types.h" |
| 23 #include "webkit/fileapi/file_system_util.h" | 24 #include "webkit/fileapi/file_system_util.h" |
| 24 #include "webkit/fileapi/isolated_context.h" | 25 #include "webkit/fileapi/isolated_context.h" |
| 25 | 26 |
| 26 using fileapi::IsolatedContext; | 27 using fileapi::IsolatedContext; |
| 27 | 28 |
| 28 const char kInvalidParameters[] = "Invalid parameters"; | 29 const char kInvalidParameters[] = "Invalid parameters"; |
| 29 const char kSecurityError[] = "Security error"; | 30 const char kSecurityError[] = "Security error"; |
| 30 const char kInvalidCallingPage[] = "Invalid calling page"; | 31 const char kInvalidCallingPage[] = "Invalid calling page"; |
| 31 const char kUserCancelled[] = "User cancelled"; | 32 const char kUserCancelled[] = "User cancelled"; |
| 32 const char kWritableFileError[] = "Invalid file for writing"; | 33 const char kWritableFileError[] = "Invalid file for writing"; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 179 |
| 179 void FileSystemEntryFunction::RegisterFileSystemAndSendResponse( | 180 void FileSystemEntryFunction::RegisterFileSystemAndSendResponse( |
| 180 const FilePath& path, EntryType entry_type) { | 181 const FilePath& path, EntryType entry_type) { |
| 181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 182 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 182 | 183 |
| 183 fileapi::IsolatedContext* isolated_context = | 184 fileapi::IsolatedContext* isolated_context = |
| 184 fileapi::IsolatedContext::GetInstance(); | 185 fileapi::IsolatedContext::GetInstance(); |
| 185 DCHECK(isolated_context); | 186 DCHECK(isolated_context); |
| 186 | 187 |
| 187 std::string registered_name; | 188 std::string registered_name; |
| 188 std::string filesystem_id = isolated_context->RegisterFileSystemForFile( | 189 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
| 189 path, ®istered_name); | 190 fileapi::kFileSystemTypeIsolated, path, ®istered_name); |
| 190 | 191 |
| 191 content::ChildProcessSecurityPolicy* policy = | 192 content::ChildProcessSecurityPolicy* policy = |
| 192 content::ChildProcessSecurityPolicy::GetInstance(); | 193 content::ChildProcessSecurityPolicy::GetInstance(); |
| 193 int renderer_id = render_view_host_->GetProcess()->GetID(); | 194 int renderer_id = render_view_host_->GetProcess()->GetID(); |
| 194 if (entry_type == WRITABLE) | 195 if (entry_type == WRITABLE) |
| 195 policy->GrantReadWriteFileSystem(renderer_id, filesystem_id); | 196 policy->GrantReadWriteFileSystem(renderer_id, filesystem_id); |
| 196 else | 197 else |
| 197 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 198 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 198 | 199 |
| 199 // We only need file level access for reading FileEntries. Saving FileEntries | 200 // We only need file level access for reading FileEntries. Saving FileEntries |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 432 |
| 432 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 433 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
| 433 error_ = kRequiresFileSystemWriteError; | 434 error_ = kRequiresFileSystemWriteError; |
| 434 return false; | 435 return false; |
| 435 } | 436 } |
| 436 | 437 |
| 437 return ShowPicker(suggested_name, picker_type, entry_type); | 438 return ShowPicker(suggested_name, picker_type, entry_type); |
| 438 } | 439 } |
| 439 | 440 |
| 440 } // namespace extensions | 441 } // namespace extensions |
| OLD | NEW |