| 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_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/extensions/extension_function.h" | 8 #include "chrome/browser/extensions/extension_function.h" |
| 9 #include "chrome/common/extensions/api/file_system.h" | 9 #include "chrome/common/extensions/api/file_system.h" |
| 10 #include "ui/shell_dialogs/select_file_dialog.h" | 10 #include "ui/shell_dialogs/select_file_dialog.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 virtual bool RunImpl() OVERRIDE; | 43 virtual bool RunImpl() OVERRIDE; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class FileSystemEntryFunction : public AsyncExtensionFunction { | 46 class FileSystemEntryFunction : public AsyncExtensionFunction { |
| 47 protected: | 47 protected: |
| 48 enum EntryType { | 48 enum EntryType { |
| 49 READ_ONLY, | 49 READ_ONLY, |
| 50 WRITABLE | 50 WRITABLE |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 FileSystemEntryFunction(); |
| 54 |
| 53 virtual ~FileSystemEntryFunction() {} | 55 virtual ~FileSystemEntryFunction() {} |
| 54 | 56 |
| 55 bool HasFileSystemWritePermission(); | 57 bool HasFileSystemWritePermission(); |
| 56 | 58 |
| 57 // This is called when a writable file entry is being returned. The function | 59 // This is called when writable file entries are being returned. The function |
| 58 // will ensure the file exists, creating it if necessary, and also check that | 60 // will ensure the files exist, creating them if necessary, and also check |
| 59 // the file is not a link. If it succeeds it proceeds to | 61 // that none of the files are links. If it succeeds it proceeds to |
| 60 // RegisterFileSystemAndSendResponse, otherwise to HandleWritableFileError. | 62 // RegisterFileSystemsAndSendResponse, otherwise to HandleWritableFileError. |
| 61 void CheckWritableFile(const base::FilePath& path); | 63 void CheckWritableFiles(const std::vector<base::FilePath>& path); |
| 62 | 64 |
| 63 // This will finish the choose file process. This is either called directly | 65 // This will finish the choose file process. This is either called directly |
| 64 // from FileSelected, or from CreateFileIfNecessary. It is called on the UI | 66 // from FilesSelected, or from WritableFileChecker. It is called on the UI |
| 65 // thread. | 67 // thread. |
| 66 void RegisterFileSystemAndSendResponse(const base::FilePath& path, | 68 void RegisterFileSystemsAndSendResponse( |
| 67 EntryType entry_type); | 69 const std::vector<base::FilePath>& path); |
| 68 | 70 |
| 69 // This will finish the choose file process. This is either called directly | 71 // Creates a response dictionary and sets it as the response to be sent. |
| 70 // from FileSelected, or from CreateFileIfNecessary. It is called on the UI | 72 void CreateResponse(); |
| 71 // thread. |id_override| specifies the id to send in the response instead of | 73 |
| 72 // the generated id. This can be useful for creating a file entry with an id | 74 // Adds an entry to the response dictionary. |
| 73 // matching another file entry, e.g. for restoreEntry. | 75 void AddEntryToResponse(const base::FilePath& path, const std::string& id); |
| 74 void RegisterFileSystemAndSendResponseWithIdOverride( | |
| 75 const base::FilePath& path, | |
| 76 EntryType entry_type, | |
| 77 const std::string& id_override); | |
| 78 | 76 |
| 79 // called on the UI thread if there is a problem checking a writable file. | 77 // called on the UI thread if there is a problem checking a writable file. |
| 80 void HandleWritableFileError(); | 78 void HandleWritableFileError(const std::string& error); |
| 79 |
| 80 // Whether multiple entries have been requested. |
| 81 bool multiple_; |
| 82 |
| 83 // The type of the entry or entries to return. |
| 84 EntryType entry_type_; |
| 85 |
| 86 // The dictionary to send as the response. |
| 87 base::DictionaryValue* response_; |
| 81 }; | 88 }; |
| 82 | 89 |
| 83 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { | 90 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { |
| 84 public: | 91 public: |
| 85 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", | 92 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", |
| 86 FILESYSTEM_GETWRITABLEENTRY) | 93 FILESYSTEM_GETWRITABLEENTRY) |
| 87 | 94 |
| 88 protected: | 95 protected: |
| 89 virtual ~FileSystemGetWritableEntryFunction() {} | 96 virtual ~FileSystemGetWritableEntryFunction() {} |
| 90 virtual bool RunImpl() OVERRIDE; | 97 virtual bool RunImpl() OVERRIDE; |
| 91 }; | 98 }; |
| 92 | 99 |
| 93 class FileSystemIsWritableEntryFunction : public SyncExtensionFunction { | 100 class FileSystemIsWritableEntryFunction : public SyncExtensionFunction { |
| 94 public: | 101 public: |
| 95 DECLARE_EXTENSION_FUNCTION("fileSystem.isWritableEntry", | 102 DECLARE_EXTENSION_FUNCTION("fileSystem.isWritableEntry", |
| 96 FILESYSTEM_ISWRITABLEENTRY) | 103 FILESYSTEM_ISWRITABLEENTRY) |
| 97 | 104 |
| 98 protected: | 105 protected: |
| 99 virtual ~FileSystemIsWritableEntryFunction() {} | 106 virtual ~FileSystemIsWritableEntryFunction() {} |
| 100 virtual bool RunImpl() OVERRIDE; | 107 virtual bool RunImpl() OVERRIDE; |
| 101 }; | 108 }; |
| 102 | 109 |
| 103 class FileSystemChooseEntryFunction : public FileSystemEntryFunction { | 110 class FileSystemChooseEntryFunction : public FileSystemEntryFunction { |
| 104 public: | 111 public: |
| 105 // Allow picker UI to be skipped in testing. | 112 // Allow picker UI to be skipped in testing. |
| 106 static void SkipPickerAndAlwaysSelectPathForTest(base::FilePath* path); | 113 static void SkipPickerAndAlwaysSelectPathForTest(base::FilePath* path); |
| 114 static void SkipPickerAndAlwaysSelectPathsForTest( |
| 115 std::vector<base::FilePath>* paths); |
| 107 static void SkipPickerAndSelectSuggestedPathForTest(); | 116 static void SkipPickerAndSelectSuggestedPathForTest(); |
| 108 static void SkipPickerAndAlwaysCancelForTest(); | 117 static void SkipPickerAndAlwaysCancelForTest(); |
| 109 static void StopSkippingPickerForTest(); | 118 static void StopSkippingPickerForTest(); |
| 110 // Call this with the directory for test file paths. On Chrome OS, accessed | 119 // Call this with the directory for test file paths. On Chrome OS, accessed |
| 111 // path needs to be explicitly registered for smooth integration with Google | 120 // path needs to be explicitly registered for smooth integration with Google |
| 112 // Drive support. | 121 // Drive support. |
| 113 static void RegisterTempExternalFileSystemForTest(const std::string& name, | 122 static void RegisterTempExternalFileSystemForTest(const std::string& name, |
| 114 const base::FilePath& path); | 123 const base::FilePath& path); |
| 115 | 124 |
| 116 DECLARE_EXTENSION_FUNCTION("fileSystem.chooseEntry", FILESYSTEM_CHOOSEENTRY) | 125 DECLARE_EXTENSION_FUNCTION("fileSystem.chooseEntry", FILESYSTEM_CHOOSEENTRY) |
| 117 | 126 |
| 118 typedef std::vector<linked_ptr<extensions::api::file_system::AcceptOption> > | 127 typedef std::vector<linked_ptr<extensions::api::file_system::AcceptOption> > |
| 119 AcceptOptions; | 128 AcceptOptions; |
| 120 | 129 |
| 121 static void BuildFileTypeInfo( | 130 static void BuildFileTypeInfo( |
| 122 ui::SelectFileDialog::FileTypeInfo* file_type_info, | 131 ui::SelectFileDialog::FileTypeInfo* file_type_info, |
| 123 const base::FilePath::StringType& suggested_extension, | 132 const base::FilePath::StringType& suggested_extension, |
| 124 const AcceptOptions* accepts, | 133 const AcceptOptions* accepts, |
| 125 const bool* acceptsAllTypes); | 134 const bool* acceptsAllTypes); |
| 126 static void BuildSuggestion(const std::string* opt_name, | 135 static void BuildSuggestion(const std::string* opt_name, |
| 127 base::FilePath* suggested_name, | 136 base::FilePath* suggested_name, |
| 128 base::FilePath::StringType* suggested_extension); | 137 base::FilePath::StringType* suggested_extension); |
| 129 | 138 |
| 130 protected: | 139 protected: |
| 131 class FilePicker; | 140 class FilePicker; |
| 132 | 141 |
| 133 virtual ~FileSystemChooseEntryFunction() {} | 142 virtual ~FileSystemChooseEntryFunction() {} |
| 134 virtual bool RunImpl() OVERRIDE; | 143 virtual bool RunImpl() OVERRIDE; |
| 135 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info, | 144 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info, |
| 136 ui::SelectFileDialog::Type picker_type, | 145 ui::SelectFileDialog::Type picker_type); |
| 137 EntryType entry_type); | |
| 138 | 146 |
| 139 private: | 147 private: |
| 140 void SetInitialPathOnFileThread(const base::FilePath& suggested_name, | 148 void SetInitialPathOnFileThread(const base::FilePath& suggested_name, |
| 141 const base::FilePath& previous_path); | 149 const base::FilePath& previous_path); |
| 142 | 150 |
| 143 // FileSelected and FileSelectionCanceled are called by the file picker. | 151 // FilesSelected and FileSelectionCanceled are called by the file picker. |
| 144 void FileSelected(const base::FilePath& path, EntryType entry_type); | 152 void FilesSelected(const std::vector<base::FilePath>& path); |
| 145 void FileSelectionCanceled(); | 153 void FileSelectionCanceled(); |
| 146 | 154 |
| 147 base::FilePath initial_path_; | 155 base::FilePath initial_path_; |
| 148 }; | 156 }; |
| 149 | 157 |
| 150 class FileSystemRetainEntryFunction : public SyncExtensionFunction { | 158 class FileSystemRetainEntryFunction : public SyncExtensionFunction { |
| 151 public: | 159 public: |
| 152 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY) | 160 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY) |
| 153 | 161 |
| 154 protected: | 162 protected: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 175 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY) | 183 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY) |
| 176 | 184 |
| 177 protected: | 185 protected: |
| 178 virtual ~FileSystemRestoreEntryFunction() {} | 186 virtual ~FileSystemRestoreEntryFunction() {} |
| 179 virtual bool RunImpl() OVERRIDE; | 187 virtual bool RunImpl() OVERRIDE; |
| 180 }; | 188 }; |
| 181 | 189 |
| 182 } // namespace extensions | 190 } // namespace extensions |
| 183 | 191 |
| 184 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 192 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
| OLD | NEW |