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 "content/public/browser/render_view_host.h"
14 #include "extensions/common/extension.h"
15 #include "extensions/common/manifest_handlers/file_handler_info.h"
19 namespace extensions
{
22 struct GrantedFileEntry
;
24 // TODO(benwells): move this to platform_apps namespace.
25 namespace app_file_handler_util
{
27 extern const char kInvalidParameters
[];
28 extern const char kSecurityError
[];
30 // A set of pairs of path and its corresponding MIME type.
31 typedef std::set
<std::pair
<base::FilePath
, std::string
> > PathAndMimeTypeSet
;
33 // Returns the file handler with the specified |handler_id|, or NULL if there
34 // is no such handler.
35 const FileHandlerInfo
* FileHandlerForId(const Extension
& app
,
36 const std::string
& handler_id
);
38 // Returns the first file handler that can handle the given MIME type or
39 // filename, or NULL if is no such handler.
40 const FileHandlerInfo
* FirstFileHandlerForFile(
42 const std::string
& mime_type
,
43 const base::FilePath
& path
);
45 // Returns the handlers that can handle all files in |files|. The paths in
46 // |files| must be populated, but the MIME types are optional.
47 std::vector
<const FileHandlerInfo
*>
48 FindFileHandlersForFiles(const Extension
& extension
,
49 const PathAndMimeTypeSet
& files
);
51 bool FileHandlerCanHandleFile(
52 const FileHandlerInfo
& handler
,
53 const std::string
& mime_type
,
54 const base::FilePath
& path
);
56 // Creates a new file entry and allows |renderer_id| to access |path|. This
57 // registers a new file system for |path|.
58 GrantedFileEntry
CreateFileEntry(Profile
* profile
,
59 const Extension
* extension
,
61 const base::FilePath
& path
,
64 // When |is_directory| is true, it verifies that directories exist at each of
65 // the |paths| and calls back to |on_success| or otherwise to |on_failure|.
66 // When |is_directory| is false, it ensures regular files exists (not links and
67 // directories) at the |paths|, creating files if needed, and calls back to
68 // |on_success| or to |on_failure| depending on the result.
69 void PrepareFilesForWritableApp(
70 const std::vector
<base::FilePath
>& paths
,
73 const base::Closure
& on_success
,
74 const base::Callback
<void(const base::FilePath
&)>& on_failure
);
76 // Returns whether |extension| has the fileSystem.write permission.
77 bool HasFileSystemWritePermission(const Extension
* extension
);
79 // Validates a file entry and populates |file_path| with the absolute path if it
81 bool ValidateFileEntryAndGetPath(
82 const std::string
& filesystem_name
,
83 const std::string
& filesystem_path
,
84 const content::RenderViewHost
* render_view_host
,
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_