| 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_HANDLERS_APP_FILE_HANDLER_UTIL_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_ | 6 #define EXTENSIONS_BROWSER_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 15 #include "extensions/common/manifest_handlers/file_handler_info.h" | 15 #include "extensions/common/manifest_handlers/file_handler_info.h" |
| 16 | 16 |
| 17 class Profile; | 17 namespace content { |
| 18 class BrowserContext; |
| 19 } |
| 18 | 20 |
| 19 namespace extensions { | 21 namespace extensions { |
| 20 | 22 |
| 21 struct EntryInfo; | 23 struct EntryInfo; |
| 22 struct FileHandlerInfo; | 24 struct FileHandlerInfo; |
| 23 struct GrantedFileEntry; | 25 struct GrantedFileEntry; |
| 24 | 26 |
| 25 // TODO(benwells): move this to platform_apps namespace. | 27 // TODO(michaelpg,benwells): move this to an app-specific namespace and |
| 28 // directory. |
| 26 namespace app_file_handler_util { | 29 namespace app_file_handler_util { |
| 27 | 30 |
| 28 extern const char kInvalidParameters[]; | 31 extern const char kInvalidParameters[]; |
| 29 extern const char kSecurityError[]; | 32 extern const char kSecurityError[]; |
| 30 | 33 |
| 31 // Returns the file handler with the specified |handler_id|, or NULL if there | 34 // Returns the file handler with the specified |handler_id|, or NULL if there |
| 32 // is no such handler. | 35 // is no such handler. |
| 33 const FileHandlerInfo* FileHandlerForId(const Extension& app, | 36 const FileHandlerInfo* FileHandlerForId(const Extension& app, |
| 34 const std::string& handler_id); | 37 const std::string& handler_id); |
| 35 | 38 |
| 36 // Returns the handlers that can handle all files in |entries|. | 39 // Returns the handlers that can handle all files in |entries|. |
| 37 std::vector<const FileHandlerInfo*> FindFileHandlersForEntries( | 40 std::vector<const FileHandlerInfo*> FindFileHandlersForEntries( |
| 38 const Extension& extension, | 41 const Extension& extension, |
| 39 const std::vector<EntryInfo> entries); | 42 const std::vector<EntryInfo> entries); |
| 40 | 43 |
| 41 bool FileHandlerCanHandleEntry(const FileHandlerInfo& handler, | 44 bool FileHandlerCanHandleEntry(const FileHandlerInfo& handler, |
| 42 const EntryInfo& entry); | 45 const EntryInfo& entry); |
| 43 | 46 |
| 44 // Creates a new file entry and allows |renderer_id| to access |path|. This | 47 // Creates a new file entry and allows |renderer_id| to access |path|. This |
| 45 // registers a new file system for |path|. | 48 // registers a new file system for |path|. |
| 46 GrantedFileEntry CreateFileEntry(Profile* profile, | 49 GrantedFileEntry CreateFileEntry(content::BrowserContext* context, |
| 47 const Extension* extension, | 50 const Extension* extension, |
| 48 int renderer_id, | 51 int renderer_id, |
| 49 const base::FilePath& path, | 52 const base::FilePath& path, |
| 50 bool is_directory); | 53 bool is_directory); |
| 51 | 54 |
| 52 // |directory_paths| contain the set of directories out of |paths|. | 55 // |directory_paths| contain the set of directories out of |paths|. |
| 53 // For directories it makes sure they exist at their corresponding |paths|, | 56 // For directories it makes sure they exist at their corresponding |paths|, |
| 54 // while for regular files it makes sure they exist (i.e. not links) at |paths|, | 57 // while for regular files it makes sure they exist (i.e. not links) at |paths|, |
| 55 // creating files if needed. If result is successful it calls |on_success|, | 58 // creating files if needed. If result is successful it calls |on_success|, |
| 56 // otherwise calls |on_failure|. | 59 // otherwise calls |on_failure|. |
| 57 void PrepareFilesForWritableApp( | 60 void PrepareFilesForWritableApp( |
| 58 const std::vector<base::FilePath>& paths, | 61 const std::vector<base::FilePath>& paths, |
| 59 Profile* profile, | 62 content::BrowserContext* context, |
| 60 const std::set<base::FilePath>& directory_paths, | 63 const std::set<base::FilePath>& directory_paths, |
| 61 const base::Closure& on_success, | 64 const base::Closure& on_success, |
| 62 const base::Callback<void(const base::FilePath&)>& on_failure); | 65 const base::Callback<void(const base::FilePath&)>& on_failure); |
| 63 | 66 |
| 64 // Returns whether |extension| has the fileSystem.write permission. | 67 // Returns whether |extension| has the fileSystem.write permission. |
| 65 bool HasFileSystemWritePermission(const Extension* extension); | 68 bool HasFileSystemWritePermission(const Extension* extension); |
| 66 | 69 |
| 67 // Validates a file entry and populates |file_path| with the absolute path if it | 70 // Validates a file entry and populates |file_path| with the absolute path if it |
| 68 // is valid. | 71 // is valid. |
| 69 bool ValidateFileEntryAndGetPath(const std::string& filesystem_name, | 72 bool ValidateFileEntryAndGetPath(const std::string& filesystem_name, |
| 70 const std::string& filesystem_path, | 73 const std::string& filesystem_path, |
| 71 int render_process_id, | 74 int render_process_id, |
| 72 base::FilePath* file_path, | 75 base::FilePath* file_path, |
| 73 std::string* error); | 76 std::string* error); |
| 74 | 77 |
| 75 } // namespace app_file_handler_util | 78 } // namespace app_file_handler_util |
| 76 | 79 |
| 77 } // namespace extensions | 80 } // namespace extensions |
| 78 | 81 |
| 79 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_ | 82 #endif // EXTENSIONS_BROWSER_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_ |
| OLD | NEW |