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