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 CHROME_BROWSER_UI_SELECT_FILE_DIALOG_H_ |
6 #define CHROME_BROWSER_UI_SELECT_FILE_DIALOG_H_ | 6 #define CHROME_BROWSER_UI_SELECT_FILE_DIALOG_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/callback_forward.h" |
12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/string16.h" | 15 #include "base/string16.h" |
15 #include "chrome/browser/ui/base_shell_dialog.h" | 16 #include "ui/base/dialogs/base_shell_dialog.h" |
16 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
17 | 18 |
| 19 namespace ui { |
| 20 class SelectFilePolicy; |
| 21 } |
| 22 |
18 namespace content { | 23 namespace content { |
19 class WebContents; | 24 class WebContents; |
20 struct SelectedFileInfo; | 25 struct SelectedFileInfo; |
21 } | 26 } |
22 | 27 |
23 // This function is declared extern such that it is accessible for unit tests | 28 // This function is declared extern such that it is accessible for unit tests |
24 // in /chrome/browser/ui/views/select_file_dialog_win_unittest.cc | 29 // in /chrome/browser/ui/views/select_file_dialog_win_unittest.cc |
25 extern std::wstring AppendExtensionIfNeeded(const std::wstring& filename, | 30 extern std::wstring AppendExtensionIfNeeded(const std::wstring& filename, |
26 const std::wstring& filter_selected, | 31 const std::wstring& filter_selected, |
27 const std::wstring& suggested_ext); | 32 const std::wstring& suggested_ext); |
28 | 33 |
29 // Shows a dialog box for selecting a file or a folder. | 34 // Shows a dialog box for selecting a file or a folder. |
30 class SelectFileDialog | 35 class SelectFileDialog |
31 : public base::RefCountedThreadSafe<SelectFileDialog>, | 36 : public base::RefCountedThreadSafe<SelectFileDialog>, |
32 public BaseShellDialog { | 37 public ui::BaseShellDialog { |
33 public: | 38 public: |
34 enum Type { | 39 enum Type { |
35 SELECT_NONE, | 40 SELECT_NONE, |
36 SELECT_FOLDER, | 41 SELECT_FOLDER, |
37 SELECT_SAVEAS_FILE, | 42 SELECT_SAVEAS_FILE, |
38 SELECT_OPEN_FILE, | 43 SELECT_OPEN_FILE, |
39 SELECT_OPEN_MULTI_FILE | 44 SELECT_OPEN_MULTI_FILE |
40 }; | 45 }; |
41 | 46 |
42 // An interface implemented by a Listener object wishing to know about the | 47 // An interface implemented by a Listener object wishing to know about the |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 80 |
76 // Notifies the Listener that the file/folder selection was aborted (via | 81 // Notifies the Listener that the file/folder selection was aborted (via |
77 // the user canceling or closing the selection dialog box, for example). | 82 // the user canceling or closing the selection dialog box, for example). |
78 // |params| is contextual passed to SelectFile. | 83 // |params| is contextual passed to SelectFile. |
79 virtual void FileSelectionCanceled(void* params) {} | 84 virtual void FileSelectionCanceled(void* params) {} |
80 | 85 |
81 protected: | 86 protected: |
82 virtual ~Listener() {} | 87 virtual ~Listener() {} |
83 }; | 88 }; |
84 | 89 |
| 90 // Sets the global file policy class. This is an optional class that lets the |
| 91 // implementer block the showing of file dialogs. |
| 92 static void SetFilePolicy(ui::SelectFilePolicy* policy); |
| 93 |
85 // Creates a dialog box helper. This object is ref-counted, but the returned | 94 // Creates a dialog box helper. This object is ref-counted, but the returned |
86 // object will have no reference (refcount is 0). | 95 // object will have no reference (refcount is 0). |
87 static SelectFileDialog* Create(Listener* listener); | 96 static SelectFileDialog* Create(Listener* listener); |
88 | 97 |
89 // Holds information about allowed extensions on a file save dialog. | 98 // Holds information about allowed extensions on a file save dialog. |
90 // |extensions| is a list of allowed extensions. For example, it might be | 99 // |extensions| is a list of allowed extensions. For example, it might be |
91 // { { "htm", "html" }, { "txt" } }. Only pass more than one extension | 100 // { { "htm", "html" }, { "txt" } }. Only pass more than one extension |
92 // in the inner vector if the extensions are equivalent. Do NOT include | 101 // in the inner vector if the extensions are equivalent. Do NOT include |
93 // leading periods. | 102 // leading periods. |
94 // |extension_description_overrides| overrides the system descriptions of the | 103 // |extension_description_overrides| overrides the system descriptions of the |
(...skipping 24 matching lines...) Expand all Loading... |
119 // |default_path| is the default path and suggested file name to be shown in | 128 // |default_path| is the default path and suggested file name to be shown in |
120 // the dialog. This only works for SELECT_SAVEAS_FILE and SELECT_OPEN_FILE. | 129 // the dialog. This only works for SELECT_SAVEAS_FILE and SELECT_OPEN_FILE. |
121 // Can be an empty string to indicate the platform default. | 130 // Can be an empty string to indicate the platform default. |
122 // |file_types| holds the information about the file types allowed. Pass NULL | 131 // |file_types| holds the information about the file types allowed. Pass NULL |
123 // to get no special behavior | 132 // to get no special behavior |
124 // |file_type_index| is the 1-based index into the file type list in | 133 // |file_type_index| is the 1-based index into the file type list in |
125 // |file_types|. Specify 0 if you don't need to specify extension behavior. | 134 // |file_types|. Specify 0 if you don't need to specify extension behavior. |
126 // |default_extension| is the default extension to add to the file if the | 135 // |default_extension| is the default extension to add to the file if the |
127 // user doesn't type one. This should NOT include the '.'. On Windows, if | 136 // user doesn't type one. This should NOT include the '.'. On Windows, if |
128 // you specify this you must also specify |file_types|. | 137 // you specify this you must also specify |file_types|. |
129 // |source_contents| is the WebContents the call is originating from, i.e. | 138 // |policy_denied| is a closure called if there is a ui::SelectFilePolicy |
130 // where the InfoBar should be shown in case file-selection dialogs are | 139 // object which denied opening this dialog. Pass an empty closure if you |
131 // forbidden by policy, or NULL if no InfoBar should be shown. | 140 // want no action to be taken. |
132 // |owning_window| is the window the dialog is modal to, or NULL for a | 141 // |owning_window| is the window the dialog is modal to, or NULL for a |
133 // modeless dialog. | 142 // modeless dialog. |
134 // |params| is data from the calling context which will be passed through to | 143 // |params| is data from the calling context which will be passed through to |
135 // the listener. Can be NULL. | 144 // the listener. Can be NULL. |
136 // NOTE: only one instance of any shell dialog can be shown per owning_window | 145 // NOTE: only one instance of any shell dialog can be shown per owning_window |
137 // at a time (for obvious reasons). | 146 // at a time (for obvious reasons). |
138 void SelectFile(Type type, | 147 void SelectFile(Type type, |
139 const string16& title, | 148 const string16& title, |
140 const FilePath& default_path, | 149 const FilePath& default_path, |
141 const FileTypeInfo* file_types, | 150 const FileTypeInfo* file_types, |
142 int file_type_index, | 151 int file_type_index, |
143 const FilePath::StringType& default_extension, | 152 const FilePath::StringType& default_extension, |
144 content::WebContents* source_contents, | 153 const base::Closure& policy_denied, |
145 gfx::NativeWindow owning_window, | 154 gfx::NativeWindow owning_window, |
146 void* params); | 155 void* params); |
147 bool HasMultipleFileTypeChoices(); | 156 bool HasMultipleFileTypeChoices(); |
148 | 157 |
149 protected: | 158 protected: |
150 friend class base::RefCountedThreadSafe<SelectFileDialog>; | 159 friend class base::RefCountedThreadSafe<SelectFileDialog>; |
151 explicit SelectFileDialog(Listener* listener); | 160 explicit SelectFileDialog(Listener* listener); |
152 virtual ~SelectFileDialog(); | 161 virtual ~SelectFileDialog(); |
153 | 162 |
154 // Displays the actual file-selection dialog. | 163 // Displays the actual file-selection dialog. |
(...skipping 17 matching lines...) Expand all Loading... |
172 // testing if the AllowFileSelectionDialogs-Policy is | 181 // testing if the AllowFileSelectionDialogs-Policy is |
173 // either unset or set to true. | 182 // either unset or set to true. |
174 bool CanOpenSelectFileDialog(); | 183 bool CanOpenSelectFileDialog(); |
175 | 184 |
176 // Informs the |listener_| that the file selection dialog was canceled. Moved | 185 // Informs the |listener_| that the file selection dialog was canceled. Moved |
177 // to a function for being able to post it to the message loop. | 186 // to a function for being able to post it to the message loop. |
178 void CancelFileSelection(void* params); | 187 void CancelFileSelection(void* params); |
179 | 188 |
180 // Returns true if the dialog has multiple file type choices. | 189 // Returns true if the dialog has multiple file type choices. |
181 virtual bool HasMultipleFileTypeChoicesImpl() = 0; | 190 virtual bool HasMultipleFileTypeChoicesImpl() = 0; |
| 191 |
| 192 static ui::SelectFilePolicy* select_file_policy_; |
182 }; | 193 }; |
183 | 194 |
184 #endif // CHROME_BROWSER_UI_SELECT_FILE_DIALOG_H_ | 195 #endif // CHROME_BROWSER_UI_SELECT_FILE_DIALOG_H_ |
OLD | NEW |