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" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 bool is_writable = policy->CanReadWriteFileSystem(renderer_id, | 252 bool is_writable = policy->CanReadWriteFileSystem(renderer_id, |
253 filesystem_id); | 253 filesystem_id); |
254 | 254 |
255 SetResult(base::Value::CreateBooleanValue(is_writable)); | 255 SetResult(base::Value::CreateBooleanValue(is_writable)); |
256 return true; | 256 return true; |
257 } | 257 } |
258 | 258 |
259 // Handles showing a dialog to the user to ask for the filename for a file to | 259 // Handles showing a dialog to the user to ask for the filename for a file to |
260 // save or open. | 260 // save or open. |
261 class FileSystemChooseFileFunction::FilePicker | 261 class FileSystemChooseFileFunction::FilePicker |
262 : public SelectFileDialog::Listener { | 262 : public ui::SelectFileDialog::Listener { |
263 public: | 263 public: |
264 FilePicker(FileSystemChooseFileFunction* function, | 264 FilePicker(FileSystemChooseFileFunction* function, |
265 content::WebContents* web_contents, | 265 content::WebContents* web_contents, |
266 const FilePath& suggested_name, | 266 const FilePath& suggested_name, |
267 SelectFileDialog::Type picker_type, | 267 ui::SelectFileDialog::Type picker_type, |
268 EntryType entry_type) | 268 EntryType entry_type) |
269 : suggested_name_(suggested_name), | 269 : suggested_name_(suggested_name), |
270 entry_type_(entry_type), | 270 entry_type_(entry_type), |
271 function_(function) { | 271 function_(function) { |
272 select_file_dialog_ = SelectFileDialog::Create( | 272 select_file_dialog_ = ui::SelectFileDialog::Create( |
273 this, new ChromeSelectFilePolicy(web_contents)); | 273 this, new ChromeSelectFilePolicy(web_contents)); |
274 SelectFileDialog::FileTypeInfo file_type_info; | 274 ui::SelectFileDialog::FileTypeInfo file_type_info; |
275 FilePath::StringType extension = suggested_name.Extension(); | 275 FilePath::StringType extension = suggested_name.Extension(); |
276 if (!extension.empty()) { | 276 if (!extension.empty()) { |
277 extension.erase(extension.begin()); // drop the . | 277 extension.erase(extension.begin()); // drop the . |
278 file_type_info.extensions.resize(1); | 278 file_type_info.extensions.resize(1); |
279 file_type_info.extensions[0].push_back(extension); | 279 file_type_info.extensions[0].push_back(extension); |
280 } | 280 } |
281 file_type_info.include_all_files = true; | 281 file_type_info.include_all_files = true; |
282 gfx::NativeWindow owning_window = web_contents ? | 282 gfx::NativeWindow owning_window = web_contents ? |
283 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; | 283 platform_util::GetTopLevel(web_contents->GetNativeView()) : NULL; |
284 | 284 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 319 |
320 virtual void FileSelectionCanceled(void* params) OVERRIDE { | 320 virtual void FileSelectionCanceled(void* params) OVERRIDE { |
321 function_->FileSelectionCanceled(); | 321 function_->FileSelectionCanceled(); |
322 delete this; | 322 delete this; |
323 } | 323 } |
324 | 324 |
325 FilePath suggested_name_; | 325 FilePath suggested_name_; |
326 | 326 |
327 EntryType entry_type_; | 327 EntryType entry_type_; |
328 | 328 |
329 scoped_refptr<SelectFileDialog> select_file_dialog_; | 329 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
330 scoped_refptr<FileSystemChooseFileFunction> function_; | 330 scoped_refptr<FileSystemChooseFileFunction> function_; |
331 | 331 |
332 DISALLOW_COPY_AND_ASSIGN(FilePicker); | 332 DISALLOW_COPY_AND_ASSIGN(FilePicker); |
333 }; | 333 }; |
334 | 334 |
335 bool FileSystemChooseFileFunction::ShowPicker( | 335 bool FileSystemChooseFileFunction::ShowPicker( |
336 const FilePath& suggested_name, | 336 const FilePath& suggested_name, |
337 SelectFileDialog::Type picker_type, | 337 ui::SelectFileDialog::Type picker_type, |
338 EntryType entry_type) { | 338 EntryType entry_type) { |
339 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | 339 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
340 DCHECK(registry); | 340 DCHECK(registry); |
341 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 341 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( |
342 render_view_host()); | 342 render_view_host()); |
343 if (!shell_window) { | 343 if (!shell_window) { |
344 error_ = kInvalidCallingPage; | 344 error_ = kInvalidCallingPage; |
345 return false; | 345 return false; |
346 } | 346 } |
347 | 347 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 error_ = kUserCancelled; | 389 error_ = kUserCancelled; |
390 SendResponse(false); | 390 SendResponse(false); |
391 } | 391 } |
392 | 392 |
393 bool FileSystemChooseFileFunction::RunImpl() { | 393 bool FileSystemChooseFileFunction::RunImpl() { |
394 scoped_ptr<ChooseFile::Params> params(ChooseFile::Params::Create(*args_)); | 394 scoped_ptr<ChooseFile::Params> params(ChooseFile::Params::Create(*args_)); |
395 EXTENSION_FUNCTION_VALIDATE(params.get()); | 395 EXTENSION_FUNCTION_VALIDATE(params.get()); |
396 | 396 |
397 FilePath suggested_name; | 397 FilePath suggested_name; |
398 EntryType entry_type = READ_ONLY; | 398 EntryType entry_type = READ_ONLY; |
399 SelectFileDialog::Type picker_type = SelectFileDialog::SELECT_OPEN_FILE; | 399 ui::SelectFileDialog::Type picker_type = |
| 400 ui::SelectFileDialog::SELECT_OPEN_FILE; |
400 | 401 |
401 file_system::ChooseFileOptions* options = params->options.get(); | 402 file_system::ChooseFileOptions* options = params->options.get(); |
402 if (options) { | 403 if (options) { |
403 if (options->type.get()) { | 404 if (options->type.get()) { |
404 if (*options->type == kOpenWritableFileOption) { | 405 if (*options->type == kOpenWritableFileOption) { |
405 entry_type = WRITABLE; | 406 entry_type = WRITABLE; |
406 } else if (*options->type == kSaveFileOption) { | 407 } else if (*options->type == kSaveFileOption) { |
407 entry_type = WRITABLE; | 408 entry_type = WRITABLE; |
408 picker_type = SelectFileDialog::SELECT_SAVEAS_FILE; | 409 picker_type = ui::SelectFileDialog::SELECT_SAVEAS_FILE; |
409 } else if (*options->type != kOpenFileOption) { | 410 } else if (*options->type != kOpenFileOption) { |
410 error_ = kUnknownChooseFileType; | 411 error_ = kUnknownChooseFileType; |
411 return false; | 412 return false; |
412 } | 413 } |
413 } | 414 } |
414 | 415 |
415 if (options->suggested_name.get()) { | 416 if (options->suggested_name.get()) { |
416 suggested_name = FilePath::FromUTF8Unsafe( | 417 suggested_name = FilePath::FromUTF8Unsafe( |
417 *options->suggested_name.get()); | 418 *options->suggested_name.get()); |
418 | 419 |
419 // Don't allow any path components; shorten to the base name. This should | 420 // Don't allow any path components; shorten to the base name. This should |
420 // result in a relative path, but in some cases may not. Clear the | 421 // result in a relative path, but in some cases may not. Clear the |
421 // suggestion for safety if this is the case. | 422 // suggestion for safety if this is the case. |
422 suggested_name = suggested_name.BaseName(); | 423 suggested_name = suggested_name.BaseName(); |
423 if (suggested_name.IsAbsolute()) { | 424 if (suggested_name.IsAbsolute()) { |
424 suggested_name = FilePath(); | 425 suggested_name = FilePath(); |
425 } | 426 } |
426 } | 427 } |
427 } | 428 } |
428 | 429 |
429 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 430 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
430 error_ = kRequiresFileSystemWriteError; | 431 error_ = kRequiresFileSystemWriteError; |
431 return false; | 432 return false; |
432 } | 433 } |
433 | 434 |
434 return ShowPicker(suggested_name, picker_type, entry_type); | 435 return ShowPicker(suggested_name, picker_type, entry_type); |
435 } | 436 } |
436 | 437 |
437 } // namespace extensions | 438 } // namespace extensions |
OLD | NEW |