OLD | NEW |
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_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 14 matching lines...) Expand all Loading... |
25 class GURL; | 25 class GURL; |
26 class PrefService; | 26 class PrefService; |
27 class Profile; | 27 class Profile; |
28 class ResourceDispatcherHost; | 28 class ResourceDispatcherHost; |
29 class SkBitmap; | 29 class SkBitmap; |
30 class SiteInstance; | 30 class SiteInstance; |
31 class UserScriptMaster; | 31 class UserScriptMaster; |
32 | 32 |
33 typedef std::vector<Extension*> ExtensionList; | 33 typedef std::vector<Extension*> ExtensionList; |
34 | 34 |
| 35 |
35 // Manages installed and running Chromium extensions. | 36 // Manages installed and running Chromium extensions. |
36 class ExtensionsService | 37 class ExtensionsService |
37 : public base::RefCountedThreadSafe<ExtensionsService> { | 38 : public base::RefCountedThreadSafe<ExtensionsService> { |
38 public: | 39 public: |
| 40 |
| 41 // TODO(port): Move Crx package definitions to ExtentionCreator. They are |
| 42 // currently here because ExtensionCreator is excluded on linux & mac. |
| 43 |
| 44 // The size of the magic character sequence at the beginning of each crx |
| 45 // file, in bytes. This should be a multiple of 4. |
| 46 static const size_t kExtensionHeaderMagicSize = 4; |
| 47 |
| 48 // The maximum size the crx parser will tolerate for a public key. |
| 49 static const size_t kMaxPublicKeySize = 1 << 16; |
| 50 |
| 51 // The maximum size the crx parser will tolerate for a signature. |
| 52 static const size_t kMaxSignatureSize = 1 << 16; |
| 53 |
| 54 // The magic character sequence at the beginning of each crx file. |
| 55 static const char kExtensionHeaderMagic[]; |
| 56 |
| 57 // The current version of the crx format. |
| 58 static const uint32 kCurrentVersion = 2; |
| 59 |
| 60 // This header is the first data at the beginning of an extension. Its |
| 61 // contents are purposely 32-bit aligned so that it can just be slurped into |
| 62 // a struct without manual parsing. |
| 63 struct ExtensionHeader { |
| 64 char magic[kExtensionHeaderMagicSize]; |
| 65 uint32 version; |
| 66 size_t key_size; // The size of the public key, in bytes. |
| 67 size_t signature_size; // The size of the signature, in bytes. |
| 68 // An ASN.1-encoded PublicKeyInfo structure follows. |
| 69 // The signature follows. |
| 70 }; |
| 71 |
39 ExtensionsService(Profile* profile, | 72 ExtensionsService(Profile* profile, |
40 MessageLoop* frontend_loop, | 73 MessageLoop* frontend_loop, |
41 MessageLoop* backend_loop, | 74 MessageLoop* backend_loop, |
42 const std::string& registry_path); | 75 const std::string& registry_path); |
43 ~ExtensionsService(); | 76 ~ExtensionsService(); |
44 | 77 |
45 // Gets the list of currently installed extensions. | 78 // Gets the list of currently installed extensions. |
46 const ExtensionList* extensions() const { | 79 const ExtensionList* extensions() const { |
47 return &extensions_; | 80 return &extensions_; |
48 } | 81 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 134 |
102 private: | 135 private: |
103 // For OnExtensionLoaded, OnExtensionInstalled, and | 136 // For OnExtensionLoaded, OnExtensionInstalled, and |
104 // OnExtensionVersionReinstalled. | 137 // OnExtensionVersionReinstalled. |
105 friend class ExtensionsServiceBackend; | 138 friend class ExtensionsServiceBackend; |
106 | 139 |
107 // Called by the backend when extensions have been loaded. | 140 // Called by the backend when extensions have been loaded. |
108 void OnExtensionsLoaded(ExtensionList* extensions); | 141 void OnExtensionsLoaded(ExtensionList* extensions); |
109 | 142 |
110 // Called by the backend when an extensoin hsa been installed. | 143 // Called by the backend when an extensoin hsa been installed. |
111 void OnExtensionInstalled(Extension* extension, bool is_update); | 144 void OnExtensionInstalled(Extension* extension, |
| 145 Extension::InstallType install_type); |
112 | 146 |
113 // Called by the backend when an external extension has been installed. | 147 // Called by the backend when an external extension has been installed. |
114 void OnExternalExtensionInstalled( | 148 void OnExternalExtensionInstalled( |
115 const std::string& id, Extension::Location location); | 149 const std::string& id, Extension::Location location); |
116 | 150 |
117 // Called by the backend when an extension has been reinstalled. | 151 // Called by the backend when an attempt was made to reinstall the same |
118 void OnExtensionVersionReinstalled(const std::string& id); | 152 // version of an existing extension. |
| 153 void OnExtensionOverinstallAttempted(const std::string& id); |
119 | 154 |
120 // The name of the directory inside the profile where extensions are | 155 // The name of the directory inside the profile where extensions are |
121 // installed to. | 156 // installed to. |
122 static const char* kInstallDirectoryName; | 157 static const char* kInstallDirectoryName; |
123 | 158 |
124 // Preferences for the owning profile. | 159 // Preferences for the owning profile. |
125 PrefService* prefs_; | 160 PrefService* prefs_; |
126 | 161 |
127 // The message loop to use with the backend. | 162 // The message loop to use with the backend. |
128 MessageLoop* backend_loop_; | 163 MessageLoop* backend_loop_; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 226 |
192 // Deletes all versions of the extension from the filesystem. Note that only | 227 // Deletes all versions of the extension from the filesystem. Note that only |
193 // extensions whose location() == INTERNAL can be uninstalled. Attempting to | 228 // extensions whose location() == INTERNAL can be uninstalled. Attempting to |
194 // uninstall other extensions will silently fail. | 229 // uninstall other extensions will silently fail. |
195 void UninstallExtension(const std::string& extension_id); | 230 void UninstallExtension(const std::string& extension_id); |
196 | 231 |
197 private: | 232 private: |
198 class UnpackerClient; | 233 class UnpackerClient; |
199 friend class UnpackerClient; | 234 friend class UnpackerClient; |
200 | 235 |
| 236 // Utility function to read an extension manifest and return it as a |
| 237 // DictionaryValue. If it fails, NULL is returned and |error| contains an |
| 238 // appropriate message. |
| 239 DictionaryValue* ReadManifest(FilePath manifest_path, std::string* error); |
| 240 |
201 // Load a single extension from |extension_path|, the top directory of | 241 // Load a single extension from |extension_path|, the top directory of |
202 // a specific extension where its manifest file lives. | 242 // a specific extension where its manifest file lives. |
203 Extension* LoadExtension(const FilePath& extension_path, bool require_id); | 243 Extension* LoadExtension(const FilePath& extension_path, bool require_id); |
204 | 244 |
205 // Load a single extension from |extension_path|, the top directory of | 245 // Load a single extension from |extension_path|, the top directory of |
206 // a versioned extension where its Current Version file lives. | 246 // a versioned extension where its Current Version file lives. |
207 Extension* LoadExtensionCurrentVersion(const FilePath& extension_path); | 247 Extension* LoadExtensionCurrentVersion(const FilePath& extension_path); |
208 | 248 |
209 // Install a crx file at |extension_path|. If |expected_id| is not empty, it's | 249 // Install a crx file at |extension_path|. If |expected_id| is not empty, it's |
210 // verified against the extension's manifest before installation. If | 250 // verified against the extension's manifest before installation. If |
211 // |from_external| is true, this extension install is from an external source, | 251 // |from_external| is true, this extension install is from an external source, |
212 // ie the Windows registry, and will be marked as such. If the extension is | 252 // ie the Windows registry, and will be marked as such. If the extension is |
213 // already installed, install the new version only if its version number is | 253 // already installed, install the new version only if its version number is |
214 // greater than the current installed version. | 254 // greater than the current installed version. |
215 void InstallOrUpdateExtension(const FilePath& extension_path, | 255 void InstallOrUpdateExtension(const FilePath& extension_path, |
216 const std::string& expected_id, | 256 const std::string& expected_id, |
217 bool from_external); | 257 bool from_external); |
218 | 258 |
| 259 // Validates the signature of the extension in |extension_path|. Returns true |
| 260 // and the public key (in |key|) if the signature validates, false otherwise. |
| 261 bool ValidateSignature(const FilePath& extension_path, std::string* key_out); |
| 262 |
219 // Finish installing an extension after it has been unpacked to | 263 // Finish installing an extension after it has been unpacked to |
220 // |temp_extension_dir| by our utility process. If |expected_id| is not | 264 // |temp_extension_dir| by our utility process. If |expected_id| is not |
221 // empty, it's verified against the extension's manifest before installation. | 265 // empty, it's verified against the extension's manifest before installation. |
222 // |manifest| and |images| are parsed information from the extension that | 266 // |manifest| and |images| are parsed information from the extension that |
223 // we want to write to disk in the browser process. | 267 // we want to write to disk in the browser process. |
224 void OnExtensionUnpacked( | 268 void OnExtensionUnpacked( |
225 const FilePath& extension_path, | 269 const FilePath& extension_path, |
226 const FilePath& temp_extension_dir, | 270 const FilePath& temp_extension_dir, |
227 const std::string expected_id, | 271 const std::string expected_id, |
228 bool from_external, | 272 bool from_external, |
229 const DictionaryValue& manifest, | 273 const DictionaryValue& manifest, |
230 const std::vector< Tuple2<SkBitmap, FilePath> >& images); | 274 const std::vector< Tuple2<SkBitmap, FilePath> >& images); |
231 | 275 |
232 // Notify the frontend that there was an error loading an extension. | 276 // Notify the frontend that there was an error loading an extension. |
233 void ReportExtensionLoadError(const FilePath& extension_path, | 277 void ReportExtensionLoadError(const FilePath& extension_path, |
234 const std::string& error); | 278 const std::string& error); |
235 | 279 |
236 // Notify the frontend that extensions were loaded. | 280 // Notify the frontend that extensions were loaded. |
237 void ReportExtensionsLoaded(ExtensionList* extensions); | 281 void ReportExtensionsLoaded(ExtensionList* extensions); |
238 | 282 |
239 // Notify the frontend that there was an error installing an extension. | 283 // Notify the frontend that there was an error installing an extension. |
240 void ReportExtensionInstallError(const FilePath& extension_path, | 284 void ReportExtensionInstallError(const FilePath& extension_path, |
241 const std::string& error); | 285 const std::string& error); |
242 | 286 |
243 // Notify the frontend that the extension had already been installed. | 287 // Notify the frontend that an attempt was made (but not carried out) to |
244 void ReportExtensionVersionReinstalled(const std::string& id); | 288 // install the same version of an existing extension. |
| 289 void ReportExtensionOverinstallAttempted(const std::string& id); |
245 | 290 |
246 // Checks a set of strings (containing id's to ignore) in order to determine | 291 // Checks a set of strings (containing id's to ignore) in order to determine |
247 // if the extension should be installed. | 292 // if the extension should be installed. |
248 bool ShouldSkipInstallingExtension(const std::set<std::string>& ids_to_ignore, | 293 bool ShouldSkipInstallingExtension(const std::set<std::string>& ids_to_ignore, |
249 const std::string& id); | 294 const std::string& id); |
250 | 295 |
251 // Installs the extension if the extension is a newer version or if the | 296 // Installs the extension if the extension is a newer version or if the |
252 // extension hasn't been installed before. | 297 // extension hasn't been installed before. |
253 void CheckVersionAndInstallExtension(const std::string& id, | 298 void CheckVersionAndInstallExtension(const std::string& id, |
254 const std::string& extension_version, | 299 const std::string& extension_version, |
255 const FilePath& extension_path, | 300 const FilePath& extension_path, |
256 bool from_external); | 301 bool from_external); |
257 | 302 |
258 // Read the manifest from the front of the extension file. | 303 // Read the manifest from the front of the extension file. |
259 // Caller takes ownership of return value. | 304 // Caller takes ownership of return value. |
260 DictionaryValue* ReadManifest(const FilePath& extension_path); | 305 DictionaryValue* ReadManifest(const FilePath& extension_path); |
261 | 306 |
262 // Reads the Current Version file from |dir| into |version_string|. | 307 // Reads the Current Version file from |dir| into |version_string|. |
263 bool ReadCurrentVersion(const FilePath& dir, std::string* version_string); | 308 bool ReadCurrentVersion(const FilePath& dir, std::string* version_string); |
264 | 309 |
265 // Check that the version to be installed is greater than the current | 310 // Look for an existing installation of the extension |id| & return |
266 // installed extension. | 311 // an InstallType that would result from installing |new_version_str|. |
267 bool CheckCurrentVersion(const std::string& version, | 312 Extension::InstallType CompareToInstalledVersion(const std::string& id, |
268 const std::string& current_version, | 313 const std::string& new_version_str, std::string* current_version_str); |
269 const FilePath& dest_dir); | 314 |
| 315 // Does an existing installed extension need to be reinstalled. |
| 316 bool NeedsReinstall(const std::string& id, |
| 317 const std::string& current_version); |
270 | 318 |
271 // Install the extension dir by moving it from |source| to |dest| safely. | 319 // Install the extension dir by moving it from |source| to |dest| safely. |
272 bool InstallDirSafely(const FilePath& source, | 320 bool InstallDirSafely(const FilePath& source, |
273 const FilePath& dest); | 321 const FilePath& dest); |
274 | 322 |
275 // Update the CurrentVersion file in |dest_dir| to |version|. | 323 // Update the CurrentVersion file in |dest_dir| to |version|. |
276 bool SetCurrentVersion(const FilePath& dest_dir, | 324 bool SetCurrentVersion(const FilePath& dest_dir, |
277 std::string version); | 325 std::string version); |
278 | 326 |
279 // For the extension in |version_path| with |id|, check to see if it's an | 327 // For the extension in |version_path| with |id|, check to see if it's an |
(...skipping 30 matching lines...) Expand all Loading... |
310 | 358 |
311 // The path to look for externally registered extensions in. This is a | 359 // The path to look for externally registered extensions in. This is a |
312 // registry key on windows, but it could be a similar string for the | 360 // registry key on windows, but it could be a similar string for the |
313 // appropriate system on other platforms in the future. | 361 // appropriate system on other platforms in the future. |
314 std::string registry_path_; | 362 std::string registry_path_; |
315 | 363 |
316 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); | 364 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceBackend); |
317 }; | 365 }; |
318 | 366 |
319 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ | 367 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_SERVICE_H_ |
OLD | NEW |