blob: 4cd10fe5322336abb2178873aec97870d72323fb [file] [log] [blame]
[email protected]c333e792012-01-06 16:57:391// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6014d672008-12-05 00:38:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]eaa7dd182010-12-14 11:09:005#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_
[email protected]6014d672008-12-05 00:38:257
[email protected]da50530a2009-06-15 17:43:018#include <map>
[email protected]31bb5ee62012-09-12 22:58:409#include <set>
[email protected]b0beaa662009-02-26 00:04:1510#include <string>
[email protected]6014d672008-12-05 00:38:2511#include <vector>
12
[email protected]e0785902011-05-19 23:34:1713#include "base/compiler_specific.h"
[email protected]57999812013-02-24 05:40:5214#include "base/files/file_path.h"
[email protected]a918f872010-06-01 14:30:5115#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/ref_counted.h"
[email protected]14908b72011-04-20 06:54:3617#include "base/memory/weak_ptr.h"
[email protected]00e7bef2013-06-10 20:35:1718#include "base/strings/string16.h"
[email protected]fdd679b2012-11-15 20:49:3919#include "chrome/browser/extensions/blacklist.h"
binjin1569c9b2014-09-05 13:33:1820#include "chrome/browser/extensions/extension_management.h"
[email protected]f3d3b382014-03-14 21:19:2821#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]6c2381d2011-10-19 02:52:5322#include "content/public/browser/notification_observer.h"
23#include "content/public/browser/notification_registrar.h"
ginkage553af3202015-02-04 12:39:0924#include "extensions/browser/crx_file_info.h"
[email protected]301116c62013-11-26 10:37:4525#include "extensions/browser/external_provider_interface.h"
[email protected]4a1d9c0d2014-06-13 12:50:1126#include "extensions/browser/install_flag.h"
[email protected]301116c62013-11-26 10:37:4527#include "extensions/browser/management_policy.h"
[email protected]98b6d942013-11-10 00:34:0728#include "extensions/browser/process_manager.h"
[email protected]e43c61f2014-07-20 21:46:3429#include "extensions/browser/uninstall_reason.h"
[email protected]e4452d32013-11-15 23:07:4130#include "extensions/common/extension.h"
[email protected]289c44b2013-12-17 03:26:5731#include "extensions/common/extension_set.h"
[email protected]d42c11152013-08-22 19:36:3232#include "extensions/common/manifest.h"
[email protected]dccba4f82014-05-29 00:52:5633#include "sync/api/string_ordinal.h"
[email protected]6014d672008-12-05 00:38:2534
thestig44b9ce22014-10-17 03:19:2835#if !defined(ENABLE_EXTENSIONS)
36#error "Extensions must be enabled"
37#endif
38
[email protected]69f1be82009-04-16 22:27:2139class GURL;
mukai87a8d402014-09-15 20:15:0940class HostContentSettingsMap;
[email protected]81e63782009-02-27 19:35:0941class Profile;
[email protected]aa142702010-03-26 01:26:3342
[email protected]7f8f24f2012-11-15 19:40:1443namespace base {
[email protected]2f3b1cc2014-03-17 23:07:1544class CommandLine;
[email protected]7f8f24f2012-11-15 19:40:1445class SequencedTaskRunner;
[email protected]1f04ef42013-04-22 07:35:5046class Version;
[email protected]7f8f24f2012-11-15 19:40:1447}
48
[email protected]dccba4f82014-05-29 00:52:5649namespace content {
50class DevToolsAgentHost;
51}
52
[email protected]9c70e0d92012-07-16 08:39:4453namespace extensions {
ryanackley48bedbd2015-01-27 23:12:1454class AppDataMigrator;
[email protected]d8c8f25f2011-11-02 18:18:0155class ComponentLoader;
[email protected]bf3d9df2012-07-24 23:20:2756class CrxInstaller;
[email protected]c77f2352012-08-08 22:07:5857class ExtensionActionStorageManager;
[email protected]02c967fe2014-08-12 14:48:4358class ExtensionDownloader;
59class ExtensionDownloaderDelegate;
[email protected]373daf972014-04-10 01:50:4460class ExtensionErrorController;
[email protected]bb1bc9b32013-12-21 03:09:1461class ExtensionRegistry;
[email protected]bd306722012-07-11 20:43:5962class ExtensionSystem;
[email protected]42a08162012-03-16 18:09:1163class ExtensionUpdater;
[email protected]2894a512014-06-26 19:03:5664class ExternalInstallManager;
rdevlin.croninf5863da2015-09-10 19:21:4565class OneShotEvent;
[email protected]90878c52014-04-04 18:21:0266class SharedModuleService;
[email protected]a9aa62b312013-11-29 05:35:0667class UpdateObserver;
[email protected]9f4e4f082013-06-21 07:11:1968} // namespace extensions
[email protected]163ed192012-07-24 19:31:0769
[email protected]d1ca0ed12009-07-01 18:24:3270// This is an interface class to encapsulate the dependencies that
[email protected]2859946f2011-04-04 18:18:0671// various classes have on ExtensionService. This allows easy mocking.
[email protected]f8aefb132013-10-30 09:29:5272class ExtensionServiceInterface
73 : public base::SupportsWeakPtr<ExtensionServiceInterface> {
[email protected]d1ca0ed12009-07-01 18:24:3274 public:
[email protected]2859946f2011-04-04 18:18:0675 virtual ~ExtensionServiceInterface() {}
[email protected]ca975942014-01-07 12:06:4776
[email protected]dccba4f82014-05-29 00:52:5677 // Gets the object managing the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:4178 virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
[email protected]420a0ec2011-06-01 01:07:0379
[email protected]dccba4f82014-05-29 00:52:5680 // Installs an update with the contents from |extension_path|. Returns true if
81 // the install can be started. Sets |out_crx_installer| to the installer if
82 // one was started.
83 // TODO(aa): This method can be removed. ExtensionUpdater could use
84 // CrxInstaller directly instead.
[email protected]420a0ec2011-06-01 01:07:0385 virtual bool UpdateExtension(
ginkage553af3202015-02-04 12:39:0986 const extensions::CRXFileInfo& file,
[email protected]044e86992014-01-24 22:59:1187 bool file_ownership_passed,
[email protected]bf3d9df2012-07-24 23:20:2788 extensions::CrxInstaller** out_crx_installer) = 0;
[email protected]dccba4f82014-05-29 00:52:5689
[email protected]eb245382014-07-28 22:23:1490 // 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]f574c402012-12-04 23:20:31108 virtual const extensions::Extension* GetExtensionById(
109 const std::string& id,
110 bool include_disabled) const = 0;
[email protected]dccba4f82014-05-29 00:52:56111
[email protected]eb245382014-07-28 22:23:14112 // DEPRECATED: Use ExtensionRegistry instead.
113 //
[email protected]dccba4f82014-05-29 00:52:56114 // Looks up an extension by ID, regardless of whether it's enabled,
[email protected]eb245382014-07-28 22:23:14115 // disabled, blacklisted, or terminated. Use instead:
116 //
sudarsana.naginenidb931782015-06-05 12:01:50117 // ExtensionRegistry::GetInstalledExtension(id).
[email protected]1c321ee2012-05-21 03:02:34118 virtual const extensions::Extension* GetInstalledExtension(
[email protected]8001df22011-04-28 19:59:47119 const std::string& id) const = 0;
[email protected]2859946f2011-04-04 18:18:06120
[email protected]dccba4f82014-05-29 00:52:56121 // 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]76b65442012-11-17 14:11:48124 virtual const extensions::Extension* GetPendingExtensionUpdate(
125 const std::string& extension_id) const = 0;
[email protected]dccba4f82014-05-29 00:52:56126
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]6f6101832012-11-27 22:10:48130 virtual void FinishDelayedInstallation(const std::string& extension_id) = 0;
[email protected]76b65442012-11-17 14:11:48131
[email protected]dccba4f82014-05-29 00:52:56132 // 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]c3cfb012011-04-06 22:07:35134 virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
[email protected]2859946f2011-04-04 18:18:06135
[email protected]dccba4f82014-05-29 00:52:56136 // 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]4ee07c62012-08-21 12:40:42139 virtual void CheckManagementPolicy() = 0;
[email protected]5ef47ec2010-01-28 05:58:05140
[email protected]31206602011-04-13 23:07:32141 // Safe to call multiple times in a row.
142 //
[email protected]90310d92011-04-17 07:35:04143 // TODO(akalin): Remove this method (and others) once we refactor
144 // themes sync to not use it directly.
[email protected]31206602011-04-13 23:07:32145 virtual void CheckForUpdatesSoon() = 0;
[email protected]25ae0152011-11-18 14:40:02146
[email protected]dccba4f82014-05-29 00:52:56147 // Adds |extension| to this ExtensionService and notifies observers that the
148 // extensions have been loaded.
[email protected]1c321ee2012-05-21 03:02:34149 virtual void AddExtension(const extensions::Extension* extension) = 0;
[email protected]dccba4f82014-05-29 00:52:56150
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]8c484b742012-11-29 06:05:36154 virtual void AddComponentExtension(
155 const extensions::Extension* extension) = 0;
[email protected]25ae0152011-11-18 14:40:02156
[email protected]dccba4f82014-05-29 00:52:56157 // Unload the specified extension.
[email protected]25ae0152011-11-18 14:40:02158 virtual void UnloadExtension(
159 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:13160 extensions::UnloadedExtensionInfo::Reason reason) = 0;
[email protected]dccba4f82014-05-29 00:52:56161
162 // Remove the specified component extension.
[email protected]8b1ec202013-09-05 02:09:50163 virtual void RemoveComponentExtension(const std::string& extension_id) = 0;
[email protected]25ae0152011-11-18 14:40:02164
[email protected]dccba4f82014-05-29 00:52:56165 // Whether the extension service is ready.
[email protected]25ae0152011-11-18 14:40:02166 virtual bool is_ready() = 0;
[email protected]7f8f24f2012-11-15 19:40:14167
168 // Returns task runner for crx installation file I/O operations.
169 virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0;
[email protected]d1ca0ed12009-07-01 18:24:32170};
[email protected]fbcc40302009-06-12 20:45:45171
[email protected]fafdc842014-01-17 18:09:08172// Manages installed and running Chromium extensions. An instance is shared
173// between normal and incognito profiles.
[email protected]eaa7dd182010-12-14 11:09:00174class ExtensionService
[email protected]14908b72011-04-20 06:54:36175 : public ExtensionServiceInterface,
[email protected]5df038b2012-07-16 19:03:27176 public extensions::ExternalProviderInterface::VisitorInterface,
[email protected]fdd679b2012-11-15 20:49:39177 public content::NotificationObserver,
binjin1569c9b2014-09-05 13:33:18178 public extensions::Blacklist::Observer,
179 public extensions::ExtensionManagement::Observer {
[email protected]4f313d52009-05-21 00:42:29180 public:
[email protected]6aeac8342010-10-01 20:21:18181 // Attempts to uninstall an extension from a given ExtensionService. Returns
182 // true iff the target extension exists.
[email protected]eaa7dd182010-12-14 11:09:00183 static bool UninstallExtensionHelper(ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04184 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34185 extensions::UninstallReason reason);
[email protected]6aeac8342010-10-01 20:21:18186
[email protected]73c47932010-12-06 18:13:43187 // Constructor stores pointers to |profile| and |extension_prefs| but
188 // ownership remains at caller.
[email protected]eaa7dd182010-12-14 11:09:00189 ExtensionService(Profile* profile,
[email protected]2f3b1cc2014-03-17 23:07:15190 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45191 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23192 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39193 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03194 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35195 bool extensions_enabled,
196 extensions::OneShotEvent* ready);
[email protected]6014d672008-12-05 00:38:25197
dchengae36a4a2014-10-21 12:36:36198 ~ExtensionService() override;
[email protected]14908b72011-04-20 06:54:36199
[email protected]eb245382014-07-28 22:23:14200 // ExtensionServiceInterface implementation.
201 //
202 // NOTE: Many of these methods are DEPRECATED. See the interface for details.
dchengae36a4a2014-10-21 12:36:36203 extensions::PendingExtensionManager* pending_extension_manager() override;
204 const extensions::Extension* GetExtensionById(
[email protected]dccba4f82014-05-29 00:52:56205 const std::string& id,
dchengae36a4a2014-10-21 12:36:36206 bool include_disabled) const override;
207 const extensions::Extension* GetInstalledExtension(
208 const std::string& id) const override;
ginkage553af3202015-02-04 12:39:09209 bool UpdateExtension(const extensions::CRXFileInfo& file,
dchengae36a4a2014-10-21 12:36:36210 bool file_ownership_passed,
211 extensions::CrxInstaller** out_crx_installer) override;
212 bool IsExtensionEnabled(const std::string& extension_id) const override;
213 void UnloadExtension(
[email protected]dccba4f82014-05-29 00:52:56214 const std::string& extension_id,
mostynba15bee12014-10-04 00:40:32215 extensions::UnloadedExtensionInfo::Reason reason) override;
dchengae36a4a2014-10-21 12:36:36216 void RemoveComponentExtension(const std::string& extension_id) override;
217 void AddExtension(const extensions::Extension* extension) override;
218 void AddComponentExtension(const extensions::Extension* extension) override;
219 const extensions::Extension* GetPendingExtensionUpdate(
mostynba15bee12014-10-04 00:40:32220 const std::string& extension_id) const override;
dchengae36a4a2014-10-21 12:36:36221 void FinishDelayedInstallation(const std::string& extension_id) override;
222 void CheckManagementPolicy() override;
223 void CheckForUpdatesSoon() override;
224 bool is_ready() override;
225 base::SequencedTaskRunner* GetFileTaskRunner() override;
[email protected]aa142702010-03-26 01:26:33226
[email protected]dccba4f82014-05-29 00:52:56227 // ExternalProvider::Visitor implementation.
228 // Exposed for testing.
dchengae36a4a2014-10-21 12:36:36229 bool OnExternalExtensionFileFound(const std::string& id,
230 const base::Version* version,
231 const base::FilePath& path,
232 extensions::Manifest::Location location,
233 int creation_flags,
xiyuan4d82f7b62015-03-04 02:29:22234 bool mark_acknowledged,
235 bool install_immediately) override;
dchengae36a4a2014-10-21 12:36:36236 bool OnExternalExtensionUpdateUrlFound(
[email protected]dccba4f82014-05-29 00:52:56237 const std::string& id,
238 const std::string& install_parameter,
239 const GURL& update_url,
240 extensions::Manifest::Location location,
241 int creation_flags,
mostynba15bee12014-10-04 00:40:32242 bool mark_acknowledged) override;
dchengae36a4a2014-10-21 12:36:36243 void OnExternalProviderReady(
mostynba15bee12014-10-04 00:40:32244 const extensions::ExternalProviderInterface* provider) override;
[email protected]ec5b50d2010-10-09 16:35:18245
binjin1569c9b2014-09-05 13:33:18246 // ExtensionManagement::Observer implementation:
dchengae36a4a2014-10-21 12:36:36247 void OnExtensionManagementSettingsChanged() override;
binjin1569c9b2014-09-05 13:33:18248
[email protected]6014d672008-12-05 00:38:25249 // Initialize and start all installed extensions.
[email protected]9f1087e2009-06-15 17:29:32250 void Init();
[email protected]6014d672008-12-05 00:38:25251
[email protected]47b896562012-08-22 23:55:15252 // Called when the associated Profile is going to be destroyed.
253 void Shutdown();
254
[email protected]2380c6b2013-01-09 02:33:13255 // Reloads the specified extension, sending the onLaunched() event to it if it
256 // currently has any window showing.
[email protected]bca4b832014-07-17 20:22:34257 // Allows noisy failures.
thestig7b4bd932014-09-09 22:44:31258 // NOTE: Reloading an extension can invalidate |extension_id| and Extension
259 // pointers for the given extension. Consider making a copy of |extension_id|
260 // first and retrieving a new Extension pointer afterwards.
[email protected]757d60a2014-05-23 00:11:44261 void ReloadExtension(const std::string& extension_id);
[email protected]9cddd4702009-07-27 22:09:40262
[email protected]bca4b832014-07-17 20:22:34263 // Suppresses noisy failures.
264 void ReloadExtensionWithQuietFailure(const std::string& extension_id);
265
[email protected]631cf822009-05-15 07:01:25266 // Uninstalls the specified extension. Callers should only call this method
[email protected]cc2f55c2014-07-08 02:19:04267 // with extensions that exist. |reason| lets the caller specify why the
268 // extension is uninstalled.
[email protected]42d58f62014-07-31 01:32:45269 //
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]0bb29bd2014-04-30 21:39:18272 virtual bool UninstallExtension(const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34273 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45274 const base::Closure& deletion_done_callback,
[email protected]439f1e32013-12-09 20:09:09275 base::string16* error);
[email protected]631cf822009-05-15 07:01:25276
[email protected]06f92562011-04-29 19:27:31277 // Enables the extension. If the extension is already enabled, does
278 // nothing.
[email protected]2859946f2011-04-04 18:18:06279 virtual void EnableExtension(const std::string& extension_id);
[email protected]06f92562011-04-29 19:27:31280
treibc1192322015-05-20 12:56:07281 // Disables the extension. If the extension is already disabled, just adds
282 // the |disable_reasons| (a bitmask of Extension::DisableReason - there can
283 // be multiple DisableReasons e.g. when an extension comes in disabled from
284 // Sync). If the extension cannot be disabled (due to policy), does nothing.
285 virtual void DisableExtension(const std::string& extension_id,
286 int disable_reasons);
[email protected]0c6da502009-08-14 22:32:39287
[email protected]3082fe32013-08-06 11:12:38288 // Disable non-default and non-managed extensions with ids not in
289 // |except_ids|. Default extensions are those from the Web Store with
290 // |was_installed_by_default| flag.
[email protected]1abf05e2013-07-09 17:04:36291 void DisableUserExtensions(const std::vector<std::string>& except_ids);
[email protected]e516e4c2013-06-12 17:41:14292
mlerman6a37b6a42014-11-26 22:10:53293 // Puts all extensions in a blocked state: Unloading every extension, and
294 // preventing them from ever loading until UnblockAllExtensions is called.
295 // This state is stored in preferences, so persists until Chrome restarts.
296 //
297 // Component, external component and whitelisted policy installed extensions
298 // are exempt from being Blocked (see CanBlockExtension).
299 void BlockAllExtensions();
300
301 // All blocked extensions are reverted to their previous state, and are
302 // reloaded. Newly added extensions are no longer automatically blocked.
303 void UnblockAllExtensions();
304
[email protected]8d888c12010-11-30 00:00:25305 // Updates the |extension|'s granted permissions lists to include all
[email protected]8d888c12010-11-30 00:00:25306 // permissions in the |extension|'s manifest and re-enables the
307 // extension.
[email protected]1c321ee2012-05-21 03:02:34308 void GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28309 const extensions::Extension* extension);
[email protected]8d888c12010-11-30 00:00:25310
[email protected]be083862012-09-01 03:53:45311 // Updates the |extension|'s granted permissions lists to include all
312 // permissions in the |extensions|'s manifest.
[email protected]dccba4f82014-05-29 00:52:56313 void GrantPermissions(const extensions::Extension* extension);
[email protected]be083862012-09-01 03:53:45314
[email protected]9f1087e2009-06-15 17:29:32315 // Check for updates (or potentially new extensions from external providers)
[email protected]93fd78f42009-07-10 16:43:17316 void CheckForExternalUpdates();
[email protected]9f1087e2009-06-15 17:29:32317
[email protected]c6d474f82009-12-16 21:11:06318 // Called when the initial extensions load has completed.
319 virtual void OnLoadedInstalledExtensions();
[email protected]7577a5c52009-07-30 06:21:58320
[email protected]bc151cf92013-02-12 04:57:26321 // Informs the service that an extension's files are in place for loading.
322 //
[email protected]4a1d9c0d2014-06-13 12:50:11323 // |extension| the extension
324 // |page_ordinal| the location of the extension in the app launcher
325 // |install_flags| a bitmask of extensions::InstallFlags
[email protected]dccba4f82014-05-29 00:52:56326 void OnExtensionInstalled(const extensions::Extension* extension,
327 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:11328 int install_flags);
329 void OnExtensionInstalled(const extensions::Extension* extension,
330 const syncer::StringOrdinal& page_ordinal) {
331 OnExtensionInstalled(extension,
332 page_ordinal,
333 static_cast<int>(extensions::kInstallFlagNone));
334 }
[email protected]0db124b02012-11-07 04:55:05335
[email protected]9f4e4f082013-06-21 07:11:19336 // Checks for delayed installation for all pending installs.
337 void MaybeFinishDelayedInstallations();
338
[email protected]406027c02010-09-27 08:03:18339 // ExtensionHost of background page calls this method right after its render
340 // view has been created.
[email protected]3a1dc572012-07-31 22:25:13341 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
[email protected]406027c02010-09-27 08:03:18342
[email protected]7f8f24f2012-11-15 19:40:14343 // Changes sequenced task runner for crx installation tasks to |task_runner|.
dcheng605ef8d2014-08-28 18:29:44344 void SetFileTaskRunnerForTesting(
345 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
[email protected]7f8f24f2012-11-15 19:40:14346
[email protected]e5f8fffe2014-04-02 00:30:44347 // Postpone installations so that we don't have to worry about race
348 // conditions.
349 void OnGarbageCollectIsolatedStorageStart();
350
351 // Restart any extension installs which were delayed for isolated storage
352 // garbage collection.
353 void OnGarbageCollectIsolatedStorageFinished();
354
[email protected]fe2dd7742011-04-19 22:52:49355 // Record a histogram using the PermissionMessage enum values for each
356 // permission in |e|.
357 // NOTE: If this is ever called with high frequency, the implementation may
358 // need to be made more efficient.
359 static void RecordPermissionMessagesHistogram(
[email protected]dccba4f82014-05-29 00:52:56360 const extensions::Extension* extension, const char* histogram);
[email protected]fe2dd7742011-04-19 22:52:49361
[email protected]e9d7496e2014-04-18 01:25:46362 // Unloads the given extension and mark the extension as terminated. This
363 // doesn't notify the user that the extension was terminated, if such a
364 // notification is desired the calling code is responsible for doing that.
365 void TerminateExtension(const std::string& extension_id);
366
mukai87a8d402014-09-15 20:15:09367 // Register self and content settings API with the specified map.
368 void RegisterContentSettings(
369 HostContentSettingsMap* host_content_settings_map);
370
[email protected]dccba4f82014-05-29 00:52:56371 // Adds/Removes update observers.
372 void AddUpdateObserver(extensions::UpdateObserver* observer);
373 void RemoveUpdateObserver(extensions::UpdateObserver* observer);
[email protected]a51c9e92012-12-09 09:19:20374
[email protected]dccba4f82014-05-29 00:52:56375 //////////////////////////////////////////////////////////////////////////////
376 // Simple Accessors
[email protected]fa2416f2011-05-03 08:41:20377
[email protected]dccba4f82014-05-29 00:52:56378 // Returns a WeakPtr to the ExtensionService.
[email protected]77e4dc0882012-06-20 18:53:50379 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
380
[email protected]dccba4f82014-05-29 00:52:56381 // Returns profile_ as a BrowserContext.
382 content::BrowserContext* GetBrowserContext() const;
383
384 bool extensions_enabled() const { return extensions_enabled_; }
385 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
386
387 const base::FilePath& install_directory() const { return install_directory_; }
388
389 const extensions::ExtensionSet* delayed_installs() const {
390 return &delayed_installs_;
391 }
392
393 bool show_extensions_prompts() const { return show_extensions_prompts_; }
394 void set_show_extensions_prompts(bool show_extensions_prompts) {
395 show_extensions_prompts_ = show_extensions_prompts;
396 }
397
398 Profile* profile() { return profile_; }
399
[email protected]dccba4f82014-05-29 00:52:56400 // Note that this may return NULL if autoupdate is not turned on.
401 extensions::ExtensionUpdater* updater() { return updater_.get(); }
402
403 extensions::ComponentLoader* component_loader() {
404 return component_loader_.get();
405 }
406
[email protected]3c4abc82012-10-22 22:25:54407 bool browser_terminating() const { return browser_terminating_; }
408
[email protected]90878c52014-04-04 18:21:02409 extensions::SharedModuleService* shared_module_service() {
410 return shared_module_service_.get();
411 }
412
[email protected]2894a512014-06-26 19:03:56413 extensions::ExternalInstallManager* external_install_manager() {
414 return external_install_manager_.get();
415 }
416
[email protected]dccba4f82014-05-29 00:52:56417 //////////////////////////////////////////////////////////////////////////////
418 // For Testing
419
420 // Unload all extensions. Does not send notifications.
421 void UnloadAllExtensionsForTest();
422
423 // Reloads all extensions. Does not notify that extensions are ready.
424 void ReloadExtensionsForTest();
425
426 // Clear all ExternalProviders.
427 void ClearProvidersForTesting();
428
429 // Adds an ExternalProviderInterface for the service to use during testing.
430 // Takes ownership of |test_provider|.
431 void AddProviderForTesting(
432 extensions::ExternalProviderInterface* test_provider);
433
[email protected]8f959f522014-08-06 06:26:28434 // Simulate an extension being blacklisted for tests.
435 void BlacklistExtensionForTest(const std::string& extension_id);
436
[email protected]dccba4f82014-05-29 00:52:56437#if defined(UNIT_TEST)
438 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
xiyuane87def2e2015-06-04 22:50:22439 TrackTerminatedExtension(extension->id());
[email protected]dccba4f82014-05-29 00:52:56440 }
441
442 void FinishInstallationForTest(const extensions::Extension* extension) {
benwells1dd4acd2015-12-09 02:20:24443 FinishInstallation(extension);
[email protected]dccba4f82014-05-29 00:52:56444 }
445#endif
446
[email protected]3c4abc82012-10-22 22:25:54447 void set_browser_terminating_for_test(bool value) {
448 browser_terminating_ = value;
449 }
450
[email protected]fc332ae2012-11-14 20:17:33451 // By default ExtensionService will wait with installing an updated extension
452 // until the extension is idle. Tests might not like this behavior, so you can
453 // disable it with this method.
454 void set_install_updates_when_idle_for_test(bool value) {
455 install_updates_when_idle_ = value;
456 }
457
[email protected]4e9b59d2013-12-18 06:47:14458 // Set a callback to be called when all external providers are ready and their
459 // extensions have been installed.
460 void set_external_updates_finished_callback_for_test(
461 const base::Closure& callback) {
462 external_updates_finished_callback_ = callback;
463 }
464
[email protected]75bdcb872013-03-13 00:41:45465
[email protected]14908b72011-04-20 06:54:36466 private:
[email protected]02c967fe2014-08-12 14:48:43467 // Creates an ExtensionDownloader for use by the updater.
468 scoped_ptr<extensions::ExtensionDownloader> CreateExtensionDownloader(
469 extensions::ExtensionDownloaderDelegate* delegate);
470
[email protected]bca4b832014-07-17 20:22:34471 // Reloads the specified extension, sending the onLaunched() event to it if it
472 // currently has any window showing. |be_noisy| determines whether noisy
473 // failures are allowed for unpacked extension installs.
474 void ReloadExtensionImpl(const std::string& extension_id, bool be_noisy);
475
[email protected]dccba4f82014-05-29 00:52:56476 // content::NotificationObserver implementation:
dchengae36a4a2014-10-21 12:36:36477 void Observe(int type,
478 const content::NotificationSource& source,
479 const content::NotificationDetails& details) override;
[email protected]dccba4f82014-05-29 00:52:56480
481 // extensions::Blacklist::Observer implementation.
dchengae36a4a2014-10-21 12:36:36482 void OnBlacklistUpdated() override;
[email protected]dccba4f82014-05-29 00:52:56483
484 // Similar to FinishInstallation, but first checks if there still is an update
485 // pending for the extension, and makes sure the extension is still idle.
486 void MaybeFinishDelayedInstallation(const std::string& extension_id);
487
488 // For the extension in |version_path| with |id|, check to see if it's an
489 // externally managed extension. If so, uninstall it.
490 void CheckExternalUninstall(const std::string& id);
491
rkaplowa8fd8d32015-02-25 21:27:56492 // Attempt to enable all disabled extensions which the only disabled reason is
493 // reloading.
494 void EnabledReloadableExtensions();
495
496 // Finish install (if possible) of extensions that were still delayed while
497 // the browser was shut down.
498 void MaybeFinishShutdownDelayed();
499
[email protected]2d19eb6e2014-01-27 17:30:00500 // Populates greylist_.
501 void LoadGreylistFromPrefs();
502
[email protected]4a10006a2013-05-17 23:18:35503 // Signals *ready_ and sends a notification to the listeners.
[email protected]820d9bd2013-04-03 03:46:03504 void SetReadyAndNotifyListeners();
505
[email protected]dccba4f82014-05-29 00:52:56506 // Returns true if all the external extension providers are ready.
507 bool AreAllExternalProvidersReady() const;
508
509 // Called once all external providers are ready. Checks for unclaimed
510 // external extensions.
511 void OnAllExternalProvidersReady();
512
xiyuane87def2e2015-06-04 22:50:22513 // Adds the given extension id to the list of terminated extensions if
[email protected]fa2416f2011-05-03 08:41:20514 // it is not already there and unloads it.
xiyuane87def2e2015-06-04 22:50:22515 void TrackTerminatedExtension(const std::string& extension_id);
[email protected]fa2416f2011-05-03 08:41:20516
517 // Removes the extension with the given id from the list of
518 // terminated extensions if it is there.
[email protected]bb7f40952011-01-13 00:21:20519 void UntrackTerminatedExtension(const std::string& id);
520
[email protected]8c484b742012-11-29 06:05:36521 // Update preferences for a new or updated extension; notify observers that
522 // the extension is installed, e.g., to update event handlers on background
523 // pages; and perform other extension install tasks before calling
524 // AddExtension.
[email protected]4a1d9c0d2014-06-13 12:50:11525 // |install_flags| is a bitmask of extensions::InstallFlags.
[email protected]d8fd0fd2014-03-24 13:16:06526 void AddNewOrUpdatedExtension(const extensions::Extension* extension,
527 extensions::Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:11528 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:06529 const syncer::StringOrdinal& page_ordinal,
530 const std::string& install_parameter);
[email protected]8c484b742012-11-29 06:05:36531
[email protected]62d30f42009-10-01 22:36:06532 // Handles sending notification that |extension| was loaded.
[email protected]1c321ee2012-05-21 03:02:34533 void NotifyExtensionLoaded(const extensions::Extension* extension);
[email protected]62d30f42009-10-01 22:36:06534
rockot494f0072015-07-29 17:58:07535 // Completes extension loading after URLRequestContexts have been updated
536 // on the IO thread.
537 void OnExtensionRegisteredWithRequestContexts(
538 scoped_refptr<const extensions::Extension> extension);
539
[email protected]62d30f42009-10-01 22:36:06540 // Handles sending notification that |extension| was unloaded.
[email protected]b0af4792013-10-23 09:12:13541 void NotifyExtensionUnloaded(
542 const extensions::Extension* extension,
543 extensions::UnloadedExtensionInfo::Reason reason);
[email protected]62d30f42009-10-01 22:36:06544
benwells1dd4acd2015-12-09 02:20:24545 // Common helper to finish installing the given extension.
546 void FinishInstallation(const extensions::Extension* extension);
[email protected]6f6101832012-11-27 22:10:48547
[email protected]b914e2952013-04-26 07:10:03548 // Disables the extension if the privilege level has increased
549 // (e.g., due to an upgrade).
550 void CheckPermissionsIncrease(const extensions::Extension* extension,
[email protected]116d40e2013-08-08 17:23:17551 bool is_extension_installed);
[email protected]b914e2952013-04-26 07:10:03552
[email protected]aab98a52009-12-02 03:22:35553 // Helper that updates the active extension list used for crash reporting.
554 void UpdateActiveExtensionsInCrashReporter();
555
binjin47947f842014-11-18 12:10:24556 // Helper to get the disable reasons for an installed (or upgraded) extension.
557 // A return value of Extension::DISABLE_NONE indicates that we should enable
558 // this extension initially.
559 int GetDisableReasonsOnInstalled(const extensions::Extension* extension);
[email protected]612a1cb12012-10-17 13:18:03560
mlerman6a37b6a42014-11-26 22:10:53561 // Helper method to determine if an extension can be blocked.
562 bool CanBlockExtension(const extensions::Extension* extension) const;
563
[email protected]e7aa7b7e2012-11-27 04:51:22564 // Helper to determine if updating an extensions should proceed immediately,
565 // or if we should delay the update until further notice.
566 bool ShouldDelayExtensionUpdate(const std::string& extension_id,
[email protected]4a1d9c0d2014-06-13 12:50:11567 bool install_immediately) const;
[email protected]e7aa7b7e2012-11-27 04:51:22568
[email protected]695b5712012-12-06 23:55:28569 // Manages the blacklisted extensions, intended as callback from
570 // Blacklist::GetBlacklistedIDs.
[email protected]2d19eb6e2014-01-27 17:30:00571 void ManageBlacklist(
572 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids);
573
mlerman6a37b6a42014-11-26 22:10:53574 // Add extensions in |blacklisted| to blacklisted_extensions, remove
575 // extensions that are neither in |blacklisted|, nor in |unchanged|.
576 void UpdateBlacklistedExtensions(
577 const extensions::ExtensionIdSet& to_blacklist,
578 const extensions::ExtensionIdSet& unchanged);
[email protected]2d19eb6e2014-01-27 17:30:00579
580 void UpdateGreylistedExtensions(
[email protected]dccba4f82014-05-29 00:52:56581 const extensions::ExtensionIdSet& greylist,
582 const extensions::ExtensionIdSet& unchanged,
[email protected]2d19eb6e2014-01-27 17:30:00583 const extensions::Blacklist::BlacklistStateMap& state_map);
[email protected]695b5712012-12-06 23:55:28584
[email protected]bb1bc9b32013-12-21 03:09:14585 // Used only by test code.
586 void UnloadAllExtensionsInternal();
587
[email protected]ebe07772014-05-22 04:16:06588 // Disable apps & extensions now to stop them from running after a profile
589 // has been conceptually deleted. Don't wait for full browser shutdown and
590 // the actual profile objects to be destroyed.
591 void OnProfileDestructionStarted();
592
[email protected]5a145e82014-05-29 22:19:07593 // Called on file task runner thread to uninstall extension.
594 static void UninstallExtensionOnFileThread(
595 const std::string& id,
596 Profile* profile,
597 const base::FilePath& install_dir,
598 const base::FilePath& extension_path);
599
[email protected]31d8f5f22012-04-02 15:22:08600 // The normal profile associated with this ExtensionService.
[email protected]6ef635e42009-07-26 06:16:12601 Profile* profile_;
602
[email protected]31d8f5f22012-04-02 15:22:08603 // The ExtensionSystem for the profile above.
[email protected]bd306722012-07-11 20:43:59604 extensions::ExtensionSystem* system_;
[email protected]31d8f5f22012-04-02 15:22:08605
[email protected]695b5712012-12-06 23:55:28606 // Preferences for the owning profile.
[email protected]45759612012-07-10 17:21:23607 extensions::ExtensionPrefs* extension_prefs_;
[email protected]894bb502009-05-21 22:39:57608
[email protected]695b5712012-12-06 23:55:28609 // Blacklist for the owning profile.
610 extensions::Blacklist* blacklist_;
611
[email protected]5fdfa562013-12-27 17:43:59612 // Sets of enabled/disabled/terminated/blacklisted extensions. Not owned.
613 extensions::ExtensionRegistry* registry_;
[email protected]695b5712012-12-06 23:55:28614
[email protected]2d19eb6e2014-01-27 17:30:00615 // Set of greylisted extensions. These extensions are disabled if they are
616 // already installed in Chromium at the time when they are added to
617 // the greylist. Unlike blacklisted extensions, greylisted ones are visible
618 // to the user and if user re-enables such an extension, they remain enabled.
619 //
620 // These extensions should appear in registry_.
621 extensions::ExtensionSet greylist_;
622
[email protected]9f4e4f082013-06-21 07:11:19623 // The list of extension installs delayed for various reasons. The reason
[email protected]bb1bc9b32013-12-21 03:09:14624 // for delayed install is stored in ExtensionPrefs. These are not part of
625 // ExtensionRegistry because they are not yet installed.
[email protected]289c44b2013-12-17 03:26:57626 extensions::ExtensionSet delayed_installs_;
[email protected]0db124b02012-11-07 04:55:05627
[email protected]b2907fd2011-03-25 16:43:37628 // Hold the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41629 extensions::PendingExtensionManager pending_extension_manager_;
[email protected]aa142702010-03-26 01:26:33630
[email protected]6014d672008-12-05 00:38:25631 // The full path to the directory where extensions are installed.
[email protected]650b2d52013-02-10 03:41:45632 base::FilePath install_directory_;
[email protected]6014d672008-12-05 00:38:25633
[email protected]e2eb43112009-05-29 21:19:54634 // Whether or not extensions are enabled.
635 bool extensions_enabled_;
636
[email protected]0e34d7892009-06-05 19:17:40637 // Whether to notify users when they attempt to install an extension.
638 bool show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54639
[email protected]fc332ae2012-11-14 20:17:33640 // Whether to delay installing of extension updates until the extension is
641 // idle.
642 bool install_updates_when_idle_;
643
[email protected]4a10006a2013-05-17 23:18:35644 // Signaled when all extensions are loaded.
645 extensions::OneShotEvent* const ready_;
[email protected]e81dba32009-06-19 20:19:13646
[email protected]93fd78f42009-07-10 16:43:17647 // Our extension updater, if updates are turned on.
[email protected]42a08162012-03-16 18:09:11648 scoped_ptr<extensions::ExtensionUpdater> updater_;
[email protected]93fd78f42009-07-10 16:43:17649
[email protected]1eb175082010-02-10 09:26:16650 // Map unloaded extensions' ids to their paths. When a temporarily loaded
[email protected]5fb889382011-06-03 00:29:20651 // extension is unloaded, we lose the information about it and don't have
[email protected]1eb175082010-02-10 09:26:16652 // any in the extension preferences file.
[email protected]650b2d52013-02-10 03:41:45653 typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap;
[email protected]1eb175082010-02-10 09:26:16654 UnloadedExtensionPathMap unloaded_extension_paths_;
655
[email protected]04ea1bb2013-07-10 09:26:09656 // Map of DevToolsAgentHost instances that are detached,
657 // waiting for an extension to be reloaded.
658 typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> >
659 OrphanedDevTools;
[email protected]4814b512009-11-07 00:12:29660 OrphanedDevTools orphaned_dev_tools_;
661
[email protected]6c2381d2011-10-19 02:52:53662 content::NotificationRegistrar registrar_;
[email protected]4814b512009-11-07 00:12:29663
[email protected]d8c8f25f2011-11-02 18:18:01664 // Keeps track of loading and unloading component extensions.
665 scoped_ptr<extensions::ComponentLoader> component_loader_;
666
[email protected]8e4560b62011-01-14 10:09:14667 // A collection of external extension providers. Each provider reads
668 // a source of external extension information. Examples include the
669 // windows registry and external_extensions.json.
[email protected]5df038b2012-07-16 19:03:27670 extensions::ProviderCollection external_extension_providers_;
[email protected]8e4560b62011-01-14 10:09:14671
672 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
[email protected]94fde232012-04-27 10:22:30673 // extension URL is found, and by CheckForUpdatesSoon() when an update check
674 // has to wait for the external providers. Used in
675 // OnAllExternalProvidersReady() to determine if an update check is needed to
676 // install pending extensions.
677 bool update_once_all_providers_are_ready_;
[email protected]8e4560b62011-01-14 10:09:14678
[email protected]4e9b59d2013-12-18 06:47:14679 // A callback to be called when all external providers are ready and their
680 // extensions have been installed. Normally this is a null callback, but
681 // is used in external provider related tests.
682 base::Closure external_updates_finished_callback_;
683
[email protected]3c4abc82012-10-22 22:25:54684 // Set when the browser is terminating. Prevents us from installing or
685 // updating additional extensions and allows in-progress installations to
686 // decide to abort.
687 bool browser_terminating_;
688
[email protected]9f4e4f082013-06-21 07:11:19689 // Set to true to delay all new extension installations. Acts as a lock to
690 // allow background processing of garbage collection of on-disk state without
691 // needing to worry about race conditions caused by extension installation and
692 // reinstallation.
693 bool installs_delayed_for_gc_;
[email protected]399583b2012-12-11 09:33:42694
[email protected]460c6712013-04-24 07:20:01695 // Set to true if this is the first time this ExtensionService has run.
696 // Used for specially handling external extensions that are installed the
697 // first time.
698 bool is_first_run_;
699
mlerman6a37b6a42014-11-26 22:10:53700 // Set to true if extensions are all to be blocked.
701 bool block_extensions_;
702
[email protected]dccba4f82014-05-29 00:52:56703 // Store the ids of reloading extensions. We use this to re-enable extensions
704 // which were disabled for a reload.
705 std::set<std::string> reloading_extensions_;
[email protected]e178ad92013-06-28 02:29:25706
[email protected]3964e572014-02-13 21:57:41707 // A set of the extension ids currently being terminated. We use this to
708 // avoid trying to unload the same extension twice.
709 std::set<std::string> extensions_being_terminated_;
710
[email protected]373daf972014-04-10 01:50:44711 // The controller for the UI that alerts the user about any blacklisted
712 // extensions.
713 scoped_ptr<extensions::ExtensionErrorController> error_controller_;
714
[email protected]2894a512014-06-26 19:03:56715 // The manager for extensions that were externally installed that is
716 // responsible for prompting the user about suspicious extensions.
717 scoped_ptr<extensions::ExternalInstallManager> external_install_manager_;
718
[email protected]7f8f24f2012-11-15 19:40:14719 // Sequenced task runner for extension related file operations.
720 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
[email protected]a9aa5932012-01-25 08:27:40721
[email protected]c77f2352012-08-08 22:07:58722 scoped_ptr<extensions::ExtensionActionStorageManager>
723 extension_action_storage_manager_;
[email protected]4c9201c42013-08-16 04:56:21724 scoped_ptr<extensions::ManagementPolicy::Provider>
725 shared_module_policy_provider_;
[email protected]c77f2352012-08-08 22:07:58726
[email protected]90878c52014-04-04 18:21:02727 // The SharedModuleService used to check for import dependencies.
728 scoped_ptr<extensions::SharedModuleService> shared_module_service_;
729
brettwd195c952015-06-02 17:31:12730 base::ObserverList<extensions::UpdateObserver, true> update_observers_;
[email protected]efdb7f1a2014-03-28 20:43:38731
ryanackley48bedbd2015-01-27 23:12:14732 // Migrates app data when upgrading a legacy packaged app to a platform app
733 scoped_ptr<extensions::AppDataMigrator> app_data_migrator_;
734
[email protected]eaa7dd182010-12-14 11:09:00735 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]dccba4f82014-05-29 00:52:56736 DestroyingProfileClearsExtensions);
[email protected]f71b582c2014-01-10 17:03:15737 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs);
738 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
739 BlacklistedExtensionWillNotInstall);
740 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
741 UnloadBlacklistedExtensionPolicy);
742 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
743 WillNotLoadBlacklistedExtensionsFromDirectory);
[email protected]757d60a2014-05-23 00:11:44744 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlacklistedExtension);
745 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlacklistedInPrefsFromStartup);
[email protected]2d19eb6e2014-01-27 17:30:00746 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
747 GreylistedExtensionDisabled);
748 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
749 GreylistDontEnableManuallyDisabled);
750 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
751 GreylistUnknownDontChange);
binjin47947f842014-11-18 12:10:24752 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
753 ManagementPolicyProhibitsEnableOnInstalled);
mlerman6a37b6a42014-11-26 22:10:53754 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
755 BlockAndUnblockBlacklistedExtension);
[email protected]dccba4f82014-05-29 00:52:56756
[email protected]eaa7dd182010-12-14 11:09:00757 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
[email protected]6014d672008-12-05 00:38:25758};
759
[email protected]eaa7dd182010-12-14 11:09:00760#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_