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

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

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