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

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

Issue 115682: Verify signed .crx extension installations (Closed)
Patch Set: moved extensions consts back to extensions_service (was causing compile errors on mac & linux) Created 11 years, 6 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_EXTENSION_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 20 matching lines...) Expand all
31 // registry on Windows). 31 // registry on Windows).
32 LOAD // --load-extension. 32 LOAD // --load-extension.
33 }; 33 };
34 34
35 enum State { 35 enum State {
36 DISABLED, 36 DISABLED,
37 ENABLED, 37 ENABLED,
38 KILLBIT, // Don't install/upgrade (applies to external extensions only). 38 KILLBIT, // Don't install/upgrade (applies to external extensions only).
39 }; 39 };
40 40
41 enum InstallType {
42 DOWNGRADE,
43 REINSTALL,
44 UPGRADE,
45 NEW_INSTALL
46 };
47
41 // An NPAPI plugin included in the extension. 48 // An NPAPI plugin included in the extension.
42 struct PluginInfo { 49 struct PluginInfo {
43 FilePath path; // Path to the plugin. 50 FilePath path; // Path to the plugin.
44 bool is_public; // False if only this extension can load this plugin. 51 bool is_public; // False if only this extension can load this plugin.
45 }; 52 };
46 53
47 // The name of the manifest inside an extension. 54 // The name of the manifest inside an extension.
48 static const char kManifestFilename[]; 55 static const char kManifestFilename[];
49 56
50 // Keys used in JSON representation of extensions. 57 // Keys used in JSON representation of extensions.
51 static const wchar_t* kBackgroundKey; 58 static const wchar_t* kBackgroundKey;
52 static const wchar_t* kContentScriptsKey; 59 static const wchar_t* kContentScriptsKey;
53 static const wchar_t* kCssKey; 60 static const wchar_t* kCssKey;
54 static const wchar_t* kDescriptionKey; 61 static const wchar_t* kDescriptionKey;
55 static const wchar_t* kIconPathKey; 62 static const wchar_t* kIconPathKey;
56 static const wchar_t* kIdKey;
57 static const wchar_t* kJsKey; 63 static const wchar_t* kJsKey;
58 static const wchar_t* kMatchesKey; 64 static const wchar_t* kMatchesKey;
59 static const wchar_t* kNameKey; 65 static const wchar_t* kNameKey;
66 static const wchar_t* kPageActionIdKey;
60 static const wchar_t* kPageActionsKey; 67 static const wchar_t* kPageActionsKey;
61 static const wchar_t* kPermissionsKey; 68 static const wchar_t* kPermissionsKey;
62 static const wchar_t* kPluginsKey; 69 static const wchar_t* kPluginsKey;
63 static const wchar_t* kPluginsPathKey; 70 static const wchar_t* kPluginsPathKey;
64 static const wchar_t* kPluginsPublicKey; 71 static const wchar_t* kPluginsPublicKey;
65 static const wchar_t* kPublicKeyKey; 72 static const wchar_t* kPublicKeyKey;
66 static const wchar_t* kSignatureKey; 73 static const wchar_t* kSignatureKey;
67 static const wchar_t* kRunAtKey; 74 static const wchar_t* kRunAtKey;
68 static const wchar_t* kThemeKey; 75 static const wchar_t* kThemeKey;
69 static const wchar_t* kThemeImagesKey; 76 static const wchar_t* kThemeImagesKey;
(...skipping 10 matching lines...) Expand all
80 static const char* kRunAtDocumentEndValue; 87 static const char* kRunAtDocumentEndValue;
81 static const char* kPageActionTypeTab; 88 static const char* kPageActionTypeTab;
82 static const char* kPageActionTypePermanent; 89 static const char* kPageActionTypePermanent;
83 90
84 // Error messages returned from InitFromValue(). 91 // Error messages returned from InitFromValue().
85 static const char* kInvalidContentScriptError; 92 static const char* kInvalidContentScriptError;
86 static const char* kInvalidContentScriptsListError; 93 static const char* kInvalidContentScriptsListError;
87 static const char* kInvalidCssError; 94 static const char* kInvalidCssError;
88 static const char* kInvalidCssListError; 95 static const char* kInvalidCssListError;
89 static const char* kInvalidDescriptionError; 96 static const char* kInvalidDescriptionError;
90 static const char* kInvalidIdError;
91 static const char* kInvalidJsError; 97 static const char* kInvalidJsError;
92 static const char* kInvalidJsListError; 98 static const char* kInvalidJsListError;
99 static const char* kInvalidKeyError;
93 static const char* kInvalidManifestError; 100 static const char* kInvalidManifestError;
94 static const char* kInvalidMatchCountError; 101 static const char* kInvalidMatchCountError;
95 static const char* kInvalidMatchError; 102 static const char* kInvalidMatchError;
96 static const char* kInvalidMatchesError; 103 static const char* kInvalidMatchesError;
97 static const char* kInvalidNameError; 104 static const char* kInvalidNameError;
98 static const char* kInvalidPluginsError; 105 static const char* kInvalidPluginsError;
99 static const char* kInvalidPluginsPathError; 106 static const char* kInvalidPluginsPathError;
100 static const char* kInvalidPluginsPublicError; 107 static const char* kInvalidPluginsPublicError;
101 108
102 static const char* kInvalidBackgroundError; 109 static const char* kInvalidBackgroundError;
103 static const char* kInvalidRunAtError; 110 static const char* kInvalidRunAtError;
111 static const char* kInvalidSignatureError;
104 static const char* kInvalidToolstripError; 112 static const char* kInvalidToolstripError;
105 static const char* kInvalidToolstripsError; 113 static const char* kInvalidToolstripsError;
106 static const char* kInvalidVersionError; 114 static const char* kInvalidVersionError;
107 static const char* kInvalidPageActionError; 115 static const char* kInvalidPageActionError;
108 static const char* kInvalidPageActionsListError; 116 static const char* kInvalidPageActionsListError;
109 static const char* kInvalidPageActionIconPathError; 117 static const char* kInvalidPageActionIconPathError;
118 static const char* kInvalidPageActionIdError;
110 static const char* kInvalidPageActionTooltipError; 119 static const char* kInvalidPageActionTooltipError;
111 static const char* kInvalidPageActionTypeValueError; 120 static const char* kInvalidPageActionTypeValueError;
112 static const char* kInvalidPermissionsError; 121 static const char* kInvalidPermissionsError;
113 static const char* kInvalidPermissionCountWarning; 122 static const char* kInvalidPermissionCountWarning;
114 static const char* kInvalidPermissionError; 123 static const char* kInvalidPermissionError;
115 static const char* kInvalidPermissionSchemeError; 124 static const char* kInvalidPermissionSchemeError;
116 static const char* kInvalidZipHashError; 125 static const char* kInvalidZipHashError;
117 static const char* kInvalidThemeError; 126 static const char* kInvalidThemeError;
118 static const char* kInvalidThemeImagesMissingError; 127 static const char* kInvalidThemeImagesMissingError;
119 static const char* kInvalidThemeImagesError; 128 static const char* kInvalidThemeImagesError;
120 static const char* kInvalidThemeColorsError; 129 static const char* kInvalidThemeColorsError;
121 static const char* kInvalidThemeTintsError; 130 static const char* kInvalidThemeTintsError;
122 static const char* kThemesCannotContainExtensionsError; 131 static const char* kThemesCannotContainExtensionsError;
123 static const char* kMissingFileError; 132 static const char* kMissingFileError;
124 133
125 #if defined(OS_WIN) 134 #if defined(OS_WIN)
126 static const char* kExtensionRegistryPath; 135 static const char* kExtensionRegistryPath;
127 #endif 136 #endif
128 137
129 // The number of bytes in a legal id. 138 // The number of bytes in a legal id.
130 static const size_t kIdSize; 139 static const size_t kIdSize;
131 140
132 Extension() : location_(INVALID), is_theme_(false) {} 141 Extension() : location_(INVALID), is_theme_(false) {}
133 explicit Extension(const FilePath& path); 142 explicit Extension(const FilePath& path);
134 virtual ~Extension(); 143 virtual ~Extension();
135 144
145 // Resets the id counter. This is only useful for unit tests.
146 static void ResetGeneratedIdCounter() {
147 id_counter_ = 0;
148 }
149
136 // Checks to see if the extension has a valid ID. 150 // Checks to see if the extension has a valid ID.
137 static bool IdIsValid(const std::string& id); 151 static bool IdIsValid(const std::string& id);
138 152
139 // Whether the |location| is external or not. 153 // Whether the |location| is external or not.
140 static inline bool IsExternalLocation(Location location) { 154 static inline bool IsExternalLocation(Location location) {
141 return location == Extension::EXTERNAL_PREF || 155 return location == Extension::EXTERNAL_PREF ||
142 location == Extension::EXTERNAL_REGISTRY; 156 location == Extension::EXTERNAL_REGISTRY;
143 } 157 }
144 158
145 // Returns an absolute url to a resource inside of an extension. The 159 // Returns an absolute url to a resource inside of an extension. The
(...skipping 20 matching lines...) Expand all
166 180
167 // |input| is expected to be the text of an rsa public or private key. It 181 // |input| is expected to be the text of an rsa public or private key. It
168 // tolerates the presence or absence of bracking header/footer like this: 182 // tolerates the presence or absence of bracking header/footer like this:
169 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- 183 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
170 // and may contain newlines. 184 // and may contain newlines.
171 static bool ParsePEMKeyBytes(const std::string& input, std::string* output); 185 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
172 186
173 // Does a simple base64 encoding of |input| into |output|. 187 // Does a simple base64 encoding of |input| into |output|.
174 static bool ProducePEM(const std::string& input, std::string* output); 188 static bool ProducePEM(const std::string& input, std::string* output);
175 189
190 // Note: The result is coverted to lower-case because the browser enforces
191 // hosts to be lower-case in omni-bar.
192 static bool GenerateIdFromPublicKey(const std::string& input,
193 std::string* output);
194
176 // Expects base64 encoded |input| and formats into |output| including 195 // Expects base64 encoded |input| and formats into |output| including
177 // the appropriate header & footer. 196 // the appropriate header & footer.
178 static bool FormatPEMForFileOutput(const std::string input, 197 static bool FormatPEMForFileOutput(const std::string input,
179 std::string* output, bool is_public); 198 std::string* output, bool is_public);
180 199
181 // Initialize the extension from a parsed manifest. 200 // Initialize the extension from a parsed manifest.
182 // If |require_id| is true, will return an error if the "id" key is missing 201 // If |require_id| is true, will return an error if the "id" key is missing
183 // from the value. 202 // from the value.
184 bool InitFromValue(const DictionaryValue& value, bool require_id, 203 bool InitFromValue(const DictionaryValue& value, bool require_id,
185 std::string* error); 204 std::string* error);
186 205
187 const FilePath& path() const { return path_; } 206 const FilePath& path() const { return path_; }
188 const GURL& url() const { return extension_url_; } 207 const GURL& url() const { return extension_url_; }
189 const Location location() const { return location_; } 208 const Location location() const { return location_; }
190 void set_location(Location location) { location_ = location; } 209 void set_location(Location location) { location_ = location; }
191 const std::string& id() const { return id_; } 210 const std::string& id() const { return id_; }
192 const Version* version() const { return version_.get(); } 211 const Version* version() const { return version_.get(); }
193 // String representation of the version number. 212 // String representation of the version number.
194 const std::string VersionString() const; 213 const std::string VersionString() const;
195 const std::string& name() const { return name_; } 214 const std::string& name() const { return name_; }
215 const std::string& public_key() const { return public_key_; }
196 const std::string& description() const { return description_; } 216 const std::string& description() const { return description_; }
197 const UserScriptList& content_scripts() const { return content_scripts_; } 217 const UserScriptList& content_scripts() const { return content_scripts_; }
198 const PageActionMap& page_actions() const { return page_actions_; } 218 const PageActionMap& page_actions() const { return page_actions_; }
199 const std::vector<PluginInfo>& plugins() const { return plugins_; } 219 const std::vector<PluginInfo>& plugins() const { return plugins_; }
200 const GURL& background_url() const { return background_url_; } 220 const GURL& background_url() const { return background_url_; }
201 const std::vector<std::string>& toolstrips() const { return toolstrips_; } 221 const std::vector<std::string>& toolstrips() const { return toolstrips_; }
202 const std::vector<URLPattern>& permissions() const { return permissions_; } 222 const std::vector<URLPattern>& permissions() const { return permissions_; }
203 223
204 // Retrieves a page action by |id|. 224 // Retrieves a page action by |id|.
205 const PageAction* GetPageAction(std::string id) const; 225 const PageAction* GetPageAction(std::string id) const;
206 226
207 // Returns the origin of this extension. This function takes a |registry_path| 227 // Returns the origin of this extension. This function takes a |registry_path|
208 // so that the registry location can be overwritten during testing. 228 // so that the registry location can be overwritten during testing.
209 Location ExternalExtensionInstallType(std::string registry_path); 229 Location ExternalExtensionInstallType(std::string registry_path);
210 230
211 // Theme-related. 231 // Theme-related.
212 DictionaryValue* GetThemeImages() const { return theme_images_.get(); } 232 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
213 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); } 233 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); }
214 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } 234 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
215 DictionaryValue* GetThemeDisplayProperties() const { 235 DictionaryValue* GetThemeDisplayProperties() const {
216 return theme_display_properties_.get(); 236 return theme_display_properties_.get();
217 } 237 }
218 bool IsTheme() { return is_theme_; } 238 bool IsTheme() { return is_theme_; }
219 239
220 // Returns a list of paths (relative to the extension dir) for images that 240 // Returns a list of paths (relative to the extension dir) for images that
221 // the browser might load (like themes and page action icons). 241 // the browser might load (like themes and page action icons).
222 std::set<FilePath> GetBrowserImages(); 242 std::set<FilePath> GetBrowserImages();
223 243
224 private: 244 private:
245 // Counter used to assign ids to extensions that are loaded using
246 // --load-extension.
247 static int id_counter_;
248
249 // Returns the next counter id. Intentionally post-incrementing so that first
250 // value is 0.
251 static int NextGeneratedId() { return id_counter_++; }
252
225 // Helper method that loads a UserScript object from a 253 // Helper method that loads a UserScript object from a
226 // dictionary in the content_script list of the manifest. 254 // dictionary in the content_script list of the manifest.
227 bool LoadUserScriptHelper(const DictionaryValue* content_script, 255 bool LoadUserScriptHelper(const DictionaryValue* content_script,
228 int definition_index, 256 int definition_index,
229 std::string* error, 257 std::string* error,
230 UserScript* result); 258 UserScript* result);
231 259
232 // Helper method that loads a PageAction object from a 260 // Helper method that loads a PageAction object from a
233 // dictionary in the page_action list of the manifest. 261 // dictionary in the page_action list of the manifest.
234 PageAction* LoadPageActionHelper(const DictionaryValue* page_action, 262 PageAction* LoadPageActionHelper(const DictionaryValue* page_action,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // Optional list of NPAPI plugins and associated properties. 302 // Optional list of NPAPI plugins and associated properties.
275 std::vector<PluginInfo> plugins_; 303 std::vector<PluginInfo> plugins_;
276 304
277 // Optional URL to a master page of which a single instance should be always 305 // Optional URL to a master page of which a single instance should be always
278 // loaded in the background. 306 // loaded in the background.
279 GURL background_url_; 307 GURL background_url_;
280 308
281 // Paths to HTML files to be displayed in the toolbar. 309 // Paths to HTML files to be displayed in the toolbar.
282 std::vector<std::string> toolstrips_; 310 std::vector<std::string> toolstrips_;
283 311
284 // A SHA1 hash of the contents of the zip file. Note that this key is only 312 // The public key ('key' in the manifest) used to sign the contents of the
285 // present in the manifest that's prepended to the zip. The inner manifest 313 // crx package ('signature' in the manifest)
286 // will not have this key. 314 std::string public_key_;
287 std::string zip_hash_;
288 315
289 // A map of resource id's to relative file paths. 316 // A map of resource id's to relative file paths.
290 scoped_ptr<DictionaryValue> theme_images_; 317 scoped_ptr<DictionaryValue> theme_images_;
291 318
292 // A map of color names to colors. 319 // A map of color names to colors.
293 scoped_ptr<DictionaryValue> theme_colors_; 320 scoped_ptr<DictionaryValue> theme_colors_;
294 321
295 // A map of color names to colors. 322 // A map of color names to colors.
296 scoped_ptr<DictionaryValue> theme_tints_; 323 scoped_ptr<DictionaryValue> theme_tints_;
297 324
298 // A map of display properties. 325 // A map of display properties.
299 scoped_ptr<DictionaryValue> theme_display_properties_; 326 scoped_ptr<DictionaryValue> theme_display_properties_;
300 327
301 // Whether the extension is a theme - if it is, certain things are disabled. 328 // Whether the extension is a theme - if it is, certain things are disabled.
302 bool is_theme_; 329 bool is_theme_;
303 330
304 // The sites this extension has permission to talk to (using XHR, etc). 331 // The sites this extension has permission to talk to (using XHR, etc).
305 std::vector<URLPattern> permissions_; 332 std::vector<URLPattern> permissions_;
306 333
307 DISALLOW_COPY_AND_ASSIGN(Extension); 334 DISALLOW_COPY_AND_ASSIGN(Extension);
308 }; 335 };
309 336
310 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 337 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service_unittest.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698