blob: 8fc0081163175bc4ae4f4bc70c7e36d578760a05 [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]c51225632011-11-11 21:40:378#include <list>
[email protected]da50530a2009-06-15 17:43:019#include <map>
[email protected]31bb5ee62012-09-12 22:58:4010#include <set>
[email protected]b0beaa662009-02-26 00:04:1511#include <string>
[email protected]6014d672008-12-05 00:38:2512#include <vector>
13
[email protected]e0785902011-05-19 23:34:1714#include "base/compiler_specific.h"
[email protected]6014d672008-12-05 00:38:2515#include "base/file_path.h"
[email protected]a918f872010-06-01 14:30:5116#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1517#include "base/memory/ref_counted.h"
[email protected]14908b72011-04-20 06:54:3618#include "base/memory/weak_ptr.h"
[email protected]03b9b4e2012-10-22 20:01:5219#include "base/prefs/public/pref_change_registrar.h"
[email protected]65187152012-06-02 13:14:1420#include "base/string16.h"
[email protected]178f8512012-02-09 01:49:3621#include "chrome/browser/extensions/app_shortcut_manager.h"
[email protected]5db9ada2012-04-11 13:48:2022#include "chrome/browser/extensions/app_sync_bundle.h"
[email protected]fdd679b2012-11-15 20:49:3923#include "chrome/browser/extensions/blacklist.h"
[email protected]b671760b2010-07-15 21:13:4724#include "chrome/browser/extensions/extension_icon_manager.h"
[email protected]c38831a12011-10-28 12:44:4925#include "chrome/browser/extensions/extension_prefs.h"
[email protected]c6e4a3412009-06-24 15:45:2926#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]5db9ada2012-04-11 13:48:2027#include "chrome/browser/extensions/extension_sync_bundle.h"
[email protected]e0360f2c2009-12-07 22:34:3128#include "chrome/browser/extensions/extension_toolbar_model.h"
[email protected]d13950e2009-12-04 01:43:0229#include "chrome/browser/extensions/extensions_quota_service.h"
[email protected]5df038b2012-07-16 19:03:2730#include "chrome/browser/extensions/external_provider_interface.h"
[email protected]5aeeae12012-07-05 19:13:1131#include "chrome/browser/extensions/menu_manager.h"
[email protected]b2907fd2011-03-25 16:43:3732#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]6f371442011-11-09 06:45:4633#include "chrome/browser/extensions/process_map.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]6c2381d2011-10-19 02:52:5337#include "content/public/browser/notification_observer.h"
38#include "content/public/browser/notification_registrar.h"
[email protected]36b643212012-09-07 12:53:0039#include "sync/api/string_ordinal.h"
[email protected]895a1e52012-05-15 02:50:1240#include "sync/api/sync_change.h"
41#include "sync/api/syncable_service.h"
[email protected]6014d672008-12-05 00:38:2542
[email protected]23d5f172011-10-25 05:49:5343class BookmarkExtensionEventRouter;
[email protected]dc9a74f72012-08-17 18:07:2144class CommandLine;
[email protected]89226982012-07-16 20:09:1845class ExtensionErrorUI;
[email protected]3bdba0d2011-08-23 07:17:3046class ExtensionSyncData;
[email protected]e0360f2c2009-12-07 22:34:3147class ExtensionToolbarModel;
[email protected]d8c8f25f2011-11-02 18:18:0148class HistoryExtensionEventRouter;
[email protected]69f1be82009-04-16 22:27:2149class GURL;
[email protected]81e63782009-02-27 19:35:0950class Profile;
[email protected]aa142702010-03-26 01:26:3351class Version;
52
[email protected]7f8f24f2012-11-15 19:40:1453namespace base {
54class SequencedTaskRunner;
55}
56
[email protected]771a6182011-10-05 16:32:5257namespace chromeos {
58class ExtensionInputMethodEventRouter;
[email protected]d8c8f25f2011-11-02 18:18:0159}
60
[email protected]9c70e0d92012-07-16 08:39:4461namespace extensions {
[email protected]8d92e0382012-08-01 18:06:5262class AppNotificationManager;
[email protected]5db9ada2012-04-11 13:48:2063class AppSyncData;
[email protected]5a38dfd2012-07-23 23:22:1064class BrowserEventRouter;
[email protected]d8c8f25f2011-11-02 18:18:0165class ComponentLoader;
[email protected]e2d720aa2012-05-17 00:11:3566class ContentSettingsStore;
[email protected]bf3d9df2012-07-24 23:20:2767class CrxInstaller;
[email protected]1c321ee2012-05-21 03:02:3468class Extension;
[email protected]c77f2352012-08-08 22:07:5869class ExtensionActionStorageManager;
[email protected]92ba7b012012-05-16 03:36:1770class ExtensionCookiesEventRouter;
[email protected]163ed192012-07-24 19:31:0771class ExtensionManagedModeEventRouter;
[email protected]5db9ada2012-04-11 13:48:2072class ExtensionSyncData;
[email protected]bd306722012-07-11 20:43:5973class ExtensionSystem;
[email protected]42a08162012-03-16 18:09:1174class ExtensionUpdater;
[email protected]31bb5ee62012-09-12 22:58:4075class MediaGalleriesPrivateEventRouter;
[email protected]3f213ad2012-07-26 23:39:4176class PendingExtensionManager;
[email protected]135e4782012-09-19 20:36:5277class PreferenceEventRouter;
[email protected]31bb5ee62012-09-12 22:58:4078class PushMessagingEventRouter;
[email protected]cccdf0aa2011-11-11 03:43:3879class SettingsFrontend;
[email protected]017ecde92012-04-04 09:11:2680class WebNavigationEventRouter;
[email protected]163ed192012-07-24 19:31:0781class WindowEventRouter;
82}
83
84namespace syncer {
[email protected]163ed192012-07-24 19:31:0785class SyncErrorFactory;
[email protected]d8c8f25f2011-11-02 18:18:0186}
[email protected]771a6182011-10-05 16:32:5287
[email protected]d1ca0ed12009-07-01 18:24:3288// This is an interface class to encapsulate the dependencies that
[email protected]2859946f2011-04-04 18:18:0689// various classes have on ExtensionService. This allows easy mocking.
[email protected]65f173552012-06-28 22:43:5890class ExtensionServiceInterface : public syncer::SyncableService {
[email protected]d1ca0ed12009-07-01 18:24:3291 public:
[email protected]b05fb9ff2011-04-23 00:07:5692 // A function that returns true if the given extension should be
93 // included and false if it should be filtered out. Identical to
94 // PendingExtensionInfo::ShouldAllowInstallPredicate.
[email protected]1c321ee2012-05-21 03:02:3495 typedef bool (*ExtensionFilter)(const extensions::Extension&);
[email protected]b05fb9ff2011-04-23 00:07:5696
[email protected]2859946f2011-04-04 18:18:0697 virtual ~ExtensionServiceInterface() {}
[email protected]84df8332011-12-06 18:22:4698 virtual const ExtensionSet* extensions() const = 0;
[email protected]c38fd352012-03-28 04:06:1299 virtual const ExtensionSet* disabled_extensions() const = 0;
[email protected]3f213ad2012-07-26 23:39:41100 virtual extensions::PendingExtensionManager* pending_extension_manager() = 0;
[email protected]420a0ec2011-06-01 01:07:03101
102 // Install an update. Return true if the install can be started.
103 // Set out_crx_installer to the installer if one was started.
104 virtual bool UpdateExtension(
105 const std::string& id,
106 const FilePath& path,
107 const GURL& download_url,
[email protected]bf3d9df2012-07-24 23:20:27108 extensions::CrxInstaller** out_crx_installer) = 0;
[email protected]1c321ee2012-05-21 03:02:34109 virtual const extensions::Extension* GetExtensionById(const std::string& id,
[email protected]b2907fd2011-03-25 16:43:37110 bool include_disabled) const = 0;
[email protected]1c321ee2012-05-21 03:02:34111 virtual const extensions::Extension* GetInstalledExtension(
[email protected]8001df22011-04-28 19:59:47112 const std::string& id) const = 0;
[email protected]2859946f2011-04-04 18:18:06113
[email protected]76b65442012-11-17 14:11:48114 virtual const extensions::Extension* GetPendingExtensionUpdate(
115 const std::string& extension_id) const = 0;
[email protected]6f6101832012-11-27 22:10:48116 virtual void FinishDelayedInstallation(const std::string& extension_id) = 0;
[email protected]76b65442012-11-17 14:11:48117
[email protected]c3cfb012011-04-06 22:07:35118 virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
119 virtual bool IsExternalExtensionUninstalled(
120 const std::string& extension_id) const = 0;
[email protected]2859946f2011-04-04 18:18:06121
[email protected]4ee07c62012-08-21 12:40:42122 virtual void CheckManagementPolicy() = 0;
[email protected]5ef47ec2010-01-28 05:58:05123
[email protected]31206602011-04-13 23:07:32124 // Safe to call multiple times in a row.
125 //
[email protected]90310d92011-04-17 07:35:04126 // TODO(akalin): Remove this method (and others) once we refactor
127 // themes sync to not use it directly.
[email protected]31206602011-04-13 23:07:32128 virtual void CheckForUpdatesSoon() = 0;
[email protected]25ae0152011-11-18 14:40:02129
[email protected]1c321ee2012-05-21 03:02:34130 virtual void AddExtension(const extensions::Extension* extension) = 0;
[email protected]8c484b742012-11-29 06:05:36131 virtual void AddComponentExtension(
132 const extensions::Extension* extension) = 0;
[email protected]25ae0152011-11-18 14:40:02133
134 virtual void UnloadExtension(
135 const std::string& extension_id,
136 extension_misc::UnloadedExtensionReason reason) = 0;
137
[email protected]1c321ee2012-05-21 03:02:34138 virtual void SyncExtensionChangeIfNeeded(
139 const extensions::Extension& extension) = 0;
[email protected]fb82dcd2012-03-21 14:15:46140
[email protected]25ae0152011-11-18 14:40:02141 virtual bool is_ready() = 0;
[email protected]7f8f24f2012-11-15 19:40:14142
143 // Returns task runner for crx installation file I/O operations.
144 virtual base::SequencedTaskRunner* GetFileTaskRunner() = 0;
[email protected]d1ca0ed12009-07-01 18:24:32145};
[email protected]fbcc40302009-06-12 20:45:45146
[email protected]4f313d52009-05-21 00:42:29147// Manages installed and running Chromium extensions.
[email protected]eaa7dd182010-12-14 11:09:00148class ExtensionService
[email protected]14908b72011-04-20 06:54:36149 : public ExtensionServiceInterface,
[email protected]5df038b2012-07-16 19:03:27150 public extensions::ExternalProviderInterface::VisitorInterface,
[email protected]fdd679b2012-11-15 20:49:39151 public content::NotificationObserver,
152 public extensions::Blacklist::Observer {
[email protected]4f313d52009-05-21 00:42:29153 public:
[email protected]a9b00ac2009-06-25 21:03:23154 // The name of the directory inside the profile where extensions are
155 // installed to.
[email protected]31bb5ee62012-09-12 22:58:40156 static const char kInstallDirectoryName[];
[email protected]a9b00ac2009-06-25 21:03:23157
[email protected]93fd78f42009-07-10 16:43:17158 // If auto-updates are turned on, default to running every 5 hours.
159 static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5;
160
[email protected]15d5b472011-11-24 04:17:24161 // The name of the directory inside the profile where per-app local settings
[email protected]b7f853e282011-08-10 09:24:20162 // are stored.
[email protected]31bb5ee62012-09-12 22:58:40163 static const char kLocalAppSettingsDirectoryName[];
[email protected]27cc7332011-11-01 01:56:43164
[email protected]15d5b472011-11-24 04:17:24165 // The name of the directory inside the profile where per-extension local
166 // settings are stored.
[email protected]31bb5ee62012-09-12 22:58:40167 static const char kLocalExtensionSettingsDirectoryName[];
[email protected]15d5b472011-11-24 04:17:24168
169 // The name of the directory inside the profile where per-app synced settings
[email protected]27cc7332011-11-01 01:56:43170 // are stored.
[email protected]31bb5ee62012-09-12 22:58:40171 static const char kSyncAppSettingsDirectoryName[];
[email protected]15d5b472011-11-24 04:17:24172
173 // The name of the directory inside the profile where per-extension synced
174 // settings are stored.
[email protected]31bb5ee62012-09-12 22:58:40175 static const char kSyncExtensionSettingsDirectoryName[];
[email protected]b7f853e282011-08-10 09:24:20176
[email protected]90e800c2012-06-12 23:11:00177 // The name of the database inside the profile where chrome-internal
178 // extension state resides.
[email protected]31bb5ee62012-09-12 22:58:40179 static const char kStateStoreName[];
[email protected]90e800c2012-06-12 23:11:00180
[email protected]d9696672011-03-15 22:45:09181 // Returns the Extension of hosted or packaged apps, NULL otherwise.
[email protected]dc9a74f72012-08-17 18:07:21182 const extensions::Extension* GetInstalledApp(const GURL& url) const;
[email protected]d9696672011-03-15 22:45:09183
[email protected]ffb204f22010-12-05 23:20:27184 // Returns whether the URL is from either a hosted or packaged app.
[email protected]dc9a74f72012-08-17 18:07:21185 bool IsInstalledApp(const GURL& url) const;
[email protected]ffb204f22010-12-05 23:20:27186
[email protected]404fb002012-10-02 21:06:17187 // If the renderer is hosting an installed app with isolated storage,
188 // returns it, otherwise returns NULL.
189 const extensions::Extension* GetIsolatedAppForRenderer(
[email protected]dc9a74f72012-08-17 18:07:21190 int renderer_child_id) const;
[email protected]da5683db2011-04-23 17:12:21191
[email protected]6aeac8342010-10-01 20:21:18192 // Attempts to uninstall an extension from a given ExtensionService. Returns
193 // true iff the target extension exists.
[email protected]eaa7dd182010-12-14 11:09:00194 static bool UninstallExtensionHelper(ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18195 const std::string& extension_id);
196
[email protected]73c47932010-12-06 18:13:43197 // Constructor stores pointers to |profile| and |extension_prefs| but
198 // ownership remains at caller.
[email protected]eaa7dd182010-12-14 11:09:00199 ExtensionService(Profile* profile,
[email protected]a29a517a2011-01-21 21:11:12200 const CommandLine* command_line,
201 const FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23202 extensions::ExtensionPrefs* extension_prefs,
[email protected]fdd679b2012-11-15 20:49:39203 extensions::Blacklist* blacklist,
[email protected]0436b102011-04-15 18:30:03204 bool autoupdate_enabled,
205 bool extensions_enabled);
[email protected]6014d672008-12-05 00:38:25206
[email protected]14908b72011-04-20 06:54:36207 virtual ~ExtensionService();
208
[email protected]6014d672008-12-05 00:38:25209 // Gets the list of currently installed extensions.
[email protected]84df8332011-12-06 18:22:46210 virtual const ExtensionSet* extensions() const OVERRIDE;
[email protected]c38fd352012-03-28 04:06:12211 virtual const ExtensionSet* disabled_extensions() const OVERRIDE;
[email protected]84df8332011-12-06 18:22:46212 const ExtensionSet* terminated_extensions() const;
[email protected]6014d672008-12-05 00:38:25213
[email protected]215a7be2012-10-22 19:53:42214 // Returns a set of all installed, disabled, and terminated extensions and
[email protected]7f4308d2012-01-18 07:43:01215 // transfers ownership to caller.
216 const ExtensionSet* GenerateInstalledExtensionsSet() const;
217
[email protected]215a7be2012-10-22 19:53:42218 // Returns a set of all extensions disabled by the sideload wipeout
219 // initiative.
220 const ExtensionSet* GetWipedOutExtensions() const;
221
[email protected]b2907fd2011-03-25 16:43:37222 // Gets the object managing the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41223 virtual extensions::PendingExtensionManager*
224 pending_extension_manager() OVERRIDE;
[email protected]aa142702010-03-26 01:26:33225
[email protected]ec5b50d2010-10-09 16:35:18226 const FilePath& install_directory() const { return install_directory_; }
227
[email protected]6f371442011-11-09 06:45:46228 extensions::ProcessMap* process_map() { return &process_map_; }
229
[email protected]db7331a2010-02-25 22:10:50230 // Whether this extension can run in an incognito window.
[email protected]c3cfb012011-04-06 22:07:35231 virtual bool IsIncognitoEnabled(const std::string& extension_id) const;
232 virtual void SetIsIncognitoEnabled(const std::string& extension_id,
233 bool enabled);
[email protected]5ef47ec2010-01-28 05:58:05234
[email protected]b2689a902011-12-01 00:41:09235 // When app notification setup is done, we call this to save the developer's
236 // oauth client id which we'll need at uninstall time to revoke the oauth
237 // permission grant for sending notifications.
[email protected]aa7599d2011-10-28 07:24:32238 virtual void SetAppNotificationSetupDone(const std::string& extension_id,
[email protected]b2689a902011-12-01 00:41:09239 const std::string& oauth_client_id);
[email protected]aa7599d2011-10-28 07:24:32240
241 virtual void SetAppNotificationDisabled(const std::string& extension_id,
242 bool value);
243
[email protected]168389f2011-12-20 17:12:48244 // Updates the app launcher value for the moved extension so that it is now
245 // located after the given predecessor and before the successor. This will
246 // trigger a sync if needed. Empty strings are used to indicate no successor
247 // or predecessor.
248 void OnExtensionMoved(const std::string& moved_extension_id,
249 const std::string& predecessor_extension_id,
250 const std::string& successor_extension_id);
251
[email protected]2a8f24e2010-11-03 21:37:05252 // Returns true if the given extension can see events and data from another
253 // sub-profile (incognito to original profile, or vice versa).
[email protected]dc9a74f72012-08-17 18:07:21254 bool CanCrossIncognito(const extensions::Extension* extension) const;
[email protected]2a8f24e2010-11-03 21:37:05255
[email protected]5ef7b002011-05-12 23:16:20256 // Returns true if the given extension can be loaded in incognito.
[email protected]1c321ee2012-05-21 03:02:34257 bool CanLoadInIncognito(const extensions::Extension* extension) const;
[email protected]5ef7b002011-05-12 23:16:20258
[email protected]05c82182010-06-24 17:49:08259 // Whether this extension can inject scripts into pages with file URLs.
[email protected]dc9a74f72012-08-17 18:07:21260 bool AllowFileAccess(const extensions::Extension* extension) const;
[email protected]3aff9ad2011-04-01 20:26:48261 // Will reload the extension since this permission is applied at loading time
262 // only.
[email protected]1c321ee2012-05-21 03:02:34263 void SetAllowFileAccess(const extensions::Extension* extension, bool allow);
[email protected]05c82182010-06-24 17:49:08264
[email protected]720ad1312012-02-27 23:07:36265 // Whether the persistent background page, if any, is ready. We don't load
266 // other components until then. If there is no background page, or if it is
267 // non-persistent (lazy), we consider it to be ready.
[email protected]dc9a74f72012-08-17 18:07:21268 bool IsBackgroundPageReady(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34269 void SetBackgroundPageReady(const extensions::Extension* extension);
[email protected]d7e9a862010-11-03 21:57:49270
271 // Getter and setter for the flag that specifies whether the extension is
272 // being upgraded.
[email protected]dc9a74f72012-08-17 18:07:21273 bool IsBeingUpgraded(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34274 void SetBeingUpgraded(const extensions::Extension* extension, bool value);
[email protected]d7e9a862010-11-03 21:57:49275
[email protected]39a5b532011-10-22 01:47:07276 // Getter and setter for the flag that specifies if the extension has used
277 // the webrequest API.
278 // TODO(mpcomplete): remove. http://crbug.com/100411
[email protected]dc9a74f72012-08-17 18:07:21279 bool HasUsedWebRequest(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34280 void SetHasUsedWebRequest(const extensions::Extension* extension, bool value);
[email protected]39a5b532011-10-22 01:47:07281
[email protected]6014d672008-12-05 00:38:25282 // Initialize and start all installed extensions.
[email protected]9f1087e2009-06-15 17:29:32283 void Init();
[email protected]6014d672008-12-05 00:38:25284
[email protected]cf593af2011-12-30 05:44:39285 // To delay some initialization until after import has finished, register
286 // for the notification.
287 // TODO(yoz): remove InitEventRoutersAterImport.
[email protected]d91268022011-08-26 13:17:37288 void InitEventRoutersAfterImport();
[email protected]cf593af2011-12-30 05:44:39289 void RegisterForImportFinished();
290
291 // Complete some initialization after being notified that import has finished.
292 void InitAfterImport();
[email protected]d91268022011-08-26 13:17:37293
[email protected]c5ae74ab2010-04-15 18:14:37294 // Start up the extension event routers.
295 void InitEventRouters();
296
[email protected]037228a2012-10-05 01:36:16297 // Called when the ProfileSyncService for the associated Profile is
298 // going to be destroyed. This is guaranteed to be called exactly
299 // once before Shutdown() is called.
300 //
301 // TODO(akalin): Remove this once http://crbug.com/153827 is fixed.
302 void OnProfileSyncServiceShutdown();
303
[email protected]47b896562012-08-22 23:55:15304 // Called when the associated Profile is going to be destroyed.
305 void Shutdown();
306
[email protected]8001df22011-04-28 19:59:47307 // Look up an extension by ID. Does not include terminated
308 // extensions.
[email protected]1c321ee2012-05-21 03:02:34309 virtual const extensions::Extension* GetExtensionById(
[email protected]b05fb9ff2011-04-23 00:07:56310 const std::string& id, bool include_disabled) const OVERRIDE;
[email protected]0c6da502009-08-14 22:32:39311
[email protected]8001df22011-04-28 19:59:47312 // Looks up a terminated (crashed) extension by ID.
[email protected]1c321ee2012-05-21 03:02:34313 const extensions::Extension*
314 GetTerminatedExtension(const std::string& id) const;
[email protected]8001df22011-04-28 19:59:47315
316 // Looks up an extension by ID, regardless of whether it's enabled,
317 // disabled, or terminated.
[email protected]1c321ee2012-05-21 03:02:34318 virtual const extensions::Extension* GetInstalledExtension(
[email protected]8001df22011-04-28 19:59:47319 const std::string& id) const OVERRIDE;
[email protected]0dfe05c2011-02-23 23:03:36320
[email protected]e957fe52009-06-23 16:51:05321 // Updates a currently-installed extension with the contents from
[email protected]7577a5c52009-07-30 06:21:58322 // |extension_path|.
[email protected]2a464a92009-08-01 17:58:35323 // TODO(aa): This method can be removed. ExtensionUpdater could use
324 // CrxInstaller directly instead.
[email protected]420a0ec2011-06-01 01:07:03325 virtual bool UpdateExtension(
326 const std::string& id,
327 const FilePath& extension_path,
328 const GURL& download_url,
[email protected]bf3d9df2012-07-24 23:20:27329 extensions::CrxInstaller** out_crx_installer) OVERRIDE;
[email protected]e957fe52009-06-23 16:51:05330
[email protected]9cddd4702009-07-27 22:09:40331 // Reloads the specified extension.
332 void ReloadExtension(const std::string& extension_id);
333
[email protected]32b36c62012-10-24 05:37:41334 // Restarts the specified extension.
335 void RestartExtension(const std::string& extension_id);
336
[email protected]631cf822009-05-15 07:01:25337 // Uninstalls the specified extension. Callers should only call this method
[email protected]17c4f3c2009-07-04 16:36:25338 // with extensions that exist. |external_uninstall| is a magical parameter
339 // that is only used to send information to ExtensionPrefs, which external
340 // callers should never set to true.
[email protected]a12c706e2011-12-01 00:58:08341 //
342 // We pass the |extension_id| by value to avoid having it deleted from under
343 // us incase someone calls it with Extension::id() or another string that we
344 // are going to delete in this function.
345 //
[email protected]17c4f3c2009-07-04 16:36:25346 // TODO(aa): Remove |external_uninstall| -- this information should be passed
347 // to ExtensionPrefs some other way.
[email protected]a12c706e2011-12-01 00:58:08348 virtual bool UninstallExtension(std::string extension_id,
[email protected]d6ebc9792011-04-07 18:18:33349 bool external_uninstall,
[email protected]65187152012-06-02 13:14:14350 string16* error);
[email protected]631cf822009-05-15 07:01:25351
[email protected]b05fb9ff2011-04-23 00:07:56352 virtual bool IsExtensionEnabled(
353 const std::string& extension_id) const OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35354 virtual bool IsExternalExtensionUninstalled(
[email protected]b05fb9ff2011-04-23 00:07:56355 const std::string& extension_id) const OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35356
[email protected]06f92562011-04-29 19:27:31357 // Enables the extension. If the extension is already enabled, does
358 // nothing.
[email protected]2859946f2011-04-04 18:18:06359 virtual void EnableExtension(const std::string& extension_id);
[email protected]06f92562011-04-29 19:27:31360
361 // Disables the extension. If the extension is already disabled, or
362 // cannot be disabled, does nothing.
[email protected]44d62b62012-04-11 00:06:03363 virtual void DisableExtension(const std::string& extension_id,
[email protected]1c321ee2012-05-21 03:02:34364 extensions::Extension::DisableReason disable_reason);
[email protected]0c6da502009-08-14 22:32:39365
[email protected]8d888c12010-11-30 00:00:25366 // Updates the |extension|'s granted permissions lists to include all
[email protected]8d888c12010-11-30 00:00:25367 // permissions in the |extension|'s manifest and re-enables the
368 // extension.
[email protected]1c321ee2012-05-21 03:02:34369 void GrantPermissionsAndEnableExtension(
[email protected]b70a2d92012-06-28 19:51:21370 const extensions::Extension* extension,
371 bool record_oauth2_grant);
[email protected]8d888c12010-11-30 00:00:25372
[email protected]be083862012-09-01 03:53:45373 // Updates the |extension|'s granted permissions lists to include all
374 // permissions in the |extensions|'s manifest.
375 void GrantPermissions(
376 const extensions::Extension* extension,
377 bool record_oauth2_grant);
378
[email protected]9f1087e2009-06-15 17:29:32379 // Check for updates (or potentially new extensions from external providers)
[email protected]93fd78f42009-07-10 16:43:17380 void CheckForExternalUpdates();
[email protected]9f1087e2009-06-15 17:29:32381
382 // Unload the specified extension.
[email protected]25ae0152011-11-18 14:40:02383 virtual void UnloadExtension(
384 const std::string& extension_id,
[email protected]1cc91fe2011-11-21 14:48:43385 extension_misc::UnloadedExtensionReason reason) OVERRIDE;
[email protected]9f1087e2009-06-15 17:29:32386
[email protected]57f71b92009-09-11 19:31:38387 // Unload all extensions. This is currently only called on shutdown, and
388 // does not send notifications.
[email protected]9f1087e2009-06-15 17:29:32389 void UnloadAllExtensions();
390
391 // Called only by testing.
392 void ReloadExtensions();
393
394 // Scan the extension directory and clean up the cruft.
395 void GarbageCollectExtensions();
396
[email protected]fb82dcd2012-03-21 14:15:46397 // Notifies Sync (if needed) of a newly-installed extension or a change to
398 // an existing extension.
[email protected]1c321ee2012-05-21 03:02:34399 virtual void SyncExtensionChangeIfNeeded(
400 const extensions::Extension& extension) OVERRIDE;
[email protected]fb82dcd2012-03-21 14:15:46401
[email protected]583d45c12010-08-31 02:48:12402 // Returns true if |url| should get extension api bindings and be permitted
403 // to make api calls. Note that this is independent of what extension
404 // permissions the given extension has been granted.
405 bool ExtensionBindingsAllowed(const GURL& url);
406
[email protected]4d007b312012-10-17 03:00:48407 // Returns true if a normal browser window should avoid showing |url| in a
408 // tab. In this case, |url| is also rewritten to an error URL.
409 bool ShouldBlockUrlInBrowserTab(GURL* url);
410
[email protected]b671760b2010-07-15 21:13:47411 // Returns the icon to display in the omnibox for the given extension.
[email protected]e8476c992012-08-20 20:27:59412 gfx::Image GetOmniboxIcon(const std::string& extension_id);
[email protected]b671760b2010-07-15 21:13:47413
[email protected]29d0d4ac2010-09-08 21:10:31414 // Returns the icon to display in the omnibox popup window for the given
415 // extension.
[email protected]e8476c992012-08-20 20:27:59416 gfx::Image GetOmniboxPopupIcon(const std::string& extension_id);
[email protected]29d0d4ac2010-09-08 21:10:31417
[email protected]c6d474f82009-12-16 21:11:06418 // Called when the initial extensions load has completed.
419 virtual void OnLoadedInstalledExtensions();
[email protected]7577a5c52009-07-30 06:21:58420
[email protected]49cd1572011-02-08 21:38:45421 // Adds |extension| to this ExtensionService and notifies observers than an
422 // extension has been loaded. Called by the backend after an extension has
423 // been loaded from a file and installed.
[email protected]1c321ee2012-05-21 03:02:34424 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE;
[email protected]7577a5c52009-07-30 06:21:58425
[email protected]8c484b742012-11-29 06:05:36426 // Check if we have preferences for the component extension and, if not or if
427 // the stored version differs, install the extension (without requirements
428 // checking) before calling AddExtension.
429 virtual void AddComponentExtension(const extensions::Extension* extension)
430 OVERRIDE;
431
[email protected]7577a5c52009-07-30 06:21:58432 // Called by the backend when an extension has been installed.
[email protected]8266d662011-07-12 21:53:26433 void OnExtensionInstalled(
[email protected]1c321ee2012-05-21 03:02:34434 const extensions::Extension* extension,
[email protected]98270432012-09-11 20:51:24435 const syncer::StringOrdinal& page_ordinal,
[email protected]0db124b02012-11-07 04:55:05436 bool has_requirement_errors,
437 bool wait_for_idle);
438
[email protected]6f6101832012-11-27 22:10:48439 // Similar to FinishInstallation, but first checks if there still is an update
440 // pending for the extension, and makes sure the extension is still idle.
441 void MaybeFinishDelayedInstallation(const std::string& extension_id);
442
[email protected]0db124b02012-11-07 04:55:05443 // Finishes installation of an update for an extension with the specified id,
444 // when installation of that extension was previously delayed because the
445 // extension was in use.
[email protected]6f6101832012-11-27 22:10:48446 virtual void FinishDelayedInstallation(
447 const std::string& extension_id) OVERRIDE;
[email protected]7577a5c52009-07-30 06:21:58448
[email protected]76b65442012-11-17 14:11:48449 // Returns an update for an extension with the specified id, if installation
450 // of that update was previously delayed because the extension was in use. If
451 // no updates are pending for the extension returns NULL.
452 virtual const extensions::Extension* GetPendingExtensionUpdate(
453 const std::string& extension_id) const OVERRIDE;
454
[email protected]902fd7b2011-07-27 18:42:31455 // Initializes the |extension|'s active permission set and disables the
456 // extension if the privilege level has increased (e.g., due to an upgrade).
[email protected]1c321ee2012-05-21 03:02:34457 void InitializePermissions(const extensions::Extension* extension);
[email protected]8d888c12010-11-30 00:00:25458
[email protected]215a7be2012-10-22 19:53:42459 // Check to see if this extension needs to be disabled, as per the sideload
460 // wipeout initiative.
461 void MaybeWipeout(const extensions::Extension* extension);
462
[email protected]4ee07c62012-08-21 12:40:42463 // Go through each extension and unload those that are not allowed to run by
464 // management policy providers (ie. network admin and Google-managed
465 // blacklist).
466 virtual void CheckManagementPolicy() OVERRIDE;
[email protected]aa96d3a2010-08-21 08:45:25467
[email protected]b05fb9ff2011-04-23 00:07:56468 virtual void CheckForUpdatesSoon() OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35469
[email protected]65f173552012-06-28 22:43:58470 // syncer::SyncableService implementation.
[email protected]3f98fd92012-11-17 15:54:29471 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
[email protected]a4a147652012-07-03 23:41:32472 syncer::ModelType type,
[email protected]65f173552012-06-28 22:43:58473 const syncer::SyncDataList& initial_sync_data,
474 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
475 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE;
[email protected]a4a147652012-07-03 23:41:32476 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
[email protected]65f173552012-06-28 22:43:58477 virtual syncer::SyncDataList GetAllSyncData(
[email protected]a4a147652012-07-03 23:41:32478 syncer::ModelType type) const OVERRIDE;
[email protected]65f173552012-06-28 22:43:58479 virtual syncer::SyncError ProcessSyncChanges(
[email protected]3bdba0d2011-08-23 07:17:30480 const tracked_objects::Location& from_here,
[email protected]65f173552012-06-28 22:43:58481 const syncer::SyncChangeList& change_list) OVERRIDE;
[email protected]90310d92011-04-17 07:35:04482
[email protected]5db9ada2012-04-11 13:48:20483 // Gets the sync data for the given extension, assuming that the extension is
484 // syncable.
485 extensions::ExtensionSyncData GetExtensionSyncData(
[email protected]1c321ee2012-05-21 03:02:34486 const extensions::Extension& extension) const;
[email protected]5db9ada2012-04-11 13:48:20487
488 // Gets the sync data for the given app, assuming that the app is
489 // syncable.
[email protected]1c321ee2012-05-21 03:02:34490 extensions::AppSyncData GetAppSyncData(
491 const extensions::Extension& extension) const;
[email protected]5db9ada2012-04-11 13:48:20492
493 // Gets the ExtensionSyncData for all extensions.
494 std::vector<extensions::ExtensionSyncData> GetExtensionSyncDataList() const;
495
496 // Gets the AppSyncData for all extensions.
497 std::vector<extensions::AppSyncData> GetAppSyncDataList() const;
498
499 // Applies the change specified passed in by either ExtensionSyncData or
500 // AppSyncData to the current system.
501 // Returns false if the changes were not completely applied and were added
502 // to the pending list to be tried again.
503 bool ProcessExtensionSyncData(
504 const extensions::ExtensionSyncData& extension_sync_data);
505 bool ProcessAppSyncData(const extensions::AppSyncData& app_sync_data);
506
507
[email protected]7577a5c52009-07-30 06:21:58508 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
[email protected]abe7a8942009-06-23 05:14:29509 bool extensions_enabled() { return extensions_enabled_; }
510
[email protected]0e34d7892009-06-05 19:17:40511 void set_show_extensions_prompts(bool enabled) {
512 show_extensions_prompts_ = enabled;
[email protected]e2eb43112009-05-29 21:19:54513 }
514
[email protected]0e34d7892009-06-05 19:17:40515 bool show_extensions_prompts() {
516 return show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54517 }
518
[email protected]c3cfb012011-04-06 22:07:35519 Profile* profile();
[email protected]24e7a9d2009-11-04 11:11:34520
[email protected]c3cfb012011-04-06 22:07:35521 // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
522 // ExtensionPrefs* mutable_extension_prefs().
[email protected]45759612012-07-10 17:21:23523 extensions::ExtensionPrefs* extension_prefs();
[email protected]e81dba32009-06-19 20:19:13524
[email protected]0d9a2202011-11-09 13:48:41525 extensions::SettingsFrontend* settings_frontend();
[email protected]b7f853e282011-08-10 09:24:20526
[email protected]e2d720aa2012-05-17 00:11:35527 extensions::ContentSettingsStore* GetContentSettingsStore();
[email protected]b790b072011-05-20 09:46:44528
[email protected]3ecda252010-11-18 19:50:55529 // Whether the extension service is ready.
[email protected]25ae0152011-11-18 14:40:02530 virtual bool is_ready() OVERRIDE;
[email protected]3ecda252010-11-18 19:50:55531
[email protected]7f8f24f2012-11-15 19:40:14532 virtual base::SequencedTaskRunner* GetFileTaskRunner() OVERRIDE;
533
[email protected]d8c8f25f2011-11-02 18:18:01534 extensions::ComponentLoader* component_loader() {
535 return component_loader_.get();
536 }
537
[email protected]1fab8452009-09-03 02:23:39538 // Note that this may return NULL if autoupdate is not turned on.
[email protected]42a08162012-03-16 18:09:11539 extensions::ExtensionUpdater* updater();
[email protected]1fab8452009-09-03 02:23:39540
[email protected]e0360f2c2009-12-07 22:34:31541 ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; }
542
[email protected]d13950e2009-12-04 01:43:02543 ExtensionsQuotaService* quota_service() { return &quota_service_; }
544
[email protected]5aeeae12012-07-05 19:13:11545 extensions::MenuManager* menu_manager() { return &menu_manager_; }
[email protected]2e3b5202010-03-23 06:52:41546
[email protected]8d92e0382012-08-01 18:06:52547 extensions::AppNotificationManager* app_notification_manager() {
[email protected]af9db5f2011-10-05 05:13:15548 return app_notification_manager_.get();
[email protected]c1d05aa2011-06-28 02:07:30549 }
550
[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]163ed192012-07-24 19:31:07555 extensions::WindowEventRouter* window_event_router() {
556 return window_event_router_.get();
557 }
558
[email protected]cab208eb02012-10-18 22:15:23559#if defined(OS_CHROMEOS)
[email protected]771a6182011-10-05 16:32:52560 chromeos::ExtensionInputMethodEventRouter* input_method_event_router() {
561 return input_method_event_router_.get();
562 }
[email protected]b16fc2e2011-07-21 21:32:58563#endif
564
[email protected]5ebd6a62012-08-01 23:54:39565 extensions::PushMessagingEventRouter* push_messaging_event_router() {
566 return push_messaging_event_router_.get();
567 }
568
[email protected]d11c8e92009-10-20 23:26:40569 // Notify the frontend that there was an error loading an extension.
[email protected]d8c8f25f2011-11-02 18:18:01570 // This method is public because UnpackedInstaller and InstalledLoader
571 // can post to here.
572 // TODO(aa): Remove this. It doesn't do enough to be worth the dependency
573 // of these classes on ExtensionService.
[email protected]d11c8e92009-10-20 23:26:40574 void ReportExtensionLoadError(const FilePath& extension_path,
575 const std::string& error,
[email protected]d11c8e92009-10-20 23:26:40576 bool be_noisy);
577
[email protected]406027c02010-09-27 08:03:18578 // ExtensionHost of background page calls this method right after its render
579 // view has been created.
[email protected]3a1dc572012-07-31 22:25:13580 void DidCreateRenderViewForBackgroundPage(extensions::ExtensionHost* host);
[email protected]406027c02010-09-27 08:03:18581
[email protected]8e4560b62011-01-14 10:09:14582 // For the extension in |version_path| with |id|, check to see if it's an
583 // externally managed extension. If so, uninstall it.
584 void CheckExternalUninstall(const std::string& id);
585
[email protected]7f8f24f2012-11-15 19:40:14586 // Changes sequenced task runner for crx installation tasks to |task_runner|.
587 void SetFileTaskRunnerForTesting(base::SequencedTaskRunner* task_runner);
588
[email protected]5df038b2012-07-16 19:03:27589 // Clear all ExternalProviders.
[email protected]8e4560b62011-01-14 10:09:14590 void ClearProvidersForTesting();
591
[email protected]5df038b2012-07-16 19:03:27592 // Adds an ExternalProviderInterface for the service to use during testing.
593 // Takes ownership of |test_provider|.
594 void AddProviderForTesting(
595 extensions::ExternalProviderInterface* test_provider);
[email protected]8e4560b62011-01-14 10:09:14596
[email protected]5df038b2012-07-16 19:03:27597 // ExternalProvider::Visitor implementation.
[email protected]1c321ee2012-05-21 03:02:34598 virtual bool OnExternalExtensionFileFound(
599 const std::string& id,
600 const Version* version,
601 const FilePath& path,
602 extensions::Extension::Location location,
603 int creation_flags,
604 bool mark_acknowledged) OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:14605
[email protected]1c321ee2012-05-21 03:02:34606 virtual bool OnExternalExtensionUpdateUrlFound(
607 const std::string& id,
608 const GURL& update_url,
609 extensions::Extension::Location location) OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:14610
[email protected]50067e52011-10-20 23:17:07611 virtual void OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:27612 const extensions::ExternalProviderInterface* provider) OVERRIDE;
[email protected]50067e52011-10-20 23:17:07613
[email protected]94fde232012-04-27 10:22:30614 // Returns true when all the external extension providers are ready.
615 bool AreAllExternalProvidersReady() const;
616
[email protected]50067e52011-10-20 23:17:07617 void OnAllExternalProvidersReady();
[email protected]8e4560b62011-01-14 10:09:14618
[email protected]62433d32011-10-12 22:33:12619 // Once all external providers are done, generates any needed alerts about
[email protected]e5af875f2011-10-10 21:09:14620 // extensions.
621 void IdentifyAlertableExtensions();
622
[email protected]89226982012-07-16 20:09:18623 // Given an ExtensionErrorUI alert, populates it with any extensions that
[email protected]07c9f2f42012-02-29 18:45:22624 // need alerting. Returns true if the alert should be displayed at all.
625 //
[email protected]89226982012-07-16 20:09:18626 // This method takes the extension_error_ui argument rather than using
[email protected]07c9f2f42012-02-29 18:45:22627 // the member variable to make it easier to test the method in isolation.
[email protected]89226982012-07-16 20:09:18628 bool PopulateExtensionErrorUI(ExtensionErrorUI* extension_error_ui);
[email protected]07c9f2f42012-02-29 18:45:22629
[email protected]612a1cb12012-10-17 13:18:03630 // Checks if there are any new external extensions to notify the user about.
631 void UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:14632
[email protected]47fc70c2011-12-06 07:29:51633 // Given a (presumably just-installed) extension id, mark that extension as
634 // acknowledged.
635 void AcknowledgeExternalExtension(const std::string& id);
636
[email protected]d96eb512012-11-01 23:44:08637 // Returns true if this extension is an external one that has yet to be
638 // marked as acknowledged.
639 bool IsUnacknowledgedExternalExtension(
640 const extensions::Extension* extension);
641
[email protected]62433d32011-10-12 22:33:12642 // Opens the Extensions page because the user wants to get more details
643 // about the alerts.
[email protected]89226982012-07-16 20:09:18644 void HandleExtensionAlertDetails();
[email protected]62433d32011-10-12 22:33:12645
[email protected]a9aa5932012-01-25 08:27:40646 // Called when the extension alert is closed.
647 void HandleExtensionAlertClosed();
[email protected]e5af875f2011-10-10 21:09:14648
[email protected]612a1cb12012-10-17 13:18:03649 // Marks alertable extensions as acknowledged, after the user presses the
650 // accept button.
651 void HandleExtensionAlertAccept();
652
[email protected]6c2381d2011-10-19 02:52:53653 // content::NotificationObserver
[email protected]432115822011-07-10 15:52:27654 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53655 const content::NotificationSource& source,
656 const content::NotificationDetails& details) OVERRIDE;
[email protected]4814b512009-11-07 00:12:29657
[email protected]ec5b50d2010-10-09 16:35:18658 // Whether there are any apps installed. Component apps are not included.
659 bool HasApps() const;
660
661 // Gets the set of loaded app ids. Component apps are not included.
[email protected]1c321ee2012-05-21 03:02:34662 extensions::ExtensionIdSet GetAppIds() const;
[email protected]377011d2010-07-20 04:18:50663
[email protected]fe2dd7742011-04-19 22:52:49664 // Record a histogram using the PermissionMessage enum values for each
665 // permission in |e|.
666 // NOTE: If this is ever called with high frequency, the implementation may
667 // need to be made more efficient.
668 static void RecordPermissionMessagesHistogram(
[email protected]1c321ee2012-05-21 03:02:34669 const extensions::Extension* e, const char* histogram);
[email protected]fe2dd7742011-04-19 22:52:49670
[email protected]65992d52012-09-19 23:05:31671 // Open a dev tools window for the background page for the given extension,
672 // starting the background page first if necesary.
673 void InspectBackgroundPage(const extensions::Extension* extension);
674
[email protected]fa2416f2011-05-03 08:41:20675#if defined(UNIT_TEST)
[email protected]1c321ee2012-05-21 03:02:34676 void TrackTerminatedExtensionForTest(const extensions::Extension* extension) {
[email protected]fa2416f2011-05-03 08:41:20677 TrackTerminatedExtension(extension);
678 }
679#endif
680
[email protected]b1912d592012-08-17 22:29:38681 extensions::AppShortcutManager* app_shortcut_manager() {
682 return &app_shortcut_manager_;
683 }
[email protected]178f8512012-02-09 01:49:36684
[email protected]65f173552012-06-28 22:43:58685 // Specialization of syncer::SyncableService::AsWeakPtr.
[email protected]77e4dc0882012-06-20 18:53:50686 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
687
[email protected]3c4abc82012-10-22 22:25:54688 bool browser_terminating() const { return browser_terminating_; }
689
690 // For testing.
691 void set_browser_terminating_for_test(bool value) {
692 browser_terminating_ = value;
693 }
694
[email protected]fc332ae2012-11-14 20:17:33695 // By default ExtensionService will wait with installing an updated extension
696 // until the extension is idle. Tests might not like this behavior, so you can
697 // disable it with this method.
698 void set_install_updates_when_idle_for_test(bool value) {
699 install_updates_when_idle_ = value;
700 }
701
[email protected]14908b72011-04-20 06:54:36702 private:
[email protected]d7e9a862010-11-03 21:57:49703 // Contains Extension data that can change during the life of the process,
704 // but does not persist across restarts.
705 struct ExtensionRuntimeData {
706 // True if the background page is ready.
707 bool background_page_ready;
708
709 // True while the extension is being upgraded.
710 bool being_upgraded;
711
[email protected]39a5b532011-10-22 01:47:07712 // True if the extension has used the webRequest API.
713 bool has_used_webrequest;
714
[email protected]d7e9a862010-11-03 21:57:49715 ExtensionRuntimeData();
716 ~ExtensionRuntimeData();
717 };
718 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap;
719
[email protected]cebc3dc2011-04-18 17:15:00720 struct NaClModuleInfo {
721 NaClModuleInfo();
722 ~NaClModuleInfo();
723
724 GURL url;
725 std::string mime_type;
726 };
727 typedef std::list<NaClModuleInfo> NaClModuleInfoList;
728
[email protected]5db9ada2012-04-11 13:48:20729 // Return true if the sync type of |extension| matches |type|.
[email protected]1c321ee2012-05-21 03:02:34730 bool IsCorrectSyncType(const extensions::Extension& extension,
[email protected]a4a147652012-07-03 23:41:32731 syncer::ModelType type)
[email protected]3bdba0d2011-08-23 07:17:30732 const;
733
[email protected]90bb38d2012-11-14 18:36:03734 void OnExtensionInstallPrefChanged();
735
[email protected]5db9ada2012-04-11 13:48:20736 // Handles setting the extension specific values in |extension_sync_data| to
737 // the current system.
738 // Returns false if the changes were not completely applied and need to be
739 // tried again later.
740 bool ProcessExtensionSyncDataHelper(
741 const extensions::ExtensionSyncData& extension_sync_data,
[email protected]a4a147652012-07-03 23:41:32742 syncer::ModelType type);
[email protected]3bdba0d2011-08-23 07:17:30743
[email protected]81f0d162012-08-15 04:21:47744 enum IncludeFlag {
745 INCLUDE_NONE = 0,
746 INCLUDE_ENABLED = 1 << 0,
747 INCLUDE_DISABLED = 1 << 1,
748 INCLUDE_TERMINATED = 1 << 2
749 };
750
[email protected]32b36c62012-10-24 05:37:41751 // Events to be fired after an extension is reloaded.
752 enum PostReloadEvents {
753 EVENT_NONE = 0,
754 EVENT_LAUNCHED = 1 << 0,
755 EVENT_RESTARTED = 1 << 1,
756 };
757
[email protected]0c6da502009-08-14 22:32:39758 // Look up an extension by ID, optionally including either or both of enabled
759 // and disabled extensions.
[email protected]1c321ee2012-05-21 03:02:34760 const extensions::Extension* GetExtensionByIdInternal(
761 const std::string& id,
[email protected]81f0d162012-08-15 04:21:47762 int include_mask) const;
[email protected]0c6da502009-08-14 22:32:39763
[email protected]fa2416f2011-05-03 08:41:20764 // Adds the given extension to the list of terminated extensions if
765 // it is not already there and unloads it.
[email protected]1c321ee2012-05-21 03:02:34766 void TrackTerminatedExtension(const extensions::Extension* extension);
[email protected]fa2416f2011-05-03 08:41:20767
768 // Removes the extension with the given id from the list of
769 // terminated extensions if it is there.
[email protected]bb7f40952011-01-13 00:21:20770 void UntrackTerminatedExtension(const std::string& id);
771
[email protected]8c484b742012-11-29 06:05:36772 // Update preferences for a new or updated extension; notify observers that
773 // the extension is installed, e.g., to update event handlers on background
774 // pages; and perform other extension install tasks before calling
775 // AddExtension.
776 void AddNewOrUpdatedExtension(
777 const extensions::Extension* extension,
778 const syncer::StringOrdinal& page_ordinal,
779 extensions::Extension::State initial_state);
780
[email protected]62d30f42009-10-01 22:36:06781 // Handles sending notification that |extension| was loaded.
[email protected]1c321ee2012-05-21 03:02:34782 void NotifyExtensionLoaded(const extensions::Extension* extension);
[email protected]62d30f42009-10-01 22:36:06783
784 // Handles sending notification that |extension| was unloaded.
[email protected]1c321ee2012-05-21 03:02:34785 void NotifyExtensionUnloaded(const extensions::Extension* extension,
[email protected]814a7bf0f2011-08-13 05:30:59786 extension_misc::UnloadedExtensionReason reason);
[email protected]62d30f42009-10-01 22:36:06787
[email protected]6f6101832012-11-27 22:10:48788 // Common helper to finish installing the given extension.
789 void FinishInstallation(const extensions::Extension* extension);
790
[email protected]32b36c62012-10-24 05:37:41791 // Reloads |extension_id| and then dispatches to it the PostReloadEvents
792 // indicated by |events|.
793 void ReloadExtensionWithEvents(const std::string& extension_id,
794 int events);
795
796 // Returns true if the app with id |extension_id| has any shell windows open.
797 bool HasShellWindows(const std::string& extension_id);
798
[email protected]aab98a52009-12-02 03:22:35799 // Helper that updates the active extension list used for crash reporting.
800 void UpdateActiveExtensionsInCrashReporter();
801
[email protected]cebc3dc2011-04-18 17:15:00802 // We implement some Pepper plug-ins using NaCl to take advantage of NaCl's
803 // strong sandbox. Typically, these NaCl modules are stored in extensions
804 // and registered here. Not all NaCl modules need to register for a MIME
805 // type, just the ones that are responsible for rendering a particular MIME
806 // type, like application/pdf. Note: We only register NaCl modules in the
807 // browser process.
808 void RegisterNaClModule(const GURL& url, const std::string& mime_type);
809 void UnregisterNaClModule(const GURL& url);
810
[email protected]ed0ba002011-05-26 16:55:13811 // Call UpdatePluginListWithNaClModules() after registering or unregistering
812 // a NaCl module to see those changes reflected in the PluginList.
813 void UpdatePluginListWithNaClModules();
814
[email protected]cebc3dc2011-04-18 17:15:00815 NaClModuleInfoList::iterator FindNaClModule(const GURL& url);
816
[email protected]32b36c62012-10-24 05:37:41817 // Performs tasks requested to occur after |extension| loads.
818 void DoPostLoadTasks(const extensions::Extension* extension);
819
[email protected]6cafe35a2012-08-27 22:40:50820 // Launches the platform app associated with |extension_host|.
821 static void LaunchApplication(extensions::ExtensionHost* extension_host);
822
[email protected]32b36c62012-10-24 05:37:41823 // Dispatches a restart event to the platform app associated with
824 // |extension_host|.
825 static void RestartApplication(extensions::ExtensionHost* extension_host);
826
[email protected]65992d52012-09-19 23:05:31827 // Helper to inspect an ExtensionHost after it has been loaded.
828 void InspectExtensionHost(extensions::ExtensionHost* host);
829
[email protected]612a1cb12012-10-17 13:18:03830 // Helper to determine whether we should initially enable an installed
831 // (or upgraded) extension.
832 bool ShouldEnableOnInstall(const extensions::Extension* extension);
833
[email protected]0db124b02012-11-07 04:55:05834 // Helper to determine if an extension is idle, and it should be safe
835 // to update the extension.
836 bool IsExtensionIdle(const std::string& extension_id) const;
837
[email protected]e7aa7b7e2012-11-27 04:51:22838 // Helper to determine if updating an extensions should proceed immediately,
839 // or if we should delay the update until further notice.
840 bool ShouldDelayExtensionUpdate(const std::string& extension_id,
841 bool wait_for_idle) const;
842
[email protected]fdd679b2012-11-15 20:49:39843 // extensions::Blacklist::Observer implementation.
844 virtual void OnBlacklistUpdated() OVERRIDE;
845
[email protected]31d8f5f22012-04-02 15:22:08846 // The normal profile associated with this ExtensionService.
[email protected]6ef635e42009-07-26 06:16:12847 Profile* profile_;
848
[email protected]31d8f5f22012-04-02 15:22:08849 // The ExtensionSystem for the profile above.
[email protected]bd306722012-07-11 20:43:59850 extensions::ExtensionSystem* system_;
[email protected]31d8f5f22012-04-02 15:22:08851
[email protected]73c47932010-12-06 18:13:43852 // Preferences for the owning profile (weak reference).
[email protected]45759612012-07-10 17:21:23853 extensions::ExtensionPrefs* extension_prefs_;
[email protected]894bb502009-05-21 22:39:57854
[email protected]adfc5462011-09-21 19:07:13855 // Settings for the owning profile.
[email protected]cccdf0aa2011-11-11 03:43:38856 scoped_ptr<extensions::SettingsFrontend> settings_frontend_;
[email protected]b7f853e282011-08-10 09:24:20857
[email protected]6014d672008-12-05 00:38:25858 // The current list of installed extensions.
[email protected]84df8332011-12-06 18:22:46859 ExtensionSet extensions_;
[email protected]6014d672008-12-05 00:38:25860
[email protected]0c6da502009-08-14 22:32:39861 // The list of installed extensions that have been disabled.
[email protected]84df8332011-12-06 18:22:46862 ExtensionSet disabled_extensions_;
[email protected]0c6da502009-08-14 22:32:39863
[email protected]bb7f40952011-01-13 00:21:20864 // The list of installed extensions that have been terminated.
[email protected]84df8332011-12-06 18:22:46865 ExtensionSet terminated_extensions_;
[email protected]bb7f40952011-01-13 00:21:20866
[email protected]0db124b02012-11-07 04:55:05867 // The list of extension updates that are waiting to be installed.
868 ExtensionSet pending_extension_updates_;
869
[email protected]b2907fd2011-03-25 16:43:37870 // Hold the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41871 extensions::PendingExtensionManager pending_extension_manager_;
[email protected]aa142702010-03-26 01:26:33872
[email protected]d7e9a862010-11-03 21:57:49873 // The map of extension IDs to their runtime data.
874 ExtensionRuntimeDataMap extension_runtime_data_;
875
[email protected]6014d672008-12-05 00:38:25876 // The full path to the directory where extensions are installed.
877 FilePath install_directory_;
878
[email protected]e2eb43112009-05-29 21:19:54879 // Whether or not extensions are enabled.
880 bool extensions_enabled_;
881
[email protected]0e34d7892009-06-05 19:17:40882 // Whether to notify users when they attempt to install an extension.
883 bool show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54884
[email protected]fc332ae2012-11-14 20:17:33885 // Whether to delay installing of extension updates until the extension is
886 // idle.
887 bool install_updates_when_idle_;
888
[email protected]d13950e2009-12-04 01:43:02889 // Used by dispatchers to limit API quota for individual extensions.
890 ExtensionsQuotaService quota_service_;
891
[email protected]432115822011-07-10 15:52:27892 // Record that Init() has been called, and chrome::EXTENSIONS_READY
[email protected]fa6a9102010-11-22 15:38:50893 // has fired.
[email protected]3ecda252010-11-18 19:50:55894 bool ready_;
[email protected]e81dba32009-06-19 20:19:13895
[email protected]93fd78f42009-07-10 16:43:17896 // Our extension updater, if updates are turned on.
[email protected]42a08162012-03-16 18:09:11897 scoped_ptr<extensions::ExtensionUpdater> updater_;
[email protected]93fd78f42009-07-10 16:43:17898
[email protected]e0360f2c2009-12-07 22:34:31899 // The model that tracks extensions with BrowserAction buttons.
900 ExtensionToolbarModel toolbar_model_;
901
[email protected]1eb175082010-02-10 09:26:16902 // Map unloaded extensions' ids to their paths. When a temporarily loaded
[email protected]5fb889382011-06-03 00:29:20903 // extension is unloaded, we lose the information about it and don't have
[email protected]1eb175082010-02-10 09:26:16904 // any in the extension preferences file.
905 typedef std::map<std::string, FilePath> UnloadedExtensionPathMap;
906 UnloadedExtensionPathMap unloaded_extension_paths_;
907
[email protected]f17dbd42010-08-16 23:21:10908 // Map disabled extensions' ids to their paths. When a temporarily loaded
909 // extension is disabled before it is reloaded, keep track of the path so that
910 // it can be re-enabled upon a successful load.
911 typedef std::map<std::string, FilePath> DisabledExtensionPathMap;
912 DisabledExtensionPathMap disabled_extension_paths_;
913
[email protected]4814b512009-11-07 00:12:29914 // Map of inspector cookies that are detached, waiting for an extension to be
915 // reloaded.
916 typedef std::map<std::string, int> OrphanedDevTools;
917 OrphanedDevTools orphaned_dev_tools_;
918
[email protected]32b36c62012-10-24 05:37:41919 // Maps extension ids to a bitmask that indicates which events should be
920 // dispatched to the extension when it is loaded.
921 std::map<std::string, int> on_load_events_;
[email protected]6cafe35a2012-08-27 22:40:50922
[email protected]6c2381d2011-10-19 02:52:53923 content::NotificationRegistrar registrar_;
[email protected]2fb7dc982010-09-29 12:24:28924 PrefChangeRegistrar pref_change_registrar_;
[email protected]4814b512009-11-07 00:12:29925
[email protected]d8c8f25f2011-11-02 18:18:01926 // Keeps track of loading and unloading component extensions.
927 scoped_ptr<extensions::ComponentLoader> component_loader_;
928
[email protected]2e3b5202010-03-23 06:52:41929 // Keeps track of menu items added by extensions.
[email protected]5aeeae12012-07-05 19:13:11930 extensions::MenuManager menu_manager_;
[email protected]2e3b5202010-03-23 06:52:41931
[email protected]c1d05aa2011-06-28 02:07:30932 // Keeps track of app notifications.
[email protected]8d92e0382012-08-01 18:06:52933 scoped_refptr<extensions::AppNotificationManager> app_notification_manager_;
[email protected]c1d05aa2011-06-28 02:07:30934
[email protected]b671760b2010-07-15 21:13:47935 // Keeps track of favicon-sized omnibox icons for extensions.
936 ExtensionIconManager omnibox_icon_manager_;
[email protected]29d0d4ac2010-09-08 21:10:31937 ExtensionIconManager omnibox_popup_icon_manager_;
[email protected]b671760b2010-07-15 21:13:47938
[email protected]b3d62312b12010-10-14 21:10:18939 // Flag to make sure event routers are only initialized once.
940 bool event_routers_initialized_;
941
[email protected]c4dc5cc2012-11-09 08:48:39942 // TODO(yoz): None of these should be owned by ExtensionService.
943 // crbug.com/159265
[email protected]d2e6bd62011-10-24 20:29:07944 scoped_ptr<HistoryExtensionEventRouter> history_event_router_;
[email protected]f825df22011-06-28 17:36:10945
[email protected]5a38dfd2012-07-23 23:22:10946 scoped_ptr<extensions::BrowserEventRouter> browser_event_router_;
[email protected]da55b8d2011-05-26 00:09:49947
[email protected]163ed192012-07-24 19:31:07948 scoped_ptr<extensions::WindowEventRouter> window_event_router_;
949
[email protected]135e4782012-09-19 20:36:52950 scoped_ptr<extensions::PreferenceEventRouter> preference_event_router_;
[email protected]118de7892011-03-16 13:31:40951
[email protected]23d5f172011-10-25 05:49:53952 scoped_ptr<BookmarkExtensionEventRouter> bookmark_event_router_;
[email protected]f825df22011-06-28 17:36:10953
[email protected]92ba7b012012-05-16 03:36:17954 scoped_ptr<extensions::ExtensionCookiesEventRouter> cookies_event_router_;
[email protected]f825df22011-06-28 17:36:10955
[email protected]31bb5ee62012-09-12 22:58:40956 scoped_ptr<extensions::MediaGalleriesPrivateEventRouter>
957 media_galleries_private_event_router_;
958
[email protected]5ebd6a62012-08-01 23:54:39959 scoped_ptr<extensions::PushMessagingEventRouter>
960 push_messaging_event_router_;
961
[email protected]017ecde92012-04-04 09:11:26962 scoped_ptr<extensions::WebNavigationEventRouter> web_navigation_event_router_;
[email protected]f825df22011-06-28 17:36:10963
[email protected]9c70e0d92012-07-16 08:39:44964 scoped_ptr<extensions::ExtensionManagedModeEventRouter>
965 managed_mode_event_router_;
[email protected]8a4cf842012-05-16 13:35:30966
[email protected]b16fc2e2011-07-21 21:32:58967#if defined(OS_CHROMEOS)
[email protected]771a6182011-10-05 16:32:52968 scoped_ptr<chromeos::ExtensionInputMethodEventRouter>
969 input_method_event_router_;
[email protected]b16fc2e2011-07-21 21:32:58970#endif
971
[email protected]8e4560b62011-01-14 10:09:14972 // A collection of external extension providers. Each provider reads
973 // a source of external extension information. Examples include the
974 // windows registry and external_extensions.json.
[email protected]5df038b2012-07-16 19:03:27975 extensions::ProviderCollection external_extension_providers_;
[email protected]8e4560b62011-01-14 10:09:14976
977 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
[email protected]94fde232012-04-27 10:22:30978 // extension URL is found, and by CheckForUpdatesSoon() when an update check
979 // has to wait for the external providers. Used in
980 // OnAllExternalProvidersReady() to determine if an update check is needed to
981 // install pending extensions.
982 bool update_once_all_providers_are_ready_;
[email protected]8e4560b62011-01-14 10:09:14983
[email protected]3c4abc82012-10-22 22:25:54984 // Set when the browser is terminating. Prevents us from installing or
985 // updating additional extensions and allows in-progress installations to
986 // decide to abort.
987 bool browser_terminating_;
988
[email protected]cebc3dc2011-04-18 17:15:00989 NaClModuleInfoList nacl_module_list_;
990
[email protected]5db9ada2012-04-11 13:48:20991 extensions::AppSyncBundle app_sync_bundle_;
992 extensions::ExtensionSyncBundle extension_sync_bundle_;
[email protected]3bdba0d2011-08-23 07:17:30993
[email protected]6f371442011-11-09 06:45:46994 extensions::ProcessMap process_map_;
995
[email protected]b1912d592012-08-17 22:29:38996 extensions::AppShortcutManager app_shortcut_manager_;
[email protected]9de83282011-12-12 11:06:37997
[email protected]89226982012-07-16 20:09:18998 scoped_ptr<ExtensionErrorUI> extension_error_ui_;
[email protected]7f8f24f2012-11-15 19:40:14999 // Sequenced task runner for extension related file operations.
1000 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
[email protected]a9aa5932012-01-25 08:27:401001
[email protected]9ce11d22012-08-08 23:20:131002#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:581003 scoped_ptr<extensions::ExtensionActionStorageManager>
1004 extension_action_storage_manager_;
[email protected]9ce11d22012-08-08 23:20:131005#endif
[email protected]c77f2352012-08-08 22:07:581006
[email protected]eaa7dd182010-12-14 11:09:001007 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]c2c263c2010-08-13 21:59:481008 InstallAppsWithUnlimtedStorage);
[email protected]eaa7dd182010-12-14 11:09:001009 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]654512b2010-09-01 02:09:421010 InstallAppsAndCheckStorageProtection);
[email protected]eaa7dd182010-12-14 11:09:001011 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
[email protected]6014d672008-12-05 00:38:251012};
1013
[email protected]eaa7dd182010-12-14 11:09:001014#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_