| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 175 |
| 175 void FileSystemEntryFunction::RegisterFileSystemAndSendResponse( | 176 void FileSystemEntryFunction::RegisterFileSystemAndSendResponse( |
| 176 const FilePath& path, EntryType entry_type) { | 177 const FilePath& path, EntryType entry_type) { |
| 177 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 178 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 178 | 179 |
| 179 fileapi::IsolatedContext* isolated_context = | 180 fileapi::IsolatedContext* isolated_context = |
| 180 fileapi::IsolatedContext::GetInstance(); | 181 fileapi::IsolatedContext::GetInstance(); |
| 181 DCHECK(isolated_context); | 182 DCHECK(isolated_context); |
| 182 | 183 |
| 183 std::string registered_name; | 184 std::string registered_name; |
| 184 std::string filesystem_id = isolated_context->RegisterFileSystemForFile( | 185 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
| 185 path, ®istered_name); | 186 fileapi::kFileSystemTypeIsolated, path, ®istered_name); |
| 186 | 187 |
| 187 content::ChildProcessSecurityPolicy* policy = | 188 content::ChildProcessSecurityPolicy* policy = |
| 188 content::ChildProcessSecurityPolicy::GetInstance(); | 189 content::ChildProcessSecurityPolicy::GetInstance(); |
| 189 int renderer_id = render_view_host_->GetProcess()->GetID(); | 190 int renderer_id = render_view_host_->GetProcess()->GetID(); |
| 190 if (entry_type == WRITABLE) | 191 if (entry_type == WRITABLE) |
| 191 policy->GrantReadWriteFileSystem(renderer_id, filesystem_id); | 192 policy->GrantReadWriteFileSystem(renderer_id, filesystem_id); |
| 192 else | 193 else |
| 193 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 194 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 194 | 195 |
| 195 // We only need file level access for reading FileEntries. Saving FileEntries | 196 // We only need file level access for reading FileEntries. Saving FileEntries |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 428 |
| 428 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 429 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
| 429 error_ = kRequiresFileSystemWriteError; | 430 error_ = kRequiresFileSystemWriteError; |
| 430 return false; | 431 return false; |
| 431 } | 432 } |
| 432 | 433 |
| 433 return ShowPicker(suggested_name, picker_type, entry_type); | 434 return ShowPicker(suggested_name, picker_type, entry_type); |
| 434 } | 435 } |
| 435 | 436 |
| 436 } // namespace extensions | 437 } // namespace extensions |
| OLD | NEW |