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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 scoped_refptr<FileSystemChooseEntryFunction> function_; | 478 scoped_refptr<FileSystemChooseEntryFunction> function_; |
479 | 479 |
480 DISALLOW_COPY_AND_ASSIGN(FilePicker); | 480 DISALLOW_COPY_AND_ASSIGN(FilePicker); |
481 }; | 481 }; |
482 | 482 |
483 bool FileSystemChooseEntryFunction::ShowPicker( | 483 bool FileSystemChooseEntryFunction::ShowPicker( |
484 const base::FilePath& suggested_name, | 484 const base::FilePath& suggested_name, |
485 const ui::SelectFileDialog::FileTypeInfo& file_type_info, | 485 const ui::SelectFileDialog::FileTypeInfo& file_type_info, |
486 ui::SelectFileDialog::Type picker_type, | 486 ui::SelectFileDialog::Type picker_type, |
487 EntryType entry_type) { | 487 EntryType entry_type) { |
488 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | 488 // TODO(asargent/benwells) - As a short term remediation for crbug.com/179010 |
489 DCHECK(registry); | 489 // we're adding the ability for a whitelisted extension to use this API since |
490 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 490 // chrome.fileBrowserHandler.selectFile is ChromeOS-only. Eventually we'd |
491 render_view_host()); | 491 // like a better solution and likely this code will go back to being |
492 if (!shell_window) { | 492 // platform-app only. |
493 error_ = kInvalidCallingPage; | 493 content::WebContents* web_contents = NULL; |
494 return false; | 494 if (extension_->is_platform_app()) { |
| 495 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
| 496 DCHECK(registry); |
| 497 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( |
| 498 render_view_host()); |
| 499 if (!shell_window) { |
| 500 error_ = kInvalidCallingPage; |
| 501 return false; |
| 502 } |
| 503 web_contents = shell_window->web_contents(); |
| 504 } else { |
| 505 web_contents = GetAssociatedWebContents(); |
495 } | 506 } |
496 | |
497 // The file picker will hold a reference to this function instance, preventing | 507 // The file picker will hold a reference to this function instance, preventing |
498 // its destruction (and subsequent sending of the function response) until the | 508 // its destruction (and subsequent sending of the function response) until the |
499 // user has selected a file or cancelled the picker. At that point, the picker | 509 // user has selected a file or cancelled the picker. At that point, the picker |
500 // will delete itself, which will also free the function instance. | 510 // will delete itself, which will also free the function instance. |
501 new FilePicker(this, shell_window->web_contents(), suggested_name, | 511 new FilePicker(this, web_contents, suggested_name, file_type_info, |
502 file_type_info, picker_type, entry_type); | 512 picker_type, entry_type); |
503 return true; | 513 return true; |
504 } | 514 } |
505 | 515 |
506 // static | 516 // static |
507 void FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 517 void FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
508 base::FilePath* path) { | 518 base::FilePath* path) { |
509 g_skip_picker_for_test = true; | 519 g_skip_picker_for_test = true; |
510 g_path_to_be_picked_for_test = path; | 520 g_path_to_be_picked_for_test = path; |
511 } | 521 } |
512 | 522 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 652 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
643 error_ = kRequiresFileSystemWriteError; | 653 error_ = kRequiresFileSystemWriteError; |
644 return false; | 654 return false; |
645 } | 655 } |
646 | 656 |
647 file_type_info.support_drive = true; | 657 file_type_info.support_drive = true; |
648 return ShowPicker(suggested_name, file_type_info, picker_type, entry_type); | 658 return ShowPicker(suggested_name, file_type_info, picker_type, entry_type); |
649 } | 659 } |
650 | 660 |
651 } // namespace extensions | 661 } // namespace extensions |
OLD | NEW |