| 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_UI_SELECT_FILE_DIALOG_H_ | 5 #ifndef UI_BASE_DIALOGS_SELECT_FILE_DIALOG_H_ |
| 6 #define CHROME_BROWSER_UI_SELECT_FILE_DIALOG_H_ | 6 #define UI_BASE_DIALOGS_SELECT_FILE_DIALOG_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "ui/base/dialogs/base_shell_dialog.h" | 17 #include "ui/base/dialogs/base_shell_dialog.h" |
| 18 #include "ui/base/ui_export.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 22 class SelectFileDialogFactory; |
| 21 class SelectFilePolicy; | 23 class SelectFilePolicy; |
| 22 } | |
| 23 | |
| 24 namespace content { | |
| 25 class WebContents; | |
| 26 } | |
| 27 | |
| 28 namespace ui { | |
| 29 struct SelectedFileInfo; | 24 struct SelectedFileInfo; |
| 30 } | |
| 31 | |
| 32 // This function is declared extern such that it is accessible for unit tests | |
| 33 // in /chrome/browser/ui/views/select_file_dialog_win_unittest.cc | |
| 34 extern std::wstring AppendExtensionIfNeeded(const std::wstring& filename, | |
| 35 const std::wstring& filter_selected, | |
| 36 const std::wstring& suggested_ext); | |
| 37 | 25 |
| 38 // Shows a dialog box for selecting a file or a folder. | 26 // Shows a dialog box for selecting a file or a folder. |
| 39 class SelectFileDialog | 27 class UI_EXPORT SelectFileDialog |
| 40 : public base::RefCountedThreadSafe<SelectFileDialog>, | 28 : public base::RefCountedThreadSafe<SelectFileDialog>, |
| 41 public ui::BaseShellDialog { | 29 public ui::BaseShellDialog { |
| 42 public: | 30 public: |
| 43 enum Type { | 31 enum Type { |
| 44 SELECT_NONE, | 32 SELECT_NONE, |
| 45 SELECT_FOLDER, | 33 SELECT_FOLDER, |
| 46 SELECT_SAVEAS_FILE, | 34 SELECT_SAVEAS_FILE, |
| 47 SELECT_OPEN_FILE, | 35 SELECT_OPEN_FILE, |
| 48 SELECT_OPEN_MULTI_FILE | 36 SELECT_OPEN_MULTI_FILE |
| 49 }; | 37 }; |
| 50 | 38 |
| 51 // An interface implemented by a Listener object wishing to know about the | 39 // An interface implemented by a Listener object wishing to know about the |
| 52 // the result of the Select File/Folder action. These callbacks must be | 40 // the result of the Select File/Folder action. These callbacks must be |
| 53 // re-entrant. | 41 // re-entrant. |
| 54 class Listener { | 42 class UI_EXPORT Listener { |
| 55 public: | 43 public: |
| 56 // Notifies the Listener that a file/folder selection has been made. The | 44 // Notifies the Listener that a file/folder selection has been made. The |
| 57 // file/folder path is in |path|. |params| is contextual passed to | 45 // file/folder path is in |path|. |params| is contextual passed to |
| 58 // SelectFile. |index| specifies the index of the filter passed to the | 46 // SelectFile. |index| specifies the index of the filter passed to the |
| 59 // the initial call to SelectFile. | 47 // the initial call to SelectFile. |
| 60 virtual void FileSelected(const FilePath& path, | 48 virtual void FileSelected(const FilePath& path, |
| 61 int index, void* params) = 0; | 49 int index, void* params) = 0; |
| 62 | 50 |
| 63 // Similar to FileSelected() but takes SelectedFileInfo instead of | 51 // Similar to FileSelected() but takes SelectedFileInfo instead of |
| 64 // FilePath. Used for passing extra information (ex. display name). | 52 // FilePath. Used for passing extra information (ex. display name). |
| (...skipping 19 matching lines...) Expand all Loading... |
| 84 | 72 |
| 85 // Notifies the Listener that the file/folder selection was aborted (via | 73 // Notifies the Listener that the file/folder selection was aborted (via |
| 86 // the user canceling or closing the selection dialog box, for example). | 74 // the user canceling or closing the selection dialog box, for example). |
| 87 // |params| is contextual passed to SelectFile. | 75 // |params| is contextual passed to SelectFile. |
| 88 virtual void FileSelectionCanceled(void* params) {} | 76 virtual void FileSelectionCanceled(void* params) {} |
| 89 | 77 |
| 90 protected: | 78 protected: |
| 91 virtual ~Listener() {} | 79 virtual ~Listener() {} |
| 92 }; | 80 }; |
| 93 | 81 |
| 82 // Sets the factory that creates SelectFileDialog objects, overriding default |
| 83 // behaviour. |
| 84 // |
| 85 // This is optional and should only be used by components that have to live |
| 86 // elsewhere in the tree due to layering violations. (For example, because of |
| 87 // a dependency on chrome's extension system.) |
| 88 static void SetFactory(ui::SelectFileDialogFactory* factory); |
| 89 |
| 94 // Creates a dialog box helper. This object is ref-counted, but the returned | 90 // Creates a dialog box helper. This object is ref-counted, but the returned |
| 95 // object will have no reference (refcount is 0). |policy| is an optional | 91 // object will have no reference (refcount is 0). |policy| is an optional |
| 96 // class that can prevent showing a dialog. | 92 // class that can prevent showing a dialog. |
| 97 static SelectFileDialog* Create(Listener* listener, | 93 static SelectFileDialog* Create(Listener* listener, |
| 98 ui::SelectFilePolicy* policy); | 94 ui::SelectFilePolicy* policy); |
| 99 | 95 |
| 100 // Holds information about allowed extensions on a file save dialog. | 96 // Holds information about allowed extensions on a file save dialog. |
| 101 // |extensions| is a list of allowed extensions. For example, it might be | 97 // |extensions| is a list of allowed extensions. For example, it might be |
| 102 // { { "htm", "html" }, { "txt" } }. Only pass more than one extension | 98 // { { "htm", "html" }, { "txt" } }. Only pass more than one extension |
| 103 // in the inner vector if the extensions are equivalent. Do NOT include | 99 // in the inner vector if the extensions are equivalent. Do NOT include |
| 104 // leading periods. | 100 // leading periods. |
| 105 // |extension_description_overrides| overrides the system descriptions of the | 101 // |extension_description_overrides| overrides the system descriptions of the |
| 106 // specified extensions. Entries correspond to |extensions|; if left blank | 102 // specified extensions. Entries correspond to |extensions|; if left blank |
| 107 // the system descriptions will be used. | 103 // the system descriptions will be used. |
| 108 // |include_all_files| specifies whether there will be a filter added for all | 104 // |include_all_files| specifies whether there will be a filter added for all |
| 109 // files (i.e. *.*). | 105 // files (i.e. *.*). |
| 110 struct FileTypeInfo { | 106 struct UI_EXPORT FileTypeInfo { |
| 111 FileTypeInfo(); | 107 FileTypeInfo(); |
| 112 ~FileTypeInfo(); | 108 ~FileTypeInfo(); |
| 113 | 109 |
| 114 std::vector<std::vector<FilePath::StringType> > extensions; | 110 std::vector<std::vector<FilePath::StringType> > extensions; |
| 115 std::vector<string16> extension_description_overrides; | 111 std::vector<string16> extension_description_overrides; |
| 116 bool include_all_files; | 112 bool include_all_files; |
| 117 }; | 113 }; |
| 118 | 114 |
| 119 // Selects a File. | 115 // Selects a File. |
| 120 // Before doing anything this function checks if FileBrowsing is forbidden | 116 // Before doing anything this function checks if FileBrowsing is forbidden |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 void CancelFileSelection(void* params); | 182 void CancelFileSelection(void* params); |
| 187 | 183 |
| 188 // Returns true if the dialog has multiple file type choices. | 184 // Returns true if the dialog has multiple file type choices. |
| 189 virtual bool HasMultipleFileTypeChoicesImpl() = 0; | 185 virtual bool HasMultipleFileTypeChoicesImpl() = 0; |
| 190 | 186 |
| 191 scoped_ptr<ui::SelectFilePolicy> select_file_policy_; | 187 scoped_ptr<ui::SelectFilePolicy> select_file_policy_; |
| 192 | 188 |
| 193 DISALLOW_COPY_AND_ASSIGN(SelectFileDialog); | 189 DISALLOW_COPY_AND_ASSIGN(SelectFileDialog); |
| 194 }; | 190 }; |
| 195 | 191 |
| 196 #endif // CHROME_BROWSER_UI_SELECT_FILE_DIALOG_H_ | 192 } // namespace ui |
| 193 |
| 194 #endif // UI_BASE_DIALOGS_SELECT_FILE_DIALOG_H_ |
| OLD | NEW |