blob: 2cac53556bb96cb05ce2aed8ddfb89b9d83c695b [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]a6a7ced2012-11-01 17:24:1820#include "base/prefs/public/pref_observer.h"
[email protected]65187152012-06-02 13:14:1421#include "base/string16.h"
[email protected]178f8512012-02-09 01:49:3622#include "chrome/browser/extensions/app_shortcut_manager.h"
[email protected]5db9ada2012-04-11 13:48:2023#include "chrome/browser/extensions/app_sync_bundle.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]7c1490da2011-10-11 18:53:2529#include "chrome/browser/extensions/extension_warning_set.h"
[email protected]d13950e2009-12-04 01:43:0230#include "chrome/browser/extensions/extensions_quota_service.h"
[email protected]5df038b2012-07-16 19:03:2731#include "chrome/browser/extensions/external_provider_interface.h"
[email protected]5aeeae12012-07-05 19:13:1132#include "chrome/browser/extensions/menu_manager.h"
[email protected]b2907fd2011-03-25 16:43:3733#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]6f371442011-11-09 06:45:4634#include "chrome/browser/extensions/process_map.h"
[email protected]3bdba0d2011-08-23 07:17:3035#include "chrome/common/extensions/extension.h"
[email protected]814a7bf0f2011-08-13 05:30:5936#include "chrome/common/extensions/extension_constants.h"
[email protected]84df8332011-12-06 18:22:4637#include "chrome/common/extensions/extension_set.h"
[email protected]6c2381d2011-10-19 02:52:5338#include "content/public/browser/notification_observer.h"
39#include "content/public/browser/notification_registrar.h"
[email protected]36b643212012-09-07 12:53:0040#include "sync/api/string_ordinal.h"
[email protected]895a1e52012-05-15 02:50:1241#include "sync/api/sync_change.h"
42#include "sync/api/syncable_service.h"
[email protected]6014d672008-12-05 00:38:2543
[email protected]23d5f172011-10-25 05:49:5344class BookmarkExtensionEventRouter;
[email protected]dc9a74f72012-08-17 18:07:2145class CommandLine;
[email protected]89226982012-07-16 20:09:1846class ExtensionErrorUI;
[email protected]f825df22011-06-28 17:36:1047class ExtensionManagementEventRouter;
[email protected]3bdba0d2011-08-23 07:17:3048class ExtensionSyncData;
[email protected]e0360f2c2009-12-07 22:34:3149class ExtensionToolbarModel;
[email protected]d8c8f25f2011-11-02 18:18:0150class HistoryExtensionEventRouter;
[email protected]69f1be82009-04-16 22:27:2151class GURL;
[email protected]81e63782009-02-27 19:35:0952class Profile;
[email protected]aa142702010-03-26 01:26:3353class Version;
54
[email protected]771a6182011-10-05 16:32:5255namespace chromeos {
56class ExtensionInputMethodEventRouter;
[email protected]d8c8f25f2011-11-02 18:18:0157}
58
[email protected]9c70e0d92012-07-16 08:39:4459namespace extensions {
[email protected]8d92e0382012-08-01 18:06:5260class AppNotificationManager;
[email protected]5db9ada2012-04-11 13:48:2061class AppSyncData;
[email protected]5a38dfd2012-07-23 23:22:1062class BrowserEventRouter;
[email protected]d8c8f25f2011-11-02 18:18:0163class ComponentLoader;
[email protected]e2d720aa2012-05-17 00:11:3564class ContentSettingsStore;
[email protected]bf3d9df2012-07-24 23:20:2765class CrxInstaller;
[email protected]1c321ee2012-05-21 03:02:3466class Extension;
[email protected]c77f2352012-08-08 22:07:5867class ExtensionActionStorageManager;
[email protected]cab208eb02012-10-18 22:15:2368class ExtensionBluetoothEventRouter;
[email protected]92ba7b012012-05-16 03:36:1769class ExtensionCookiesEventRouter;
[email protected]163ed192012-07-24 19:31:0770class ExtensionManagedModeEventRouter;
[email protected]5db9ada2012-04-11 13:48:2071class ExtensionSyncData;
[email protected]bd306722012-07-11 20:43:5972class ExtensionSystem;
[email protected]42a08162012-03-16 18:09:1173class ExtensionUpdater;
[email protected]31bb5ee62012-09-12 22:58:4074class FontSettingsEventRouter;
75class 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]c3cfb012011-04-06 22:07:35114 virtual bool IsExtensionEnabled(const std::string& extension_id) const = 0;
115 virtual bool IsExternalExtensionUninstalled(
116 const std::string& extension_id) const = 0;
[email protected]2859946f2011-04-04 18:18:06117
[email protected]6b75ec32009-08-14 06:37:18118 virtual void UpdateExtensionBlacklist(
119 const std::vector<std::string>& blacklist) = 0;
[email protected]4ee07c62012-08-21 12:40:42120 virtual void CheckManagementPolicy() = 0;
[email protected]5ef47ec2010-01-28 05:58:05121
[email protected]31206602011-04-13 23:07:32122 // Safe to call multiple times in a row.
123 //
[email protected]90310d92011-04-17 07:35:04124 // TODO(akalin): Remove this method (and others) once we refactor
125 // themes sync to not use it directly.
[email protected]31206602011-04-13 23:07:32126 virtual void CheckForUpdatesSoon() = 0;
[email protected]25ae0152011-11-18 14:40:02127
[email protected]1c321ee2012-05-21 03:02:34128 virtual void AddExtension(const extensions::Extension* extension) = 0;
[email protected]25ae0152011-11-18 14:40:02129
130 virtual void UnloadExtension(
131 const std::string& extension_id,
132 extension_misc::UnloadedExtensionReason reason) = 0;
133
[email protected]1c321ee2012-05-21 03:02:34134 virtual void SyncExtensionChangeIfNeeded(
135 const extensions::Extension& extension) = 0;
[email protected]fb82dcd2012-03-21 14:15:46136
[email protected]25ae0152011-11-18 14:40:02137 virtual bool is_ready() = 0;
[email protected]d1ca0ed12009-07-01 18:24:32138};
[email protected]fbcc40302009-06-12 20:45:45139
[email protected]4f313d52009-05-21 00:42:29140// Manages installed and running Chromium extensions.
[email protected]eaa7dd182010-12-14 11:09:00141class ExtensionService
[email protected]14908b72011-04-20 06:54:36142 : public ExtensionServiceInterface,
[email protected]5df038b2012-07-16 19:03:27143 public extensions::ExternalProviderInterface::VisitorInterface,
[email protected]a6a7ced2012-11-01 17:24:18144 public content::NotificationObserver,
145 public PrefObserver {
[email protected]4f313d52009-05-21 00:42:29146 public:
[email protected]a9b00ac2009-06-25 21:03:23147 // The name of the directory inside the profile where extensions are
148 // installed to.
[email protected]31bb5ee62012-09-12 22:58:40149 static const char kInstallDirectoryName[];
[email protected]a9b00ac2009-06-25 21:03:23150
[email protected]93fd78f42009-07-10 16:43:17151 // If auto-updates are turned on, default to running every 5 hours.
152 static const int kDefaultUpdateFrequencySeconds = 60 * 60 * 5;
153
[email protected]15d5b472011-11-24 04:17:24154 // The name of the directory inside the profile where per-app local settings
[email protected]b7f853e282011-08-10 09:24:20155 // are stored.
[email protected]31bb5ee62012-09-12 22:58:40156 static const char kLocalAppSettingsDirectoryName[];
[email protected]27cc7332011-11-01 01:56:43157
[email protected]15d5b472011-11-24 04:17:24158 // The name of the directory inside the profile where per-extension local
159 // settings are stored.
[email protected]31bb5ee62012-09-12 22:58:40160 static const char kLocalExtensionSettingsDirectoryName[];
[email protected]15d5b472011-11-24 04:17:24161
162 // The name of the directory inside the profile where per-app synced settings
[email protected]27cc7332011-11-01 01:56:43163 // are stored.
[email protected]31bb5ee62012-09-12 22:58:40164 static const char kSyncAppSettingsDirectoryName[];
[email protected]15d5b472011-11-24 04:17:24165
166 // The name of the directory inside the profile where per-extension synced
167 // settings are stored.
[email protected]31bb5ee62012-09-12 22:58:40168 static const char kSyncExtensionSettingsDirectoryName[];
[email protected]b7f853e282011-08-10 09:24:20169
[email protected]90e800c2012-06-12 23:11:00170 // The name of the database inside the profile where chrome-internal
171 // extension state resides.
[email protected]31bb5ee62012-09-12 22:58:40172 static const char kStateStoreName[];
[email protected]90e800c2012-06-12 23:11:00173
[email protected]d9696672011-03-15 22:45:09174 // Returns the Extension of hosted or packaged apps, NULL otherwise.
[email protected]dc9a74f72012-08-17 18:07:21175 const extensions::Extension* GetInstalledApp(const GURL& url) const;
[email protected]d9696672011-03-15 22:45:09176
[email protected]ffb204f22010-12-05 23:20:27177 // Returns whether the URL is from either a hosted or packaged app.
[email protected]dc9a74f72012-08-17 18:07:21178 bool IsInstalledApp(const GURL& url) const;
[email protected]ffb204f22010-12-05 23:20:27179
[email protected]404fb002012-10-02 21:06:17180 // If the renderer is hosting an installed app with isolated storage,
181 // returns it, otherwise returns NULL.
182 const extensions::Extension* GetIsolatedAppForRenderer(
[email protected]dc9a74f72012-08-17 18:07:21183 int renderer_child_id) const;
[email protected]da5683db2011-04-23 17:12:21184
[email protected]6aeac8342010-10-01 20:21:18185 // Attempts to uninstall an extension from a given ExtensionService. Returns
186 // true iff the target extension exists.
[email protected]eaa7dd182010-12-14 11:09:00187 static bool UninstallExtensionHelper(ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18188 const std::string& extension_id);
189
[email protected]73c47932010-12-06 18:13:43190 // Constructor stores pointers to |profile| and |extension_prefs| but
191 // ownership remains at caller.
[email protected]eaa7dd182010-12-14 11:09:00192 ExtensionService(Profile* profile,
[email protected]a29a517a2011-01-21 21:11:12193 const CommandLine* command_line,
194 const FilePath& install_directory,
[email protected]45759612012-07-10 17:21:23195 extensions::ExtensionPrefs* extension_prefs,
[email protected]0436b102011-04-15 18:30:03196 bool autoupdate_enabled,
197 bool extensions_enabled);
[email protected]6014d672008-12-05 00:38:25198
[email protected]14908b72011-04-20 06:54:36199 virtual ~ExtensionService();
200
[email protected]6014d672008-12-05 00:38:25201 // Gets the list of currently installed extensions.
[email protected]84df8332011-12-06 18:22:46202 virtual const ExtensionSet* extensions() const OVERRIDE;
[email protected]c38fd352012-03-28 04:06:12203 virtual const ExtensionSet* disabled_extensions() const OVERRIDE;
[email protected]84df8332011-12-06 18:22:46204 const ExtensionSet* terminated_extensions() const;
[email protected]6014d672008-12-05 00:38:25205
[email protected]215a7be2012-10-22 19:53:42206 // Returns a set of all installed, disabled, and terminated extensions and
[email protected]7f4308d2012-01-18 07:43:01207 // transfers ownership to caller.
208 const ExtensionSet* GenerateInstalledExtensionsSet() const;
209
[email protected]215a7be2012-10-22 19:53:42210 // Returns a set of all extensions disabled by the sideload wipeout
211 // initiative.
212 const ExtensionSet* GetWipedOutExtensions() const;
213
[email protected]b2907fd2011-03-25 16:43:37214 // Gets the object managing the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41215 virtual extensions::PendingExtensionManager*
216 pending_extension_manager() OVERRIDE;
[email protected]aa142702010-03-26 01:26:33217
[email protected]ec5b50d2010-10-09 16:35:18218 const FilePath& install_directory() const { return install_directory_; }
219
[email protected]6f371442011-11-09 06:45:46220 extensions::ProcessMap* process_map() { return &process_map_; }
221
[email protected]db7331a2010-02-25 22:10:50222 // Whether this extension can run in an incognito window.
[email protected]c3cfb012011-04-06 22:07:35223 virtual bool IsIncognitoEnabled(const std::string& extension_id) const;
224 virtual void SetIsIncognitoEnabled(const std::string& extension_id,
225 bool enabled);
[email protected]5ef47ec2010-01-28 05:58:05226
[email protected]b2689a902011-12-01 00:41:09227 // When app notification setup is done, we call this to save the developer's
228 // oauth client id which we'll need at uninstall time to revoke the oauth
229 // permission grant for sending notifications.
[email protected]aa7599d2011-10-28 07:24:32230 virtual void SetAppNotificationSetupDone(const std::string& extension_id,
[email protected]b2689a902011-12-01 00:41:09231 const std::string& oauth_client_id);
[email protected]aa7599d2011-10-28 07:24:32232
233 virtual void SetAppNotificationDisabled(const std::string& extension_id,
234 bool value);
235
[email protected]168389f2011-12-20 17:12:48236 // Updates the app launcher value for the moved extension so that it is now
237 // located after the given predecessor and before the successor. This will
238 // trigger a sync if needed. Empty strings are used to indicate no successor
239 // or predecessor.
240 void OnExtensionMoved(const std::string& moved_extension_id,
241 const std::string& predecessor_extension_id,
242 const std::string& successor_extension_id);
243
[email protected]2a8f24e2010-11-03 21:37:05244 // Returns true if the given extension can see events and data from another
245 // sub-profile (incognito to original profile, or vice versa).
[email protected]dc9a74f72012-08-17 18:07:21246 bool CanCrossIncognito(const extensions::Extension* extension) const;
[email protected]2a8f24e2010-11-03 21:37:05247
[email protected]5ef7b002011-05-12 23:16:20248 // Returns true if the given extension can be loaded in incognito.
[email protected]1c321ee2012-05-21 03:02:34249 bool CanLoadInIncognito(const extensions::Extension* extension) const;
[email protected]5ef7b002011-05-12 23:16:20250
[email protected]05c82182010-06-24 17:49:08251 // Whether this extension can inject scripts into pages with file URLs.
[email protected]dc9a74f72012-08-17 18:07:21252 bool AllowFileAccess(const extensions::Extension* extension) const;
[email protected]3aff9ad2011-04-01 20:26:48253 // Will reload the extension since this permission is applied at loading time
254 // only.
[email protected]1c321ee2012-05-21 03:02:34255 void SetAllowFileAccess(const extensions::Extension* extension, bool allow);
[email protected]05c82182010-06-24 17:49:08256
[email protected]720ad1312012-02-27 23:07:36257 // Whether the persistent background page, if any, is ready. We don't load
258 // other components until then. If there is no background page, or if it is
259 // non-persistent (lazy), we consider it to be ready.
[email protected]dc9a74f72012-08-17 18:07:21260 bool IsBackgroundPageReady(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34261 void SetBackgroundPageReady(const extensions::Extension* extension);
[email protected]d7e9a862010-11-03 21:57:49262
263 // Getter and setter for the flag that specifies whether the extension is
264 // being upgraded.
[email protected]dc9a74f72012-08-17 18:07:21265 bool IsBeingUpgraded(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34266 void SetBeingUpgraded(const extensions::Extension* extension, bool value);
[email protected]d7e9a862010-11-03 21:57:49267
[email protected]39a5b532011-10-22 01:47:07268 // Getter and setter for the flag that specifies if the extension has used
269 // the webrequest API.
270 // TODO(mpcomplete): remove. http://crbug.com/100411
[email protected]dc9a74f72012-08-17 18:07:21271 bool HasUsedWebRequest(const extensions::Extension* extension) const;
[email protected]1c321ee2012-05-21 03:02:34272 void SetHasUsedWebRequest(const extensions::Extension* extension, bool value);
[email protected]39a5b532011-10-22 01:47:07273
[email protected]6014d672008-12-05 00:38:25274 // Initialize and start all installed extensions.
[email protected]9f1087e2009-06-15 17:29:32275 void Init();
[email protected]6014d672008-12-05 00:38:25276
[email protected]cf593af2011-12-30 05:44:39277 // To delay some initialization until after import has finished, register
278 // for the notification.
279 // TODO(yoz): remove InitEventRoutersAterImport.
[email protected]d91268022011-08-26 13:17:37280 void InitEventRoutersAfterImport();
[email protected]cf593af2011-12-30 05:44:39281 void RegisterForImportFinished();
282
283 // Complete some initialization after being notified that import has finished.
284 void InitAfterImport();
[email protected]d91268022011-08-26 13:17:37285
[email protected]c5ae74ab2010-04-15 18:14:37286 // Start up the extension event routers.
287 void InitEventRouters();
288
[email protected]037228a2012-10-05 01:36:16289 // Called when the ProfileSyncService for the associated Profile is
290 // going to be destroyed. This is guaranteed to be called exactly
291 // once before Shutdown() is called.
292 //
293 // TODO(akalin): Remove this once http://crbug.com/153827 is fixed.
294 void OnProfileSyncServiceShutdown();
295
[email protected]47b896562012-08-22 23:55:15296 // Called when the associated Profile is going to be destroyed.
297 void Shutdown();
298
[email protected]8001df22011-04-28 19:59:47299 // Look up an extension by ID. Does not include terminated
300 // extensions.
[email protected]1c321ee2012-05-21 03:02:34301 virtual const extensions::Extension* GetExtensionById(
[email protected]b05fb9ff2011-04-23 00:07:56302 const std::string& id, bool include_disabled) const OVERRIDE;
[email protected]0c6da502009-08-14 22:32:39303
[email protected]8001df22011-04-28 19:59:47304 // Looks up a terminated (crashed) extension by ID.
[email protected]1c321ee2012-05-21 03:02:34305 const extensions::Extension*
306 GetTerminatedExtension(const std::string& id) const;
[email protected]8001df22011-04-28 19:59:47307
308 // Looks up an extension by ID, regardless of whether it's enabled,
309 // disabled, or terminated.
[email protected]1c321ee2012-05-21 03:02:34310 virtual const extensions::Extension* GetInstalledExtension(
[email protected]8001df22011-04-28 19:59:47311 const std::string& id) const OVERRIDE;
[email protected]0dfe05c2011-02-23 23:03:36312
[email protected]e957fe52009-06-23 16:51:05313 // Updates a currently-installed extension with the contents from
[email protected]7577a5c52009-07-30 06:21:58314 // |extension_path|.
[email protected]2a464a92009-08-01 17:58:35315 // TODO(aa): This method can be removed. ExtensionUpdater could use
316 // CrxInstaller directly instead.
[email protected]420a0ec2011-06-01 01:07:03317 virtual bool UpdateExtension(
318 const std::string& id,
319 const FilePath& extension_path,
320 const GURL& download_url,
[email protected]bf3d9df2012-07-24 23:20:27321 extensions::CrxInstaller** out_crx_installer) OVERRIDE;
[email protected]e957fe52009-06-23 16:51:05322
[email protected]9cddd4702009-07-27 22:09:40323 // Reloads the specified extension.
324 void ReloadExtension(const std::string& extension_id);
325
[email protected]32b36c62012-10-24 05:37:41326 // Restarts the specified extension.
327 void RestartExtension(const std::string& extension_id);
328
[email protected]631cf822009-05-15 07:01:25329 // Uninstalls the specified extension. Callers should only call this method
[email protected]17c4f3c2009-07-04 16:36:25330 // with extensions that exist. |external_uninstall| is a magical parameter
331 // that is only used to send information to ExtensionPrefs, which external
332 // callers should never set to true.
[email protected]a12c706e2011-12-01 00:58:08333 //
334 // We pass the |extension_id| by value to avoid having it deleted from under
335 // us incase someone calls it with Extension::id() or another string that we
336 // are going to delete in this function.
337 //
[email protected]17c4f3c2009-07-04 16:36:25338 // TODO(aa): Remove |external_uninstall| -- this information should be passed
339 // to ExtensionPrefs some other way.
[email protected]a12c706e2011-12-01 00:58:08340 virtual bool UninstallExtension(std::string extension_id,
[email protected]d6ebc9792011-04-07 18:18:33341 bool external_uninstall,
[email protected]65187152012-06-02 13:14:14342 string16* error);
[email protected]631cf822009-05-15 07:01:25343
[email protected]b05fb9ff2011-04-23 00:07:56344 virtual bool IsExtensionEnabled(
345 const std::string& extension_id) const OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35346 virtual bool IsExternalExtensionUninstalled(
[email protected]b05fb9ff2011-04-23 00:07:56347 const std::string& extension_id) const OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35348
[email protected]06f92562011-04-29 19:27:31349 // Enables the extension. If the extension is already enabled, does
350 // nothing.
[email protected]2859946f2011-04-04 18:18:06351 virtual void EnableExtension(const std::string& extension_id);
[email protected]06f92562011-04-29 19:27:31352
353 // Disables the extension. If the extension is already disabled, or
354 // cannot be disabled, does nothing.
[email protected]44d62b62012-04-11 00:06:03355 virtual void DisableExtension(const std::string& extension_id,
[email protected]1c321ee2012-05-21 03:02:34356 extensions::Extension::DisableReason disable_reason);
[email protected]0c6da502009-08-14 22:32:39357
[email protected]8d888c12010-11-30 00:00:25358 // Updates the |extension|'s granted permissions lists to include all
[email protected]8d888c12010-11-30 00:00:25359 // permissions in the |extension|'s manifest and re-enables the
360 // extension.
[email protected]1c321ee2012-05-21 03:02:34361 void GrantPermissionsAndEnableExtension(
[email protected]b70a2d92012-06-28 19:51:21362 const extensions::Extension* extension,
363 bool record_oauth2_grant);
[email protected]8d888c12010-11-30 00:00:25364
[email protected]be083862012-09-01 03:53:45365 // Updates the |extension|'s granted permissions lists to include all
366 // permissions in the |extensions|'s manifest.
367 void GrantPermissions(
368 const extensions::Extension* extension,
369 bool record_oauth2_grant);
370
[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]b671760b2010-07-15 21:13:47403 // Returns the icon to display in the omnibox for the given extension.
[email protected]e8476c992012-08-20 20:27:59404 gfx::Image GetOmniboxIcon(const std::string& extension_id);
[email protected]b671760b2010-07-15 21:13:47405
[email protected]29d0d4ac2010-09-08 21:10:31406 // Returns the icon to display in the omnibox popup window for the given
407 // extension.
[email protected]e8476c992012-08-20 20:27:59408 gfx::Image GetOmniboxPopupIcon(const std::string& extension_id);
[email protected]29d0d4ac2010-09-08 21:10:31409
[email protected]c6d474f82009-12-16 21:11:06410 // Called when the initial extensions load has completed.
411 virtual void OnLoadedInstalledExtensions();
[email protected]7577a5c52009-07-30 06:21:58412
[email protected]49cd1572011-02-08 21:38:45413 // Adds |extension| to this ExtensionService and notifies observers than an
414 // extension has been loaded. Called by the backend after an extension has
415 // been loaded from a file and installed.
[email protected]1c321ee2012-05-21 03:02:34416 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE;
[email protected]7577a5c52009-07-30 06:21:58417
418 // Called by the backend when an extension has been installed.
[email protected]8266d662011-07-12 21:53:26419 void OnExtensionInstalled(
[email protected]1c321ee2012-05-21 03:02:34420 const extensions::Extension* extension,
[email protected]98270432012-09-11 20:51:24421 const syncer::StringOrdinal& page_ordinal,
[email protected]0db124b02012-11-07 04:55:05422 bool has_requirement_errors,
423 bool wait_for_idle);
424
425 // Finishes installation of an update for an extension with the specified id,
426 // when installation of that extension was previously delayed because the
427 // extension was in use.
428 void FinishInstallation(const std::string& extension_id);
429
430 // Similar to FinishInstallation, but first checks if there still is an update
431 // pending for the extension, and makes sure the extension is still idle.
432 void MaybeFinishInstallation(const std::string& extension_id);
[email protected]7577a5c52009-07-30 06:21:58433
[email protected]902fd7b2011-07-27 18:42:31434 // Initializes the |extension|'s active permission set and disables the
435 // extension if the privilege level has increased (e.g., due to an upgrade).
[email protected]1c321ee2012-05-21 03:02:34436 void InitializePermissions(const extensions::Extension* extension);
[email protected]8d888c12010-11-30 00:00:25437
[email protected]215a7be2012-10-22 19:53:42438 // Check to see if this extension needs to be disabled, as per the sideload
439 // wipeout initiative.
440 void MaybeWipeout(const extensions::Extension* extension);
441
[email protected]6b75ec32009-08-14 06:37:18442 // Go through each extensions in pref, unload blacklisted extensions
443 // and update the blacklist state in pref.
444 virtual void UpdateExtensionBlacklist(
[email protected]8266d662011-07-12 21:53:26445 const std::vector<std::string>& blacklist) OVERRIDE;
[email protected]6b75ec32009-08-14 06:37:18446
[email protected]4ee07c62012-08-21 12:40:42447 // Go through each extension and unload those that are not allowed to run by
448 // management policy providers (ie. network admin and Google-managed
449 // blacklist).
450 virtual void CheckManagementPolicy() OVERRIDE;
[email protected]aa96d3a2010-08-21 08:45:25451
[email protected]b05fb9ff2011-04-23 00:07:56452 virtual void CheckForUpdatesSoon() OVERRIDE;
[email protected]c3cfb012011-04-06 22:07:35453
[email protected]65f173552012-06-28 22:43:58454 // syncer::SyncableService implementation.
455 virtual syncer::SyncError MergeDataAndStartSyncing(
[email protected]a4a147652012-07-03 23:41:32456 syncer::ModelType type,
[email protected]65f173552012-06-28 22:43:58457 const syncer::SyncDataList& initial_sync_data,
458 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
459 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE;
[email protected]a4a147652012-07-03 23:41:32460 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
[email protected]65f173552012-06-28 22:43:58461 virtual syncer::SyncDataList GetAllSyncData(
[email protected]a4a147652012-07-03 23:41:32462 syncer::ModelType type) const OVERRIDE;
[email protected]65f173552012-06-28 22:43:58463 virtual syncer::SyncError ProcessSyncChanges(
[email protected]3bdba0d2011-08-23 07:17:30464 const tracked_objects::Location& from_here,
[email protected]65f173552012-06-28 22:43:58465 const syncer::SyncChangeList& change_list) OVERRIDE;
[email protected]90310d92011-04-17 07:35:04466
[email protected]5db9ada2012-04-11 13:48:20467 // Gets the sync data for the given extension, assuming that the extension is
468 // syncable.
469 extensions::ExtensionSyncData GetExtensionSyncData(
[email protected]1c321ee2012-05-21 03:02:34470 const extensions::Extension& extension) const;
[email protected]5db9ada2012-04-11 13:48:20471
472 // Gets the sync data for the given app, assuming that the app is
473 // syncable.
[email protected]1c321ee2012-05-21 03:02:34474 extensions::AppSyncData GetAppSyncData(
475 const extensions::Extension& extension) const;
[email protected]5db9ada2012-04-11 13:48:20476
477 // Gets the ExtensionSyncData for all extensions.
478 std::vector<extensions::ExtensionSyncData> GetExtensionSyncDataList() const;
479
480 // Gets the AppSyncData for all extensions.
481 std::vector<extensions::AppSyncData> GetAppSyncDataList() const;
482
483 // Applies the change specified passed in by either ExtensionSyncData or
484 // AppSyncData to the current system.
485 // Returns false if the changes were not completely applied and were added
486 // to the pending list to be tried again.
487 bool ProcessExtensionSyncData(
488 const extensions::ExtensionSyncData& extension_sync_data);
489 bool ProcessAppSyncData(const extensions::AppSyncData& app_sync_data);
490
491
[email protected]7577a5c52009-07-30 06:21:58492 void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
[email protected]abe7a8942009-06-23 05:14:29493 bool extensions_enabled() { return extensions_enabled_; }
494
[email protected]0e34d7892009-06-05 19:17:40495 void set_show_extensions_prompts(bool enabled) {
496 show_extensions_prompts_ = enabled;
[email protected]e2eb43112009-05-29 21:19:54497 }
498
[email protected]0e34d7892009-06-05 19:17:40499 bool show_extensions_prompts() {
500 return show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54501 }
502
[email protected]c3cfb012011-04-06 22:07:35503 Profile* profile();
[email protected]24e7a9d2009-11-04 11:11:34504
[email protected]c3cfb012011-04-06 22:07:35505 // TODO(skerner): Change to const ExtensionPrefs& extension_prefs() const,
506 // ExtensionPrefs* mutable_extension_prefs().
[email protected]45759612012-07-10 17:21:23507 extensions::ExtensionPrefs* extension_prefs();
[email protected]e81dba32009-06-19 20:19:13508
[email protected]0d9a2202011-11-09 13:48:41509 extensions::SettingsFrontend* settings_frontend();
[email protected]b7f853e282011-08-10 09:24:20510
[email protected]e2d720aa2012-05-17 00:11:35511 extensions::ContentSettingsStore* GetContentSettingsStore();
[email protected]b790b072011-05-20 09:46:44512
[email protected]3ecda252010-11-18 19:50:55513 // Whether the extension service is ready.
[email protected]25ae0152011-11-18 14:40:02514 virtual bool is_ready() OVERRIDE;
[email protected]3ecda252010-11-18 19:50:55515
[email protected]d8c8f25f2011-11-02 18:18:01516 extensions::ComponentLoader* component_loader() {
517 return component_loader_.get();
518 }
519
[email protected]1fab8452009-09-03 02:23:39520 // Note that this may return NULL if autoupdate is not turned on.
[email protected]42a08162012-03-16 18:09:11521 extensions::ExtensionUpdater* updater();
[email protected]1fab8452009-09-03 02:23:39522
[email protected]e0360f2c2009-12-07 22:34:31523 ExtensionToolbarModel* toolbar_model() { return &toolbar_model_; }
524
[email protected]d13950e2009-12-04 01:43:02525 ExtensionsQuotaService* quota_service() { return &quota_service_; }
526
[email protected]5aeeae12012-07-05 19:13:11527 extensions::MenuManager* menu_manager() { return &menu_manager_; }
[email protected]2e3b5202010-03-23 06:52:41528
[email protected]8d92e0382012-08-01 18:06:52529 extensions::AppNotificationManager* app_notification_manager() {
[email protected]af9db5f2011-10-05 05:13:15530 return app_notification_manager_.get();
[email protected]c1d05aa2011-06-28 02:07:30531 }
532
[email protected]5a38dfd2012-07-23 23:22:10533 extensions::BrowserEventRouter* browser_event_router() {
[email protected]97d2f1d2011-01-15 00:41:08534 return browser_event_router_.get();
535 }
536
[email protected]163ed192012-07-24 19:31:07537 extensions::WindowEventRouter* window_event_router() {
538 return window_event_router_.get();
539 }
540
[email protected]cab208eb02012-10-18 22:15:23541 extensions::ExtensionBluetoothEventRouter* bluetooth_event_router() {
[email protected]f463bc92012-03-22 16:38:23542 return bluetooth_event_router_.get();
543 }
[email protected]cab208eb02012-10-18 22:15:23544
545#if defined(OS_CHROMEOS)
[email protected]771a6182011-10-05 16:32:52546 chromeos::ExtensionInputMethodEventRouter* input_method_event_router() {
547 return input_method_event_router_.get();
548 }
[email protected]b16fc2e2011-07-21 21:32:58549#endif
550
[email protected]5ebd6a62012-08-01 23:54:39551 extensions::PushMessagingEventRouter* push_messaging_event_router() {
552 return push_messaging_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]d11c8e92009-10-20 23:26:40560 void ReportExtensionLoadError(const FilePath& extension_path,
561 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]5df038b2012-07-16 19:03:27572 // Clear all ExternalProviders.
[email protected]8e4560b62011-01-14 10:09:14573 void ClearProvidersForTesting();
574
[email protected]5df038b2012-07-16 19:03:27575 // Adds an ExternalProviderInterface for the service to use during testing.
576 // Takes ownership of |test_provider|.
577 void AddProviderForTesting(
578 extensions::ExternalProviderInterface* test_provider);
[email protected]8e4560b62011-01-14 10:09:14579
[email protected]5df038b2012-07-16 19:03:27580 // ExternalProvider::Visitor implementation.
[email protected]1c321ee2012-05-21 03:02:34581 virtual bool OnExternalExtensionFileFound(
582 const std::string& id,
583 const Version* version,
584 const FilePath& path,
585 extensions::Extension::Location location,
586 int creation_flags,
587 bool mark_acknowledged) OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:14588
[email protected]1c321ee2012-05-21 03:02:34589 virtual bool OnExternalExtensionUpdateUrlFound(
590 const std::string& id,
591 const GURL& update_url,
592 extensions::Extension::Location location) OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:14593
[email protected]50067e52011-10-20 23:17:07594 virtual void OnExternalProviderReady(
[email protected]5df038b2012-07-16 19:03:27595 const extensions::ExternalProviderInterface* provider) OVERRIDE;
[email protected]50067e52011-10-20 23:17:07596
[email protected]94fde232012-04-27 10:22:30597 // Returns true when all the external extension providers are ready.
598 bool AreAllExternalProvidersReady() const;
599
[email protected]50067e52011-10-20 23:17:07600 void OnAllExternalProvidersReady();
[email protected]8e4560b62011-01-14 10:09:14601
[email protected]62433d32011-10-12 22:33:12602 // Once all external providers are done, generates any needed alerts about
[email protected]e5af875f2011-10-10 21:09:14603 // extensions.
604 void IdentifyAlertableExtensions();
605
[email protected]89226982012-07-16 20:09:18606 // Given an ExtensionErrorUI alert, populates it with any extensions that
[email protected]07c9f2f42012-02-29 18:45:22607 // need alerting. Returns true if the alert should be displayed at all.
608 //
[email protected]89226982012-07-16 20:09:18609 // This method takes the extension_error_ui argument rather than using
[email protected]07c9f2f42012-02-29 18:45:22610 // the member variable to make it easier to test the method in isolation.
[email protected]89226982012-07-16 20:09:18611 bool PopulateExtensionErrorUI(ExtensionErrorUI* extension_error_ui);
[email protected]07c9f2f42012-02-29 18:45:22612
[email protected]612a1cb12012-10-17 13:18:03613 // Checks if there are any new external extensions to notify the user about.
614 void UpdateExternalExtensionAlert();
[email protected]e5af875f2011-10-10 21:09:14615
[email protected]47fc70c2011-12-06 07:29:51616 // Given a (presumably just-installed) extension id, mark that extension as
617 // acknowledged.
618 void AcknowledgeExternalExtension(const std::string& id);
619
[email protected]d96eb512012-11-01 23:44:08620 // Returns true if this extension is an external one that has yet to be
621 // marked as acknowledged.
622 bool IsUnacknowledgedExternalExtension(
623 const extensions::Extension* extension);
624
[email protected]62433d32011-10-12 22:33:12625 // Opens the Extensions page because the user wants to get more details
626 // about the alerts.
[email protected]89226982012-07-16 20:09:18627 void HandleExtensionAlertDetails();
[email protected]62433d32011-10-12 22:33:12628
[email protected]a9aa5932012-01-25 08:27:40629 // Called when the extension alert is closed.
630 void HandleExtensionAlertClosed();
[email protected]e5af875f2011-10-10 21:09:14631
[email protected]612a1cb12012-10-17 13:18:03632 // Marks alertable extensions as acknowledged, after the user presses the
633 // accept button.
634 void HandleExtensionAlertAccept();
635
[email protected]6c2381d2011-10-19 02:52:53636 // content::NotificationObserver
[email protected]432115822011-07-10 15:52:27637 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53638 const content::NotificationSource& source,
639 const content::NotificationDetails& details) OVERRIDE;
[email protected]4814b512009-11-07 00:12:29640
[email protected]a6a7ced2012-11-01 17:24:18641 // PrefObserver
642 virtual void OnPreferenceChanged(PrefServiceBase* service,
643 const std::string& pref_name) OVERRIDE;
644
[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,
659 // starting the background page first if necesary.
660 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 }
666#endif
667
[email protected]7c1490da2011-10-11 18:53:25668 ExtensionWarningSet* extension_warnings() {
669 return &extension_warnings_;
670 }
671
[email protected]b1912d592012-08-17 22:29:38672 extensions::AppShortcutManager* app_shortcut_manager() {
673 return &app_shortcut_manager_;
674 }
[email protected]178f8512012-02-09 01:49:36675
[email protected]65f173552012-06-28 22:43:58676 // Specialization of syncer::SyncableService::AsWeakPtr.
[email protected]77e4dc0882012-06-20 18:53:50677 base::WeakPtr<ExtensionService> AsWeakPtr() { return base::AsWeakPtr(this); }
678
[email protected]3c4abc82012-10-22 22:25:54679 bool browser_terminating() const { return browser_terminating_; }
680
681 // For testing.
682 void set_browser_terminating_for_test(bool value) {
683 browser_terminating_ = value;
684 }
685
[email protected]14908b72011-04-20 06:54:36686 private:
[email protected]d7e9a862010-11-03 21:57:49687 // Contains Extension data that can change during the life of the process,
688 // but does not persist across restarts.
689 struct ExtensionRuntimeData {
690 // True if the background page is ready.
691 bool background_page_ready;
692
693 // True while the extension is being upgraded.
694 bool being_upgraded;
695
[email protected]39a5b532011-10-22 01:47:07696 // True if the extension has used the webRequest API.
697 bool has_used_webrequest;
698
[email protected]d7e9a862010-11-03 21:57:49699 ExtensionRuntimeData();
700 ~ExtensionRuntimeData();
701 };
702 typedef std::map<std::string, ExtensionRuntimeData> ExtensionRuntimeDataMap;
703
[email protected]cebc3dc2011-04-18 17:15:00704 struct NaClModuleInfo {
705 NaClModuleInfo();
706 ~NaClModuleInfo();
707
708 GURL url;
709 std::string mime_type;
710 };
711 typedef std::list<NaClModuleInfo> NaClModuleInfoList;
712
[email protected]5db9ada2012-04-11 13:48:20713 // Return true if the sync type of |extension| matches |type|.
[email protected]1c321ee2012-05-21 03:02:34714 bool IsCorrectSyncType(const extensions::Extension& extension,
[email protected]a4a147652012-07-03 23:41:32715 syncer::ModelType type)
[email protected]3bdba0d2011-08-23 07:17:30716 const;
717
[email protected]5db9ada2012-04-11 13:48:20718 // Handles setting the extension specific values in |extension_sync_data| to
719 // the current system.
720 // Returns false if the changes were not completely applied and need to be
721 // tried again later.
722 bool ProcessExtensionSyncDataHelper(
723 const extensions::ExtensionSyncData& extension_sync_data,
[email protected]a4a147652012-07-03 23:41:32724 syncer::ModelType type);
[email protected]3bdba0d2011-08-23 07:17:30725
[email protected]81f0d162012-08-15 04:21:47726 enum IncludeFlag {
727 INCLUDE_NONE = 0,
728 INCLUDE_ENABLED = 1 << 0,
729 INCLUDE_DISABLED = 1 << 1,
730 INCLUDE_TERMINATED = 1 << 2
731 };
732
[email protected]32b36c62012-10-24 05:37:41733 // Events to be fired after an extension is reloaded.
734 enum PostReloadEvents {
735 EVENT_NONE = 0,
736 EVENT_LAUNCHED = 1 << 0,
737 EVENT_RESTARTED = 1 << 1,
738 };
739
[email protected]0c6da502009-08-14 22:32:39740 // Look up an extension by ID, optionally including either or both of enabled
741 // and disabled extensions.
[email protected]1c321ee2012-05-21 03:02:34742 const extensions::Extension* GetExtensionByIdInternal(
743 const std::string& id,
[email protected]81f0d162012-08-15 04:21:47744 int include_mask) const;
[email protected]0c6da502009-08-14 22:32:39745
[email protected]fa2416f2011-05-03 08:41:20746 // Adds the given extension to the list of terminated extensions if
747 // it is not already there and unloads it.
[email protected]1c321ee2012-05-21 03:02:34748 void TrackTerminatedExtension(const extensions::Extension* extension);
[email protected]fa2416f2011-05-03 08:41:20749
750 // Removes the extension with the given id from the list of
751 // terminated extensions if it is there.
[email protected]bb7f40952011-01-13 00:21:20752 void UntrackTerminatedExtension(const std::string& id);
753
[email protected]62d30f42009-10-01 22:36:06754 // Handles sending notification that |extension| was loaded.
[email protected]1c321ee2012-05-21 03:02:34755 void NotifyExtensionLoaded(const extensions::Extension* extension);
[email protected]62d30f42009-10-01 22:36:06756
757 // Handles sending notification that |extension| was unloaded.
[email protected]1c321ee2012-05-21 03:02:34758 void NotifyExtensionUnloaded(const extensions::Extension* extension,
[email protected]814a7bf0f2011-08-13 05:30:59759 extension_misc::UnloadedExtensionReason reason);
[email protected]62d30f42009-10-01 22:36:06760
[email protected]32b36c62012-10-24 05:37:41761 // Reloads |extension_id| and then dispatches to it the PostReloadEvents
762 // indicated by |events|.
763 void ReloadExtensionWithEvents(const std::string& extension_id,
764 int events);
765
766 // Returns true if the app with id |extension_id| has any shell windows open.
767 bool HasShellWindows(const std::string& extension_id);
768
[email protected]aab98a52009-12-02 03:22:35769 // Helper that updates the active extension list used for crash reporting.
770 void UpdateActiveExtensionsInCrashReporter();
771
[email protected]cebc3dc2011-04-18 17:15:00772 // We implement some Pepper plug-ins using NaCl to take advantage of NaCl's
773 // strong sandbox. Typically, these NaCl modules are stored in extensions
774 // and registered here. Not all NaCl modules need to register for a MIME
775 // type, just the ones that are responsible for rendering a particular MIME
776 // type, like application/pdf. Note: We only register NaCl modules in the
777 // browser process.
778 void RegisterNaClModule(const GURL& url, const std::string& mime_type);
779 void UnregisterNaClModule(const GURL& url);
780
[email protected]ed0ba002011-05-26 16:55:13781 // Call UpdatePluginListWithNaClModules() after registering or unregistering
782 // a NaCl module to see those changes reflected in the PluginList.
783 void UpdatePluginListWithNaClModules();
784
[email protected]cebc3dc2011-04-18 17:15:00785 NaClModuleInfoList::iterator FindNaClModule(const GURL& url);
786
[email protected]32b36c62012-10-24 05:37:41787 // Performs tasks requested to occur after |extension| loads.
788 void DoPostLoadTasks(const extensions::Extension* extension);
789
[email protected]6cafe35a2012-08-27 22:40:50790 // Launches the platform app associated with |extension_host|.
791 static void LaunchApplication(extensions::ExtensionHost* extension_host);
792
[email protected]32b36c62012-10-24 05:37:41793 // Dispatches a restart event to the platform app associated with
794 // |extension_host|.
795 static void RestartApplication(extensions::ExtensionHost* extension_host);
796
[email protected]65992d52012-09-19 23:05:31797 // Helper to inspect an ExtensionHost after it has been loaded.
798 void InspectExtensionHost(extensions::ExtensionHost* host);
799
[email protected]612a1cb12012-10-17 13:18:03800 // Helper to determine whether we should initially enable an installed
801 // (or upgraded) extension.
802 bool ShouldEnableOnInstall(const extensions::Extension* extension);
803
[email protected]0db124b02012-11-07 04:55:05804 // Helper to determine if an extension is idle, and it should be safe
805 // to update the extension.
806 bool IsExtensionIdle(const std::string& extension_id) const;
807
[email protected]31d8f5f22012-04-02 15:22:08808 // The normal profile associated with this ExtensionService.
[email protected]6ef635e42009-07-26 06:16:12809 Profile* profile_;
810
[email protected]31d8f5f22012-04-02 15:22:08811 // The ExtensionSystem for the profile above.
[email protected]bd306722012-07-11 20:43:59812 extensions::ExtensionSystem* system_;
[email protected]31d8f5f22012-04-02 15:22:08813
[email protected]73c47932010-12-06 18:13:43814 // Preferences for the owning profile (weak reference).
[email protected]45759612012-07-10 17:21:23815 extensions::ExtensionPrefs* extension_prefs_;
[email protected]894bb502009-05-21 22:39:57816
[email protected]adfc5462011-09-21 19:07:13817 // Settings for the owning profile.
[email protected]cccdf0aa2011-11-11 03:43:38818 scoped_ptr<extensions::SettingsFrontend> settings_frontend_;
[email protected]b7f853e282011-08-10 09:24:20819
[email protected]6014d672008-12-05 00:38:25820 // The current list of installed extensions.
[email protected]84df8332011-12-06 18:22:46821 ExtensionSet extensions_;
[email protected]6014d672008-12-05 00:38:25822
[email protected]0c6da502009-08-14 22:32:39823 // The list of installed extensions that have been disabled.
[email protected]84df8332011-12-06 18:22:46824 ExtensionSet disabled_extensions_;
[email protected]0c6da502009-08-14 22:32:39825
[email protected]bb7f40952011-01-13 00:21:20826 // The list of installed extensions that have been terminated.
[email protected]84df8332011-12-06 18:22:46827 ExtensionSet terminated_extensions_;
[email protected]bb7f40952011-01-13 00:21:20828
[email protected]0db124b02012-11-07 04:55:05829 // The list of extension updates that are waiting to be installed.
830 ExtensionSet pending_extension_updates_;
831
[email protected]b2907fd2011-03-25 16:43:37832 // Hold the set of pending extensions.
[email protected]3f213ad2012-07-26 23:39:41833 extensions::PendingExtensionManager pending_extension_manager_;
[email protected]aa142702010-03-26 01:26:33834
[email protected]d7e9a862010-11-03 21:57:49835 // The map of extension IDs to their runtime data.
836 ExtensionRuntimeDataMap extension_runtime_data_;
837
[email protected]6014d672008-12-05 00:38:25838 // The full path to the directory where extensions are installed.
839 FilePath install_directory_;
840
[email protected]e2eb43112009-05-29 21:19:54841 // Whether or not extensions are enabled.
842 bool extensions_enabled_;
843
[email protected]0e34d7892009-06-05 19:17:40844 // Whether to notify users when they attempt to install an extension.
845 bool show_extensions_prompts_;
[email protected]e2eb43112009-05-29 21:19:54846
[email protected]d13950e2009-12-04 01:43:02847 // Used by dispatchers to limit API quota for individual extensions.
848 ExtensionsQuotaService quota_service_;
849
[email protected]432115822011-07-10 15:52:27850 // Record that Init() has been called, and chrome::EXTENSIONS_READY
[email protected]fa6a9102010-11-22 15:38:50851 // has fired.
[email protected]3ecda252010-11-18 19:50:55852 bool ready_;
[email protected]e81dba32009-06-19 20:19:13853
[email protected]93fd78f42009-07-10 16:43:17854 // Our extension updater, if updates are turned on.
[email protected]42a08162012-03-16 18:09:11855 scoped_ptr<extensions::ExtensionUpdater> updater_;
[email protected]93fd78f42009-07-10 16:43:17856
[email protected]e0360f2c2009-12-07 22:34:31857 // The model that tracks extensions with BrowserAction buttons.
858 ExtensionToolbarModel toolbar_model_;
859
[email protected]1eb175082010-02-10 09:26:16860 // Map unloaded extensions' ids to their paths. When a temporarily loaded
[email protected]5fb889382011-06-03 00:29:20861 // extension is unloaded, we lose the information about it and don't have
[email protected]1eb175082010-02-10 09:26:16862 // any in the extension preferences file.
863 typedef std::map<std::string, FilePath> UnloadedExtensionPathMap;
864 UnloadedExtensionPathMap unloaded_extension_paths_;
865
[email protected]f17dbd42010-08-16 23:21:10866 // Map disabled extensions' ids to their paths. When a temporarily loaded
867 // extension is disabled before it is reloaded, keep track of the path so that
868 // it can be re-enabled upon a successful load.
869 typedef std::map<std::string, FilePath> DisabledExtensionPathMap;
870 DisabledExtensionPathMap disabled_extension_paths_;
871
[email protected]4814b512009-11-07 00:12:29872 // Map of inspector cookies that are detached, waiting for an extension to be
873 // reloaded.
874 typedef std::map<std::string, int> OrphanedDevTools;
875 OrphanedDevTools orphaned_dev_tools_;
876
[email protected]32b36c62012-10-24 05:37:41877 // Maps extension ids to a bitmask that indicates which events should be
878 // dispatched to the extension when it is loaded.
879 std::map<std::string, int> on_load_events_;
[email protected]6cafe35a2012-08-27 22:40:50880
[email protected]6c2381d2011-10-19 02:52:53881 content::NotificationRegistrar registrar_;
[email protected]2fb7dc982010-09-29 12:24:28882 PrefChangeRegistrar pref_change_registrar_;
[email protected]4814b512009-11-07 00:12:29883
[email protected]d8c8f25f2011-11-02 18:18:01884 // Keeps track of loading and unloading component extensions.
885 scoped_ptr<extensions::ComponentLoader> component_loader_;
886
[email protected]2e3b5202010-03-23 06:52:41887 // Keeps track of menu items added by extensions.
[email protected]5aeeae12012-07-05 19:13:11888 extensions::MenuManager menu_manager_;
[email protected]2e3b5202010-03-23 06:52:41889
[email protected]c1d05aa2011-06-28 02:07:30890 // Keeps track of app notifications.
[email protected]8d92e0382012-08-01 18:06:52891 scoped_refptr<extensions::AppNotificationManager> app_notification_manager_;
[email protected]c1d05aa2011-06-28 02:07:30892
[email protected]b671760b2010-07-15 21:13:47893 // Keeps track of favicon-sized omnibox icons for extensions.
894 ExtensionIconManager omnibox_icon_manager_;
[email protected]29d0d4ac2010-09-08 21:10:31895 ExtensionIconManager omnibox_popup_icon_manager_;
[email protected]b671760b2010-07-15 21:13:47896
[email protected]b3d62312b12010-10-14 21:10:18897 // Flag to make sure event routers are only initialized once.
898 bool event_routers_initialized_;
899
[email protected]d2e6bd62011-10-24 20:29:07900 scoped_ptr<HistoryExtensionEventRouter> history_event_router_;
[email protected]f825df22011-06-28 17:36:10901
[email protected]5a38dfd2012-07-23 23:22:10902 scoped_ptr<extensions::BrowserEventRouter> browser_event_router_;
[email protected]da55b8d2011-05-26 00:09:49903
[email protected]163ed192012-07-24 19:31:07904 scoped_ptr<extensions::WindowEventRouter> window_event_router_;
905
[email protected]135e4782012-09-19 20:36:52906 scoped_ptr<extensions::PreferenceEventRouter> preference_event_router_;
[email protected]118de7892011-03-16 13:31:40907
[email protected]23d5f172011-10-25 05:49:53908 scoped_ptr<BookmarkExtensionEventRouter> bookmark_event_router_;
[email protected]f825df22011-06-28 17:36:10909
[email protected]92ba7b012012-05-16 03:36:17910 scoped_ptr<extensions::ExtensionCookiesEventRouter> cookies_event_router_;
[email protected]f825df22011-06-28 17:36:10911
912 scoped_ptr<ExtensionManagementEventRouter> management_event_router_;
913
[email protected]31bb5ee62012-09-12 22:58:40914 scoped_ptr<extensions::MediaGalleriesPrivateEventRouter>
915 media_galleries_private_event_router_;
916
[email protected]5ebd6a62012-08-01 23:54:39917 scoped_ptr<extensions::PushMessagingEventRouter>
918 push_messaging_event_router_;
919
[email protected]017ecde92012-04-04 09:11:26920 scoped_ptr<extensions::WebNavigationEventRouter> web_navigation_event_router_;
[email protected]f825df22011-06-28 17:36:10921
[email protected]91aa8a32012-08-07 10:35:33922 scoped_ptr<extensions::FontSettingsEventRouter> font_settings_event_router_;
[email protected]bdd34452012-04-16 15:58:40923
[email protected]9c70e0d92012-07-16 08:39:44924 scoped_ptr<extensions::ExtensionManagedModeEventRouter>
925 managed_mode_event_router_;
[email protected]8a4cf842012-05-16 13:35:30926
[email protected]cab208eb02012-10-18 22:15:23927 scoped_ptr<extensions::ExtensionBluetoothEventRouter> bluetooth_event_router_;
928
[email protected]b16fc2e2011-07-21 21:32:58929#if defined(OS_CHROMEOS)
[email protected]771a6182011-10-05 16:32:52930 scoped_ptr<chromeos::ExtensionInputMethodEventRouter>
931 input_method_event_router_;
[email protected]b16fc2e2011-07-21 21:32:58932#endif
933
[email protected]8e4560b62011-01-14 10:09:14934 // A collection of external extension providers. Each provider reads
935 // a source of external extension information. Examples include the
936 // windows registry and external_extensions.json.
[email protected]5df038b2012-07-16 19:03:27937 extensions::ProviderCollection external_extension_providers_;
[email protected]8e4560b62011-01-14 10:09:14938
939 // Set to true by OnExternalExtensionUpdateUrlFound() when an external
[email protected]94fde232012-04-27 10:22:30940 // extension URL is found, and by CheckForUpdatesSoon() when an update check
941 // has to wait for the external providers. Used in
942 // OnAllExternalProvidersReady() to determine if an update check is needed to
943 // install pending extensions.
944 bool update_once_all_providers_are_ready_;
[email protected]8e4560b62011-01-14 10:09:14945
[email protected]3c4abc82012-10-22 22:25:54946 // Set when the browser is terminating. Prevents us from installing or
947 // updating additional extensions and allows in-progress installations to
948 // decide to abort.
949 bool browser_terminating_;
950
[email protected]cebc3dc2011-04-18 17:15:00951 NaClModuleInfoList nacl_module_list_;
952
[email protected]5db9ada2012-04-11 13:48:20953 extensions::AppSyncBundle app_sync_bundle_;
954 extensions::ExtensionSyncBundle extension_sync_bundle_;
[email protected]3bdba0d2011-08-23 07:17:30955
[email protected]7c1490da2011-10-11 18:53:25956 // Contains an entry for each warning that shall be currently shown.
957 ExtensionWarningSet extension_warnings_;
958
[email protected]6f371442011-11-09 06:45:46959 extensions::ProcessMap process_map_;
960
[email protected]b1912d592012-08-17 22:29:38961 extensions::AppShortcutManager app_shortcut_manager_;
[email protected]9de83282011-12-12 11:06:37962
[email protected]89226982012-07-16 20:09:18963 scoped_ptr<ExtensionErrorUI> extension_error_ui_;
[email protected]a9aa5932012-01-25 08:27:40964
[email protected]9ce11d22012-08-08 23:20:13965#if defined(ENABLE_EXTENSIONS)
[email protected]c77f2352012-08-08 22:07:58966 scoped_ptr<extensions::ExtensionActionStorageManager>
967 extension_action_storage_manager_;
[email protected]9ce11d22012-08-08 23:20:13968#endif
[email protected]c77f2352012-08-08 22:07:58969
[email protected]eaa7dd182010-12-14 11:09:00970 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]c2c263c2010-08-13 21:59:48971 InstallAppsWithUnlimtedStorage);
[email protected]eaa7dd182010-12-14 11:09:00972 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]654512b2010-09-01 02:09:42973 InstallAppsAndCheckStorageProtection);
[email protected]eaa7dd182010-12-14 11:09:00974 DISALLOW_COPY_AND_ASSIGN(ExtensionService);
[email protected]6014d672008-12-05 00:38:25975};
976
[email protected]eaa7dd182010-12-14 11:09:00977#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SERVICE_H_