| 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 "apps/app_window.h" |
| 8 #include "apps/app_window_registry.h" |
| 7 #include "apps/saved_files_service.h" | 9 #include "apps/saved_files_service.h" |
| 8 #include "apps/shell_window.h" | |
| 9 #include "apps/shell_window_registry.h" | |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/value_conversions.h" | 19 #include "base/value_conversions.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 48 #include <CoreFoundation/CoreFoundation.h> | 48 #include <CoreFoundation/CoreFoundation.h> |
| 49 #include "base/mac/foundation_util.h" | 49 #include "base/mac/foundation_util.h" |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
| 53 #include "chrome/browser/chromeos/drive/file_system_util.h" | 53 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 54 #endif | 54 #endif |
| 55 | 55 |
| 56 using apps::SavedFileEntry; | 56 using apps::SavedFileEntry; |
| 57 using apps::SavedFilesService; | 57 using apps::SavedFilesService; |
| 58 using apps::ShellWindow; | 58 using apps::AppWindow; |
| 59 using fileapi::IsolatedContext; | 59 using fileapi::IsolatedContext; |
| 60 | 60 |
| 61 const char kInvalidCallingPage[] = "Invalid calling page. This function can't " | 61 const char kInvalidCallingPage[] = "Invalid calling page. This function can't " |
| 62 "be called from a background page."; | 62 "be called from a background page."; |
| 63 const char kUserCancelled[] = "User cancelled"; | 63 const char kUserCancelled[] = "User cancelled"; |
| 64 const char kWritableFileErrorFormat[] = "Error opening %s"; | 64 const char kWritableFileErrorFormat[] = "Error opening %s"; |
| 65 const char kRequiresFileSystemWriteError[] = | 65 const char kRequiresFileSystemWriteError[] = |
| 66 "Operation requires fileSystem.write permission"; | 66 "Operation requires fileSystem.write permission"; |
| 67 const char kRequiresFileSystemDirectoryError[] = | 67 const char kRequiresFileSystemDirectoryError[] = |
| 68 "Operation requires fileSystem.directory permission"; | 68 "Operation requires fileSystem.directory permission"; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 void FileSystemChooseEntryFunction::ShowPicker( | 539 void FileSystemChooseEntryFunction::ShowPicker( |
| 540 const ui::SelectFileDialog::FileTypeInfo& file_type_info, | 540 const ui::SelectFileDialog::FileTypeInfo& file_type_info, |
| 541 ui::SelectFileDialog::Type picker_type) { | 541 ui::SelectFileDialog::Type picker_type) { |
| 542 // TODO(asargent/benwells) - As a short term remediation for crbug.com/179010 | 542 // TODO(asargent/benwells) - As a short term remediation for crbug.com/179010 |
| 543 // we're adding the ability for a whitelisted extension to use this API since | 543 // we're adding the ability for a whitelisted extension to use this API since |
| 544 // chrome.fileBrowserHandler.selectFile is ChromeOS-only. Eventually we'd | 544 // chrome.fileBrowserHandler.selectFile is ChromeOS-only. Eventually we'd |
| 545 // like a better solution and likely this code will go back to being | 545 // like a better solution and likely this code will go back to being |
| 546 // platform-app only. | 546 // platform-app only. |
| 547 content::WebContents* web_contents = NULL; | 547 content::WebContents* web_contents = NULL; |
| 548 if (extension_->is_platform_app()) { | 548 if (extension_->is_platform_app()) { |
| 549 apps::ShellWindowRegistry* registry = | 549 apps::AppWindowRegistry* registry = |
| 550 apps::ShellWindowRegistry::Get(GetProfile()); | 550 apps::AppWindowRegistry::Get(GetProfile()); |
| 551 DCHECK(registry); | 551 DCHECK(registry); |
| 552 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 552 AppWindow* app_window = |
| 553 render_view_host()); | 553 registry->GetAppWindowForRenderViewHost(render_view_host()); |
| 554 if (!shell_window) { | 554 if (!app_window) { |
| 555 error_ = kInvalidCallingPage; | 555 error_ = kInvalidCallingPage; |
| 556 SendResponse(false); | 556 SendResponse(false); |
| 557 return; | 557 return; |
| 558 } | 558 } |
| 559 web_contents = shell_window->web_contents(); | 559 web_contents = app_window->web_contents(); |
| 560 } else { | 560 } else { |
| 561 web_contents = GetAssociatedWebContents(); | 561 web_contents = GetAssociatedWebContents(); |
| 562 } | 562 } |
| 563 // The file picker will hold a reference to this function instance, preventing | 563 // The file picker will hold a reference to this function instance, preventing |
| 564 // its destruction (and subsequent sending of the function response) until the | 564 // its destruction (and subsequent sending of the function response) until the |
| 565 // user has selected a file or cancelled the picker. At that point, the picker | 565 // user has selected a file or cancelled the picker. At that point, the picker |
| 566 // will delete itself, which will also free the function instance. | 566 // will delete itself, which will also free the function instance. |
| 567 new FilePicker( | 567 new FilePicker( |
| 568 this, web_contents, initial_path_, file_type_info, picker_type); | 568 this, web_contents, initial_path_, file_type_info, picker_type); |
| 569 } | 569 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } else { | 660 } else { |
| 661 last_choose_directory = paths[0].DirName(); | 661 last_choose_directory = paths[0].DirName(); |
| 662 } | 662 } |
| 663 file_system_api::SetLastChooseEntryDirectory( | 663 file_system_api::SetLastChooseEntryDirectory( |
| 664 ExtensionPrefs::Get(GetProfile()), | 664 ExtensionPrefs::Get(GetProfile()), |
| 665 GetExtension()->id(), | 665 GetExtension()->id(), |
| 666 last_choose_directory); | 666 last_choose_directory); |
| 667 if (is_directory_) { | 667 if (is_directory_) { |
| 668 // Get the WebContents for the app window to be the parent window of the | 668 // Get the WebContents for the app window to be the parent window of the |
| 669 // confirmation dialog if necessary. | 669 // confirmation dialog if necessary. |
| 670 apps::ShellWindowRegistry* registry = | 670 apps::AppWindowRegistry* registry = |
| 671 apps::ShellWindowRegistry::Get(GetProfile()); | 671 apps::AppWindowRegistry::Get(GetProfile()); |
| 672 DCHECK(registry); | 672 DCHECK(registry); |
| 673 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 673 AppWindow* app_window = |
| 674 render_view_host()); | 674 registry->GetAppWindowForRenderViewHost(render_view_host()); |
| 675 if (!shell_window) { | 675 if (!app_window) { |
| 676 error_ = kInvalidCallingPage; | 676 error_ = kInvalidCallingPage; |
| 677 SendResponse(false); | 677 SendResponse(false); |
| 678 return; | 678 return; |
| 679 } | 679 } |
| 680 content::WebContents* web_contents = shell_window->web_contents(); | 680 content::WebContents* web_contents = app_window->web_contents(); |
| 681 | 681 |
| 682 content::BrowserThread::PostTask( | 682 content::BrowserThread::PostTask( |
| 683 content::BrowserThread::FILE, | 683 content::BrowserThread::FILE, |
| 684 FROM_HERE, | 684 FROM_HERE, |
| 685 base::Bind( | 685 base::Bind( |
| 686 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, | 686 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, |
| 687 this, | 687 this, |
| 688 paths, | 688 paths, |
| 689 web_contents)); | 689 web_contents)); |
| 690 return; | 690 return; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 if (needs_new_entry) { | 976 if (needs_new_entry) { |
| 977 is_directory_ = file_entry->is_directory; | 977 is_directory_ = file_entry->is_directory; |
| 978 CreateResponse(); | 978 CreateResponse(); |
| 979 AddEntryToResponse(file_entry->path, file_entry->id); | 979 AddEntryToResponse(file_entry->path, file_entry->id); |
| 980 } | 980 } |
| 981 SendResponse(true); | 981 SendResponse(true); |
| 982 return true; | 982 return true; |
| 983 } | 983 } |
| 984 | 984 |
| 985 } // namespace extensions | 985 } // namespace extensions |
| OLD | NEW |