blob: c0ce5ecde11521e8eb7a07c4c181bdb98bd40615 [file] [log] [blame]
[email protected]8e4560b62011-01-14 10:09:141// Copyright (c) 2011 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#include "chrome/browser/extensions/extension_service.h"
[email protected]6014d672008-12-05 00:38:256
[email protected]654512b2010-09-01 02:09:427#include <algorithm>
[email protected]97d2f1d2011-01-15 00:41:088#include <set>
[email protected]654512b2010-09-01 02:09:429
[email protected]24b538a2010-02-27 01:22:4410#include "base/basictypes.h"
[email protected]e2eb43112009-05-29 21:19:5411#include "base/command_line.h"
[email protected]6014d672008-12-05 00:38:2512#include "base/file_util.h"
[email protected]14908b72011-04-20 06:54:3613#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3814#include "base/metrics/histogram.h"
[email protected]cebc3dc2011-04-18 17:15:0015#include "base/path_service.h"
[email protected]cd500f72010-06-25 23:44:3216#include "base/stl_util-inl.h"
[email protected]24b538a2010-02-27 01:22:4417#include "base/string16.h"
[email protected]e83326f2010-07-31 17:29:2518#include "base/string_number_conversions.h"
[email protected]6014d672008-12-05 00:38:2519#include "base/string_util.h"
[email protected]18d4b6c2010-09-21 03:21:0420#include "base/stringprintf.h"
[email protected]34b99632011-01-01 01:01:0621#include "base/threading/thread_restrictions.h"
[email protected]cc2c3432009-11-06 17:24:3622#include "base/time.h"
[email protected]ce7f62e32010-08-10 23:43:5923#include "base/utf_string_conversions.h"
[email protected]cc655912009-01-29 23:19:1924#include "base/values.h"
[email protected]aa142702010-03-26 01:26:3325#include "base/version.h"
[email protected]15730c42009-09-03 00:03:2026#include "chrome/browser/browser_process.h"
[email protected]18cc5a52011-04-15 16:03:3827#include "chrome/browser/extensions/apps_promo.h"
[email protected]e0785902011-05-19 23:34:1728#include "chrome/browser/extensions/crx_installer.h"
[email protected]5cbe1e22010-01-30 01:18:5629#include "chrome/browser/extensions/extension_accessibility_api.h"
[email protected]840b0db2009-11-20 03:00:3830#include "chrome/browser/extensions/extension_bookmarks_module.h"
[email protected]b68d5ed2009-04-16 02:41:2831#include "chrome/browser/extensions/extension_browser_event_router.h"
[email protected]2c5e1e12010-06-10 13:14:4432#include "chrome/browser/extensions/extension_cookies_api.h"
[email protected]c10da4b02010-03-25 14:38:3233#include "chrome/browser/extensions/extension_data_deleter.h"
[email protected]14a000d2010-04-29 21:44:2434#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]de768a832009-10-30 05:25:0135#include "chrome/browser/extensions/extension_history_api.h"
[email protected]b1748b1d82009-11-30 20:32:5636#include "chrome/browser/extensions/extension_host.h"
[email protected]5fb889382011-06-03 00:29:2037#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]7596ce72010-08-30 05:10:4638#include "chrome/browser/extensions/extension_management_api.h"
[email protected]118de7892011-03-16 13:31:4039#include "chrome/browser/extensions/extension_preference_api.h"
[email protected]4814b512009-11-07 00:12:2940#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]8a661f82010-10-19 21:47:1141#include "chrome/browser/extensions/extension_processes_api.h"
[email protected]19eb80152011-02-26 00:28:4342#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]90310d92011-04-17 07:35:0443#include "chrome/browser/extensions/extension_sync_data.h"
[email protected]93fd78f42009-07-10 16:43:1744#include "chrome/browser/extensions/extension_updater.h"
[email protected]8f9d4eb2011-02-05 01:39:1045#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]784688a62010-09-13 07:06:5246#include "chrome/browser/extensions/extension_webnavigation_api.h"
[email protected]8e4560b62011-01-14 10:09:1447#include "chrome/browser/extensions/external_extension_provider_impl.h"
[email protected]42b795652011-02-22 23:32:3848#include "chrome/browser/extensions/external_extension_provider_interface.h"
[email protected]b2907fd2011-03-25 16:43:3749#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]56ad3792010-05-28 17:45:3350#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]37858e52010-08-26 00:22:0251#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3352#include "chrome/browser/profiles/profile.h"
[email protected]8e5c89a2011-06-07 18:13:3353#include "chrome/browser/search_engines/template_url_service.h"
54#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]18280372011-03-22 18:05:2255#include "chrome/browser/themes/theme_service.h"
[email protected]a0ea76c2011-03-23 17:36:4256#include "chrome/browser/themes/theme_service_factory.h"
[email protected]c8d407e2011-04-28 21:27:1757#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
58#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]7c5c6f3a2011-04-28 19:56:4959#include "chrome/browser/ui/webui/ntp/shown_sections_handler.h"
[email protected]aab98a52009-12-02 03:22:3560#include "chrome/common/child_process_logging.h"
[email protected]432115822011-07-10 15:52:2761#include "chrome/common/chrome_notification_types.h"
[email protected]cebc3dc2011-04-18 17:15:0062#include "chrome/common/chrome_paths.h"
[email protected]e2eb43112009-05-29 21:19:5463#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5864#include "chrome/common/extensions/extension.h"
[email protected]d7b36dc2009-10-29 21:47:4065#include "chrome/common/extensions/extension_constants.h"
[email protected]05c82182010-06-24 17:49:0866#include "chrome/common/extensions/extension_error_utils.h"
[email protected]7c927b62010-02-24 09:54:1367#include "chrome/common/extensions/extension_file_util.h"
[email protected]c6d474f82009-12-16 21:11:0668#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]77a6970c2011-04-23 16:58:5669#include "chrome/common/extensions/extension_messages.h"
[email protected]a315ba92010-11-16 14:12:2170#include "chrome/common/extensions/extension_resource.h"
[email protected]25b34332009-06-05 21:53:1971#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1472#include "chrome/common/url_constants.h"
[email protected]5f945a0e2011-03-01 17:47:5373#include "content/browser/browser_thread.h"
[email protected]b46442d7e2011-06-29 02:16:0674#include "content/browser/debugger/devtools_manager.h"
[email protected]2de307592011-04-05 21:16:5875#include "content/browser/plugin_process_host.h"
76#include "content/browser/plugin_service.h"
[email protected]77a6970c2011-04-23 16:58:5677#include "content/browser/renderer_host/render_process_host.h"
[email protected]432115822011-07-10 15:52:2778#include "content/common/content_notification_types.h"
[email protected]c3113022011-04-16 03:26:3079#include "content/common/json_value_serializer.h"
[email protected]b3841c502011-03-09 01:21:3180#include "content/common/notification_service.h"
[email protected]cebc3dc2011-04-18 17:15:0081#include "content/common/pepper_plugin_registry.h"
[email protected]c10da4b02010-03-25 14:38:3282#include "googleurl/src/gurl.h"
[email protected]1debbbb62010-10-06 17:23:4483#include "net/base/registry_controlled_domain.h"
[email protected]24b538a2010-02-27 01:22:4484#include "webkit/database/database_tracker.h"
85#include "webkit/database/database_util.h"
[email protected]2de307592011-04-05 21:16:5886#include "webkit/plugins/npapi/plugin_list.h"
[email protected]c64631652009-04-29 22:24:3187
[email protected]eed367e2011-04-12 03:43:3188#if defined(OS_CHROMEOS)
89#include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
[email protected]be5bd5742011-07-14 07:21:0190#include "chrome/browser/chromeos/extensions/input_method_event_router.h"
[email protected]ce9802042011-05-27 10:11:4091#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
[email protected]b777b332011-04-16 04:01:0892#include "webkit/fileapi/file_system_context.h"
93#include "webkit/fileapi/file_system_mount_point_provider.h"
94#include "webkit/fileapi/file_system_path_manager.h"
[email protected]eed367e2011-04-12 03:43:3195#endif
96
[email protected]27072cad2011-05-09 19:46:4097#if defined(OS_CHROMEOS) && defined(TOUCH_UI)
[email protected]c8d4e9462011-06-29 23:18:5798#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]27072cad2011-05-09 19:46:4099#include "chrome/browser/extensions/extension_input_ui_api.h"
100#endif
101
[email protected]5ef47ec2010-01-28 05:58:05102using base::Time;
103
[email protected]c6d474f82009-12-16 21:11:06104namespace errors = extension_manifest_errors;
105
[email protected]b6ab96d2009-08-20 18:58:19106namespace {
107
[email protected]29d0d4ac2010-09-08 21:10:31108#if defined(OS_LINUX)
109static const int kOmniboxIconPaddingLeft = 2;
110static const int kOmniboxIconPaddingRight = 2;
111#elif defined(OS_MACOSX)
112static const int kOmniboxIconPaddingLeft = 0;
113static const int kOmniboxIconPaddingRight = 2;
114#else
115static const int kOmniboxIconPaddingLeft = 0;
116static const int kOmniboxIconPaddingRight = 0;
117#endif
118
[email protected]a315ba92010-11-16 14:12:21119// The following enumeration is used in histograms matching
120// Extensions.ManifestReload* . Values may be added, as long
121// as existing values are not changed.
122enum ManifestReloadReason {
123 NOT_NEEDED = 0, // Reload not needed.
124 UNPACKED_DIR, // Unpacked directory
125 NEEDS_RELOCALIZATION, // The local has changed since we read this extension.
126 NUM_MANIFEST_RELOAD_REASONS
127};
[email protected]2111b1a2010-03-12 18:12:44128
[email protected]a315ba92010-11-16 14:12:21129ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) {
130 // Always reload manifests of unpacked extensions, because they can change
131 // on disk independent of the manifest in our prefs.
132 if (info.extension_location == Extension::LOAD)
133 return UNPACKED_DIR;
134
135 // Reload the manifest if it needs to be relocalized.
136 if (extension_l10n_util::ShouldRelocalizeManifest(info))
137 return NEEDS_RELOCALIZATION;
138
139 return NOT_NEEDED;
[email protected]2111b1a2010-03-12 18:12:44140}
141
[email protected]2de307592011-04-05 21:16:58142static void ForceShutdownPlugin(const FilePath& plugin_path) {
143 PluginProcessHost* plugin =
144 PluginService::GetInstance()->FindNpapiPluginProcess(plugin_path);
145 if (plugin)
146 plugin->ForceShutdown();
147}
148
[email protected]5fb889382011-06-03 00:29:20149// Manages an ExtensionInstallUI for a particular extension.
150class SimpleExtensionLoadPrompt : public ExtensionInstallUI::Delegate {
151 public:
152 SimpleExtensionLoadPrompt(Profile* profile,
153 base::WeakPtr<ExtensionService> extension_service,
154 const Extension* extension);
155 ~SimpleExtensionLoadPrompt();
156
157 void ShowPrompt();
158
159 // ExtensionInstallUI::Delegate
160 virtual void InstallUIProceed();
[email protected]d828fac2011-06-28 05:43:04161 virtual void InstallUIAbort(bool user_initiated);
[email protected]5fb889382011-06-03 00:29:20162
163 private:
164 base::WeakPtr<ExtensionService> extension_service_;
165 scoped_ptr<ExtensionInstallUI> install_ui_;
166 scoped_refptr<const Extension> extension_;
167};
168
169SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt(
170 Profile* profile,
171 base::WeakPtr<ExtensionService> extension_service,
172 const Extension* extension)
173 : extension_service_(extension_service),
174 install_ui_(new ExtensionInstallUI(profile)),
175 extension_(extension) {
176}
177
178SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() {
179}
180
181void SimpleExtensionLoadPrompt::ShowPrompt() {
182 install_ui_->ConfirmInstall(this, extension_);
183}
184
185void SimpleExtensionLoadPrompt::InstallUIProceed() {
186 if (extension_service_.get())
[email protected]8266d662011-07-12 21:53:26187 extension_service_->OnExtensionInstalled(
188 extension_, false); // Not from web store.
[email protected]5fb889382011-06-03 00:29:20189 delete this;
190}
191
[email protected]d828fac2011-06-28 05:43:04192void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) {
[email protected]5fb889382011-06-03 00:29:20193 delete this;
194}
195
[email protected]c6d474f82009-12-16 21:11:06196} // namespace
[email protected]b6ab96d2009-08-20 18:58:19197
[email protected]ad63a792011-06-16 06:41:11198bool ExtensionService::ComponentExtensionInfo::Equals(
199 const ComponentExtensionInfo& other) const {
200 return other.manifest == manifest && other.root_directory == root_directory;
201}
202
[email protected]eaa7dd182010-12-14 11:09:00203ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
[email protected]d7e9a862010-11-03 21:57:49204 : background_page_ready(false),
205 being_upgraded(false) {
206}
207
[email protected]eaa7dd182010-12-14 11:09:00208ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
[email protected]d7e9a862010-11-03 21:57:49209}
210
[email protected]cebc3dc2011-04-18 17:15:00211ExtensionService::NaClModuleInfo::NaClModuleInfo() {
212}
213
214ExtensionService::NaClModuleInfo::~NaClModuleInfo() {
215}
216
[email protected]eaa7dd182010-12-14 11:09:00217// ExtensionService.
[email protected]6014d672008-12-05 00:38:25218
[email protected]eaa7dd182010-12-14 11:09:00219const char* ExtensionService::kInstallDirectoryName = "Extensions";
220const char* ExtensionService::kCurrentVersionFileName = "Current Version";
[email protected]494c06e2009-07-25 01:06:42221
[email protected]eaa7dd182010-12-14 11:09:00222// Implements IO for the ExtensionService.
[email protected]7a4c6852010-09-16 03:44:22223
[email protected]eaa7dd182010-12-14 11:09:00224class ExtensionServiceBackend
[email protected]8e4560b62011-01-14 10:09:14225 : public base::RefCountedThreadSafe<ExtensionServiceBackend> {
[email protected]7a4c6852010-09-16 03:44:22226 public:
[email protected]1f830eb2010-09-28 08:25:14227 // |install_directory| is a path where to look for extensions to load.
[email protected]14908b72011-04-20 06:54:36228 ExtensionServiceBackend(
229 base::WeakPtr<ExtensionService> frontend,
230 const FilePath& install_directory);
[email protected]7a4c6852010-09-16 03:44:22231
232 // Loads a single extension from |path| where |path| is the top directory of
[email protected]e49002a2011-07-13 03:40:44233 // a specific extension where its manifest file lives. If |prompt_for_plugins|
234 // is true and the extension contains plugins, we prompt the user before
235 // loading.
[email protected]7a4c6852010-09-16 03:44:22236 // Errors are reported through ExtensionErrorReporter. On success,
[email protected]49cd1572011-02-08 21:38:45237 // AddExtension() is called.
[email protected]7a4c6852010-09-16 03:44:22238 // TODO(erikkay): It might be useful to be able to load a packed extension
239 // (presumably into memory) without installing it.
[email protected]e49002a2011-07-13 03:40:44240 void LoadSingleExtension(const FilePath &path, bool prompt_for_plugins);
[email protected]7a4c6852010-09-16 03:44:22241
[email protected]7a4c6852010-09-16 03:44:22242 private:
[email protected]eaa7dd182010-12-14 11:09:00243 friend class base::RefCountedThreadSafe<ExtensionServiceBackend>;
[email protected]7a4c6852010-09-16 03:44:22244
[email protected]eaa7dd182010-12-14 11:09:00245 virtual ~ExtensionServiceBackend();
[email protected]7a4c6852010-09-16 03:44:22246
[email protected]d10f4602011-06-16 15:44:50247 // LoadSingleExtension needs to check the file access preference, which needs
248 // to happen back on the UI thread, so it posts CheckExtensionFileAccess on
249 // the UI thread. In turn, once that gets the pref, it goes back to the
250 // file thread with LoadSingleExtensionWithFileAccess.
[email protected]e49002a2011-07-13 03:40:44251 void CheckExtensionFileAccess(const FilePath& extension_path,
252 bool prompt_for_plugins);
[email protected]d10f4602011-06-16 15:44:50253 void LoadSingleExtensionWithFileAccess(
[email protected]e49002a2011-07-13 03:40:44254 const FilePath &path, bool allow_file_access, bool prompt_for_plugins);
[email protected]d10f4602011-06-16 15:44:50255
[email protected]7a4c6852010-09-16 03:44:22256 // Notify the frontend that there was an error loading an extension.
257 void ReportExtensionLoadError(const FilePath& extension_path,
258 const std::string& error);
259
[email protected]14908b72011-04-20 06:54:36260 // Notify the frontend that an extension was installed.
[email protected]e49002a2011-07-13 03:40:44261 void OnLoadSingleExtension(const scoped_refptr<const Extension>& extension,
262 bool prompt_for_plugins);
[email protected]14908b72011-04-20 06:54:36263
264 base::WeakPtr<ExtensionService> frontend_;
[email protected]7a4c6852010-09-16 03:44:22265
266 // The top-level extensions directory being installed to.
267 FilePath install_directory_;
268
[email protected]eaa7dd182010-12-14 11:09:00269 DISALLOW_COPY_AND_ASSIGN(ExtensionServiceBackend);
[email protected]7a4c6852010-09-16 03:44:22270};
271
[email protected]eaa7dd182010-12-14 11:09:00272ExtensionServiceBackend::ExtensionServiceBackend(
[email protected]14908b72011-04-20 06:54:36273 base::WeakPtr<ExtensionService> frontend,
[email protected]aebe23a32010-12-10 22:15:48274 const FilePath& install_directory)
[email protected]14908b72011-04-20 06:54:36275 : frontend_(frontend),
276 install_directory_(install_directory) {
277 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]7a4c6852010-09-16 03:44:22278}
279
[email protected]eaa7dd182010-12-14 11:09:00280ExtensionServiceBackend::~ExtensionServiceBackend() {
[email protected]14908b72011-04-20 06:54:36281 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
282 BrowserThread::CurrentlyOn(BrowserThread::FILE));
[email protected]7a4c6852010-09-16 03:44:22283}
284
[email protected]e49002a2011-07-13 03:40:44285void ExtensionServiceBackend::LoadSingleExtension(const FilePath& path_in,
286 bool prompt_for_plugins) {
[email protected]a29a517a2011-01-21 21:11:12287 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
[email protected]a8af9fdb2010-10-28 21:52:20288
[email protected]7a4c6852010-09-16 03:44:22289 FilePath extension_path = path_in;
290 file_util::AbsolutePath(&extension_path);
291
[email protected]e49002a2011-07-13 03:40:44292 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
293 NewRunnableMethod(this,
294 &ExtensionServiceBackend::CheckExtensionFileAccess,
295 extension_path, prompt_for_plugins));
[email protected]d10f4602011-06-16 15:44:50296}
297
298void ExtensionServiceBackend::CheckExtensionFileAccess(
[email protected]e49002a2011-07-13 03:40:44299 const FilePath& extension_path, bool prompt_for_plugins) {
[email protected]d10f4602011-06-16 15:44:50300 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
301 std::string id = Extension::GenerateIdForPath(extension_path);
302 // Unpacked extensions default to allowing file access, but if that has been
303 // overridden, don't reset the value.
304 bool allow_file_access =
305 Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) &&
306 !frontend_->extension_prefs()->HasAllowFileAccessSetting(id);
307
[email protected]e49002a2011-07-13 03:40:44308 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
309 NewRunnableMethod(
310 this,
311 &ExtensionServiceBackend::LoadSingleExtensionWithFileAccess,
312 extension_path, allow_file_access, prompt_for_plugins));
[email protected]d10f4602011-06-16 15:44:50313}
314
[email protected]d10f4602011-06-16 15:44:50315void ExtensionServiceBackend::LoadSingleExtensionWithFileAccess(
[email protected]e49002a2011-07-13 03:40:44316 const FilePath& extension_path,
317 bool allow_file_access,
318 bool prompt_for_plugins) {
[email protected]d10f4602011-06-16 15:44:50319 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
320 int flags = allow_file_access ?
[email protected]3aff9ad2011-04-01 20:26:48321 Extension::ALLOW_FILE_ACCESS : Extension::NO_FLAGS;
[email protected]83048a22011-03-29 00:14:13322 if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD))
323 flags |= Extension::STRICT_ERROR_CHECKS;
[email protected]7a4c6852010-09-16 03:44:22324 std::string error;
[email protected]ad8e04a2010-11-01 04:16:27325 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
[email protected]7a4c6852010-09-16 03:44:22326 extension_path,
[email protected]92888082010-10-18 19:24:57327 Extension::LOAD,
[email protected]83048a22011-03-29 00:14:13328 flags,
[email protected]ad8e04a2010-11-01 04:16:27329 &error));
[email protected]7a4c6852010-09-16 03:44:22330
331 if (!extension) {
[email protected]e49002a2011-07-13 03:40:44332 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
333 NewRunnableMethod(
334 this,
335 &ExtensionServiceBackend::ReportExtensionLoadError,
336 extension_path, error));
[email protected]7a4c6852010-09-16 03:44:22337 return;
338 }
339
[email protected]7a4c6852010-09-16 03:44:22340 // Report this as an installed extension so that it gets remembered in the
341 // prefs.
[email protected]e49002a2011-07-13 03:40:44342 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
343 NewRunnableMethod(
344 this,
345 &ExtensionServiceBackend::OnLoadSingleExtension,
346 extension, prompt_for_plugins));
[email protected]7a4c6852010-09-16 03:44:22347}
348
[email protected]eaa7dd182010-12-14 11:09:00349void ExtensionServiceBackend::ReportExtensionLoadError(
[email protected]7a4c6852010-09-16 03:44:22350 const FilePath& extension_path, const std::string &error) {
[email protected]14908b72011-04-20 06:54:36351 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
352 if (frontend_.get())
353 frontend_->ReportExtensionLoadError(
[email protected]432115822011-07-10 15:52:27354 extension_path, error, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
[email protected]14908b72011-04-20 06:54:36355 true /* alert_on_error */);
356}
357
[email protected]5fb889382011-06-03 00:29:20358void ExtensionServiceBackend::OnLoadSingleExtension(
[email protected]e49002a2011-07-13 03:40:44359 const scoped_refptr<const Extension>& extension, bool prompt_for_plugins) {
[email protected]14908b72011-04-20 06:54:36360 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
361 if (frontend_.get())
[email protected]e49002a2011-07-13 03:40:44362 frontend_->OnLoadSingleExtension(extension, prompt_for_plugins);
[email protected]7a4c6852010-09-16 03:44:22363}
364
[email protected]8e4560b62011-01-14 10:09:14365void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12366 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20367
[email protected]7a4c6852010-09-16 03:44:22368 // Check if the providers know about this extension.
[email protected]0a60a2e2010-10-25 16:15:21369 ProviderCollection::const_iterator i;
370 for (i = external_extension_providers_.begin();
371 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14372 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21373 if (i->get()->HasExtension(id))
374 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22375 }
376
[email protected]0f48fca2011-05-19 18:46:35377 // We get the list of external extensions to check from preferences.
378 // It is possible that an extension has preferences but is not loaded.
379 // For example, an extension that requires experimental permissions
380 // will not be loaded if the experimental command line flag is not used.
381 // In this case, do not uninstall.
382 const Extension* extension = GetInstalledExtension(id);
383 if (!extension) {
384 // We can't call UninstallExtension with an unloaded/invalid
385 // extension ID.
386 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
387 << "with id: " << id;
388 return;
389 }
[email protected]d6ebc9792011-04-07 18:18:33390 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22391}
392
[email protected]8e4560b62011-01-14 10:09:14393void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22394 external_extension_providers_.clear();
395}
396
[email protected]8e4560b62011-01-14 10:09:14397void ExtensionService::AddProviderForTesting(
398 ExternalExtensionProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12399 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21400 external_extension_providers_.push_back(
[email protected]8e4560b62011-01-14 10:09:14401 linked_ptr<ExternalExtensionProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22402}
403
[email protected]8e4560b62011-01-14 10:09:14404void ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22405 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42406 const GURL& update_url,
407 Extension::Location location) {
[email protected]ab22ba42011-01-14 16:36:38408 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
409 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20410
[email protected]8e4560b62011-01-14 10:09:14411 if (GetExtensionById(id, true)) {
[email protected]7a4c6852010-09-16 03:44:22412 // Already installed. Do not change the update URL that the extension set.
413 return;
414 }
[email protected]b2907fd2011-03-25 16:43:37415 pending_extension_manager()->AddFromExternalUpdateUrl(
416 id, update_url, location);
[email protected]a29a517a2011-01-21 21:11:12417 external_extension_url_added_ |= true;
[email protected]7a4c6852010-09-16 03:44:22418}
419
[email protected]eaa7dd182010-12-14 11:09:00420bool ExtensionService::IsDownloadFromGallery(const GURL& download_url,
[email protected]a29a517a2011-01-21 21:11:12421 const GURL& referrer_url) {
[email protected]d3071992010-10-08 15:24:07422 // Special-case the themes mini-gallery.
423 // TODO(erikkay) When that gallery goes away, remove this code.
424 if (IsDownloadFromMiniGallery(download_url) &&
425 StartsWithASCII(referrer_url.spec(),
426 extension_urls::kMiniGalleryBrowsePrefix, false)) {
[email protected]334e04a2010-06-24 23:34:44427 return true;
[email protected]1debbbb62010-10-06 17:23:44428 }
[email protected]473ff6e2010-05-12 15:31:55429
[email protected]9adb9692010-10-29 23:14:02430 const Extension* download_extension = GetExtensionByWebExtent(download_url);
431 const Extension* referrer_extension = GetExtensionByWebExtent(referrer_url);
432 const Extension* webstore_app = GetWebStoreApp();
[email protected]d3071992010-10-08 15:24:07433
434 bool referrer_valid = (referrer_extension == webstore_app);
435 bool download_valid = (download_extension == webstore_app);
436
437 // If the command-line gallery URL is set, then be a bit more lenient.
438 GURL store_url =
439 GURL(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
440 switches::kAppsGalleryURL));
441 if (!store_url.is_empty()) {
442 std::string store_tld =
443 net::RegistryControlledDomainService::GetDomainAndRegistry(store_url);
444 if (!referrer_valid) {
445 std::string referrer_tld =
446 net::RegistryControlledDomainService::GetDomainAndRegistry(
447 referrer_url);
448 // The referrer gets stripped when transitioning from https to http,
449 // or when hitting an unknown test cert and that commonly happens in
450 // testing environments. Given this, we allow an empty referrer when
451 // the command-line flag is set.
452 // Otherwise, the TLD must match the TLD of the command-line url.
453 referrer_valid = referrer_url.is_empty() || (referrer_tld == store_tld);
454 }
455
456 if (!download_valid) {
457 std::string download_tld =
458 net::RegistryControlledDomainService::GetDomainAndRegistry(
[email protected]04866c42011-05-03 20:03:50459 download_url);
[email protected]d3071992010-10-08 15:24:07460
461 // Otherwise, the TLD must match the TLD of the command-line url.
462 download_valid = (download_tld == store_tld);
463 }
464 }
465
466 return (referrer_valid && download_valid);
[email protected]b7c2f252009-12-08 00:47:23467}
468
[email protected]8266d662011-07-12 21:53:26469bool ExtensionService::IsFromWebStore(const std::string& id) const {
470 return extension_prefs_->IsFromWebStore(id);
471}
472
[email protected]eaa7dd182010-12-14 11:09:00473bool ExtensionService::IsDownloadFromMiniGallery(const GURL& download_url) {
[email protected]ac025282009-12-16 19:16:38474 return StartsWithASCII(download_url.spec(),
475 extension_urls::kMiniGalleryDownloadPrefix,
476 false); // case_sensitive
477}
478
[email protected]d9696672011-03-15 22:45:09479const Extension* ExtensionService::GetInstalledApp(const GURL& url) {
[email protected]ffb204f22010-12-05 23:20:27480 // Check for hosted app.
[email protected]d9696672011-03-15 22:45:09481 const Extension* app = GetExtensionByWebExtent(url);
482 if (app)
483 return app;
[email protected]ffb204f22010-12-05 23:20:27484
485 // Check for packaged app.
[email protected]d9696672011-03-15 22:45:09486 app = GetExtensionByURL(url);
487 if (app && app->is_app())
488 return app;
489
490 return NULL;
491}
492
493bool ExtensionService::IsInstalledApp(const GURL& url) {
494 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27495}
496
[email protected]da5683db2011-04-23 17:12:21497void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id,
498 const Extension* app) {
499 installed_app_hosts_[renderer_child_id] = app;
500}
501
502const Extension* ExtensionService::GetInstalledAppForRenderer(
503 int renderer_child_id) {
504 InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id);
505 if (i == installed_app_hosts_.end())
506 return NULL;
507 return i->second;
508}
509
[email protected]6aeac8342010-10-01 20:21:18510// static
[email protected]d6ebc9792011-04-07 18:18:33511// This function is used to implement the command-line switch
512// --uninstall-extension. The LOG statements within this function are used to
513// inform the user if the uninstall cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00514bool ExtensionService::UninstallExtensionHelper(
515 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18516 const std::string& extension_id) {
[email protected]6aeac8342010-10-01 20:21:18517
[email protected]95da88c42011-03-31 10:07:33518 const Extension* extension =
[email protected]8001df22011-04-28 19:59:47519 extensions_service->GetInstalledExtension(extension_id);
[email protected]95da88c42011-03-31 10:07:33520
[email protected]d6ebc9792011-04-07 18:18:33521 // We can't call UninstallExtension with an invalid extension ID.
[email protected]95da88c42011-03-31 10:07:33522 if (!extension) {
[email protected]6aeac8342010-10-01 20:21:18523 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33524 << "id: " << extension_id;
525 return false;
[email protected]6aeac8342010-10-01 20:21:18526 }
527
[email protected]d6ebc9792011-04-07 18:18:33528 // The following call to UninstallExtension will not allow an uninstall of a
529 // policy-controlled extension.
530 std::string error;
531 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
532 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
533 << ": " << error;
534 return false;
535 }
[email protected]95da88c42011-03-31 10:07:33536
[email protected]6aeac8342010-10-01 20:21:18537 return true;
538}
539
[email protected]eaa7dd182010-12-14 11:09:00540ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24541 const CommandLine* command_line,
542 const FilePath& install_directory,
543 ExtensionPrefs* extension_prefs,
[email protected]0436b102011-04-15 18:30:03544 bool autoupdate_enabled,
545 bool extensions_enabled)
[email protected]14908b72011-04-20 06:54:36546 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
547 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
548 profile_(profile),
[email protected]73c47932010-12-06 18:13:43549 extension_prefs_(extension_prefs),
[email protected]14908b72011-04-20 06:54:36550 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]a9b00ac2009-06-25 21:03:23551 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03552 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13553 show_extensions_prompts_(true),
[email protected]3ecda252010-11-18 19:50:55554 ready_(false),
[email protected]14908b72011-04-20 06:54:36555 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]18cc5a52011-04-15 16:03:38556 apps_promo_(profile->GetPrefs()),
[email protected]b3d62312b12010-10-14 21:10:18557 event_routers_initialized_(false) {
[email protected]a29a517a2011-01-21 21:11:12558 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20559
[email protected]36a784c2009-06-23 06:21:08560 // Figure out if extension installation should be enabled.
[email protected]6d60703b2009-08-29 01:29:23561 if (command_line->HasSwitch(switches::kDisableExtensions)) {
562 extensions_enabled_ = false;
563 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
564 extensions_enabled_ = false;
[email protected]6b75ec32009-08-14 06:37:18565 }
[email protected]36a784c2009-06-23 06:21:08566
[email protected]432115822011-07-10 15:52:27567 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]bc535ee52010-08-31 18:40:32568 NotificationService::AllSources());
[email protected]432115822011-07-10 15:52:27569 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
[email protected]77a6970c2011-04-23 16:58:56570 NotificationService::AllSources());
[email protected]432115822011-07-10 15:52:27571 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]da5683db2011-04-23 17:12:21572 NotificationService::AllSources());
[email protected]2fb7dc982010-09-29 12:24:28573 pref_change_registrar_.Init(profile->GetPrefs());
574 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this);
575 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this);
[email protected]4814b512009-11-07 00:12:29576
[email protected]93fd78f42009-07-10 16:43:17577 // Set up the ExtensionUpdater
578 if (autoupdate_enabled) {
579 int update_frequency = kDefaultUpdateFrequencySeconds;
580 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25581 base::StringToInt(command_line->GetSwitchValueASCII(
582 switches::kExtensionsUpdateFrequency),
583 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17584 }
[email protected]82b6e512011-04-12 20:33:27585 updater_.reset(new ExtensionUpdater(this,
586 extension_prefs,
587 profile->GetPrefs(),
588 profile,
589 update_frequency));
[email protected]93fd78f42009-07-10 16:43:17590 }
591
[email protected]14908b72011-04-20 06:54:36592 backend_ =
593 new ExtensionServiceBackend(weak_ptr_factory_.GetWeakPtr(),
594 install_directory_);
[email protected]8e4560b62011-01-14 10:09:14595
[email protected]0436b102011-04-15 18:30:03596 if (extensions_enabled_) {
[email protected]873531342011-03-09 12:16:05597 ExternalExtensionProviderImpl::CreateExternalProviders(
598 this, profile_, &external_extension_providers_);
599 }
[email protected]b671760b2010-07-15 21:13:47600
[email protected]aa96d3a2010-08-21 08:45:25601 // Use monochrome icons for Omnibox icons.
[email protected]29d0d4ac2010-09-08 21:10:31602 omnibox_popup_icon_manager_.set_monochrome(true);
[email protected]b671760b2010-07-15 21:13:47603 omnibox_icon_manager_.set_monochrome(true);
[email protected]29d0d4ac2010-09-08 21:10:31604 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft,
605 0, kOmniboxIconPaddingRight));
[email protected]cb0e50312011-05-09 15:03:07606
607 // How long is the path to the Extensions directory?
608 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
609 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25610}
611
[email protected]eaa7dd182010-12-14 11:09:00612const ExtensionList* ExtensionService::extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45613 return &extensions_;
614}
615
[email protected]eaa7dd182010-12-14 11:09:00616const ExtensionList* ExtensionService::disabled_extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45617 return &disabled_extensions_;
618}
619
[email protected]bb7f40952011-01-13 00:21:20620const ExtensionList* ExtensionService::terminated_extensions() const {
621 return &terminated_extensions_;
622}
623
[email protected]b2907fd2011-03-25 16:43:37624PendingExtensionManager* ExtensionService::pending_extension_manager() {
625 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45626}
627
[email protected]ad63a792011-06-16 06:41:11628void ExtensionService::UnregisterComponentExtension(
629 const ComponentExtensionInfo& info) {
630 RegisteredComponentExtensions new_component_extension_manifests;
631 for (RegisteredComponentExtensions::iterator it =
632 component_extension_manifests_.begin();
633 it != component_extension_manifests_.end(); ++it) {
634 if (!it->Equals(info))
635 new_component_extension_manifests.push_back(*it);
636 }
637 component_extension_manifests_.swap(new_component_extension_manifests);
638}
639
[email protected]eaa7dd182010-12-14 11:09:00640ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17641 // No need to unload extensions here because they are profile-scoped, and the
642 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17643
[email protected]8e4560b62011-01-14 10:09:14644 ProviderCollection::const_iterator i;
645 for (i = external_extension_providers_.begin();
646 i != external_extension_providers_.end(); ++i) {
647 ExternalExtensionProviderInterface* provider = i->get();
648 provider->ServiceShutdown();
649 }
[email protected]c8bf09be2011-06-25 03:22:27650
651#if defined(OS_CHROMEOS)
652 if (event_routers_initialized_) {
653 ExtensionFileBrowserEventRouter::GetInstance()->
654 StopObservingFileSystemEvents();
655 }
656#endif
[email protected]6014d672008-12-05 00:38:25657}
658
[email protected]eaa7dd182010-12-14 11:09:00659void ExtensionService::InitEventRouters() {
[email protected]b3d62312b12010-10-14 21:10:18660 if (event_routers_initialized_)
661 return;
662
[email protected]f825df22011-06-28 17:36:10663 history_event_router_.reset(new ExtensionHistoryEventRouter());
664 history_event_router_->ObserveProfile(profile_);
[email protected]7da9a8232011-05-27 21:07:11665 ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_);
[email protected]97d2f1d2011-01-15 00:41:08666 browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_));
667 browser_event_router_->Init();
[email protected]118de7892011-03-16 13:31:40668 preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_));
[email protected]f825df22011-06-28 17:36:10669 bookmark_event_router_.reset(new ExtensionBookmarkEventRouter(
670 profile_->GetBookmarkModel()));
671 bookmark_event_router_->Init();
672 cookies_event_router_.reset(new ExtensionCookiesEventRouter(profile_));
673 cookies_event_router_->Init();
674 management_event_router_.reset(new ExtensionManagementEventRouter(profile_));
675 management_event_router_->Init();
[email protected]7da9a8232011-05-27 21:07:11676 ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_);
[email protected]f825df22011-06-28 17:36:10677 web_navigation_event_router_.reset(
678 new ExtensionWebNavigationEventRouter(profile_));
679 web_navigation_event_router_->Init();
[email protected]27072cad2011-05-09 19:46:40680
[email protected]eed367e2011-04-12 03:43:31681#if defined(OS_CHROMEOS)
[email protected]c8bf09be2011-06-25 03:22:27682 ExtensionFileBrowserEventRouter::GetInstance()->ObserveFileSystemEvents(
683 profile_);
[email protected]be5bd5742011-07-14 07:21:01684 // Lazy initialization.
685 chromeos::ExtensionInputMethodEventRouter::GetInstance();
686
[email protected]c8bf09be2011-06-25 03:22:27687 ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_);
[email protected]eed367e2011-04-12 03:43:31688#endif
[email protected]27072cad2011-05-09 19:46:40689
690#if defined(OS_CHROMEOS) && defined(TOUCH_UI)
691 ExtensionInputUiEventRouter::GetInstance()->Init();
692#endif
693
[email protected]b3d62312b12010-10-14 21:10:18694 event_routers_initialized_ = true;
[email protected]c5ae74ab2010-04-15 18:14:37695}
696
[email protected]b2907fd2011-03-25 16:43:37697const Extension* ExtensionService::GetExtensionById(
698 const std::string& id, bool include_disabled) const {
[email protected]8001df22011-04-28 19:59:47699 return GetExtensionByIdInternal(id, true, include_disabled, false);
[email protected]78994ab02010-12-08 18:06:44700}
701
[email protected]eaa7dd182010-12-14 11:09:00702void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12703 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20704
[email protected]fa6a9102010-11-22 15:38:50705 DCHECK(!ready_); // Can't redo init.
[email protected]93fd78f42009-07-10 16:43:17706 DCHECK_EQ(extensions_.size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32707
[email protected]95dd38f2009-10-20 20:09:15708 // Hack: we need to ensure the ResourceDispatcherHost is ready before we load
709 // the first extension, because its members listen for loaded notifications.
710 g_browser_process->resource_dispatcher_host();
711
[email protected]9f1087e2009-06-15 17:29:32712 LoadAllExtensions();
[email protected]894bb502009-05-21 22:39:57713
[email protected]9f1087e2009-06-15 17:29:32714 // TODO(erikkay) this should probably be deferred to a future point
715 // rather than running immediately at startup.
[email protected]93fd78f42009-07-10 16:43:17716 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57717
[email protected]9f1087e2009-06-15 17:29:32718 // TODO(erikkay) this should probably be deferred as well.
719 GarbageCollectExtensions();
[email protected]6014d672008-12-05 00:38:25720}
721
[email protected]420a0ec2011-06-01 01:07:03722bool ExtensionService::UpdateExtension(
723 const std::string& id,
724 const FilePath& extension_path,
725 const GURL& download_url,
726 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12727 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20728
[email protected]b2907fd2011-03-25 16:43:37729 PendingExtensionInfo pending_extension_info;
730 bool is_pending_extension = pending_extension_manager_.GetById(
731 id, &pending_extension_info);
[email protected]8ef78fd2010-08-19 17:14:32732
[email protected]8001df22011-04-28 19:59:47733 const Extension* extension =
734 GetExtensionByIdInternal(id, true, true, false);
[email protected]5eb375e92010-11-26 07:50:41735 if (!is_pending_extension && !extension) {
[email protected]aa142702010-03-26 01:26:33736 LOG(WARNING) << "Will not update extension " << id
737 << " because it is not installed or pending";
738 // Delete extension_path since we're not creating a CrxInstaller
739 // that would do it for us.
[email protected]14908b72011-04-20 06:54:36740 if (!BrowserThread::PostTask(
741 BrowserThread::FILE, FROM_HERE,
742 NewRunnableFunction(
743 extension_file_util::DeleteFile, extension_path, false)))
744 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03745
746 return false;
[email protected]e957fe52009-06-23 16:51:05747 }
748
[email protected]aa142702010-03-26 01:26:33749 // We want a silent install only for non-pending extensions and
750 // pending extensions that have install_silently set.
751 ExtensionInstallUI* client =
[email protected]b2907fd2011-03-25 16:43:37752 (!is_pending_extension || pending_extension_info.install_silently()) ?
[email protected]aa142702010-03-26 01:26:33753 NULL : new ExtensionInstallUI(profile_);
754
[email protected]14908b72011-04-20 06:54:36755 scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(client));
[email protected]6dfbbf82010-03-12 23:09:16756 installer->set_expected_id(id);
[email protected]ec5b50d2010-10-09 16:35:18757 if (is_pending_extension)
[email protected]b2907fd2011-03-25 16:43:37758 installer->set_install_source(pending_extension_info.install_source());
[email protected]5eb375e92010-11-26 07:50:41759 else if (extension)
760 installer->set_install_source(extension->location());
[email protected]0d3e4a22011-06-23 19:02:52761 if (pending_extension_info.install_silently())
762 installer->set_allow_silent_install(true);
[email protected]6dfbbf82010-03-12 23:09:16763 installer->set_delete_source(true);
[email protected]5c8516202010-03-18 21:43:34764 installer->set_original_url(download_url);
[email protected]cb0e50312011-05-09 15:03:07765 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16766 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03767
768 if (out_crx_installer)
769 *out_crx_installer = installer;
770
771 return true;
[email protected]e957fe52009-06-23 16:51:05772}
773
[email protected]eaa7dd182010-12-14 11:09:00774void ExtensionService::ReloadExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12775 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]b65272f2009-08-31 15:47:06776 FilePath path;
[email protected]9adb9692010-10-29 23:14:02777 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40778
[email protected]f17dbd42010-08-16 23:21:10779 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06780 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29781 // If the extension has an inspector open for its background page, detach
782 // the inspector and hang onto a cookie for it, so that we can reattach
783 // later.
784 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager();
785 ExtensionHost* host = manager->GetBackgroundHostForExtension(
786 current_extension);
787 if (host) {
788 // Look for an open inspector for the background page.
789 int devtools_cookie = DevToolsManager::GetInstance()->DetachClientHost(
790 host->render_view_host());
791 if (devtools_cookie >= 0)
792 orphaned_dev_tools_[extension_id] = devtools_cookie;
793 }
794
[email protected]b65272f2009-08-31 15:47:06795 path = current_extension->path();
[email protected]f17dbd42010-08-16 23:21:10796 DisableExtension(extension_id);
797 disabled_extension_paths_[extension_id] = path;
[email protected]1eb175082010-02-10 09:26:16798 } else {
799 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06800 }
801
[email protected]e6090e42010-03-23 22:44:08802 // Check the installed extensions to see if what we're reloading was already
803 // installed.
804 scoped_ptr<ExtensionInfo> installed_extension(
805 extension_prefs_->GetInstalledExtensionInfo(extension_id));
806 if (installed_extension.get() &&
807 installed_extension->extension_manifest.get()) {
808 LoadInstalledExtension(*installed_extension, false);
809 } else {
810 // We should always be able to remember the extension's path. If it's not in
811 // the map, someone failed to update |unloaded_extension_paths_|.
812 CHECK(!path.empty());
813 LoadExtension(path);
814 }
[email protected]9cddd4702009-07-27 22:09:40815}
816
[email protected]fa2416f2011-05-03 08:41:20817bool ExtensionService::UninstallExtension(
818 const std::string& extension_id_unsafe,
819 bool external_uninstall,
820 std::string* error) {
[email protected]a29a517a2011-01-21 21:11:12821 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20822
[email protected]fa2416f2011-05-03 08:41:20823 // Copy the extension identifier since the reference might have been
824 // obtained via Extension::id() and the extension may be deleted in
825 // this function.
826 std::string extension_id(extension_id_unsafe);
827
[email protected]8001df22011-04-28 19:59:47828 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]631cf822009-05-15 07:01:25829
[email protected]e7afe2452010-08-22 16:19:13830 // Callers should not send us nonexistent extensions.
[email protected]aebe23a32010-12-10 22:15:48831 CHECK(extension);
[email protected]9f1087e2009-06-15 17:29:32832
[email protected]831aa212010-03-26 13:55:19833 // Get hold of information we need after unloading, since the extension
834 // pointer will be invalid then.
835 GURL extension_url(extension->url());
836 Extension::Location location(extension->location());
[email protected]95da88c42011-03-31 10:07:33837
838 // Policy change which triggers an uninstall will always set
839 // |external_uninstall| to true so this is the only way to uninstall
840 // managed extensions.
[email protected]d6ebc9792011-04-07 18:18:33841 if (!Extension::UserMayDisable(location) && !external_uninstall) {
842 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27843 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]d6ebc9792011-04-07 18:18:33844 Source<Profile>(profile_),
845 Details<const Extension>(extension));
846 if (error != NULL) {
847 *error = errors::kCannotUninstallManagedExtension;
848 }
849 return false;
850 }
[email protected]95da88c42011-03-31 10:07:33851
[email protected]211030342010-09-30 18:41:06852 UninstalledExtensionInfo uninstalled_extension_info(*extension);
[email protected]831aa212010-03-26 13:55:19853
[email protected]9b217652010-10-08 22:04:23854 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08855 extension->GetType(), 100);
[email protected]fe2dd7742011-04-19 22:52:49856 RecordPermissionMessagesHistogram(
857 extension, "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23858
[email protected]8e5c89a2011-06-07 18:13:33859 TemplateURLService* url_service =
860 TemplateURLServiceFactory::GetForProfile(profile_);
861 if (url_service)
862 url_service->UnregisterExtensionKeyword(extension);
[email protected]56ad3792010-05-28 17:45:33863
[email protected]831aa212010-03-26 13:55:19864 // Unload before doing more cleanup to ensure that nothing is hanging on to
865 // any of these resources.
[email protected]a9f39a312010-12-23 22:14:27866 UnloadExtension(extension_id, UnloadedExtensionInfo::UNINSTALL);
[email protected]831aa212010-03-26 13:55:19867
[email protected]fa2416f2011-05-03 08:41:20868 extension_prefs_->OnExtensionUninstalled(extension_id, location,
[email protected]831aa212010-03-26 13:55:19869 external_uninstall);
[email protected]9f1087e2009-06-15 17:29:32870
871 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]831aa212010-03-26 13:55:19872 if (Extension::LOAD != location) {
[email protected]14908b72011-04-20 06:54:36873 if (!BrowserThread::PostTask(
874 BrowserThread::FILE, FROM_HERE,
875 NewRunnableFunction(
876 &extension_file_util::UninstallExtension,
877 install_directory_,
[email protected]fa2416f2011-05-03 08:41:20878 extension_id)))
[email protected]14908b72011-04-20 06:54:36879 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32880 }
881
[email protected]c10da4b02010-03-25 14:38:32882 ClearExtensionData(extension_url);
[email protected]0dfe05c2011-02-23 23:03:36883 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06884
885 // Notify interested parties that we've uninstalled this extension.
886 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27887 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]211030342010-09-30 18:41:06888 Source<Profile>(profile_),
889 Details<UninstalledExtensionInfo>(&uninstalled_extension_info));
[email protected]d6ebc9792011-04-07 18:18:33890
891 return true;
[email protected]c10da4b02010-03-25 14:38:32892}
893
[email protected]eaa7dd182010-12-14 11:09:00894void ExtensionService::ClearExtensionData(const GURL& extension_url) {
[email protected]c10da4b02010-03-25 14:38:32895 scoped_refptr<ExtensionDataDeleter> deleter(
896 new ExtensionDataDeleter(profile_, extension_url));
897 deleter->StartDeleting();
[email protected]9f1087e2009-06-15 17:29:32898}
899
[email protected]c3cfb012011-04-06 22:07:35900bool ExtensionService::IsExtensionEnabled(
901 const std::string& extension_id) const {
[email protected]36429da2011-07-11 20:25:18902 const Extension* extension =
903 GetExtensionByIdInternal(extension_id, true, false, false);
904 if (extension)
905 return true;
906
907 // If the extension hasn't been loaded yet, check the prefs for it.
908 return extension_prefs_->GetExtensionState(extension_id) ==
909 Extension::ENABLED;
[email protected]c3cfb012011-04-06 22:07:35910}
911
912bool ExtensionService::IsExternalExtensionUninstalled(
913 const std::string& extension_id) const {
914 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
915}
916
[email protected]eaa7dd182010-12-14 11:09:00917void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12918 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20919
[email protected]06f92562011-04-29 19:27:31920 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39921 return;
[email protected]0c6da502009-08-14 22:32:39922
[email protected]b3317ad2011-04-28 23:46:00923 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]1784e83a2009-09-08 21:01:52924
[email protected]06f92562011-04-29 19:27:31925 const Extension* extension =
926 GetExtensionByIdInternal(extension_id, false, true, false);
927 // This can happen if sync enables an extension that is not
928 // installed yet.
929 if (!extension)
930 return;
931
[email protected]0c6da502009-08-14 22:32:39932 // Move it over to the enabled list.
[email protected]00cd9c42010-11-02 20:15:57933 extensions_.push_back(make_scoped_refptr(extension));
[email protected]0c6da502009-08-14 22:32:39934 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
935 disabled_extensions_.end(),
936 extension);
937 disabled_extensions_.erase(iter);
938
[email protected]f681c782010-11-19 11:19:39939 // Make sure any browser action contained within it is not hidden.
940 extension_prefs_->SetBrowserActionVisibility(extension, true);
941
[email protected]62d30f42009-10-01 22:36:06942 NotifyExtensionLoaded(extension);
[email protected]0c6da502009-08-14 22:32:39943}
944
[email protected]eaa7dd182010-12-14 11:09:00945void ExtensionService::DisableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12946 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20947
[email protected]b2ba9962009-12-10 20:10:15948 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:31949 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:52950 return;
[email protected]1784e83a2009-09-08 21:01:52951
[email protected]06f92562011-04-29 19:27:31952 const Extension* extension = GetInstalledExtension(extension_id);
953 // |extension| can be NULL if sync disables an extension that is not
954 // installed yet.
955 if (extension && !Extension::UserMayDisable(extension->location()))
[email protected]95da88c42011-03-31 10:07:33956 return;
957
[email protected]b3317ad2011-04-28 23:46:00958 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]1784e83a2009-09-08 21:01:52959
[email protected]06f92562011-04-29 19:27:31960 extension = GetExtensionByIdInternal(extension_id, true, false, true);
961 if (!extension)
962 return;
963
[email protected]1784e83a2009-09-08 21:01:52964 // Move it over to the disabled list.
[email protected]00cd9c42010-11-02 20:15:57965 disabled_extensions_.push_back(make_scoped_refptr(extension));
[email protected]1784e83a2009-09-08 21:01:52966 ExtensionList::iterator iter = std::find(extensions_.begin(),
967 extensions_.end(),
968 extension);
[email protected]06f92562011-04-29 19:27:31969 if (iter != extensions_.end()) {
970 extensions_.erase(iter);
971 } else {
972 iter = std::find(terminated_extensions_.begin(),
973 terminated_extensions_.end(),
974 extension);
975 terminated_extensions_.erase(iter);
976 }
[email protected]1784e83a2009-09-08 21:01:52977
[email protected]a9f39a312010-12-23 22:14:27978 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE);
[email protected]1784e83a2009-09-08 21:01:52979}
980
[email protected]eaa7dd182010-12-14 11:09:00981void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]8d888c12010-11-30 00:00:25982 CHECK(extension);
983
984 // We only maintain the granted permissions prefs for INTERNAL extensions.
[email protected]139e5732011-03-16 19:29:51985 CHECK_EQ(Extension::INTERNAL, extension->location());
[email protected]8d888c12010-11-30 00:00:25986
[email protected]8d888c12010-11-30 00:00:25987 extension_prefs_->AddGrantedPermissions(extension->id(),
[email protected]0d3e4a22011-06-23 19:02:52988 extension->permission_set());
[email protected]8d888c12010-11-30 00:00:25989}
990
[email protected]eaa7dd182010-12-14 11:09:00991void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]8d888c12010-11-30 00:00:25992 const Extension* extension) {
993 CHECK(extension);
[email protected]fe2dd7742011-04-19 22:52:49994 RecordPermissionMessagesHistogram(
995 extension, "Extensions.Permissions_ReEnable");
[email protected]8d888c12010-11-30 00:00:25996 GrantPermissions(extension);
997 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
998 EnableExtension(extension->id());
999}
1000
[email protected]eaa7dd182010-12-14 11:09:001001void ExtensionService::LoadExtension(const FilePath& extension_path) {
[email protected]e49002a2011-07-13 03:40:441002 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
1003 NewRunnableMethod(backend_.get(),
1004 &ExtensionServiceBackend::LoadSingleExtension,
1005 extension_path, true));
1006}
1007
1008void ExtensionService::LoadExtensionFromCommandLine(
1009 const FilePath& extension_path) {
1010 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
1011 NewRunnableMethod(backend_.get(),
1012 &ExtensionServiceBackend::LoadSingleExtension,
1013 extension_path, false));
[email protected]9f1087e2009-06-15 17:29:321014}
1015
[email protected]eaa7dd182010-12-14 11:09:001016void ExtensionService::LoadComponentExtensions() {
[email protected]1952c7d2010-03-04 23:48:341017 for (RegisteredComponentExtensions::iterator it =
1018 component_extension_manifests_.begin();
1019 it != component_extension_manifests_.end(); ++it) {
[email protected]61b55b62011-03-24 09:03:101020 LoadComponentExtension(*it);
[email protected]1952c7d2010-03-04 23:48:341021 }
1022}
1023
[email protected]a964e112011-04-14 21:52:511024const Extension* ExtensionService::LoadComponentExtension(
[email protected]61b55b62011-03-24 09:03:101025 const ComponentExtensionInfo &info) {
1026 JSONStringValueSerializer serializer(info.manifest);
1027 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL));
1028 if (!manifest.get()) {
1029 DLOG(ERROR) << "Failed to parse manifest for extension";
[email protected]a964e112011-04-14 21:52:511030 return NULL;
[email protected]61b55b62011-03-24 09:03:101031 }
1032
[email protected]83048a22011-03-29 00:14:131033 int flags = Extension::REQUIRE_KEY;
1034 if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT))
1035 flags |= Extension::STRICT_ERROR_CHECKS;
[email protected]61b55b62011-03-24 09:03:101036 std::string error;
1037 scoped_refptr<const Extension> extension(Extension::Create(
1038 info.root_directory,
1039 Extension::COMPONENT,
1040 *static_cast<DictionaryValue*>(manifest.get()),
[email protected]83048a22011-03-29 00:14:131041 flags,
[email protected]61b55b62011-03-24 09:03:101042 &error));
1043 if (!extension.get()) {
1044 NOTREACHED() << error;
[email protected]a964e112011-04-14 21:52:511045 return NULL;
[email protected]61b55b62011-03-24 09:03:101046 }
1047 AddExtension(extension);
[email protected]a964e112011-04-14 21:52:511048 return extension;
[email protected]61b55b62011-03-24 09:03:101049}
1050
[email protected]ad63a792011-06-16 06:41:111051void ExtensionService::UnloadComponentExtension(
1052 const ComponentExtensionInfo& info) {
1053 JSONStringValueSerializer serializer(info.manifest);
1054 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL));
1055 if (!manifest.get()) {
1056 DLOG(ERROR) << "Failed to parse manifest for extension";
1057 return;
1058 }
1059 std::string public_key;
1060 std::string public_key_bytes;
1061 std::string id;
1062 if (!static_cast<DictionaryValue*>(manifest.get())->
1063 GetString(extension_manifest_keys::kPublicKey, &public_key) ||
1064 !Extension::ParsePEMKeyBytes(public_key, &public_key_bytes) ||
1065 !Extension::GenerateId(public_key_bytes, &id)) {
1066 DLOG(ERROR) << "Failed to get extension id";
1067 return;
1068 }
1069 UnloadExtension(id, UnloadedExtensionInfo::DISABLE);
1070}
1071
[email protected]eaa7dd182010-12-14 11:09:001072void ExtensionService::LoadAllExtensions() {
[email protected]a29a517a2011-01-21 21:11:121073 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a315ba92010-11-16 14:12:211074
[email protected]cc2c3432009-11-06 17:24:361075 base::TimeTicks start_time = base::TimeTicks::Now();
1076
[email protected]1952c7d2010-03-04 23:48:341077 // Load any component extensions.
1078 LoadComponentExtensions();
1079
[email protected]e72e8eb82009-06-18 17:21:511080 // Load the previously installed extensions.
[email protected]a315ba92010-11-16 14:12:211081 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]e6090e42010-03-23 22:44:081082 extension_prefs_->GetInstalledExtensionsInfo());
[email protected]c6d474f82009-12-16 21:11:061083
[email protected]a315ba92010-11-16 14:12:211084 std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0);
1085 bool should_write_prefs = false;
1086
1087 for (size_t i = 0; i < extensions_info->size(); ++i) {
1088 ExtensionInfo* info = extensions_info->at(i).get();
1089
1090 ManifestReloadReason reload_reason = ShouldReloadExtensionManifest(*info);
1091 ++reload_reason_counts[reload_reason];
1092 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestReloadEnumValue",
1093 reload_reason, 100);
1094
1095 if (reload_reason != NOT_NEEDED) {
1096 // Reloading and extension reads files from disk. We do this on the
1097 // UI thread because reloads should be very rare, and the complexity
1098 // added by delaying the time when the extensions service knows about
1099 // all extensions is significant. See crbug.com/37548 for details.
1100 // |allow_io| disables tests that file operations run on the file
1101 // thread.
1102 base::ThreadRestrictions::ScopedAllowIO allow_io;
1103
[email protected]83048a22011-03-29 00:14:131104 int flags = Extension::NO_FLAGS;
1105 if (Extension::ShouldDoStrictErrorChecking(info->extension_location))
1106 flags |= Extension::STRICT_ERROR_CHECKS;
[email protected]3aff9ad2011-04-01 20:26:481107 if (extension_prefs_->AllowFileAccess(info->extension_id))
1108 flags |= Extension::ALLOW_FILE_ACCESS;
[email protected]a315ba92010-11-16 14:12:211109 std::string error;
1110 scoped_refptr<const Extension> extension(
1111 extension_file_util::LoadExtension(
[email protected]542258c2011-03-04 21:25:311112 info->extension_path,
1113 info->extension_location,
[email protected]83048a22011-03-29 00:14:131114 flags,
[email protected]542258c2011-03-04 21:25:311115 &error));
[email protected]a315ba92010-11-16 14:12:211116
1117 if (extension.get()) {
1118 extensions_info->at(i)->extension_manifest.reset(
1119 static_cast<DictionaryValue*>(
1120 extension->manifest_value()->DeepCopy()));
1121 should_write_prefs = true;
1122 }
[email protected]c6d474f82009-12-16 21:11:061123 }
1124 }
1125
[email protected]a315ba92010-11-16 14:12:211126 for (size_t i = 0; i < extensions_info->size(); ++i) {
1127 LoadInstalledExtension(*extensions_info->at(i), should_write_prefs);
[email protected]c6d474f82009-12-16 21:11:061128 }
1129
[email protected]ae09ca62009-08-21 19:46:461130 OnLoadedInstalledExtensions();
[email protected]cc2c3432009-11-06 17:24:361131
[email protected]a315ba92010-11-16 14:12:211132 // The histograms Extensions.ManifestReload* allow us to validate
1133 // the assumption that reloading manifest is a rare event.
1134 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded",
1135 reload_reason_counts[NOT_NEEDED]);
1136 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir",
1137 reload_reason_counts[UNPACKED_DIR]);
1138 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization",
1139 reload_reason_counts[NEEDS_RELOCALIZATION]);
1140
[email protected]cc2c3432009-11-06 17:24:361141 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", extensions_.size());
1142 UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", disabled_extensions_.size());
1143
[email protected]1952c7d2010-03-04 23:48:341144 UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime",
1145 base::TimeTicks::Now() - start_time);
[email protected]cc2c3432009-11-06 17:24:361146
[email protected]9b217652010-10-08 22:04:231147 int app_count = 0;
1148 int hosted_app_count = 0;
1149 int packaged_app_count = 0;
[email protected]1952c7d2010-03-04 23:48:341150 int user_script_count = 0;
1151 int extension_count = 0;
1152 int theme_count = 0;
1153 int external_count = 0;
1154 int page_action_count = 0;
1155 int browser_action_count = 0;
1156 ExtensionList::iterator ex;
1157 for (ex = extensions_.begin(); ex != extensions_.end(); ++ex) {
[email protected]9b217652010-10-08 22:04:231158 Extension::Location location = (*ex)->location();
[email protected]7fa19f82010-12-21 19:40:081159 Extension::Type type = (*ex)->GetType();
[email protected]9b217652010-10-08 22:04:231160 if ((*ex)->is_app()) {
1161 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation",
1162 location, 100);
1163 } else if (type == Extension::TYPE_EXTENSION) {
1164 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation",
1165 location, 100);
1166 }
1167
[email protected]1952c7d2010-03-04 23:48:341168 // Don't count component extensions, since they are only extensions as an
1169 // implementation detail.
[email protected]9b217652010-10-08 22:04:231170 if (location == Extension::COMPONENT)
[email protected]1952c7d2010-03-04 23:48:341171 continue;
1172
[email protected]e8c729a2010-03-09 19:55:191173 // Don't count unpacked extensions, since they're a developer-specific
1174 // feature.
[email protected]9b217652010-10-08 22:04:231175 if (location == Extension::LOAD)
[email protected]e8c729a2010-03-09 19:55:191176 continue;
1177
[email protected]9b217652010-10-08 22:04:231178 // Using an enumeration shows us the total installed ratio across all users.
1179 // Using the totals per user at each startup tells us the distribution of
1180 // usage for each user (e.g. 40% of users have at least one app installed).
1181 UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100);
1182 switch (type) {
1183 case Extension::TYPE_THEME:
[email protected]a315ba92010-11-16 14:12:211184 ++theme_count;
[email protected]9b217652010-10-08 22:04:231185 break;
1186 case Extension::TYPE_USER_SCRIPT:
[email protected]a315ba92010-11-16 14:12:211187 ++user_script_count;
[email protected]9b217652010-10-08 22:04:231188 break;
1189 case Extension::TYPE_HOSTED_APP:
[email protected]a315ba92010-11-16 14:12:211190 ++app_count;
1191 ++hosted_app_count;
[email protected]9b217652010-10-08 22:04:231192 break;
1193 case Extension::TYPE_PACKAGED_APP:
[email protected]a315ba92010-11-16 14:12:211194 ++app_count;
1195 ++packaged_app_count;
[email protected]9b217652010-10-08 22:04:231196 break;
1197 case Extension::TYPE_EXTENSION:
1198 default:
[email protected]a315ba92010-11-16 14:12:211199 ++extension_count;
[email protected]9b217652010-10-08 22:04:231200 break;
[email protected]cc2c3432009-11-06 17:24:361201 }
[email protected]9b217652010-10-08 22:04:231202 if (Extension::IsExternalLocation(location))
[email protected]a315ba92010-11-16 14:12:211203 ++external_count;
[email protected]9b217652010-10-08 22:04:231204 if ((*ex)->page_action() != NULL)
[email protected]a315ba92010-11-16 14:12:211205 ++page_action_count;
[email protected]9b217652010-10-08 22:04:231206 if ((*ex)->browser_action() != NULL)
[email protected]a315ba92010-11-16 14:12:211207 ++browser_action_count;
[email protected]fe2dd7742011-04-19 22:52:491208
1209 RecordPermissionMessagesHistogram(
1210 ex->get(), "Extensions.Permissions_Load");
[email protected]cc2c3432009-11-06 17:24:361211 }
[email protected]9b217652010-10-08 22:04:231212 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp", app_count);
1213 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadHostedApp", hosted_app_count);
1214 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPackagedApp", packaged_app_count);
[email protected]1952c7d2010-03-04 23:48:341215 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtension", extension_count);
1216 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadUserScript", user_script_count);
1217 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadTheme", theme_count);
1218 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExternal", external_count);
1219 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPageAction", page_action_count);
1220 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadBrowserAction",
1221 browser_action_count);
[email protected]ae09ca62009-08-21 19:46:461222}
1223
[email protected]fe2dd7742011-04-19 22:52:491224// static
1225void ExtensionService::RecordPermissionMessagesHistogram(
1226 const Extension* e, const char* histogram) {
1227 // Since this is called from multiple sources, and since the Histogram macros
1228 // use statics, we need to manually lookup the Histogram ourselves.
1229 base::Histogram* counter = base::LinearHistogram::FactoryGet(
1230 histogram,
1231 1,
[email protected]0d3e4a22011-06-23 19:02:521232 ExtensionPermissionMessage::kEnumBoundary,
1233 ExtensionPermissionMessage::kEnumBoundary + 1,
[email protected]fe2dd7742011-04-19 22:52:491234 base::Histogram::kUmaTargetedHistogramFlag);
1235
[email protected]0d3e4a22011-06-23 19:02:521236 ExtensionPermissionMessages permissions = e->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:491237 if (permissions.empty()) {
[email protected]0d3e4a22011-06-23 19:02:521238 counter->Add(ExtensionPermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:491239 } else {
[email protected]0d3e4a22011-06-23 19:02:521240 for (ExtensionPermissionMessages::iterator it = permissions.begin();
1241 it != permissions.end(); ++it)
1242 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:491243 }
1244}
1245
[email protected]eaa7dd182010-12-14 11:09:001246void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info,
[email protected]542258c2011-03-04 21:25:311247 bool write_to_prefs) {
[email protected]ae09ca62009-08-21 19:46:461248 std::string error;
[email protected]9adb9692010-10-29 23:14:021249 scoped_refptr<const Extension> extension(NULL);
[email protected]306a2bd2010-08-11 14:56:361250 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) {
1251 error = errors::kDisabledByPolicy;
1252 } else if (info.extension_manifest.get()) {
[email protected]83048a22011-03-29 00:14:131253 int flags = Extension::NO_FLAGS;
1254 if (info.extension_location != Extension::LOAD)
1255 flags |= Extension::REQUIRE_KEY;
1256 if (Extension::ShouldDoStrictErrorChecking(info.extension_location))
1257 flags |= Extension::STRICT_ERROR_CHECKS;
[email protected]3aff9ad2011-04-01 20:26:481258 if (extension_prefs_->AllowFileAccess(info.extension_id))
1259 flags |= Extension::ALLOW_FILE_ACCESS;
[email protected]66e4eb32010-10-27 20:37:411260 extension = Extension::Create(
[email protected]542258c2011-03-04 21:25:311261 info.extension_path,
1262 info.extension_location,
1263 *info.extension_manifest,
[email protected]83048a22011-03-29 00:14:131264 flags,
[email protected]542258c2011-03-04 21:25:311265 &error);
[email protected]ae09ca62009-08-21 19:46:461266 } else {
[email protected]c6d474f82009-12-16 21:11:061267 error = errors::kManifestUnreadable;
[email protected]ae09ca62009-08-21 19:46:461268 }
1269
1270 if (!extension) {
[email protected]c6d474f82009-12-16 21:11:061271 ReportExtensionLoadError(info.extension_path,
[email protected]d11c8e92009-10-20 23:26:401272 error,
[email protected]432115822011-07-10 15:52:271273 chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
[email protected]d11c8e92009-10-20 23:26:401274 false);
[email protected]ae09ca62009-08-21 19:46:461275 return;
1276 }
1277
[email protected]c6d474f82009-12-16 21:11:061278 if (write_to_prefs)
1279 extension_prefs_->UpdateManifest(extension);
1280
[email protected]49cd1572011-02-08 21:38:451281 AddExtension(extension);
[email protected]9f1087e2009-06-15 17:29:321282}
1283
[email protected]eaa7dd182010-12-14 11:09:001284void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:421285 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061286 // was loaded, otherwise a race can arise where a renderer that is created
1287 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421288 // that the request context doesn't yet know about. The profile is responsible
1289 // for ensuring its URLRequestContexts appropriately discover the loaded
1290 // extension.
[email protected]c8d407e2011-04-28 21:27:171291 profile_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:061292
[email protected]c8d407e2011-04-28 21:27:171293 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1294 // extension.
[email protected]62d30f42009-10-01 22:36:061295 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271296 chrome::NOTIFICATION_EXTENSION_LOADED,
[email protected]24e7a9d2009-11-04 11:11:341297 Source<Profile>(profile_),
[email protected]9adb9692010-10-29 23:14:021298 Details<const Extension>(extension));
[email protected]2de307592011-04-05 21:16:581299
[email protected]c8d407e2011-04-28 21:27:171300 // Tell renderers about the new extension.
[email protected]77a6970c2011-04-23 16:58:561301 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
1302 !i.IsAtEnd(); i.Advance()) {
[email protected]c8d407e2011-04-28 21:27:171303 RenderProcessHost* host = i.GetCurrentValue();
1304 if (host->profile()->GetOriginalProfile() ==
1305 profile_->GetOriginalProfile()) {
1306 host->Send(
1307 new ExtensionMsg_Loaded(ExtensionMsg_Loaded_Params(extension)));
1308 }
[email protected]77a6970c2011-04-23 16:58:561309 }
1310
[email protected]c8d407e2011-04-28 21:27:171311 // Tell a random-ass collection of other subsystems about the new extension.
1312 // TODO(aa): What should we do with all this goop? Can it move into the
1313 // relevant objects via EXTENSION_LOADED?
1314
1315 profile_->GetExtensionSpecialStoragePolicy()->
1316 GrantRightsForExtension(extension);
1317
1318 UpdateActiveExtensionsInCrashReporter();
1319
1320 ExtensionWebUI::RegisterChromeURLOverrides(
1321 profile_, extension->GetChromeURLOverrides());
1322
[email protected]8e5c89a2011-06-07 18:13:331323 TemplateURLService* url_service =
1324 TemplateURLServiceFactory::GetForProfile(profile_);
1325 if (url_service)
1326 url_service->RegisterExtensionKeyword(extension);
[email protected]c8d407e2011-04-28 21:27:171327
1328 // Load the icon for omnibox-enabled extensions so it will be ready to display
1329 // in the URL bar.
1330 if (!extension->omnibox_keyword().empty()) {
1331 omnibox_popup_icon_manager_.LoadIcon(extension);
1332 omnibox_icon_manager_.LoadIcon(extension);
1333 }
1334
1335 // If the extension has permission to load chrome://favicon/ resources we need
1336 // to make sure that the FaviconSource is registered with the
1337 // ChromeURLDataManager.
1338 if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
1339 FaviconSource* favicon_source = new FaviconSource(profile_,
1340 FaviconSource::FAVICON);
1341 profile_->GetChromeURLDataManager()->AddDataSource(favicon_source);
1342 }
1343
1344 // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757.
[email protected]2de307592011-04-05 21:16:581345 bool plugins_changed = false;
1346 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1347 const Extension::PluginInfo& plugin = extension->plugins()[i];
1348 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
1349 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(plugin.path);
1350 plugins_changed = true;
1351 if (!plugin.is_public) {
1352 PluginService::GetInstance()->RestrictPluginToUrl(
1353 plugin.path, extension->url());
1354 }
1355 }
[email protected]84396dbc2011-04-14 06:33:421356
1357 bool nacl_modules_changed = false;
1358 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1359 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001360 RegisterNaClModule(module.url, module.mime_type);
[email protected]84396dbc2011-04-14 06:33:421361 nacl_modules_changed = true;
1362 }
1363
[email protected]ed0ba002011-05-26 16:55:131364 if (nacl_modules_changed)
1365 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421366
1367 if (plugins_changed || nacl_modules_changed)
[email protected]2de307592011-04-05 21:16:581368 PluginService::GetInstance()->PurgePluginListCache(false);
[email protected]b4d9d122011-06-17 01:58:541369
1370#if defined(OS_CHROMEOS) && defined(TOUCH_UI)
[email protected]c8d4e9462011-06-29 23:18:571371 chromeos::input_method::InputMethodManager* input_method_manager =
1372 chromeos::input_method::InputMethodManager::GetInstance();
[email protected]b4d9d122011-06-17 01:58:541373 for (std::vector<Extension::InputComponentInfo>::const_iterator component =
1374 extension->input_components().begin();
1375 component != extension->input_components().end();
1376 ++component) {
1377 if (component->type == Extension::INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD &&
1378 !component->layouts.empty()) {
1379 const bool is_system =
1380 !Extension::IsExternalLocation(extension->location());
[email protected]c8d4e9462011-06-29 23:18:571381 input_method_manager->RegisterVirtualKeyboard(extension->url(),
[email protected]b4d9d122011-06-17 01:58:541382 component->layouts,
1383 is_system);
1384 }
1385 }
1386#endif
[email protected]62d30f42009-10-01 22:36:061387}
1388
[email protected]a9f39a312010-12-23 22:14:271389void ExtensionService::NotifyExtensionUnloaded(
1390 const Extension* extension, UnloadedExtensionInfo::Reason reason) {
1391 UnloadedExtensionInfo details(extension, reason);
[email protected]62d30f42009-10-01 22:36:061392 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271393 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]24e7a9d2009-11-04 11:11:341394 Source<Profile>(profile_),
[email protected]a9f39a312010-12-23 22:14:271395 Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061396
[email protected]77a6970c2011-04-23 16:58:561397 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
1398 !i.IsAtEnd(); i.Advance()) {
[email protected]c8d407e2011-04-28 21:27:171399 RenderProcessHost* host = i.GetCurrentValue();
1400 if (host->profile()->GetOriginalProfile() ==
1401 profile_->GetOriginalProfile()) {
1402 host->Send(new ExtensionMsg_Unloaded(extension->id()));
1403 }
[email protected]77a6970c2011-04-23 16:58:561404 }
1405
[email protected]dd163fb02011-05-04 22:22:171406 profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]c8d407e2011-04-28 21:27:171407 profile_->GetExtensionSpecialStoragePolicy()->
1408 RevokeRightsForExtension(extension);
1409
1410 ExtensionWebUI::UnregisterChromeURLOverrides(
1411 profile_, extension->GetChromeURLOverrides());
1412
[email protected]b777b332011-04-16 04:01:081413#if defined(OS_CHROMEOS)
1414 // Revoke external file access to
[email protected]c8d407e2011-04-28 21:27:171415 if (profile_->GetFileSystemContext() &&
1416 profile_->GetFileSystemContext()->path_manager() &&
1417 profile_->GetFileSystemContext()->path_manager()->external_provider()) {
1418 profile_->GetFileSystemContext()->path_manager()->external_provider()->
1419 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061420 }
[email protected]c8d407e2011-04-28 21:27:171421#endif
1422
1423 UpdateActiveExtensionsInCrashReporter();
[email protected]2de307592011-04-05 21:16:581424
1425 bool plugins_changed = false;
1426 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1427 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]14908b72011-04-20 06:54:361428 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1429 NewRunnableFunction(&ForceShutdownPlugin,
1430 plugin.path)))
1431 NOTREACHED();
[email protected]2de307592011-04-05 21:16:581432 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
1433 webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath(
1434 plugin.path);
1435 plugins_changed = true;
1436 if (!plugin.is_public)
1437 PluginService::GetInstance()->RestrictPluginToUrl(plugin.path, GURL());
1438 }
[email protected]84396dbc2011-04-14 06:33:421439
1440 bool nacl_modules_changed = false;
1441 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1442 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001443 UnregisterNaClModule(module.url);
[email protected]84396dbc2011-04-14 06:33:421444 nacl_modules_changed = true;
1445 }
1446
[email protected]ed0ba002011-05-26 16:55:131447 if (nacl_modules_changed)
1448 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421449
1450 if (plugins_changed || nacl_modules_changed)
[email protected]2de307592011-04-05 21:16:581451 PluginService::GetInstance()->PurgePluginListCache(false);
[email protected]62d30f42009-10-01 22:36:061452}
1453
[email protected]eaa7dd182010-12-14 11:09:001454void ExtensionService::UpdateExtensionBlacklist(
[email protected]6b75ec32009-08-14 06:37:181455 const std::vector<std::string>& blacklist) {
1456 // Use this set to indicate if an extension in the blacklist has been used.
1457 std::set<std::string> blacklist_set;
1458 for (unsigned int i = 0; i < blacklist.size(); ++i) {
1459 if (Extension::IdIsValid(blacklist[i])) {
1460 blacklist_set.insert(blacklist[i]);
1461 }
1462 }
1463 extension_prefs_->UpdateBlacklist(blacklist_set);
1464 std::vector<std::string> to_be_removed;
1465 // Loop current extensions, unload installed extensions.
1466 for (ExtensionList::const_iterator iter = extensions_.begin();
1467 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021468 const Extension* extension = (*iter);
[email protected]6b75ec32009-08-14 06:37:181469 if (blacklist_set.find(extension->id()) != blacklist_set.end()) {
1470 to_be_removed.push_back(extension->id());
1471 }
1472 }
1473
1474 // UnloadExtension will change the extensions_ list. So, we should
1475 // call it outside the iterator loop.
1476 for (unsigned int i = 0; i < to_be_removed.size(); ++i) {
[email protected]a9f39a312010-12-23 22:14:271477 UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE);
[email protected]6b75ec32009-08-14 06:37:181478 }
1479}
1480
[email protected]0a071a32011-02-08 00:18:241481Profile* ExtensionService::profile() {
1482 return profile_;
1483}
1484
[email protected]eaa7dd182010-12-14 11:09:001485ExtensionPrefs* ExtensionService::extension_prefs() {
[email protected]ddb1e5a2010-12-13 20:10:451486 return extension_prefs_;
1487}
1488
[email protected]b790b072011-05-20 09:46:441489ExtensionContentSettingsStore*
1490 ExtensionService::GetExtensionContentSettingsStore() {
1491 return extension_prefs()->content_settings_store();
1492}
1493
[email protected]2859946f2011-04-04 18:18:061494ExtensionUpdater* ExtensionService::updater() {
1495 return updater_.get();
1496}
1497
[email protected]eaa7dd182010-12-14 11:09:001498void ExtensionService::CheckAdminBlacklist() {
[email protected]aa96d3a2010-08-21 08:45:251499 std::vector<std::string> to_be_removed;
1500 // Loop through extensions list, unload installed extensions.
1501 for (ExtensionList::const_iterator iter = extensions_.begin();
1502 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021503 const Extension* extension = (*iter);
[email protected]aa96d3a2010-08-21 08:45:251504 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id()))
1505 to_be_removed.push_back(extension->id());
1506 }
1507
1508 // UnloadExtension will change the extensions_ list. So, we should
1509 // call it outside the iterator loop.
1510 for (unsigned int i = 0; i < to_be_removed.size(); ++i)
[email protected]a9f39a312010-12-23 22:14:271511 UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE);
[email protected]aa96d3a2010-08-21 08:45:251512}
1513
[email protected]31206602011-04-13 23:07:321514void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351515 if (updater()) {
[email protected]31206602011-04-13 23:07:321516 updater()->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351517 } else {
[email protected]31206602011-04-13 23:07:321518 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351519 }
1520}
1521
[email protected]b05fb9ff2011-04-23 00:07:561522ExtensionSyncData ExtensionService::GetSyncDataHelper(
1523 const Extension& extension) const {
1524 const std::string& id = extension.id();
1525 ExtensionSyncData data;
1526 data.id = id;
1527 data.uninstalled = false;
1528 data.enabled = IsExtensionEnabled(id);
1529 data.incognito_enabled = IsIncognitoEnabled(id);
1530 data.version = *extension.version();
1531 data.update_url = extension.update_url();
1532 data.name = extension.name();
1533 return data;
1534}
1535
1536bool ExtensionService::GetSyncData(
[email protected]85fc9202011-05-05 00:04:591537 const Extension& extension,
[email protected]b05fb9ff2011-04-23 00:07:561538 ExtensionFilter filter,
1539 ExtensionSyncData* extension_sync_data) const {
[email protected]85fc9202011-05-05 00:04:591540 if (!(*filter)(extension)) {
[email protected]b05fb9ff2011-04-23 00:07:561541 return false;
1542 }
[email protected]85fc9202011-05-05 00:04:591543 *extension_sync_data = GetSyncDataHelper(extension);
[email protected]b05fb9ff2011-04-23 00:07:561544 return true;
1545}
1546
1547void ExtensionService::GetSyncDataListHelper(
1548 const ExtensionList& extensions,
1549 ExtensionFilter filter,
1550 std::vector<ExtensionSyncData>* sync_data_list) const {
1551 for (ExtensionList::const_iterator it = extensions.begin();
1552 it != extensions.end(); ++it) {
1553 const Extension& extension = **it;
1554 if ((*filter)(extension)) {
1555 sync_data_list->push_back(GetSyncDataHelper(extension));
1556 }
1557 }
1558}
1559
1560std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList(
1561 ExtensionFilter filter) const {
1562 std::vector<ExtensionSyncData> sync_data_list;
1563 GetSyncDataListHelper(extensions_, filter, &sync_data_list);
1564 GetSyncDataListHelper(disabled_extensions_, filter, &sync_data_list);
[email protected]45b6fee2011-05-03 09:41:311565 GetSyncDataListHelper(terminated_extensions_, filter, &sync_data_list);
[email protected]b05fb9ff2011-04-23 00:07:561566 return sync_data_list;
1567}
1568
[email protected]90310d92011-04-17 07:35:041569void ExtensionService::ProcessSyncData(
1570 const ExtensionSyncData& extension_sync_data,
[email protected]b05fb9ff2011-04-23 00:07:561571 ExtensionFilter filter) {
[email protected]90310d92011-04-17 07:35:041572 const std::string& id = extension_sync_data.id;
1573
1574 // Handle uninstalls first.
1575 if (extension_sync_data.uninstalled) {
1576 std::string error;
1577 if (!UninstallExtensionHelper(this, id)) {
1578 LOG(WARNING) << "Could not uninstall extension " << id
1579 << " for sync";
1580 }
1581 return;
1582 }
1583
[email protected]06f92562011-04-29 19:27:311584 // Set user settings.
1585 if (extension_sync_data.enabled) {
1586 EnableExtension(id);
1587 } else {
1588 DisableExtension(id);
1589 }
[email protected]81b14cc2011-04-29 00:39:371590 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled);
1591
[email protected]06f92562011-04-29 19:27:311592 const Extension* extension = GetInstalledExtension(id);
[email protected]90310d92011-04-17 07:35:041593 if (extension) {
[email protected]06f92562011-04-29 19:27:311594 // If the extension is already installed, check if it's outdated.
[email protected]90310d92011-04-17 07:35:041595 int result = extension->version()->CompareTo(extension_sync_data.version);
1596 if (result < 0) {
1597 // Extension is outdated.
1598 CheckForUpdatesSoon();
1599 } else if (result > 0) {
1600 // Sync version is outdated. Do nothing for now, as sync code
1601 // in other places will eventually update the sync data.
1602 //
1603 // TODO(akalin): Move that code here.
1604 }
[email protected]06f92562011-04-29 19:27:311605 } else {
[email protected]06f92562011-04-29 19:27:311606 // TODO(akalin): Replace silent update with a list of enabled
1607 // permissions.
[email protected]6cc7dbae2011-04-29 21:18:331608 const bool kInstallSilently = true;
[email protected]06f92562011-04-29 19:27:311609 if (!pending_extension_manager()->AddFromSync(
1610 id,
1611 extension_sync_data.update_url,
1612 filter,
[email protected]6cc7dbae2011-04-29 21:18:331613 kInstallSilently)) {
[email protected]06f92562011-04-29 19:27:311614 LOG(WARNING) << "Could not add pending extension for " << id;
1615 return;
1616 }
1617 CheckForUpdatesSoon();
[email protected]90310d92011-04-17 07:35:041618 }
[email protected]90310d92011-04-17 07:35:041619}
1620
[email protected]c3cfb012011-04-06 22:07:351621bool ExtensionService::IsIncognitoEnabled(
1622 const std::string& extension_id) const {
1623 // If this is an existing component extension we always allow it to
1624 // work in incognito mode.
[email protected]81b14cc2011-04-29 00:39:371625 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]c3cfb012011-04-06 22:07:351626 if (extension && extension->location() == Extension::COMPONENT)
[email protected]cb0ce1e022010-03-10 19:54:411627 return true;
1628
1629 // Check the prefs.
[email protected]c3cfb012011-04-06 22:07:351630 return extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]db7331a2010-02-25 22:10:501631}
[email protected]55a35692010-02-11 23:25:211632
[email protected]c3cfb012011-04-06 22:07:351633void ExtensionService::SetIsIncognitoEnabled(
1634 const std::string& extension_id, bool enabled) {
[email protected]81b14cc2011-04-29 00:39:371635 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]c3cfb012011-04-06 22:07:351636 if (extension && extension->location() == Extension::COMPONENT) {
1637 // This shouldn't be called for component extensions.
1638 NOTREACHED();
1639 return;
1640 }
1641
[email protected]8c6c8c22011-03-09 12:52:341642 // Broadcast unloaded and loaded events to update browser state. Only bother
1643 // if the value changed and the extension is actually enabled, since there is
1644 // no UI otherwise.
[email protected]c3cfb012011-04-06 22:07:351645 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]8c6c8c22011-03-09 12:52:341646 if (enabled == old_enabled)
1647 return;
1648
[email protected]c3cfb012011-04-06 22:07:351649 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
[email protected]81b14cc2011-04-29 00:39:371650
1651 // If the extension is enabled (and not terminated), unload and
1652 // reload it to update UI.
1653 const Extension* enabled_extension = GetExtensionById(extension_id, false);
1654 if (enabled_extension) {
1655 NotifyExtensionUnloaded(enabled_extension, UnloadedExtensionInfo::DISABLE);
1656 NotifyExtensionLoaded(enabled_extension);
[email protected]568f33d2010-08-04 17:06:411657 }
[email protected]55a35692010-02-11 23:25:211658}
1659
[email protected]eaa7dd182010-12-14 11:09:001660bool ExtensionService::CanCrossIncognito(const Extension* extension) {
[email protected]2a8f24e2010-11-03 21:37:051661 // We allow the extension to see events and data from another profile iff it
1662 // uses "spanning" behavior and it has incognito access. "split" mode
1663 // extensions only see events for a matching profile.
[email protected]c3cfb012011-04-06 22:07:351664 return IsIncognitoEnabled(extension->id()) &&
1665 !extension->incognito_split_mode();
[email protected]2a8f24e2010-11-03 21:37:051666}
1667
[email protected]5ef7b002011-05-12 23:16:201668bool ExtensionService::CanLoadInIncognito(const Extension* extension) const {
1669 if (extension->is_hosted_app())
1670 return true;
1671 // Packaged apps and regular extensions need to be enabled specifically for
1672 // incognito (and split mode should be set).
1673 return extension->incognito_split_mode() &&
1674 IsIncognitoEnabled(extension->id());
1675}
1676
[email protected]eaa7dd182010-12-14 11:09:001677bool ExtensionService::AllowFileAccess(const Extension* extension) {
[email protected]05c82182010-06-24 17:49:081678 return (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]334e04a2010-06-24 23:34:441679 switches::kDisableExtensionsFileAccessCheck) ||
[email protected]05c82182010-06-24 17:49:081680 extension_prefs_->AllowFileAccess(extension->id()));
1681}
1682
[email protected]eaa7dd182010-12-14 11:09:001683void ExtensionService::SetAllowFileAccess(const Extension* extension,
[email protected]3aff9ad2011-04-01 20:26:481684 bool allow) {
1685 // Reload to update browser state. Only bother if the value changed and the
1686 // extension is actually enabled, since there is no UI otherwise.
1687 bool old_allow = AllowFileAccess(extension);
1688 if (allow == old_allow)
1689 return;
1690
[email protected]05c82182010-06-24 17:49:081691 extension_prefs_->SetAllowFileAccess(extension->id(), allow);
[email protected]3aff9ad2011-04-01 20:26:481692
1693 bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
1694 extension) != extensions_.end();
1695 if (extension_is_enabled)
1696 ReloadExtension(extension->id());
[email protected]05c82182010-06-24 17:49:081697}
1698
[email protected]eaa7dd182010-12-14 11:09:001699bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) {
[email protected]f681c782010-11-19 11:19:391700 return extension_prefs_->GetBrowserActionVisibility(extension);
1701}
1702
[email protected]eaa7dd182010-12-14 11:09:001703void ExtensionService::SetBrowserActionVisibility(const Extension* extension,
[email protected]8e4560b62011-01-14 10:09:141704 bool visible) {
[email protected]f681c782010-11-19 11:19:391705 extension_prefs_->SetBrowserActionVisibility(extension, visible);
1706}
1707
[email protected]8e4560b62011-01-14 10:09:141708// Some extensions will autoupdate themselves externally from Chrome. These
1709// are typically part of some larger client application package. To support
1710// these, the extension will register its location in the the preferences file
1711// (and also, on Windows, in the registry) and this code will periodically
1712// check that location for a .crx file, which it will then install locally if
1713// a new version is available.
1714// Errors are reported through ExtensionErrorReporter. Succcess is not
1715// reported.
[email protected]eaa7dd182010-12-14 11:09:001716void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121717 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141718
1719 // Note that this installation is intentionally silent (since it didn't
1720 // go through the front-end). Extensions that are registered in this
1721 // way are effectively considered 'pre-bundled', and so implicitly
1722 // trusted. In general, if something has HKLM or filesystem access,
1723 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121724
1725 // If any external extension records give a URL, a provider will set
1726 // this to true. Used by OnExternalProviderReady() to see if we need
1727 // to start an update check to fetch a new external extension.
1728 external_extension_url_added_ = false;
[email protected]8e4560b62011-01-14 10:09:141729
1730 // Ask each external extension provider to give us a call back for each
1731 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
1732 ProviderCollection::const_iterator i;
1733 for (i = external_extension_providers_.begin();
1734 i != external_extension_providers_.end(); ++i) {
1735 ExternalExtensionProviderInterface* provider = i->get();
1736 provider->VisitRegisteredExtension();
1737 }
1738
1739 // Uninstall of unclaimed extensions will happen after all the providers
[email protected]a29a517a2011-01-21 21:11:121740 // had reported ready. Every provider calls OnExternalProviderReady()
1741 // when it finishes, and OnExternalProviderReady() only acts when all
1742 // providers are ready. In case there are no providers, we call it
1743 // to trigger removal of extensions that used to have an external source.
1744 if (external_extension_providers_.empty())
1745 OnExternalProviderReady();
[email protected]9f1087e2009-06-15 17:29:321746}
1747
[email protected]8e4560b62011-01-14 10:09:141748void ExtensionService::OnExternalProviderReady() {
[email protected]a29a517a2011-01-21 21:11:121749 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1750
1751 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141752 // if all of them are finished. So we check them first.
1753 ProviderCollection::const_iterator i;
1754 for (i = external_extension_providers_.begin();
1755 i != external_extension_providers_.end(); ++i) {
1756 ExternalExtensionProviderInterface* provider = i->get();
[email protected]a29a517a2011-01-21 21:11:121757 if (!provider->IsReady())
[email protected]8e4560b62011-01-14 10:09:141758 return;
[email protected]8e4560b62011-01-14 10:09:141759 }
1760
[email protected]a29a517a2011-01-21 21:11:121761 // All the providers are ready. Install any pending extensions.
1762 if (external_extension_url_added_ && updater()) {
1763 external_extension_url_added_ = false;
[email protected]8e4560b62011-01-14 10:09:141764 updater()->CheckNow();
1765 }
1766
1767 // Uninstall all the unclaimed extensions.
1768 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
1769 extension_prefs_->GetInstalledExtensionsInfo());
1770 for (size_t i = 0; i < extensions_info->size(); ++i) {
1771 ExtensionInfo* info = extensions_info->at(i).get();
1772 if (Extension::IsExternalLocation(info->extension_location))
1773 CheckExternalUninstall(info->extension_id);
1774 }
[email protected]6c751e72010-11-23 10:11:101775}
1776
[email protected]a9f39a312010-12-23 22:14:271777void ExtensionService::UnloadExtension(
1778 const std::string& extension_id,
1779 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091780 // Make sure the extension gets deleted after we return from this function.
[email protected]9adb9692010-10-29 23:14:021781 scoped_refptr<const Extension> extension(
[email protected]8001df22011-04-28 19:59:471782 GetExtensionByIdInternal(extension_id, true, true, false));
[email protected]631cf822009-05-15 07:01:251783
[email protected]fa0c96732010-11-17 00:14:231784 // This method can be called via PostTask, so the extension may have been
1785 // unloaded by the time this runs.
[email protected]dd163fb02011-05-04 22:22:171786 if (!extension) {
1787 // In case the extension may have crashed/uninstalled. Allow the profile to
1788 // clean up its RequestContexts.
1789 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231790 return;
[email protected]dd163fb02011-05-04 22:22:171791 }
[email protected]0c6da502009-08-14 22:32:391792
[email protected]1eb175082010-02-10 09:26:161793 // Keep information about the extension so that we can reload it later
1794 // even if it's not permanently installed.
1795 unloaded_extension_paths_[extension->id()] = extension->path();
1796
[email protected]f17dbd42010-08-16 23:21:101797 // Clean up if the extension is meant to be enabled after a reload.
1798 disabled_extension_paths_.erase(extension->id());
1799
[email protected]d7e9a862010-11-03 21:57:491800 // Clean up runtime data.
1801 extension_runtime_data_.erase(extension_id);
1802
[email protected]0c6da502009-08-14 22:32:391803 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
1804 disabled_extensions_.end(),
1805 extension.get());
1806 if (iter != disabled_extensions_.end()) {
[email protected]a9f39a312010-12-23 22:14:271807 UnloadedExtensionInfo details(extension, reason);
1808 details.already_disabled = true;
[email protected]0c6da502009-08-14 22:32:391809 disabled_extensions_.erase(iter);
[email protected]866930682009-08-18 22:53:471810 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271811 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]24e7a9d2009-11-04 11:11:341812 Source<Profile>(profile_),
[email protected]a9f39a312010-12-23 22:14:271813 Details<UnloadedExtensionInfo>(&details));
[email protected]dd163fb02011-05-04 22:22:171814 // Make sure the profile cleans up its RequestContexts when an already
1815 // disabled extension is unloaded (since they are also tracking the disabled
1816 // extensions).
1817 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]0c6da502009-08-14 22:32:391818 return;
1819 }
1820
1821 iter = std::find(extensions_.begin(), extensions_.end(), extension.get());
[email protected]894bb502009-05-21 22:39:571822
[email protected]631cf822009-05-15 07:01:251823 // Remove the extension from our list.
1824 extensions_.erase(iter);
1825
[email protected]a9f39a312010-12-23 22:14:271826 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]631cf822009-05-15 07:01:251827}
1828
[email protected]eaa7dd182010-12-14 11:09:001829void ExtensionService::UnloadAllExtensions() {
[email protected]c8d407e2011-04-28 21:27:171830 profile_->GetExtensionSpecialStoragePolicy()->
1831 RevokeRightsForAllExtensions();
1832
[email protected]9f1087e2009-06-15 17:29:321833 extensions_.clear();
[email protected]cd500f72010-06-25 23:44:321834 disabled_extensions_.clear();
[email protected]bb7f40952011-01-13 00:21:201835 terminated_extension_ids_.clear();
1836 terminated_extensions_.clear();
[email protected]d7e9a862010-11-03 21:57:491837 extension_runtime_data_.clear();
[email protected]cd500f72010-06-25 23:44:321838
[email protected]c6e4a3412009-06-24 15:45:291839 // TODO(erikkay) should there be a notification for this? We can't use
1840 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1841 // or uninstalled, and UnloadAll is just part of shutdown.
[email protected]9f1087e2009-06-15 17:29:321842}
1843
[email protected]eaa7dd182010-12-14 11:09:001844void ExtensionService::ReloadExtensions() {
[email protected]9f1087e2009-06-15 17:29:321845 UnloadAllExtensions();
1846 LoadAllExtensions();
1847}
1848
[email protected]eaa7dd182010-12-14 11:09:001849void ExtensionService::GarbageCollectExtensions() {
[email protected]39d9f62c2010-12-03 10:48:501850 if (extension_prefs_->pref_service()->ReadOnly())
[email protected]ba399672010-04-06 15:42:391851 return;
1852
[email protected]ca3dbf52010-05-19 22:27:061853 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info(
1854 extension_prefs_->GetInstalledExtensionsInfo());
1855
1856 std::map<std::string, FilePath> extension_paths;
1857 for (size_t i = 0; i < info->size(); ++i)
1858 extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path;
1859
[email protected]14908b72011-04-20 06:54:361860 if (!BrowserThread::PostTask(
1861 BrowserThread::FILE, FROM_HERE,
1862 NewRunnableFunction(
1863 &extension_file_util::GarbageCollectExtensions,
1864 install_directory_,
1865 extension_paths)))
1866 NOTREACHED();
[email protected]f6ccd652010-11-17 00:48:341867
1868 // Also garbage-collect themes. We check |profile_| to be
1869 // defensive; in the future, we may call GarbageCollectExtensions()
1870 // from somewhere other than Init() (e.g., in a timer).
1871 if (profile_) {
[email protected]18280372011-03-22 18:05:221872 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
[email protected]f6ccd652010-11-17 00:48:341873 }
[email protected]3cf4f0992009-02-03 23:00:301874}
1875
[email protected]eaa7dd182010-12-14 11:09:001876void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]93fd78f42009-07-10 16:43:171877 if (updater_.get()) {
1878 updater_->Start();
1879 }
[email protected]fa6a9102010-11-22 15:38:501880
1881 ready_ = true;
[email protected]e72e8eb82009-06-18 17:21:511882 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271883 chrome::NOTIFICATION_EXTENSIONS_READY,
[email protected]24e7a9d2009-11-04 11:11:341884 Source<Profile>(profile_),
[email protected]e72e8eb82009-06-18 17:21:511885 NotificationService::NoDetails());
1886}
1887
[email protected]49cd1572011-02-08 21:38:451888void ExtensionService::AddExtension(const Extension* extension) {
[email protected]ae09ca62009-08-21 19:46:461889 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:021890 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]9f1087e2009-06-15 17:29:321891
[email protected]c8d407e2011-04-28 21:27:171892 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1893 // default extension state to DISABLED when the --disable-extensions flag
1894 // is set (http://crbug.com/29067).
1895 if (!extensions_enabled() &&
1896 !extension->is_theme() &&
1897 extension->location() != Extension::COMPONENT &&
1898 !Extension::IsExternalLocation(extension->location()))
1899 return;
1900
1901 SetBeingUpgraded(extension, false);
1902
[email protected]1eb175082010-02-10 09:26:161903 // The extension is now loaded, remove its data from unloaded extension map.
1904 unloaded_extension_paths_.erase(extension->id());
1905
[email protected]bb7f40952011-01-13 00:21:201906 // If a terminated extension is loaded, remove it from the terminated list.
1907 UntrackTerminatedExtension(extension->id());
1908
[email protected]f17dbd42010-08-16 23:21:101909 // If the extension was disabled for a reload, then enable it.
1910 if (disabled_extension_paths_.erase(extension->id()) > 0)
1911 EnableExtension(extension->id());
1912
[email protected]d728e002010-12-08 04:46:231913 // Check if the extension's privileges have changed and disable the
1914 // extension if necessary.
[email protected]8d888c12010-11-30 00:00:251915 DisableIfPrivilegeIncrease(extension);
[email protected]0c6da502009-08-14 22:32:391916
[email protected]36429da2011-07-11 20:25:181917 bool disabled = Extension::UserMayDisable(extension->location()) &&
1918 extension_prefs_->GetExtensionState(extension->id()) ==
1919 Extension::DISABLED;
1920 if (disabled) {
[email protected]c8d407e2011-04-28 21:27:171921 disabled_extensions_.push_back(scoped_extension);
1922 // TODO(aa): This seems dodgy. It seems that AddExtension() could get called
1923 // with a disabled extension for other reasons other than that an update was
1924 // disabled.
1925 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271926 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
[email protected]c8d407e2011-04-28 21:27:171927 Source<Profile>(profile_),
1928 Details<const Extension>(extension));
1929 return;
[email protected]e72e8eb82009-06-18 17:21:511930 }
[email protected]aab98a52009-12-02 03:22:351931
[email protected]c8d407e2011-04-28 21:27:171932 extensions_.push_back(scoped_extension);
1933 NotifyExtensionLoaded(extension);
[email protected]aab98a52009-12-02 03:22:351934}
1935
[email protected]eaa7dd182010-12-14 11:09:001936void ExtensionService::DisableIfPrivilegeIncrease(const Extension* extension) {
[email protected]8d888c12010-11-30 00:00:251937 // We keep track of all permissions the user has granted each extension.
1938 // This allows extensions to gracefully support backwards compatibility
1939 // by including unknown permissions in their manifests. When the user
1940 // installs the extension, only the recognized permissions are recorded.
1941 // When the unknown permissions become recognized (e.g., through browser
1942 // upgrade), we can prompt the user to accept these new permissions.
1943 // Extensions can also silently upgrade to less permissions, and then
1944 // silently upgrade to a version that adds these permissions back.
1945 //
1946 // For example, pretend that Chrome 10 includes a permission "omnibox"
1947 // for an API that adds suggestions to the omnibox. An extension can
1948 // maintain backwards compatibility while still having "omnibox" in the
1949 // manifest. If a user installs the extension on Chrome 9, the browser
1950 // will record the permissions it recognized, not including "omnibox."
1951 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1952 // will disable the extension and prompt the user to approve the increase
1953 // in privileges. The extension could then release a new version that
1954 // removes the "omnibox" permission. When the user upgrades, Chrome will
1955 // still remember that "omnibox" had been granted, so that if the
1956 // extension once again includes "omnibox" in an upgrade, the extension
1957 // can upgrade without requiring this user's approval.
1958 const Extension* old = GetExtensionByIdInternal(extension->id(),
[email protected]8001df22011-04-28 19:59:471959 true, true, false);
[email protected]8d888c12010-11-30 00:00:251960 bool is_extension_upgrade = old != NULL;
1961 bool is_privilege_increase = false;
1962
1963 // We only record the granted permissions for INTERNAL extensions, since
1964 // they can't silently increase privileges.
1965 if (extension->location() == Extension::INTERNAL) {
1966 // Add all the recognized permissions if the granted permissions list
1967 // hasn't been initialized yet.
[email protected]0d3e4a22011-06-23 19:02:521968 scoped_ptr<ExtensionPermissionSet> granted_permissions(
1969 extension_prefs_->GetGrantedPermissions(extension->id()));
1970 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:251971
1972 // Here, we check if an extension's privileges have increased in a manner
1973 // that requires the user's approval. This could occur because the browser
1974 // upgraded and recognized additional privileges, or an extension upgrades
1975 // to a version that requires additional privileges.
[email protected]0d3e4a22011-06-23 19:02:521976 is_privilege_increase =
1977 granted_permissions->HasLessPrivilegesThan(extension->permission_set());
[email protected]8d888c12010-11-30 00:00:251978 }
1979
1980 if (is_extension_upgrade) {
[email protected]66e26872010-12-03 20:07:251981 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1982 // that we aren't downgrading.
1983 if (extension->location() != Extension::LOAD)
1984 CHECK(extension->version()->CompareTo(*(old->version())) >= 0);
[email protected]8d888c12010-11-30 00:00:251985
1986 // Extensions get upgraded if the privileges are allowed to increase or
1987 // the privileges haven't increased.
1988 if (!is_privilege_increase) {
1989 SetBeingUpgraded(old, true);
1990 SetBeingUpgraded(extension, true);
1991 }
1992
1993 // To upgrade an extension in place, unload the old one and
1994 // then load the new one.
[email protected]a9f39a312010-12-23 22:14:271995 UnloadExtension(old->id(), UnloadedExtensionInfo::UPDATE);
[email protected]8d888c12010-11-30 00:00:251996 old = NULL;
1997 }
1998
1999 // Extension has changed permissions significantly. Disable it. A
2000 // notification should be sent by the caller.
2001 if (is_privilege_increase) {
[email protected]fe2dd7742011-04-19 22:52:492002 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
2003 RecordPermissionMessagesHistogram(
2004 extension, "Extensions.Permissions_AutoDisable");
2005 }
[email protected]b3317ad2011-04-28 23:46:002006 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:252007 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
2008 }
2009}
2010
[email protected]eaa7dd182010-12-14 11:09:002011void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:392012 std::set<std::string> extension_ids;
[email protected]aab98a52009-12-02 03:22:352013 for (size_t i = 0; i < extensions_.size(); ++i) {
[email protected]2a500c1b2010-11-05 15:27:342014 if (!extensions_[i]->is_theme() &&
2015 extensions_[i]->location() != Extension::COMPONENT)
[email protected]c8865962009-12-16 07:47:392016 extension_ids.insert(extensions_[i]->id());
[email protected]aab98a52009-12-02 03:22:352017 }
2018
2019 child_process_logging::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:252020}
2021
[email protected]e49002a2011-07-13 03:40:442022void ExtensionService::OnLoadSingleExtension(const Extension* extension,
2023 bool prompt_for_plugins) {
[email protected]5fb889382011-06-03 00:29:202024 // If this is a new install of an extension with plugins, prompt the user
2025 // first.
[email protected]e49002a2011-07-13 03:40:442026 if (show_extensions_prompts_ && prompt_for_plugins &&
[email protected]5fb889382011-06-03 00:29:202027 !extension->plugins().empty() &&
2028 disabled_extension_paths_.find(extension->id()) ==
2029 disabled_extension_paths_.end()) {
2030 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
2031 profile_, weak_ptr_factory_.GetWeakPtr(), extension);
2032 prompt->ShowPrompt();
2033 return; // continues in SimpleExtensionLoadPrompt::InstallUI*
2034 }
[email protected]8266d662011-07-12 21:53:262035 OnExtensionInstalled(extension, false); // Not from web store.
[email protected]5fb889382011-06-03 00:29:202036}
2037
[email protected]8266d662011-07-12 21:53:262038void ExtensionService::OnExtensionInstalled(
2039 const Extension* extension, bool from_webstore) {
[email protected]a29a517a2011-01-21 21:11:122040 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:202041
[email protected]4416c5a2010-06-26 01:28:572042 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:022043 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]c3cfb012011-04-06 22:07:352044 const std::string& id = extension->id();
[email protected]6cc7dbae2011-04-29 21:18:332045 bool initial_enable = IsExtensionEnabled(id);
[email protected]b2907fd2011-03-25 16:43:372046
2047 PendingExtensionInfo pending_extension_info;
[email protected]c3cfb012011-04-06 22:07:352048 if (pending_extension_manager()->GetById(id, &pending_extension_info)) {
2049 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:322050
[email protected]483d1ff2011-03-03 17:12:022051 if (!pending_extension_info.ShouldAllowInstall(*extension)) {
[email protected]4416c5a2010-06-26 01:28:572052 LOG(WARNING)
[email protected]ae6cb3022011-04-04 20:11:542053 << "ShouldAllowInstall() returned false for "
[email protected]c3cfb012011-04-06 22:07:352054 << id << " of type " << extension->GetType()
[email protected]7fa19f82010-12-21 19:40:082055 << " and update URL " << extension->update_url().spec()
2056 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:542057
2058 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272059 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED,
[email protected]ae6cb3022011-04-04 20:11:542060 Source<Profile>(profile_),
2061 Details<const Extension>(extension));
2062
[email protected]4416c5a2010-06-26 01:28:572063 // Delete the extension directory since we're not going to
2064 // load it.
[email protected]14908b72011-04-20 06:54:362065 if (!BrowserThread::PostTask(
2066 BrowserThread::FILE, FROM_HERE,
2067 NewRunnableFunction(&extension_file_util::DeleteFile,
2068 extension->path(), true)))
2069 NOTREACHED();
[email protected]4416c5a2010-06-26 01:28:572070 return;
2071 }
[email protected]4416c5a2010-06-26 01:28:572072 } else {
[email protected]c3cfb012011-04-06 22:07:352073 // We explicitly want to re-enable an uninstalled external
2074 // extension; if we're here, that means the user is manually
2075 // installing the extension.
[email protected]6cc7dbae2011-04-29 21:18:332076 if (IsExternalExtensionUninstalled(id)) {
2077 initial_enable = true;
2078 }
[email protected]aa142702010-03-26 01:26:332079 }
2080
[email protected]07533022011-06-27 20:42:552081 // Do not record the install histograms for upgrades.
2082 if (!GetExtensionByIdInternal(extension->id(), true, true, false)) {
2083 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2084 extension->GetType(), 100);
2085 RecordPermissionMessagesHistogram(
2086 extension, "Extensions.Permissions_Install");
2087 }
2088
[email protected]eda3c362010-11-12 08:08:232089 ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension);
[email protected]4416c5a2010-06-26 01:28:572090 extension_prefs_->OnExtensionInstalled(
[email protected]8266d662011-07-12 21:53:262091 extension,
2092 initial_enable ? Extension::ENABLED : Extension::DISABLED,
2093 from_webstore);
[email protected]25b34332009-06-05 21:53:192094
[email protected]3aff9ad2011-04-01 20:26:482095 // Unpacked extensions default to allowing file access, but if that has been
2096 // overridden, don't reset the value.
2097 if (Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) &&
[email protected]c3cfb012011-04-06 22:07:352098 !extension_prefs_->HasAllowFileAccessSetting(id)) {
2099 extension_prefs_->SetAllowFileAccess(id, true);
[email protected]3aff9ad2011-04-01 20:26:482100 }
[email protected]92a5b1d2010-07-20 00:42:002101
[email protected]a3e61e82011-04-15 20:32:082102 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272103 chrome::NOTIFICATION_EXTENSION_INSTALLED,
[email protected]a3e61e82011-04-15 20:32:082104 Source<Profile>(profile_),
2105 Details<const Extension>(extension));
[email protected]7577a5c52009-07-30 06:21:582106
[email protected]49cd1572011-02-08 21:38:452107 // Transfer ownership of |extension| to AddExtension.
2108 AddExtension(scoped_extension);
[email protected]4a190632009-05-09 01:07:422109}
2110
[email protected]eaa7dd182010-12-14 11:09:002111const Extension* ExtensionService::GetExtensionByIdInternal(
[email protected]8001df22011-04-28 19:59:472112 const std::string& id, bool include_enabled, bool include_disabled,
2113 bool include_terminated) const {
[email protected]e957fe52009-06-23 16:51:052114 std::string lowercase_id = StringToLowerASCII(id);
[email protected]0c6da502009-08-14 22:32:392115 if (include_enabled) {
2116 for (ExtensionList::const_iterator iter = extensions_.begin();
2117 iter != extensions_.end(); ++iter) {
2118 if ((*iter)->id() == lowercase_id)
2119 return *iter;
2120 }
2121 }
2122 if (include_disabled) {
2123 for (ExtensionList::const_iterator iter = disabled_extensions_.begin();
2124 iter != disabled_extensions_.end(); ++iter) {
2125 if ((*iter)->id() == lowercase_id)
2126 return *iter;
2127 }
[email protected]ce5c4502009-05-06 16:46:112128 }
[email protected]8001df22011-04-28 19:59:472129 if (include_terminated) {
2130 for (ExtensionList::const_iterator iter = terminated_extensions_.begin();
2131 iter != terminated_extensions_.end(); ++iter) {
2132 if ((*iter)->id() == lowercase_id)
2133 return *iter;
2134 }
2135 }
[email protected]ce5c4502009-05-06 16:46:112136 return NULL;
2137}
2138
[email protected]bb7f40952011-01-13 00:21:202139void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
2140 if (terminated_extension_ids_.insert(extension->id()).second)
2141 terminated_extensions_.push_back(make_scoped_refptr(extension));
[email protected]fa2416f2011-05-03 08:41:202142
2143 UnloadExtension(extension->id(), UnloadedExtensionInfo::DISABLE);
[email protected]bb7f40952011-01-13 00:21:202144}
2145
2146void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202147 std::string lowercase_id = StringToLowerASCII(id);
2148 if (terminated_extension_ids_.erase(lowercase_id) <= 0)
[email protected]bb7f40952011-01-13 00:21:202149 return;
2150
[email protected]bb7f40952011-01-13 00:21:202151 for (ExtensionList::iterator iter = terminated_extensions_.begin();
2152 iter != terminated_extensions_.end(); ++iter) {
2153 if ((*iter)->id() == lowercase_id) {
2154 terminated_extensions_.erase(iter);
2155 return;
2156 }
2157 }
2158}
2159
[email protected]0dfe05c2011-02-23 23:03:362160const Extension* ExtensionService::GetTerminatedExtension(
[email protected]8001df22011-04-28 19:59:472161 const std::string& id) const {
2162 return GetExtensionByIdInternal(id, false, false, true);
2163}
2164
2165const Extension* ExtensionService::GetInstalledExtension(
2166 const std::string& id) const {
2167 return GetExtensionByIdInternal(id, true, true, true);
[email protected]0dfe05c2011-02-23 23:03:362168}
2169
[email protected]eaa7dd182010-12-14 11:09:002170const Extension* ExtensionService::GetWebStoreApp() {
[email protected]d3071992010-10-08 15:24:072171 return GetExtensionById(extension_misc::kWebStoreAppId, false);
2172}
2173
[email protected]eaa7dd182010-12-14 11:09:002174const Extension* ExtensionService::GetExtensionByURL(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:572175 return url.scheme() != chrome::kExtensionScheme ? NULL :
2176 GetExtensionById(url.host(), false);
2177}
2178
[email protected]eaa7dd182010-12-14 11:09:002179const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:572180 for (size_t i = 0; i < extensions_.size(); ++i) {
[email protected]cced75a2011-05-20 08:31:122181 if (extensions_[i]->web_extent().MatchesURL(url))
[email protected]a888b29e62010-04-01 13:38:572182 return extensions_[i];
2183 }
2184 return NULL;
[email protected]9f1087e2009-06-15 17:29:322185}
2186
[email protected]eaa7dd182010-12-14 11:09:002187bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]056ad2a2011-07-12 02:13:552188 // Allow bindings for all packaged extensions.
2189 // Note that GetExtensionByURL may return an Extension for hosted apps
2190 // if the URL came from GetEffectiveURL.
2191 const Extension* extension = GetExtensionByURL(url);
2192 if (extension && extension->GetType() != Extension::TYPE_HOSTED_APP)
[email protected]583d45c12010-08-31 02:48:122193 return true;
2194
2195 // Allow bindings for all component, hosted apps.
[email protected]056ad2a2011-07-12 02:13:552196 if (!extension)
2197 extension = GetExtensionByWebExtent(url);
[email protected]583d45c12010-08-31 02:48:122198 return (extension && extension->location() == Extension::COMPONENT);
2199}
2200
[email protected]eaa7dd182010-12-14 11:09:002201const Extension* ExtensionService::GetExtensionByOverlappingWebExtent(
[email protected]cced75a2011-05-20 08:31:122202 const URLPatternSet& extent) {
[email protected]22c966c2010-06-26 06:35:022203 for (size_t i = 0; i < extensions_.size(); ++i) {
2204 if (extensions_[i]->web_extent().OverlapsWith(extent))
2205 return extensions_[i];
2206 }
2207
[email protected]6d2e60bd2010-06-03 22:37:392208 return NULL;
2209}
2210
[email protected]eaa7dd182010-12-14 11:09:002211const SkBitmap& ExtensionService::GetOmniboxIcon(
[email protected]b671760b2010-07-15 21:13:472212 const std::string& extension_id) {
2213 return omnibox_icon_manager_.GetIcon(extension_id);
2214}
2215
[email protected]eaa7dd182010-12-14 11:09:002216const SkBitmap& ExtensionService::GetOmniboxPopupIcon(
[email protected]29d0d4ac2010-09-08 21:10:312217 const std::string& extension_id) {
2218 return omnibox_popup_icon_manager_.GetIcon(extension_id);
2219}
2220
[email protected]eaa7dd182010-12-14 11:09:002221void ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322222 const std::string& id,
[email protected]8e4560b62011-01-14 10:09:142223 const Version* version,
[email protected]8ef78fd2010-08-19 17:14:322224 const FilePath& path,
2225 Extension::Location location) {
[email protected]ab22ba42011-01-14 16:36:382226 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2227 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012228 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]683d0702010-12-06 16:25:572229 return;
[email protected]a8af9fdb2010-10-28 21:52:202230
[email protected]8e4560b62011-01-14 10:09:142231 DCHECK(version);
2232
[email protected]7577a5c52009-07-30 06:21:582233 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492234 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582235 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022236 const Extension* existing = GetExtensionById(id, true);
[email protected]7577a5c52009-07-30 06:21:582237 if (existing) {
[email protected]8e4560b62011-01-14 10:09:142238 switch (existing->version()->CompareTo(*version)) {
[email protected]7577a5c52009-07-30 06:21:582239 case -1: // existing version is older, we should upgrade
2240 break;
2241 case 0: // existing version is same, do nothing
2242 return;
2243 case 1: // existing version is newer, uh-oh
2244 LOG(WARNING) << "Found external version of extension " << id
2245 << "that is older than current version. Current version "
2246 << "is: " << existing->VersionString() << ". New version "
2247 << "is: " << version << ". Keeping current version.";
2248 return;
2249 }
2250 }
2251
[email protected]b2907fd2011-03-25 16:43:372252 pending_extension_manager()->AddFromExternalFile(id, location);
[email protected]9c635f22010-12-02 09:36:362253
[email protected]14908b72011-04-20 06:54:362254 // no client (silent install)
2255 scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(NULL));
[email protected]6dfbbf82010-03-12 23:09:162256 installer->set_install_source(location);
2257 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072258 installer->set_expected_version(*version);
2259 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]6dfbbf82010-03-12 23:09:162260 installer->InstallCrx(path);
[email protected]7577a5c52009-07-30 06:21:582261}
2262
[email protected]eaa7dd182010-12-14 11:09:002263void ExtensionService::ReportExtensionLoadError(
[email protected]d11c8e92009-10-20 23:26:402264 const FilePath& extension_path,
2265 const std::string &error,
[email protected]432115822011-07-10 15:52:272266 int type,
[email protected]d11c8e92009-10-20 23:26:402267 bool be_noisy) {
2268 NotificationService* service = NotificationService::current();
2269 service->Notify(type,
[email protected]24e7a9d2009-11-04 11:11:342270 Source<Profile>(profile_),
[email protected]d11c8e92009-10-20 23:26:402271 Details<const std::string>(&error));
2272
[email protected]8a205c02011-02-04 20:41:332273 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName());
[email protected]18d4b6c2010-09-21 03:21:042274 std::string message = base::StringPrintf(
2275 "Could not load extension from '%s'. %s",
2276 path_str.c_str(), error.c_str());
[email protected]d11c8e92009-10-20 23:26:402277 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
2278}
2279
[email protected]eaa7dd182010-12-14 11:09:002280void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]406027c02010-09-27 08:03:182281 ExtensionHost* host) {
2282 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332283 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182284 if (iter == orphaned_dev_tools_.end())
2285 return;
2286
2287 DevToolsManager::GetInstance()->AttachClientHost(
2288 iter->second, host->render_view_host());
2289 orphaned_dev_tools_.erase(iter);
2290}
2291
[email protected]432115822011-07-10 15:52:272292void ExtensionService::Observe(int type,
[email protected]fa2416f2011-05-03 08:41:202293 const NotificationSource& source,
2294 const NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272295 switch (type) {
2296 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]bc535ee52010-08-31 18:40:322297 if (profile_ != Source<Profile>(source).ptr()->GetOriginalProfile())
2298 break;
[email protected]a4ed6282009-12-14 20:51:162299
[email protected]f128af42010-08-05 18:05:262300 ExtensionHost* host = Details<ExtensionHost>(details).ptr();
2301
[email protected]fa2416f2011-05-03 08:41:202302 // Mark the extension as terminated and Unload it. We want it to
2303 // be in a consistent state: either fully working or not loaded
2304 // at all, but never half-crashed. We do it in a PostTask so
2305 // that other handlers of this notification will still have
2306 // access to the Extension and ExtensionHost.
[email protected]14908b72011-04-20 06:54:362307 MessageLoop::current()->PostTask(
2308 FROM_HERE,
2309 method_factory_.NewRunnableMethod(
[email protected]fa2416f2011-05-03 08:41:202310 &ExtensionService::TrackTerminatedExtension,
2311 host->extension()));
[email protected]31f77262009-12-02 20:48:532312 break;
2313 }
[email protected]432115822011-07-10 15:52:272314 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
[email protected]77a6970c2011-04-23 16:58:562315 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
2316 // Valid extension function names, used to setup bindings in renderer.
2317 std::vector<std::string> function_names;
2318 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
2319 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
[email protected]31f77262009-12-02 20:48:532320
[email protected]77a6970c2011-04-23 16:58:562321 // Scripting whitelist. This is modified by tests and must be communicated
2322 // to renderers.
2323 process->Send(new ExtensionMsg_SetScriptingWhitelist(
2324 *Extension::GetScriptingWhitelist()));
2325
2326 // Loaded extensions.
2327 for (size_t i = 0; i < extensions_.size(); ++i) {
2328 process->Send(new ExtensionMsg_Loaded(
2329 ExtensionMsg_Loaded_Params(extensions_[i])));
2330 }
2331 break;
2332 }
[email protected]432115822011-07-10 15:52:272333 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]da5683db2011-04-23 17:12:212334 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
2335 installed_app_hosts_.erase(process->id());
2336 break;
2337 }
[email protected]432115822011-07-10 15:52:272338 case chrome::NOTIFICATION_PREF_CHANGED: {
[email protected]aa96d3a2010-08-21 08:45:252339 std::string* pref_name = Details<std::string>(details).ptr();
[email protected]6c751e72010-11-23 10:11:102340 if (*pref_name == prefs::kExtensionInstallAllowList ||
2341 *pref_name == prefs::kExtensionInstallDenyList) {
2342 CheckAdminBlacklist();
[email protected]6c751e72010-11-23 10:11:102343 } else {
2344 NOTREACHED() << "Unexpected preference name.";
2345 }
[email protected]aa96d3a2010-08-21 08:45:252346 break;
2347 }
2348
[email protected]4814b512009-11-07 00:12:292349 default:
2350 NOTREACHED() << "Unexpected notification type.";
2351 }
2352}
2353
[email protected]eaa7dd182010-12-14 11:09:002354bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:182355 return !GetAppIds().empty();
2356}
[email protected]377011d2010-07-20 04:18:502357
[email protected]eaa7dd182010-12-14 11:09:002358ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:182359 ExtensionIdSet result;
[email protected]377011d2010-07-20 04:18:502360 for (ExtensionList::const_iterator it = extensions_.begin();
2361 it != extensions_.end(); ++it) {
[email protected]ec5b50d2010-10-09 16:35:182362 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
2363 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:502364 }
2365
[email protected]ec5b50d2010-10-09 16:35:182366 return result;
[email protected]377011d2010-07-20 04:18:502367}
[email protected]d7e9a862010-11-03 21:57:492368
[email protected]14908b72011-04-20 06:54:362369scoped_refptr<CrxInstaller> ExtensionService::MakeCrxInstaller(
2370 ExtensionInstallUI* client) {
2371 return new CrxInstaller(weak_ptr_factory_.GetWeakPtr(), client);
2372}
2373
[email protected]eaa7dd182010-12-14 11:09:002374bool ExtensionService::IsBackgroundPageReady(const Extension* extension) {
[email protected]d7e9a862010-11-03 21:57:492375 return (extension->background_url().is_empty() ||
2376 extension_runtime_data_[extension->id()].background_page_ready);
2377}
2378
[email protected]eaa7dd182010-12-14 11:09:002379void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
[email protected]d7e9a862010-11-03 21:57:492380 DCHECK(!extension->background_url().is_empty());
2381 extension_runtime_data_[extension->id()].background_page_ready = true;
2382 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272383 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
[email protected]d7e9a862010-11-03 21:57:492384 Source<const Extension>(extension),
2385 NotificationService::NoDetails());
2386}
2387
[email protected]eaa7dd182010-12-14 11:09:002388bool ExtensionService::IsBeingUpgraded(const Extension* extension) {
[email protected]d7e9a862010-11-03 21:57:492389 return extension_runtime_data_[extension->id()].being_upgraded;
2390}
2391
[email protected]eaa7dd182010-12-14 11:09:002392void ExtensionService::SetBeingUpgraded(const Extension* extension,
[email protected]d7e9a862010-11-03 21:57:492393 bool value) {
2394 extension_runtime_data_[extension->id()].being_upgraded = value;
2395}
[email protected]1bead0712010-11-27 17:41:532396
[email protected]eaa7dd182010-12-14 11:09:002397PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) {
[email protected]1bead0712010-11-27 17:41:532398 return &extension_runtime_data_[extension->id()].property_bag;
2399}
[email protected]cebc3dc2011-04-18 17:15:002400
2401void ExtensionService::RegisterNaClModule(const GURL& url,
2402 const std::string& mime_type) {
2403 NaClModuleInfo info;
2404 info.url = url;
2405 info.mime_type = mime_type;
2406
2407 DCHECK(FindNaClModule(url) == nacl_module_list_.end());
2408 nacl_module_list_.push_front(info);
2409}
2410
2411void ExtensionService::UnregisterNaClModule(const GURL& url) {
2412 NaClModuleInfoList::iterator iter = FindNaClModule(url);
2413 DCHECK(iter != nacl_module_list_.end());
2414 nacl_module_list_.erase(iter);
2415}
2416
[email protected]ed0ba002011-05-26 16:55:132417void ExtensionService::UpdatePluginListWithNaClModules() {
[email protected]ed0ba002011-05-26 16:55:132418 FilePath path;
2419 PathService::Get(chrome::FILE_NACL_PLUGIN, &path);
2420
2421 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(path);
2422
2423 const PepperPluginInfo* pepper_info = NULL;
2424 std::vector<PepperPluginInfo> plugins;
2425 PepperPluginRegistry::ComputeList(&plugins);
2426 for (size_t i = 0; i < plugins.size(); ++i) {
2427 if (path == plugins[i].path) {
2428 pepper_info = &plugins[i];
2429 break;
2430 }
2431 }
2432 CHECK(pepper_info);
2433 webkit::npapi::WebPluginInfo info = pepper_info->ToWebPluginInfo();
2434
2435 DCHECK(nacl_module_list_.size() <= 1);
2436 for (ExtensionService::NaClModuleInfoList::const_iterator iter =
2437 nacl_module_list_.begin(); iter != nacl_module_list_.end(); ++iter) {
2438 webkit::npapi::WebPluginMimeType mime_type_info;
2439 mime_type_info.mime_type = iter->mime_type;
2440 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl"));
2441 mime_type_info.additional_param_values.push_back(
2442 UTF8ToUTF16(iter->url.spec()));
2443 info.mime_types.push_back(mime_type_info);
2444 }
2445
2446 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
2447 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info);
2448}
2449
[email protected]cebc3dc2011-04-18 17:15:002450ExtensionService::NaClModuleInfoList::iterator
2451 ExtensionService::FindNaClModule(const GURL& url) {
2452 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2453 iter != nacl_module_list_.end(); ++iter) {
2454 if (iter->url == url)
2455 return iter;
2456 }
2457 return nacl_module_list_.end();
2458}