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.
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_
13 #include "base/callback.h"
14 #include "extensions/common/extension.h"
15 #include "extensions/common/manifest_handlers/file_handler_info.h"
19 namespace extensions
{
22 struct FileHandlerInfo
;
23 struct GrantedFileEntry
;
25 // TODO(benwells): move this to platform_apps namespace.
26 namespace app_file_handler_util
{
28 extern const char kInvalidParameters
[];
29 extern const char kSecurityError
[];
31 // A set of pairs of path and its corresponding MIME type.
32 typedef std::set
<std::pair
<base::FilePath
, std::string
> > PathAndMimeTypeSet
;
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
);
39 // Returns the first file handler that can handle the given MIME type or
40 // filename, or NULL if is no such handler.
41 const FileHandlerInfo
* FirstFileHandlerForFile(
43 const std::string
& mime_type
,
44 const base::FilePath
& path
);
46 // Returns the handlers that can handle all files in |files|. The paths in
47 // |files| must be populated, but the MIME types are optional.
48 std::vector
<const FileHandlerInfo
*>
49 FindFileHandlersForFiles(const Extension
& extension
,
50 const PathAndMimeTypeSet
& files
);
52 bool FileHandlerCanHandleFile(
53 const FileHandlerInfo
& handler
,
54 const std::string
& mime_type
,
55 const base::FilePath
& path
);
57 // Creates a new file entry and allows |renderer_id| to access |path|. This
58 // registers a new file system for |path|.
59 GrantedFileEntry
CreateFileEntry(Profile
* profile
,
60 const Extension
* extension
,
62 const base::FilePath
& path
,
65 // When |is_directory| is true, it verifies that directories exist at each of
66 // the |paths| and calls back to |on_success| or otherwise to |on_failure|.
67 // When |is_directory| is false, it ensures regular files exists (not links and
68 // directories) at the |paths|, creating files if needed, and calls back to
69 // |on_success| or to |on_failure| depending on the result.
70 void PrepareFilesForWritableApp(
71 const std::vector
<base::FilePath
>& paths
,
74 const base::Closure
& on_success
,
75 const base::Callback
<void(const base::FilePath
&)>& on_failure
);
77 // Returns whether |extension| has the fileSystem.write permission.
78 bool HasFileSystemWritePermission(const Extension
* extension
);
80 // Validates a file entry and populates |file_path| with the absolute path if it
82 bool ValidateFileEntryAndGetPath(const std::string
& filesystem_name
,
83 const std::string
& filesystem_path
,
84 int render_process_id
,
85 base::FilePath
* file_path
,
88 } // namespace app_file_handler_util
90 } // namespace extensions
92 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_APP_FILE_HANDLER_UTIL_H_