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 CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_ 7 8 #include <set> 9 #include <string> 10 #include <utility> 11 #include <vector> 12 13 #include "content/public/browser/render_view_host.h" 14 #include "extensions/common/extension.h" 15 #include "extensions/common/manifest_handlers/file_handler_info.h" 16 17 class Profile; 18 19 namespace apps { 20 namespace file_handler_util { 21 struct GrantedFileEntry; 22 } 23 } 24 25 namespace extensions { 26 class ExtensionPrefs; 27 28 // TODO(benwells): move this to platform_apps namespace. 29 namespace app_file_handler_util { 30 31 extern const char kInvalidParameters[]; 32 extern const char kSecurityError[]; 33 34 // A set of pairs of path and its corresponding MIME type. 35 typedef std::set<std::pair<base::FilePath, std::string> > PathAndMimeTypeSet; 36 37 // Returns the file handler with the specified |handler_id|, or NULL if there 38 // is no such handler. 39 const FileHandlerInfo* FileHandlerForId(const Extension& app, 40 const std::string& handler_id); 41 42 // Returns the first file handler that can handle the given MIME type or 43 // filename, or NULL if is no such handler. 44 const FileHandlerInfo* FirstFileHandlerForFile( 45 const Extension& app, 46 const std::string& mime_type, 47 const base::FilePath& path); 48 49 // Returns the handlers that can handle all files in |files|. The paths in 50 // |files| must be populated, but the MIME types are optional. 51 std::vector<const FileHandlerInfo*> 52 FindFileHandlersForFiles(const Extension& extension, 53 const PathAndMimeTypeSet& files); 54 55 bool FileHandlerCanHandleFile( 56 const FileHandlerInfo& handler, 57 const std::string& mime_type, 58 const base::FilePath& path); 59 60 // Creates a new file entry and allows |renderer_id| to access |path|. This 61 // registers a new file system for |path|. 62 apps::file_handler_util::GrantedFileEntry CreateFileEntry( 63 Profile* profile, 64 const Extension* extension, 65 int renderer_id, 66 const base::FilePath& path, 67 bool is_directory); 68 69 // When |is_directory| is true, it verifies that directories exist at each of 70 // the |paths| and calls back to |on_success| or otherwise to |on_failure|. 71 // When |is_directory| is false, it ensures regular files exists (not links and 72 // directories) at the |paths|, creating files if needed, and calls back to 73 // |on_success| or to |on_failure| depending on the result. 74 void PrepareFilesForWritableApp( 75 const std::vector<base::FilePath>& paths, 76 Profile* profile, 77 bool is_directory, 78 const base::Closure& on_success, 79 const base::Callback<void(const base::FilePath&)>& on_failure); 80 81 // Returns whether |extension| has the fileSystem.write permission. 82 bool HasFileSystemWritePermission(const Extension* extension); 83 84 // Validates a file entry and populates |file_path| with the absolute path if it 85 // is valid. 86 bool ValidateFileEntryAndGetPath( 87 const std::string& filesystem_name, 88 const std::string& filesystem_path, 89 const content::RenderViewHost* render_view_host, 90 base::FilePath* file_path, 91 std::string* error); 92 93 } // namespace app_file_handler_util 94 95 } // namespace extensions 96 97 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_ 98