| 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/path_service.h" | 11 #include "base/path_service.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/extensions/shell_window_registry.h" | 13 #include "chrome/browser/extensions/shell_window_registry.h" |
| 13 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
| 14 #include "chrome/browser/ui/chrome_select_file_policy.h" | 15 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 15 #include "chrome/browser/ui/extensions/shell_window.h" | 16 #include "chrome/browser/ui/extensions/shell_window.h" |
| 16 #include "chrome/common/extensions/api/file_system.h" | 17 #include "chrome/common/extensions/api/file_system.h" |
| 17 #include "chrome/common/extensions/permissions/api_permission.h" | 18 #include "chrome/common/extensions/permissions/api_permission.h" |
| 18 #include "content/public/browser/child_process_security_policy.h" | 19 #include "content/public/browser/child_process_security_policy.h" |
| 19 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 if (!GetFilePathOfFileEntry(filesystem_name, filesystem_path, | 230 if (!GetFilePathOfFileEntry(filesystem_name, filesystem_path, |
| 230 render_view_host_, &path, &error_)) | 231 render_view_host_, &path, &error_)) |
| 231 return false; | 232 return false; |
| 232 | 233 |
| 233 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 234 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
| 234 base::Bind(&FileSystemGetWritableFileEntryFunction::CheckWritableFile, | 235 base::Bind(&FileSystemGetWritableFileEntryFunction::CheckWritableFile, |
| 235 this, path)); | 236 this, path)); |
| 236 return true; | 237 return true; |
| 237 } | 238 } |
| 238 | 239 |
| 240 bool FileSystemIsWritableFileEntryFunction::RunImpl() { |
| 241 std::string filesystem_name; |
| 242 std::string filesystem_path; |
| 243 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
| 244 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
| 245 |
| 246 std::string filesystem_id; |
| 247 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { |
| 248 error_ = kInvalidParameters; |
| 249 return false; |
| 250 } |
| 251 |
| 252 content::ChildProcessSecurityPolicy* policy = |
| 253 content::ChildProcessSecurityPolicy::GetInstance(); |
| 254 int renderer_id = render_view_host_->GetProcess()->GetID(); |
| 255 bool is_writable = policy->CanReadWriteFileSystem(renderer_id, |
| 256 filesystem_id); |
| 257 |
| 258 SetResult(base::Value::CreateBooleanValue(is_writable)); |
| 259 return true; |
| 260 } |
| 261 |
| 239 // Handles showing a dialog to the user to ask for the filename for a file to | 262 // Handles showing a dialog to the user to ask for the filename for a file to |
| 240 // save or open. | 263 // save or open. |
| 241 class FileSystemChooseFileFunction::FilePicker | 264 class FileSystemChooseFileFunction::FilePicker |
| 242 : public SelectFileDialog::Listener { | 265 : public SelectFileDialog::Listener { |
| 243 public: | 266 public: |
| 244 FilePicker(FileSystemChooseFileFunction* function, | 267 FilePicker(FileSystemChooseFileFunction* function, |
| 245 content::WebContents* web_contents, | 268 content::WebContents* web_contents, |
| 246 const FilePath& suggested_name, | 269 const FilePath& suggested_name, |
| 247 SelectFileDialog::Type picker_type, | 270 SelectFileDialog::Type picker_type, |
| 248 EntryType entry_type) | 271 EntryType entry_type) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 | 431 |
| 409 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 432 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
| 410 error_ = kRequiresFileSystemWriteError; | 433 error_ = kRequiresFileSystemWriteError; |
| 411 return false; | 434 return false; |
| 412 } | 435 } |
| 413 | 436 |
| 414 return ShowPicker(suggested_name, picker_type, entry_type); | 437 return ShowPicker(suggested_name, picker_type, entry_type); |
| 415 } | 438 } |
| 416 | 439 |
| 417 } // namespace extensions | 440 } // namespace extensions |
| OLD | NEW |