OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EXTENSION_API_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EXTENSION_API_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/platform_file.h" | |
14 #include "chrome/browser/extensions/extension_function.h" | |
15 #include "googleurl/src/url_util.h" | |
16 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
17 | |
18 #ifdef OS_CHROMEOS | |
19 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" | |
20 #endif | |
21 | |
22 class GURL; | |
23 | |
24 // Implements the chrome.fileBrowserPrivate.requestLocalFileSystem method. | |
25 class RequestLocalFileSystemFunction : public AsyncExtensionFunction { | |
26 protected: | |
27 // AsyncExtensionFunction overrides. | |
28 virtual bool RunImpl() OVERRIDE; | |
29 | |
30 private: | |
31 class LocalFileSystemCallbackDispatcher; | |
32 | |
33 void RespondSuccessOnUIThread(const std::string& name, | |
34 const GURL& root_path); | |
35 void RespondFailedOnUIThread(base::PlatformFileError error_code); | |
36 void RequestOnFileThread(const GURL& source_url, int child_id); | |
37 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.requestLocalFileSystem"); | |
38 }; | |
39 | |
40 // Implements the chrome.fileBrowserPrivate.addFileWatch method. | |
41 class FileWatchBrowserFunctionBase : public AsyncExtensionFunction { | |
42 protected: | |
43 virtual bool PerformFileWatchOperation( | |
44 const FilePath& local_path, const FilePath& virtual_path, | |
45 const std::string& extension_id) = 0; | |
46 | |
47 // AsyncExtensionFunction overrides. | |
48 virtual bool RunImpl() OVERRIDE; | |
49 | |
50 private: | |
51 bool GetLocalFilePath(const GURL& file_url, FilePath* local_path, | |
52 FilePath* virtual_path); | |
53 void RespondOnUIThread(bool success); | |
54 void RunFileWatchOperationOnFileThread(const GURL& file_url, | |
55 const std::string& extension_id); | |
56 }; | |
57 | |
58 // Implements the chrome.fileBrowserPrivate.addFileWatch method. | |
59 class AddFileWatchBrowserFunction : public FileWatchBrowserFunctionBase { | |
60 protected: | |
61 virtual bool PerformFileWatchOperation( | |
62 const FilePath& local_path, const FilePath& virtual_path, | |
63 const std::string& extension_id) OVERRIDE; | |
64 | |
65 private: | |
66 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.addFileWatch"); | |
67 }; | |
68 | |
69 | |
70 // Implements the chrome.fileBrowserPrivate.removeFileWatch method. | |
71 class RemoveFileWatchBrowserFunction : public FileWatchBrowserFunctionBase { | |
72 protected: | |
73 virtual bool PerformFileWatchOperation( | |
74 const FilePath& local_path, const FilePath& virtual_path, | |
75 const std::string& extension_id) OVERRIDE; | |
76 | |
77 private: | |
78 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeFileWatch"); | |
79 }; | |
80 | |
81 // Implements the chrome.fileBrowserPrivate.getFileTasks method. | |
82 class GetFileTasksFileBrowserFunction : public AsyncExtensionFunction { | |
83 protected: | |
84 // AsyncExtensionFunction overrides. | |
85 virtual bool RunImpl() OVERRIDE; | |
86 | |
87 private: | |
88 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getFileTasks"); | |
89 }; | |
90 | |
91 | |
92 // Implements the chrome.fileBrowserPrivate.executeTask method. | |
93 class ExecuteTasksFileBrowserFunction : public AsyncExtensionFunction { | |
94 protected: | |
95 // AsyncExtensionFunction overrides. | |
96 virtual bool RunImpl() OVERRIDE; | |
97 | |
98 private: | |
99 struct FileDefinition { | |
100 GURL target_file_url; | |
101 FilePath virtual_path; | |
102 bool is_directory; | |
103 }; | |
104 typedef std::vector<FileDefinition> FileDefinitionList; | |
105 class ExecuteTasksFileSystemCallbackDispatcher; | |
106 // Initates execution of context menu tasks identified with |task_id| for | |
107 // each element of |files_list|. | |
108 bool InitiateFileTaskExecution(const std::string& task_id, | |
109 base::ListValue* files_list); | |
110 void RequestFileEntryOnFileThread(const GURL& source_url, | |
111 const std::string& task_id, | |
112 const std::vector<GURL>& file_urls); | |
113 void RespondFailedOnUIThread(base::PlatformFileError error_code); | |
114 void ExecuteFileActionsOnUIThread(const std::string& task_id, | |
115 const std::string& file_system_name, | |
116 const GURL& file_system_root, | |
117 const FileDefinitionList& file_list); | |
118 void ExecuteFailedOnUIThread(); | |
119 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.executeTask"); | |
120 }; | |
121 | |
122 // Parent class for the chromium extension APIs for the file dialog. | |
123 class FileBrowserFunction | |
124 : public AsyncExtensionFunction { | |
125 public: | |
126 FileBrowserFunction(); | |
127 | |
128 protected: | |
129 typedef std::vector<GURL> UrlList; | |
130 typedef std::vector<FilePath> FilePathList; | |
131 typedef base::Callback<void(const FilePathList&)> GetLocalPathsCallback; | |
132 | |
133 virtual ~FileBrowserFunction(); | |
134 | |
135 // Converts virtual paths to local paths by calling GetLocalPathsOnFileThread | |
136 // on the file thread and call |callback| on the UI thread with the result. | |
137 void GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | |
138 const UrlList& file_urls, | |
139 GetLocalPathsCallback callback); | |
140 | |
141 // Figure out the tab_id of the hosting tab. | |
142 int32 GetTabId() const; | |
143 | |
144 private: | |
145 // Converts virtual paths to local paths and call |callback| (on the UI | |
146 // thread) with the results. | |
147 // This method must be called from the file thread. | |
148 void GetLocalPathsOnFileThread(const UrlList& file_urls, | |
149 GetLocalPathsCallback callback); | |
150 }; | |
151 | |
152 // Select a single file. Closes the dialog window. | |
153 class SelectFileFunction | |
154 : public FileBrowserFunction { | |
155 public: | |
156 SelectFileFunction() {} | |
157 | |
158 protected: | |
159 virtual ~SelectFileFunction() {} | |
160 | |
161 // AsyncExtensionFunction overrides. | |
162 virtual bool RunImpl() OVERRIDE; | |
163 | |
164 private: | |
165 // A callback method to handle the result of | |
166 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | |
167 void GetLocalPathsResponseOnUIThread(const FilePathList& files); | |
168 | |
169 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFile"); | |
170 }; | |
171 | |
172 // View multiple selected files. Window stays open. | |
173 class ViewFilesFunction | |
174 : public FileBrowserFunction { | |
175 public: | |
176 ViewFilesFunction(); | |
177 | |
178 protected: | |
179 virtual ~ViewFilesFunction(); | |
180 | |
181 // AsyncExtensionFunction overrides. | |
182 virtual bool RunImpl() OVERRIDE; | |
183 | |
184 private: | |
185 // A callback method to handle the result of | |
186 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | |
187 void GetLocalPathsResponseOnUIThread(const std::string& internal_task_id, | |
188 const FilePathList& files); | |
189 | |
190 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.viewFiles"); | |
191 }; | |
192 | |
193 // Select multiple files. Closes the dialog window. | |
194 class SelectFilesFunction | |
195 : public FileBrowserFunction { | |
196 public: | |
197 SelectFilesFunction(); | |
198 | |
199 protected: | |
200 virtual ~SelectFilesFunction(); | |
201 | |
202 // AsyncExtensionFunction overrides. | |
203 virtual bool RunImpl() OVERRIDE; | |
204 | |
205 private: | |
206 // A callback method to handle the result of | |
207 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | |
208 void GetLocalPathsResponseOnUIThread(const FilePathList& files); | |
209 | |
210 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFiles"); | |
211 }; | |
212 | |
213 // Cancel file selection Dialog. Closes the dialog window. | |
214 class CancelFileDialogFunction | |
215 : public FileBrowserFunction { | |
216 public: | |
217 CancelFileDialogFunction() {} | |
218 | |
219 protected: | |
220 virtual ~CancelFileDialogFunction() {} | |
221 | |
222 // AsyncExtensionFunction overrides. | |
223 virtual bool RunImpl() OVERRIDE; | |
224 | |
225 private: | |
226 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.cancelDialog"); | |
227 }; | |
228 | |
229 // Mount a device or a file. | |
230 class AddMountFunction | |
231 : public FileBrowserFunction { | |
232 public: | |
233 AddMountFunction(); | |
234 | |
235 protected: | |
236 virtual ~AddMountFunction(); | |
237 | |
238 // AsyncExtensionFunction overrides. | |
239 virtual bool RunImpl() OVERRIDE; | |
240 | |
241 private: | |
242 // A callback method to handle the result of | |
243 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | |
244 void GetLocalPathsResponseOnUIThread(const std::string& mount_type_str, | |
245 const FilePathList& files); | |
246 | |
247 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.addMount"); | |
248 }; | |
249 | |
250 // Unmounts selected device. Expects mount point path as an argument. | |
251 class RemoveMountFunction | |
252 : public FileBrowserFunction { | |
253 public: | |
254 RemoveMountFunction(); | |
255 | |
256 protected: | |
257 virtual ~RemoveMountFunction(); | |
258 | |
259 // AsyncExtensionFunction overrides. | |
260 virtual bool RunImpl() OVERRIDE; | |
261 | |
262 private: | |
263 // A callback method to handle the result of | |
264 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | |
265 void GetLocalPathsResponseOnUIThread(const FilePathList& files); | |
266 | |
267 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeMount"); | |
268 }; | |
269 | |
270 class GetMountPointsFunction | |
271 : public AsyncExtensionFunction { | |
272 public: | |
273 GetMountPointsFunction(); | |
274 | |
275 protected: | |
276 virtual ~GetMountPointsFunction(); | |
277 | |
278 // AsyncExtensionFunction overrides. | |
279 virtual bool RunImpl() OVERRIDE; | |
280 | |
281 private: | |
282 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getMountPoints"); | |
283 }; | |
284 | |
285 // Formats Device given its mount path. | |
286 class FormatDeviceFunction | |
287 : public FileBrowserFunction { | |
288 public: | |
289 FormatDeviceFunction(); | |
290 | |
291 protected: | |
292 virtual ~FormatDeviceFunction(); | |
293 | |
294 // AsyncExtensionFunction overrides. | |
295 virtual bool RunImpl() OVERRIDE; | |
296 | |
297 private: | |
298 // A callback method to handle the result of | |
299 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | |
300 void GetLocalPathsResponseOnUIThread(const FilePathList& files); | |
301 | |
302 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.formatDevice"); | |
303 }; | |
304 | |
305 class GetSizeStatsFunction | |
306 : public FileBrowserFunction { | |
307 public: | |
308 GetSizeStatsFunction(); | |
309 | |
310 protected: | |
311 virtual ~GetSizeStatsFunction(); | |
312 | |
313 // AsyncExtensionFunction overrides. | |
314 virtual bool RunImpl() OVERRIDE; | |
315 | |
316 private: | |
317 // A callback method to handle the result of | |
318 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. | |
319 void GetLocalPathsResponseOnUIThread(const FilePathList& files); | |
320 | |
321 void GetSizeStatsCallbackOnUIThread(const std::string& mount_path, | |
322 size_t total_size_kb, | |
323 size_t remaining_size_kb); | |
324 void CallGetSizeStatsOnFileThread(const std::string& mount_path); | |
325 | |
326 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getSizeStats"); | |
327 }; | |
328 | |
329 // Retrieves devices meta-data. Expects volume's device path as an argument. | |
330 class GetVolumeMetadataFunction | |
331 : public SyncExtensionFunction { | |
332 public: | |
333 GetVolumeMetadataFunction(); | |
334 | |
335 protected: | |
336 virtual ~GetVolumeMetadataFunction(); | |
337 | |
338 virtual bool RunImpl() OVERRIDE; | |
339 | |
340 private: | |
341 #if defined(OS_CHROMEOS) | |
342 std::string DeviceTypeToString(chromeos::DeviceType type); | |
343 #endif | |
344 | |
345 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getVolumeMetadata"); | |
346 }; | |
347 | |
348 // File Dialog Strings. | |
349 class FileDialogStringsFunction : public SyncExtensionFunction { | |
350 public: | |
351 FileDialogStringsFunction() {} | |
352 | |
353 protected: | |
354 virtual ~FileDialogStringsFunction() {} | |
355 | |
356 // SyncExtensionFunction overrides. | |
357 virtual bool RunImpl() OVERRIDE; | |
358 | |
359 private: | |
360 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getStrings"); | |
361 }; | |
362 | |
363 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EXTENSION_API_H_ | |
OLD | NEW |