OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ |
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ | 6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class DictionaryValue; | |
14 class Value; | 15 class Value; |
15 } | 16 } |
16 | 17 |
17 namespace extensions { | 18 namespace extensions { |
18 | 19 |
19 class Extension; | 20 class Extension; |
20 | 21 |
22 // Base class for extension APIs to implement to parse data they care about | |
23 // from the manifest. This only supports parsing from a single manifest key. | |
24 // If multiple keys need to be passed as input, use ManifestMultiKeyHandler. | |
21 class ManifestHandler { | 25 class ManifestHandler { |
22 public: | 26 public: |
23 ManifestHandler(); | 27 ManifestHandler(); |
24 virtual ~ManifestHandler(); | 28 virtual ~ManifestHandler(); |
25 | 29 |
26 // Attempts to parse the manifest value. | 30 // Attempts to parse the manifest value. |
27 // Returns true on success or false on failure; if false, |error| will | 31 // Returns true on success or false on failure; if false, |error| will |
28 // be set to a failure message. | 32 // be set to a failure message. |
29 virtual bool Parse(const base::Value* value, | 33 virtual bool Parse(const base::Value* value, |
30 Extension* extension, | 34 Extension* extension, |
(...skipping 14 matching lines...) Expand all Loading... | |
45 // Get the manifest handler associated with |key|, or NULL | 49 // Get the manifest handler associated with |key|, or NULL |
46 // if there is none. | 50 // if there is none. |
47 static ManifestHandler* Get(const std::string& key); | 51 static ManifestHandler* Get(const std::string& key); |
48 | 52 |
49 // If the handler is not handling most of the keys, it may be | 53 // If the handler is not handling most of the keys, it may be |
50 // more efficient to have a list of keys to iterate over. | 54 // more efficient to have a list of keys to iterate over. |
51 // TODO(yoz): this isn't the long-term solution. | 55 // TODO(yoz): this isn't the long-term solution. |
52 static std::vector<std::string> GetKeys(); | 56 static std::vector<std::string> GetKeys(); |
53 }; | 57 }; |
54 | 58 |
59 // Like ManifestHandler, but used when the parsing of manifest data requires | |
60 // input from multiple keys in the manifest. | |
61 class ManifestMultiKeyHandler { | |
Matt Perry
2013/01/25 20:56:40
It seems unnecessary to differentiate between sing
Devlin
2013/01/25 21:50:55
Another thought:
- Have only one type of handler,
| |
62 public: | |
63 typedef std::vector<const char*> KeySet; | |
64 | |
65 ManifestMultiKeyHandler(); | |
66 virtual ~ManifestMultiKeyHandler(); | |
67 | |
68 // Attempts to parse the manifest values. |dict_value| maps the registered | |
69 // keys from key_set() to their values from the manifest. If a key is absent | |
70 // from the the manifest, it will be absent from |dict_value|. | |
71 // Returns true on success or false on failure; if false, |error| will | |
72 // be set to a failure message. | |
73 virtual bool Parse(const base::DictionaryValue* dict_value, | |
74 Extension* extension, | |
75 string16* error) = 0; | |
76 | |
77 // Returns the key set this handler should be registered for. | |
78 virtual const KeySet key_set() = 0; | |
79 | |
80 // Associate |handler| with its key set in the manifest. Takes ownership | |
81 // of |handler|. | |
82 // WARNING: Manifest handlers registered only in the browser process | |
83 // are not available to renderers. | |
84 static void Register(ManifestMultiKeyHandler* handler); | |
Yoyo Zhou
2013/01/25 00:28:23
Notice this is different from the ManifestHandler:
| |
85 | |
86 // Get the manifest handler associated with |key_set|, or NULL | |
87 // if there is none. | |
88 static ManifestMultiKeyHandler* Get(const KeySet& key_set); | |
89 | |
90 // Get all key sets associated with manifest multi-key handlers. | |
91 static std::vector<KeySet> GetKeySets(); | |
92 }; | |
55 | 93 |
56 } // namespace extensions | 94 } // namespace extensions |
57 | 95 |
58 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ | 96 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ |
OLD | NEW |