1 // Copyright 2013 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_COMMON_EXTENSIONS_API_FILE_BROWSER_HANDLERS_FILE_BROWSER_HANDLER_H_
6 #define CHROME_COMMON_EXTENSIONS_API_FILE_BROWSER_HANDLERS_FILE_BROWSER_HANDLER_H_
11 #include "base/basictypes.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_handler.h"
14 #include "extensions/common/url_pattern.h"
15 #include "extensions/common/url_pattern_set.h"
20 // FileBrowserHandler encapsulates the state of a file browser action.
21 class FileBrowserHandler
{
23 typedef std::vector
<linked_ptr
<FileBrowserHandler
> > List
;
26 ~FileBrowserHandler();
29 std::string
extension_id() const { return extension_id_
; }
30 void set_extension_id(const std::string
& extension_id
) {
31 extension_id_
= extension_id
;
35 const std::string
& id() const { return id_
; }
36 void set_id(const std::string
& id
) { id_
= id
; }
39 const std::string
& title() const { return title_
; }
40 void set_title(const std::string
& title
) { title_
= title
; }
42 // File schema URL patterns.
43 const extensions::URLPatternSet
& file_url_patterns() const {
46 void AddPattern(const URLPattern
& pattern
);
47 bool MatchesURL(const GURL
& url
) const;
51 const std::string
& icon_path() const { return default_icon_path_
; }
52 void set_icon_path(const std::string
& path
) {
53 default_icon_path_
= path
;
56 // File access permissions.
57 // Adjusts file_access_permission_flags_ to allow specified permission.
58 bool AddFileAccessPermission(const std::string
& permission_str
);
59 // Checks that specified file access permissions are valid (all set
60 // permissions are valid and there is no other permission specified with
62 // If no access permissions were set, initialize them to default value.
63 bool ValidateFileAccessPermissions();
64 // Checks if handler has read access.
66 // Checks if handler has write access.
67 bool CanWrite() const;
68 // Checks if handler has "create" access specified.
69 bool HasCreateAccessPermission() const;
71 // Returns the file browser handlers associated with the |extension|.
72 static List
* GetHandlers(const extensions::Extension
* extension
);
75 // The id for the extension this action belongs to (as defined in the
76 // extension manifest).
77 std::string extension_id_
;
79 std::string default_icon_path_
;
80 // The id for the FileBrowserHandler, for example: "PdfFileAction".
82 unsigned int file_access_permission_flags_
;
84 // A list of file filters.
85 extensions::URLPatternSet url_set_
;
88 // Parses the "file_browser_handlers" extension manifest key.
89 class FileBrowserHandlerParser
: public extensions::ManifestHandler
{
91 FileBrowserHandlerParser();
92 ~FileBrowserHandlerParser() override
;
94 bool Parse(extensions::Extension
* extension
, base::string16
* error
) override
;
97 const std::vector
<std::string
> Keys() const override
;
100 #endif // CHROME_COMMON_EXTENSIONS_API_FILE_BROWSER_HANDLERS_FILE_BROWSER_HANDLER_H_