OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_H_ | 5 #ifndef UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_H_ |
6 #define UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_H_ | 6 #define UI_SHELL_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/files/file_path.h" | 13 #include "base/files/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/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
18 #include "ui/shell_dialogs/base_shell_dialog.h" | 18 #include "ui/shell_dialogs/base_shell_dialog.h" |
19 #include "ui/shell_dialogs/shell_dialogs_export.h" | 19 #include "ui/shell_dialogs/shell_dialogs_export.h" |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 class SelectFileDialogFactory; | 22 class SelectFileDialogFactory; |
23 class SelectFilePolicy; | 23 class SelectFilePolicy; |
24 struct SelectedFileInfo; | 24 struct SelectedFileInfo; |
25 class ShellDialogsDelegate; | 25 class ShellDialogsDelegate; |
26 | 26 |
27 // Shows a dialog box for selecting a file or a folder. | 27 // Shows a dialog box for selecting a file or a folder. |
28 class SHELL_DIALOGS_EXPORT SelectFileDialog | 28 class SHELL_DIALOGS_EXPORT SelectFileDialog |
29 : public base::RefCountedThreadSafe<SelectFileDialog>, | 29 : public base::RefCountedThreadSafe<SelectFileDialog>, |
30 public ui::BaseShellDialog { | 30 public BaseShellDialog { |
31 public: | 31 public: |
32 enum Type { | 32 enum Type { |
33 SELECT_NONE, | 33 SELECT_NONE, |
34 SELECT_FOLDER, | 34 SELECT_FOLDER, |
35 SELECT_SAVEAS_FILE, | 35 SELECT_SAVEAS_FILE, |
36 SELECT_OPEN_FILE, | 36 SELECT_OPEN_FILE, |
37 SELECT_OPEN_MULTI_FILE | 37 SELECT_OPEN_MULTI_FILE |
38 }; | 38 }; |
39 | 39 |
40 // An interface implemented by a Listener object wishing to know about the | 40 // An interface implemented by a Listener object wishing to know about the |
41 // the result of the Select File/Folder action. These callbacks must be | 41 // the result of the Select File/Folder action. These callbacks must be |
42 // re-entrant. | 42 // re-entrant. |
43 class SHELL_DIALOGS_EXPORT Listener { | 43 class SHELL_DIALOGS_EXPORT Listener { |
44 public: | 44 public: |
45 // Notifies the Listener that a file/folder selection has been made. The | 45 // Notifies the Listener that a file/folder selection has been made. The |
46 // file/folder path is in |path|. |params| is contextual passed to | 46 // file/folder path is in |path|. |params| is contextual passed to |
47 // SelectFile. |index| specifies the index of the filter passed to the | 47 // SelectFile. |index| specifies the index of the filter passed to the |
48 // the initial call to SelectFile. | 48 // the initial call to SelectFile. |
49 virtual void FileSelected(const base::FilePath& path, | 49 virtual void FileSelected(const base::FilePath& path, |
50 int index, void* params) = 0; | 50 int index, void* params) = 0; |
51 | 51 |
52 // Similar to FileSelected() but takes SelectedFileInfo instead of | 52 // Similar to FileSelected() but takes SelectedFileInfo instead of |
53 // base::FilePath. Used for passing extra information (ex. display name). | 53 // base::FilePath. Used for passing extra information (ex. display name). |
54 // | 54 // |
55 // If not overridden, calls FileSelected() with path from |file|. | 55 // If not overridden, calls FileSelected() with path from |file|. |
56 virtual void FileSelectedWithExtraInfo( | 56 virtual void FileSelectedWithExtraInfo( |
57 const ui::SelectedFileInfo& file, | 57 const SelectedFileInfo& file, |
58 int index, | 58 int index, |
59 void* params); | 59 void* params); |
60 | 60 |
61 // Notifies the Listener that many files have been selected. The | 61 // Notifies the Listener that many files have been selected. The |
62 // files are in |files|. |params| is contextual passed to SelectFile. | 62 // files are in |files|. |params| is contextual passed to SelectFile. |
63 virtual void MultiFilesSelected( | 63 virtual void MultiFilesSelected( |
64 const std::vector<base::FilePath>& files, void* params) {} | 64 const std::vector<base::FilePath>& files, void* params) {} |
65 | 65 |
66 // Similar to MultiFilesSelected() but takes SelectedFileInfo instead of | 66 // Similar to MultiFilesSelected() but takes SelectedFileInfo instead of |
67 // base::FilePath. Used for passing extra information (ex. display name). | 67 // base::FilePath. Used for passing extra information (ex. display name). |
68 // | 68 // |
69 // If not overridden, calls MultiFilesSelected() with paths from |files|. | 69 // If not overridden, calls MultiFilesSelected() with paths from |files|. |
70 virtual void MultiFilesSelectedWithExtraInfo( | 70 virtual void MultiFilesSelectedWithExtraInfo( |
71 const std::vector<ui::SelectedFileInfo>& files, | 71 const std::vector<SelectedFileInfo>& files, |
72 void* params); | 72 void* params); |
73 | 73 |
74 // Notifies the Listener that the file/folder selection was aborted (via | 74 // Notifies the Listener that the file/folder selection was aborted (via |
75 // the user canceling or closing the selection dialog box, for example). | 75 // the user canceling or closing the selection dialog box, for example). |
76 // |params| is contextual passed to SelectFile. | 76 // |params| is contextual passed to SelectFile. |
77 virtual void FileSelectionCanceled(void* params) {} | 77 virtual void FileSelectionCanceled(void* params) {} |
78 | 78 |
79 protected: | 79 protected: |
80 virtual ~Listener() {} | 80 virtual ~Listener() {} |
81 }; | 81 }; |
82 | 82 |
83 // Sets the factory that creates SelectFileDialog objects, overriding default | 83 // Sets the factory that creates SelectFileDialog objects, overriding default |
84 // behaviour. | 84 // behaviour. |
85 // | 85 // |
86 // This is optional and should only be used by components that have to live | 86 // This is optional and should only be used by components that have to live |
87 // elsewhere in the tree due to layering violations. (For example, because of | 87 // elsewhere in the tree due to layering violations. (For example, because of |
88 // a dependency on chrome's extension system.) | 88 // a dependency on chrome's extension system.) |
89 static void SetFactory(ui::SelectFileDialogFactory* factory); | 89 static void SetFactory(SelectFileDialogFactory* factory); |
90 | 90 |
91 // Creates a dialog box helper. This is an inexpensive wrapper around the | 91 // Creates a dialog box helper. This is an inexpensive wrapper around the |
92 // platform-native file selection dialog. |policy| is an optional class that | 92 // platform-native file selection dialog. |policy| is an optional class that |
93 // can prevent showing a dialog. | 93 // can prevent showing a dialog. |
94 static scoped_refptr<SelectFileDialog> Create(Listener* listener, | 94 static scoped_refptr<SelectFileDialog> Create(Listener* listener, |
95 ui::SelectFilePolicy* policy); | 95 SelectFilePolicy* policy); |
96 | 96 |
97 // Holds information about allowed extensions on a file save dialog. | 97 // Holds information about allowed extensions on a file save dialog. |
98 struct SHELL_DIALOGS_EXPORT FileTypeInfo { | 98 struct SHELL_DIALOGS_EXPORT FileTypeInfo { |
99 FileTypeInfo(); | 99 FileTypeInfo(); |
100 ~FileTypeInfo(); | 100 ~FileTypeInfo(); |
101 | 101 |
102 // A list of allowed extensions. For example, it might be | 102 // A list of allowed extensions. For example, it might be |
103 // | 103 // |
104 // { { "htm", "html" }, { "txt" } } | 104 // { { "htm", "html" }, { "txt" } } |
105 // | 105 // |
106 // Only pass more than one extension in the inner vector if the extensions | 106 // Only pass more than one extension in the inner vector if the extensions |
107 // are equivalent. Do NOT include leading periods. | 107 // are equivalent. Do NOT include leading periods. |
108 std::vector<std::vector<base::FilePath::StringType> > extensions; | 108 std::vector<std::vector<base::FilePath::StringType> > extensions; |
109 | 109 |
110 // Overrides the system descriptions of the specified extensions. Entries | 110 // Overrides the system descriptions of the specified extensions. Entries |
111 // correspond to |extensions|; if left blank the system descriptions will | 111 // correspond to |extensions|; if left blank the system descriptions will |
112 // be used. | 112 // be used. |
113 std::vector<string16> extension_description_overrides; | 113 std::vector<base::string16> extension_description_overrides; |
114 | 114 |
115 // Specifies whether there will be a filter added for all files (i.e. *.*). | 115 // Specifies whether there will be a filter added for all files (i.e. *.*). |
116 bool include_all_files; | 116 bool include_all_files; |
117 | 117 |
118 // Specifies whether the caller can support files/folders that are on Drive. | 118 // Specifies whether the caller can support files/folders that are on Drive. |
119 bool support_drive; | 119 bool support_drive; |
120 }; | 120 }; |
121 | 121 |
122 // Selects a File. | 122 // Selects a File. |
123 // Before doing anything this function checks if FileBrowsing is forbidden | 123 // Before doing anything this function checks if FileBrowsing is forbidden |
(...skipping 16 matching lines...) Expand all Loading... |
140 // |default_extension| is the default extension to add to the file if the | 140 // |default_extension| is the default extension to add to the file if the |
141 // user doesn't type one. This should NOT include the '.'. On Windows, if | 141 // user doesn't type one. This should NOT include the '.'. On Windows, if |
142 // you specify this you must also specify |file_types|. | 142 // you specify this you must also specify |file_types|. |
143 // |owning_window| is the window the dialog is modal to, or NULL for a | 143 // |owning_window| is the window the dialog is modal to, or NULL for a |
144 // modeless dialog. | 144 // modeless dialog. |
145 // |params| is data from the calling context which will be passed through to | 145 // |params| is data from the calling context which will be passed through to |
146 // the listener. Can be NULL. | 146 // the listener. Can be NULL. |
147 // NOTE: only one instance of any shell dialog can be shown per owning_window | 147 // NOTE: only one instance of any shell dialog can be shown per owning_window |
148 // at a time (for obvious reasons). | 148 // at a time (for obvious reasons). |
149 void SelectFile(Type type, | 149 void SelectFile(Type type, |
150 const string16& title, | 150 const base::string16& title, |
151 const base::FilePath& default_path, | 151 const base::FilePath& default_path, |
152 const FileTypeInfo* file_types, | 152 const FileTypeInfo* file_types, |
153 int file_type_index, | 153 int file_type_index, |
154 const base::FilePath::StringType& default_extension, | 154 const base::FilePath::StringType& default_extension, |
155 gfx::NativeWindow owning_window, | 155 gfx::NativeWindow owning_window, |
156 void* params); | 156 void* params); |
157 bool HasMultipleFileTypeChoices(); | 157 bool HasMultipleFileTypeChoices(); |
158 | 158 |
159 // Sets the global ShellDialogsDelegate. Defaults to NULL. | 159 // Sets the global ShellDialogsDelegate. Defaults to NULL. |
160 static void SetShellDialogsDelegate(ShellDialogsDelegate* delegate); | 160 static void SetShellDialogsDelegate(ShellDialogsDelegate* delegate); |
161 | 161 |
162 protected: | 162 protected: |
163 friend class base::RefCountedThreadSafe<SelectFileDialog>; | 163 friend class base::RefCountedThreadSafe<SelectFileDialog>; |
164 explicit SelectFileDialog(Listener* listener, | 164 explicit SelectFileDialog(Listener* listener, SelectFilePolicy* policy); |
165 ui::SelectFilePolicy* policy); | |
166 virtual ~SelectFileDialog(); | 165 virtual ~SelectFileDialog(); |
167 | 166 |
168 // Displays the actual file-selection dialog. | 167 // Displays the actual file-selection dialog. |
169 // This is overridden in the platform-specific descendants of FileSelectDialog | 168 // This is overridden in the platform-specific descendants of FileSelectDialog |
170 // and gets called from SelectFile after testing the | 169 // and gets called from SelectFile after testing the |
171 // AllowFileSelectionDialogs-Policy. | 170 // AllowFileSelectionDialogs-Policy. |
172 virtual void SelectFileImpl( | 171 virtual void SelectFileImpl( |
173 Type type, | 172 Type type, |
174 const string16& title, | 173 const base::string16& title, |
175 const base::FilePath& default_path, | 174 const base::FilePath& default_path, |
176 const FileTypeInfo* file_types, | 175 const FileTypeInfo* file_types, |
177 int file_type_index, | 176 int file_type_index, |
178 const base::FilePath::StringType& default_extension, | 177 const base::FilePath::StringType& default_extension, |
179 gfx::NativeWindow owning_window, | 178 gfx::NativeWindow owning_window, |
180 void* params) = 0; | 179 void* params) = 0; |
181 | 180 |
182 // Returns the global ShellDialogsDelegate instance if any. | 181 // Returns the global ShellDialogsDelegate instance if any. |
183 ShellDialogsDelegate* GetShellDialogsDelegate(); | 182 ShellDialogsDelegate* GetShellDialogsDelegate(); |
184 | 183 |
185 // The listener to be notified of selection completion. | 184 // The listener to be notified of selection completion. |
186 Listener* listener_; | 185 Listener* listener_; |
187 | 186 |
188 private: | 187 private: |
189 // Tests if the file selection dialog can be displayed by | 188 // Tests if the file selection dialog can be displayed by |
190 // testing if the AllowFileSelectionDialogs-Policy is | 189 // testing if the AllowFileSelectionDialogs-Policy is |
191 // either unset or set to true. | 190 // either unset or set to true. |
192 bool CanOpenSelectFileDialog(); | 191 bool CanOpenSelectFileDialog(); |
193 | 192 |
194 // Informs the |listener_| that the file selection dialog was canceled. Moved | 193 // Informs the |listener_| that the file selection dialog was canceled. Moved |
195 // to a function for being able to post it to the message loop. | 194 // to a function for being able to post it to the message loop. |
196 void CancelFileSelection(void* params); | 195 void CancelFileSelection(void* params); |
197 | 196 |
198 // Returns true if the dialog has multiple file type choices. | 197 // Returns true if the dialog has multiple file type choices. |
199 virtual bool HasMultipleFileTypeChoicesImpl() = 0; | 198 virtual bool HasMultipleFileTypeChoicesImpl() = 0; |
200 | 199 |
201 scoped_ptr<ui::SelectFilePolicy> select_file_policy_; | 200 scoped_ptr<SelectFilePolicy> select_file_policy_; |
202 | 201 |
203 DISALLOW_COPY_AND_ASSIGN(SelectFileDialog); | 202 DISALLOW_COPY_AND_ASSIGN(SelectFileDialog); |
204 }; | 203 }; |
205 | 204 |
206 } // namespace ui | 205 } // namespace ui |
207 | 206 |
208 #endif // UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_H_ | 207 #endif // UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_H_ |
209 | |
OLD | NEW |