OLD | NEW |
| (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_H_ | |
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <string> | |
11 #include <set> | |
12 | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/string16.h" | |
15 | |
16 namespace base { | |
17 class DictionaryValue; | |
18 class ListValue; | |
19 class Value; | |
20 } | |
21 | |
22 namespace extensions { | |
23 | |
24 // Lightweight wrapper around a DictionaryValue representing an extension's | |
25 // manifest. Currently enforces access to properties of the manifest based | |
26 // on manifest type. | |
27 // | |
28 // TODO(aa): Move more smarts about mmanifest into this class over time. | |
29 class Manifest { | |
30 public: | |
31 // Flags for matching types of extension manifests. | |
32 enum Type { | |
33 kTypeNone = 0, | |
34 | |
35 // Extension::TYPE_EXTENSION and Extension::TYPE_USER_SCRIPT | |
36 kTypeExtension = 1 << 0, | |
37 | |
38 // Extension::TYPE_THEME | |
39 kTypeTheme = 1 << 1, | |
40 | |
41 // Extension::TYPE_HOSTED_APP | |
42 kTypeHostedApp = 1 << 2, | |
43 | |
44 // Extension::TYPE_PACKAGED_APP | |
45 kTypePackagedApp = 1 << 3, | |
46 | |
47 // Extension::TYPE_PLATFORM_APP | |
48 kTypePlatformApp = 1 << 4, | |
49 | |
50 // All types | |
51 kTypeAll = (1 << 5) - 1, | |
52 }; | |
53 | |
54 // Returns all known keys (this is used for testing). | |
55 static std::set<std::string> GetAllKnownKeys(); | |
56 | |
57 // Takes over ownership of |value|. | |
58 explicit Manifest(base::DictionaryValue* value); | |
59 virtual ~Manifest(); | |
60 | |
61 // Returns true if all keys in the manifest can be specified by | |
62 // the extension type. | |
63 bool ValidateManifest(std::string* error) const; | |
64 | |
65 // Returns the manifest type. | |
66 Type GetType() const; | |
67 | |
68 // Returns true if the manifest represents an Extension::TYPE_THEME. | |
69 bool IsTheme() const; | |
70 | |
71 // Returns true for Extension::TYPE_PLATFORM_APP | |
72 bool IsPlatformApp() const; | |
73 | |
74 // Returns true for Extension::TYPE_PACKAGED_APP. | |
75 bool IsPackagedApp() const; | |
76 | |
77 // Returns true for Extension::TYPE_HOSTED_APP. | |
78 bool IsHostedApp() const; | |
79 | |
80 // These access the wrapped manifest value, returning false when the property | |
81 // does not exist or if the manifest type can't access it. | |
82 bool HasKey(const std::string& key) const; | |
83 bool Get(const std::string& path, base::Value** out_value) const; | |
84 bool GetBoolean(const std::string& path, bool* out_value) const; | |
85 bool GetInteger(const std::string& path, int* out_value) const; | |
86 bool GetString(const std::string& path, std::string* out_value) const; | |
87 bool GetString(const std::string& path, string16* out_value) const; | |
88 bool GetDictionary(const std::string& path, | |
89 base::DictionaryValue** out_value) const; | |
90 bool GetList(const std::string& path, base::ListValue** out_value) const; | |
91 | |
92 // Returns a new Manifest equal to this one, passing ownership to | |
93 // the caller. | |
94 Manifest* DeepCopy() const; | |
95 | |
96 // Returns true if this equals the |other| manifest. | |
97 bool Equals(const Manifest* other) const; | |
98 | |
99 // Gets the underlying DictionaryValue representing the manifest. | |
100 // Note: only know this when you KNOW you don't need the validation. | |
101 base::DictionaryValue* value() const { return value_.get(); } | |
102 | |
103 private: | |
104 // Returns true if the extension can specify the given |path|. | |
105 bool CanAccessPath(const std::string& path) const; | |
106 | |
107 scoped_ptr<base::DictionaryValue> value_; | |
108 }; | |
109 | |
110 } // namespace extensions | |
111 | |
112 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_H_ | |
OLD | NEW |