blob: 43ae3974644f6edba6a3f2f36a3813ed85a06454 [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]373daf972014-04-10 01:50:4452class ExtensionErrorController;
[email protected]bb1bc9b32013-12-21 03:09:1453class ExtensionRegistry;
[email protected]bd306722012-07-11 20:43:5954class ExtensionSystem;
[email protected]42a08162012-03-16 18:09:1155class ExtensionUpdater;
[email protected]dccba4f82014-05-29 00:52:5656class OneShotEvent;
[email protected]2894a512014-06-26 19:03:5657class ExternalInstallManager;
[email protected]90878c52014-04-04 18:21:0258class SharedModuleService;
[email protected]a9aa62b312013-11-29 05:35:0659class UpdateObserver;
[email protected]9f4e4f082013-06-21 07:11:1960} // namespace extensions
[email protected]163ed192012-07-24 19:31:0761
[email protected]d1ca0ed12009-07-01 18:24:3262// This is an interface class to encapsulate the dependencies that
[email protected]2859946f2011-04-04 18:18:0663// various classes have on ExtensionService. This allows easy mocking.
[email protected]f8aefb132013-10-30 09:29:5264class ExtensionServiceInterface
65 : public base::SupportsWeakPtr<ExtensionServiceInterface> {
[email protected]d1ca0ed12009-07-01 18:24:3266 public:
[email protected]2859946f2011-04-04 18:18:0667 virtual ~ExtensionServiceInterface() {}
[email protected]ca975942014-01-07 12:06:4768
69 // DEPRECATED: Use ExtensionRegistry::enabled_extensions() instead.
[email protected]eb245382014-07-28 22:23:1470 //
[email protected]ca975942014-01-07 12:06:4771 // ExtensionRegistry also has the disabled, terminated and blacklisted sets.
[email protected]289c44b2013-12-17 03:26:5772 virtual const extensions::ExtensionSet* extensions() const = 0;
[email protected]ca975942014-01-07 12:06:4773
[email protected]dccba4f82014-05-29 00:52:5674 // Gets the object managing the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:4175 virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
[email protected]420a0ec2011-06-01 01:07:0376
[email protected]dccba4f82014-05-29 00:52:5677 // Installs an update with the contents from |extension_path|. Returns true if
78 // the install can be started. Sets |out_crx_installer| to the installer if
79 // one was started.
80 // TODO(aa): This method can be removed. ExtensionUpdater could use
81 // CrxInstaller directly instead.
[email protected]420a0ec2011-06-01 01:07:0382 virtual bool UpdateExtension(
83 const std::string& id,
[email protected]650b2d52013-02-10 03:41:4584 const base::FilePath& path,
[email protected]044e86992014-01-24 22:59:1185 bool file_ownership_passed,
[email protected]bf3d9df2012-07-24 23:20:2786 extensions::CrxInstaller** out_crx_installer) = 0;
[email protected]dccba4f82014-05-29 00:52:5687
[email protected]eb245382014-07-28 22:23:1488 // DEPRECATED. Use ExtensionRegistry instead.
89 //
90 // Looks up an extension by its ID.
91 //
92 // If |include_disabled| is false then this will only include enabled
93 // extensions. Use instead:
94 //
95 // ExtensionRegistry::enabled_extensions().GetByID(id).
96 //
97 // If |include_disabled| is true then this will also include disabled and
98 // blacklisted extensions (not terminated extensions). Use instead:
99 //
100 // ExtensionRegistry::GetExtensionById(
101 // id, ExtensionRegistry::ENABLED |
102 // ExtensionRegistry::DISABLED |
103 // ExtensionRegistry::BLACKLISTED)
104 //
105 // Or don't, because it's probably not something you ever need to know.
[email protected]f574c402012-12-04 23:20:31106 virtual const extensions::Extension* GetExtensionById(
107 const std::string& id,
108 bool include_disabled) const = 0;
[email protected]dccba4f82014-05-29 00:52:56109
[email protected]eb245382014-07-28 22:23:14110 // DEPRECATED: Use ExtensionRegistry instead.
111 //
[email protected]dccba4f82014-05-29 00:52:56112 // Looks up an extension by ID, regardless of whether it's enabled,
[email protected]eb245382014-07-28 22:23:14113 // disabled, blacklisted, or terminated. Use instead:
114 //
115 // ExtensionRegistry::GetExtensionById(id, ExtensionRegistry::EVERYTHING).
[email protected]1c321ee2012-05-21 03:02:34116 virtual const extensions::Extension* GetInstalledExtension(
[email protected]8001df22011-04-28 19:59:47117 const std::string& id) const = 0;
[email protected]2859946f2011-04-04 18:18:06118
[email protected]dccba4f82014-05-29 00:52:56119 // Returns an update for an extension with the specified id, if installation
120 // of that update was previously delayed because the extension was in use. If
121 // no updates are pending for the extension returns NULL.
[email protected]76b65442012-11-17 14:11:48122 virtual const extensions::Extension* GetPendingExtensionUpdate(
123 const std::string& extension_id) const = 0;
[email protected]dccba4f82014-05-29 00:52:56124
125 // Finishes installation of an update for an extension with the specified id,
126 // when installation of that extension was previously delayed because the
127 // extension was in use.
[email protected]6f6101832012-11-27 22:10:48128 virtual void FinishDelayedInstallation(const std::string& extension_id) = 0;
[email protected]76b65442012-11-17 14:11:48129
[email protected]dccba4f82014-05-29 00:52:56130 // Returns true if the extension with the given |extension_id| is enabled.
131 // This will return a valid answer even if the extension is not loaded yet.
[email protected]c3cfb012011-04-06 22:07:35132 virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
[email protected]2859946f2011-04-04 18:18:06133
[email protected]dccba4f82014-05-29 00:52:56134 // Go through each extension and unload those that are not allowed to run by
135 // management policy providers (ie. network admin and Google-managed
136 // blacklist).
[email protected]4ee07c62012-08-21 12:40:42137 virtual void CheckManagementPolicy() = 0;
[email protected]5ef47ec2010-01-28 05:58:05138
[email protected]31206602011-04-13 23:07:32139 // Safe to call multiple times in a row.
140 //
[email protected]90310d92011-04-17 07:35:04141 // TODO(akalin): Remove this method (and others) once we refactor
142 // themes sync to not use it directly.
[email protected]31206602011-04-13 23:07:32143 virtual void CheckForUpdatesSoon() = 0;
[email protected]25ae0152011-11-18 14:40:02144
[email protected]dccba4f82014-05-29 00:52:56145 // Adds |extension| to this ExtensionService and notifies observers that the
146 // extensions have been loaded.
[email protected]1c321ee2012-05-21 03:02:34147 virtual void AddExtension(const extensions::Extension* extension) = 0;
[email protected]dccba4f82014-05-29 00:52:56148
149 // Check if we have preferences for the component extension and, if not or if
150 // the stored version differs, install the extension (without requirements
151 // checking) before calling AddExtension.
[email protected]8c484b742012-11-29 06:05:36152 virtual void AddComponentExtension(
153 const extensions::Extension* extension) = 0;
[email protected]25ae0152011-11-18 14:40:02154
[email protected]dccba4f82014-05-29 00:52:56155 // Unload the specified extension.
[email protected]25ae0152011-11-18 14:40:02156 virtual void UnloadExtension(
157 const std::string& extension_id,
[email protected]b0af4792013-10-23 09:12:13158 extensions::UnloadedExtensionInfo::Reason reason) = 0;
[email protected]dccba4f82014-05-29 00:52:56159
160 // Remove the specified component extension.
[email protected]8b1ec202013-09-05 02:09:50161 virtual void RemoveComponentExtension(const std::string& extension_id) = 0;
[email protected]25ae0152011-11-18 14:40:02162
[email protected]dccba4f82014-05-29 00:52:56163 // Whether the extension service is ready.
[email protected]25ae0152011-11-18 14:40:02164 virtual bool is_ready() = 0;
[email protected]7f8f24f2012-11-15 19:40:14165
166 // Returns task runner for crx installation file I/O operations.
167 virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0;
[email protected]d1ca0ed12009-07-01 18:24:32168};
[email protected]fbcc40302009-06-12 20:45:45169
[email protected]fafdc842014-01-17 18:09:08170// Manages installed and running Chromium extensions. An instance is shared
171// between normal and incognito profiles.
[email protected]eaa7dd182010-12-14 11:09:00172class ExtensionService
[email protected]14908b72011-04-20 06:54:36173 : public ExtensionServiceInterface,
[email protected]5df038b2012-07-16 19:03:27174 public extensions::ExternalProviderInterface::VisitorInterface,
[email protected]fdd679b2012-11-15 20:49:39175 public content::NotificationObserver,
[email protected]f83bd432014-05-10 20:44:40176 public extensions::Blacklist::Observer {
[email protected]4f313d52009-05-21 00:42:29177 public:
[email protected]6aeac8342010-10-01 20:21:18178 // Attempts to uninstall an extension from a given ExtensionService. Returns
179 // true iff the target extension exists.
[email protected]eaa7dd182010-12-14 11:09:00180 static bool UninstallExtensionHelper(ExtensionService* extensions_service,
[email protected]cc2f55c2014-07-08 02:19:04181 const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34182 extensions::UninstallReason reason);
[email protected]6aeac8342010-10-01 20:21:18183
[email protected]73c47932010-12-06 18:13:43184 // Constructor stores pointers to |profile| and |extension_prefs| but
185 // ownership remains at caller.
[email protected]eaa7dd182010-12-14 11:09:00186 ExtensionService(Profile* profile,
[email protected]2f3b1cc2014-03-17 23:07:15187 const base::CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45188 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23189 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39190 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03191 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35192 bool extensions_enabled,
193 extensions::OneShotEvent* ready);
[email protected]6014d672008-12-05 00:38:25194
[email protected]14908b72011-04-20 06:54:36195 virtual ~ExtensionService();
196
[email protected]eb245382014-07-28 22:23:14197 // ExtensionServiceInterface implementation.
198 //
199 // NOTE: Many of these methods are DEPRECATED. See the interface for details.
[email protected]289c44b2013-12-17 03:26:57200 virtual const extensions::ExtensionSet* extensions() const OVERRIDE;
[email protected]3f213ad2012-07-26 23:39:41201 virtual extensions::PendingExtensionManager*
202 pending_extension_manager() OVERRIDE;
[email protected]dccba4f82014-05-29 00:52:56203 virtual const extensions::Extension* GetExtensionById(
204 const std::string& id, bool include_disabled) const OVERRIDE;
205 virtual const extensions::Extension* GetInstalledExtension(
206 const std::string& id) const OVERRIDE;
207 virtual bool UpdateExtension(
208 const std::string& id,
209 const base::FilePath& extension_path,
210 bool file_ownership_passed,
211 extensions::CrxInstaller** out_crx_installer) OVERRIDE;
212 virtual bool IsExtensionEnabled(
213 const std::string& extension_id) const OVERRIDE;
214 virtual void UnloadExtension(
215 const std::string& extension_id,
216 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
217 virtual void RemoveComponentExtension(const std::string& extension_id)
218 OVERRIDE;
219 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE;
220 virtual void AddComponentExtension(const extensions::Extension* extension)
221 OVERRIDE;
222 virtual const extensions::Extension* GetPendingExtensionUpdate(
223 const std::string& extension_id) const OVERRIDE;
224 virtual void FinishDelayedInstallation(
225 const std::string& extension_id) OVERRIDE;
226 virtual void CheckManagementPolicy() OVERRIDE;
227 virtual void CheckForUpdatesSoon() OVERRIDE;
228 virtual bool is_ready() OVERRIDE;
229 virtual base::SequencedTaskRunner* GetFileTaskRunner() OVERRIDE;
[email protected]aa142702010-03-26 01:26:33230
[email protected]dccba4f82014-05-29 00:52:56231 // ExternalProvider::Visitor implementation.
232 // Exposed for testing.
233 virtual bool OnExternalExtensionFileFound(
234 const std::string& id,
235 const base::Version* version,
236 const base::FilePath& path,
237 extensions::Manifest::Location location,
238 int creation_flags,
239 bool mark_acknowledged) OVERRIDE;
240 virtual bool OnExternalExtensionUpdateUrlFound(
241 const std::string& id,
242 const std::string& install_parameter,
243 const GURL& update_url,
244 extensions::Manifest::Location location,
245 int creation_flags,
246 bool mark_acknowledged) OVERRIDE;
247 virtual void OnExternalProviderReady(
248 const extensions::ExternalProviderInterface* provider) OVERRIDE;
[email protected]ec5b50d2010-10-09 16:35:18249
[email protected]6014d672008-12-05 00:38:25250 // Initialize and start all installed extensions.
[email protected]9f1087e2009-06-15 17:29:32251 void Init();
[email protected]6014d672008-12-05 00:38:25252
[email protected]47b896562012-08-22 23:55:15253 // Called when the associated Profile is going to be destroyed.
254 void Shutdown();
255
[email protected]2380c6b2013-01-09 02:33:13256 // Reloads the specified extension, sending the onLaunched() event to it if it
257 // currently has any window showing.
[email protected]bca4b832014-07-17 20:22:34258 // Allows noisy failures.
[email protected]757d60a2014-05-23 00:11:44259 void ReloadExtension(const std::string& extension_id);
[email protected]9cddd4702009-07-27 22:09:40260
[email protected]bca4b832014-07-17 20:22:34261 // Suppresses noisy failures.
262 void ReloadExtensionWithQuietFailure(const std::string& extension_id);
263
[email protected]631cf822009-05-15 07:01:25264 // Uninstalls the specified extension. Callers should only call this method
[email protected]cc2f55c2014-07-08 02:19:04265 // with extensions that exist. |reason| lets the caller specify why the
266 // extension is uninstalled.
[email protected]42d58f62014-07-31 01:32:45267 //
268 // If the return value is true, |deletion_done_callback| is invoked when data
269 // deletion is done or at least is scheduled.
[email protected]0bb29bd2014-04-30 21:39:18270 virtual bool UninstallExtension(const std::string& extension_id,
[email protected]e43c61f2014-07-20 21:46:34271 extensions::UninstallReason reason,
[email protected]42d58f62014-07-31 01:32:45272 const base::Closure& deletion_done_callback,
[email protected]439f1e32013-12-09 20:09:09273 base::string16* error);
[email protected]631cf822009-05-15 07:01:25274
[email protected]06f92562011-04-29 19:27:31275 // Enables the extension. If the extension is already enabled, does
276 // nothing.
[email protected]2859946f2011-04-04 18:18:06277 virtual void EnableExtension(const std::string& extension_id);
[email protected]06f92562011-04-29 19:27:31278
279 // Disables the extension. If the extension is already disabled, or
280 // cannot be disabled, does nothing.
[email protected]dccba4f82014-05-29 00:52:56281 virtual void DisableExtension(
282 const std::string& extension_id,
[email protected]1c321ee2012-05-21 03:02:34283 extensions::Extension::DisableReason disable_reason);
[email protected]0c6da502009-08-14 22:32:39284
[email protected]3082fe32013-08-06 11:12:38285 // Disable non-default and non-managed extensions with ids not in
286 // |except_ids|. Default extensions are those from the Web Store with
287 // |was_installed_by_default| flag.
[email protected]1abf05e2013-07-09 17:04:36288 void DisableUserExtensions(const std::vector<std::string>& except_ids);
[email protected]e516e4c2013-06-12 17:41:14289
[email protected]8d888c12010-11-30 00:00:25290 // Updates the |extension|'s granted permissions lists to include all
[email protected]8d888c12010-11-30 00:00:25291 // permissions in the |extension|'s manifest and re-enables the
292 // extension.
[email protected]1c321ee2012-05-21 03:02:34293 void GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28294 const extensions::Extension* extension);
[email protected]8d888c12010-11-30 00:00:25295
[email protected]be083862012-09-01 03:53:45296 // Updates the |extension|'s granted permissions lists to include all
297 // permissions in the |extensions|'s manifest.
[email protected]dccba4f82014-05-29 00:52:56298 void GrantPermissions(const extensions::Extension* extension);
[email protected]be083862012-09-01 03:53:45299
[email protected]9f1087e2009-06-15 17:29:32300 // Check for updates (or potentially new extensions from external providers)
[email protected]93fd78f42009-07-10 16:43:17301 void CheckForExternalUpdates();
[email protected]9f1087e2009-06-15 17:29:32302
[email protected]c6d474f82009-12-16 21:11:06303 // Called when the initial extensions load has completed.
304 virtual void OnLoadedInstalledExtensions();
[email protected]7577a5c52009-07-30 06:21:58305
[email protected]bc151cf92013-02-12 04:57:26306 // Informs the service that an extension's files are in place for loading.
307 //
[email protected]4a1d9c0d2014-06-13 12:50:11308 // |extension| the extension
309 // |page_ordinal| the location of the extension in the app launcher
310 // |install_flags| a bitmask of extensions::InstallFlags
[email protected]dccba4f82014-05-29 00:52:56311 void OnExtensionInstalled(const extensions::Extension* extension,
312 const syncer::StringOrdinal& page_ordinal,
[email protected]4a1d9c0d2014-06-13 12:50:11313 int install_flags);
314 void OnExtensionInstalled(const extensions::Extension* extension,
315 const syncer::StringOrdinal& page_ordinal) {
316 OnExtensionInstalled(extension,
317 page_ordinal,
318 static_cast<int>(extensions::kInstallFlagNone));
319 }
[email protected]0db124b02012-11-07 04:55:05320
[email protected]9f4e4f082013-06-21 07:11:19321 // Checks for delayed installation for all pending installs.
322 void MaybeFinishDelayedInstallations();
323
[email protected]760f743b2014-05-28 13:52:02324 // Promotes an ephemeral app to a regular installed app. Ephemeral apps
325 // are already installed in extension system (albiet transiently) and only
326 // need to be exposed in the UI. Set |is_from_sync| to true if the
327 // install was initiated via sync.
328 void PromoteEphemeralApp(
329 const extensions::Extension* extension, bool is_from_sync);
[email protected]7577a5c52009-07-30 06:21:58330
[email protected]406027c02010-09-27 08:03:18331 // ExtensionHost of background page calls this method right after its render
332 // view has been created.
[email protected]3a1dc572012-07-31 22:25:13333 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
[email protected]406027c02010-09-27 08:03:18334
[email protected]7f8f24f2012-11-15 19:40:14335 // Changes sequenced task runner for crx installation tasks to |task_runner|.
336 void SetFileTaskRunnerForTesting(base::SequencedTaskRunner* task_runner);
337
[email protected]e5f8fffe2014-04-02 00:30:44338 // Postpone installations so that we don't have to worry about race
339 // conditions.
340 void OnGarbageCollectIsolatedStorageStart();
341
342 // Restart any extension installs which were delayed for isolated storage
343 // garbage collection.
344 void OnGarbageCollectIsolatedStorageFinished();
345
[email protected]fe2dd7742011-04-19 22:52:49346 // Record a histogram using the PermissionMessage enum values for each
347 // permission in |e|.
348 // NOTE: If this is ever called with high frequency, the implementation may
349 // need to be made more efficient.
350 static void RecordPermissionMessagesHistogram(
[email protected]dccba4f82014-05-29 00:52:56351 const extensions::Extension* extension, const char* histogram);
[email protected]fe2dd7742011-04-19 22:52:49352
[email protected]e9d7496e2014-04-18 01:25:46353 // Unloads the given extension and mark the extension as terminated. This
354 // doesn't notify the user that the extension was terminated, if such a
355 // notification is desired the calling code is responsible for doing that.
356 void TerminateExtension(const std::string& extension_id);
357
[email protected]dccba4f82014-05-29 00:52:56358 // Adds/Removes update observers.
359 void AddUpdateObserver(extensions::UpdateObserver* observer);
360 void RemoveUpdateObserver(extensions::UpdateObserver* observer);
[email protected]a51c9e92012-12-09 09:19:20361
[email protected]dccba4f82014-05-29 00:52:56362 //////////////////////////////////////////////////////////////////////////////
363 // Simple Accessors
[email protected]fa2416f2011-05-03 08:41:20364
[email protected]dccba4f82014-05-29 00:52:56365 // Returns a WeakPtr to the ExtensionService.
[email protected]77e4dc0882012-06-20 18:53:50366 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
367
[email protected]dccba4f82014-05-29 00:52:56368 // Returns profile_ as a BrowserContext.
369 content::BrowserContext* GetBrowserContext() const;
370
371 bool extensions_enabled() const { return extensions_enabled_; }
372 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
373
374 const base::FilePath& install_directory() const { return install_directory_; }
375
376 const extensions::ExtensionSet* delayed_installs() const {
377 return &delayed_installs_;
378 }
379
380 bool show_extensions_prompts() const { return show_extensions_prompts_; }
381 void set_show_extensions_prompts(bool show_extensions_prompts) {
382 show_extensions_prompts_ = show_extensions_prompts;
383 }
384
385 Profile* profile() { return profile_; }
386
387 void set_extension_sync_service(
388 ExtensionSyncService* extension_sync_service) {
389 extension_sync_service_ = extension_sync_service;
390 }
391
392 // Note that this may return NULL if autoupdate is not turned on.
[email protected]ddc6a122014-06-27 04:52:32393#if defined(ENABLE_EXTENSIONS)
[email protected]dccba4f82014-05-29 00:52:56394 extensions::ExtensionUpdater* updater() { return updater_.get(); }
[email protected]ddc6a122014-06-27 04:52:32395#else
396 extensions::ExtensionUpdater* updater() { return NULL; }
397#endif
[email protected]dccba4f82014-05-29 00:52:56398
399 extensions::ComponentLoader* component_loader() {
400 return component_loader_.get();
401 }
402
[email protected]3c4abc82012-10-22 22:25:54403 bool browser_terminating() const { return browser_terminating_; }
404
[email protected]90878c52014-04-04 18:21:02405 extensions::SharedModuleService* shared_module_service() {
406 return shared_module_service_.get();
407 }
408
[email protected]2894a512014-06-26 19:03:56409 extensions::ExternalInstallManager* external_install_manager() {
410 return external_install_manager_.get();
411 }
412
[email protected]dccba4f82014-05-29 00:52:56413 //////////////////////////////////////////////////////////////////////////////
414 // For Testing
415
416 // Unload all extensions. Does not send notifications.
417 void UnloadAllExtensionsForTest();
418
419 // Reloads all extensions. Does not notify that extensions are ready.
420 void ReloadExtensionsForTest();
421
422 // Clear all ExternalProviders.
423 void ClearProvidersForTesting();
424
425 // Adds an ExternalProviderInterface for the service to use during testing.
426 // Takes ownership of |test_provider|.
427 void AddProviderForTesting(
428 extensions::ExternalProviderInterface* test_provider);
429
430#if defined(UNIT_TEST)
431 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
432 TrackTerminatedExtension(extension);
433 }
434
435 void FinishInstallationForTest(const extensions::Extension* extension) {
436 FinishInstallation(extension, false /* not ephemeral */);
437 }
438#endif
439
[email protected]3c4abc82012-10-22 22:25:54440 void set_browser_terminating_for_test(bool value) {
441 browser_terminating_ = value;
442 }
443
[email protected]fc332ae2012-11-14 20:17:33444 // By default ExtensionService will wait with installing an updated extension
445 // until the extension is idle. Tests might not like this behavior, so you can
446 // disable it with this method.
447 void set_install_updates_when_idle_for_test(bool value) {
448 install_updates_when_idle_ = value;
449 }
450
[email protected]4e9b59d2013-12-18 06:47:14451 // Set a callback to be called when all external providers are ready and their
452 // extensions have been installed.
453 void set_external_updates_finished_callback_for_test(
454 const base::Closure& callback) {
455 external_updates_finished_callback_ = callback;
456 }
457
[email protected]75bdcb872013-03-13 00:41:45458
[email protected]14908b72011-04-20 06:54:36459 private:
[email protected]bca4b832014-07-17 20:22:34460 // Reloads the specified extension, sending the onLaunched() event to it if it
461 // currently has any window showing. |be_noisy| determines whether noisy
462 // failures are allowed for unpacked extension installs.
463 void ReloadExtensionImpl(const std::string& extension_id, bool be_noisy);
464
[email protected]dccba4f82014-05-29 00:52:56465 // content::NotificationObserver implementation:
466 virtual void Observe(int type,
467 const content::NotificationSource& source,
468 const content::NotificationDetails& details) OVERRIDE;
469
470 // extensions::Blacklist::Observer implementation.
471 virtual void OnBlacklistUpdated() OVERRIDE;
472
473 // Similar to FinishInstallation, but first checks if there still is an update
474 // pending for the extension, and makes sure the extension is still idle.
475 void MaybeFinishDelayedInstallation(const std::string& extension_id);
476
477 // For the extension in |version_path| with |id|, check to see if it's an
478 // externally managed extension. If so, uninstall it.
479 void CheckExternalUninstall(const std::string& id);
480
[email protected]2d19eb6e2014-01-27 17:30:00481 // Populates greylist_.
482 void LoadGreylistFromPrefs();
483
[email protected]4a10006a2013-05-17 23:18:35484 // Signals *ready_ and sends a notification to the listeners.
[email protected]820d9bd2013-04-03 03:46:03485 void SetReadyAndNotifyListeners();
486
[email protected]dccba4f82014-05-29 00:52:56487 // Returns true if all the external extension providers are ready.
488 bool AreAllExternalProvidersReady() const;
489
490 // Called once all external providers are ready. Checks for unclaimed
491 // external extensions.
492 void OnAllExternalProvidersReady();
493
[email protected]5db9ada2012-04-11 13:48:20494 // Return true if the sync type of |extension| matches |type|.
[email protected]90bb38d2012-11-14 18:36:03495 void OnExtensionInstallPrefChanged();
496
[email protected]fa2416f2011-05-03 08:41:20497 // Adds the given extension to the list of terminated extensions if
498 // it is not already there and unloads it.
[email protected]1c321ee2012-05-21 03:02:34499 void TrackTerminatedExtension(const extensions::Extension* extension);
[email protected]fa2416f2011-05-03 08:41:20500
501 // Removes the extension with the given id from the list of
502 // terminated extensions if it is there.
[email protected]bb7f40952011-01-13 00:21:20503 void UntrackTerminatedExtension(const std::string& id);
504
[email protected]8c484b742012-11-29 06:05:36505 // Update preferences for a new or updated extension; notify observers that
506 // the extension is installed, e.g., to update event handlers on background
507 // pages; and perform other extension install tasks before calling
508 // AddExtension.
[email protected]4a1d9c0d2014-06-13 12:50:11509 // |install_flags| is a bitmask of extensions::InstallFlags.
[email protected]d8fd0fd2014-03-24 13:16:06510 void AddNewOrUpdatedExtension(const extensions::Extension* extension,
511 extensions::Extension::State initial_state,
[email protected]4a1d9c0d2014-06-13 12:50:11512 int install_flags,
[email protected]d8fd0fd2014-03-24 13:16:06513 const syncer::StringOrdinal& page_ordinal,
514 const std::string& install_parameter);
[email protected]8c484b742012-11-29 06:05:36515
[email protected]62d30f42009-10-01 22:36:06516 // Handles sending notification that |extension| was loaded.
[email protected]1c321ee2012-05-21 03:02:34517 void NotifyExtensionLoaded(const extensions::Extension* extension);
[email protected]62d30f42009-10-01 22:36:06518
519 // Handles sending notification that |extension| was unloaded.
[email protected]b0af4792013-10-23 09:12:13520 void NotifyExtensionUnloaded(
521 const extensions::Extension* extension,
522 extensions::UnloadedExtensionInfo::Reason reason);
[email protected]62d30f42009-10-01 22:36:06523
[email protected]760f743b2014-05-28 13:52:02524 // Common helper to finish installing the given extension. |was_ephemeral|
525 // should be true if the extension was previously installed and ephemeral.
526 void FinishInstallation(const extensions::Extension* extension,
527 bool was_ephemeral);
[email protected]6f6101832012-11-27 22:10:48528
[email protected]b914e2952013-04-26 07:10:03529 // Disables the extension if the privilege level has increased
530 // (e.g., due to an upgrade).
531 void CheckPermissionsIncrease(const extensions::Extension* extension,
[email protected]116d40e2013-08-08 17:23:17532 bool is_extension_installed);
[email protected]b914e2952013-04-26 07:10:03533
[email protected]aab98a52009-12-02 03:22:35534 // Helper that updates the active extension list used for crash reporting.
535 void UpdateActiveExtensionsInCrashReporter();
536
[email protected]612a1cb12012-10-17 13:18:03537 // Helper to determine whether we should initially enable an installed
538 // (or upgraded) extension.
539 bool ShouldEnableOnInstall(const extensions::Extension* extension);
540
[email protected]e7aa7b7e2012-11-27 04:51:22541 // Helper to determine if updating an extensions should proceed immediately,
542 // or if we should delay the update until further notice.
543 bool ShouldDelayExtensionUpdate(const std::string& extension_id,
[email protected]4a1d9c0d2014-06-13 12:50:11544 bool install_immediately) const;
[email protected]e7aa7b7e2012-11-27 04:51:22545
[email protected]695b5712012-12-06 23:55:28546 // Manages the blacklisted extensions, intended as callback from
547 // Blacklist::GetBlacklistedIDs.
[email protected]2d19eb6e2014-01-27 17:30:00548 void ManageBlacklist(
549 const extensions::Blacklist::BlacklistStateMap& blacklisted_ids);
550
551 // Add extensions in |blocked| to blacklisted_extensions, remove extensions
552 // that are neither in |blocked|, nor in |unchanged|.
[email protected]dccba4f82014-05-29 00:52:56553 void UpdateBlockedExtensions(const extensions::ExtensionIdSet& blocked,
554 const extensions::ExtensionIdSet& unchanged);
[email protected]2d19eb6e2014-01-27 17:30:00555
556 void UpdateGreylistedExtensions(
[email protected]dccba4f82014-05-29 00:52:56557 const extensions::ExtensionIdSet& greylist,
558 const extensions::ExtensionIdSet& unchanged,
[email protected]2d19eb6e2014-01-27 17:30:00559 const extensions::Blacklist::BlacklistStateMap& state_map);
[email protected]695b5712012-12-06 23:55:28560
[email protected]bb1bc9b32013-12-21 03:09:14561 // Used only by test code.
562 void UnloadAllExtensionsInternal();
563
[email protected]ebe07772014-05-22 04:16:06564 // Disable apps & extensions now to stop them from running after a profile
565 // has been conceptually deleted. Don't wait for full browser shutdown and
566 // the actual profile objects to be destroyed.
567 void OnProfileDestructionStarted();
568
[email protected]5a145e82014-05-29 22:19:07569 // Called on file task runner thread to uninstall extension.
570 static void UninstallExtensionOnFileThread(
571 const std::string& id,
572 Profile* profile,
573 const base::FilePath& install_dir,
574 const base::FilePath& extension_path);
575
[email protected]31d8f5f22012-04-02 15:22:08576 // The normal profile associated with this ExtensionService.
[email protected]6ef635e42009-07-26 06:16:12577 Profile* profile_;
578
[email protected]31d8f5f22012-04-02 15:22:08579 // The ExtensionSystem for the profile above.
[email protected]bd306722012-07-11 20:43:59580 extensions::ExtensionSystem* system_;
[email protected]31d8f5f22012-04-02 15:22:08581
[email protected]695b5712012-12-06 23:55:28582 // Preferences for the owning profile.
[email protected]45759612012-07-10 17:21:23583 extensions::ExtensionPrefs* extension_prefs_;
[email protected]894bb502009-05-21 22:39:57584
[email protected]695b5712012-12-06 23:55:28585 // Blacklist for the owning profile.
586 extensions::Blacklist* blacklist_;
587
[email protected]f8aefb132013-10-30 09:29:52588 // The ExtensionSyncService that is used by this ExtensionService.
589 ExtensionSyncService* extension_sync_service_;
590
[email protected]5fdfa562013-12-27 17:43:59591 // Sets of enabled/disabled/terminated/blacklisted extensions. Not owned.
592 extensions::ExtensionRegistry* registry_;
[email protected]695b5712012-12-06 23:55:28593
[email protected]2d19eb6e2014-01-27 17:30:00594 // Set of greylisted extensions. These extensions are disabled if they are
595 // already installed in Chromium at the time when they are added to
596 // the greylist. Unlike blacklisted extensions, greylisted ones are visible
597 // to the user and if user re-enables such an extension, they remain enabled.
598 //
599 // These extensions should appear in registry_.
600 extensions::ExtensionSet greylist_;
601
[email protected]9f4e4f082013-06-21 07:11:19602 // The list of extension installs delayed for various reasons. The reason
[email protected]bb1bc9b32013-12-21 03:09:14603 // for delayed install is stored in ExtensionPrefs. These are not part of
604 // ExtensionRegistry because they are not yet installed.
[email protected]289c44b2013-12-17 03:26:57605 extensions::ExtensionSet delayed_installs_;
[email protected]0db124b02012-11-07 04:55:05606
[email protected]b2907fd2011-03-25 16:43:37607 // Hold the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41608 extensions::PendingExtensionManager pending_extension_manager_;
[email protected]aa142702010-03-26 01:26:33609
[email protected]6014d672008-12-05 00:38:25610 // The full path to the directory where extensions are installed.
[email protected]650b2d52013-02-10 03:41:45611 base::FilePath install_directory_;
[email protected]6014d672008-12-05 00:38:25612
[email protected]e2eb43112009-05-29 21:19:54613 // Whether or not extensions are enabled.
614 bool extensions_enabled_;
615
[email protected]0e34d7892009-06-05 19:17:40616 // Whether to notify users when they attempt to install an extension.
617 bool show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54618
[email protected]fc332ae2012-11-14 20:17:33619 // Whether to delay installing of extension updates until the extension is
620 // idle.
621 bool install_updates_when_idle_;
622
[email protected]4a10006a2013-05-17 23:18:35623 // Signaled when all extensions are loaded.
624 extensions::OneShotEvent* const ready_;
[email protected]e81dba32009-06-19 20:19:13625
[email protected]ddc6a122014-06-27 04:52:32626#if defined(ENABLE_EXTENSIONS)
[email protected]93fd78f42009-07-10 16:43:17627 // Our extension updater, if updates are turned on.
[email protected]42a08162012-03-16 18:09:11628 scoped_ptr<extensions::ExtensionUpdater> updater_;
[email protected]ddc6a122014-06-27 04:52:32629#endif
[email protected]93fd78f42009-07-10 16:43:17630
[email protected]1eb175082010-02-10 09:26:16631 // Map unloaded extensions' ids to their paths. When a temporarily loaded
[email protected]5fb889382011-06-03 00:29:20632 // extension is unloaded, we lose the information about it and don't have
[email protected]1eb175082010-02-10 09:26:16633 // any in the extension preferences file.
[email protected]650b2d52013-02-10 03:41:45634 typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap;
[email protected]1eb175082010-02-10 09:26:16635 UnloadedExtensionPathMap unloaded_extension_paths_;
636
[email protected]04ea1bb2013-07-10 09:26:09637 // Map of DevToolsAgentHost instances that are detached,
638 // waiting for an extension to be reloaded.
639 typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> >
640 OrphanedDevTools;
[email protected]4814b512009-11-07 00:12:29641 OrphanedDevTools orphaned_dev_tools_;
642
[email protected]6c2381d2011-10-19 02:52:53643 content::NotificationRegistrar registrar_;
[email protected]2fb7dc982010-09-29 12:24:28644 PrefChangeRegistrar pref_change_registrar_;
[email protected]4814b512009-11-07 00:12:29645
[email protected]d8c8f25f2011-11-02 18:18:01646 // Keeps track of loading and unloading component extensions.
647 scoped_ptr<extensions::ComponentLoader> component_loader_;
648
[email protected]8e4560b62011-01-14 10:09:14649 // A collection of external extension providers. Each provider reads
650 // a source of external extension information. Examples include the
651 // windows registry and external_extensions.json.
[email protected]5df038b2012-07-16 19:03:27652 extensions::ProviderCollection external_extension_providers_;
[email protected]8e4560b62011-01-14 10:09:14653
654 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
[email protected]94fde232012-04-27 10:22:30655 // extension URL is found, and by CheckForUpdatesSoon() when an update check
656 // has to wait for the external providers. Used in
657 // OnAllExternalProvidersReady() to determine if an update check is needed to
658 // install pending extensions.
659 bool update_once_all_providers_are_ready_;
[email protected]8e4560b62011-01-14 10:09:14660
[email protected]4e9b59d2013-12-18 06:47:14661 // A callback to be called when all external providers are ready and their
662 // extensions have been installed. Normally this is a null callback, but
663 // is used in external provider related tests.
664 base::Closure external_updates_finished_callback_;
665
[email protected]3c4abc82012-10-22 22:25:54666 // Set when the browser is terminating. Prevents us from installing or
667 // updating additional extensions and allows in-progress installations to
668 // decide to abort.
669 bool browser_terminating_;
670
[email protected]9f4e4f082013-06-21 07:11:19671 // Set to true to delay all new extension installations. Acts as a lock to
672 // allow background processing of garbage collection of on-disk state without
673 // needing to worry about race conditions caused by extension installation and
674 // reinstallation.
675 bool installs_delayed_for_gc_;
[email protected]399583b2012-12-11 09:33:42676
[email protected]460c6712013-04-24 07:20:01677 // Set to true if this is the first time this ExtensionService has run.
678 // Used for specially handling external extensions that are installed the
679 // first time.
680 bool is_first_run_;
681
[email protected]dccba4f82014-05-29 00:52:56682 // Store the ids of reloading extensions. We use this to re-enable extensions
683 // which were disabled for a reload.
684 std::set<std::string> reloading_extensions_;
[email protected]e178ad92013-06-28 02:29:25685
[email protected]3964e572014-02-13 21:57:41686 // A set of the extension ids currently being terminated. We use this to
687 // avoid trying to unload the same extension twice.
688 std::set<std::string> extensions_being_terminated_;
689
[email protected]373daf972014-04-10 01:50:44690 // The controller for the UI that alerts the user about any blacklisted
691 // extensions.
692 scoped_ptr<extensions::ExtensionErrorController> error_controller_;
693
[email protected]2894a512014-06-26 19:03:56694 // The manager for extensions that were externally installed that is
695 // responsible for prompting the user about suspicious extensions.
696 scoped_ptr<extensions::ExternalInstallManager> external_install_manager_;
697
[email protected]7f8f24f2012-11-15 19:40:14698 // Sequenced task runner for extension related file operations.
699 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
[email protected]a9aa5932012-01-25 08:27:40700
[email protected]9ce11d22012-08-08 23:20:13701#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58702 scoped_ptr<extensions::ExtensionActionStorageManager>
703 extension_action_storage_manager_;
[email protected]9ce11d22012-08-08 23:20:13704#endif
[email protected]4c9201c42013-08-16 04:56:21705 scoped_ptr<extensions::ManagementPolicy::Provider>
706 shared_module_policy_provider_;
[email protected]c77f2352012-08-08 22:07:58707
[email protected]90878c52014-04-04 18:21:02708 // The SharedModuleService used to check for import dependencies.
709 scoped_ptr<extensions::SharedModuleService> shared_module_service_;
710
[email protected]e5f8fffe2014-04-02 00:30:44711 ObserverList<extensions::UpdateObserver, true> update_observers_;
[email protected]efdb7f1a2014-03-28 20:43:38712
[email protected]eaa7dd182010-12-14 11:09:00713 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]dccba4f82014-05-29 00:52:56714 DestroyingProfileClearsExtensions);
[email protected]f71b582c2014-01-10 17:03:15715 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, SetUnsetBlacklistInPrefs);
716 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
717 BlacklistedExtensionWillNotInstall);
718 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
719 UnloadBlacklistedExtensionPolicy);
720 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
721 WillNotLoadBlacklistedExtensionsFromDirectory);
[email protected]757d60a2014-05-23 00:11:44722 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, ReloadBlacklistedExtension);
723 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, BlacklistedInPrefsFromStartup);
[email protected]2d19eb6e2014-01-27 17:30:00724 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
725 GreylistedExtensionDisabled);
726 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
727 GreylistDontEnableManuallyDisabled);
728 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
729 GreylistUnknownDontChange);
[email protected]dccba4f82014-05-29 00:52:56730
[email protected]eaa7dd182010-12-14 11:09:00731 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
[email protected]6014d672008-12-05 00:38:25732};
733
[email protected]eaa7dd182010-12-14 11:09:00734#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_