| 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 CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "chrome/common/extensions/extension.h" | |
| 14 #include "chrome/common/extensions/manifest_handler.h" | |
| 15 #include "extensions/common/url_pattern.h" | |
| 16 #include "extensions/common/url_pattern_set.h" | |
| 17 #include "googleurl/src/gurl.h" | |
| 18 | |
| 19 class URLPattern; | |
| 20 | |
| 21 // FileBrowserHandler encapsulates the state of a file browser action. | |
| 22 class FileBrowserHandler { | |
| 23 public: | |
| 24 typedef std::vector<linked_ptr<FileBrowserHandler> > List; | |
| 25 | |
| 26 FileBrowserHandler(); | |
| 27 ~FileBrowserHandler(); | |
| 28 | |
| 29 // extension id | |
| 30 std::string extension_id() const { return extension_id_; } | |
| 31 void set_extension_id(const std::string& extension_id) { | |
| 32 extension_id_ = extension_id; | |
| 33 } | |
| 34 | |
| 35 // action id | |
| 36 const std::string& id() const { return id_; } | |
| 37 void set_id(const std::string& id) { id_ = id; } | |
| 38 | |
| 39 // default title | |
| 40 const std::string& title() const { return title_; } | |
| 41 void set_title(const std::string& title) { title_ = title; } | |
| 42 | |
| 43 // File schema URL patterns. | |
| 44 const extensions::URLPatternSet& file_url_patterns() const { | |
| 45 return url_set_; | |
| 46 } | |
| 47 void AddPattern(const URLPattern& pattern); | |
| 48 bool MatchesURL(const GURL& url) const; | |
| 49 void ClearPatterns(); | |
| 50 | |
| 51 // Action icon path. | |
| 52 const std::string icon_path() const { return default_icon_path_; } | |
| 53 void set_icon_path(const std::string& path) { | |
| 54 default_icon_path_ = path; | |
| 55 } | |
| 56 | |
| 57 // File access permissions. | |
| 58 // Adjusts file_access_permission_flags_ to allow specified permission. | |
| 59 bool AddFileAccessPermission(const std::string& permission_str); | |
| 60 // Checks that specified file access permissions are valid (all set | |
| 61 // permissions are valid and there is no other permission specified with | |
| 62 // "create") | |
| 63 // If no access permissions were set, initialize them to default value. | |
| 64 bool ValidateFileAccessPermissions(); | |
| 65 // Checks if handler has read access. | |
| 66 bool CanRead() const; | |
| 67 // Checks if handler has write access. | |
| 68 bool CanWrite() const; | |
| 69 // Checks if handler has "create" access specified. | |
| 70 bool HasCreateAccessPermission() const; | |
| 71 | |
| 72 // Returns the file browser handlers associated with the |extension|. | |
| 73 static List* GetHandlers(const extensions::Extension* extension); | |
| 74 | |
| 75 private: | |
| 76 // The id for the extension this action belongs to (as defined in the | |
| 77 // extension manifest). | |
| 78 std::string extension_id_; | |
| 79 std::string title_; | |
| 80 std::string default_icon_path_; | |
| 81 // The id for the FileBrowserHandler, for example: "PdfFileAction". | |
| 82 std::string id_; | |
| 83 unsigned int file_access_permission_flags_; | |
| 84 | |
| 85 // A list of file filters. | |
| 86 extensions::URLPatternSet url_set_; | |
| 87 }; | |
| 88 | |
| 89 // Parses the "file_browser_handlers" extension manifest key. | |
| 90 class FileBrowserHandlerParser : public extensions::ManifestHandler { | |
| 91 public: | |
| 92 FileBrowserHandlerParser(); | |
| 93 virtual ~FileBrowserHandlerParser(); | |
| 94 | |
| 95 virtual bool Parse(extensions::Extension* extension, | |
| 96 string16* error) OVERRIDE; | |
| 97 | |
| 98 private: | |
| 99 virtual const std::vector<std::string> Keys() const OVERRIDE; | |
| 100 }; | |
| 101 | |
| 102 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_ | |
| OLD | NEW |