| 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 "chrome/browser/extensions/shell_window_registry.h" | 10 #include "chrome/browser/extensions/shell_window_registry.h" |
| 11 #include "chrome/browser/platform_util.h" | 11 #include "chrome/browser/platform_util.h" |
| 12 #include "chrome/browser/ui/chrome_select_file_policy.h" | |
| 13 #include "chrome/browser/ui/extensions/shell_window.h" | 12 #include "chrome/browser/ui/extensions/shell_window.h" |
| 14 #include "chrome/common/extensions/api/file_system.h" | 13 #include "chrome/common/extensions/api/file_system.h" |
| 15 #include "chrome/common/extensions/permissions/api_permission.h" | 14 #include "chrome/common/extensions/permissions/api_permission.h" |
| 16 #include "content/public/browser/child_process_security_policy.h" | 15 #include "content/public/browser/child_process_security_policy.h" |
| 17 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 20 #include "webkit/fileapi/file_system_util.h" | 19 #include "webkit/fileapi/file_system_util.h" |
| 21 #include "webkit/fileapi/isolated_context.h" | 20 #include "webkit/fileapi/isolated_context.h" |
| 22 | 21 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 : public SelectFileDialog::Listener { | 198 : public SelectFileDialog::Listener { |
| 200 public: | 199 public: |
| 201 FilePicker(FileSystemChooseFileFunction* function, | 200 FilePicker(FileSystemChooseFileFunction* function, |
| 202 content::WebContents* web_contents, | 201 content::WebContents* web_contents, |
| 203 const FilePath& suggested_path, | 202 const FilePath& suggested_path, |
| 204 SelectFileDialog::Type picker_type, | 203 SelectFileDialog::Type picker_type, |
| 205 EntryType entry_type) | 204 EntryType entry_type) |
| 206 : suggested_path_(suggested_path), | 205 : suggested_path_(suggested_path), |
| 207 entry_type_(entry_type), | 206 entry_type_(entry_type), |
| 208 function_(function) { | 207 function_(function) { |
| 209 select_file_dialog_ = SelectFileDialog::Create( | 208 select_file_dialog_ = SelectFileDialog::Create(this); |
| 210 this, new ChromeSelectFilePolicy(web_contents)); | |
| 211 SelectFileDialog::FileTypeInfo file_type_info; | 209 SelectFileDialog::FileTypeInfo file_type_info; |
| 212 FilePath::StringType extension = suggested_path.Extension(); | 210 FilePath::StringType extension = suggested_path.Extension(); |
| 213 if (!extension.empty()) { | 211 if (!extension.empty()) { |
| 214 extension.erase(extension.begin()); // drop the . | 212 extension.erase(extension.begin()); // drop the . |
| 215 file_type_info.extensions.resize(1); | 213 file_type_info.extensions.resize(1); |
| 216 file_type_info.extensions[0].push_back(extension); | 214 file_type_info.extensions[0].push_back(extension); |
| 217 } | 215 } |
| 218 file_type_info.include_all_files = true; | 216 file_type_info.include_all_files = true; |
| 219 gfx::NativeWindow owning_window = web_contents ? | 217 gfx::NativeWindow owning_window = web_contents ? |
| 220 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; | 218 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 233 FileSelectionCanceled, | 231 FileSelectionCanceled, |
| 234 base::Unretained(this), static_cast<void*>(NULL))); | 232 base::Unretained(this), static_cast<void*>(NULL))); |
| 235 } | 233 } |
| 236 return; | 234 return; |
| 237 } | 235 } |
| 238 | 236 |
| 239 select_file_dialog_->SelectFile(picker_type, | 237 select_file_dialog_->SelectFile(picker_type, |
| 240 string16(), | 238 string16(), |
| 241 suggested_path, | 239 suggested_path, |
| 242 &file_type_info, 0, FILE_PATH_LITERAL(""), | 240 &file_type_info, 0, FILE_PATH_LITERAL(""), |
| 243 owning_window, NULL); | 241 web_contents, owning_window, NULL); |
| 244 } | 242 } |
| 245 | 243 |
| 246 virtual ~FilePicker() {} | 244 virtual ~FilePicker() {} |
| 247 | 245 |
| 248 private: | 246 private: |
| 249 // SelectFileDialog::Listener implementation. | 247 // SelectFileDialog::Listener implementation. |
| 250 virtual void FileSelected(const FilePath& path, | 248 virtual void FileSelected(const FilePath& path, |
| 251 int index, | 249 int index, |
| 252 void* params) OVERRIDE { | 250 void* params) OVERRIDE { |
| 253 function_->FileSelected(path, entry_type_); | 251 function_->FileSelected(path, entry_type_); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 346 |
| 349 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 347 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
| 350 error_ = kRequiresFileSystemWriteError; | 348 error_ = kRequiresFileSystemWriteError; |
| 351 return false; | 349 return false; |
| 352 } | 350 } |
| 353 | 351 |
| 354 return ShowPicker(FilePath(), picker_type, entry_type); | 352 return ShowPicker(FilePath(), picker_type, entry_type); |
| 355 } | 353 } |
| 356 | 354 |
| 357 } // namespace extensions | 355 } // namespace extensions |
| OLD | NEW |