| 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 8 #include "base/callback.h" |
| 9 #include "ui/shell_dialogs/select_file_dialog.h" | 9 #include "ui/shell_dialogs/select_file_dialog.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 class FilePath; | 12 class FilePath; |
| 13 } | 13 } |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 class DownloadItem; | 16 class DownloadItem; |
| 17 class DownloadManager; | 17 class DownloadManager; |
| 18 class WebContents; | 18 class WebContents; |
| 19 } | 19 } |
| 20 | 20 |
| 21 // Handles showing a dialog to the user to ask for the filename for a download. | 21 // Handles showing a dialog to the user to ask for the filename for a download. |
| 22 class DownloadFilePicker : public ui::SelectFileDialog::Listener { | 22 class DownloadFilePicker : public ui::SelectFileDialog::Listener { |
| 23 public: | 23 public: |
| 24 DownloadFilePicker(); | 24 // Callback used to pass the user selection back to the owner of this |
| 25 // object. If the user selection is successful, the arguments will be as |
| 26 // follows: |
| 27 // |virtual_path|: The opaque path representing the virtual target chosen by |
| 28 // the user. If the target is local file system, then this will be same as |
| 29 // |local_path|. |
| 30 // |local_path|: The path on the local file system to use for storing the |
| 31 // downloaded file. |
| 32 // |
| 33 // If the path selection is successful, both paths will be non-empty and |
| 34 // valid. Otherwise, if the user cancels the selection, both paths will be |
| 35 // empty. |
| 36 typedef base::Callback<void( |
| 37 const base::FilePath& virtual_path, |
| 38 const base::FilePath& local_path)> FileSelectedCallback; |
| 39 |
| 40 DownloadFilePicker(content::DownloadItem* item, |
| 41 const base::FilePath& suggested_path, |
| 42 const FileSelectedCallback& callback); |
| 25 virtual ~DownloadFilePicker(); | 43 virtual ~DownloadFilePicker(); |
| 26 | 44 |
| 27 void Init(content::DownloadManager* download_manager, | |
| 28 content::DownloadItem* item, | |
| 29 const base::FilePath& suggested_path, | |
| 30 const ChromeDownloadManagerDelegate::FileSelectedCallback& | |
| 31 callback); | |
| 32 | |
| 33 protected: | |
| 34 // On ChromeOS |suggested_path| might be a temporary local filename. This | 45 // On ChromeOS |suggested_path| might be a temporary local filename. This |
| 35 // method should be overridden to set the correct suggested path to prompt the | 46 // method should be overridden to set the correct suggested path to prompt the |
| 36 // user. | 47 // user. |
| 37 virtual void InitSuggestedPath(content::DownloadItem* item, | 48 virtual void InitSuggestedPath(content::DownloadItem* item, |
| 38 const base::FilePath& suggested_path); | 49 const base::FilePath& suggested_path); |
| 39 | 50 |
| 40 void set_suggested_path(const base::FilePath& suggested_path) { | 51 void set_suggested_path(const base::FilePath& suggested_path) { |
| 41 suggested_path_ = suggested_path; | 52 suggested_path_ = suggested_path; |
| 42 } | 53 } |
| 43 | 54 |
| 44 // Runs |file_selected_callback_| with |path| and then deletes this object. | 55 // Runs |file_selected_callback_| with |virtual_path| and |local_path| and |
| 45 void OnFileSelected(const base::FilePath& path); | 56 // then deletes this object. |
| 57 void OnFileSelected(const base::FilePath& virtual_path, |
| 58 const base::FilePath& local_path); |
| 46 | 59 |
| 47 void RecordFileSelected(const base::FilePath& path); | 60 void RecordFileSelected(const base::FilePath& path); |
| 48 | 61 |
| 49 scoped_refptr<content::DownloadManager> download_manager_; | 62 scoped_refptr<content::DownloadManager> download_manager_; |
| 50 int32 download_id_; | 63 int32 download_id_; |
| 51 | 64 |
| 52 private: | 65 private: |
| 53 // SelectFileDialog::Listener implementation. | 66 // SelectFileDialog::Listener implementation. |
| 54 virtual void FileSelected(const base::FilePath& path, | 67 virtual void FileSelected(const base::FilePath& path, |
| 55 int index, | 68 int index, |
| 56 void* params) OVERRIDE; | 69 void* params) OVERRIDE; |
| 57 virtual void FileSelectionCanceled(void* params) OVERRIDE; | 70 virtual void FileSelectionCanceled(void* params) OVERRIDE; |
| 58 | 71 |
| 59 base::FilePath suggested_path_; | 72 base::FilePath suggested_path_; |
| 60 | 73 |
| 61 ChromeDownloadManagerDelegate::FileSelectedCallback file_selected_callback_; | 74 FileSelectedCallback file_selected_callback_; |
| 62 | 75 |
| 63 // For managing select file dialogs. | 76 // For managing select file dialogs. |
| 64 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | 77 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
| 65 | 78 |
| 66 DISALLOW_COPY_AND_ASSIGN(DownloadFilePicker); | 79 DISALLOW_COPY_AND_ASSIGN(DownloadFilePicker); |
| 67 }; | 80 }; |
| 68 | 81 |
| 82 class DownloadFilePickerFactory { |
| 83 public: |
| 84 virtual ~DownloadFilePickerFactory(); |
| 85 virtual void Create(content::DownloadItem* item, |
| 86 const base::FilePath& suggested_path, |
| 87 const DownloadFilePicker::FileSelectedCallback& callback); |
| 88 }; |
| 89 |
| 69 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ | 90 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ |
| OLD | NEW |