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, |
74 void RegisterFileSystemAndSendResponseWithIdOverride( | 76 const std::string& id_override); |
75 const base::FilePath& path, | |
76 EntryType entry_type, | |
77 const std::string& id_override); | |
78 | 77 |
79 // called on the UI thread if there is a problem checking a writable file. | 78 // called on the UI thread if there is a problem checking a writable file. |
80 void HandleWritableFileError(); | 79 void HandleWritableFileError(const std::string& error); |
| 80 |
| 81 // Whether multiple entries have been requested. |
| 82 bool multiple_; |
| 83 |
| 84 // The type of the entry or entries to return. |
| 85 EntryType entry_type_; |
| 86 |
| 87 // The dictionary to send as the response. |
| 88 base::DictionaryValue* response_; |
81 }; | 89 }; |
82 | 90 |
83 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { | 91 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { |
84 public: | 92 public: |
85 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", | 93 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", |
86 FILESYSTEM_GETWRITABLEENTRY) | 94 FILESYSTEM_GETWRITABLEENTRY) |
87 | 95 |
88 protected: | 96 protected: |
89 virtual ~FileSystemGetWritableEntryFunction() {} | 97 virtual ~FileSystemGetWritableEntryFunction() {} |
90 virtual bool RunImpl() OVERRIDE; | 98 virtual bool RunImpl() OVERRIDE; |
91 }; | 99 }; |
92 | 100 |
93 class FileSystemIsWritableEntryFunction : public SyncExtensionFunction { | 101 class FileSystemIsWritableEntryFunction : public SyncExtensionFunction { |
94 public: | 102 public: |
95 DECLARE_EXTENSION_FUNCTION("fileSystem.isWritableEntry", | 103 DECLARE_EXTENSION_FUNCTION("fileSystem.isWritableEntry", |
96 FILESYSTEM_ISWRITABLEENTRY) | 104 FILESYSTEM_ISWRITABLEENTRY) |
97 | 105 |
98 protected: | 106 protected: |
99 virtual ~FileSystemIsWritableEntryFunction() {} | 107 virtual ~FileSystemIsWritableEntryFunction() {} |
100 virtual bool RunImpl() OVERRIDE; | 108 virtual bool RunImpl() OVERRIDE; |
101 }; | 109 }; |
102 | 110 |
103 class FileSystemChooseEntryFunction : public FileSystemEntryFunction { | 111 class FileSystemChooseEntryFunction : public FileSystemEntryFunction { |
104 public: | 112 public: |
105 // Allow picker UI to be skipped in testing. | 113 // Allow picker UI to be skipped in testing. |
106 static void SkipPickerAndAlwaysSelectPathForTest(base::FilePath* path); | 114 static void SkipPickerAndAlwaysSelectPathForTest(base::FilePath* path); |
| 115 static void SkipPickerAndAlwaysSelectPathsForTest( |
| 116 std::vector<base::FilePath>* paths); |
107 static void SkipPickerAndSelectSuggestedPathForTest(); | 117 static void SkipPickerAndSelectSuggestedPathForTest(); |
108 static void SkipPickerAndAlwaysCancelForTest(); | 118 static void SkipPickerAndAlwaysCancelForTest(); |
109 static void StopSkippingPickerForTest(); | 119 static void StopSkippingPickerForTest(); |
110 // Call this with the directory for test file paths. On Chrome OS, accessed | 120 // 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 | 121 // path needs to be explicitly registered for smooth integration with Google |
112 // Drive support. | 122 // Drive support. |
113 static void RegisterTempExternalFileSystemForTest(const std::string& name, | 123 static void RegisterTempExternalFileSystemForTest(const std::string& name, |
114 const base::FilePath& path); | 124 const base::FilePath& path); |
115 | 125 |
116 DECLARE_EXTENSION_FUNCTION("fileSystem.chooseEntry", FILESYSTEM_CHOOSEENTRY) | 126 DECLARE_EXTENSION_FUNCTION("fileSystem.chooseEntry", FILESYSTEM_CHOOSEENTRY) |
117 | 127 |
118 typedef std::vector<linked_ptr<extensions::api::file_system::AcceptOption> > | 128 typedef std::vector<linked_ptr<extensions::api::file_system::AcceptOption> > |
119 AcceptOptions; | 129 AcceptOptions; |
120 | 130 |
121 static void BuildFileTypeInfo( | 131 static void BuildFileTypeInfo( |
122 ui::SelectFileDialog::FileTypeInfo* file_type_info, | 132 ui::SelectFileDialog::FileTypeInfo* file_type_info, |
123 const base::FilePath::StringType& suggested_extension, | 133 const base::FilePath::StringType& suggested_extension, |
124 const AcceptOptions* accepts, | 134 const AcceptOptions* accepts, |
125 const bool* acceptsAllTypes); | 135 const bool* acceptsAllTypes); |
126 static void BuildSuggestion(const std::string* opt_name, | 136 static void BuildSuggestion(const std::string* opt_name, |
127 base::FilePath* suggested_name, | 137 base::FilePath* suggested_name, |
128 base::FilePath::StringType* suggested_extension); | 138 base::FilePath::StringType* suggested_extension); |
129 | 139 |
130 protected: | 140 protected: |
131 class FilePicker; | 141 class FilePicker; |
132 | 142 |
133 virtual ~FileSystemChooseEntryFunction() {} | 143 virtual ~FileSystemChooseEntryFunction() {} |
134 virtual bool RunImpl() OVERRIDE; | 144 virtual bool RunImpl() OVERRIDE; |
135 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info, | 145 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info, |
136 ui::SelectFileDialog::Type picker_type, | 146 ui::SelectFileDialog::Type picker_type); |
137 EntryType entry_type); | |
138 | 147 |
139 private: | 148 private: |
140 void SetInitialPathOnFileThread(const base::FilePath& suggested_name, | 149 void SetInitialPathOnFileThread(const base::FilePath& suggested_name, |
141 const base::FilePath& previous_path); | 150 const base::FilePath& previous_path); |
142 | 151 |
143 // FileSelected and FileSelectionCanceled are called by the file picker. | 152 // FilesSelected and FileSelectionCanceled are called by the file picker. |
144 void FileSelected(const base::FilePath& path, EntryType entry_type); | 153 void FilesSelected(const std::vector<base::FilePath>& path); |
145 void FileSelectionCanceled(); | 154 void FileSelectionCanceled(); |
146 | 155 |
147 base::FilePath initial_path_; | 156 base::FilePath initial_path_; |
148 }; | 157 }; |
149 | 158 |
150 class FileSystemRetainEntryFunction : public SyncExtensionFunction { | 159 class FileSystemRetainEntryFunction : public SyncExtensionFunction { |
151 public: | 160 public: |
152 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY) | 161 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY) |
153 | 162 |
154 protected: | 163 protected: |
(...skipping 20 matching lines...) Expand all Loading... |
175 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY) | 184 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY) |
176 | 185 |
177 protected: | 186 protected: |
178 virtual ~FileSystemRestoreEntryFunction() {} | 187 virtual ~FileSystemRestoreEntryFunction() {} |
179 virtual bool RunImpl() OVERRIDE; | 188 virtual bool RunImpl() OVERRIDE; |
180 }; | 189 }; |
181 | 190 |
182 } // namespace extensions | 191 } // namespace extensions |
183 | 192 |
184 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 193 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
OLD | NEW |