OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_H_ |
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_H_ | 6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/common/extensions/extension.h" | |
16 | 15 |
17 namespace extensions { | 16 namespace extensions { |
| 17 struct InstallWarning; |
18 | 18 |
19 // Wraps the DictionaryValue form of extension's manifest. Enforces access to | 19 // Wraps the DictionaryValue form of extension's manifest. Enforces access to |
20 // properties of the manifest using ManifestFeatureProvider. | 20 // properties of the manifest using ManifestFeatureProvider. |
21 class Manifest { | 21 class Manifest { |
22 public: | 22 public: |
23 Manifest(Extension::Location location, scoped_ptr<DictionaryValue> value); | 23 // What an extension was loaded from. |
| 24 // NOTE: These values are stored as integers in the preferences and used |
| 25 // in histograms so don't remove or reorder existing items. Just append |
| 26 // to the end. |
| 27 enum Location { |
| 28 INVALID_LOCATION, |
| 29 INTERNAL, // A crx file from the internal Extensions directory. |
| 30 EXTERNAL_PREF, // A crx file from an external directory (via prefs). |
| 31 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the |
| 32 // registry on Windows). |
| 33 LOAD, // --load-extension. |
| 34 COMPONENT, // An integral component of Chrome itself, which |
| 35 // happens to be implemented as an extension. We don't |
| 36 // show these in the management UI. |
| 37 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via |
| 38 // prefs), installed from an update URL. |
| 39 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via |
| 40 // admin policies), installed from an update URL. |
| 41 |
| 42 NUM_LOCATIONS |
| 43 }; |
| 44 |
| 45 // Do not change the order of entries or remove entries in this list |
| 46 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions. |
| 47 enum Type { |
| 48 TYPE_UNKNOWN = 0, |
| 49 TYPE_EXTENSION, |
| 50 TYPE_THEME, |
| 51 TYPE_USER_SCRIPT, |
| 52 TYPE_HOSTED_APP, |
| 53 // This is marked legacy because platform apps are preferred. For |
| 54 // backwards compatibility, we can't remove support for packaged apps |
| 55 TYPE_LEGACY_PACKAGED_APP, |
| 56 TYPE_PLATFORM_APP |
| 57 }; |
| 58 |
| 59 // Given two install sources, return the one which should take priority |
| 60 // over the other. If an extension is installed from two sources A and B, |
| 61 // its install source should be set to GetHigherPriorityLocation(A, B). |
| 62 static Location GetHigherPriorityLocation(Location loc1, Location loc2); |
| 63 |
| 64 // Whether the |location| is external or not. |
| 65 static inline bool IsExternalLocation(Location location) { |
| 66 return location == EXTERNAL_PREF || |
| 67 location == EXTERNAL_REGISTRY || |
| 68 location == EXTERNAL_PREF_DOWNLOAD || |
| 69 location == EXTERNAL_POLICY_DOWNLOAD; |
| 70 } |
| 71 |
| 72 // Whether extensions with |location| are auto-updatable or not. |
| 73 static inline bool IsAutoUpdateableLocation(Location location) { |
| 74 // Only internal and external extensions can be autoupdated. |
| 75 return location == INTERNAL || |
| 76 IsExternalLocation(location); |
| 77 } |
| 78 |
| 79 // Unpacked extensions start off with file access since they are a developer |
| 80 // feature. |
| 81 static inline bool ShouldAlwaysAllowFileAccess(Location location) { |
| 82 return location == LOAD; |
| 83 } |
| 84 |
| 85 Manifest(Location location, scoped_ptr<DictionaryValue> value); |
24 virtual ~Manifest(); | 86 virtual ~Manifest(); |
25 | 87 |
26 const std::string& extension_id() const { return extension_id_; } | 88 const std::string& extension_id() const { return extension_id_; } |
27 void set_extension_id(const std::string& id) { extension_id_ = id; } | 89 void set_extension_id(const std::string& id) { extension_id_ = id; } |
28 | 90 |
29 Extension::Location location() const { return location_; } | 91 Location location() const { return location_; } |
30 | 92 |
31 // |error| will be non-empty if the manifest is malformed. |warnings| will | 93 // |error| will be non-empty if the manifest is malformed. |warnings| will |
32 // be populated if there are keys in the manifest that cannot be specified by | 94 // be populated if there are keys in the manifest that cannot be specified by |
33 // the extension type. | 95 // the extension type. |
34 void ValidateManifest(std::string* error, | 96 void ValidateManifest(std::string* error, |
35 Extension::InstallWarningVector* warnings) const; | 97 std::vector<InstallWarning>* warnings) const; |
36 | 98 |
37 // The version of this extension's manifest. We increase the manifest | 99 // The version of this extension's manifest. We increase the manifest |
38 // version when making breaking changes to the extension system. If the | 100 // version when making breaking changes to the extension system. If the |
39 // manifest contains no explicit manifest version, this returns the current | 101 // manifest contains no explicit manifest version, this returns the current |
40 // system default. | 102 // system default. |
41 int GetManifestVersion() const; | 103 int GetManifestVersion() const; |
42 | 104 |
43 // Returns the manifest type. | 105 // Returns the manifest type. |
44 Extension::Type type() const { return type_; } | 106 Type type() const { return type_; } |
45 | 107 |
46 bool is_theme() const { return type_ == Extension::TYPE_THEME; } | 108 bool is_theme() const { return type_ == TYPE_THEME; } |
47 bool is_platform_app() const { return type_ == Extension::TYPE_PLATFORM_APP; } | 109 bool is_platform_app() const { return type_ == TYPE_PLATFORM_APP; } |
48 bool is_hosted_app() const { return type_ == Extension::TYPE_HOSTED_APP; } | 110 bool is_hosted_app() const { return type_ == TYPE_HOSTED_APP; } |
49 bool is_legacy_packaged_app() const { | 111 bool is_legacy_packaged_app() const { |
50 return type_ == Extension::TYPE_LEGACY_PACKAGED_APP; | 112 return type_ == TYPE_LEGACY_PACKAGED_APP; |
51 } | 113 } |
52 bool is_extension() const { return type_ == Extension::TYPE_EXTENSION; } | 114 bool is_extension() const { return type_ == TYPE_EXTENSION; } |
53 | 115 |
54 // These access the wrapped manifest value, returning false when the property | 116 // These access the wrapped manifest value, returning false when the property |
55 // does not exist or if the manifest type can't access it. | 117 // does not exist or if the manifest type can't access it. |
56 bool HasKey(const std::string& key) const; | 118 bool HasKey(const std::string& key) const; |
57 bool HasPath(const std::string& path) const; | 119 bool HasPath(const std::string& path) const; |
58 bool Get(const std::string& path, base::Value** out_value) const; | 120 bool Get(const std::string& path, base::Value** out_value) const; |
59 bool GetBoolean(const std::string& path, bool* out_value) const; | 121 bool GetBoolean(const std::string& path, bool* out_value) const; |
60 bool GetInteger(const std::string& path, int* out_value) const; | 122 bool GetInteger(const std::string& path, int* out_value) const; |
61 bool GetString(const std::string& path, std::string* out_value) const; | 123 bool GetString(const std::string& path, std::string* out_value) const; |
62 bool GetString(const std::string& path, string16* out_value) const; | 124 bool GetString(const std::string& path, string16* out_value) const; |
(...skipping 21 matching lines...) Expand all Loading... |
84 bool CanAccessPath(const std::string& path) const; | 146 bool CanAccessPath(const std::string& path) const; |
85 bool CanAccessKey(const std::string& key) const; | 147 bool CanAccessKey(const std::string& key) const; |
86 | 148 |
87 // A persistent, globally unique ID. An extension's ID is used in things | 149 // A persistent, globally unique ID. An extension's ID is used in things |
88 // like directory structures and URLs, and is expected to not change across | 150 // like directory structures and URLs, and is expected to not change across |
89 // versions. It is generated as a SHA-256 hash of the extension's public | 151 // versions. It is generated as a SHA-256 hash of the extension's public |
90 // key, or as a hash of the path in the case of unpacked extensions. | 152 // key, or as a hash of the path in the case of unpacked extensions. |
91 std::string extension_id_; | 153 std::string extension_id_; |
92 | 154 |
93 // The location the extension was loaded from. | 155 // The location the extension was loaded from. |
94 Extension::Location location_; | 156 Location location_; |
95 | 157 |
96 // The underlying dictionary representation of the manifest. | 158 // The underlying dictionary representation of the manifest. |
97 scoped_ptr<base::DictionaryValue> value_; | 159 scoped_ptr<base::DictionaryValue> value_; |
98 | 160 |
99 Extension::Type type_; | 161 Type type_; |
100 | 162 |
101 DISALLOW_COPY_AND_ASSIGN(Manifest); | 163 DISALLOW_COPY_AND_ASSIGN(Manifest); |
102 }; | 164 }; |
103 | 165 |
104 } // namespace extensions | 166 } // namespace extensions |
105 | 167 |
106 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_H_ | 168 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_H_ |
OLD | NEW |