Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: chrome/common/extensions/manifest_value.h

Issue 8654001: Reland restrict extension features based on the extension type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_COMMON_EXTENSIONS_MANIFEST_VALUE_H_
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_VALUE_H_
7 #pragma once
8
9 #include <map>
10 #include <string>
11
12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h"
14
15 namespace base {
16 class DictionaryValue;
17 class ListValue;
18 class Value;
19 }
20
Aaron Boodman 2011/11/23 01:45:25 Put this in namespace extensions { ?
jstritar 2011/11/28 23:09:56 Done.
21 // 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.
22 // DictionaryValue.
23 class ManifestValue {
Aaron Boodman 2011/11/23 01:45:25 Consider just calling this Manifest.
jstritar 2011/11/28 23:09:56 Done.
24 public:
25 // Takes over ownership of |value|.
26 explicit ManifestValue(base::DictionaryValue* value);
27 virtual ~ManifestValue();
28
29 // Returns true if all keys in the manifest can be specified by
30 // the extension type.
31 bool ValidateManifest(std::string* error) const;
32
33 // Returns true if the manifest represents an Extension::TYPE_THEME.
34 bool IsTheme() const;
35
36 // Returns true for Extension::TYPE_PLATFORM_APP
37 bool IsPlatformApp() const;
38
39 // Returns true for Extension::TYPE_PACKAGED_APP.
40 bool IsPackagedApp() const;
41
42 // Returns true for Extension::TYPE_HOSTED_APP.
43 bool IsHostedApp() const;
44
45 // Returns true if the manifest contains the given |key| and it is
46 // accessible by the extension's type.
47 bool HasKey(const std::string& key) const;
48
49 // 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.
50 // to manifest keys based on the extension's type.
51 bool Get(const std::string& path, base::Value** out_value) const;
52 bool GetBoolean(const std::string& path, bool* out_value) const;
53 bool GetInteger(const std::string& path, int* out_value) const;
54 bool GetString(const std::string& path, std::string* out_value) const;
55 bool GetString(const std::string& path, string16* out_value) const;
56 bool GetDictionary(const std::string& path,
57 base::DictionaryValue** out_value) const;
58 bool GetList(const std::string& path, base::ListValue** out_value) const;
59
60 // Returns a new ManifestValue equal to this one, passing ownership to
61 // the caller.
62 ManifestValue* DeepCopy() const;
63
64 // Returns true if this equals the |other| manifest.
65 bool Equals(const ManifestValue* other) const;
66
67 // Gets the underlying DictionaryValue representing the manifest.
68 // Note: only know this when you KNOW you don't need the validation.
69 base::DictionaryValue* value() const { return value_.get(); }
70
71 private:
72 // Flags for specifying what extension types can access manifest keys.
73 enum TypeRestriction {
74 kTypeNone = 0,
75
76 // Extension::TYPE_EXTENSION and Extension::TYPE_USER_SCRIPT
77 kTypeExtension = 1 << 0,
78
79 // Extension::TYPE_THEME
80 kTypeTheme = 1 << 1,
81
82 // Extension::TYPE_HOSTED_APP
83 kTypeHostedApp = 1 << 2,
84
85 // Extension::TYPE_PACKAGED_APP
86 kTypePackagedApp = 1 << 3,
87
88 // Extension::TYPE_PLATFORM_APP
89 kTypePlatformApp = 1 << 4,
90
91 // Supports all types.
92 kTypeAll = (1 << 5) - 1,
93
94 // Supports all app types.
95 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
96
97 // Supports all types except themes.
98 kTypeAllButThemes = kTypeAll - kTypeTheme
99 };
100
101 typedef std::map<std::string, int> RestrictionMap;
102
103 // Holds the manifest key restrictions.
104 struct FeatureRestriction;
105 static const FeatureRestriction kFeatureRestrictions[];
106
107 // Returns true if the |key| is recognized.
108 bool IsKnownKey(const std::string& key) const;
109
110 // Returns true if the extension can specify the given |key|.
111 bool CanAccessKey(const std::string& key) const;
112
113 // Returns true if the extension can specify the given |path|.
114 bool CanAccessPath(const std::string& path) const;
115
116 scoped_ptr<base::DictionaryValue> value_;
117 RestrictionMap restrictions_;
118 TypeRestriction type_;
119 };
120
121 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_VALUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698