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 |
(...skipping 30 matching lines...) Expand all Loading... |
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, |
46 const base::FilePath& path); | 46 const base::FilePath& path); |
47 | 47 |
48 private: | 48 private: |
49 friend class base::RefCountedThreadSafe<FileSelectHelper>; | 49 friend class base::RefCountedThreadSafe<FileSelectHelper>; |
50 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, IsAcceptTypeValid); | 50 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, IsAcceptTypeValid); |
| 51 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, ZipPackage); |
51 explicit FileSelectHelper(Profile* profile); | 52 explicit FileSelectHelper(Profile* profile); |
52 virtual ~FileSelectHelper(); | 53 virtual ~FileSelectHelper(); |
53 | 54 |
54 // Utility class which can listen for directory lister events and relay | 55 // Utility class which can listen for directory lister events and relay |
55 // them to the main object with the correct tracking id. | 56 // them to the main object with the correct tracking id. |
56 class DirectoryListerDispatchDelegate | 57 class DirectoryListerDispatchDelegate |
57 : public net::DirectoryLister::DirectoryListerDelegate { | 58 : public net::DirectoryLister::DirectoryListerDelegate { |
58 public: | 59 public: |
59 DirectoryListerDispatchDelegate(FileSelectHelper* parent, int id) | 60 DirectoryListerDispatchDelegate(FileSelectHelper* parent, int id) |
60 : parent_(parent), | 61 : parent_(parent), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // Callbacks from directory enumeration. | 115 // Callbacks from directory enumeration. |
115 virtual void OnListFile( | 116 virtual void OnListFile( |
116 int id, | 117 int id, |
117 const net::DirectoryLister::DirectoryListerData& data); | 118 const net::DirectoryLister::DirectoryListerData& data); |
118 virtual void OnListDone(int id, int error); | 119 virtual void OnListDone(int id, int error); |
119 | 120 |
120 // Cleans up and releases this instance. This must be called after the last | 121 // Cleans up and releases this instance. This must be called after the last |
121 // callback is received from the enumeration code. | 122 // callback is received from the enumeration code. |
122 void EnumerateDirectoryEnd(); | 123 void EnumerateDirectoryEnd(); |
123 | 124 |
| 125 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 126 // Must be called on the FILE_USER_BLOCKING thread. Each selected file that is |
| 127 // a package will be zipped, and the zip will be passed to the render view |
| 128 // host in place of the package. |
| 129 void ProcessSelectedFilesMac(const std::vector<ui::SelectedFileInfo>& files); |
| 130 |
| 131 // Saves the paths of |zipped_files| for later deletion. Passes |files| to the |
| 132 // render view host. |
| 133 void ProcessSelectedFilesMacOnUIThread( |
| 134 const std::vector<ui::SelectedFileInfo>& files, |
| 135 const std::vector<base::FilePath>& zipped_files); |
| 136 |
| 137 // Zips the package at |path| into a temporary destination. Returns the |
| 138 // temporary destination, if the zip was successful. Otherwise returns an |
| 139 // empty path. |
| 140 static base::FilePath ZipPackage(const base::FilePath& path); |
| 141 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 142 |
| 143 // Utility method that passes |files| to the render view host, and ends the |
| 144 // file chooser. |
| 145 void NotifyRenderViewHostAndEnd( |
| 146 const std::vector<ui::SelectedFileInfo>& files); |
| 147 |
| 148 // Schedules the deletion of the files in |temporary_files_| and clears the |
| 149 // vector. |
| 150 void DeleteTemporaryFiles(); |
| 151 |
124 // Helper method to get allowed extensions for select file dialog from | 152 // Helper method to get allowed extensions for select file dialog from |
125 // the specified accept types as defined in the spec: | 153 // the specified accept types as defined in the spec: |
126 // http://whatwg.org/html/number-state.html#attr-input-accept | 154 // http://whatwg.org/html/number-state.html#attr-input-accept |
127 // |accept_types| contains only valid lowercased MIME types or file extensions | 155 // |accept_types| contains only valid lowercased MIME types or file extensions |
128 // beginning with a period (.). | 156 // beginning with a period (.). |
129 static scoped_ptr<ui::SelectFileDialog::FileTypeInfo> | 157 static scoped_ptr<ui::SelectFileDialog::FileTypeInfo> |
130 GetFileTypesFromAcceptType( | 158 GetFileTypesFromAcceptType( |
131 const std::vector<base::string16>& accept_types); | 159 const std::vector<base::string16>& accept_types); |
132 | 160 |
133 // Check the accept type is valid. It is expected to be all lower case with | 161 // Check the accept type is valid. It is expected to be all lower case with |
(...skipping 20 matching lines...) Expand all Loading... |
154 | 182 |
155 // Maintain a list of active directory enumerations. These could come from | 183 // 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 | 184 // the file select dialog or from drag-and-drop of directories, so there could |
157 // be more than one going on at a time. | 185 // be more than one going on at a time. |
158 struct ActiveDirectoryEnumeration; | 186 struct ActiveDirectoryEnumeration; |
159 std::map<int, ActiveDirectoryEnumeration*> directory_enumerations_; | 187 std::map<int, ActiveDirectoryEnumeration*> directory_enumerations_; |
160 | 188 |
161 // Registrar for notifications regarding our RenderViewHost. | 189 // Registrar for notifications regarding our RenderViewHost. |
162 content::NotificationRegistrar notification_registrar_; | 190 content::NotificationRegistrar notification_registrar_; |
163 | 191 |
| 192 // Temporary files only used on OSX. This class is responsible for deleting |
| 193 // these files when they are no longer needed. |
| 194 std::vector<base::FilePath> temporary_files_; |
| 195 |
164 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); | 196 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); |
165 }; | 197 }; |
166 | 198 |
167 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ | 199 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ |
OLD | NEW |