[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 7 | |
[email protected] | da50530a | 2009-06-15 17:43:01 | [diff] [blame] | 8 | #include <map> |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 9 | #include <set> |
[email protected] | b0beaa66 | 2009-02-26 00:04:15 | [diff] [blame] | 10 | #include <string> |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
[email protected] | a918f87 | 2010-06-01 14:30:51 | [diff] [blame] | 15 | #include "base/gtest_prod_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/ref_counted.h" |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 17 | #include "base/memory/weak_ptr.h" |
[email protected] | 1ab137b | 2013-03-21 03:33:18 | [diff] [blame] | 18 | #include "base/prefs/pref_change_registrar.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 19 | #include "base/strings/string16.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 20 | #include "chrome/browser/extensions/blacklist.h" |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 21 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 22 | #include "content/public/browser/notification_observer.h" |
| 23 | #include "content/public/browser/notification_registrar.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 24 | #include "extensions/browser/external_provider_interface.h" |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 25 | #include "extensions/browser/install_flag.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 26 | #include "extensions/browser/management_policy.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 27 | #include "extensions/browser/process_manager.h" |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 28 | #include "extensions/browser/uninstall_reason.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 29 | #include "extensions/common/extension.h" |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 30 | #include "extensions/common/extension_set.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 31 | #include "extensions/common/manifest.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 32 | #include "sync/api/string_ordinal.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 33 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 34 | class ExtensionSyncService; |
[email protected] | 69f1be8 | 2009-04-16 22:27:21 | [diff] [blame] | 35 | class GURL; |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 36 | class Profile; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 37 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 38 | namespace base { |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 39 | class CommandLine; |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 40 | class SequencedTaskRunner; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 41 | class Version; |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 42 | } |
| 43 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 44 | namespace content { |
| 45 | class DevToolsAgentHost; |
| 46 | } |
| 47 | |
[email protected] | 9c70e0d9 | 2012-07-16 08:39:44 | [diff] [blame] | 48 | namespace extensions { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 49 | class ComponentLoader; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 50 | class CrxInstaller; |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 51 | class ExtensionActionStorageManager; |
[email protected] | 02c967fe | 2014-08-12 14:48:43 | [diff] [blame] | 52 | class ExtensionDownloader; |
| 53 | class ExtensionDownloaderDelegate; |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 54 | class ExtensionErrorController; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 55 | class ExtensionRegistry; |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 56 | class ExtensionSystem; |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 57 | class ExtensionUpdater; |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 58 | class OneShotEvent; |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 59 | class ExternalInstallManager; |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 60 | class SharedModuleService; |
[email protected] | a9aa62b31 | 2013-11-29 05:35:06 | [diff] [blame] | 61 | class UpdateObserver; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 62 | } // namespace extensions |
[email protected] | 163ed19 | 2012-07-24 19:31:07 | [diff] [blame] | 63 | |
[email protected] | d1ca0ed1 | 2009-07-01 18:24:32 | [diff] [blame] | 64 | // This is an interface class to encapsulate the dependencies that |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 65 | // various classes have on ExtensionService. This allows easy mocking. |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 66 | class ExtensionServiceInterface |
| 67 | : public base::SupportsWeakPtr<ExtensionServiceInterface> { |
[email protected] | d1ca0ed1 | 2009-07-01 18:24:32 | [diff] [blame] | 68 | public: |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 69 | virtual ~ExtensionServiceInterface() {} |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 70 | |
| 71 | // DEPRECATED: Use ExtensionRegistry::enabled_extensions() instead. |
[email protected] | eb24538 | 2014-07-28 22:23:14 | [diff] [blame] | 72 | // |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 73 | // ExtensionRegistry also has the disabled, terminated and blacklisted sets. |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 74 | virtual const extensions::ExtensionSet* extensions() const = 0; |
[email protected] | ca97594 | 2014-01-07 12:06:47 | [diff] [blame] | 75 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 76 | // Gets the object managing the set of pending extensions. |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 77 | virtual extensions::PendingExtensionManager* pending_extension_manager() = 0; |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 78 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 79 | // Installs an update with the contents from |extension_path|. Returns true if |
| 80 | // the install can be started. Sets |out_crx_installer| to the installer if |
| 81 | // one was started. |
| 82 | // TODO(aa): This method can be removed. ExtensionUpdater could use |
| 83 | // CrxInstaller directly instead. |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 84 | virtual bool UpdateExtension( |
| 85 | const std::string& id, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 86 | const base::FilePath& path, |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 87 | bool file_ownership_passed, |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 88 | extensions::CrxInstaller** out_crx_installer) = 0; |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 89 | |
[email protected] | eb24538 | 2014-07-28 22:23:14 | [diff] [blame] | 90 | // DEPRECATED. Use ExtensionRegistry instead. |
| 91 | // |
| 92 | // Looks up an extension by its ID. |
| 93 | // |
| 94 | // If |include_disabled| is false then this will only include enabled |
| 95 | // extensions. Use instead: |
| 96 | // |
| 97 | // ExtensionRegistry::enabled_extensions().GetByID(id). |
| 98 | // |
| 99 | // If |include_disabled| is true then this will also include disabled and |
| 100 | // blacklisted extensions (not terminated extensions). Use instead: |
| 101 | // |
| 102 | // ExtensionRegistry::GetExtensionById( |
| 103 | // id, ExtensionRegistry::ENABLED | |
| 104 | // ExtensionRegistry::DISABLED | |
| 105 | // ExtensionRegistry::BLACKLISTED) |
| 106 | // |
| 107 | // Or don't, because it's probably not something you ever need to know. |
[email protected] | f574c40 | 2012-12-04 23:20:31 | [diff] [blame] | 108 | virtual const extensions::Extension* GetExtensionById( |
| 109 | const std::string& id, |
| 110 | bool include_disabled) const = 0; |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 111 | |
[email protected] | eb24538 | 2014-07-28 22:23:14 | [diff] [blame] | 112 | // DEPRECATED: Use ExtensionRegistry instead. |
| 113 | // |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 114 | // Looks up an extension by ID, regardless of whether it's enabled, |
[email protected] | eb24538 | 2014-07-28 22:23:14 | [diff] [blame] | 115 | // disabled, blacklisted, or terminated. Use instead: |
| 116 | // |
| 117 | // ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::EVERYTHING). |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 118 | virtual const extensions::Extension* GetInstalledExtension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 119 | const std::string& id) const = 0; |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 120 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 121 | // Returns an update for an extension with the specified id, if installation |
| 122 | // of that update was previously delayed because the extension was in use. If |
| 123 | // no updates are pending for the extension returns NULL. |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 124 | virtual const extensions::Extension* GetPendingExtensionUpdate( |
| 125 | const std::string& extension_id) const = 0; |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 126 | |
| 127 | // Finishes installation of an update for an extension with the specified id, |
| 128 | // when installation of that extension was previously delayed because the |
| 129 | // extension was in use. |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 130 | virtual void FinishDelayedInstallation(const std::string& extension_id) = 0; |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 131 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 132 | // Returns true if the extension with the given |extension_id| is enabled. |
| 133 | // This will return a valid answer even if the extension is not loaded yet. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 134 | virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0; |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 135 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 136 | // Go through each extension and unload those that are not allowed to run by |
| 137 | // management policy providers (ie. network admin and Google-managed |
| 138 | // blacklist). |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 139 | virtual void CheckManagementPolicy() = 0; |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 140 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 141 | // Safe to call multiple times in a row. |
| 142 | // |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 143 | // TODO(akalin): Remove this method (and others) once we refactor |
| 144 | // themes sync to not use it directly. |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 145 | virtual void CheckForUpdatesSoon() = 0; |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 146 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 147 | // Adds |extension| to this ExtensionService and notifies observers that the |
| 148 | // extensions have been loaded. |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 149 | virtual void AddExtension(const extensions::Extension* extension) = 0; |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 150 | |
| 151 | // Check if we have preferences for the component extension and, if not or if |
| 152 | // the stored version differs, install the extension (without requirements |
| 153 | // checking) before calling AddExtension. |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 154 | virtual void AddComponentExtension( |
| 155 | const extensions::Extension* extension) = 0; |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 156 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 157 | // Unload the specified extension. |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 158 | virtual void UnloadExtension( |
| 159 | const std::string& extension_id, |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 160 | extensions::UnloadedExtensionInfo::Reason reason) = 0; |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 161 | |
| 162 | // Remove the specified component extension. |
[email protected] | 8b1ec20 | 2013-09-05 02:09:50 | [diff] [blame] | 163 | virtual void RemoveComponentExtension(const std::string& extension_id) = 0; |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 164 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 165 | // Whether the extension service is ready. |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 166 | virtual bool is_ready() = 0; |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 167 | |
| 168 | // Returns task runner for crx installation file I/O operations. |
| 169 | virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0; |
[email protected] | d1ca0ed1 | 2009-07-01 18:24:32 | [diff] [blame] | 170 | }; |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 171 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 172 | // Manages installed and running Chromium extensions. An instance is shared |
| 173 | // between normal and incognito profiles. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 174 | class ExtensionService |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 175 | : public ExtensionServiceInterface, |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 176 | public extensions::ExternalProviderInterface::VisitorInterface, |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 177 | public content::NotificationObserver, |
[email protected] | f83bd43 | 2014-05-10 20:44:40 | [diff] [blame] | 178 | public extensions::Blacklist::Observer { |
[email protected] | 4f313d5 | 2009-05-21 00:42:29 | [diff] [blame] | 179 | public: |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 180 | // Attempts to uninstall an extension from a given ExtensionService. Returns |
| 181 | // true iff the target extension exists. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 182 | static bool UninstallExtensionHelper(ExtensionService* extensions_service, |
[email protected] | cc2f55c | 2014-07-08 02:19:04 | [diff] [blame] | 183 | const std::string& extension_id, |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 184 | extensions::UninstallReason reason); |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 185 | |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 186 | // Constructor stores pointers to |profile| and |extension_prefs| but |
| 187 | // ownership remains at caller. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 188 | ExtensionService(Profile* profile, |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 189 | const base::CommandLine* command_line, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 190 | const base::FilePath& install_directory, |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 191 | extensions::ExtensionPrefs* extension_prefs, |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 192 | extensions::Blacklist* blacklist, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 193 | bool autoupdate_enabled, |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 194 | bool extensions_enabled, |
| 195 | extensions::OneShotEvent* ready); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 196 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 197 | virtual ~ExtensionService(); |
| 198 | |
[email protected] | eb24538 | 2014-07-28 22:23:14 | [diff] [blame] | 199 | // ExtensionServiceInterface implementation. |
| 200 | // |
| 201 | // NOTE: Many of these methods are DEPRECATED. See the interface for details. |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 202 | virtual const extensions::ExtensionSet* extensions() const OVERRIDE; |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 203 | virtual extensions::PendingExtensionManager* |
| 204 | pending_extension_manager() OVERRIDE; |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 205 | virtual const extensions::Extension* GetExtensionById( |
| 206 | const std::string& id, bool include_disabled) const OVERRIDE; |
| 207 | virtual const extensions::Extension* GetInstalledExtension( |
| 208 | const std::string& id) const OVERRIDE; |
| 209 | virtual bool UpdateExtension( |
| 210 | const std::string& id, |
| 211 | const base::FilePath& extension_path, |
| 212 | bool file_ownership_passed, |
| 213 | extensions::CrxInstaller** out_crx_installer) OVERRIDE; |
| 214 | virtual bool IsExtensionEnabled( |
| 215 | const std::string& extension_id) const OVERRIDE; |
| 216 | virtual void UnloadExtension( |
| 217 | const std::string& extension_id, |
| 218 | extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 219 | virtual void RemoveComponentExtension(const std::string& extension_id) |
| 220 | OVERRIDE; |
| 221 | virtual void AddExtension(const extensions::Extension* extension) OVERRIDE; |
| 222 | virtual void AddComponentExtension(const extensions::Extension* extension) |
| 223 | OVERRIDE; |
| 224 | virtual const extensions::Extension* GetPendingExtensionUpdate( |
| 225 | const std::string& extension_id) const OVERRIDE; |
| 226 | virtual void FinishDelayedInstallation( |
| 227 | const std::string& extension_id) OVERRIDE; |
| 228 | virtual void CheckManagementPolicy() OVERRIDE; |
| 229 | virtual void CheckForUpdatesSoon() OVERRIDE; |
| 230 | virtual bool is_ready() OVERRIDE; |
| 231 | virtual base::SequencedTaskRunner* GetFileTaskRunner() OVERRIDE; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 232 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 233 | // ExternalProvider::Visitor implementation. |
| 234 | // Exposed for testing. |
| 235 | virtual bool OnExternalExtensionFileFound( |
| 236 | const std::string& id, |
| 237 | const base::Version* version, |
| 238 | const base::FilePath& path, |
| 239 | extensions::Manifest::Location location, |
| 240 | int creation_flags, |
| 241 | bool mark_acknowledged) OVERRIDE; |
| 242 | virtual bool OnExternalExtensionUpdateUrlFound( |
| 243 | const std::string& id, |
| 244 | const std::string& install_parameter, |
| 245 | const GURL& update_url, |
| 246 | extensions::Manifest::Location location, |
| 247 | int creation_flags, |
| 248 | bool mark_acknowledged) OVERRIDE; |
| 249 | virtual void OnExternalProviderReady( |
| 250 | const extensions::ExternalProviderInterface* provider) OVERRIDE; |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 251 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 252 | // Initialize and start all installed extensions. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 253 | void Init(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 254 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 255 | // Called when the associated Profile is going to be destroyed. |
| 256 | void Shutdown(); |
| 257 | |
[email protected] | 2380c6b | 2013-01-09 02:33:13 | [diff] [blame] | 258 | // Reloads the specified extension, sending the onLaunched() event to it if it |
| 259 | // currently has any window showing. |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 260 | // Allows noisy failures. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 261 | void ReloadExtension(const std::string& extension_id); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 262 | |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 263 | // Suppresses noisy failures. |
| 264 | void ReloadExtensionWithQuietFailure(const std::string& extension_id); |
| 265 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 266 | // Uninstalls the specified extension. Callers should only call this method |
[email protected] | cc2f55c | 2014-07-08 02:19:04 | [diff] [blame] | 267 | // with extensions that exist. |reason| lets the caller specify why the |
| 268 | // extension is uninstalled. |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 269 | // |
| 270 | // If the return value is true, |deletion_done_callback| is invoked when data |
| 271 | // deletion is done or at least is scheduled. |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 272 | virtual bool UninstallExtension(const std::string& extension_id, |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 273 | extensions::UninstallReason reason, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 274 | const base::Closure& deletion_done_callback, |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 275 | base::string16* error); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 276 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 277 | // Enables the extension. If the extension is already enabled, does |
| 278 | // nothing. |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 279 | virtual void EnableExtension(const std::string& extension_id); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 280 | |
| 281 | // Disables the extension. If the extension is already disabled, or |
| 282 | // cannot be disabled, does nothing. |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 283 | virtual void DisableExtension( |
| 284 | const std::string& extension_id, |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 285 | extensions::Extension::DisableReason disable_reason); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 286 | |
[email protected] | 3082fe3 | 2013-08-06 11:12:38 | [diff] [blame] | 287 | // Disable non-default and non-managed extensions with ids not in |
| 288 | // |except_ids|. Default extensions are those from the Web Store with |
| 289 | // |was_installed_by_default| flag. |
[email protected] | 1abf05e | 2013-07-09 17:04:36 | [diff] [blame] | 290 | void DisableUserExtensions(const std::vector<std::string>& except_ids); |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 291 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 292 | // Updates the |extension|'s granted permissions lists to include all |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 293 | // permissions in the |extension|'s manifest and re-enables the |
| 294 | // extension. |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 295 | void GrantPermissionsAndEnableExtension( |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 296 | const extensions::Extension* extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 297 | |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 298 | // Updates the |extension|'s granted permissions lists to include all |
| 299 | // permissions in the |extensions|'s manifest. |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 300 | void GrantPermissions(const extensions::Extension* extension); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 301 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 302 | // Check for updates (or potentially new extensions from external providers) |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 303 | void CheckForExternalUpdates(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 304 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 305 | // Called when the initial extensions load has completed. |
| 306 | virtual void OnLoadedInstalledExtensions(); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 307 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 308 | // Informs the service that an extension's files are in place for loading. |
| 309 | // |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 310 | // |extension| the extension |
| 311 | // |page_ordinal| the location of the extension in the app launcher |
| 312 | // |install_flags| a bitmask of extensions::InstallFlags |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 313 | void OnExtensionInstalled(const extensions::Extension* extension, |
| 314 | const syncer::StringOrdinal& page_ordinal, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 315 | int install_flags); |
| 316 | void OnExtensionInstalled(const extensions::Extension* extension, |
| 317 | const syncer::StringOrdinal& page_ordinal) { |
| 318 | OnExtensionInstalled(extension, |
| 319 | page_ordinal, |
| 320 | static_cast<int>(extensions::kInstallFlagNone)); |
| 321 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 322 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 323 | // Checks for delayed installation for all pending installs. |
| 324 | void MaybeFinishDelayedInstallations(); |
| 325 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 326 | // Promotes an ephemeral app to a regular installed app. Ephemeral apps |
| 327 | // are already installed in extension system (albiet transiently) and only |
| 328 | // need to be exposed in the UI. Set |is_from_sync| to true if the |
| 329 | // install was initiated via sync. |
| 330 | void PromoteEphemeralApp( |
| 331 | const extensions::Extension* extension, bool is_from_sync); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 332 | |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 333 | // ExtensionHost of background page calls this method right after its render |
| 334 | // view has been created. |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 335 | void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 336 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 337 | // Changes sequenced task runner for crx installation tasks to |task_runner|. |
dcheng | 605ef8d | 2014-08-28 18:29:44 | [diff] [blame^] | 338 | void SetFileTaskRunnerForTesting( |
| 339 | const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 340 | |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 341 | // Postpone installations so that we don't have to worry about race |
| 342 | // conditions. |
| 343 | void OnGarbageCollectIsolatedStorageStart(); |
| 344 | |
| 345 | // Restart any extension installs which were delayed for isolated storage |
| 346 | // garbage collection. |
| 347 | void OnGarbageCollectIsolatedStorageFinished(); |
| 348 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 349 | // Record a histogram using the PermissionMessage enum values for each |
| 350 | // permission in |e|. |
| 351 | // NOTE: If this is ever called with high frequency, the implementation may |
| 352 | // need to be made more efficient. |
| 353 | static void RecordPermissionMessagesHistogram( |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 354 | const extensions::Extension* extension, const char* histogram); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 355 | |
[email protected] | e9d7496e | 2014-04-18 01:25:46 | [diff] [blame] | 356 | // Unloads the given extension and mark the extension as terminated. This |
| 357 | // doesn't notify the user that the extension was terminated, if such a |
| 358 | // notification is desired the calling code is responsible for doing that. |
| 359 | void TerminateExtension(const std::string& extension_id); |
| 360 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 361 | // Adds/Removes update observers. |
| 362 | void AddUpdateObserver(extensions::UpdateObserver* observer); |
| 363 | void RemoveUpdateObserver(extensions::UpdateObserver* observer); |
[email protected] | a51c9e9 | 2012-12-09 09:19:20 | [diff] [blame] | 364 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 365 | ////////////////////////////////////////////////////////////////////////////// |
| 366 | // Simple Accessors |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 367 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 368 | // Returns a WeakPtr to the ExtensionService. |
[email protected] | 77e4dc088 | 2012-06-20 18:53:50 | [diff] [blame] | 369 | base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); } |
| 370 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 371 | // Returns profile_ as a BrowserContext. |
| 372 | content::BrowserContext* GetBrowserContext() const; |
| 373 | |
| 374 | bool extensions_enabled() const { return extensions_enabled_; } |
| 375 | void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; } |
| 376 | |
| 377 | const base::FilePath& install_directory() const { return install_directory_; } |
| 378 | |
| 379 | const extensions::ExtensionSet* delayed_installs() const { |
| 380 | return &delayed_installs_; |
| 381 | } |
| 382 | |
| 383 | bool show_extensions_prompts() const { return show_extensions_prompts_; } |
| 384 | void set_show_extensions_prompts(bool show_extensions_prompts) { |
| 385 | show_extensions_prompts_ = show_extensions_prompts; |
| 386 | } |
| 387 | |
| 388 | Profile* profile() { return profile_; } |
| 389 | |
| 390 | void set_extension_sync_service( |
| 391 | ExtensionSyncService* extension_sync_service) { |
| 392 | extension_sync_service_ = extension_sync_service; |
| 393 | } |
| 394 | |
| 395 | // Note that this may return NULL if autoupdate is not turned on. |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 396 | extensions::ExtensionUpdater* updater() { return updater_.get(); } |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 397 | |
| 398 | extensions::ComponentLoader* component_loader() { |
| 399 | return component_loader_.get(); |
| 400 | } |
| 401 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 402 | bool browser_terminating() const { return browser_terminating_; } |
| 403 | |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 404 | extensions::SharedModuleService* shared_module_service() { |
| 405 | return shared_module_service_.get(); |
| 406 | } |
| 407 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 408 | extensions::ExternalInstallManager* external_install_manager() { |
| 409 | return external_install_manager_.get(); |
| 410 | } |
| 411 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 412 | ////////////////////////////////////////////////////////////////////////////// |
| 413 | // For Testing |
| 414 | |
| 415 | // Unload all extensions. Does not send notifications. |
| 416 | void UnloadAllExtensionsForTest(); |
| 417 | |
| 418 | // Reloads all extensions. Does not notify that extensions are ready. |
| 419 | void ReloadExtensionsForTest(); |
| 420 | |
| 421 | // Clear all ExternalProviders. |
| 422 | void ClearProvidersForTesting(); |
| 423 | |
| 424 | // Adds an ExternalProviderInterface for the service to use during testing. |
| 425 | // Takes ownership of |test_provider|. |
| 426 | void AddProviderForTesting( |
| 427 | extensions::ExternalProviderInterface* test_provider); |
| 428 | |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 429 | // Simulate an extension being blacklisted for tests. |
| 430 | void BlacklistExtensionForTest(const std::string& extension_id); |
| 431 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 432 | #if defined(UNIT_TEST) |
| 433 | void TrackTerminatedExtensionForTest(const extensions::Extension* extension) { |
| 434 | TrackTerminatedExtension(extension); |
| 435 | } |
| 436 | |
| 437 | void FinishInstallationForTest(const extensions::Extension* extension) { |
| 438 | FinishInstallation(extension, false /* not ephemeral */); |
| 439 | } |
| 440 | #endif |
| 441 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 442 | void set_browser_terminating_for_test(bool value) { |
| 443 | browser_terminating_ = value; |
| 444 | } |
| 445 | |
[email protected] | fc332ae | 2012-11-14 20:17:33 | [diff] [blame] | 446 | // By default ExtensionService will wait with installing an updated extension |
| 447 | // until the extension is idle. Tests might not like this behavior, so you can |
| 448 | // disable it with this method. |
| 449 | void set_install_updates_when_idle_for_test(bool value) { |
| 450 | install_updates_when_idle_ = value; |
| 451 | } |
| 452 | |
[email protected] | 4e9b59d | 2013-12-18 06:47:14 | [diff] [blame] | 453 | // Set a callback to be called when all external providers are ready and their |
| 454 | // extensions have been installed. |
| 455 | void set_external_updates_finished_callback_for_test( |
| 456 | const base::Closure& callback) { |
| 457 | external_updates_finished_callback_ = callback; |
| 458 | } |
| 459 | |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 460 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 461 | private: |
[email protected] | 02c967fe | 2014-08-12 14:48:43 | [diff] [blame] | 462 | // Creates an ExtensionDownloader for use by the updater. |
| 463 | scoped_ptr<extensions::ExtensionDownloader> CreateExtensionDownloader( |
| 464 | extensions::ExtensionDownloaderDelegate* delegate); |
| 465 | |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 466 | // Reloads the specified extension, sending the onLaunched() event to it if it |
| 467 | // currently has any window showing. |be_noisy| determines whether noisy |
| 468 | // failures are allowed for unpacked extension installs. |
| 469 | void ReloadExtensionImpl(const std::string& extension_id, bool be_noisy); |
| 470 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 471 | // content::NotificationObserver implementation: |
| 472 | virtual void Observe(int type, |
| 473 | const content::NotificationSource& source, |
| 474 | const content::NotificationDetails& details) OVERRIDE; |
| 475 | |
| 476 | // extensions::Blacklist::Observer implementation. |
| 477 | virtual void OnBlacklistUpdated() OVERRIDE; |
| 478 | |
| 479 | // Similar to FinishInstallation, but first checks if there still is an update |
| 480 | // pending for the extension, and makes sure the extension is still idle. |
| 481 | void MaybeFinishDelayedInstallation(const std::string& extension_id); |
| 482 | |
| 483 | // For the extension in |version_path| with |id|, check to see if it's an |
| 484 | // externally managed extension. If so, uninstall it. |
| 485 | void CheckExternalUninstall(const std::string& id); |
| 486 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 487 | // Populates greylist_. |
| 488 | void LoadGreylistFromPrefs(); |
| 489 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 490 | // Signals *ready_ and sends a notification to the listeners. |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 491 | void SetReadyAndNotifyListeners(); |
| 492 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 493 | // Returns true if all the external extension providers are ready. |
| 494 | bool AreAllExternalProvidersReady() const; |
| 495 | |
| 496 | // Called once all external providers are ready. Checks for unclaimed |
| 497 | // external extensions. |
| 498 | void OnAllExternalProvidersReady(); |
| 499 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 500 | // Return true if the sync type of |extension| matches |type|. |
[email protected] | 90bb38d | 2012-11-14 18:36:03 | [diff] [blame] | 501 | void OnExtensionInstallPrefChanged(); |
| 502 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 503 | // Adds the given extension to the list of terminated extensions if |
| 504 | // it is not already there and unloads it. |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 505 | void TrackTerminatedExtension(const extensions::Extension* extension); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 506 | |
| 507 | // Removes the extension with the given id from the list of |
| 508 | // terminated extensions if it is there. |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 509 | void UntrackTerminatedExtension(const std::string& id); |
| 510 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 511 | // Update preferences for a new or updated extension; notify observers that |
| 512 | // the extension is installed, e.g., to update event handlers on background |
| 513 | // pages; and perform other extension install tasks before calling |
| 514 | // AddExtension. |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 515 | // |install_flags| is a bitmask of extensions::InstallFlags. |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 516 | void AddNewOrUpdatedExtension(const extensions::Extension* extension, |
| 517 | extensions::Extension::State initial_state, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 518 | int install_flags, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 519 | const syncer::StringOrdinal& page_ordinal, |
| 520 | const std::string& install_parameter); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 521 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 522 | // Handles sending notification that |extension| was loaded. |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 523 | void NotifyExtensionLoaded(const extensions::Extension* extension); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 524 | |
| 525 | // Handles sending notification that |extension| was unloaded. |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 526 | void NotifyExtensionUnloaded( |
| 527 | const extensions::Extension* extension, |
| 528 | extensions::UnloadedExtensionInfo::Reason reason); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 529 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 530 | // Common helper to finish installing the given extension. |was_ephemeral| |
| 531 | // should be true if the extension was previously installed and ephemeral. |
| 532 | void FinishInstallation(const extensions::Extension* extension, |
| 533 | bool was_ephemeral); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 534 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 535 | // Disables the extension if the privilege level has increased |
| 536 | // (e.g., due to an upgrade). |
| 537 | void CheckPermissionsIncrease(const extensions::Extension* extension, |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 538 | bool is_extension_installed); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 539 | |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 540 | // Helper that updates the active extension list used for crash reporting. |
| 541 | void UpdateActiveExtensionsInCrashReporter(); |
| 542 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 543 | // Helper to determine whether we should initially enable an installed |
| 544 | // (or upgraded) extension. |
| 545 | bool ShouldEnableOnInstall(const extensions::Extension* extension); |
| 546 | |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 547 | // Helper to determine if updating an extensions should proceed immediately, |
| 548 | // or if we should delay the update until further notice. |
| 549 | bool ShouldDelayExtensionUpdate(const std::string& extension_id, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 550 | bool install_immediately) const; |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 551 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 552 | // Manages the blacklisted extensions, intended as callback from |
| 553 | // Blacklist::GetBlacklistedIDs. |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 554 | void ManageBlacklist( |
| 555 | const extensions::Blacklist::BlacklistStateMap& blacklisted_ids); |
| 556 | |
| 557 | // Add extensions in |blocked| to blacklisted_extensions, remove extensions |
| 558 | // that are neither in |blocked|, nor in |unchanged|. |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 559 | void UpdateBlockedExtensions(const extensions::ExtensionIdSet& blocked, |
| 560 | const extensions::ExtensionIdSet& unchanged); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 561 | |
| 562 | void UpdateGreylistedExtensions( |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 563 | const extensions::ExtensionIdSet& greylist, |
| 564 | const extensions::ExtensionIdSet& unchanged, |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 565 | const extensions::Blacklist::BlacklistStateMap& state_map); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 566 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 567 | // Used only by test code. |
| 568 | void UnloadAllExtensionsInternal(); |
| 569 | |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 570 | // Disable apps & extensions now to stop them from running after a profile |
| 571 | // has been conceptually deleted. Don't wait for full browser shutdown and |
| 572 | // the actual profile objects to be destroyed. |
| 573 | void OnProfileDestructionStarted(); |
| 574 | |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 575 | // Called on file task runner thread to uninstall extension. |
| 576 | static void UninstallExtensionOnFileThread( |
| 577 | const std::string& id, |
| 578 | Profile* profile, |
| 579 | const base::FilePath& install_dir, |
| 580 | const base::FilePath& extension_path); |
| 581 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 582 | // The normal profile associated with this ExtensionService. |
[email protected] | 6ef635e4 | 2009-07-26 06:16:12 | [diff] [blame] | 583 | Profile* profile_; |
| 584 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 585 | // The ExtensionSystem for the profile above. |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 586 | extensions::ExtensionSystem* system_; |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 587 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 588 | // Preferences for the owning profile. |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 589 | extensions::ExtensionPrefs* extension_prefs_; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 590 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 591 | // Blacklist for the owning profile. |
| 592 | extensions::Blacklist* blacklist_; |
| 593 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 594 | // The ExtensionSyncService that is used by this ExtensionService. |
| 595 | ExtensionSyncService* extension_sync_service_; |
| 596 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 597 | // Sets of enabled/disabled/terminated/blacklisted extensions. Not owned. |
| 598 | extensions::ExtensionRegistry* registry_; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 599 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 600 | // Set of greylisted extensions. These extensions are disabled if they are |
| 601 | // already installed in Chromium at the time when they are added to |
| 602 | // the greylist. Unlike blacklisted extensions, greylisted ones are visible |
| 603 | // to the user and if user re-enables such an extension, they remain enabled. |
| 604 | // |
| 605 | // These extensions should appear in registry_. |
| 606 | extensions::ExtensionSet greylist_; |
| 607 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 608 | // The list of extension installs delayed for various reasons. The reason |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 609 | // for delayed install is stored in ExtensionPrefs. These are not part of |
| 610 | // ExtensionRegistry because they are not yet installed. |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 611 | extensions::ExtensionSet delayed_installs_; |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 612 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 613 | // Hold the set of pending extensions. |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 614 | extensions::PendingExtensionManager pending_extension_manager_; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 615 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 616 | // The full path to the directory where extensions are installed. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 617 | base::FilePath install_directory_; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 618 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 619 | // Whether or not extensions are enabled. |
| 620 | bool extensions_enabled_; |
| 621 | |
[email protected] | 0e34d789 | 2009-06-05 19:17:40 | [diff] [blame] | 622 | // Whether to notify users when they attempt to install an extension. |
| 623 | bool show_extensions_prompts_; |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 624 | |
[email protected] | fc332ae | 2012-11-14 20:17:33 | [diff] [blame] | 625 | // Whether to delay installing of extension updates until the extension is |
| 626 | // idle. |
| 627 | bool install_updates_when_idle_; |
| 628 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 629 | // Signaled when all extensions are loaded. |
| 630 | extensions::OneShotEvent* const ready_; |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 631 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 632 | // Our extension updater, if updates are turned on. |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 633 | scoped_ptr<extensions::ExtensionUpdater> updater_; |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 634 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 635 | // Map unloaded extensions' ids to their paths. When a temporarily loaded |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 636 | // extension is unloaded, we lose the information about it and don't have |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 637 | // any in the extension preferences file. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 638 | typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap; |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 639 | UnloadedExtensionPathMap unloaded_extension_paths_; |
| 640 | |
[email protected] | 04ea1bb | 2013-07-10 09:26:09 | [diff] [blame] | 641 | // Map of DevToolsAgentHost instances that are detached, |
| 642 | // waiting for an extension to be reloaded. |
| 643 | typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> > |
| 644 | OrphanedDevTools; |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 645 | OrphanedDevTools orphaned_dev_tools_; |
| 646 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 647 | content::NotificationRegistrar registrar_; |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 648 | PrefChangeRegistrar pref_change_registrar_; |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 649 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 650 | // Keeps track of loading and unloading component extensions. |
| 651 | scoped_ptr<extensions::ComponentLoader> component_loader_; |
| 652 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 653 | // A collection of external extension providers. Each provider reads |
| 654 | // a source of external extension information. Examples include the |
| 655 | // windows registry and external_extensions.json. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 656 | extensions::ProviderCollection external_extension_providers_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 657 | |
| 658 | // Set to true by OnExternalExtensionUpdateUrlFound() when an external |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 659 | // extension URL is found, and by CheckForUpdatesSoon() when an update check |
| 660 | // has to wait for the external providers. Used in |
| 661 | // OnAllExternalProvidersReady() to determine if an update check is needed to |
| 662 | // install pending extensions. |
| 663 | bool update_once_all_providers_are_ready_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 664 | |
[email protected] | 4e9b59d | 2013-12-18 06:47:14 | [diff] [blame] | 665 | // A callback to be called when all external providers are ready and their |
| 666 | // extensions have been installed. Normally this is a null callback, but |
| 667 | // is used in external provider related tests. |
| 668 | base::Closure external_updates_finished_callback_; |
| 669 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 670 | // Set when the browser is terminating. Prevents us from installing or |
| 671 | // updating additional extensions and allows in-progress installations to |
| 672 | // decide to abort. |
| 673 | bool browser_terminating_; |
| 674 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 675 | // Set to true to delay all new extension installations. Acts as a lock to |
| 676 | // allow background processing of garbage collection of on-disk state without |
| 677 | // needing to worry about race conditions caused by extension installation and |
| 678 | // reinstallation. |
| 679 | bool installs_delayed_for_gc_; |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 680 | |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 681 | // Set to true if this is the first time this ExtensionService has run. |
| 682 | // Used for specially handling external extensions that are installed the |
| 683 | // first time. |
| 684 | bool is_first_run_; |
| 685 | |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 686 | // Store the ids of reloading extensions. We use this to re-enable extensions |
| 687 | // which were disabled for a reload. |
| 688 | std::set<std::string> reloading_extensions_; |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 689 | |
[email protected] | 3964e57 | 2014-02-13 21:57:41 | [diff] [blame] | 690 | // A set of the extension ids currently being terminated. We use this to |
| 691 | // avoid trying to unload the same extension twice. |
| 692 | std::set<std::string> extensions_being_terminated_; |
| 693 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 694 | // The controller for the UI that alerts the user about any blacklisted |
| 695 | // extensions. |
| 696 | scoped_ptr<extensions::ExtensionErrorController> error_controller_; |
| 697 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 698 | // The manager for extensions that were externally installed that is |
| 699 | // responsible for prompting the user about suspicious extensions. |
| 700 | scoped_ptr<extensions::ExternalInstallManager> external_install_manager_; |
| 701 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 702 | // Sequenced task runner for extension related file operations. |
| 703 | scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 704 | |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 705 | scoped_ptr<extensions::ExtensionActionStorageManager> |
| 706 | extension_action_storage_manager_; |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 707 | scoped_ptr<extensions::ManagementPolicy::Provider> |
| 708 | shared_module_policy_provider_; |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 709 | |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 710 | // The SharedModuleService used to check for import dependencies. |
| 711 | scoped_ptr<extensions::SharedModuleService> shared_module_service_; |
| 712 | |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 713 | ObserverList<extensions::UpdateObserver, true> update_observers_; |
[email protected] | efdb7f1a | 2014-03-28 20:43:38 | [diff] [blame] | 714 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 715 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 716 | DestroyingProfileClearsExtensions); |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 717 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs); |
| 718 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 719 | BlacklistedExtensionWillNotInstall); |
| 720 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 721 | UnloadBlacklistedExtensionPolicy); |
| 722 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 723 | WillNotLoadBlacklistedExtensionsFromDirectory); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 724 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlacklistedExtension); |
| 725 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlacklistedInPrefsFromStartup); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 726 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 727 | GreylistedExtensionDisabled); |
| 728 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 729 | GreylistDontEnableManuallyDisabled); |
| 730 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 731 | GreylistUnknownDontChange); |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 732 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 733 | DISALLOW_COPY_AND_ASSIGN(ExtensionService); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 734 | }; |
| 735 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 736 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_ |