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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 13 matching lines...) Expand all Loading... |
24 } | 24 } |
25 | 25 |
26 // This class handles file-selection requests coming from WebUI elements | 26 // This class handles file-selection requests coming from WebUI elements |
27 // (via the ExtensionHost class). It implements both the initialisation | 27 // (via the ExtensionHost class). It implements both the initialisation |
28 // and listener functions for file-selection dialogs. | 28 // and listener functions for file-selection dialogs. |
29 class FileSelectHelper | 29 class FileSelectHelper |
30 : public base::RefCountedThreadSafe<FileSelectHelper>, | 30 : public base::RefCountedThreadSafe<FileSelectHelper>, |
31 public SelectFileDialog::Listener, | 31 public SelectFileDialog::Listener, |
32 public content::NotificationObserver { | 32 public content::NotificationObserver { |
33 public: | 33 public: |
34 explicit FileSelectHelper(Profile* profile); | |
35 | 34 |
36 // Show the file chooser dialog. | 35 // Show the file chooser dialog. |
37 void RunFileChooser(content::RenderViewHost* render_view_host, | 36 static void RunFileChooser(content::WebContents* tab, |
38 content::WebContents* tab_contents, | 37 const content::FileChooserParams& params); |
39 const content::FileChooserParams& params); | |
40 | 38 |
41 // Enumerates all the files in directory. | 39 // Enumerates all the files in directory. |
42 void EnumerateDirectory(int request_id, | 40 static void EnumerateDirectory(content::WebContents* tab, |
43 content::RenderViewHost* render_view_host, | 41 int request_id, |
44 const FilePath& path); | 42 const FilePath& path); |
45 | 43 |
46 private: | 44 private: |
47 friend class base::RefCountedThreadSafe<FileSelectHelper>; | 45 friend class base::RefCountedThreadSafe<FileSelectHelper>; |
| 46 explicit FileSelectHelper(Profile* profile); |
48 virtual ~FileSelectHelper(); | 47 virtual ~FileSelectHelper(); |
49 | 48 |
50 // Utility class which can listen for directory lister events and relay | 49 // Utility class which can listen for directory lister events and relay |
51 // them to the main object with the correct tracking id. | 50 // them to the main object with the correct tracking id. |
52 class DirectoryListerDispatchDelegate | 51 class DirectoryListerDispatchDelegate |
53 : public net::DirectoryLister::DirectoryListerDelegate { | 52 : public net::DirectoryLister::DirectoryListerDelegate { |
54 public: | 53 public: |
55 DirectoryListerDispatchDelegate(FileSelectHelper* parent, int id) | 54 DirectoryListerDispatchDelegate(FileSelectHelper* parent, int id) |
56 : parent_(parent), | 55 : parent_(parent), |
57 id_(id) {} | 56 id_(id) {} |
58 virtual ~DirectoryListerDispatchDelegate() {} | 57 virtual ~DirectoryListerDispatchDelegate() {} |
59 virtual void OnListFile( | 58 virtual void OnListFile( |
60 const net::DirectoryLister::DirectoryListerData& data) OVERRIDE { | 59 const net::DirectoryLister::DirectoryListerData& data) OVERRIDE { |
61 parent_->OnListFile(id_, data); | 60 parent_->OnListFile(id_, data); |
62 } | 61 } |
63 virtual void OnListDone(int error) OVERRIDE { | 62 virtual void OnListDone(int error) OVERRIDE { |
64 parent_->OnListDone(id_, error); | 63 parent_->OnListDone(id_, error); |
65 } | 64 } |
66 private: | 65 private: |
67 // This FileSelectHelper owns this object. | 66 // This FileSelectHelper owns this object. |
68 FileSelectHelper* parent_; | 67 FileSelectHelper* parent_; |
69 int id_; | 68 int id_; |
70 | 69 |
71 DISALLOW_COPY_AND_ASSIGN(DirectoryListerDispatchDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(DirectoryListerDispatchDelegate); |
72 }; | 71 }; |
73 | 72 |
| 73 void RunFileChooser(content::RenderViewHost* render_view_host, |
| 74 content::WebContents* tab_contents, |
| 75 const content::FileChooserParams& params); |
74 void RunFileChooserOnFileThread( | 76 void RunFileChooserOnFileThread( |
75 const content::FileChooserParams& params); | 77 const content::FileChooserParams& params); |
76 void RunFileChooserOnUIThread( | 78 void RunFileChooserOnUIThread( |
77 const content::FileChooserParams& params); | 79 const content::FileChooserParams& params); |
78 | 80 |
79 // Cleans up and releases this instance. This must be called after the last | 81 // Cleans up and releases this instance. This must be called after the last |
80 // callback is received from the file chooser dialog. | 82 // callback is received from the file chooser dialog. |
81 void RunFileChooserEnd(); | 83 void RunFileChooserEnd(); |
82 | 84 |
83 // SelectFileDialog::Listener overrides. | 85 // SelectFileDialog::Listener overrides. |
84 virtual void FileSelected( | 86 virtual void FileSelected( |
85 const FilePath& path, int index, void* params) OVERRIDE; | 87 const FilePath& path, int index, void* params) OVERRIDE; |
86 virtual void FileSelectedWithExtraInfo( | 88 virtual void FileSelectedWithExtraInfo( |
87 const content::SelectedFileInfo& file, | 89 const content::SelectedFileInfo& file, |
88 int index, | 90 int index, |
89 void* params) OVERRIDE; | 91 void* params) OVERRIDE; |
90 virtual void MultiFilesSelected(const std::vector<FilePath>& files, | 92 virtual void MultiFilesSelected(const std::vector<FilePath>& files, |
91 void* params) OVERRIDE; | 93 void* params) OVERRIDE; |
92 virtual void MultiFilesSelectedWithExtraInfo( | 94 virtual void MultiFilesSelectedWithExtraInfo( |
93 const std::vector<content::SelectedFileInfo>& files, | 95 const std::vector<content::SelectedFileInfo>& files, |
94 void* params) OVERRIDE; | 96 void* params) OVERRIDE; |
95 virtual void FileSelectionCanceled(void* params) OVERRIDE; | 97 virtual void FileSelectionCanceled(void* params) OVERRIDE; |
96 | 98 |
97 // content::NotificationObserver overrides. | 99 // content::NotificationObserver overrides. |
98 virtual void Observe(int type, | 100 virtual void Observe(int type, |
99 const content::NotificationSource& source, | 101 const content::NotificationSource& source, |
100 const content::NotificationDetails& details) OVERRIDE; | 102 const content::NotificationDetails& details) OVERRIDE; |
101 | 103 |
| 104 void EnumerateDirectory(int request_id, |
| 105 content::RenderViewHost* render_view_host, |
| 106 const FilePath& path); |
| 107 |
102 // Kicks off a new directory enumeration. | 108 // Kicks off a new directory enumeration. |
103 void StartNewEnumeration(const FilePath& path, | 109 void StartNewEnumeration(const FilePath& path, |
104 int request_id, | 110 int request_id, |
105 content::RenderViewHost* render_view_host); | 111 content::RenderViewHost* render_view_host); |
106 | 112 |
107 // Callbacks from directory enumeration. | 113 // Callbacks from directory enumeration. |
108 virtual void OnListFile( | 114 virtual void OnListFile( |
109 int id, | 115 int id, |
110 const net::DirectoryLister::DirectoryListerData& data); | 116 const net::DirectoryLister::DirectoryListerData& data); |
111 virtual void OnListDone(int id, int error); | 117 virtual void OnListDone(int id, int error); |
(...skipping 30 matching lines...) Expand all Loading... |
142 struct ActiveDirectoryEnumeration; | 148 struct ActiveDirectoryEnumeration; |
143 std::map<int, ActiveDirectoryEnumeration*> directory_enumerations_; | 149 std::map<int, ActiveDirectoryEnumeration*> directory_enumerations_; |
144 | 150 |
145 // Registrar for notifications regarding our RenderViewHost. | 151 // Registrar for notifications regarding our RenderViewHost. |
146 content::NotificationRegistrar notification_registrar_; | 152 content::NotificationRegistrar notification_registrar_; |
147 | 153 |
148 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); | 154 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); |
149 }; | 155 }; |
150 | 156 |
151 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ | 157 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ |
OLD | NEW |