Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 14 #include "chrome/browser/extensions/extension_function.h" | 14 #include "chrome/browser/extensions/extension_function.h" |
| 15 #include "chrome/browser/ui/shell_dialogs.h" | 15 #include "chrome/browser/ui/shell_dialogs.h" |
| 16 #include "googleurl/src/url_util.h" | 16 #include "googleurl/src/url_util.h" |
| 17 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 17 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 18 | 18 |
| 19 #ifdef OS_CHROMEOS | 19 #ifdef OS_CHROMEOS |
| 20 #include "chrome/browser/chromeos/cros/mount_library.h" | 20 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 class GURL; | 23 class GURL; |
| 24 | 24 |
| 25 // Implements the chrome.fileBrowserPrivate.requestLocalFileSystem method. | 25 // Implements the chrome.fileBrowserPrivate.requestLocalFileSystem method. |
| 26 class RequestLocalFileSystemFunction : public AsyncExtensionFunction { | 26 class RequestLocalFileSystemFunction : public AsyncExtensionFunction { |
| 27 protected: | 27 protected: |
| 28 friend class LocalFileSystemCallbackDispatcher; | |
| 29 // AsyncExtensionFunction overrides. | 28 // AsyncExtensionFunction overrides. |
| 30 virtual bool RunImpl() OVERRIDE; | 29 virtual bool RunImpl() OVERRIDE; |
| 30 | |
| 31 private: | |
| 32 class LocalFileSystemCallbackDispatcher; | |
| 33 | |
| 31 void RespondSuccessOnUIThread(const std::string& name, | 34 void RespondSuccessOnUIThread(const std::string& name, |
| 32 const GURL& root_path); | 35 const GURL& root_path); |
| 33 void RespondFailedOnUIThread(base::PlatformFileError error_code); | 36 void RespondFailedOnUIThread(base::PlatformFileError error_code); |
| 34 void RequestOnFileThread(const GURL& source_url, int child_id); | 37 void RequestOnFileThread(const GURL& source_url, int child_id); |
| 35 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.requestLocalFileSystem"); | 38 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.requestLocalFileSystem"); |
| 36 }; | 39 }; |
| 37 | 40 |
| 38 // Implements the chrome.fileBrowserPrivate.addFileWatch method. | 41 // Implements the chrome.fileBrowserPrivate.addFileWatch method. |
| 39 class FileWatchBrowserFunctionBase : public AsyncExtensionFunction { | 42 class FileWatchBrowserFunctionBase : public AsyncExtensionFunction { |
| 40 protected: | 43 protected: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 // AsyncExtensionFunction overrides. | 96 // AsyncExtensionFunction overrides. |
| 94 virtual bool RunImpl() OVERRIDE; | 97 virtual bool RunImpl() OVERRIDE; |
| 95 | 98 |
| 96 private: | 99 private: |
| 97 struct FileDefinition { | 100 struct FileDefinition { |
| 98 GURL target_file_url; | 101 GURL target_file_url; |
| 99 FilePath virtual_path; | 102 FilePath virtual_path; |
| 100 bool is_directory; | 103 bool is_directory; |
| 101 }; | 104 }; |
| 102 typedef std::vector<FileDefinition> FileDefinitionList; | 105 typedef std::vector<FileDefinition> FileDefinitionList; |
| 103 friend class ExecuteTasksFileSystemCallbackDispatcher; | 106 class ExecuteTasksFileSystemCallbackDispatcher; |
| 104 // Initates execution of context menu tasks identified with |task_id| for | 107 // Initates execution of context menu tasks identified with |task_id| for |
| 105 // each element of |files_list|. | 108 // each element of |files_list|. |
| 106 bool InitiateFileTaskExecution(const std::string& task_id, | 109 bool InitiateFileTaskExecution(const std::string& task_id, |
| 107 base::ListValue* files_list); | 110 base::ListValue* files_list); |
| 108 void RequestFileEntryOnFileThread(const GURL& source_url, | 111 void RequestFileEntryOnFileThread(const GURL& source_url, |
| 109 const std::string& task_id, | 112 const std::string& task_id, |
| 110 const std::vector<GURL>& file_urls); | 113 const std::vector<GURL>& file_urls); |
| 111 void RespondFailedOnUIThread(base::PlatformFileError error_code); | 114 void RespondFailedOnUIThread(base::PlatformFileError error_code); |
| 112 void ExecuteFileActionsOnUIThread(const std::string& task_id, | 115 void ExecuteFileActionsOnUIThread(const std::string& task_id, |
| 113 const std::string& file_system_name, | 116 const std::string& file_system_name, |
| 114 const GURL& file_system_root, | 117 const GURL& file_system_root, |
| 115 const FileDefinitionList& file_list); | 118 const FileDefinitionList& file_list); |
| 116 void ExecuteFailedOnUIThread(); | 119 void ExecuteFailedOnUIThread(); |
| 117 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.executeTask"); | 120 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.executeTask"); |
| 118 }; | 121 }; |
| 119 | 122 |
| 120 // Parent class for the chromium extension APIs for the file dialog. | 123 // Parent class for the chromium extension APIs for the file dialog. |
| 121 class FileBrowserFunction | 124 class FileBrowserFunction |
| 122 : public AsyncExtensionFunction { | 125 : public AsyncExtensionFunction { |
| 123 public: | 126 public: |
| 124 FileBrowserFunction(); | 127 FileBrowserFunction(); |
| 125 | 128 |
| 126 protected: | 129 protected: |
| 127 typedef std::vector<GURL> UrlList; | 130 typedef std::vector<GURL> UrlList; |
| 128 typedef std::vector<FilePath> FilePathList; | 131 typedef std::vector<FilePath> FilePathList; |
| 132 typedef base::Callback<void(const FilePathList&)> GetLocalPathsCallback; | |
| 129 | 133 |
| 130 virtual ~FileBrowserFunction(); | 134 virtual ~FileBrowserFunction(); |
| 131 | 135 |
| 132 // Convert virtual paths to local paths on the file thread. | 136 // Convert virtual paths to local paths |
|
satorux1
2011/11/16 06:46:06
period is missing. looking at the implementation,
hashimoto
2011/11/16 07:45:32
Done.
| |
| 133 void GetLocalPathsOnFileThread(const UrlList& file_urls, | 137 void GetLocalPaths(const UrlList& file_urls, GetLocalPathsCallback callback); |
| 134 void* context); | |
| 135 | |
| 136 // Callback with converted local paths. | |
| 137 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, | |
| 138 void* context) {} | |
| 139 | 138 |
| 140 // Figure out the tab_id of the hosting tab. | 139 // Figure out the tab_id of the hosting tab. |
| 141 int32 GetTabId() const; | 140 int32 GetTabId() const; |
| 141 | |
| 142 private: | |
| 143 void GetLocalPathsOnFileThread(const UrlList& file_urls, | |
|
satorux1
2011/11/16 06:46:06
function comment is missing.
hashimoto
2011/11/16 07:45:32
Done.
| |
| 144 GetLocalPathsCallback callback); | |
| 142 }; | 145 }; |
| 143 | 146 |
| 144 // Select a single file. Closes the dialog window. | 147 // Select a single file. Closes the dialog window. |
| 145 class SelectFileFunction | 148 class SelectFileFunction |
| 146 : public FileBrowserFunction { | 149 : public FileBrowserFunction { |
| 147 public: | 150 public: |
| 148 SelectFileFunction() {} | 151 SelectFileFunction() {} |
| 149 | 152 |
| 150 protected: | 153 protected: |
| 151 virtual ~SelectFileFunction() {} | 154 virtual ~SelectFileFunction() {} |
| 152 | 155 |
| 153 // AsyncExtensionFunction overrides. | 156 // AsyncExtensionFunction overrides. |
| 154 virtual bool RunImpl() OVERRIDE; | 157 virtual bool RunImpl() OVERRIDE; |
| 155 | 158 |
| 156 // FileBrowserFunction overrides. | 159 private: |
| 157 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, | 160 void GetLocalPathsResponseOnUIThread(const FilePathList& files); |
|
satorux1
2011/11/16 06:46:06
ditto.
hashimoto
2011/11/16 07:45:32
Done.
| |
| 158 void* context) OVERRIDE; | |
| 159 | 161 |
| 160 private: | |
| 161 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFile"); | 162 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFile"); |
| 162 }; | 163 }; |
| 163 | 164 |
| 164 // View multiple selected files. Window stays open. | 165 // View multiple selected files. Window stays open. |
| 165 class ViewFilesFunction | 166 class ViewFilesFunction |
| 166 : public FileBrowserFunction { | 167 : public FileBrowserFunction { |
| 167 public: | 168 public: |
| 168 ViewFilesFunction(); | 169 ViewFilesFunction(); |
| 169 | 170 |
| 170 protected: | 171 protected: |
| 171 virtual ~ViewFilesFunction(); | 172 virtual ~ViewFilesFunction(); |
| 172 | 173 |
| 173 // AsyncExtensionFunction overrides. | 174 // AsyncExtensionFunction overrides. |
| 174 virtual bool RunImpl() OVERRIDE; | 175 virtual bool RunImpl() OVERRIDE; |
| 175 | 176 |
| 176 // FileBrowserFunction overrides. | 177 private: |
| 177 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, | 178 void GetLocalPathsResponseOnUIThread(const std::string& internal_task_id, |
|
satorux1
2011/11/16 06:46:06
ditto.
hashimoto
2011/11/16 07:45:32
Done.
| |
| 178 void* context) OVERRIDE; | 179 const FilePathList& files); |
| 179 | 180 |
| 180 private: | |
| 181 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.viewFiles"); | 181 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.viewFiles"); |
| 182 }; | 182 }; |
| 183 | 183 |
| 184 // Select multiple files. Closes the dialog window. | 184 // Select multiple files. Closes the dialog window. |
| 185 class SelectFilesFunction | 185 class SelectFilesFunction |
| 186 : public FileBrowserFunction { | 186 : public FileBrowserFunction { |
| 187 public: | 187 public: |
| 188 SelectFilesFunction(); | 188 SelectFilesFunction(); |
| 189 | 189 |
| 190 protected: | 190 protected: |
| 191 virtual ~SelectFilesFunction(); | 191 virtual ~SelectFilesFunction(); |
| 192 | 192 |
| 193 // AsyncExtensionFunction overrides. | 193 // AsyncExtensionFunction overrides. |
| 194 virtual bool RunImpl() OVERRIDE; | 194 virtual bool RunImpl() OVERRIDE; |
| 195 | 195 |
| 196 // FileBrowserFunction overrides. | 196 private: |
| 197 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, | 197 void GetLocalPathsResponseOnUIThread(const FilePathList& files); |
|
satorux1
2011/11/16 06:46:06
ditto
hashimoto
2011/11/16 07:45:32
Done.
| |
| 198 void* context) OVERRIDE; | |
| 199 | 198 |
| 200 private: | |
| 201 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFiles"); | 199 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFiles"); |
| 202 }; | 200 }; |
| 203 | 201 |
| 204 // Cancel file selection Dialog. Closes the dialog window. | 202 // Cancel file selection Dialog. Closes the dialog window. |
| 205 class CancelFileDialogFunction | 203 class CancelFileDialogFunction |
| 206 : public FileBrowserFunction { | 204 : public FileBrowserFunction { |
| 207 public: | 205 public: |
| 208 CancelFileDialogFunction() {} | 206 CancelFileDialogFunction() {} |
| 209 | 207 |
| 210 protected: | 208 protected: |
| 211 virtual ~CancelFileDialogFunction() {} | 209 virtual ~CancelFileDialogFunction() {} |
| 212 | 210 |
| 213 // AsyncExtensionFunction overrides. | 211 // AsyncExtensionFunction overrides. |
| 214 virtual bool RunImpl() OVERRIDE; | 212 virtual bool RunImpl() OVERRIDE; |
| 215 | 213 |
| 216 private: | 214 private: |
| 217 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.cancelDialog"); | 215 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.cancelDialog"); |
| 218 }; | 216 }; |
| 219 | 217 |
| 220 // Mount a device or a file. | 218 // Mount a device or a file. |
| 221 class AddMountFunction | 219 class AddMountFunction |
| 222 : public FileBrowserFunction { | 220 : public FileBrowserFunction { |
| 223 public: | 221 public: |
| 224 AddMountFunction(); | 222 AddMountFunction(); |
| 225 | 223 |
| 226 protected: | 224 protected: |
| 227 virtual ~AddMountFunction(); | 225 virtual ~AddMountFunction(); |
| 228 | 226 |
| 227 // AsyncExtensionFunction overrides. | |
| 229 virtual bool RunImpl() OVERRIDE; | 228 virtual bool RunImpl() OVERRIDE; |
| 230 | 229 |
| 231 // FileBrowserFunction overrides. | |
| 232 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, | |
| 233 void* context) OVERRIDE; | |
| 234 | |
| 235 private: | 230 private: |
| 236 #if defined(OS_CHROMEOS) | 231 void GetLocalPathsResponseOnUIThread(const std::string& mount_type_str, |
| 237 struct MountParamaters { | 232 const FilePathList& files); |
| 238 MountParamaters(const std::string& type, | |
| 239 const chromeos::MountPathOptions& options) | |
| 240 : mount_type(type), mount_options(options) {} | |
| 241 ~MountParamaters() {} | |
| 242 std::string mount_type; | |
| 243 chromeos::MountPathOptions mount_options; | |
| 244 }; | |
| 245 #endif | |
| 246 | 233 |
| 247 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.addMount"); | 234 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.addMount"); |
| 248 }; | 235 }; |
| 249 | 236 |
| 250 // Unmounts selected device. Expects mount point path as an argument. | 237 // Unmounts selected device. Expects mount point path as an argument. |
| 251 class RemoveMountFunction | 238 class RemoveMountFunction |
| 252 : public FileBrowserFunction { | 239 : public FileBrowserFunction { |
| 253 public: | 240 public: |
| 254 RemoveMountFunction(); | 241 RemoveMountFunction(); |
| 255 | 242 |
| 256 protected: | 243 protected: |
| 257 virtual ~RemoveMountFunction(); | 244 virtual ~RemoveMountFunction(); |
| 258 | 245 |
| 259 // FileBrowserFunction overrides. | 246 // AsyncExtensionFunction overrides. |
| 260 virtual bool RunImpl() OVERRIDE; | 247 virtual bool RunImpl() OVERRIDE; |
| 261 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, | |
| 262 void* context) OVERRIDE; | |
| 263 | 248 |
| 264 private: | 249 private: |
| 250 void GetLocalPathsResponseOnUIThread(const FilePathList& files); | |
| 251 | |
| 265 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeMount"); | 252 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeMount"); |
| 266 }; | 253 }; |
| 267 | 254 |
| 268 class GetMountPointsFunction | 255 class GetMountPointsFunction |
| 269 : public AsyncExtensionFunction { | 256 : public AsyncExtensionFunction { |
| 270 public: | 257 public: |
| 271 GetMountPointsFunction(); | 258 GetMountPointsFunction(); |
| 272 | 259 |
| 273 protected: | 260 protected: |
| 274 virtual ~GetMountPointsFunction(); | 261 virtual ~GetMountPointsFunction(); |
| 275 | 262 |
| 263 // AsyncExtensionFunction overrides. | |
| 276 virtual bool RunImpl() OVERRIDE; | 264 virtual bool RunImpl() OVERRIDE; |
| 277 | 265 |
| 278 private: | 266 private: |
| 279 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getMountPoints"); | 267 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getMountPoints"); |
| 280 }; | 268 }; |
| 281 | 269 |
| 282 // Formats Device given its mount path. | 270 // Formats Device given its mount path. |
| 283 class FormatDeviceFunction | 271 class FormatDeviceFunction |
| 284 : public FileBrowserFunction { | 272 : public FileBrowserFunction { |
| 285 public: | 273 public: |
| 286 FormatDeviceFunction(); | 274 FormatDeviceFunction(); |
| 287 | 275 |
| 288 protected: | 276 protected: |
| 289 virtual ~FormatDeviceFunction(); | 277 virtual ~FormatDeviceFunction(); |
| 290 | 278 |
| 279 // AsyncExtensionFunction overrides. | |
| 291 virtual bool RunImpl() OVERRIDE; | 280 virtual bool RunImpl() OVERRIDE; |
| 292 | 281 |
| 293 // FileBrowserFunction overrides. | 282 private: |
| 294 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, | 283 void GetLocalPathsResponseOnUIThread(const FilePathList& files); |
| 295 void* context) OVERRIDE; | |
| 296 | 284 |
| 297 private: | |
| 298 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.formatDevice"); | 285 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.formatDevice"); |
| 299 }; | 286 }; |
| 300 | 287 |
| 301 class GetSizeStatsFunction | 288 class GetSizeStatsFunction |
| 302 : public FileBrowserFunction { | 289 : public FileBrowserFunction { |
| 303 public: | 290 public: |
| 304 GetSizeStatsFunction(); | 291 GetSizeStatsFunction(); |
| 305 | 292 |
| 306 protected: | 293 protected: |
| 307 virtual ~GetSizeStatsFunction(); | 294 virtual ~GetSizeStatsFunction(); |
| 308 | 295 |
| 309 // FileBrowserFunction overrides. | 296 // AsyncExtensionFunction overrides. |
| 310 virtual bool RunImpl() OVERRIDE; | 297 virtual bool RunImpl() OVERRIDE; |
| 311 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, | |
| 312 void* context) OVERRIDE; | |
| 313 | 298 |
| 314 private: | 299 private: |
| 315 void GetSizeStatsCallbackOnUIThread(const char* mount_path, | 300 void GetLocalPathsResponseOnUIThread(const FilePathList& files); |
| 301 | |
| 302 void GetSizeStatsCallbackOnUIThread(const std::string& mount_path, | |
| 316 size_t total_size_kb, | 303 size_t total_size_kb, |
| 317 size_t remaining_size_kb); | 304 size_t remaining_size_kb); |
| 318 void CallGetSizeStatsOnFileThread(const char* mount_path); | 305 void CallGetSizeStatsOnFileThread(const std::string& mount_path); |
| 319 | 306 |
| 320 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getSizeStats"); | 307 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getSizeStats"); |
| 321 }; | 308 }; |
| 322 | 309 |
| 323 // Retrieves devices meta-data. Expects volume's device path as an argument. | 310 // Retrieves devices meta-data. Expects volume's device path as an argument. |
| 324 class GetVolumeMetadataFunction | 311 class GetVolumeMetadataFunction |
| 325 : public SyncExtensionFunction { | 312 : public SyncExtensionFunction { |
| 326 public: | 313 public: |
| 327 GetVolumeMetadataFunction(); | 314 GetVolumeMetadataFunction(); |
| 328 | 315 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 348 virtual ~FileDialogStringsFunction() {} | 335 virtual ~FileDialogStringsFunction() {} |
| 349 | 336 |
| 350 // SyncExtensionFunction overrides. | 337 // SyncExtensionFunction overrides. |
| 351 virtual bool RunImpl() OVERRIDE; | 338 virtual bool RunImpl() OVERRIDE; |
| 352 | 339 |
| 353 private: | 340 private: |
| 354 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getStrings"); | 341 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getStrings"); |
| 355 }; | 342 }; |
| 356 | 343 |
| 357 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ | 344 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ |
| OLD | NEW |