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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
10 | 11 |
11 #include "base/memory/linked_ptr.h" | |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/extensions/manifest.h" | 14 #include "chrome/common/extensions/manifest.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 | 17 |
18 class ManifestHandler { | 18 class ManifestHandler { |
19 public: | 19 public: |
20 ManifestHandler(); | 20 ManifestHandler(); |
21 virtual ~ManifestHandler(); | 21 virtual ~ManifestHandler(); |
22 | 22 |
23 // Attempts to parse the extension's manifest. | 23 // Attempts to parse the extension's manifest. |
24 // Returns true on success or false on failure; if false, |error| will | 24 // Returns true on success or false on failure; if false, |error| will |
25 // be set to a failure message. | 25 // be set to a failure message. |
26 virtual bool Parse(Extension* extension, string16* error) = 0; | 26 virtual bool Parse(Extension* extension, string16* error) = 0; |
27 | 27 |
28 // If false (the default), only parse the manifest if a registered | 28 // If false (the default), only parse the manifest if a registered |
29 // key is present in the manifest. If true, always attempt to parse | 29 // key is present in the manifest. If true, always attempt to parse |
30 // the manifest for this extension type, even if no registered keys | 30 // the manifest for this extension type, even if no registered keys |
31 // are present. This allows specifying a default parsed value for | 31 // are present. This allows specifying a default parsed value for |
32 // extensions that don't declare our key in the manifest. | 32 // extensions that don't declare our key in the manifest. |
33 // TODO(yoz): Use Feature availability instead. | 33 // TODO(yoz): Use Feature availability instead. |
34 virtual bool AlwaysParseForType(Manifest::Type type); | 34 virtual bool AlwaysParseForType(Manifest::Type type) const; |
35 | 35 |
36 // The list of keys that, if present, should be parsed before calling our | 36 // The list of keys that, if present, should be parsed before calling our |
37 // Parse (typically, because our Parse needs to read those keys). | 37 // Parse (typically, because our Parse needs to read those keys). |
38 // Defaults to empty. | 38 // Defaults to empty. |
39 virtual const std::vector<std::string>& PrerequisiteKeys(); | 39 virtual const std::vector<std::string> PrerequisiteKeys() const; |
40 | 40 |
41 // Associate |handler| with |key| in the manifest. A handler can register | 41 // Associate us with our keys() in the manifest. A handler can register |
42 // for multiple keys. The global registry takes ownership of |handler|; | 42 // for multiple keys. The global registry takes ownership of this; |
43 // if it has an existing handler for |key|, it replaces it with this one. | 43 // if it has an existing handler for |key|, it replaces it with this. |
| 44 // Typical usage: |
| 45 // (new MyManifestHandler)->Register(); |
44 // | 46 // |
45 // WARNING: Manifest handlers registered only in the browser process | 47 // WARNING: Manifest handlers registered only in the browser process |
46 // are not available to renderers or utility processes. | 48 // are not available to renderers or utility processes. |
47 static void Register(const std::string& key, | 49 void Register(); |
48 linked_ptr<ManifestHandler> handler); | |
49 | 50 |
50 // Call Parse on all registered manifest handlers that should parse | 51 // Call Parse on all registered manifest handlers that should parse |
51 // this extension. | 52 // this extension. |
52 static bool ParseExtension(Extension* extension, string16* error); | 53 static bool ParseExtension(Extension* extension, string16* error); |
53 | 54 |
54 // Reset the manifest handler registry to an empty state. Useful for | 55 // Reset the manifest handler registry to an empty state. Useful for |
55 // unit tests. | 56 // unit tests. |
56 static void ClearRegistryForTesting(); | 57 static void ClearRegistryForTesting(); |
| 58 |
| 59 protected: |
| 60 // A convenience method for handlers that only register for 1 key, |
| 61 // so that they can define keys() { return SingleKey(kKey); } |
| 62 static const std::vector<std::string> SingleKey(const std::string& key); |
| 63 |
| 64 private: |
| 65 // The keys to register us for (in Register). |
| 66 virtual const std::vector<std::string> Keys() const = 0; |
57 }; | 67 }; |
58 | 68 |
59 } // namespace extensions | 69 } // namespace extensions |
60 | 70 |
61 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ | 71 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ |
OLD | NEW |