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