| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/linked_ptr.h" | 18 #include "base/memory/linked_ptr.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/task.h" | 21 #include "base/task.h" |
| 22 #include "base/time.h" | 22 #include "base/time.h" |
| 23 #include "base/tuple.h" | 23 #include "base/tuple.h" |
| 24 #include "chrome/browser/extensions/apps_promo.h" | 24 #include "chrome/browser/extensions/apps_promo.h" |
| 25 #include "chrome/browser/extensions/extension_app_api.h" | 25 #include "chrome/browser/extensions/extension_app_api.h" |
| 26 #include "chrome/browser/extensions/extension_icon_manager.h" | 26 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 27 #include "chrome/browser/extensions/extension_menu_manager.h" | 27 #include "chrome/browser/extensions/extension_menu_manager.h" |
| 28 #include "chrome/browser/extensions/extension_prefs.h" | 28 #include "chrome/browser/extensions/extension_prefs.h" |
| 29 #include "chrome/browser/extensions/extension_permissions_api.h" |
| 29 #include "chrome/browser/extensions/extension_process_manager.h" | 30 #include "chrome/browser/extensions/extension_process_manager.h" |
| 30 #include "chrome/browser/extensions/extension_toolbar_model.h" | 31 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 31 #include "chrome/browser/extensions/extensions_quota_service.h" | 32 #include "chrome/browser/extensions/extensions_quota_service.h" |
| 32 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 33 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
| 33 #include "chrome/browser/extensions/pending_extension_manager.h" | 34 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 34 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 35 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
| 35 #include "chrome/browser/prefs/pref_change_registrar.h" | 36 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 36 #include "chrome/common/extensions/extension.h" | 37 #include "chrome/common/extensions/extension.h" |
| 37 #include "content/browser/browser_thread.h" | 38 #include "content/browser/browser_thread.h" |
| 38 #include "content/common/notification_observer.h" | 39 #include "content/common/notification_observer.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 313 |
| 313 // Updates the |extension|'s granted permissions lists to include all | 314 // Updates the |extension|'s granted permissions lists to include all |
| 314 // permissions in the |extension|'s manifest. | 315 // permissions in the |extension|'s manifest. |
| 315 void GrantPermissions(const Extension* extension); | 316 void GrantPermissions(const Extension* extension); |
| 316 | 317 |
| 317 // Updates the |extension|'s granted permissions lists to include all | 318 // Updates the |extension|'s granted permissions lists to include all |
| 318 // permissions in the |extension|'s manifest and re-enables the | 319 // permissions in the |extension|'s manifest and re-enables the |
| 319 // extension. | 320 // extension. |
| 320 void GrantPermissionsAndEnableExtension(const Extension* extension); | 321 void GrantPermissionsAndEnableExtension(const Extension* extension); |
| 321 | 322 |
| 323 // Sets the |extension|'s active permissions to |permissions|. |
| 324 void UpdateActivePermissions(const Extension* extension, |
| 325 const ExtensionPermissionSet* permissions); |
| 326 |
| 322 // Loads the extension from the directory |extension_path|. | 327 // Loads the extension from the directory |extension_path|. |
| 323 void LoadExtension(const FilePath& extension_path); | 328 void LoadExtension(const FilePath& extension_path); |
| 324 | 329 |
| 325 // Same as above, but for use with command line switch --load-extension=path. | 330 // Same as above, but for use with command line switch --load-extension=path. |
| 326 void LoadExtensionFromCommandLine(const FilePath& extension_path); | 331 void LoadExtensionFromCommandLine(const FilePath& extension_path); |
| 327 | 332 |
| 328 // Loads any component extensions. | 333 // Loads any component extensions. |
| 329 void LoadComponentExtensions(); | 334 void LoadComponentExtensions(); |
| 330 | 335 |
| 331 // Loads particular component extension. | 336 // Loads particular component extension. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 void AddExtension(const Extension* extension); | 402 void AddExtension(const Extension* extension); |
| 398 | 403 |
| 399 // Called by the backend when an unpacked extension has been loaded. | 404 // Called by the backend when an unpacked extension has been loaded. |
| 400 void OnLoadSingleExtension(const Extension* extension, | 405 void OnLoadSingleExtension(const Extension* extension, |
| 401 bool prompt_for_plugins); | 406 bool prompt_for_plugins); |
| 402 | 407 |
| 403 // Called by the backend when an extension has been installed. | 408 // Called by the backend when an extension has been installed. |
| 404 void OnExtensionInstalled( | 409 void OnExtensionInstalled( |
| 405 const Extension* extension, bool from_webstore); | 410 const Extension* extension, bool from_webstore); |
| 406 | 411 |
| 407 // Checks if the privileges requested by |extension| have increased, and if | 412 // Initializes the |extension|'s active permission set and disables the |
| 408 // so, disables the extension and prompts the user to approve the change. | 413 // extension if the privilege level has increased (e.g., due to an upgrade). |
| 409 void DisableIfPrivilegeIncrease(const Extension* extension); | 414 void InitializePermissions(const Extension* extension); |
| 410 | 415 |
| 411 // Go through each extensions in pref, unload blacklisted extensions | 416 // Go through each extensions in pref, unload blacklisted extensions |
| 412 // and update the blacklist state in pref. | 417 // and update the blacklist state in pref. |
| 413 virtual void UpdateExtensionBlacklist( | 418 virtual void UpdateExtensionBlacklist( |
| 414 const std::vector<std::string>& blacklist) OVERRIDE; | 419 const std::vector<std::string>& blacklist) OVERRIDE; |
| 415 | 420 |
| 416 // Go through each extension and unload those that the network admin has | 421 // Go through each extension and unload those that the network admin has |
| 417 // put on the blacklist (not to be confused with the Google managed blacklist | 422 // put on the blacklist (not to be confused with the Google managed blacklist |
| 418 // set of extensions. | 423 // set of extensions. |
| 419 virtual void CheckAdminBlacklist() OVERRIDE; | 424 virtual void CheckAdminBlacklist() OVERRIDE; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; } | 465 ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; } |
| 461 | 466 |
| 462 ExtensionsQuotaService* quota_service() { return "a_service_; } | 467 ExtensionsQuotaService* quota_service() { return "a_service_; } |
| 463 | 468 |
| 464 ExtensionMenuManager* menu_manager() { return &menu_manager_; } | 469 ExtensionMenuManager* menu_manager() { return &menu_manager_; } |
| 465 | 470 |
| 466 AppNotificationManager* app_notification_manager() { | 471 AppNotificationManager* app_notification_manager() { |
| 467 return &app_notification_manager_; | 472 return &app_notification_manager_; |
| 468 } | 473 } |
| 469 | 474 |
| 475 ExtensionPermissionsManager* permissions_manager() { |
| 476 return &permissions_manager_; |
| 477 } |
| 478 |
| 470 ExtensionBrowserEventRouter* browser_event_router() { | 479 ExtensionBrowserEventRouter* browser_event_router() { |
| 471 return browser_event_router_.get(); | 480 return browser_event_router_.get(); |
| 472 } | 481 } |
| 473 | 482 |
| 474 // Notify the frontend that there was an error loading an extension. | 483 // Notify the frontend that there was an error loading an extension. |
| 475 // This method is public because ExtensionServiceBackend can post to here. | 484 // This method is public because ExtensionServiceBackend can post to here. |
| 476 void ReportExtensionLoadError(const FilePath& extension_path, | 485 void ReportExtensionLoadError(const FilePath& extension_path, |
| 477 const std::string& error, | 486 const std::string& error, |
| 478 int type, | 487 int type, |
| 479 bool be_noisy); | 488 bool be_noisy); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 // Clear all persistent data that may have been stored by the extension. | 581 // Clear all persistent data that may have been stored by the extension. |
| 573 void ClearExtensionData(const GURL& extension_url); | 582 void ClearExtensionData(const GURL& extension_url); |
| 574 | 583 |
| 575 // Look up an extension by ID, optionally including either or both of enabled | 584 // Look up an extension by ID, optionally including either or both of enabled |
| 576 // and disabled extensions. | 585 // and disabled extensions. |
| 577 const Extension* GetExtensionByIdInternal(const std::string& id, | 586 const Extension* GetExtensionByIdInternal(const std::string& id, |
| 578 bool include_enabled, | 587 bool include_enabled, |
| 579 bool include_disabled, | 588 bool include_disabled, |
| 580 bool include_terminated) const; | 589 bool include_terminated) const; |
| 581 | 590 |
| 582 | |
| 583 // Adds the given extension to the list of terminated extensions if | 591 // Adds the given extension to the list of terminated extensions if |
| 584 // it is not already there and unloads it. | 592 // it is not already there and unloads it. |
| 585 void TrackTerminatedExtension(const Extension* extension); | 593 void TrackTerminatedExtension(const Extension* extension); |
| 586 | 594 |
| 587 // Removes the extension with the given id from the list of | 595 // Removes the extension with the given id from the list of |
| 588 // terminated extensions if it is there. | 596 // terminated extensions if it is there. |
| 589 void UntrackTerminatedExtension(const std::string& id); | 597 void UntrackTerminatedExtension(const std::string& id); |
| 590 | 598 |
| 591 // Handles sending notification that |extension| was loaded. | 599 // Handles sending notification that |extension| was loaded. |
| 592 void NotifyExtensionLoaded(const Extension* extension); | 600 void NotifyExtensionLoaded(const Extension* extension); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 702 |
| 695 NotificationRegistrar registrar_; | 703 NotificationRegistrar registrar_; |
| 696 PrefChangeRegistrar pref_change_registrar_; | 704 PrefChangeRegistrar pref_change_registrar_; |
| 697 | 705 |
| 698 // Keeps track of menu items added by extensions. | 706 // Keeps track of menu items added by extensions. |
| 699 ExtensionMenuManager menu_manager_; | 707 ExtensionMenuManager menu_manager_; |
| 700 | 708 |
| 701 // Keeps track of app notifications. | 709 // Keeps track of app notifications. |
| 702 AppNotificationManager app_notification_manager_; | 710 AppNotificationManager app_notification_manager_; |
| 703 | 711 |
| 712 // Keeps track of extension permissions. |
| 713 ExtensionPermissionsManager permissions_manager_; |
| 714 |
| 704 // Keeps track of favicon-sized omnibox icons for extensions. | 715 // Keeps track of favicon-sized omnibox icons for extensions. |
| 705 ExtensionIconManager omnibox_icon_manager_; | 716 ExtensionIconManager omnibox_icon_manager_; |
| 706 ExtensionIconManager omnibox_popup_icon_manager_; | 717 ExtensionIconManager omnibox_popup_icon_manager_; |
| 707 | 718 |
| 708 // List of registered component extensions (see Extension::Location). | 719 // List of registered component extensions (see Extension::Location). |
| 709 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; | 720 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; |
| 710 RegisteredComponentExtensions component_extension_manifests_; | 721 RegisteredComponentExtensions component_extension_manifests_; |
| 711 | 722 |
| 712 // Manages the promotion of the web store. | 723 // Manages the promotion of the web store. |
| 713 AppsPromo apps_promo_; | 724 AppsPromo apps_promo_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 742 NaClModuleInfoList nacl_module_list_; | 753 NaClModuleInfoList nacl_module_list_; |
| 743 | 754 |
| 744 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 755 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 745 InstallAppsWithUnlimtedStorage); | 756 InstallAppsWithUnlimtedStorage); |
| 746 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 757 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 747 InstallAppsAndCheckStorageProtection); | 758 InstallAppsAndCheckStorageProtection); |
| 748 DISALLOW_COPY_AND_ASSIGN(ExtensionService); | 759 DISALLOW_COPY_AND_ASSIGN(ExtensionService); |
| 749 }; | 760 }; |
| 750 | 761 |
| 751 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 762 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
| OLD | NEW |