blob: b31157b118041e83cd102565694ca8974f8eff89 [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]1ab137b2013-03-21 03:33:1818#include "base/prefs/pref_change_registrar.h"
[email protected]00e7bef2013-06-10 20:35:1719#include "base/strings/string16.h"
[email protected]fdd679b2012-11-15 20:49:3920#include "chrome/browser/extensions/blacklist.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"
[email protected]301116c62013-11-26 10:37:4524#include "extensions/browser/external_provider_interface.h"
[email protected]4a1d9c0d2014-06-13 12:50:1125#include "extensions/browser/install_flag.h"
[email protected]301116c62013-11-26 10:37:4526#include "extensions/browser/management_policy.h"
[email protected]98b6d942013-11-10 00:34:0727#include "extensions/browser/process_manager.h"
[email protected]e43c61f2014-07-20 21:46:3428#include "extensions/browser/uninstall_reason.h"
[email protected]e4452d32013-11-15 23:07:4129#include "extensions/common/extension.h"
[email protected]289c44b2013-12-17 03:26:5730#include "extensions/common/extension_set.h"
[email protected]d42c11152013-08-22 19:36:3231#include "extensions/common/manifest.h"
[email protected]dccba4f82014-05-29 00:52:5632#include "sync/api/string_ordinal.h"
[email protected]6014d672008-12-05 00:38:2533
[email protected]dccba4f82014-05-29 00:52:5634class ExtensionSyncService;
[email protected]69f1be82009-04-16 22:27:2135class GURL;
[email protected]81e63782009-02-27 19:35:0936class Profile;
[email protected]aa142702010-03-26 01:26:3337
[email protected]7f8f24f2012-11-15 19:40:1438namespace base {
[email protected]2f3b1cc2014-03-17 23:07:1539class CommandLine;
[email protected]7f8f24f2012-11-15 19:40:1440class SequencedTaskRunner;
[email protected]1f04ef42013-04-22 07:35:5041class Version;
[email protected]7f8f24f2012-11-15 19:40:1442}
43
[email protected]dccba4f82014-05-29 00:52:5644namespace content {
45class DevToolsAgentHost;
46}
47
[email protected]9c70e0d92012-07-16 08:39:4448namespace extensions {
[email protected]d8c8f25f2011-11-02 18:18:0149class ComponentLoader;
[email protected]bf3d9df2012-07-24 23:20:2750class CrxInstaller;
[email protected]c77f2352012-08-08 22:07:5851class ExtensionActionStorageManager;
[email protected]02c967fe2014-08-12 14:48:4352class ExtensionDownloader;
53class ExtensionDownloaderDelegate;
[email protected]373daf972014-04-10 01:50:4454class ExtensionErrorController;
[email protected]bb1bc9b32013-12-21 03:09:1455class ExtensionRegistry;
[email protected]bd306722012-07-11 20:43:5956class ExtensionSystem;
[email protected]42a08162012-03-16 18:09:1157class ExtensionUpdater;
[email protected]dccba4f82014-05-29 00:52:5658class OneShotEvent;
[email protected]2894a512014-06-26 19:03:5659class ExternalInstallManager;
[email protected]90878c52014-04-04 18:21:0260class SharedModuleService;
[email protected]a9aa62b312013-11-29 05:35:0661class UpdateObserver;
[email protected]9f4e4f082013-06-21 07:11:1962} // namespace extensions
[email protected]163ed192012-07-24 19:31:0763
[email protected]d1ca0ed12009-07-01 18:24:3264// This is an interface class to encapsulate the dependencies that
[email protected]2859946f2011-04-04 18:18:0665// various classes have on ExtensionService. This allows easy mocking.
[email protected]f8aefb132013-10-30 09:29:5266class ExtensionServiceInterface
67 : public base::SupportsWeakPtr<ExtensionServiceInterface> {
[email protected]d1ca0ed12009-07-01 18:24:3268 public:
[email protected]2859946f2011-04-04 18:18:0669 virtual ~ExtensionServiceInterface() {}
[email protected]ca975942014-01-07 12:06:4770
71 // DEPRECATED: Use ExtensionRegistry::enabled_extensions() instead.
[email protected]eb245382014-07-28 22:23:1472 //
[email protected]ca975942014-01-07 12:06:4773 // ExtensionRegistry also has the disabled, terminated and blacklisted sets.
[email protected]289c44b2013-12-17 03:26:5774 virtual const extensions::ExtensionSet* extensions() const = 0;
[email protected]ca975942014-01-07 12:06:4775
[email protected]dccba4f82014-05-29 00:52:5676 // Gets the object managing the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:4177 virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
[email protected]420a0ec2011-06-01 01:07:0378
[email protected]dccba4f82014-05-29 00:52:5679 // Installs an update with the contents from |extension_path|. Returns true if
80 // the install can be started. Sets |out_crx_installer| to the installer if
81 // one was started.
82 // TODO(aa): This method can be removed. ExtensionUpdater could use
83 // CrxInstaller directly instead.
[email protected]420a0ec2011-06-01 01:07:0384 virtual bool UpdateExtension(
85 const std::string& id,
[email protected]650b2d52013-02-10 03:41:4586 const base::FilePath& path,
[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 //
117 // ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::EVERYTHING).
[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,
[email protected]f83bd432014-05-10 20:44:40178 public extensions::Blacklist::Observer {
[email protected]4f313d52009-05-21 00:42:29179 public:
[email protected]6aeac8342010-10-01 20:21:18180 // Attempts to uninstall an extension from a given ExtensionService. Returns
181 // true iff the target extension exists.
[email protected]eaa7dd182010-12-14 11:09:00182 static bool UninstallExtensionHelper(ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04183 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34184 extensions::UninstallReason reason);
[email protected]6aeac8342010-10-01 20:21:18185
[email protected]73c47932010-12-06 18:13:43186 // Constructor stores pointers to |profile| and |extension_prefs| but
187 // ownership remains at caller.
[email protected]eaa7dd182010-12-14 11:09:00188 ExtensionService(Profile* profile,
[email protected]2f3b1cc2014-03-17 23:07:15189 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45190 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23191 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39192 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03193 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35194 bool extensions_enabled,
195 extensions::OneShotEvent* ready);
[email protected]6014d672008-12-05 00:38:25196
[email protected]14908b72011-04-20 06:54:36197 virtual ~ExtensionService();
198
[email protected]eb245382014-07-28 22:23:14199 // ExtensionServiceInterface implementation.
200 //
201 // NOTE: Many of these methods are DEPRECATED. See the interface for details.
[email protected]289c44b2013-12-17 03:26:57202 virtual const extensions::ExtensionSet* extensions() const OVERRIDE;
[email protected]3f213ad2012-07-26 23:39:41203 virtual extensions::PendingExtensionManager*
204 pending_extension_manager() OVERRIDE;
[email protected]dccba4f82014-05-29 00:52:56205 virtual const extensions::Extension* GetExtensionById(
206 const std::string& id, bool include_disabled) const OVERRIDE;
207 virtual const extensions::Extension* GetInstalledExtension(
208 const std::string& id) const OVERRIDE;
209 virtual bool UpdateExtension(
210 const std::string& id,
211 const base::FilePath& extension_path,
212 bool file_ownership_passed,
213 extensions::CrxInstaller** out_crx_installer) OVERRIDE;
214 virtual bool IsExtensionEnabled(
215 const std::string& extension_id) const OVERRIDE;
216 virtual void UnloadExtension(
217 const std::string& extension_id,
218 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
219 virtual void RemoveComponentExtension(const std::string& extension_id)
220 OVERRIDE;
221 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE;
222 virtual void AddComponentExtension(const extensions::Extension* extension)
223 OVERRIDE;
224 virtual const extensions::Extension* GetPendingExtensionUpdate(
225 const std::string& extension_id) const OVERRIDE;
226 virtual void FinishDelayedInstallation(
227 const std::string& extension_id) OVERRIDE;
228 virtual void CheckManagementPolicy() OVERRIDE;
229 virtual void CheckForUpdatesSoon() OVERRIDE;
230 virtual bool is_ready() OVERRIDE;
231 virtual base::SequencedTaskRunner* GetFileTaskRunner() OVERRIDE;
[email protected]aa142702010-03-26 01:26:33232
[email protected]dccba4f82014-05-29 00:52:56233 // ExternalProvider::Visitor implementation.
234 // Exposed for testing.
235 virtual bool OnExternalExtensionFileFound(
236 const std::string& id,
237 const base::Version* version,
238 const base::FilePath& path,
239 extensions::Manifest::Location location,
240 int creation_flags,
241 bool mark_acknowledged) OVERRIDE;
242 virtual bool OnExternalExtensionUpdateUrlFound(
243 const std::string& id,
244 const std::string& install_parameter,
245 const GURL& update_url,
246 extensions::Manifest::Location location,
247 int creation_flags,
248 bool mark_acknowledged) OVERRIDE;
249 virtual void OnExternalProviderReady(
250 const extensions::ExternalProviderInterface* provider) OVERRIDE;
[email protected]ec5b50d2010-10-09 16:35:18251
[email protected]6014d672008-12-05 00:38:25252 // Initialize and start all installed extensions.
[email protected]9f1087e2009-06-15 17:29:32253 void Init();
[email protected]6014d672008-12-05 00:38:25254
[email protected]47b896562012-08-22 23:55:15255 // Called when the associated Profile is going to be destroyed.
256 void Shutdown();
257
[email protected]2380c6b2013-01-09 02:33:13258 // Reloads the specified extension, sending the onLaunched() event to it if it
259 // currently has any window showing.
[email protected]bca4b832014-07-17 20:22:34260 // Allows noisy failures.
[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
281 // Disables the extension. If the extension is already disabled, or
282 // cannot be disabled, does nothing.
[email protected]dccba4f82014-05-29 00:52:56283 virtual void DisableExtension(
284 const std::string& extension_id,
[email protected]1c321ee2012-05-21 03:02:34285 extensions::Extension::DisableReason disable_reason);
[email protected]0c6da502009-08-14 22:32:39286
[email protected]3082fe32013-08-06 11:12:38287 // Disable non-default and non-managed extensions with ids not in
288 // |except_ids|. Default extensions are those from the Web Store with
289 // |was_installed_by_default| flag.
[email protected]1abf05e2013-07-09 17:04:36290 void DisableUserExtensions(const std::vector<std::string>& except_ids);
[email protected]e516e4c2013-06-12 17:41:14291
[email protected]8d888c12010-11-30 00:00:25292 // Updates the |extension|'s granted permissions lists to include all
[email protected]8d888c12010-11-30 00:00:25293 // permissions in the |extension|'s manifest and re-enables the
294 // extension.
[email protected]1c321ee2012-05-21 03:02:34295 void GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28296 const extensions::Extension* extension);
[email protected]8d888c12010-11-30 00:00:25297
[email protected]be083862012-09-01 03:53:45298 // Updates the |extension|'s granted permissions lists to include all
299 // permissions in the |extensions|'s manifest.
[email protected]dccba4f82014-05-29 00:52:56300 void GrantPermissions(const extensions::Extension* extension);
[email protected]be083862012-09-01 03:53:45301
[email protected]9f1087e2009-06-15 17:29:32302 // Check for updates (or potentially new extensions from external providers)
[email protected]93fd78f42009-07-10 16:43:17303 void CheckForExternalUpdates();
[email protected]9f1087e2009-06-15 17:29:32304
[email protected]c6d474f82009-12-16 21:11:06305 // Called when the initial extensions load has completed.
306 virtual void OnLoadedInstalledExtensions();
[email protected]7577a5c52009-07-30 06:21:58307
[email protected]bc151cf92013-02-12 04:57:26308 // Informs the service that an extension's files are in place for loading.
309 //
[email protected]4a1d9c0d2014-06-13 12:50:11310 // |extension| the extension
311 // |page_ordinal| the location of the extension in the app launcher
312 // |install_flags| a bitmask of extensions::InstallFlags
[email protected]dccba4f82014-05-29 00:52:56313 void OnExtensionInstalled(const extensions::Extension* extension,
314 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:11315 int install_flags);
316 void OnExtensionInstalled(const extensions::Extension* extension,
317 const syncer::StringOrdinal& page_ordinal) {
318 OnExtensionInstalled(extension,
319 page_ordinal,
320 static_cast<int>(extensions::kInstallFlagNone));
321 }
[email protected]0db124b02012-11-07 04:55:05322
[email protected]9f4e4f082013-06-21 07:11:19323 // Checks for delayed installation for all pending installs.
324 void MaybeFinishDelayedInstallations();
325
[email protected]760f743b2014-05-28 13:52:02326 // Promotes an ephemeral app to a regular installed app. Ephemeral apps
327 // are already installed in extension system (albiet transiently) and only
328 // need to be exposed in the UI. Set |is_from_sync| to true if the
329 // install was initiated via sync.
330 void PromoteEphemeralApp(
331 const extensions::Extension* extension, bool is_from_sync);
[email protected]7577a5c52009-07-30 06:21:58332
[email protected]406027c02010-09-27 08:03:18333 // ExtensionHost of background page calls this method right after its render
334 // view has been created.
[email protected]3a1dc572012-07-31 22:25:13335 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
[email protected]406027c02010-09-27 08:03:18336
[email protected]7f8f24f2012-11-15 19:40:14337 // Changes sequenced task runner for crx installation tasks to |task_runner|.
dcheng605ef8d2014-08-28 18:29:44338 void SetFileTaskRunnerForTesting(
339 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
[email protected]7f8f24f2012-11-15 19:40:14340
[email protected]e5f8fffe2014-04-02 00:30:44341 // Postpone installations so that we don't have to worry about race
342 // conditions.
343 void OnGarbageCollectIsolatedStorageStart();
344
345 // Restart any extension installs which were delayed for isolated storage
346 // garbage collection.
347 void OnGarbageCollectIsolatedStorageFinished();
348
[email protected]fe2dd7742011-04-19 22:52:49349 // Record a histogram using the PermissionMessage enum values for each
350 // permission in |e|.
351 // NOTE: If this is ever called with high frequency, the implementation may
352 // need to be made more efficient.
353 static void RecordPermissionMessagesHistogram(
[email protected]dccba4f82014-05-29 00:52:56354 const extensions::Extension* extension, const char* histogram);
[email protected]fe2dd7742011-04-19 22:52:49355
[email protected]e9d7496e2014-04-18 01:25:46356 // Unloads the given extension and mark the extension as terminated. This
357 // doesn't notify the user that the extension was terminated, if such a
358 // notification is desired the calling code is responsible for doing that.
359 void TerminateExtension(const std::string& extension_id);
360
[email protected]dccba4f82014-05-29 00:52:56361 // Adds/Removes update observers.
362 void AddUpdateObserver(extensions::UpdateObserver* observer);
363 void RemoveUpdateObserver(extensions::UpdateObserver* observer);
[email protected]a51c9e92012-12-09 09:19:20364
[email protected]dccba4f82014-05-29 00:52:56365 //////////////////////////////////////////////////////////////////////////////
366 // Simple Accessors
[email protected]fa2416f2011-05-03 08:41:20367
[email protected]dccba4f82014-05-29 00:52:56368 // Returns a WeakPtr to the ExtensionService.
[email protected]77e4dc0882012-06-20 18:53:50369 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
370
[email protected]dccba4f82014-05-29 00:52:56371 // Returns profile_ as a BrowserContext.
372 content::BrowserContext* GetBrowserContext() const;
373
374 bool extensions_enabled() const { return extensions_enabled_; }
375 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
376
377 const base::FilePath& install_directory() const { return install_directory_; }
378
379 const extensions::ExtensionSet* delayed_installs() const {
380 return &delayed_installs_;
381 }
382
383 bool show_extensions_prompts() const { return show_extensions_prompts_; }
384 void set_show_extensions_prompts(bool show_extensions_prompts) {
385 show_extensions_prompts_ = show_extensions_prompts;
386 }
387
388 Profile* profile() { return profile_; }
389
390 void set_extension_sync_service(
391 ExtensionSyncService* extension_sync_service) {
392 extension_sync_service_ = extension_sync_service;
393 }
394
395 // Note that this may return NULL if autoupdate is not turned on.
[email protected]dccba4f82014-05-29 00:52:56396 extensions::ExtensionUpdater* updater() { return updater_.get(); }
[email protected]dccba4f82014-05-29 00:52:56397
398 extensions::ComponentLoader* component_loader() {
399 return component_loader_.get();
400 }
401
[email protected]3c4abc82012-10-22 22:25:54402 bool browser_terminating() const { return browser_terminating_; }
403
[email protected]90878c52014-04-04 18:21:02404 extensions::SharedModuleService* shared_module_service() {
405 return shared_module_service_.get();
406 }
407
[email protected]2894a512014-06-26 19:03:56408 extensions::ExternalInstallManager* external_install_manager() {
409 return external_install_manager_.get();
410 }
411
[email protected]dccba4f82014-05-29 00:52:56412 //////////////////////////////////////////////////////////////////////////////
413 // For Testing
414
415 // Unload all extensions. Does not send notifications.
416 void UnloadAllExtensionsForTest();
417
418 // Reloads all extensions. Does not notify that extensions are ready.
419 void ReloadExtensionsForTest();
420
421 // Clear all ExternalProviders.
422 void ClearProvidersForTesting();
423
424 // Adds an ExternalProviderInterface for the service to use during testing.
425 // Takes ownership of |test_provider|.
426 void AddProviderForTesting(
427 extensions::ExternalProviderInterface* test_provider);
428
[email protected]8f959f522014-08-06 06:26:28429 // Simulate an extension being blacklisted for tests.
430 void BlacklistExtensionForTest(const std::string& extension_id);
431
[email protected]dccba4f82014-05-29 00:52:56432#if defined(UNIT_TEST)
433 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
434 TrackTerminatedExtension(extension);
435 }
436
437 void FinishInstallationForTest(const extensions::Extension* extension) {
438 FinishInstallation(extension, false /* not ephemeral */);
439 }
440#endif
441
[email protected]3c4abc82012-10-22 22:25:54442 void set_browser_terminating_for_test(bool value) {
443 browser_terminating_ = value;
444 }
445
[email protected]fc332ae2012-11-14 20:17:33446 // By default ExtensionService will wait with installing an updated extension
447 // until the extension is idle. Tests might not like this behavior, so you can
448 // disable it with this method.
449 void set_install_updates_when_idle_for_test(bool value) {
450 install_updates_when_idle_ = value;
451 }
452
[email protected]4e9b59d2013-12-18 06:47:14453 // Set a callback to be called when all external providers are ready and their
454 // extensions have been installed.
455 void set_external_updates_finished_callback_for_test(
456 const base::Closure& callback) {
457 external_updates_finished_callback_ = callback;
458 }
459
[email protected]75bdcb872013-03-13 00:41:45460
[email protected]14908b72011-04-20 06:54:36461 private:
[email protected]02c967fe2014-08-12 14:48:43462 // Creates an ExtensionDownloader for use by the updater.
463 scoped_ptr<extensions::ExtensionDownloader> CreateExtensionDownloader(
464 extensions::ExtensionDownloaderDelegate* delegate);
465
[email protected]bca4b832014-07-17 20:22:34466 // Reloads the specified extension, sending the onLaunched() event to it if it
467 // currently has any window showing. |be_noisy| determines whether noisy
468 // failures are allowed for unpacked extension installs.
469 void ReloadExtensionImpl(const std::string& extension_id, bool be_noisy);
470
[email protected]dccba4f82014-05-29 00:52:56471 // content::NotificationObserver implementation:
472 virtual void Observe(int type,
473 const content::NotificationSource& source,
474 const content::NotificationDetails& details) OVERRIDE;
475
476 // extensions::Blacklist::Observer implementation.
477 virtual void OnBlacklistUpdated() OVERRIDE;
478
479 // Similar to FinishInstallation, but first checks if there still is an update
480 // pending for the extension, and makes sure the extension is still idle.
481 void MaybeFinishDelayedInstallation(const std::string& extension_id);
482
483 // For the extension in |version_path| with |id|, check to see if it's an
484 // externally managed extension. If so, uninstall it.
485 void CheckExternalUninstall(const std::string& id);
486
[email protected]2d19eb6e2014-01-27 17:30:00487 // Populates greylist_.
488 void LoadGreylistFromPrefs();
489
[email protected]4a10006a2013-05-17 23:18:35490 // Signals *ready_ and sends a notification to the listeners.
[email protected]820d9bd2013-04-03 03:46:03491 void SetReadyAndNotifyListeners();
492
[email protected]dccba4f82014-05-29 00:52:56493 // Returns true if all the external extension providers are ready.
494 bool AreAllExternalProvidersReady() const;
495
496 // Called once all external providers are ready. Checks for unclaimed
497 // external extensions.
498 void OnAllExternalProvidersReady();
499
[email protected]5db9ada2012-04-11 13:48:20500 // Return true if the sync type of |extension| matches |type|.
[email protected]90bb38d2012-11-14 18:36:03501 void OnExtensionInstallPrefChanged();
502
[email protected]fa2416f2011-05-03 08:41:20503 // Adds the given extension to the list of terminated extensions if
504 // it is not already there and unloads it.
[email protected]1c321ee2012-05-21 03:02:34505 void TrackTerminatedExtension(const extensions::Extension* extension);
[email protected]fa2416f2011-05-03 08:41:20506
507 // Removes the extension with the given id from the list of
508 // terminated extensions if it is there.
[email protected]bb7f40952011-01-13 00:21:20509 void UntrackTerminatedExtension(const std::string& id);
510
[email protected]8c484b742012-11-29 06:05:36511 // Update preferences for a new or updated extension; notify observers that
512 // the extension is installed, e.g., to update event handlers on background
513 // pages; and perform other extension install tasks before calling
514 // AddExtension.
[email protected]4a1d9c0d2014-06-13 12:50:11515 // |install_flags| is a bitmask of extensions::InstallFlags.
[email protected]d8fd0fd2014-03-24 13:16:06516 void AddNewOrUpdatedExtension(const extensions::Extension* extension,
517 extensions::Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:11518 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:06519 const syncer::StringOrdinal& page_ordinal,
520 const std::string& install_parameter);
[email protected]8c484b742012-11-29 06:05:36521
[email protected]62d30f42009-10-01 22:36:06522 // Handles sending notification that |extension| was loaded.
[email protected]1c321ee2012-05-21 03:02:34523 void NotifyExtensionLoaded(const extensions::Extension* extension);
[email protected]62d30f42009-10-01 22:36:06524
525 // Handles sending notification that |extension| was unloaded.
[email protected]b0af4792013-10-23 09:12:13526 void NotifyExtensionUnloaded(
527 const extensions::Extension* extension,
528 extensions::UnloadedExtensionInfo::Reason reason);
[email protected]62d30f42009-10-01 22:36:06529
[email protected]760f743b2014-05-28 13:52:02530 // Common helper to finish installing the given extension. |was_ephemeral|
531 // should be true if the extension was previously installed and ephemeral.
532 void FinishInstallation(const extensions::Extension* extension,
533 bool was_ephemeral);
[email protected]6f6101832012-11-27 22:10:48534
[email protected]b914e2952013-04-26 07:10:03535 // Disables the extension if the privilege level has increased
536 // (e.g., due to an upgrade).
537 void CheckPermissionsIncrease(const extensions::Extension* extension,
[email protected]116d40e2013-08-08 17:23:17538 bool is_extension_installed);
[email protected]b914e2952013-04-26 07:10:03539
[email protected]aab98a52009-12-02 03:22:35540 // Helper that updates the active extension list used for crash reporting.
541 void UpdateActiveExtensionsInCrashReporter();
542
[email protected]612a1cb12012-10-17 13:18:03543 // Helper to determine whether we should initially enable an installed
544 // (or upgraded) extension.
545 bool ShouldEnableOnInstall(const extensions::Extension* extension);
546
[email protected]e7aa7b7e2012-11-27 04:51:22547 // Helper to determine if updating an extensions should proceed immediately,
548 // or if we should delay the update until further notice.
549 bool ShouldDelayExtensionUpdate(const std::string& extension_id,
[email protected]4a1d9c0d2014-06-13 12:50:11550 bool install_immediately) const;
[email protected]e7aa7b7e2012-11-27 04:51:22551
[email protected]695b5712012-12-06 23:55:28552 // Manages the blacklisted extensions, intended as callback from
553 // Blacklist::GetBlacklistedIDs.
[email protected]2d19eb6e2014-01-27 17:30:00554 void ManageBlacklist(
555 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids);
556
557 // Add extensions in |blocked| to blacklisted_extensions, remove extensions
558 // that are neither in |blocked|, nor in |unchanged|.
[email protected]dccba4f82014-05-29 00:52:56559 void UpdateBlockedExtensions(const extensions::ExtensionIdSet& blocked,
560 const extensions::ExtensionIdSet& unchanged);
[email protected]2d19eb6e2014-01-27 17:30:00561
562 void UpdateGreylistedExtensions(
[email protected]dccba4f82014-05-29 00:52:56563 const extensions::ExtensionIdSet& greylist,
564 const extensions::ExtensionIdSet& unchanged,
[email protected]2d19eb6e2014-01-27 17:30:00565 const extensions::Blacklist::BlacklistStateMap& state_map);
[email protected]695b5712012-12-06 23:55:28566
[email protected]bb1bc9b32013-12-21 03:09:14567 // Used only by test code.
568 void UnloadAllExtensionsInternal();
569
[email protected]ebe07772014-05-22 04:16:06570 // Disable apps & extensions now to stop them from running after a profile
571 // has been conceptually deleted. Don't wait for full browser shutdown and
572 // the actual profile objects to be destroyed.
573 void OnProfileDestructionStarted();
574
[email protected]5a145e82014-05-29 22:19:07575 // Called on file task runner thread to uninstall extension.
576 static void UninstallExtensionOnFileThread(
577 const std::string& id,
578 Profile* profile,
579 const base::FilePath& install_dir,
580 const base::FilePath& extension_path);
581
[email protected]31d8f5f22012-04-02 15:22:08582 // The normal profile associated with this ExtensionService.
[email protected]6ef635e42009-07-26 06:16:12583 Profile* profile_;
584
[email protected]31d8f5f22012-04-02 15:22:08585 // The ExtensionSystem for the profile above.
[email protected]bd306722012-07-11 20:43:59586 extensions::ExtensionSystem* system_;
[email protected]31d8f5f22012-04-02 15:22:08587
[email protected]695b5712012-12-06 23:55:28588 // Preferences for the owning profile.
[email protected]45759612012-07-10 17:21:23589 extensions::ExtensionPrefs* extension_prefs_;
[email protected]894bb502009-05-21 22:39:57590
[email protected]695b5712012-12-06 23:55:28591 // Blacklist for the owning profile.
592 extensions::Blacklist* blacklist_;
593
[email protected]f8aefb132013-10-30 09:29:52594 // The ExtensionSyncService that is used by this ExtensionService.
595 ExtensionSyncService* extension_sync_service_;
596
[email protected]5fdfa562013-12-27 17:43:59597 // Sets of enabled/disabled/terminated/blacklisted extensions. Not owned.
598 extensions::ExtensionRegistry* registry_;
[email protected]695b5712012-12-06 23:55:28599
[email protected]2d19eb6e2014-01-27 17:30:00600 // Set of greylisted extensions. These extensions are disabled if they are
601 // already installed in Chromium at the time when they are added to
602 // the greylist. Unlike blacklisted extensions, greylisted ones are visible
603 // to the user and if user re-enables such an extension, they remain enabled.
604 //
605 // These extensions should appear in registry_.
606 extensions::ExtensionSet greylist_;
607
[email protected]9f4e4f082013-06-21 07:11:19608 // The list of extension installs delayed for various reasons. The reason
[email protected]bb1bc9b32013-12-21 03:09:14609 // for delayed install is stored in ExtensionPrefs. These are not part of
610 // ExtensionRegistry because they are not yet installed.
[email protected]289c44b2013-12-17 03:26:57611 extensions::ExtensionSet delayed_installs_;
[email protected]0db124b02012-11-07 04:55:05612
[email protected]b2907fd2011-03-25 16:43:37613 // Hold the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41614 extensions::PendingExtensionManager pending_extension_manager_;
[email protected]aa142702010-03-26 01:26:33615
[email protected]6014d672008-12-05 00:38:25616 // The full path to the directory where extensions are installed.
[email protected]650b2d52013-02-10 03:41:45617 base::FilePath install_directory_;
[email protected]6014d672008-12-05 00:38:25618
[email protected]e2eb43112009-05-29 21:19:54619 // Whether or not extensions are enabled.
620 bool extensions_enabled_;
621
[email protected]0e34d7892009-06-05 19:17:40622 // Whether to notify users when they attempt to install an extension.
623 bool show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54624
[email protected]fc332ae2012-11-14 20:17:33625 // Whether to delay installing of extension updates until the extension is
626 // idle.
627 bool install_updates_when_idle_;
628
[email protected]4a10006a2013-05-17 23:18:35629 // Signaled when all extensions are loaded.
630 extensions::OneShotEvent* const ready_;
[email protected]e81dba32009-06-19 20:19:13631
[email protected]93fd78f42009-07-10 16:43:17632 // Our extension updater, if updates are turned on.
[email protected]42a08162012-03-16 18:09:11633 scoped_ptr<extensions::ExtensionUpdater> updater_;
[email protected]93fd78f42009-07-10 16:43:17634
[email protected]1eb175082010-02-10 09:26:16635 // Map unloaded extensions' ids to their paths. When a temporarily loaded
[email protected]5fb889382011-06-03 00:29:20636 // extension is unloaded, we lose the information about it and don't have
[email protected]1eb175082010-02-10 09:26:16637 // any in the extension preferences file.
[email protected]650b2d52013-02-10 03:41:45638 typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap;
[email protected]1eb175082010-02-10 09:26:16639 UnloadedExtensionPathMap unloaded_extension_paths_;
640
[email protected]04ea1bb2013-07-10 09:26:09641 // Map of DevToolsAgentHost instances that are detached,
642 // waiting for an extension to be reloaded.
643 typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> >
644 OrphanedDevTools;
[email protected]4814b512009-11-07 00:12:29645 OrphanedDevTools orphaned_dev_tools_;
646
[email protected]6c2381d2011-10-19 02:52:53647 content::NotificationRegistrar registrar_;
[email protected]2fb7dc982010-09-29 12:24:28648 PrefChangeRegistrar pref_change_registrar_;
[email protected]4814b512009-11-07 00:12:29649
[email protected]d8c8f25f2011-11-02 18:18:01650 // Keeps track of loading and unloading component extensions.
651 scoped_ptr<extensions::ComponentLoader> component_loader_;
652
[email protected]8e4560b62011-01-14 10:09:14653 // A collection of external extension providers. Each provider reads
654 // a source of external extension information. Examples include the
655 // windows registry and external_extensions.json.
[email protected]5df038b2012-07-16 19:03:27656 extensions::ProviderCollection external_extension_providers_;
[email protected]8e4560b62011-01-14 10:09:14657
658 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
[email protected]94fde232012-04-27 10:22:30659 // extension URL is found, and by CheckForUpdatesSoon() when an update check
660 // has to wait for the external providers. Used in
661 // OnAllExternalProvidersReady() to determine if an update check is needed to
662 // install pending extensions.
663 bool update_once_all_providers_are_ready_;
[email protected]8e4560b62011-01-14 10:09:14664
[email protected]4e9b59d2013-12-18 06:47:14665 // A callback to be called when all external providers are ready and their
666 // extensions have been installed. Normally this is a null callback, but
667 // is used in external provider related tests.
668 base::Closure external_updates_finished_callback_;
669
[email protected]3c4abc82012-10-22 22:25:54670 // Set when the browser is terminating. Prevents us from installing or
671 // updating additional extensions and allows in-progress installations to
672 // decide to abort.
673 bool browser_terminating_;
674
[email protected]9f4e4f082013-06-21 07:11:19675 // Set to true to delay all new extension installations. Acts as a lock to
676 // allow background processing of garbage collection of on-disk state without
677 // needing to worry about race conditions caused by extension installation and
678 // reinstallation.
679 bool installs_delayed_for_gc_;
[email protected]399583b2012-12-11 09:33:42680
[email protected]460c6712013-04-24 07:20:01681 // Set to true if this is the first time this ExtensionService has run.
682 // Used for specially handling external extensions that are installed the
683 // first time.
684 bool is_first_run_;
685
[email protected]dccba4f82014-05-29 00:52:56686 // Store the ids of reloading extensions. We use this to re-enable extensions
687 // which were disabled for a reload.
688 std::set<std::string> reloading_extensions_;
[email protected]e178ad92013-06-28 02:29:25689
[email protected]3964e572014-02-13 21:57:41690 // A set of the extension ids currently being terminated. We use this to
691 // avoid trying to unload the same extension twice.
692 std::set<std::string> extensions_being_terminated_;
693
[email protected]373daf972014-04-10 01:50:44694 // The controller for the UI that alerts the user about any blacklisted
695 // extensions.
696 scoped_ptr<extensions::ExtensionErrorController> error_controller_;
697
[email protected]2894a512014-06-26 19:03:56698 // The manager for extensions that were externally installed that is
699 // responsible for prompting the user about suspicious extensions.
700 scoped_ptr<extensions::ExternalInstallManager> external_install_manager_;
701
[email protected]7f8f24f2012-11-15 19:40:14702 // Sequenced task runner for extension related file operations.
703 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
[email protected]a9aa5932012-01-25 08:27:40704
[email protected]c77f2352012-08-08 22:07:58705 scoped_ptr<extensions::ExtensionActionStorageManager>
706 extension_action_storage_manager_;
[email protected]4c9201c42013-08-16 04:56:21707 scoped_ptr<extensions::ManagementPolicy::Provider>
708 shared_module_policy_provider_;
[email protected]c77f2352012-08-08 22:07:58709
[email protected]90878c52014-04-04 18:21:02710 // The SharedModuleService used to check for import dependencies.
711 scoped_ptr<extensions::SharedModuleService> shared_module_service_;
712
[email protected]e5f8fffe2014-04-02 00:30:44713 ObserverList<extensions::UpdateObserver, true> update_observers_;
[email protected]efdb7f1a2014-03-28 20:43:38714
[email protected]eaa7dd182010-12-14 11:09:00715 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]dccba4f82014-05-29 00:52:56716 DestroyingProfileClearsExtensions);
[email protected]f71b582c2014-01-10 17:03:15717 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs);
718 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
719 BlacklistedExtensionWillNotInstall);
720 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
721 UnloadBlacklistedExtensionPolicy);
722 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
723 WillNotLoadBlacklistedExtensionsFromDirectory);
[email protected]757d60a2014-05-23 00:11:44724 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlacklistedExtension);
725 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlacklistedInPrefsFromStartup);
[email protected]2d19eb6e2014-01-27 17:30:00726 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
727 GreylistedExtensionDisabled);
728 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
729 GreylistDontEnableManuallyDisabled);
730 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
731 GreylistUnknownDontChange);
[email protected]dccba4f82014-05-29 00:52:56732
[email protected]eaa7dd182010-12-14 11:09:00733 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
[email protected]6014d672008-12-05 00:38:25734};
735
[email protected]eaa7dd182010-12-14 11:09:00736#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_