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