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