Chromium Code Reviews| Index: chrome/common/extensions/manifest_value.h |
| diff --git a/chrome/common/extensions/manifest_value.h b/chrome/common/extensions/manifest_value.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e4f7b96a34f3a4a1dc3f2945c523c69ecb66a1fa |
| --- /dev/null |
| +++ b/chrome/common/extensions/manifest_value.h |
| @@ -0,0 +1,121 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_VALUE_H_ |
| +#define CHROME_COMMON_EXTENSIONS_MANIFEST_VALUE_H_ |
| +#pragma once |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/string16.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +class ListValue; |
| +class Value; |
| +} |
| + |
|
Aaron Boodman
2011/11/23 01:45:25
Put this in namespace extensions { ?
jstritar
2011/11/28 23:09:56
Done.
|
| +// Represents an extension manifest and enforces manifest schemas on top of |
|
Aaron Boodman
2011/11/23 01:45:25
Suggest:
Lightweight wrapper around a DictionaryV
jstritar
2011/11/28 23:09:56
Done.
|
| +// DictionaryValue. |
| +class ManifestValue { |
|
Aaron Boodman
2011/11/23 01:45:25
Consider just calling this Manifest.
jstritar
2011/11/28 23:09:56
Done.
|
| + public: |
| + // Takes over ownership of |value|. |
| + explicit ManifestValue(base::DictionaryValue* value); |
| + virtual ~ManifestValue(); |
| + |
| + // Returns true if all keys in the manifest can be specified by |
| + // the extension type. |
| + bool ValidateManifest(std::string* error) const; |
| + |
| + // Returns true if the manifest represents an Extension::TYPE_THEME. |
| + bool IsTheme() const; |
| + |
| + // Returns true for Extension::TYPE_PLATFORM_APP |
| + bool IsPlatformApp() const; |
| + |
| + // Returns true for Extension::TYPE_PACKAGED_APP. |
| + bool IsPackagedApp() const; |
| + |
| + // Returns true for Extension::TYPE_HOSTED_APP. |
| + bool IsHostedApp() const; |
| + |
| + // Returns true if the manifest contains the given |key| and it is |
| + // accessible by the extension's type. |
| + bool HasKey(const std::string& key) const; |
| + |
| + // These access the manifest value, and restrict access (with CHECKs) |
|
Aaron Boodman
2011/11/23 01:45:25
I would not enforce with CHECK because that makes
jstritar
2011/11/28 23:09:56
Done. We just return false now.
|
| + // to manifest keys based on the extension's type. |
| + bool Get(const std::string& path, base::Value** out_value) const; |
| + bool GetBoolean(const std::string& path, bool* out_value) const; |
| + bool GetInteger(const std::string& path, int* out_value) const; |
| + bool GetString(const std::string& path, std::string* out_value) const; |
| + bool GetString(const std::string& path, string16* out_value) const; |
| + bool GetDictionary(const std::string& path, |
| + base::DictionaryValue** out_value) const; |
| + bool GetList(const std::string& path, base::ListValue** out_value) const; |
| + |
| + // Returns a new ManifestValue equal to this one, passing ownership to |
| + // the caller. |
| + ManifestValue* DeepCopy() const; |
| + |
| + // Returns true if this equals the |other| manifest. |
| + bool Equals(const ManifestValue* other) const; |
| + |
| + // Gets the underlying DictionaryValue representing the manifest. |
| + // Note: only know this when you KNOW you don't need the validation. |
| + base::DictionaryValue* value() const { return value_.get(); } |
| + |
| + private: |
| + // Flags for specifying what extension types can access manifest keys. |
| + enum TypeRestriction { |
| + kTypeNone = 0, |
| + |
| + // Extension::TYPE_EXTENSION and Extension::TYPE_USER_SCRIPT |
| + kTypeExtension = 1 << 0, |
| + |
| + // Extension::TYPE_THEME |
| + kTypeTheme = 1 << 1, |
| + |
| + // Extension::TYPE_HOSTED_APP |
| + kTypeHostedApp = 1 << 2, |
| + |
| + // Extension::TYPE_PACKAGED_APP |
| + kTypePackagedApp = 1 << 3, |
| + |
| + // Extension::TYPE_PLATFORM_APP |
| + kTypePlatformApp = 1 << 4, |
| + |
| + // Supports all types. |
| + kTypeAll = (1 << 5) - 1, |
| + |
| + // Supports all app types. |
| + kTypeAllApps = kTypeHostedApp | kTypePackagedApp | kTypePlatformApp, |
|
Aaron Boodman
2011/11/23 01:45:25
Wow, there is a feature that is supported by all a
jstritar
2011/11/28 23:09:56
The 'app' manifest key technically is. I changed t
|
| + |
| + // Supports all types except themes. |
| + kTypeAllButThemes = kTypeAll - kTypeTheme |
| + }; |
| + |
| + typedef std::map<std::string, int> RestrictionMap; |
| + |
| + // Holds the manifest key restrictions. |
| + struct FeatureRestriction; |
| + static const FeatureRestriction kFeatureRestrictions[]; |
| + |
| + // Returns true if the |key| is recognized. |
| + bool IsKnownKey(const std::string& key) const; |
| + |
| + // Returns true if the extension can specify the given |key|. |
| + bool CanAccessKey(const std::string& key) const; |
| + |
| + // Returns true if the extension can specify the given |path|. |
| + bool CanAccessPath(const std::string& path) const; |
| + |
| + scoped_ptr<base::DictionaryValue> value_; |
| + RestrictionMap restrictions_; |
| + TypeRestriction type_; |
| +}; |
| + |
| +#endif // CHROME_COMMON_EXTENSIONS_MANIFEST_VALUE_H_ |