| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_EXTENSION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 virtual bool HasInstalledExtensions() = 0; | 92 virtual bool HasInstalledExtensions() = 0; |
| 93 | 93 |
| 94 virtual ExtensionPrefs* extension_prefs() = 0; | 94 virtual ExtensionPrefs* extension_prefs() = 0; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 // Manages installed and running Chromium extensions. | 97 // Manages installed and running Chromium extensions. |
| 98 class ExtensionService | 98 class ExtensionService |
| 99 : public base::RefCountedThreadSafe<ExtensionService, | 99 : public base::RefCountedThreadSafe<ExtensionService, |
| 100 BrowserThread::DeleteOnUIThread>, | 100 BrowserThread::DeleteOnUIThread>, |
| 101 public ExtensionUpdateService, | 101 public ExtensionUpdateService, |
| 102 public ExternalExtensionProvider::Visitor, |
| 102 public NotificationObserver { | 103 public NotificationObserver { |
| 103 public: | 104 public: |
| 104 // Information about a registered component extension. | 105 // Information about a registered component extension. |
| 105 struct ComponentExtensionInfo { | 106 struct ComponentExtensionInfo { |
| 106 ComponentExtensionInfo(const std::string& manifest, | 107 ComponentExtensionInfo(const std::string& manifest, |
| 107 const FilePath& root_directory) | 108 const FilePath& root_directory) |
| 108 : manifest(manifest), | 109 : manifest(manifest), |
| 109 root_directory(root_directory) { | 110 root_directory(root_directory) { |
| 110 } | 111 } |
| 111 | 112 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // Continues loading all know extensions. It can be called from | 291 // Continues loading all know extensions. It can be called from |
| 291 // LoadAllExtensions or from file thread if we had to relocalize manifest | 292 // LoadAllExtensions or from file thread if we had to relocalize manifest |
| 292 // (write_to_prefs is true in that case). | 293 // (write_to_prefs is true in that case). |
| 293 void ContinueLoadAllExtensions(ExtensionPrefs::ExtensionsInfo* info, | 294 void ContinueLoadAllExtensions(ExtensionPrefs::ExtensionsInfo* info, |
| 294 base::TimeTicks start_time, | 295 base::TimeTicks start_time, |
| 295 bool write_to_prefs); | 296 bool write_to_prefs); |
| 296 | 297 |
| 297 // Check for updates (or potentially new extensions from external providers) | 298 // Check for updates (or potentially new extensions from external providers) |
| 298 void CheckForExternalUpdates(); | 299 void CheckForExternalUpdates(); |
| 299 | 300 |
| 300 // Copies the list of force-installed extensions from the user PrefService | |
| 301 // to ExternalPolicyExtensionProvider. | |
| 302 void UpdateExternalPolicyExtensionProvider(); | |
| 303 | |
| 304 // Unload the specified extension. | 301 // Unload the specified extension. |
| 305 void UnloadExtension(const std::string& extension_id, | 302 void UnloadExtension(const std::string& extension_id, |
| 306 UnloadedExtensionInfo::Reason reason); | 303 UnloadedExtensionInfo::Reason reason); |
| 307 | 304 |
| 308 // Unload all extensions. This is currently only called on shutdown, and | 305 // Unload all extensions. This is currently only called on shutdown, and |
| 309 // does not send notifications. | 306 // does not send notifications. |
| 310 void UnloadAllExtensions(); | 307 void UnloadAllExtensions(); |
| 311 | 308 |
| 312 // Called only by testing. | 309 // Called only by testing. |
| 313 void ReloadExtensions(); | 310 void ReloadExtensions(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 335 // permissions the given extension has been granted. | 332 // permissions the given extension has been granted. |
| 336 bool ExtensionBindingsAllowed(const GURL& url); | 333 bool ExtensionBindingsAllowed(const GURL& url); |
| 337 | 334 |
| 338 // Returns the icon to display in the omnibox for the given extension. | 335 // Returns the icon to display in the omnibox for the given extension. |
| 339 const SkBitmap& GetOmniboxIcon(const std::string& extension_id); | 336 const SkBitmap& GetOmniboxIcon(const std::string& extension_id); |
| 340 | 337 |
| 341 // Returns the icon to display in the omnibox popup window for the given | 338 // Returns the icon to display in the omnibox popup window for the given |
| 342 // extension. | 339 // extension. |
| 343 const SkBitmap& GetOmniboxPopupIcon(const std::string& extension_id); | 340 const SkBitmap& GetOmniboxPopupIcon(const std::string& extension_id); |
| 344 | 341 |
| 345 // Clear all ExternalExtensionProviders. | |
| 346 void ClearProvidersForTesting(); | |
| 347 | |
| 348 // Sets an ExternalExtensionProvider for the service to use during testing. | |
| 349 // Takes ownership of |test_provider|. | |
| 350 void AddProviderForTesting(ExternalExtensionProvider* test_provider); | |
| 351 | |
| 352 // Called when the initial extensions load has completed. | 342 // Called when the initial extensions load has completed. |
| 353 virtual void OnLoadedInstalledExtensions(); | 343 virtual void OnLoadedInstalledExtensions(); |
| 354 | 344 |
| 355 // Called when an extension has been loaded. | 345 // Called when an extension has been loaded. |
| 356 void OnExtensionLoaded(const Extension* extension); | 346 void OnExtensionLoaded(const Extension* extension); |
| 357 | 347 |
| 358 // Called by the backend when an extension has been installed. | 348 // Called by the backend when an extension has been installed. |
| 359 void OnExtensionInstalled(const Extension* extension); | 349 void OnExtensionInstalled(const Extension* extension); |
| 360 | 350 |
| 361 // Called by the backend when an external extension is found. | |
| 362 void OnExternalExtensionFileFound(const std::string& id, | |
| 363 const std::string& version, | |
| 364 const FilePath& path, | |
| 365 Extension::Location location); | |
| 366 | |
| 367 // Checks if the privileges requested by |extension| have increased, and if | 351 // Checks if the privileges requested by |extension| have increased, and if |
| 368 // so, disables the extension and prompts the user to approve the change. | 352 // so, disables the extension and prompts the user to approve the change. |
| 369 void DisableIfPrivilegeIncrease(const Extension* extension); | 353 void DisableIfPrivilegeIncrease(const Extension* extension); |
| 370 | 354 |
| 371 // Go through each extensions in pref, unload blacklisted extensions | 355 // Go through each extensions in pref, unload blacklisted extensions |
| 372 // and update the blacklist state in pref. | 356 // and update the blacklist state in pref. |
| 373 virtual void UpdateExtensionBlacklist( | 357 virtual void UpdateExtensionBlacklist( |
| 374 const std::vector<std::string>& blacklist); | 358 const std::vector<std::string>& blacklist); |
| 375 | 359 |
| 376 // Go through each extension and unload those that the network admin has | 360 // Go through each extension and unload those that the network admin has |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // This method is public because ExtensionServiceBackend can post to here. | 402 // This method is public because ExtensionServiceBackend can post to here. |
| 419 void ReportExtensionLoadError(const FilePath& extension_path, | 403 void ReportExtensionLoadError(const FilePath& extension_path, |
| 420 const std::string& error, | 404 const std::string& error, |
| 421 NotificationType type, | 405 NotificationType type, |
| 422 bool be_noisy); | 406 bool be_noisy); |
| 423 | 407 |
| 424 // ExtensionHost of background page calls this method right after its render | 408 // ExtensionHost of background page calls this method right after its render |
| 425 // view has been created. | 409 // view has been created. |
| 426 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host); | 410 void DidCreateRenderViewForBackgroundPage(ExtensionHost* host); |
| 427 | 411 |
| 412 // For the extension in |version_path| with |id|, check to see if it's an |
| 413 // externally managed extension. If so, uninstall it. |
| 414 void CheckExternalUninstall(const std::string& id); |
| 415 |
| 416 // Clear all ExternalExtensionProviders. |
| 417 void ClearProvidersForTesting(); |
| 418 |
| 419 // Adds an ExternalExtensionProvider for the service to use during testing. |
| 420 // Takes ownership of |test_provider|. |
| 421 void AddProviderForTesting(ExternalExtensionProvider* test_provider); |
| 422 |
| 423 // ExternalExtensionProvider::Visitor implementation. |
| 424 virtual void OnExternalExtensionFileFound(const std::string& id, |
| 425 const Version* version, |
| 426 const FilePath& path, |
| 427 Extension::Location location); |
| 428 |
| 429 virtual void OnExternalExtensionUpdateUrlFound(const std::string& id, |
| 430 const GURL& update_url, |
| 431 Extension::Location location); |
| 432 |
| 433 virtual void OnExternalProviderReady(); |
| 434 |
| 428 // NotificationObserver | 435 // NotificationObserver |
| 429 virtual void Observe(NotificationType type, | 436 virtual void Observe(NotificationType type, |
| 430 const NotificationSource& source, | 437 const NotificationSource& source, |
| 431 const NotificationDetails& details); | 438 const NotificationDetails& details); |
| 432 | 439 |
| 433 // Whether there are any apps installed. Component apps are not included. | 440 // Whether there are any apps installed. Component apps are not included. |
| 434 bool HasApps() const; | 441 bool HasApps() const; |
| 435 | 442 |
| 436 // Gets the set of loaded app ids. Component apps are not included. | 443 // Gets the set of loaded app ids. Component apps are not included. |
| 437 ExtensionIdSet GetAppIds() const; | 444 ExtensionIdSet GetAppIds() const; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 typedef std::map<GURL, int> ProtectedStorageMap; | 589 typedef std::map<GURL, int> ProtectedStorageMap; |
| 583 ProtectedStorageMap protected_storage_map_; | 590 ProtectedStorageMap protected_storage_map_; |
| 584 | 591 |
| 585 // Manages the installation of default apps and the promotion of them in the | 592 // Manages the installation of default apps and the promotion of them in the |
| 586 // app launcher. | 593 // app launcher. |
| 587 DefaultApps default_apps_; | 594 DefaultApps default_apps_; |
| 588 | 595 |
| 589 // Flag to make sure event routers are only initialized once. | 596 // Flag to make sure event routers are only initialized once. |
| 590 bool event_routers_initialized_; | 597 bool event_routers_initialized_; |
| 591 | 598 |
| 599 // A collection of external extension providers. Each provider reads |
| 600 // a source of external extension information. Examples include the |
| 601 // windows registry and external_extensions.json. |
| 602 ProviderCollection external_extension_providers_; |
| 603 |
| 604 // Set to true by OnExternalExtensionUpdateUrlFound() when an external |
| 605 // extension URL is found. Used in CheckForExternalUpdates() to see |
| 606 // if an update check is needed to install pending extensions. |
| 607 bool external_extension_added_; |
| 608 |
| 592 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 609 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 593 UpdatePendingExtensionAlreadyInstalled); | 610 UpdatePendingExtensionAlreadyInstalled); |
| 594 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 611 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 595 InstallAppsWithUnlimtedStorage); | 612 InstallAppsWithUnlimtedStorage); |
| 596 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 613 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 597 InstallAppsAndCheckStorageProtection); | 614 InstallAppsAndCheckStorageProtection); |
| 598 DISALLOW_COPY_AND_ASSIGN(ExtensionService); | 615 DISALLOW_COPY_AND_ASSIGN(ExtensionService); |
| 599 }; | 616 }; |
| 600 | 617 |
| 601 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 618 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
| OLD | NEW |