| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 virtual bool UpdateExtension( | 321 virtual bool UpdateExtension( |
| 322 const std::string& id, | 322 const std::string& id, |
| 323 const base::FilePath& extension_path, | 323 const base::FilePath& extension_path, |
| 324 const GURL& download_url, | 324 const GURL& download_url, |
| 325 extensions::CrxInstaller** out_crx_installer) OVERRIDE; | 325 extensions::CrxInstaller** out_crx_installer) OVERRIDE; |
| 326 | 326 |
| 327 // Reloads the specified extension, sending the onLaunched() event to it if it | 327 // Reloads the specified extension, sending the onLaunched() event to it if it |
| 328 // currently has any window showing. | 328 // currently has any window showing. |
| 329 void ReloadExtension(const std::string& extension_id); | 329 void ReloadExtension(const std::string& extension_id); |
| 330 | 330 |
| 331 // Reloads an extension and sends it the onRestarted() event. | |
| 332 void RestartExtension(const std::string& extension_id); | |
| 333 | |
| 334 // Uninstalls the specified extension. Callers should only call this method | 331 // Uninstalls the specified extension. Callers should only call this method |
| 335 // with extensions that exist. |external_uninstall| is a magical parameter | 332 // with extensions that exist. |external_uninstall| is a magical parameter |
| 336 // that is only used to send information to ExtensionPrefs, which external | 333 // that is only used to send information to ExtensionPrefs, which external |
| 337 // callers should never set to true. | 334 // callers should never set to true. |
| 338 // | 335 // |
| 339 // We pass the |extension_id| by value to avoid having it deleted from under | 336 // We pass the |extension_id| by value to avoid having it deleted from under |
| 340 // us incase someone calls it with Extension::id() or another string that we | 337 // us incase someone calls it with Extension::id() or another string that we |
| 341 // are going to delete in this function. | 338 // are going to delete in this function. |
| 342 // | 339 // |
| 343 // TODO(aa): Remove |external_uninstall| -- this information should be passed | 340 // TODO(aa): Remove |external_uninstall| -- this information should be passed |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // Adds |extension| to this ExtensionService and notifies observers that the | 409 // Adds |extension| to this ExtensionService and notifies observers that the |
| 413 // extensions have been loaded. | 410 // extensions have been loaded. |
| 414 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE; | 411 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE; |
| 415 | 412 |
| 416 // Check if we have preferences for the component extension and, if not or if | 413 // Check if we have preferences for the component extension and, if not or if |
| 417 // the stored version differs, install the extension (without requirements | 414 // the stored version differs, install the extension (without requirements |
| 418 // checking) before calling AddExtension. | 415 // checking) before calling AddExtension. |
| 419 virtual void AddComponentExtension(const extensions::Extension* extension) | 416 virtual void AddComponentExtension(const extensions::Extension* extension) |
| 420 OVERRIDE; | 417 OVERRIDE; |
| 421 | 418 |
| 422 // Launch an extension the next time it is loaded. | |
| 423 void ScheduleLaunchOnLoad(const std::string& extension_id); | |
| 424 | |
| 425 // Informs the service that an extension's files are in place for loading. | 419 // Informs the service that an extension's files are in place for loading. |
| 426 // | 420 // |
| 427 // Please make sure the Blacklist is checked some time before calling this | 421 // Please make sure the Blacklist is checked some time before calling this |
| 428 // method. | 422 // method. |
| 429 void OnExtensionInstalled( | 423 void OnExtensionInstalled( |
| 430 const extensions::Extension* extension, | 424 const extensions::Extension* extension, |
| 431 const syncer::StringOrdinal& page_ordinal, | 425 const syncer::StringOrdinal& page_ordinal, |
| 432 bool has_requirement_errors, | 426 bool has_requirement_errors, |
| 433 bool wait_for_idle); | 427 bool wait_for_idle); |
| 434 | 428 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 void OnExtensionInstallPrefChanged(); | 706 void OnExtensionInstallPrefChanged(); |
| 713 | 707 |
| 714 // Handles setting the extension specific values in |extension_sync_data| to | 708 // Handles setting the extension specific values in |extension_sync_data| to |
| 715 // the current system. | 709 // the current system. |
| 716 // Returns false if the changes were not completely applied and need to be | 710 // Returns false if the changes were not completely applied and need to be |
| 717 // tried again later. | 711 // tried again later. |
| 718 bool ProcessExtensionSyncDataHelper( | 712 bool ProcessExtensionSyncDataHelper( |
| 719 const extensions::ExtensionSyncData& extension_sync_data, | 713 const extensions::ExtensionSyncData& extension_sync_data, |
| 720 syncer::ModelType type); | 714 syncer::ModelType type); |
| 721 | 715 |
| 722 // Events to be fired after an extension is reloaded. | |
| 723 enum PostReloadEvents { | |
| 724 EVENT_NONE = 0, | |
| 725 EVENT_LAUNCHED = 1 << 0, | |
| 726 EVENT_RESTARTED = 1 << 1, | |
| 727 }; | |
| 728 | |
| 729 // Adds the given extension to the list of terminated extensions if | 716 // Adds the given extension to the list of terminated extensions if |
| 730 // it is not already there and unloads it. | 717 // it is not already there and unloads it. |
| 731 void TrackTerminatedExtension(const extensions::Extension* extension); | 718 void TrackTerminatedExtension(const extensions::Extension* extension); |
| 732 | 719 |
| 733 // Removes the extension with the given id from the list of | 720 // Removes the extension with the given id from the list of |
| 734 // terminated extensions if it is there. | 721 // terminated extensions if it is there. |
| 735 void UntrackTerminatedExtension(const std::string& id); | 722 void UntrackTerminatedExtension(const std::string& id); |
| 736 | 723 |
| 737 // Update preferences for a new or updated extension; notify observers that | 724 // Update preferences for a new or updated extension; notify observers that |
| 738 // the extension is installed, e.g., to update event handlers on background | 725 // the extension is installed, e.g., to update event handlers on background |
| 739 // pages; and perform other extension install tasks before calling | 726 // pages; and perform other extension install tasks before calling |
| 740 // AddExtension. | 727 // AddExtension. |
| 741 void AddNewOrUpdatedExtension(const extensions::Extension* extension, | 728 void AddNewOrUpdatedExtension(const extensions::Extension* extension, |
| 742 extensions::Extension::State initial_state, | 729 extensions::Extension::State initial_state, |
| 743 const syncer::StringOrdinal& page_ordinal); | 730 const syncer::StringOrdinal& page_ordinal); |
| 744 | 731 |
| 745 // Handles sending notification that |extension| was loaded. | 732 // Handles sending notification that |extension| was loaded. |
| 746 void NotifyExtensionLoaded(const extensions::Extension* extension); | 733 void NotifyExtensionLoaded(const extensions::Extension* extension); |
| 747 | 734 |
| 748 // Handles sending notification that |extension| was unloaded. | 735 // Handles sending notification that |extension| was unloaded. |
| 749 void NotifyExtensionUnloaded(const extensions::Extension* extension, | 736 void NotifyExtensionUnloaded(const extensions::Extension* extension, |
| 750 extension_misc::UnloadedExtensionReason reason); | 737 extension_misc::UnloadedExtensionReason reason); |
| 751 | 738 |
| 752 // Common helper to finish installing the given extension. | 739 // Common helper to finish installing the given extension. |
| 753 void FinishInstallation(const extensions::Extension* extension); | 740 void FinishInstallation(const extensions::Extension* extension); |
| 754 | 741 |
| 755 // Reloads |extension_id| and then dispatches to it the PostReloadEvents | |
| 756 // indicated by |events|. | |
| 757 void ReloadExtensionWithEvents(const std::string& extension_id, | |
| 758 int events); | |
| 759 | |
| 760 // Updates the |extension|'s active permission set to include only permissions | 742 // Updates the |extension|'s active permission set to include only permissions |
| 761 // currently requested by the extension and all the permissions required by | 743 // currently requested by the extension and all the permissions required by |
| 762 // the extension. | 744 // the extension. |
| 763 void UpdateActivePermissions(const extensions::Extension* extension); | 745 void UpdateActivePermissions(const extensions::Extension* extension); |
| 764 | 746 |
| 765 // Disables the extension if the privilege level has increased | 747 // Disables the extension if the privilege level has increased |
| 766 // (e.g., due to an upgrade). | 748 // (e.g., due to an upgrade). |
| 767 void CheckPermissionsIncrease(const extensions::Extension* extension, | 749 void CheckPermissionsIncrease(const extensions::Extension* extension, |
| 768 bool is_upgrade); | 750 bool is_upgrade); |
| 769 | 751 |
| 770 // Returns true if the app with id |extension_id| has any shell windows open. | |
| 771 bool HasShellWindows(const std::string& extension_id); | |
| 772 | |
| 773 // Helper that updates the active extension list used for crash reporting. | 752 // Helper that updates the active extension list used for crash reporting. |
| 774 void UpdateActiveExtensionsInCrashReporter(); | 753 void UpdateActiveExtensionsInCrashReporter(); |
| 775 | 754 |
| 776 // We implement some Pepper plug-ins using NaCl to take advantage of NaCl's | 755 // We implement some Pepper plug-ins using NaCl to take advantage of NaCl's |
| 777 // strong sandbox. Typically, these NaCl modules are stored in extensions | 756 // strong sandbox. Typically, these NaCl modules are stored in extensions |
| 778 // and registered here. Not all NaCl modules need to register for a MIME | 757 // and registered here. Not all NaCl modules need to register for a MIME |
| 779 // type, just the ones that are responsible for rendering a particular MIME | 758 // type, just the ones that are responsible for rendering a particular MIME |
| 780 // type, like application/pdf. Note: We only register NaCl modules in the | 759 // type, like application/pdf. Note: We only register NaCl modules in the |
| 781 // browser process. | 760 // browser process. |
| 782 void RegisterNaClModule(const GURL& url, const std::string& mime_type); | 761 void RegisterNaClModule(const GURL& url, const std::string& mime_type); |
| 783 void UnregisterNaClModule(const GURL& url); | 762 void UnregisterNaClModule(const GURL& url); |
| 784 | 763 |
| 785 // Call UpdatePluginListWithNaClModules() after registering or unregistering | 764 // Call UpdatePluginListWithNaClModules() after registering or unregistering |
| 786 // a NaCl module to see those changes reflected in the PluginList. | 765 // a NaCl module to see those changes reflected in the PluginList. |
| 787 void UpdatePluginListWithNaClModules(); | 766 void UpdatePluginListWithNaClModules(); |
| 788 | 767 |
| 789 NaClModuleInfoList::iterator FindNaClModule(const GURL& url); | 768 NaClModuleInfoList::iterator FindNaClModule(const GURL& url); |
| 790 | 769 |
| 791 // Performs tasks requested to occur after |extension| loads. | |
| 792 void DoPostLoadTasks(const extensions::Extension* extension); | |
| 793 | |
| 794 // Launches the platform app associated with |extension_host|. | |
| 795 static void LaunchApplication(extensions::ExtensionHost* extension_host); | |
| 796 | |
| 797 // Dispatches a restart event to the platform app associated with | |
| 798 // |extension_host|. | |
| 799 static void RestartApplication(extensions::ExtensionHost* extension_host); | |
| 800 | |
| 801 // Helper to inspect an ExtensionHost after it has been loaded. | 770 // Helper to inspect an ExtensionHost after it has been loaded. |
| 802 void InspectExtensionHost(extensions::ExtensionHost* host); | 771 void InspectExtensionHost(extensions::ExtensionHost* host); |
| 803 | 772 |
| 804 // Helper to determine whether we should initially enable an installed | 773 // Helper to determine whether we should initially enable an installed |
| 805 // (or upgraded) extension. | 774 // (or upgraded) extension. |
| 806 bool ShouldEnableOnInstall(const extensions::Extension* extension); | 775 bool ShouldEnableOnInstall(const extensions::Extension* extension); |
| 807 | 776 |
| 808 // Helper to determine if an extension is idle, and it should be safe | 777 // Helper to determine if an extension is idle, and it should be safe |
| 809 // to update the extension. | 778 // to update the extension. |
| 810 bool IsExtensionIdle(const std::string& extension_id) const; | 779 bool IsExtensionIdle(const std::string& extension_id) const; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 UnloadedExtensionPathMap unloaded_extension_paths_; | 878 UnloadedExtensionPathMap unloaded_extension_paths_; |
| 910 | 879 |
| 911 // Store the ids of reloading extensions. | 880 // Store the ids of reloading extensions. |
| 912 std::set<std::string> reloading_extensions_; | 881 std::set<std::string> reloading_extensions_; |
| 913 | 882 |
| 914 // Map of inspector cookies that are detached, waiting for an extension to be | 883 // Map of inspector cookies that are detached, waiting for an extension to be |
| 915 // reloaded. | 884 // reloaded. |
| 916 typedef std::map<std::string, std::string> OrphanedDevTools; | 885 typedef std::map<std::string, std::string> OrphanedDevTools; |
| 917 OrphanedDevTools orphaned_dev_tools_; | 886 OrphanedDevTools orphaned_dev_tools_; |
| 918 | 887 |
| 919 // Maps extension ids to a bitmask that indicates which events should be | |
| 920 // dispatched to the extension when it is loaded. | |
| 921 std::map<std::string, int> on_load_events_; | |
| 922 | |
| 923 content::NotificationRegistrar registrar_; | 888 content::NotificationRegistrar registrar_; |
| 924 PrefChangeRegistrar pref_change_registrar_; | 889 PrefChangeRegistrar pref_change_registrar_; |
| 925 | 890 |
| 926 // Keeps track of loading and unloading component extensions. | 891 // Keeps track of loading and unloading component extensions. |
| 927 scoped_ptr<extensions::ComponentLoader> component_loader_; | 892 scoped_ptr<extensions::ComponentLoader> component_loader_; |
| 928 | 893 |
| 929 // Keeps track of menu items added by extensions. | 894 // Keeps track of menu items added by extensions. |
| 930 extensions::MenuManager menu_manager_; | 895 extensions::MenuManager menu_manager_; |
| 931 | 896 |
| 932 // Flag to make sure event routers are only initialized once. | 897 // Flag to make sure event routers are only initialized once. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 ObserverList<extensions::UpdateObserver, true> update_observers_; | 948 ObserverList<extensions::UpdateObserver, true> update_observers_; |
| 984 | 949 |
| 985 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 950 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 986 InstallAppsWithUnlimtedStorage); | 951 InstallAppsWithUnlimtedStorage); |
| 987 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 952 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 988 InstallAppsAndCheckStorageProtection); | 953 InstallAppsAndCheckStorageProtection); |
| 989 DISALLOW_COPY_AND_ASSIGN(ExtensionService); | 954 DISALLOW_COPY_AND_ASSIGN(ExtensionService); |
| 990 }; | 955 }; |
| 991 | 956 |
| 992 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ | 957 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
| OLD | NEW |