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_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/common/extensions/permissions/api_permission.h" | 21 #include "chrome/common/extensions/permissions/api_permission.h" |
22 #include "content/public/browser/child_process_security_policy.h" | 22 #include "content/public/browser/child_process_security_policy.h" |
23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_view.h" | 26 #include "content/public/browser/web_contents_view.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "net/base/mime_util.h" | 28 #include "net/base/mime_util.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/shell_dialogs/select_file_dialog.h" | 30 #include "ui/shell_dialogs/select_file_dialog.h" |
| 31 #include "ui/shell_dialogs/selected_file_info.h" |
| 32 #include "webkit/fileapi/external_mount_points.h" |
31 #include "webkit/fileapi/file_system_types.h" | 33 #include "webkit/fileapi/file_system_types.h" |
32 #include "webkit/fileapi/file_system_util.h" | 34 #include "webkit/fileapi/file_system_util.h" |
33 #include "webkit/fileapi/isolated_context.h" | 35 #include "webkit/fileapi/isolated_context.h" |
34 | 36 |
35 #if defined(OS_MACOSX) | 37 #if defined(OS_MACOSX) |
36 #include <CoreFoundation/CoreFoundation.h> | 38 #include <CoreFoundation/CoreFoundation.h> |
37 #include "base/mac/foundation_util.h" | 39 #include "base/mac/foundation_util.h" |
38 #endif | 40 #endif |
39 | 41 |
40 using fileapi::IsolatedContext; | 42 using fileapi::IsolatedContext; |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 entry_type_(entry_type), | 384 entry_type_(entry_type), |
383 function_(function) { | 385 function_(function) { |
384 select_file_dialog_ = ui::SelectFileDialog::Create( | 386 select_file_dialog_ = ui::SelectFileDialog::Create( |
385 this, new ChromeSelectFilePolicy(web_contents)); | 387 this, new ChromeSelectFilePolicy(web_contents)); |
386 gfx::NativeWindow owning_window = web_contents ? | 388 gfx::NativeWindow owning_window = web_contents ? |
387 platform_util::GetTopLevel(web_contents->GetView()->GetNativeView()) : | 389 platform_util::GetTopLevel(web_contents->GetView()->GetNativeView()) : |
388 NULL; | 390 NULL; |
389 | 391 |
390 if (g_skip_picker_for_test) { | 392 if (g_skip_picker_for_test) { |
391 if (g_path_to_be_picked_for_test) { | 393 if (g_path_to_be_picked_for_test) { |
| 394 ui::SelectedFileInfo selected_path(*g_path_to_be_picked_for_test, |
| 395 base::FilePath()); |
392 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 396 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
393 base::Bind( | 397 base::Bind( |
394 &FileSystemChooseEntryFunction::FilePicker::FileSelected, | 398 &FileSystemChooseEntryFunction::FilePicker:: |
395 base::Unretained(this), *g_path_to_be_picked_for_test, 1, | 399 FileSelectedWithExtraInfo, |
| 400 base::Unretained(this), selected_path, 1, |
396 static_cast<void*>(NULL))); | 401 static_cast<void*>(NULL))); |
397 } else { | 402 } else { |
398 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 403 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
399 base::Bind( | 404 base::Bind( |
400 &FileSystemChooseEntryFunction::FilePicker:: | 405 &FileSystemChooseEntryFunction::FilePicker:: |
401 FileSelectionCanceled, | 406 FileSelectionCanceled, |
402 base::Unretained(this), static_cast<void*>(NULL))); | 407 base::Unretained(this), static_cast<void*>(NULL))); |
403 } | 408 } |
404 return; | 409 return; |
405 } | 410 } |
406 | 411 |
407 select_file_dialog_->SelectFile(picker_type, | 412 select_file_dialog_->SelectFile(picker_type, |
408 string16(), | 413 string16(), |
409 suggested_name, | 414 suggested_name, |
410 &file_type_info, 0, FILE_PATH_LITERAL(""), | 415 &file_type_info, 0, FILE_PATH_LITERAL(""), |
411 owning_window, NULL); | 416 owning_window, NULL); |
412 } | 417 } |
413 | 418 |
414 virtual ~FilePicker() {} | 419 virtual ~FilePicker() {} |
415 | 420 |
416 private: | 421 private: |
417 // ui::SelectFileDialog::Listener implementation. | 422 // ui::SelectFileDialog::Listener implementation. |
418 virtual void FileSelected(const base::FilePath& path, | 423 virtual void FileSelected(const base::FilePath& path, |
419 int index, | 424 int index, |
420 void* params) OVERRIDE { | 425 void* params) OVERRIDE { |
421 function_->FileSelected(path, entry_type_); | 426 // The version taking ui::SelectedFileInfo should be used. |
| 427 NOTREACHED(); |
| 428 } |
| 429 |
| 430 virtual void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file, |
| 431 int index, |
| 432 void* params) OVERRIDE { |
| 433 // Normally, file.local_path is used because it is a native path to the |
| 434 // local read-only cached file in the case of remote file system like |
| 435 // Chrome OS's Google Drive integration. Here, however, |file.file_path| is |
| 436 // necessary because we need to create a FileEntry denoting the remote file, |
| 437 // not its cache. On other platforms than Chrome OS, they are the same. |
| 438 // |
| 439 // TODO(kinaba): remove this, once after the file picker implements proper |
| 440 // switch of the path treatment depending on the |support_drive| flag. |
| 441 function_->FileSelected(file.file_path, entry_type_); |
422 delete this; | 442 delete this; |
423 } | 443 } |
424 | 444 |
425 virtual void FileSelectionCanceled(void* params) OVERRIDE { | 445 virtual void FileSelectionCanceled(void* params) OVERRIDE { |
426 function_->FileSelectionCanceled(); | 446 function_->FileSelectionCanceled(); |
427 delete this; | 447 delete this; |
428 } | 448 } |
429 | 449 |
430 base::FilePath suggested_name_; | 450 base::FilePath suggested_name_; |
431 | 451 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 void FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest() { | 491 void FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest() { |
472 g_skip_picker_for_test = true; | 492 g_skip_picker_for_test = true; |
473 g_path_to_be_picked_for_test = NULL; | 493 g_path_to_be_picked_for_test = NULL; |
474 } | 494 } |
475 | 495 |
476 // static | 496 // static |
477 void FileSystemChooseEntryFunction::StopSkippingPickerForTest() { | 497 void FileSystemChooseEntryFunction::StopSkippingPickerForTest() { |
478 g_skip_picker_for_test = false; | 498 g_skip_picker_for_test = false; |
479 } | 499 } |
480 | 500 |
| 501 // static |
| 502 void FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( |
| 503 const std::string& name, const base::FilePath& path) { |
| 504 // For testing on Chrome OS, where to deal with remote and local paths |
| 505 // smoothly, all accessed paths need to be registered in the list of |
| 506 // external mount points. |
| 507 fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
| 508 name, fileapi::kFileSystemTypeNativeLocal, path); |
| 509 } |
| 510 |
481 void FileSystemChooseEntryFunction::FileSelected(const base::FilePath& path, | 511 void FileSystemChooseEntryFunction::FileSelected(const base::FilePath& path, |
482 EntryType entry_type) { | 512 EntryType entry_type) { |
483 if (entry_type == WRITABLE) { | 513 if (entry_type == WRITABLE) { |
484 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 514 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
485 base::Bind(&FileSystemChooseEntryFunction::CheckWritableFile, | 515 base::Bind(&FileSystemChooseEntryFunction::CheckWritableFile, |
486 this, path)); | 516 this, path)); |
487 return; | 517 return; |
488 } | 518 } |
489 | 519 |
490 // Don't need to check the file, it's for reading. | 520 // Don't need to check the file, it's for reading. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 616 |
587 BuildFileTypeInfo(&file_type_info, suggested_extension, | 617 BuildFileTypeInfo(&file_type_info, suggested_extension, |
588 options->accepts.get(), options->accepts_all_types.get()); | 618 options->accepts.get(), options->accepts_all_types.get()); |
589 } | 619 } |
590 | 620 |
591 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 621 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
592 error_ = kRequiresFileSystemWriteError; | 622 error_ = kRequiresFileSystemWriteError; |
593 return false; | 623 return false; |
594 } | 624 } |
595 | 625 |
| 626 if (entry_type != WRITABLE) |
| 627 file_type_info.support_drive = true; |
| 628 |
596 return ShowPicker(suggested_name, file_type_info, picker_type, entry_type); | 629 return ShowPicker(suggested_name, file_type_info, picker_type, entry_type); |
597 } | 630 } |
598 | 631 |
599 } // namespace extensions | 632 } // namespace extensions |
OLD | NEW |