blob: 89325766f2012c6d42f5f2ad18bdab9cf870df96 [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]5db9ada2012-04-11 13:48:2020#include "chrome/browser/extensions/app_sync_bundle.h"
[email protected]fdd679b2012-11-15 20:49:3921#include "chrome/browser/extensions/blacklist.h"
[email protected]07ad9622013-01-18 23:00:3322#include "chrome/browser/extensions/extension_function_histogram_value.h"
[email protected]b671760b2010-07-15 21:13:4723#include "chrome/browser/extensions/extension_icon_manager.h"
[email protected]c38831a12011-10-28 12:44:4924#include "chrome/browser/extensions/extension_prefs.h"
[email protected]c6e4a3412009-06-24 15:45:2925#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]5db9ada2012-04-11 13:48:2026#include "chrome/browser/extensions/extension_sync_bundle.h"
[email protected]e0360f2c2009-12-07 22:34:3127#include "chrome/browser/extensions/extension_toolbar_model.h"
[email protected]d13950e2009-12-04 01:43:0228#include "chrome/browser/extensions/extensions_quota_service.h"
[email protected]5df038b2012-07-16 19:03:2729#include "chrome/browser/extensions/external_provider_interface.h"
[email protected]5aeeae12012-07-05 19:13:1130#include "chrome/browser/extensions/menu_manager.h"
[email protected]b2907fd2011-03-25 16:43:3731#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]6f371442011-11-09 06:45:4632#include "chrome/browser/extensions/process_map.h"
[email protected]75bdcb872013-03-13 00:41:4533#include "chrome/browser/extensions/update_observer.h"
[email protected]3bdba0d2011-08-23 07:17:3034#include "chrome/common/extensions/extension.h"
[email protected]814a7bf0f2011-08-13 05:30:5935#include "chrome/common/extensions/extension_constants.h"
[email protected]84df8332011-12-06 18:22:4636#include "chrome/common/extensions/extension_set.h"
[email protected]1d5e58b2013-01-31 08:41:4037#include "chrome/common/extensions/manifest.h"
[email protected]04ea1bb2013-07-10 09:26:0938#include "content/public/browser/devtools_agent_host.h"
[email protected]6c2381d2011-10-19 02:52:5339#include "content/public/browser/notification_observer.h"
40#include "content/public/browser/notification_registrar.h"
[email protected]4a10006a2013-05-17 23:18:3541#include "extensions/common/one_shot_event.h"
[email protected]36b643212012-09-07 12:53:0042#include "sync/api/string_ordinal.h"
[email protected]895a1e52012-05-15 02:50:1243#include "sync/api/sync_change.h"
44#include "sync/api/syncable_service.h"
[email protected]6014d672008-12-05 00:38:2545
[email protected]dc9a74f72012-08-17 18:07:2146class CommandLine;
[email protected]89226982012-07-16 20:09:1847class ExtensionErrorUI;
[email protected]3bdba0d2011-08-23 07:17:3048class ExtensionSyncData;
[email protected]e0360f2c2009-12-07 22:34:3149class ExtensionToolbarModel;
[email protected]69f1be82009-04-16 22:27:2150class GURL;
[email protected]81e63782009-02-27 19:35:0951class Profile;
[email protected]aa142702010-03-26 01:26:3352
[email protected]7f8f24f2012-11-15 19:40:1453namespace base {
54class SequencedTaskRunner;
[email protected]1f04ef42013-04-22 07:35:5055class Version;
[email protected]7f8f24f2012-11-15 19:40:1456}
57
[email protected]9c70e0d92012-07-16 08:39:4458namespace extensions {
[email protected]5db9ada2012-04-11 13:48:2059class AppSyncData;
[email protected]5a38dfd2012-07-23 23:22:1060class BrowserEventRouter;
[email protected]d8c8f25f2011-11-02 18:18:0161class ComponentLoader;
[email protected]e2d720aa2012-05-17 00:11:3562class ContentSettingsStore;
[email protected]bf3d9df2012-07-24 23:20:2763class CrxInstaller;
[email protected]c77f2352012-08-08 22:07:5864class ExtensionActionStorageManager;
[email protected]5db9ada2012-04-11 13:48:2065class ExtensionSyncData;
[email protected]bd306722012-07-11 20:43:5966class ExtensionSystem;
[email protected]42a08162012-03-16 18:09:1167class ExtensionUpdater;
[email protected]3f213ad2012-07-26 23:39:4168class PendingExtensionManager;
[email protected]cccdf0aa2011-11-11 03:43:3869class SettingsFrontend;
[email protected]9f4e4f082013-06-21 07:11:1970} // namespace extensions
[email protected]163ed192012-07-24 19:31:0771
72namespace syncer {
[email protected]163ed192012-07-24 19:31:0773class SyncErrorFactory;
[email protected]d8c8f25f2011-11-02 18:18:0174}
[email protected]771a6182011-10-05 16:32:5275
[email protected]d1ca0ed12009-07-01 18:24:3276// This is an interface class to encapsulate the dependencies that
[email protected]2859946f2011-04-04 18:18:0677// various classes have on ExtensionService. This allows easy mocking.
[email protected]65f173552012-06-28 22:43:5878class ExtensionServiceInterface : public syncer::SyncableService {
[email protected]d1ca0ed12009-07-01 18:24:3279 public:
[email protected]2859946f2011-04-04 18:18:0680 virtual ~ExtensionServiceInterface() {}
[email protected]84df8332011-12-06 18:22:4681 virtual const ExtensionSet* extensions() const = 0;
[email protected]c38fd352012-03-28 04:06:1282 virtual const ExtensionSet* disabled_extensions() const = 0;
[email protected]3f213ad2012-07-26 23:39:4183 virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
[email protected]420a0ec2011-06-01 01:07:0384
85 // Install an update. Return true if the install can be started.
86 // Set out_crx_installer to the installer if one was started.
87 virtual bool UpdateExtension(
88 const std::string& id,
[email protected]650b2d52013-02-10 03:41:4589 const base::FilePath& path,
[email protected]420a0ec2011-06-01 01:07:0390 const GURL& download_url,
[email protected]bf3d9df2012-07-24 23:20:2791 extensions::CrxInstaller** out_crx_installer) = 0;
[email protected]f574c402012-12-04 23:20:3192 virtual const extensions::Extension* GetExtensionById(
93 const std::string& id,
94 bool include_disabled) const = 0;
[email protected]1c321ee2012-05-21 03:02:3495 virtual const extensions::Extension* GetInstalledExtension(
[email protected]8001df22011-04-28 19:59:4796 const std::string& id) const = 0;
[email protected]2859946f2011-04-04 18:18:0697
[email protected]76b65442012-11-17 14:11:4898 virtual const extensions::Extension* GetPendingExtensionUpdate(
99 const std::string& extension_id) const = 0;
[email protected]6f6101832012-11-27 22:10:48100 virtual void FinishDelayedInstallation(const std::string& extension_id) = 0;
[email protected]76b65442012-11-17 14:11:48101
[email protected]c3cfb012011-04-06 22:07:35102 virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
103 virtual bool IsExternalExtensionUninstalled(
104 const std::string& extension_id) const = 0;
[email protected]2859946f2011-04-04 18:18:06105
[email protected]4ee07c62012-08-21 12:40:42106 virtual void CheckManagementPolicy() = 0;
[email protected]5ef47ec2010-01-28 05:58:05107
[email protected]31206602011-04-13 23:07:32108 // Safe to call multiple times in a row.
109 //
[email protected]90310d92011-04-17 07:35:04110 // TODO(akalin): Remove this method (and others) once we refactor
111 // themes sync to not use it directly.
[email protected]31206602011-04-13 23:07:32112 virtual void CheckForUpdatesSoon() = 0;
[email protected]25ae0152011-11-18 14:40:02113
[email protected]1c321ee2012-05-21 03:02:34114 virtual void AddExtension(const extensions::Extension* extension) = 0;
[email protected]8c484b742012-11-29 06:05:36115 virtual void AddComponentExtension(
116 const extensions::Extension* extension) = 0;
[email protected]25ae0152011-11-18 14:40:02117
118 virtual void UnloadExtension(
119 const std::string& extension_id,
120 extension_misc::UnloadedExtensionReason reason) = 0;
121
[email protected]1c321ee2012-05-21 03:02:34122 virtual void SyncExtensionChangeIfNeeded(
123 const extensions::Extension& extension) = 0;
[email protected]fb82dcd2012-03-21 14:15:46124
[email protected]25ae0152011-11-18 14:40:02125 virtual bool is_ready() = 0;
[email protected]7f8f24f2012-11-15 19:40:14126
127 // Returns task runner for crx installation file I/O operations.
128 virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0;
[email protected]d1ca0ed12009-07-01 18:24:32129};
[email protected]fbcc40302009-06-12 20:45:45130
[email protected]4f313d52009-05-21 00:42:29131// Manages installed and running Chromium extensions.
[email protected]eaa7dd182010-12-14 11:09:00132class ExtensionService
[email protected]14908b72011-04-20 06:54:36133 : public ExtensionServiceInterface,
[email protected]5df038b2012-07-16 19:03:27134 public extensions::ExternalProviderInterface::VisitorInterface,
[email protected]fdd679b2012-11-15 20:49:39135 public content::NotificationObserver,
136 public extensions::Blacklist::Observer {
[email protected]4f313d52009-05-21 00:42:29137 public:
[email protected]93fd78f42009-07-10 16:43:17138 // If auto-updates are turned on, default to running every 5 hours.
139 static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5;
140
[email protected]15d5b472011-11-24 04:17:24141 // The name of the directory inside the profile where per-app local settings
[email protected]b7f853e282011-08-10 09:24:20142 // are stored.
[email protected]31bb5ee62012-09-12 22:58:40143 static const char kLocalAppSettingsDirectoryName[];
[email protected]27cc7332011-11-01 01:56:43144
[email protected]15d5b472011-11-24 04:17:24145 // The name of the directory inside the profile where per-extension local
146 // settings are stored.
[email protected]31bb5ee62012-09-12 22:58:40147 static const char kLocalExtensionSettingsDirectoryName[];
[email protected]15d5b472011-11-24 04:17:24148
149 // The name of the directory inside the profile where per-app synced settings
[email protected]27cc7332011-11-01 01:56:43150 // are stored.
[email protected]31bb5ee62012-09-12 22:58:40151 static const char kSyncAppSettingsDirectoryName[];
[email protected]15d5b472011-11-24 04:17:24152
153 // The name of the directory inside the profile where per-extension synced
154 // settings are stored.
[email protected]31bb5ee62012-09-12 22:58:40155 static const char kSyncExtensionSettingsDirectoryName[];
[email protected]b7f853e282011-08-10 09:24:20156
[email protected]675bb01012012-12-14 22:03:29157 // The name of the directory inside the profile where per-extension persistent
158 // managed settings are stored.
159 static const char kManagedSettingsDirectoryName[];
160
[email protected]90e800c2012-06-12 23:11:00161 // The name of the database inside the profile where chrome-internal
162 // extension state resides.
[email protected]31bb5ee62012-09-12 22:58:40163 static const char kStateStoreName[];
[email protected]90e800c2012-06-12 23:11:00164
[email protected]a690e292012-12-19 19:22:49165 // The name of the database inside the profile where declarative extension
166 // rules are stored.
167 static const char kRulesStoreName[];
168
[email protected]d9696672011-03-15 22:45:09169 // Returns the Extension of hosted or packaged apps, NULL otherwise.
[email protected]dc9a74f72012-08-17 18:07:21170 const extensions::Extension* GetInstalledApp(const GURL& url) const;
[email protected]d9696672011-03-15 22:45:09171
[email protected]ffb204f22010-12-05 23:20:27172 // Returns whether the URL is from either a hosted or packaged app.
[email protected]dc9a74f72012-08-17 18:07:21173 bool IsInstalledApp(const GURL& url) const;
[email protected]ffb204f22010-12-05 23:20:27174
[email protected]404fb002012-10-02 21:06:17175 // If the renderer is hosting an installed app with isolated storage,
176 // returns it, otherwise returns NULL.
177 const extensions::Extension* GetIsolatedAppForRenderer(
[email protected]dc9a74f72012-08-17 18:07:21178 int renderer_child_id) const;
[email protected]da5683db2011-04-23 17:12:21179
[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]6aeac8342010-10-01 20:21:18183 const std::string& extension_id);
184
[email protected]73c47932010-12-06 18:13:43185 // Constructor stores pointers to |profile| and |extension_prefs| but
186 // ownership remains at caller.
[email protected]eaa7dd182010-12-14 11:09:00187 ExtensionService(Profile* profile,
[email protected]a29a517a2011-01-21 21:11:12188 const CommandLine* command_line,
[email protected]650b2d52013-02-10 03:41:45189 const base::FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23190 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39191 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03192 bool autoupdate_enabled,
[email protected]4a10006a2013-05-17 23:18:35193 bool extensions_enabled,
194 extensions::OneShotEvent* ready);
[email protected]6014d672008-12-05 00:38:25195
[email protected]14908b72011-04-20 06:54:36196 virtual ~ExtensionService();
197
[email protected]6014d672008-12-05 00:38:25198 // Gets the list of currently installed extensions.
[email protected]84df8332011-12-06 18:22:46199 virtual const ExtensionSet* extensions() const OVERRIDE;
[email protected]c38fd352012-03-28 04:06:12200 virtual const ExtensionSet* disabled_extensions() const OVERRIDE;
[email protected]84df8332011-12-06 18:22:46201 const ExtensionSet* terminated_extensions() const;
[email protected]695b5712012-12-06 23:55:28202 const ExtensionSet* blacklisted_extensions() const;
[email protected]9e9c1d12013-07-31 01:58:12203 const ExtensionSet* delayed_installs() const;
[email protected]6014d672008-12-05 00:38:25204
[email protected]695b5712012-12-06 23:55:28205 // Returns a set of all installed, disabled, blacklisted, and terminated
206 // extensions.
207 scoped_ptr<const ExtensionSet> GenerateInstalledExtensionsSet() const;
[email protected]7f4308d2012-01-18 07:43:01208
[email protected]b2907fd2011-03-25 16:43:37209 // Gets the object managing the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41210 virtual extensions::PendingExtensionManager*
211 pending_extension_manager() OVERRIDE;
[email protected]aa142702010-03-26 01:26:33212
[email protected]650b2d52013-02-10 03:41:45213 const base::FilePath& install_directory() const { return install_directory_; }
[email protected]ec5b50d2010-10-09 16:35:18214
[email protected]6f371442011-11-09 06:45:46215 extensions::ProcessMap* process_map() { return &process_map_; }
216
[email protected]db7331a2010-02-25 22:10:50217 // Whether this extension can run in an incognito window.
[email protected]c3cfb012011-04-06 22:07:35218 virtual bool IsIncognitoEnabled(const std::string& extension_id) const;
219 virtual void SetIsIncognitoEnabled(const std::string& extension_id,
220 bool enabled);
[email protected]5ef47ec2010-01-28 05:58:05221
[email protected]168389f2011-12-20 17:12:48222 // Updates the app launcher value for the moved extension so that it is now
223 // located after the given predecessor and before the successor. This will
224 // trigger a sync if needed. Empty strings are used to indicate no successor
225 // or predecessor.
226 void OnExtensionMoved(const std::string& moved_extension_id,
227 const std::string& predecessor_extension_id,
228 const std::string& successor_extension_id);
229
[email protected]2a8f24e2010-11-03 21:37:05230 // Returns true if the given extension can see events and data from another
231 // sub-profile (incognito to original profile, or vice versa).
[email protected]dc9a74f72012-08-17 18:07:21232 bool CanCrossIncognito(const extensions::Extension* extension) const;
[email protected]2a8f24e2010-11-03 21:37:05233
[email protected]5ef7b002011-05-12 23:16:20234 // Returns true if the given extension can be loaded in incognito.
[email protected]1c321ee2012-05-21 03:02:34235 bool CanLoadInIncognito(const extensions::Extension* extension) const;
[email protected]5ef7b002011-05-12 23:16:20236
[email protected]05c82182010-06-24 17:49:08237 // Whether this extension can inject scripts into pages with file URLs.
[email protected]dc9a74f72012-08-17 18:07:21238 bool AllowFileAccess(const extensions::Extension* extension) const;
[email protected]3aff9ad2011-04-01 20:26:48239 // Will reload the extension since this permission is applied at loading time
240 // only.
[email protected]1c321ee2012-05-21 03:02:34241 void SetAllowFileAccess(const extensions::Extension* extension, bool allow);
[email protected]05c82182010-06-24 17:49:08242
[email protected]720ad1312012-02-27 23:07:36243 // Whether the persistent background page, if any, is ready. We don't load
244 // other components until then. If there is no background page, or if it is
245 // non-persistent (lazy), we consider it to be ready.
[email protected]dc9a74f72012-08-17 18:07:21246 bool IsBackgroundPageReady(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34247 void SetBackgroundPageReady(const extensions::Extension* extension);
[email protected]d7e9a862010-11-03 21:57:49248
249 // Getter and setter for the flag that specifies whether the extension is
250 // being upgraded.
[email protected]dc9a74f72012-08-17 18:07:21251 bool IsBeingUpgraded(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34252 void SetBeingUpgraded(const extensions::Extension* extension, bool value);
[email protected]d7e9a862010-11-03 21:57:49253
[email protected]e178ad92013-06-28 02:29:25254 // Getter and setter for the flag that specifies whether the extension is
255 // being reloaded.
256 bool IsBeingReloaded(const std::string& extension_name) const;
257 void SetBeingReloaded(const std::string& extension_id, bool value);
258
[email protected]39a5b532011-10-22 01:47:07259 // Getter and setter for the flag that specifies if the extension has used
260 // the webrequest API.
261 // TODO(mpcomplete): remove. http://crbug.com/100411
[email protected]dc9a74f72012-08-17 18:07:21262 bool HasUsedWebRequest(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34263 void SetHasUsedWebRequest(const extensions::Extension* extension, bool value);
[email protected]39a5b532011-10-22 01:47:07264
[email protected]6014d672008-12-05 00:38:25265 // Initialize and start all installed extensions.
[email protected]9f1087e2009-06-15 17:29:32266 void Init();
[email protected]6014d672008-12-05 00:38:25267
[email protected]c5ae74ab2010-04-15 18:14:37268 // Start up the extension event routers.
269 void InitEventRouters();
270
[email protected]47b896562012-08-22 23:55:15271 // Called when the associated Profile is going to be destroyed.
272 void Shutdown();
273
[email protected]695b5712012-12-06 23:55:28274 // Look up an extension by ID. Does not include terminated
[email protected]8001df22011-04-28 19:59:47275 // extensions.
[email protected]1c321ee2012-05-21 03:02:34276 virtual const extensions::Extension* GetExtensionById(
[email protected]b05fb9ff2011-04-23 00:07:56277 const std::string& id, bool include_disabled) const OVERRIDE;
[email protected]0c6da502009-08-14 22:32:39278
[email protected]695b5712012-12-06 23:55:28279 enum IncludeFlag {
280 INCLUDE_NONE = 0,
281 INCLUDE_ENABLED = 1 << 0,
282 INCLUDE_DISABLED = 1 << 1,
283 INCLUDE_TERMINATED = 1 << 2,
284 INCLUDE_BLACKLISTED = 1 << 3,
285 INCLUDE_EVERYTHING = (1 << 4) - 1,
286 };
287
288 // Look up an extension by ID, selecting which sets to look in:
289 // * extensions() --> INCLUDE_ENABLED
290 // * disabled_extensions() --> INCLUDE_DISABLED
291 // * terminated_extensions() --> INCLUDE_TERMINATED
292 // * blacklisted_extensions() --> INCLUDE_BLACKLISTED
293 const extensions::Extension* GetExtensionById(const std::string& id,
294 int include_mask) const;
295
[email protected]399583b2012-12-11 09:33:42296 // Returns the site of the given |extension_id|. Suitable for use with
297 // BrowserContext::GetStoragePartitionForSite().
298 GURL GetSiteForExtensionId(const std::string& extension_id);
299
[email protected]8001df22011-04-28 19:59:47300 // Looks up a terminated (crashed) extension by ID.
[email protected]1c321ee2012-05-21 03:02:34301 const extensions::Extension*
302 GetTerminatedExtension(const std::string& id) const;
[email protected]8001df22011-04-28 19:59:47303
304 // Looks up an extension by ID, regardless of whether it's enabled,
[email protected]695b5712012-12-06 23:55:28305 // disabled, blacklisted, or terminated.
[email protected]1c321ee2012-05-21 03:02:34306 virtual const extensions::Extension* GetInstalledExtension(
[email protected]8001df22011-04-28 19:59:47307 const std::string& id) const OVERRIDE;
[email protected]0dfe05c2011-02-23 23:03:36308
[email protected]e957fe52009-06-23 16:51:05309 // Updates a currently-installed extension with the contents from
[email protected]7577a5c52009-07-30 06:21:58310 // |extension_path|.
[email protected]2a464a92009-08-01 17:58:35311 // TODO(aa): This method can be removed. ExtensionUpdater could use
312 // CrxInstaller directly instead.
[email protected]420a0ec2011-06-01 01:07:03313 virtual bool UpdateExtension(
314 const std::string& id,
[email protected]650b2d52013-02-10 03:41:45315 const base::FilePath& extension_path,
[email protected]420a0ec2011-06-01 01:07:03316 const GURL& download_url,
[email protected]bf3d9df2012-07-24 23:20:27317 extensions::CrxInstaller** out_crx_installer) OVERRIDE;
[email protected]e957fe52009-06-23 16:51:05318
[email protected]2380c6b2013-01-09 02:33:13319 // Reloads the specified extension, sending the onLaunched() event to it if it
320 // currently has any window showing.
[email protected]e178ad92013-06-28 02:29:25321 void ReloadExtension(const std::string extension_id);
[email protected]9cddd4702009-07-27 22:09:40322
[email protected]631cf822009-05-15 07:01:25323 // Uninstalls the specified extension. Callers should only call this method
[email protected]17c4f3c2009-07-04 16:36:25324 // with extensions that exist. |external_uninstall| is a magical parameter
325 // that is only used to send information to ExtensionPrefs, which external
326 // callers should never set to true.
[email protected]a12c706e2011-12-01 00:58:08327 //
328 // We pass the |extension_id| by value to avoid having it deleted from under
329 // us incase someone calls it with Extension::id() or another string that we
330 // are going to delete in this function.
331 //
[email protected]17c4f3c2009-07-04 16:36:25332 // TODO(aa): Remove |external_uninstall| -- this information should be passed
333 // to ExtensionPrefs some other way.
[email protected]a12c706e2011-12-01 00:58:08334 virtual bool UninstallExtension(std::string extension_id,
[email protected]d6ebc9792011-04-07 18:18:33335 bool external_uninstall,
[email protected]65187152012-06-02 13:14:14336 string16* error);
[email protected]631cf822009-05-15 07:01:25337
[email protected]b05fb9ff2011-04-23 00:07:56338 virtual bool IsExtensionEnabled(
339 const std::string& extension_id) const OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35340 virtual bool IsExternalExtensionUninstalled(
[email protected]b05fb9ff2011-04-23 00:07:56341 const std::string& extension_id) const OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35342
[email protected]e2377032013-01-18 17:53:22343 // Whether the extension should show as enabled state in launcher.
344 bool IsExtensionEnabledForLauncher(const std::string& extension_id) const;
345
[email protected]06f92562011-04-29 19:27:31346 // Enables the extension. If the extension is already enabled, does
347 // nothing.
[email protected]2859946f2011-04-04 18:18:06348 virtual void EnableExtension(const std::string& extension_id);
[email protected]06f92562011-04-29 19:27:31349
350 // Disables the extension. If the extension is already disabled, or
351 // cannot be disabled, does nothing.
[email protected]44d62b62012-04-11 00:06:03352 virtual void DisableExtension(const std::string& extension_id,
[email protected]1c321ee2012-05-21 03:02:34353 extensions::Extension::DisableReason disable_reason);
[email protected]0c6da502009-08-14 22:32:39354
[email protected]3082fe32013-08-06 11:12:38355 // Disable non-default and non-managed extensions with ids not in
356 // |except_ids|. Default extensions are those from the Web Store with
357 // |was_installed_by_default| flag.
[email protected]1abf05e2013-07-09 17:04:36358 void DisableUserExtensions(const std::vector<std::string>& except_ids);
[email protected]e516e4c2013-06-12 17:41:14359
[email protected]8d888c12010-11-30 00:00:25360 // Updates the |extension|'s granted permissions lists to include all
[email protected]8d888c12010-11-30 00:00:25361 // permissions in the |extension|'s manifest and re-enables the
362 // extension.
[email protected]1c321ee2012-05-21 03:02:34363 void GrantPermissionsAndEnableExtension(
[email protected]009633c2013-03-07 22:08:28364 const extensions::Extension* extension);
[email protected]8d888c12010-11-30 00:00:25365
[email protected]be083862012-09-01 03:53:45366 // Updates the |extension|'s granted permissions lists to include all
367 // permissions in the |extensions|'s manifest.
368 void GrantPermissions(
[email protected]009633c2013-03-07 22:08:28369 const extensions::Extension* extension);
[email protected]be083862012-09-01 03:53:45370
[email protected]9f1087e2009-06-15 17:29:32371 // Check for updates (or potentially new extensions from external providers)
[email protected]93fd78f42009-07-10 16:43:17372 void CheckForExternalUpdates();
[email protected]9f1087e2009-06-15 17:29:32373
374 // Unload the specified extension.
[email protected]25ae0152011-11-18 14:40:02375 virtual void UnloadExtension(
376 const std::string& extension_id,
[email protected]1cc91fe2011-11-21 14:48:43377 extension_misc::UnloadedExtensionReason reason) OVERRIDE;
[email protected]9f1087e2009-06-15 17:29:32378
[email protected]57f71b92009-09-11 19:31:38379 // Unload all extensions. This is currently only called on shutdown, and
380 // does not send notifications.
[email protected]9f1087e2009-06-15 17:29:32381 void UnloadAllExtensions();
382
383 // Called only by testing.
384 void ReloadExtensions();
385
386 // Scan the extension directory and clean up the cruft.
387 void GarbageCollectExtensions();
388
[email protected]fb82dcd2012-03-21 14:15:46389 // Notifies Sync (if needed) of a newly-installed extension or a change to
390 // an existing extension.
[email protected]1c321ee2012-05-21 03:02:34391 virtual void SyncExtensionChangeIfNeeded(
392 const extensions::Extension& extension) OVERRIDE;
[email protected]fb82dcd2012-03-21 14:15:46393
[email protected]583d45c12010-08-31 02:48:12394 // Returns true if |url| should get extension api bindings and be permitted
395 // to make api calls. Note that this is independent of what extension
396 // permissions the given extension has been granted.
397 bool ExtensionBindingsAllowed(const GURL& url);
398
[email protected]4d007b312012-10-17 03:00:48399 // Returns true if a normal browser window should avoid showing |url| in a
400 // tab. In this case, |url| is also rewritten to an error URL.
401 bool ShouldBlockUrlInBrowserTab(GURL* url);
402
[email protected]c6d474f82009-12-16 21:11:06403 // Called when the initial extensions load has completed.
404 virtual void OnLoadedInstalledExtensions();
[email protected]7577a5c52009-07-30 06:21:58405
[email protected]bc151cf92013-02-12 04:57:26406 // Adds |extension| to this ExtensionService and notifies observers that the
407 // extensions have been loaded.
[email protected]1c321ee2012-05-21 03:02:34408 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE;
[email protected]7577a5c52009-07-30 06:21:58409
[email protected]8c484b742012-11-29 06:05:36410 // Check if we have preferences for the component extension and, if not or if
411 // the stored version differs, install the extension (without requirements
412 // checking) before calling AddExtension.
413 virtual void AddComponentExtension(const extensions::Extension* extension)
414 OVERRIDE;
415
[email protected]9f4e4f082013-06-21 07:11:19416 enum ImportStatus {
417 IMPORT_STATUS_OK,
418 IMPORT_STATUS_UNSATISFIED,
419 IMPORT_STATUS_UNRECOVERABLE
420 };
421
422 // Checks an extension's shared module imports to see if they are satisfied.
423 // If they are not, this function adds the dependencies to the pending install
424 // list if |extension| came from the webstore.
425 ImportStatus SatisfyImports(const extensions::Extension* extension);
426
427 // Returns a set of extensions that import a given extension.
428 scoped_ptr<const ExtensionSet> GetDependentExtensions(
429 const extensions::Extension* extension);
430
431 // Uninstalls shared modules that were only referenced by |extension|.
432 void PruneSharedModulesOnUninstall(const extensions::Extension* extension);
433
[email protected]bc151cf92013-02-12 04:57:26434 // Informs the service that an extension's files are in place for loading.
435 //
[email protected]9f3c8532013-07-31 19:52:07436 // |page_ordinal| is the location of the extension in the app launcher.
437 // |has_requirement_errors| is true if requirements of the extension weren't
438 // met (for example graphics capabilities).
439 // |blacklist_state| will be BLACKLISTED if the extension is blacklisted.
440 // |wait_for_idle| may be false to install the extension immediately.
[email protected]8266d662011-07-12 21:53:26441 void OnExtensionInstalled(
[email protected]1c321ee2012-05-21 03:02:34442 const extensions::Extension* extension,
[email protected]98270432012-09-11 20:51:24443 const syncer::StringOrdinal& page_ordinal,
[email protected]0db124b02012-11-07 04:55:05444 bool has_requirement_errors,
[email protected]9f3c8532013-07-31 19:52:07445 extensions::Blacklist::BlacklistState blacklist_state,
[email protected]0db124b02012-11-07 04:55:05446 bool wait_for_idle);
447
[email protected]9f4e4f082013-06-21 07:11:19448 // Checks for delayed installation for all pending installs.
449 void MaybeFinishDelayedInstallations();
450
[email protected]6f6101832012-11-27 22:10:48451 // Similar to FinishInstallation, but first checks if there still is an update
452 // pending for the extension, and makes sure the extension is still idle.
453 void MaybeFinishDelayedInstallation(const std::string& extension_id);
454
[email protected]0db124b02012-11-07 04:55:05455 // Finishes installation of an update for an extension with the specified id,
456 // when installation of that extension was previously delayed because the
457 // extension was in use.
[email protected]6f6101832012-11-27 22:10:48458 virtual void FinishDelayedInstallation(
459 const std::string& extension_id) OVERRIDE;
[email protected]7577a5c52009-07-30 06:21:58460
[email protected]76b65442012-11-17 14:11:48461 // Returns an update for an extension with the specified id, if installation
462 // of that update was previously delayed because the extension was in use. If
463 // no updates are pending for the extension returns NULL.
464 virtual const extensions::Extension* GetPendingExtensionUpdate(
465 const std::string& extension_id) const OVERRIDE;
466
[email protected]4ee07c62012-08-21 12:40:42467 // Go through each extension and unload those that are not allowed to run by
468 // management policy providers (ie. network admin and Google-managed
469 // blacklist).
470 virtual void CheckManagementPolicy() OVERRIDE;
[email protected]aa96d3a2010-08-21 08:45:25471
[email protected]b05fb9ff2011-04-23 00:07:56472 virtual void CheckForUpdatesSoon() OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35473
[email protected]65f173552012-06-28 22:43:58474 // syncer::SyncableService implementation.
[email protected]3f98fd92012-11-17 15:54:29475 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
[email protected]a4a147652012-07-03 23:41:32476 syncer::ModelType type,
[email protected]65f173552012-06-28 22:43:58477 const syncer::SyncDataList& initial_sync_data,
478 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
479 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE;
[email protected]a4a147652012-07-03 23:41:32480 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
[email protected]65f173552012-06-28 22:43:58481 virtual syncer::SyncDataList GetAllSyncData(
[email protected]a4a147652012-07-03 23:41:32482 syncer::ModelType type) const OVERRIDE;
[email protected]65f173552012-06-28 22:43:58483 virtual syncer::SyncError ProcessSyncChanges(
[email protected]3bdba0d2011-08-23 07:17:30484 const tracked_objects::Location& from_here,
[email protected]65f173552012-06-28 22:43:58485 const syncer::SyncChangeList& change_list) OVERRIDE;
[email protected]90310d92011-04-17 07:35:04486
[email protected]5db9ada2012-04-11 13:48:20487 // Gets the sync data for the given extension, assuming that the extension is
488 // syncable.
489 extensions::ExtensionSyncData GetExtensionSyncData(
[email protected]1c321ee2012-05-21 03:02:34490 const extensions::Extension& extension) const;
[email protected]5db9ada2012-04-11 13:48:20491
492 // Gets the sync data for the given app, assuming that the app is
493 // syncable.
[email protected]1c321ee2012-05-21 03:02:34494 extensions::AppSyncData GetAppSyncData(
495 const extensions::Extension& extension) const;
[email protected]5db9ada2012-04-11 13:48:20496
497 // Gets the ExtensionSyncData for all extensions.
498 std::vector<extensions::ExtensionSyncData> GetExtensionSyncDataList() const;
499
500 // Gets the AppSyncData for all extensions.
501 std::vector<extensions::AppSyncData> GetAppSyncDataList() const;
502
503 // Applies the change specified passed in by either ExtensionSyncData or
504 // AppSyncData to the current system.
505 // Returns false if the changes were not completely applied and were added
506 // to the pending list to be tried again.
507 bool ProcessExtensionSyncData(
508 const extensions::ExtensionSyncData& extension_sync_data);
509 bool ProcessAppSyncData(const extensions::AppSyncData& app_sync_data);
510
511
[email protected]7577a5c52009-07-30 06:21:58512 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
[email protected]abe7a8942009-06-23 05:14:29513 bool extensions_enabled() { return extensions_enabled_; }
514
[email protected]0e34d7892009-06-05 19:17:40515 void set_show_extensions_prompts(bool enabled) {
516 show_extensions_prompts_ = enabled;
[email protected]e2eb43112009-05-29 21:19:54517 }
518
[email protected]0e34d7892009-06-05 19:17:40519 bool show_extensions_prompts() {
520 return show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54521 }
522
[email protected]c3cfb012011-04-06 22:07:35523 Profile* profile();
[email protected]24e7a9d2009-11-04 11:11:34524
[email protected]c3cfb012011-04-06 22:07:35525 // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
526 // ExtensionPrefs* mutable_extension_prefs().
[email protected]45759612012-07-10 17:21:23527 extensions::ExtensionPrefs* extension_prefs();
[email protected]e81dba32009-06-19 20:19:13528
[email protected]0d9a2202011-11-09 13:48:41529 extensions::SettingsFrontend* settings_frontend();
[email protected]b7f853e282011-08-10 09:24:20530
[email protected]e2d720aa2012-05-17 00:11:35531 extensions::ContentSettingsStore* GetContentSettingsStore();
[email protected]b790b072011-05-20 09:46:44532
[email protected]3ecda252010-11-18 19:50:55533 // Whether the extension service is ready.
[email protected]25ae0152011-11-18 14:40:02534 virtual bool is_ready() OVERRIDE;
[email protected]3ecda252010-11-18 19:50:55535
[email protected]7f8f24f2012-11-15 19:40:14536 virtual base::SequencedTaskRunner* GetFileTaskRunner() OVERRIDE;
537
[email protected]d8c8f25f2011-11-02 18:18:01538 extensions::ComponentLoader* component_loader() {
539 return component_loader_.get();
540 }
541
[email protected]1fab8452009-09-03 02:23:39542 // Note that this may return NULL if autoupdate is not turned on.
[email protected]42a08162012-03-16 18:09:11543 extensions::ExtensionUpdater* updater();
[email protected]1fab8452009-09-03 02:23:39544
[email protected]e0360f2c2009-12-07 22:34:31545 ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; }
546
[email protected]d13950e2009-12-04 01:43:02547 ExtensionsQuotaService* quota_service() { return &quota_service_; }
548
[email protected]5aeeae12012-07-05 19:13:11549 extensions::MenuManager* menu_manager() { return &menu_manager_; }
[email protected]2e3b5202010-03-23 06:52:41550
[email protected]5a38dfd2012-07-23 23:22:10551 extensions::BrowserEventRouter* browser_event_router() {
[email protected]97d2f1d2011-01-15 00:41:08552 return browser_event_router_.get();
553 }
554
[email protected]d11c8e92009-10-20 23:26:40555 // Notify the frontend that there was an error loading an extension.
[email protected]d8c8f25f2011-11-02 18:18:01556 // This method is public because UnpackedInstaller and InstalledLoader
557 // can post to here.
558 // TODO(aa): Remove this. It doesn't do enough to be worth the dependency
559 // of these classes on ExtensionService.
[email protected]650b2d52013-02-10 03:41:45560 void ReportExtensionLoadError(const base::FilePath& extension_path,
[email protected]d11c8e92009-10-20 23:26:40561 const std::string& error,
[email protected]d11c8e92009-10-20 23:26:40562 bool be_noisy);
563
[email protected]406027c02010-09-27 08:03:18564 // ExtensionHost of background page calls this method right after its render
565 // view has been created.
[email protected]3a1dc572012-07-31 22:25:13566 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
[email protected]406027c02010-09-27 08:03:18567
[email protected]8e4560b62011-01-14 10:09:14568 // For the extension in |version_path| with |id|, check to see if it's an
569 // externally managed extension. If so, uninstall it.
570 void CheckExternalUninstall(const std::string& id);
571
[email protected]7f8f24f2012-11-15 19:40:14572 // Changes sequenced task runner for crx installation tasks to |task_runner|.
573 void SetFileTaskRunnerForTesting(base::SequencedTaskRunner* task_runner);
574
[email protected]5df038b2012-07-16 19:03:27575 // Clear all ExternalProviders.
[email protected]8e4560b62011-01-14 10:09:14576 void ClearProvidersForTesting();
577
[email protected]5df038b2012-07-16 19:03:27578 // Adds an ExternalProviderInterface for the service to use during testing.
579 // Takes ownership of |test_provider|.
580 void AddProviderForTesting(
581 extensions::ExternalProviderInterface* test_provider);
[email protected]8e4560b62011-01-14 10:09:14582
[email protected]5df038b2012-07-16 19:03:27583 // ExternalProvider::Visitor implementation.
[email protected]1c321ee2012-05-21 03:02:34584 virtual bool OnExternalExtensionFileFound(
585 const std::string& id,
[email protected]1f04ef42013-04-22 07:35:50586 const base::Version* version,
[email protected]650b2d52013-02-10 03:41:45587 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40588 extensions::Manifest::Location location,
[email protected]1c321ee2012-05-21 03:02:34589 int creation_flags,
590 bool mark_acknowledged) OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:14591
[email protected]1c321ee2012-05-21 03:02:34592 virtual bool OnExternalExtensionUpdateUrlFound(
593 const std::string& id,
594 const GURL& update_url,
[email protected]1d5e58b2013-01-31 08:41:40595 extensions::Manifest::Location location) OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:14596
[email protected]50067e52011-10-20 23:17:07597 virtual void OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:27598 const extensions::ExternalProviderInterface* provider) OVERRIDE;
[email protected]50067e52011-10-20 23:17:07599
[email protected]94fde232012-04-27 10:22:30600 // Returns true when all the external extension providers are ready.
601 bool AreAllExternalProvidersReady() const;
602
[email protected]50067e52011-10-20 23:17:07603 void OnAllExternalProvidersReady();
[email protected]8e4560b62011-01-14 10:09:14604
[email protected]62433d32011-10-12 22:33:12605 // Once all external providers are done, generates any needed alerts about
[email protected]e5af875f2011-10-10 21:09:14606 // extensions.
607 void IdentifyAlertableExtensions();
608
[email protected]89226982012-07-16 20:09:18609 // Given an ExtensionErrorUI alert, populates it with any extensions that
[email protected]07c9f2f42012-02-29 18:45:22610 // need alerting. Returns true if the alert should be displayed at all.
611 //
[email protected]89226982012-07-16 20:09:18612 // This method takes the extension_error_ui argument rather than using
[email protected]07c9f2f42012-02-29 18:45:22613 // the member variable to make it easier to test the method in isolation.
[email protected]89226982012-07-16 20:09:18614 bool PopulateExtensionErrorUI(ExtensionErrorUI* extension_error_ui);
[email protected]07c9f2f42012-02-29 18:45:22615
[email protected]612a1cb12012-10-17 13:18:03616 // Checks if there are any new external extensions to notify the user about.
617 void UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:14618
[email protected]47fc70c2011-12-06 07:29:51619 // Given a (presumably just-installed) extension id, mark that extension as
620 // acknowledged.
621 void AcknowledgeExternalExtension(const std::string& id);
622
[email protected]d96eb512012-11-01 23:44:08623 // Returns true if this extension is an external one that has yet to be
624 // marked as acknowledged.
625 bool IsUnacknowledgedExternalExtension(
626 const extensions::Extension* extension);
627
[email protected]62433d32011-10-12 22:33:12628 // Opens the Extensions page because the user wants to get more details
629 // about the alerts.
[email protected]89226982012-07-16 20:09:18630 void HandleExtensionAlertDetails();
[email protected]62433d32011-10-12 22:33:12631
[email protected]73a85e012013-04-04 10:45:30632 // Called when the extension alert is closed. Updates prefs and deletes
633 // the active |extension_error_ui_|.
[email protected]a9aa5932012-01-25 08:27:40634 void HandleExtensionAlertClosed();
[email protected]e5af875f2011-10-10 21:09:14635
[email protected]612a1cb12012-10-17 13:18:03636 // Marks alertable extensions as acknowledged, after the user presses the
637 // accept button.
638 void HandleExtensionAlertAccept();
639
[email protected]6c2381d2011-10-19 02:52:53640 // content::NotificationObserver
[email protected]432115822011-07-10 15:52:27641 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53642 const content::NotificationSource& source,
643 const content::NotificationDetails& details) OVERRIDE;
[email protected]4814b512009-11-07 00:12:29644
[email protected]ec5b50d2010-10-09 16:35:18645 // Whether there are any apps installed. Component apps are not included.
646 bool HasApps() const;
647
648 // Gets the set of loaded app ids. Component apps are not included.
[email protected]1c321ee2012-05-21 03:02:34649 extensions::ExtensionIdSet GetAppIds() const;
[email protected]377011d2010-07-20 04:18:50650
[email protected]fe2dd7742011-04-19 22:52:49651 // Record a histogram using the PermissionMessage enum values for each
652 // permission in |e|.
653 // NOTE: If this is ever called with high frequency, the implementation may
654 // need to be made more efficient.
655 static void RecordPermissionMessagesHistogram(
[email protected]1c321ee2012-05-21 03:02:34656 const extensions::Extension* e, const char* histogram);
[email protected]fe2dd7742011-04-19 22:52:49657
[email protected]65992d52012-09-19 23:05:31658 // Open a dev tools window for the background page for the given extension,
[email protected]07ad9622013-01-18 23:00:33659 // starting the background page first if necessary.
[email protected]65992d52012-09-19 23:05:31660 void InspectBackgroundPage(const extensions::Extension* extension);
661
[email protected]fa2416f2011-05-03 08:41:20662#if defined(UNIT_TEST)
[email protected]1c321ee2012-05-21 03:02:34663 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
[email protected]fa2416f2011-05-03 08:41:20664 TrackTerminatedExtension(extension);
665 }
[email protected]a51c9e92012-12-09 09:19:20666
667 void FinishInstallationForTest(const extensions::Extension* extension) {
668 FinishInstallation(extension);
669 }
[email protected]fa2416f2011-05-03 08:41:20670#endif
671
[email protected]65f173552012-06-28 22:43:58672 // Specialization of syncer::SyncableService::AsWeakPtr.
[email protected]77e4dc0882012-06-20 18:53:50673 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
674
[email protected]3c4abc82012-10-22 22:25:54675 bool browser_terminating() const { return browser_terminating_; }
676
677 // For testing.
678 void set_browser_terminating_for_test(bool value) {
679 browser_terminating_ = value;
680 }
681
[email protected]fc332ae2012-11-14 20:17:33682 // By default ExtensionService will wait with installing an updated extension
683 // until the extension is idle. Tests might not like this behavior, so you can
684 // disable it with this method.
685 void set_install_updates_when_idle_for_test(bool value) {
686 install_updates_when_idle_ = value;
687 }
688
[email protected]75bdcb872013-03-13 00:41:45689 // Adds/Removes update observers.
690 void AddUpdateObserver(extensions::UpdateObserver* observer);
691 void RemoveUpdateObserver(extensions::UpdateObserver* observer);
692
[email protected]6d147912013-07-09 08:02:14693 // |flare| provides a StartSyncFlare to the SyncableService. See
694 // sync_start_util for more.
695 void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare);
696
[email protected]14908b72011-04-20 06:54:36697 private:
[email protected]d7e9a862010-11-03 21:57:49698 // Contains Extension data that can change during the life of the process,
699 // but does not persist across restarts.
700 struct ExtensionRuntimeData {
701 // True if the background page is ready.
702 bool background_page_ready;
703
704 // True while the extension is being upgraded.
705 bool being_upgraded;
706
[email protected]39a5b532011-10-22 01:47:07707 // True if the extension has used the webRequest API.
708 bool has_used_webrequest;
709
[email protected]d7e9a862010-11-03 21:57:49710 ExtensionRuntimeData();
711 ~ExtensionRuntimeData();
712 };
713 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap;
714
[email protected]4a10006a2013-05-17 23:18:35715 // Signals *ready_ and sends a notification to the listeners.
[email protected]820d9bd2013-04-03 03:46:03716 void SetReadyAndNotifyListeners();
717
[email protected]5db9ada2012-04-11 13:48:20718 // Return true if the sync type of |extension| matches |type|.
[email protected]1c321ee2012-05-21 03:02:34719 bool IsCorrectSyncType(const extensions::Extension& extension,
[email protected]a4a147652012-07-03 23:41:32720 syncer::ModelType type)
[email protected]3bdba0d2011-08-23 07:17:30721 const;
722
[email protected]90bb38d2012-11-14 18:36:03723 void OnExtensionInstallPrefChanged();
724
[email protected]5db9ada2012-04-11 13:48:20725 // Handles setting the extension specific values in |extension_sync_data| to
726 // the current system.
727 // Returns false if the changes were not completely applied and need to be
728 // tried again later.
729 bool ProcessExtensionSyncDataHelper(
730 const extensions::ExtensionSyncData& extension_sync_data,
[email protected]a4a147652012-07-03 23:41:32731 syncer::ModelType type);
[email protected]3bdba0d2011-08-23 07:17:30732
[email protected]fa2416f2011-05-03 08:41:20733 // Adds the given extension to the list of terminated extensions if
734 // it is not already there and unloads it.
[email protected]1c321ee2012-05-21 03:02:34735 void TrackTerminatedExtension(const extensions::Extension* extension);
[email protected]fa2416f2011-05-03 08:41:20736
737 // Removes the extension with the given id from the list of
738 // terminated extensions if it is there.
[email protected]bb7f40952011-01-13 00:21:20739 void UntrackTerminatedExtension(const std::string& id);
740
[email protected]8c484b742012-11-29 06:05:36741 // Update preferences for a new or updated extension; notify observers that
742 // the extension is installed, e.g., to update event handlers on background
743 // pages; and perform other extension install tasks before calling
744 // AddExtension.
[email protected]9f3c8532013-07-31 19:52:07745 void AddNewOrUpdatedExtension(
746 const extensions::Extension* extension,
747 extensions::Extension::State initial_state,
748 extensions::Blacklist::BlacklistState blacklist_state,
749 const syncer::StringOrdinal& page_ordinal);
[email protected]8c484b742012-11-29 06:05:36750
[email protected]62d30f42009-10-01 22:36:06751 // Handles sending notification that |extension| was loaded.
[email protected]1c321ee2012-05-21 03:02:34752 void NotifyExtensionLoaded(const extensions::Extension* extension);
[email protected]62d30f42009-10-01 22:36:06753
754 // Handles sending notification that |extension| was unloaded.
[email protected]1c321ee2012-05-21 03:02:34755 void NotifyExtensionUnloaded(const extensions::Extension* extension,
[email protected]814a7bf0f2011-08-13 05:30:59756 extension_misc::UnloadedExtensionReason reason);
[email protected]62d30f42009-10-01 22:36:06757
[email protected]6f6101832012-11-27 22:10:48758 // Common helper to finish installing the given extension.
759 void FinishInstallation(const extensions::Extension* extension);
760
[email protected]b914e2952013-04-26 07:10:03761 // Updates the |extension|'s active permission set to include only permissions
762 // currently requested by the extension and all the permissions required by
763 // the extension.
764 void UpdateActivePermissions(const extensions::Extension* extension);
765
766 // Disables the extension if the privilege level has increased
767 // (e.g., due to an upgrade).
768 void CheckPermissionsIncrease(const extensions::Extension* extension,
769 bool is_upgrade);
770
[email protected]aab98a52009-12-02 03:22:35771 // Helper that updates the active extension list used for crash reporting.
772 void UpdateActiveExtensionsInCrashReporter();
773
[email protected]65992d52012-09-19 23:05:31774 // Helper to inspect an ExtensionHost after it has been loaded.
775 void InspectExtensionHost(extensions::ExtensionHost* host);
776
[email protected]612a1cb12012-10-17 13:18:03777 // Helper to determine whether we should initially enable an installed
778 // (or upgraded) extension.
779 bool ShouldEnableOnInstall(const extensions::Extension* extension);
780
[email protected]0db124b02012-11-07 04:55:05781 // Helper to determine if an extension is idle, and it should be safe
782 // to update the extension.
783 bool IsExtensionIdle(const std::string& extension_id) const;
784
[email protected]e7aa7b7e2012-11-27 04:51:22785 // Helper to determine if updating an extensions should proceed immediately,
786 // or if we should delay the update until further notice.
787 bool ShouldDelayExtensionUpdate(const std::string& extension_id,
788 bool wait_for_idle) const;
789
[email protected]399583b2012-12-11 09:33:42790 // Helper to search storage directories for extensions with isolated storage
791 // that have been orphaned by an uninstall.
792 void GarbageCollectIsolatedStorage();
793 void OnGarbageCollectIsolatedStorageFinished();
794 void OnNeedsToGarbageCollectIsolatedStorage();
795
[email protected]fdd679b2012-11-15 20:49:39796 // extensions::Blacklist::Observer implementation.
797 virtual void OnBlacklistUpdated() OVERRIDE;
798
[email protected]695b5712012-12-06 23:55:28799 // Manages the blacklisted extensions, intended as callback from
800 // Blacklist::GetBlacklistedIDs.
801 void ManageBlacklist(const std::set<std::string>& old_blacklisted_ids,
802 const std::set<std::string>& new_blacklisted_ids);
803
[email protected]9f4e4f082013-06-21 07:11:19804 // Controls if installs are delayed. See comment for
805 // |installs_delayed_for_gc_|.
806 void set_installs_delayed_for_gc(bool value) {
807 installs_delayed_for_gc_ = value;
808 }
809 bool installs_delayed_for_gc() const { return installs_delayed_for_gc_; }
[email protected]399583b2012-12-11 09:33:42810
[email protected]31d8f5f22012-04-02 15:22:08811 // The normal profile associated with this ExtensionService.
[email protected]6ef635e42009-07-26 06:16:12812 Profile* profile_;
813
[email protected]31d8f5f22012-04-02 15:22:08814 // The ExtensionSystem for the profile above.
[email protected]bd306722012-07-11 20:43:59815 extensions::ExtensionSystem* system_;
[email protected]31d8f5f22012-04-02 15:22:08816
[email protected]695b5712012-12-06 23:55:28817 // Preferences for the owning profile.
[email protected]45759612012-07-10 17:21:23818 extensions::ExtensionPrefs* extension_prefs_;
[email protected]894bb502009-05-21 22:39:57819
[email protected]695b5712012-12-06 23:55:28820 // Blacklist for the owning profile.
821 extensions::Blacklist* blacklist_;
822
[email protected]adfc5462011-09-21 19:07:13823 // Settings for the owning profile.
[email protected]cccdf0aa2011-11-11 03:43:38824 scoped_ptr<extensions::SettingsFrontend> settings_frontend_;
[email protected]b7f853e282011-08-10 09:24:20825
[email protected]6014d672008-12-05 00:38:25826 // The current list of installed extensions.
[email protected]84df8332011-12-06 18:22:46827 ExtensionSet extensions_;
[email protected]6014d672008-12-05 00:38:25828
[email protected]0c6da502009-08-14 22:32:39829 // The list of installed extensions that have been disabled.
[email protected]84df8332011-12-06 18:22:46830 ExtensionSet disabled_extensions_;
[email protected]0c6da502009-08-14 22:32:39831
[email protected]bb7f40952011-01-13 00:21:20832 // The list of installed extensions that have been terminated.
[email protected]84df8332011-12-06 18:22:46833 ExtensionSet terminated_extensions_;
[email protected]bb7f40952011-01-13 00:21:20834
[email protected]695b5712012-12-06 23:55:28835 // The list of installed extensions that have been blacklisted. Generally
836 // these shouldn't be considered as installed by the extension platform: we
837 // only keep them around so that if extensions are blacklisted by mistake
838 // they can easily be un-blacklisted.
839 ExtensionSet blacklisted_extensions_;
840
[email protected]9f4e4f082013-06-21 07:11:19841 // The list of extension installs delayed for various reasons. The reason
842 // for delayed install is stored in ExtensionPrefs.
[email protected]399583b2012-12-11 09:33:42843 ExtensionSet delayed_installs_;
[email protected]0db124b02012-11-07 04:55:05844
[email protected]b2907fd2011-03-25 16:43:37845 // Hold the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41846 extensions::PendingExtensionManager pending_extension_manager_;
[email protected]aa142702010-03-26 01:26:33847
[email protected]d7e9a862010-11-03 21:57:49848 // The map of extension IDs to their runtime data.
849 ExtensionRuntimeDataMap extension_runtime_data_;
850
[email protected]6014d672008-12-05 00:38:25851 // The full path to the directory where extensions are installed.
[email protected]650b2d52013-02-10 03:41:45852 base::FilePath install_directory_;
[email protected]6014d672008-12-05 00:38:25853
[email protected]e2eb43112009-05-29 21:19:54854 // Whether or not extensions are enabled.
855 bool extensions_enabled_;
856
[email protected]0e34d7892009-06-05 19:17:40857 // Whether to notify users when they attempt to install an extension.
858 bool show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54859
[email protected]fc332ae2012-11-14 20:17:33860 // Whether to delay installing of extension updates until the extension is
861 // idle.
862 bool install_updates_when_idle_;
863
[email protected]d13950e2009-12-04 01:43:02864 // Used by dispatchers to limit API quota for individual extensions.
865 ExtensionsQuotaService quota_service_;
866
[email protected]4a10006a2013-05-17 23:18:35867 // Signaled when all extensions are loaded.
868 extensions::OneShotEvent* const ready_;
[email protected]e81dba32009-06-19 20:19:13869
[email protected]93fd78f42009-07-10 16:43:17870 // Our extension updater, if updates are turned on.
[email protected]42a08162012-03-16 18:09:11871 scoped_ptr<extensions::ExtensionUpdater> updater_;
[email protected]93fd78f42009-07-10 16:43:17872
[email protected]e0360f2c2009-12-07 22:34:31873 // The model that tracks extensions with BrowserAction buttons.
874 ExtensionToolbarModel toolbar_model_;
875
[email protected]1eb175082010-02-10 09:26:16876 // Map unloaded extensions' ids to their paths. When a temporarily loaded
[email protected]5fb889382011-06-03 00:29:20877 // extension is unloaded, we lose the information about it and don't have
[email protected]1eb175082010-02-10 09:26:16878 // any in the extension preferences file.
[email protected]650b2d52013-02-10 03:41:45879 typedef std::map<std::string, base::FilePath> UnloadedExtensionPathMap;
[email protected]1eb175082010-02-10 09:26:16880 UnloadedExtensionPathMap unloaded_extension_paths_;
881
[email protected]b914e2952013-04-26 07:10:03882 // Store the ids of reloading extensions.
883 std::set<std::string> reloading_extensions_;
[email protected]f17dbd42010-08-16 23:21:10884
[email protected]04ea1bb2013-07-10 09:26:09885 // Map of DevToolsAgentHost instances that are detached,
886 // waiting for an extension to be reloaded.
887 typedef std::map<std::string, scoped_refptr<content::DevToolsAgentHost> >
888 OrphanedDevTools;
[email protected]4814b512009-11-07 00:12:29889 OrphanedDevTools orphaned_dev_tools_;
890
[email protected]6c2381d2011-10-19 02:52:53891 content::NotificationRegistrar registrar_;
[email protected]2fb7dc982010-09-29 12:24:28892 PrefChangeRegistrar pref_change_registrar_;
[email protected]4814b512009-11-07 00:12:29893
[email protected]d8c8f25f2011-11-02 18:18:01894 // Keeps track of loading and unloading component extensions.
895 scoped_ptr<extensions::ComponentLoader> component_loader_;
896
[email protected]2e3b5202010-03-23 06:52:41897 // Keeps track of menu items added by extensions.
[email protected]5aeeae12012-07-05 19:13:11898 extensions::MenuManager menu_manager_;
[email protected]2e3b5202010-03-23 06:52:41899
[email protected]b3d62312b12010-10-14 21:10:18900 // Flag to make sure event routers are only initialized once.
901 bool event_routers_initialized_;
902
[email protected]c4dc5cc2012-11-09 08:48:39903 // TODO(yoz): None of these should be owned by ExtensionService.
904 // crbug.com/159265
[email protected]5a38dfd2012-07-23 23:22:10905 scoped_ptr<extensions::BrowserEventRouter> browser_event_router_;
[email protected]da55b8d2011-05-26 00:09:49906
[email protected]8e4560b62011-01-14 10:09:14907 // A collection of external extension providers. Each provider reads
908 // a source of external extension information. Examples include the
909 // windows registry and external_extensions.json.
[email protected]5df038b2012-07-16 19:03:27910 extensions::ProviderCollection external_extension_providers_;
[email protected]8e4560b62011-01-14 10:09:14911
912 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
[email protected]94fde232012-04-27 10:22:30913 // extension URL is found, and by CheckForUpdatesSoon() when an update check
914 // has to wait for the external providers. Used in
915 // OnAllExternalProvidersReady() to determine if an update check is needed to
916 // install pending extensions.
917 bool update_once_all_providers_are_ready_;
[email protected]8e4560b62011-01-14 10:09:14918
[email protected]3c4abc82012-10-22 22:25:54919 // Set when the browser is terminating. Prevents us from installing or
920 // updating additional extensions and allows in-progress installations to
921 // decide to abort.
922 bool browser_terminating_;
923
[email protected]9f4e4f082013-06-21 07:11:19924 // Set to true to delay all new extension installations. Acts as a lock to
925 // allow background processing of garbage collection of on-disk state without
926 // needing to worry about race conditions caused by extension installation and
927 // reinstallation.
928 bool installs_delayed_for_gc_;
[email protected]399583b2012-12-11 09:33:42929
[email protected]460c6712013-04-24 07:20:01930 // Set to true if this is the first time this ExtensionService has run.
931 // Used for specially handling external extensions that are installed the
932 // first time.
933 bool is_first_run_;
934
[email protected]5db9ada2012-04-11 13:48:20935 extensions::AppSyncBundle app_sync_bundle_;
936 extensions::ExtensionSyncBundle extension_sync_bundle_;
[email protected]3bdba0d2011-08-23 07:17:30937
[email protected]6f371442011-11-09 06:45:46938 extensions::ProcessMap process_map_;
939
[email protected]e178ad92013-06-28 02:29:25940 // A set of the extension ids currently being reloaded. We use this to
941 // avoid showing a "new install" notice for an extension reinstall.
942 std::set<std::string> extensions_being_reloaded_;
943
[email protected]89226982012-07-16 20:09:18944 scoped_ptr<ExtensionErrorUI> extension_error_ui_;
[email protected]7f8f24f2012-11-15 19:40:14945 // Sequenced task runner for extension related file operations.
946 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
[email protected]a9aa5932012-01-25 08:27:40947
[email protected]9ce11d22012-08-08 23:20:13948#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58949 scoped_ptr<extensions::ExtensionActionStorageManager>
950 extension_action_storage_manager_;
[email protected]9ce11d22012-08-08 23:20:13951#endif
[email protected]c77f2352012-08-08 22:07:58952
[email protected]75bdcb872013-03-13 00:41:45953 ObserverList<extensions::UpdateObserver, true> update_observers_;
954
[email protected]6d147912013-07-09 08:02:14955 // Run()ning tells sync to try and start soon, because syncable changes
956 // have started happening. It will cause sync to call us back
957 // asynchronously via MergeDataAndStartSyncing as soon as possible.
958 syncer::SyncableService::StartSyncFlare flare_;
959
[email protected]eaa7dd182010-12-14 11:09:00960 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]c2c263c2010-08-13 21:59:48961 InstallAppsWithUnlimtedStorage);
[email protected]eaa7dd182010-12-14 11:09:00962 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]654512b2010-09-01 02:09:42963 InstallAppsAndCheckStorageProtection);
[email protected]eaa7dd182010-12-14 11:09:00964 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
[email protected]6014d672008-12-05 00:38:25965};
966
[email protected]eaa7dd182010-12-14 11:09:00967#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_