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_FILE_SELECT_HELPER_H_ | 5 #ifndef CHROME_BROWSER_FILE_SELECT_HELPER_H_ |
6 #define CHROME_BROWSER_FILE_SELECT_HELPER_H_ | 6 #define CHROME_BROWSER_FILE_SELECT_HELPER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "chrome/browser/ui/select_file_dialog.h" | |
14 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
16 #include "net/base/directory_lister.h" | 15 #include "net/base/directory_lister.h" |
| 16 #include "ui/base/dialogs/select_file_dialog.h" |
17 | 17 |
18 class Profile; | 18 class Profile; |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 class RenderViewHost; | 21 class RenderViewHost; |
22 class WebContents; | 22 class WebContents; |
23 struct FileChooserParams; | 23 struct FileChooserParams; |
24 } | 24 } |
25 | 25 |
26 namespace ui { | 26 namespace ui { |
27 struct SelectedFileInfo; | 27 struct SelectedFileInfo; |
28 } | 28 } |
29 | 29 |
30 // This class handles file-selection requests coming from WebUI elements | 30 // This class handles file-selection requests coming from WebUI elements |
31 // (via the ExtensionHost class). It implements both the initialisation | 31 // (via the ExtensionHost class). It implements both the initialisation |
32 // and listener functions for file-selection dialogs. | 32 // and listener functions for file-selection dialogs. |
33 class FileSelectHelper | 33 class FileSelectHelper |
34 : public base::RefCountedThreadSafe<FileSelectHelper>, | 34 : public base::RefCountedThreadSafe<FileSelectHelper>, |
35 public SelectFileDialog::Listener, | 35 public ui::SelectFileDialog::Listener, |
36 public content::NotificationObserver { | 36 public content::NotificationObserver { |
37 public: | 37 public: |
38 | 38 |
39 // Show the file chooser dialog. | 39 // Show the file chooser dialog. |
40 static void RunFileChooser(content::WebContents* tab, | 40 static void RunFileChooser(content::WebContents* tab, |
41 const content::FileChooserParams& params); | 41 const content::FileChooserParams& params); |
42 | 42 |
43 // Enumerates all the files in directory. | 43 // Enumerates all the files in directory. |
44 static void EnumerateDirectory(content::WebContents* tab, | 44 static void EnumerateDirectory(content::WebContents* tab, |
45 int request_id, | 45 int request_id, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 // Cleans up and releases this instance. This must be called after the last | 124 // Cleans up and releases this instance. This must be called after the last |
125 // callback is received from the enumeration code. | 125 // callback is received from the enumeration code. |
126 void EnumerateDirectoryEnd(); | 126 void EnumerateDirectoryEnd(); |
127 | 127 |
128 // Helper method to get allowed extensions for select file dialog from | 128 // Helper method to get allowed extensions for select file dialog from |
129 // the specified accept types as defined in the spec: | 129 // the specified accept types as defined in the spec: |
130 // http://whatwg.org/html/number-state.html#attr-input-accept | 130 // http://whatwg.org/html/number-state.html#attr-input-accept |
131 // |accept_types| contains only valid lowercased MIME types or file extensions | 131 // |accept_types| contains only valid lowercased MIME types or file extensions |
132 // beginning with a period (.). | 132 // beginning with a period (.). |
133 SelectFileDialog::FileTypeInfo* GetFileTypesFromAcceptType( | 133 ui::SelectFileDialog::FileTypeInfo* GetFileTypesFromAcceptType( |
134 const std::vector<string16>& accept_types); | 134 const std::vector<string16>& accept_types); |
135 | 135 |
136 // Check the accept type is valid. It is expected to be all lower case with | 136 // Check the accept type is valid. It is expected to be all lower case with |
137 // no whitespace. | 137 // no whitespace. |
138 static bool IsAcceptTypeValid(const std::string& accept_type); | 138 static bool IsAcceptTypeValid(const std::string& accept_type); |
139 | 139 |
140 // Profile used to set/retrieve the last used directory. | 140 // Profile used to set/retrieve the last used directory. |
141 Profile* profile_; | 141 Profile* profile_; |
142 | 142 |
143 // The RenderViewHost and WebContents for the page showing a file dialog | 143 // The RenderViewHost and WebContents for the page showing a file dialog |
144 // (may only be one such dialog). | 144 // (may only be one such dialog). |
145 content::RenderViewHost* render_view_host_; | 145 content::RenderViewHost* render_view_host_; |
146 content::WebContents* web_contents_; | 146 content::WebContents* web_contents_; |
147 | 147 |
148 // Dialog box used for choosing files to upload from file form fields. | 148 // Dialog box used for choosing files to upload from file form fields. |
149 scoped_refptr<SelectFileDialog> select_file_dialog_; | 149 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
150 scoped_ptr<SelectFileDialog::FileTypeInfo> select_file_types_; | 150 scoped_ptr<ui::SelectFileDialog::FileTypeInfo> select_file_types_; |
151 | 151 |
152 // The type of file dialog last shown. | 152 // The type of file dialog last shown. |
153 SelectFileDialog::Type dialog_type_; | 153 ui::SelectFileDialog::Type dialog_type_; |
154 | 154 |
155 // Maintain a list of active directory enumerations. These could come from | 155 // Maintain a list of active directory enumerations. These could come from |
156 // the file select dialog or from drag-and-drop of directories, so there could | 156 // the file select dialog or from drag-and-drop of directories, so there could |
157 // be more than one going on at a time. | 157 // be more than one going on at a time. |
158 struct ActiveDirectoryEnumeration; | 158 struct ActiveDirectoryEnumeration; |
159 std::map<int, ActiveDirectoryEnumeration*> directory_enumerations_; | 159 std::map<int, ActiveDirectoryEnumeration*> directory_enumerations_; |
160 | 160 |
161 // Registrar for notifications regarding our RenderViewHost. | 161 // Registrar for notifications regarding our RenderViewHost. |
162 content::NotificationRegistrar notification_registrar_; | 162 content::NotificationRegistrar notification_registrar_; |
163 | 163 |
164 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); | 164 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); |
165 }; | 165 }; |
166 | 166 |
167 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ | 167 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ |
OLD | NEW |