blob: f6b9583ec41fad554082557141495e231ff31c02 [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]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]cebc3dc2011-04-18 17:15:0014#include "base/path_service.h"
[email protected]cd500f72010-06-25 23:44:3215#include "base/stl_util-inl.h"
[email protected]24b538a2010-02-27 01:22:4416#include "base/string16.h"
[email protected]e83326f2010-07-31 17:29:2517#include "base/string_number_conversions.h"
[email protected]6014d672008-12-05 00:38:2518#include "base/string_util.h"
[email protected]18d4b6c2010-09-21 03:21:0419#include "base/stringprintf.h"
[email protected]34b99632011-01-01 01:01:0620#include "base/threading/thread_restrictions.h"
[email protected]cc2c3432009-11-06 17:24:3621#include "base/time.h"
[email protected]ce7f62e32010-08-10 23:43:5922#include "base/utf_string_conversions.h"
[email protected]cc655912009-01-29 23:19:1923#include "base/values.h"
[email protected]aa142702010-03-26 01:26:3324#include "base/version.h"
[email protected]15730c42009-09-03 00:03:2025#include "chrome/browser/browser_process.h"
[email protected]4814b512009-11-07 00:12:2926#include "chrome/browser/debugger/devtools_manager.h"
[email protected]7577a5c52009-07-30 06:21:5827#include "chrome/browser/extensions/crx_installer.h"
[email protected]18cc5a52011-04-15 16:03:3828#include "chrome/browser/extensions/apps_promo.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]7596ce72010-08-30 05:10:4637#include "chrome/browser/extensions/extension_management_api.h"
[email protected]118de7892011-03-16 13:31:4038#include "chrome/browser/extensions/extension_preference_api.h"
[email protected]4814b512009-11-07 00:12:2939#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]8a661f82010-10-19 21:47:1140#include "chrome/browser/extensions/extension_processes_api.h"
[email protected]19eb80152011-02-26 00:28:4341#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]90310d92011-04-17 07:35:0442#include "chrome/browser/extensions/extension_sync_data.h"
[email protected]93fd78f42009-07-10 16:43:1743#include "chrome/browser/extensions/extension_updater.h"
[email protected]8f9d4eb2011-02-05 01:39:1044#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]784688a62010-09-13 07:06:5245#include "chrome/browser/extensions/extension_webnavigation_api.h"
[email protected]8e4560b62011-01-14 10:09:1446#include "chrome/browser/extensions/external_extension_provider_impl.h"
[email protected]42b795652011-02-22 23:32:3847#include "chrome/browser/extensions/external_extension_provider_interface.h"
[email protected]b2907fd2011-03-25 16:43:3748#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]56ad3792010-05-28 17:45:3349#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]37858e52010-08-26 00:22:0250#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3351#include "chrome/browser/profiles/profile.h"
[email protected]56ad3792010-05-28 17:45:3352#include "chrome/browser/search_engines/template_url_model.h"
[email protected]18280372011-03-22 18:05:2253#include "chrome/browser/themes/theme_service.h"
[email protected]a0ea76c2011-03-23 17:36:4254#include "chrome/browser/themes/theme_service_factory.h"
[email protected]fd42ac30f2011-02-27 19:33:3655#include "chrome/browser/ui/webui/shown_sections_handler.h"
[email protected]aab98a52009-12-02 03:22:3556#include "chrome/common/child_process_logging.h"
[email protected]cebc3dc2011-04-18 17:15:0057#include "chrome/common/chrome_paths.h"
[email protected]e2eb43112009-05-29 21:19:5458#include "chrome/common/chrome_switches.h"
[email protected]5b1a0e22009-05-26 19:00:5859#include "chrome/common/extensions/extension.h"
[email protected]d7b36dc2009-10-29 21:47:4060#include "chrome/common/extensions/extension_constants.h"
[email protected]05c82182010-06-24 17:49:0861#include "chrome/common/extensions/extension_error_utils.h"
[email protected]7c927b62010-02-24 09:54:1362#include "chrome/common/extensions/extension_file_util.h"
[email protected]c6d474f82009-12-16 21:11:0663#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]a315ba92010-11-16 14:12:2164#include "chrome/common/extensions/extension_resource.h"
[email protected]25b34332009-06-05 21:53:1965#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1466#include "chrome/common/url_constants.h"
[email protected]5f945a0e2011-03-01 17:47:5367#include "content/browser/browser_thread.h"
[email protected]2de307592011-04-05 21:16:5868#include "content/browser/plugin_process_host.h"
69#include "content/browser/plugin_service.h"
[email protected]c3113022011-04-16 03:26:3070#include "content/common/json_value_serializer.h"
[email protected]b3841c502011-03-09 01:21:3171#include "content/common/notification_service.h"
72#include "content/common/notification_type.h"
[email protected]cebc3dc2011-04-18 17:15:0073#include "content/common/pepper_plugin_registry.h"
[email protected]c10da4b02010-03-25 14:38:3274#include "googleurl/src/gurl.h"
[email protected]1debbbb62010-10-06 17:23:4475#include "net/base/registry_controlled_domain.h"
[email protected]24b538a2010-02-27 01:22:4476#include "webkit/database/database_tracker.h"
77#include "webkit/database/database_util.h"
[email protected]2de307592011-04-05 21:16:5878#include "webkit/plugins/npapi/plugin_list.h"
[email protected]c64631652009-04-29 22:24:3179
[email protected]eed367e2011-04-12 03:43:3180#if defined(OS_CHROMEOS)
81#include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
[email protected]b777b332011-04-16 04:01:0882#include "webkit/fileapi/file_system_context.h"
83#include "webkit/fileapi/file_system_mount_point_provider.h"
84#include "webkit/fileapi/file_system_path_manager.h"
[email protected]eed367e2011-04-12 03:43:3185#endif
86
[email protected]5ef47ec2010-01-28 05:58:0587using base::Time;
88
[email protected]c6d474f82009-12-16 21:11:0689namespace errors = extension_manifest_errors;
90
[email protected]b6ab96d2009-08-20 18:58:1991namespace {
92
[email protected]29d0d4ac2010-09-08 21:10:3193#if defined(OS_LINUX)
94static const int kOmniboxIconPaddingLeft = 2;
95static const int kOmniboxIconPaddingRight = 2;
96#elif defined(OS_MACOSX)
97static const int kOmniboxIconPaddingLeft = 0;
98static const int kOmniboxIconPaddingRight = 2;
99#else
100static const int kOmniboxIconPaddingLeft = 0;
101static const int kOmniboxIconPaddingRight = 0;
102#endif
103
[email protected]a315ba92010-11-16 14:12:21104// The following enumeration is used in histograms matching
105// Extensions.ManifestReload* . Values may be added, as long
106// as existing values are not changed.
107enum ManifestReloadReason {
108 NOT_NEEDED = 0, // Reload not needed.
109 UNPACKED_DIR, // Unpacked directory
110 NEEDS_RELOCALIZATION, // The local has changed since we read this extension.
111 NUM_MANIFEST_RELOAD_REASONS
112};
[email protected]2111b1a2010-03-12 18:12:44113
[email protected]a315ba92010-11-16 14:12:21114ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) {
115 // Always reload manifests of unpacked extensions, because they can change
116 // on disk independent of the manifest in our prefs.
117 if (info.extension_location == Extension::LOAD)
118 return UNPACKED_DIR;
119
120 // Reload the manifest if it needs to be relocalized.
121 if (extension_l10n_util::ShouldRelocalizeManifest(info))
122 return NEEDS_RELOCALIZATION;
123
124 return NOT_NEEDED;
[email protected]2111b1a2010-03-12 18:12:44125}
126
[email protected]2de307592011-04-05 21:16:58127static void ForceShutdownPlugin(const FilePath& plugin_path) {
128 PluginProcessHost* plugin =
129 PluginService::GetInstance()->FindNpapiPluginProcess(plugin_path);
130 if (plugin)
131 plugin->ForceShutdown();
132}
133
[email protected]c6d474f82009-12-16 21:11:06134} // namespace
[email protected]b6ab96d2009-08-20 18:58:19135
[email protected]eaa7dd182010-12-14 11:09:00136ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
[email protected]d7e9a862010-11-03 21:57:49137 : background_page_ready(false),
138 being_upgraded(false) {
139}
140
[email protected]eaa7dd182010-12-14 11:09:00141ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
[email protected]d7e9a862010-11-03 21:57:49142}
143
[email protected]cebc3dc2011-04-18 17:15:00144ExtensionService::NaClModuleInfo::NaClModuleInfo() {
145}
146
147ExtensionService::NaClModuleInfo::~NaClModuleInfo() {
148}
149
[email protected]eaa7dd182010-12-14 11:09:00150// ExtensionService.
[email protected]6014d672008-12-05 00:38:25151
[email protected]eaa7dd182010-12-14 11:09:00152const char* ExtensionService::kInstallDirectoryName = "Extensions";
153const char* ExtensionService::kCurrentVersionFileName = "Current Version";
[email protected]494c06e2009-07-25 01:06:42154
[email protected]eaa7dd182010-12-14 11:09:00155// Implements IO for the ExtensionService.
[email protected]7a4c6852010-09-16 03:44:22156
[email protected]eaa7dd182010-12-14 11:09:00157class ExtensionServiceBackend
[email protected]8e4560b62011-01-14 10:09:14158 : public base::RefCountedThreadSafe<ExtensionServiceBackend> {
[email protected]7a4c6852010-09-16 03:44:22159 public:
[email protected]1f830eb2010-09-28 08:25:14160 // |install_directory| is a path where to look for extensions to load.
[email protected]8e4560b62011-01-14 10:09:14161 explicit ExtensionServiceBackend(const FilePath& install_directory);
[email protected]7a4c6852010-09-16 03:44:22162
163 // Loads a single extension from |path| where |path| is the top directory of
164 // a specific extension where its manifest file lives.
165 // Errors are reported through ExtensionErrorReporter. On success,
[email protected]49cd1572011-02-08 21:38:45166 // AddExtension() is called.
[email protected]7a4c6852010-09-16 03:44:22167 // TODO(erikkay): It might be useful to be able to load a packed extension
168 // (presumably into memory) without installing it.
169 void LoadSingleExtension(const FilePath &path,
[email protected]eaa7dd182010-12-14 11:09:00170 scoped_refptr<ExtensionService> frontend);
[email protected]7a4c6852010-09-16 03:44:22171
[email protected]7a4c6852010-09-16 03:44:22172 private:
[email protected]eaa7dd182010-12-14 11:09:00173 friend class base::RefCountedThreadSafe<ExtensionServiceBackend>;
[email protected]7a4c6852010-09-16 03:44:22174
[email protected]eaa7dd182010-12-14 11:09:00175 virtual ~ExtensionServiceBackend();
[email protected]7a4c6852010-09-16 03:44:22176
177 // Finish installing the extension in |crx_path| after it has been unpacked to
178 // |unpacked_path|. If |expected_id| is not empty, it's verified against the
179 // extension's manifest before installation. If |silent| is true, there will
180 // be no install confirmation dialog. |from_gallery| indicates whether the
181 // crx was installed from our gallery, which results in different UI.
182 //
183 // Note: We take ownership of |extension|.
184 void OnExtensionUnpacked(const FilePath& crx_path,
185 const FilePath& unpacked_path,
[email protected]9adb9692010-10-29 23:14:02186 const Extension* extension,
[email protected]7a4c6852010-09-16 03:44:22187 const std::string expected_id);
188
189 // Notify the frontend that there was an error loading an extension.
190 void ReportExtensionLoadError(const FilePath& extension_path,
191 const std::string& error);
192
[email protected]7a4c6852010-09-16 03:44:22193 // This is a naked pointer which is set by each entry point.
194 // The entry point is responsible for ensuring lifetime.
[email protected]eaa7dd182010-12-14 11:09:00195 ExtensionService* frontend_;
[email protected]7a4c6852010-09-16 03:44:22196
197 // The top-level extensions directory being installed to.
198 FilePath install_directory_;
199
200 // Whether errors result in noisy alerts.
201 bool alert_on_error_;
202
[email protected]eaa7dd182010-12-14 11:09:00203 DISALLOW_COPY_AND_ASSIGN(ExtensionServiceBackend);
[email protected]7a4c6852010-09-16 03:44:22204};
205
[email protected]eaa7dd182010-12-14 11:09:00206ExtensionServiceBackend::ExtensionServiceBackend(
[email protected]aebe23a32010-12-10 22:15:48207 const FilePath& install_directory)
[email protected]7a4c6852010-09-16 03:44:22208 : frontend_(NULL),
209 install_directory_(install_directory),
[email protected]8e4560b62011-01-14 10:09:14210 alert_on_error_(false) {
[email protected]7a4c6852010-09-16 03:44:22211}
212
[email protected]eaa7dd182010-12-14 11:09:00213ExtensionServiceBackend::~ExtensionServiceBackend() {
[email protected]7a4c6852010-09-16 03:44:22214}
215
[email protected]eaa7dd182010-12-14 11:09:00216void ExtensionServiceBackend::LoadSingleExtension(
217 const FilePath& path_in, scoped_refptr<ExtensionService> frontend) {
[email protected]a29a517a2011-01-21 21:11:12218 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
[email protected]a8af9fdb2010-10-28 21:52:20219
[email protected]7a4c6852010-09-16 03:44:22220 frontend_ = frontend;
221
222 // Explicit UI loads are always noisy.
223 alert_on_error_ = true;
224
225 FilePath extension_path = path_in;
226 file_util::AbsolutePath(&extension_path);
227
[email protected]3aff9ad2011-04-01 20:26:48228 int flags = Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) ?
229 Extension::ALLOW_FILE_ACCESS : Extension::NO_FLAGS;
[email protected]83048a22011-03-29 00:14:13230 if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD))
231 flags |= Extension::STRICT_ERROR_CHECKS;
[email protected]7a4c6852010-09-16 03:44:22232 std::string error;
[email protected]ad8e04a2010-11-01 04:16:27233 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
[email protected]7a4c6852010-09-16 03:44:22234 extension_path,
[email protected]92888082010-10-18 19:24:57235 Extension::LOAD,
[email protected]83048a22011-03-29 00:14:13236 flags,
[email protected]ad8e04a2010-11-01 04:16:27237 &error));
[email protected]7a4c6852010-09-16 03:44:22238
239 if (!extension) {
240 ReportExtensionLoadError(extension_path, error);
241 return;
242 }
243
[email protected]7a4c6852010-09-16 03:44:22244 // Report this as an installed extension so that it gets remembered in the
245 // prefs.
[email protected]ca4b5fa32010-10-09 12:42:18246 BrowserThread::PostTask(
247 BrowserThread::UI, FROM_HERE,
[email protected]8d888c12010-11-30 00:00:25248 NewRunnableMethod(frontend_,
[email protected]eaa7dd182010-12-14 11:09:00249 &ExtensionService::OnExtensionInstalled,
[email protected]8d888c12010-11-30 00:00:25250 extension));
[email protected]7a4c6852010-09-16 03:44:22251}
252
[email protected]eaa7dd182010-12-14 11:09:00253void ExtensionServiceBackend::ReportExtensionLoadError(
[email protected]7a4c6852010-09-16 03:44:22254 const FilePath& extension_path, const std::string &error) {
[email protected]a29a517a2011-01-21 21:11:12255 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
[email protected]ca4b5fa32010-10-09 12:42:18256 BrowserThread::PostTask(
257 BrowserThread::UI, FROM_HERE,
[email protected]7a4c6852010-09-16 03:44:22258 NewRunnableMethod(
259 frontend_,
[email protected]eaa7dd182010-12-14 11:09:00260 &ExtensionService::ReportExtensionLoadError, extension_path,
[email protected]7a4c6852010-09-16 03:44:22261 error, NotificationType::EXTENSION_INSTALL_ERROR, alert_on_error_));
262}
263
[email protected]8e4560b62011-01-14 10:09:14264void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12265 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20266
[email protected]7a4c6852010-09-16 03:44:22267 // Check if the providers know about this extension.
[email protected]0a60a2e2010-10-25 16:15:21268 ProviderCollection::const_iterator i;
269 for (i = external_extension_providers_.begin();
270 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14271 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21272 if (i->get()->HasExtension(id))
273 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22274 }
275
[email protected]7a4c6852010-09-16 03:44:22276 // This is an external extension that we don't have registered. Uninstall.
[email protected]d6ebc9792011-04-07 18:18:33277 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22278}
279
[email protected]8e4560b62011-01-14 10:09:14280void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22281 external_extension_providers_.clear();
282}
283
[email protected]8e4560b62011-01-14 10:09:14284void ExtensionService::AddProviderForTesting(
285 ExternalExtensionProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12286 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21287 external_extension_providers_.push_back(
[email protected]8e4560b62011-01-14 10:09:14288 linked_ptr<ExternalExtensionProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22289}
290
[email protected]8e4560b62011-01-14 10:09:14291void ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22292 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42293 const GURL& update_url,
294 Extension::Location location) {
[email protected]ab22ba42011-01-14 16:36:38295 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
296 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20297
[email protected]8e4560b62011-01-14 10:09:14298 if (GetExtensionById(id, true)) {
[email protected]7a4c6852010-09-16 03:44:22299 // Already installed. Do not change the update URL that the extension set.
300 return;
301 }
[email protected]b2907fd2011-03-25 16:43:37302 pending_extension_manager()->AddFromExternalUpdateUrl(
303 id, update_url, location);
[email protected]a29a517a2011-01-21 21:11:12304 external_extension_url_added_ |= true;
[email protected]7a4c6852010-09-16 03:44:22305}
306
[email protected]eaa7dd182010-12-14 11:09:00307bool ExtensionService::IsDownloadFromGallery(const GURL& download_url,
[email protected]a29a517a2011-01-21 21:11:12308 const GURL& referrer_url) {
[email protected]d3071992010-10-08 15:24:07309 // Special-case the themes mini-gallery.
310 // TODO(erikkay) When that gallery goes away, remove this code.
311 if (IsDownloadFromMiniGallery(download_url) &&
312 StartsWithASCII(referrer_url.spec(),
313 extension_urls::kMiniGalleryBrowsePrefix, false)) {
[email protected]334e04a2010-06-24 23:34:44314 return true;
[email protected]1debbbb62010-10-06 17:23:44315 }
[email protected]473ff6e2010-05-12 15:31:55316
[email protected]9adb9692010-10-29 23:14:02317 const Extension* download_extension = GetExtensionByWebExtent(download_url);
318 const Extension* referrer_extension = GetExtensionByWebExtent(referrer_url);
319 const Extension* webstore_app = GetWebStoreApp();
[email protected]d3071992010-10-08 15:24:07320
321 bool referrer_valid = (referrer_extension == webstore_app);
322 bool download_valid = (download_extension == webstore_app);
323
324 // If the command-line gallery URL is set, then be a bit more lenient.
325 GURL store_url =
326 GURL(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
327 switches::kAppsGalleryURL));
328 if (!store_url.is_empty()) {
329 std::string store_tld =
330 net::RegistryControlledDomainService::GetDomainAndRegistry(store_url);
331 if (!referrer_valid) {
332 std::string referrer_tld =
333 net::RegistryControlledDomainService::GetDomainAndRegistry(
334 referrer_url);
335 // The referrer gets stripped when transitioning from https to http,
336 // or when hitting an unknown test cert and that commonly happens in
337 // testing environments. Given this, we allow an empty referrer when
338 // the command-line flag is set.
339 // Otherwise, the TLD must match the TLD of the command-line url.
340 referrer_valid = referrer_url.is_empty() || (referrer_tld == store_tld);
341 }
342
343 if (!download_valid) {
344 std::string download_tld =
345 net::RegistryControlledDomainService::GetDomainAndRegistry(
346 GURL(download_url));
347
348 // Otherwise, the TLD must match the TLD of the command-line url.
349 download_valid = (download_tld == store_tld);
350 }
351 }
352
353 return (referrer_valid && download_valid);
[email protected]b7c2f252009-12-08 00:47:23354}
355
[email protected]eaa7dd182010-12-14 11:09:00356bool ExtensionService::IsDownloadFromMiniGallery(const GURL& download_url) {
[email protected]ac025282009-12-16 19:16:38357 return StartsWithASCII(download_url.spec(),
358 extension_urls::kMiniGalleryDownloadPrefix,
359 false); // case_sensitive
360}
361
[email protected]d9696672011-03-15 22:45:09362const Extension* ExtensionService::GetInstalledApp(const GURL& url) {
[email protected]ffb204f22010-12-05 23:20:27363 // Check for hosted app.
[email protected]d9696672011-03-15 22:45:09364 const Extension* app = GetExtensionByWebExtent(url);
365 if (app)
366 return app;
[email protected]ffb204f22010-12-05 23:20:27367
368 // Check for packaged app.
[email protected]d9696672011-03-15 22:45:09369 app = GetExtensionByURL(url);
370 if (app && app->is_app())
371 return app;
372
373 return NULL;
374}
375
376bool ExtensionService::IsInstalledApp(const GURL& url) {
377 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27378}
379
[email protected]6aeac8342010-10-01 20:21:18380// static
[email protected]d6ebc9792011-04-07 18:18:33381// This function is used to implement the command-line switch
382// --uninstall-extension. The LOG statements within this function are used to
383// inform the user if the uninstall cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00384bool ExtensionService::UninstallExtensionHelper(
385 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18386 const std::string& extension_id) {
[email protected]6aeac8342010-10-01 20:21:18387
[email protected]95da88c42011-03-31 10:07:33388 const Extension* extension =
389 extensions_service->GetExtensionById(extension_id, true);
390 if (!extension)
391 extension = extensions_service->GetTerminatedExtension(extension_id);
392
[email protected]d6ebc9792011-04-07 18:18:33393 // We can't call UninstallExtension with an invalid extension ID.
[email protected]95da88c42011-03-31 10:07:33394 if (!extension) {
[email protected]6aeac8342010-10-01 20:21:18395 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33396 << "id: " << extension_id;
397 return false;
[email protected]6aeac8342010-10-01 20:21:18398 }
399
[email protected]d6ebc9792011-04-07 18:18:33400 // The following call to UninstallExtension will not allow an uninstall of a
401 // policy-controlled extension.
402 std::string error;
403 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
404 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
405 << ": " << error;
406 return false;
407 }
[email protected]95da88c42011-03-31 10:07:33408
[email protected]6aeac8342010-10-01 20:21:18409 return true;
410}
411
[email protected]eaa7dd182010-12-14 11:09:00412ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24413 const CommandLine* command_line,
414 const FilePath& install_directory,
415 ExtensionPrefs* extension_prefs,
[email protected]0436b102011-04-15 18:30:03416 bool autoupdate_enabled,
417 bool extensions_enabled)
[email protected]6ef635e42009-07-26 06:16:12418 : profile_(profile),
[email protected]73c47932010-12-06 18:13:43419 extension_prefs_(extension_prefs),
[email protected]b2907fd2011-03-25 16:43:37420 ALLOW_THIS_IN_INITIALIZER_LIST(pending_extension_manager_(*this)),
[email protected]a9b00ac2009-06-25 21:03:23421 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03422 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13423 show_extensions_prompts_(true),
[email protected]3ecda252010-11-18 19:50:55424 ready_(false),
[email protected]ec5b50d2010-10-09 16:35:18425 ALLOW_THIS_IN_INITIALIZER_LIST(toolbar_model_(this)),
[email protected]18cc5a52011-04-15 16:03:38426 apps_promo_(profile->GetPrefs()),
[email protected]b3d62312b12010-10-14 21:10:18427 event_routers_initialized_(false) {
[email protected]a29a517a2011-01-21 21:11:12428 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20429
[email protected]36a784c2009-06-23 06:21:08430 // Figure out if extension installation should be enabled.
[email protected]6d60703b2009-08-29 01:29:23431 if (command_line->HasSwitch(switches::kDisableExtensions)) {
432 extensions_enabled_ = false;
433 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
434 extensions_enabled_ = false;
[email protected]6b75ec32009-08-14 06:37:18435 }
[email protected]36a784c2009-06-23 06:21:08436
[email protected]a4ed6282009-12-14 20:51:16437 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED,
[email protected]bc535ee52010-08-31 18:40:32438 NotificationService::AllSources());
[email protected]2fb7dc982010-09-29 12:24:28439 pref_change_registrar_.Init(profile->GetPrefs());
440 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this);
441 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this);
[email protected]4814b512009-11-07 00:12:29442
[email protected]93fd78f42009-07-10 16:43:17443 // Set up the ExtensionUpdater
444 if (autoupdate_enabled) {
445 int update_frequency = kDefaultUpdateFrequencySeconds;
446 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25447 base::StringToInt(command_line->GetSwitchValueASCII(
448 switches::kExtensionsUpdateFrequency),
449 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17450 }
[email protected]82b6e512011-04-12 20:33:27451 updater_.reset(new ExtensionUpdater(this,
452 extension_prefs,
453 profile->GetPrefs(),
454 profile,
455 update_frequency));
[email protected]93fd78f42009-07-10 16:43:17456 }
457
[email protected]8e4560b62011-01-14 10:09:14458 backend_ = new ExtensionServiceBackend(install_directory_);
459
[email protected]0436b102011-04-15 18:30:03460 if (extensions_enabled_) {
[email protected]873531342011-03-09 12:16:05461 ExternalExtensionProviderImpl::CreateExternalProviders(
462 this, profile_, &external_extension_providers_);
463 }
[email protected]b671760b2010-07-15 21:13:47464
[email protected]aa96d3a2010-08-21 08:45:25465 // Use monochrome icons for Omnibox icons.
[email protected]29d0d4ac2010-09-08 21:10:31466 omnibox_popup_icon_manager_.set_monochrome(true);
[email protected]b671760b2010-07-15 21:13:47467 omnibox_icon_manager_.set_monochrome(true);
[email protected]29d0d4ac2010-09-08 21:10:31468 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft,
469 0, kOmniboxIconPaddingRight));
[email protected]6014d672008-12-05 00:38:25470}
471
[email protected]eaa7dd182010-12-14 11:09:00472const ExtensionList* ExtensionService::extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45473 return &extensions_;
474}
475
[email protected]eaa7dd182010-12-14 11:09:00476const ExtensionList* ExtensionService::disabled_extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45477 return &disabled_extensions_;
478}
479
[email protected]bb7f40952011-01-13 00:21:20480const ExtensionList* ExtensionService::terminated_extensions() const {
481 return &terminated_extensions_;
482}
483
[email protected]b2907fd2011-03-25 16:43:37484PendingExtensionManager* ExtensionService::pending_extension_manager() {
485 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45486}
487
[email protected]eaa7dd182010-12-14 11:09:00488ExtensionService::~ExtensionService() {
[email protected]2fb7dc982010-09-29 12:24:28489 DCHECK(!profile_); // Profile should have told us it's going away.
[email protected]9f1087e2009-06-15 17:29:32490 UnloadAllExtensions();
[email protected]94b4ffc2011-02-04 05:55:17491
[email protected]8e4560b62011-01-14 10:09:14492 ProviderCollection::const_iterator i;
493 for (i = external_extension_providers_.begin();
494 i != external_extension_providers_.end(); ++i) {
495 ExternalExtensionProviderInterface* provider = i->get();
496 provider->ServiceShutdown();
497 }
[email protected]eed367e2011-04-12 03:43:31498
499#if defined(OS_CHROMEOS)
500 if (event_routers_initialized_) {
501 ExtensionFileBrowserEventRouter::GetInstance()->
502 StopObservingFileSystemEvents();
503 }
504#endif
[email protected]6014d672008-12-05 00:38:25505}
506
[email protected]eaa7dd182010-12-14 11:09:00507void ExtensionService::InitEventRouters() {
[email protected]b3d62312b12010-10-14 21:10:18508 if (event_routers_initialized_)
509 return;
510
[email protected]c5ae74ab2010-04-15 18:14:37511 ExtensionHistoryEventRouter::GetInstance()->ObserveProfile(profile_);
512 ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_);
[email protected]97d2f1d2011-01-15 00:41:08513 browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_));
514 browser_event_router_->Init();
[email protected]118de7892011-03-16 13:31:40515 preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_));
[email protected]8e8bb6d2010-12-13 08:18:55516 ExtensionBookmarkEventRouter::GetInstance()->Observe(
[email protected]c5ae74ab2010-04-15 18:14:37517 profile_->GetBookmarkModel());
[email protected]2c5e1e12010-06-10 13:14:44518 ExtensionCookiesEventRouter::GetInstance()->Init();
[email protected]7596ce72010-08-30 05:10:46519 ExtensionManagementEventRouter::GetInstance()->Init();
[email protected]8a661f82010-10-19 21:47:11520 ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_);
[email protected]784688a62010-09-13 07:06:52521 ExtensionWebNavigationEventRouter::GetInstance()->Init();
[email protected]eed367e2011-04-12 03:43:31522#if defined(OS_CHROMEOS)
523 ExtensionFileBrowserEventRouter::GetInstance()->ObserveFileSystemEvents(
524 profile_);
525#endif
[email protected]b3d62312b12010-10-14 21:10:18526 event_routers_initialized_ = true;
[email protected]c5ae74ab2010-04-15 18:14:37527}
528
[email protected]b2907fd2011-03-25 16:43:37529const Extension* ExtensionService::GetExtensionById(
530 const std::string& id, bool include_disabled) const {
[email protected]78994ab02010-12-08 18:06:44531 return GetExtensionByIdInternal(id, true, include_disabled);
532}
533
[email protected]eaa7dd182010-12-14 11:09:00534void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12535 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20536
[email protected]fa6a9102010-11-22 15:38:50537 DCHECK(!ready_); // Can't redo init.
[email protected]93fd78f42009-07-10 16:43:17538 DCHECK_EQ(extensions_.size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32539
[email protected]95dd38f2009-10-20 20:09:15540 // Hack: we need to ensure the ResourceDispatcherHost is ready before we load
541 // the first extension, because its members listen for loaded notifications.
542 g_browser_process->resource_dispatcher_host();
543
[email protected]9f1087e2009-06-15 17:29:32544 LoadAllExtensions();
[email protected]894bb502009-05-21 22:39:57545
[email protected]9f1087e2009-06-15 17:29:32546 // TODO(erikkay) this should probably be deferred to a future point
547 // rather than running immediately at startup.
[email protected]93fd78f42009-07-10 16:43:17548 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57549
[email protected]9f1087e2009-06-15 17:29:32550 // TODO(erikkay) this should probably be deferred as well.
551 GarbageCollectExtensions();
[email protected]6014d672008-12-05 00:38:25552}
553
[email protected]eaa7dd182010-12-14 11:09:00554void ExtensionService::UpdateExtension(const std::string& id,
[email protected]9a8c4022011-01-25 14:25:33555 const FilePath& extension_path,
556 const GURL& download_url) {
[email protected]a29a517a2011-01-21 21:11:12557 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20558
[email protected]b2907fd2011-03-25 16:43:37559 PendingExtensionInfo pending_extension_info;
560 bool is_pending_extension = pending_extension_manager_.GetById(
561 id, &pending_extension_info);
[email protected]8ef78fd2010-08-19 17:14:32562
[email protected]5eb375e92010-11-26 07:50:41563 const Extension* extension = GetExtensionByIdInternal(id, true, true);
564 if (!is_pending_extension && !extension) {
[email protected]aa142702010-03-26 01:26:33565 LOG(WARNING) << "Will not update extension " << id
566 << " because it is not installed or pending";
567 // Delete extension_path since we're not creating a CrxInstaller
568 // that would do it for us.
[email protected]ca4b5fa32010-10-09 12:42:18569 BrowserThread::PostTask(
570 BrowserThread::FILE, FROM_HERE,
[email protected]53da2c962011-03-03 17:08:05571 NewRunnableFunction(
572 extension_file_util::DeleteFile, extension_path, false));
[email protected]4c967932009-07-31 01:15:49573 return;
[email protected]e957fe52009-06-23 16:51:05574 }
575
[email protected]aa142702010-03-26 01:26:33576 // We want a silent install only for non-pending extensions and
577 // pending extensions that have install_silently set.
578 ExtensionInstallUI* client =
[email protected]b2907fd2011-03-25 16:43:37579 (!is_pending_extension || pending_extension_info.install_silently()) ?
[email protected]aa142702010-03-26 01:26:33580 NULL : new ExtensionInstallUI(profile_);
581
[email protected]6dfbbf82010-03-12 23:09:16582 scoped_refptr<CrxInstaller> installer(
[email protected]bb461532010-11-26 21:50:23583 new CrxInstaller(this, // frontend
[email protected]aa142702010-03-26 01:26:33584 client));
[email protected]6dfbbf82010-03-12 23:09:16585 installer->set_expected_id(id);
[email protected]ec5b50d2010-10-09 16:35:18586 if (is_pending_extension)
[email protected]b2907fd2011-03-25 16:43:37587 installer->set_install_source(pending_extension_info.install_source());
[email protected]5eb375e92010-11-26 07:50:41588 else if (extension)
589 installer->set_install_source(extension->location());
[email protected]6dfbbf82010-03-12 23:09:16590 installer->set_delete_source(true);
[email protected]5c8516202010-03-18 21:43:34591 installer->set_original_url(download_url);
[email protected]6dfbbf82010-03-12 23:09:16592 installer->InstallCrx(extension_path);
[email protected]e957fe52009-06-23 16:51:05593}
594
[email protected]eaa7dd182010-12-14 11:09:00595void ExtensionService::ReloadExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12596 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]b65272f2009-08-31 15:47:06597 FilePath path;
[email protected]9adb9692010-10-29 23:14:02598 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40599
[email protected]f17dbd42010-08-16 23:21:10600 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06601 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29602 // If the extension has an inspector open for its background page, detach
603 // the inspector and hang onto a cookie for it, so that we can reattach
604 // later.
605 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager();
606 ExtensionHost* host = manager->GetBackgroundHostForExtension(
607 current_extension);
608 if (host) {
609 // Look for an open inspector for the background page.
610 int devtools_cookie = DevToolsManager::GetInstance()->DetachClientHost(
611 host->render_view_host());
612 if (devtools_cookie >= 0)
613 orphaned_dev_tools_[extension_id] = devtools_cookie;
614 }
615
[email protected]b65272f2009-08-31 15:47:06616 path = current_extension->path();
[email protected]f17dbd42010-08-16 23:21:10617 DisableExtension(extension_id);
618 disabled_extension_paths_[extension_id] = path;
[email protected]1eb175082010-02-10 09:26:16619 } else {
620 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06621 }
622
[email protected]e6090e42010-03-23 22:44:08623 // Check the installed extensions to see if what we're reloading was already
624 // installed.
625 scoped_ptr<ExtensionInfo> installed_extension(
626 extension_prefs_->GetInstalledExtensionInfo(extension_id));
627 if (installed_extension.get() &&
628 installed_extension->extension_manifest.get()) {
629 LoadInstalledExtension(*installed_extension, false);
630 } else {
631 // We should always be able to remember the extension's path. If it's not in
632 // the map, someone failed to update |unloaded_extension_paths_|.
633 CHECK(!path.empty());
634 LoadExtension(path);
635 }
[email protected]9cddd4702009-07-27 22:09:40636}
637
[email protected]d6ebc9792011-04-07 18:18:33638bool ExtensionService::UninstallExtension(const std::string& extension_id,
639 bool external_uninstall,
640 std::string* error) {
[email protected]a29a517a2011-01-21 21:11:12641 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20642
[email protected]9adb9692010-10-29 23:14:02643 const Extension* extension =
644 GetExtensionByIdInternal(extension_id, true, true);
[email protected]0dfe05c2011-02-23 23:03:36645 if (!extension)
646 extension = GetTerminatedExtension(extension_id);
[email protected]631cf822009-05-15 07:01:25647
[email protected]e7afe2452010-08-22 16:19:13648 // Callers should not send us nonexistent extensions.
[email protected]aebe23a32010-12-10 22:15:48649 CHECK(extension);
[email protected]9f1087e2009-06-15 17:29:32650
[email protected]831aa212010-03-26 13:55:19651 // Get hold of information we need after unloading, since the extension
652 // pointer will be invalid then.
653 GURL extension_url(extension->url());
654 Extension::Location location(extension->location());
[email protected]95da88c42011-03-31 10:07:33655
656 // Policy change which triggers an uninstall will always set
657 // |external_uninstall| to true so this is the only way to uninstall
658 // managed extensions.
[email protected]d6ebc9792011-04-07 18:18:33659 if (!Extension::UserMayDisable(location) && !external_uninstall) {
660 NotificationService::current()->Notify(
661 NotificationType::EXTENSION_UNINSTALL_NOT_ALLOWED,
662 Source<Profile>(profile_),
663 Details<const Extension>(extension));
664 if (error != NULL) {
665 *error = errors::kCannotUninstallManagedExtension;
666 }
667 return false;
668 }
[email protected]95da88c42011-03-31 10:07:33669
[email protected]211030342010-09-30 18:41:06670 UninstalledExtensionInfo uninstalled_extension_info(*extension);
[email protected]831aa212010-03-26 13:55:19671
[email protected]9b217652010-10-08 22:04:23672 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08673 extension->GetType(), 100);
[email protected]fe2dd7742011-04-19 22:52:49674 RecordPermissionMessagesHistogram(
675 extension, "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23676
[email protected]831aa212010-03-26 13:55:19677 // Also copy the extension identifier since the reference might have been
678 // obtained via Extension::id().
679 std::string extension_id_copy(extension_id);
680
[email protected]56ad3792010-05-28 17:45:33681 if (profile_->GetTemplateURLModel())
682 profile_->GetTemplateURLModel()->UnregisterExtensionKeyword(extension);
683
[email protected]831aa212010-03-26 13:55:19684 // Unload before doing more cleanup to ensure that nothing is hanging on to
685 // any of these resources.
[email protected]a9f39a312010-12-23 22:14:27686 UnloadExtension(extension_id, UnloadedExtensionInfo::UNINSTALL);
[email protected]831aa212010-03-26 13:55:19687
688 extension_prefs_->OnExtensionUninstalled(extension_id_copy, location,
689 external_uninstall);
[email protected]9f1087e2009-06-15 17:29:32690
691 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]831aa212010-03-26 13:55:19692 if (Extension::LOAD != location) {
[email protected]ca4b5fa32010-10-09 12:42:18693 BrowserThread::PostTask(
694 BrowserThread::FILE, FROM_HERE,
[email protected]95d29192009-10-30 01:49:06695 NewRunnableFunction(
[email protected]ca3dbf52010-05-19 22:27:06696 &extension_file_util::UninstallExtension,
697 install_directory_,
698 extension_id_copy));
[email protected]9f1087e2009-06-15 17:29:32699 }
700
[email protected]c10da4b02010-03-25 14:38:32701 ClearExtensionData(extension_url);
[email protected]0dfe05c2011-02-23 23:03:36702 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06703
704 // Notify interested parties that we've uninstalled this extension.
705 NotificationService::current()->Notify(
706 NotificationType::EXTENSION_UNINSTALLED,
707 Source<Profile>(profile_),
708 Details<UninstalledExtensionInfo>(&uninstalled_extension_info));
[email protected]d6ebc9792011-04-07 18:18:33709
710 return true;
[email protected]c10da4b02010-03-25 14:38:32711}
712
[email protected]eaa7dd182010-12-14 11:09:00713void ExtensionService::ClearExtensionData(const GURL& extension_url) {
[email protected]c10da4b02010-03-25 14:38:32714 scoped_refptr<ExtensionDataDeleter> deleter(
715 new ExtensionDataDeleter(profile_, extension_url));
716 deleter->StartDeleting();
[email protected]9f1087e2009-06-15 17:29:32717}
718
[email protected]c3cfb012011-04-06 22:07:35719bool ExtensionService::IsExtensionEnabled(
720 const std::string& extension_id) const {
721 // TODO(akalin): GetExtensionState() isn't very safe as it returns
722 // Extension::ENABLED by default; either change it to return
723 // something else by default or create a separate function that does
724 // so.
725 return
726 extension_prefs_->GetExtensionState(extension_id) == Extension::ENABLED;
727}
728
729bool ExtensionService::IsExternalExtensionUninstalled(
730 const std::string& extension_id) const {
731 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
732}
733
[email protected]eaa7dd182010-12-14 11:09:00734void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12735 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20736
[email protected]9adb9692010-10-29 23:14:02737 const Extension* extension =
738 GetExtensionByIdInternal(extension_id, false, true);
[email protected]f681c782010-11-19 11:19:39739 if (!extension)
[email protected]0c6da502009-08-14 22:32:39740 return;
[email protected]0c6da502009-08-14 22:32:39741
[email protected]e8c729a2010-03-09 19:55:19742 extension_prefs_->SetExtensionState(extension, Extension::ENABLED);
[email protected]1784e83a2009-09-08 21:01:52743
[email protected]0c6da502009-08-14 22:32:39744 // Move it over to the enabled list.
[email protected]00cd9c42010-11-02 20:15:57745 extensions_.push_back(make_scoped_refptr(extension));
[email protected]0c6da502009-08-14 22:32:39746 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
747 disabled_extensions_.end(),
748 extension);
749 disabled_extensions_.erase(iter);
750
[email protected]f681c782010-11-19 11:19:39751 // Make sure any browser action contained within it is not hidden.
752 extension_prefs_->SetBrowserActionVisibility(extension, true);
753
[email protected]8f9d4eb2011-02-05 01:39:10754 ExtensionWebUI::RegisterChromeURLOverrides(profile_,
[email protected]86c008e82009-08-28 20:26:05755 extension->GetChromeURLOverrides());
756
[email protected]62d30f42009-10-01 22:36:06757 NotifyExtensionLoaded(extension);
[email protected]aab98a52009-12-02 03:22:35758 UpdateActiveExtensionsInCrashReporter();
[email protected]0c6da502009-08-14 22:32:39759}
760
[email protected]eaa7dd182010-12-14 11:09:00761void ExtensionService::DisableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12762 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20763
[email protected]9adb9692010-10-29 23:14:02764 const Extension* extension =
765 GetExtensionByIdInternal(extension_id, true, false);
[email protected]b2ba9962009-12-10 20:10:15766 // The extension may have been disabled already.
767 if (!extension)
[email protected]1784e83a2009-09-08 21:01:52768 return;
[email protected]1784e83a2009-09-08 21:01:52769
[email protected]95da88c42011-03-31 10:07:33770 if (!Extension::UserMayDisable(extension->location()))
771 return;
772
[email protected]e8c729a2010-03-09 19:55:19773 extension_prefs_->SetExtensionState(extension, Extension::DISABLED);
[email protected]1784e83a2009-09-08 21:01:52774
775 // Move it over to the disabled list.
[email protected]00cd9c42010-11-02 20:15:57776 disabled_extensions_.push_back(make_scoped_refptr(extension));
[email protected]1784e83a2009-09-08 21:01:52777 ExtensionList::iterator iter = std::find(extensions_.begin(),
778 extensions_.end(),
779 extension);
780 extensions_.erase(iter);
781
[email protected]8f9d4eb2011-02-05 01:39:10782 ExtensionWebUI::UnregisterChromeURLOverrides(profile_,
[email protected]1784e83a2009-09-08 21:01:52783 extension->GetChromeURLOverrides());
784
[email protected]a9f39a312010-12-23 22:14:27785 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE);
[email protected]aab98a52009-12-02 03:22:35786 UpdateActiveExtensionsInCrashReporter();
[email protected]1784e83a2009-09-08 21:01:52787}
788
[email protected]eaa7dd182010-12-14 11:09:00789void ExtensionService::GrantPermissions(const Extension* extension) {
[email protected]8d888c12010-11-30 00:00:25790 CHECK(extension);
791
792 // We only maintain the granted permissions prefs for INTERNAL extensions.
[email protected]139e5732011-03-16 19:29:51793 CHECK_EQ(Extension::INTERNAL, extension->location());
[email protected]8d888c12010-11-30 00:00:25794
795 ExtensionExtent effective_hosts = extension->GetEffectiveHostPermissions();
796 extension_prefs_->AddGrantedPermissions(extension->id(),
797 extension->HasFullPermissions(),
798 extension->api_permissions(),
799 effective_hosts);
800}
801
[email protected]eaa7dd182010-12-14 11:09:00802void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]8d888c12010-11-30 00:00:25803 const Extension* extension) {
804 CHECK(extension);
[email protected]fe2dd7742011-04-19 22:52:49805 RecordPermissionMessagesHistogram(
806 extension, "Extensions.Permissions_ReEnable");
[email protected]8d888c12010-11-30 00:00:25807 GrantPermissions(extension);
808 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
809 EnableExtension(extension->id());
810}
811
[email protected]eaa7dd182010-12-14 11:09:00812void ExtensionService::LoadExtension(const FilePath& extension_path) {
[email protected]ca4b5fa32010-10-09 12:42:18813 BrowserThread::PostTask(
814 BrowserThread::FILE, FROM_HERE,
[email protected]95d29192009-10-30 01:49:06815 NewRunnableMethod(
816 backend_.get(),
[email protected]eaa7dd182010-12-14 11:09:00817 &ExtensionServiceBackend::LoadSingleExtension,
818 extension_path, scoped_refptr<ExtensionService>(this)));
[email protected]9f1087e2009-06-15 17:29:32819}
820
[email protected]eaa7dd182010-12-14 11:09:00821void ExtensionService::LoadComponentExtensions() {
[email protected]1952c7d2010-03-04 23:48:34822 for (RegisteredComponentExtensions::iterator it =
823 component_extension_manifests_.begin();
824 it != component_extension_manifests_.end(); ++it) {
[email protected]61b55b62011-03-24 09:03:10825 LoadComponentExtension(*it);
[email protected]1952c7d2010-03-04 23:48:34826 }
827}
828
[email protected]a964e112011-04-14 21:52:51829const Extension* ExtensionService::LoadComponentExtension(
[email protected]61b55b62011-03-24 09:03:10830 const ComponentExtensionInfo &info) {
831 JSONStringValueSerializer serializer(info.manifest);
832 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL));
833 if (!manifest.get()) {
834 DLOG(ERROR) << "Failed to parse manifest for extension";
[email protected]a964e112011-04-14 21:52:51835 return NULL;
[email protected]61b55b62011-03-24 09:03:10836 }
837
[email protected]83048a22011-03-29 00:14:13838 int flags = Extension::REQUIRE_KEY;
839 if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT))
840 flags |= Extension::STRICT_ERROR_CHECKS;
[email protected]61b55b62011-03-24 09:03:10841 std::string error;
842 scoped_refptr<const Extension> extension(Extension::Create(
843 info.root_directory,
844 Extension::COMPONENT,
845 *static_cast<DictionaryValue*>(manifest.get()),
[email protected]83048a22011-03-29 00:14:13846 flags,
[email protected]61b55b62011-03-24 09:03:10847 &error));
848 if (!extension.get()) {
849 NOTREACHED() << error;
[email protected]a964e112011-04-14 21:52:51850 return NULL;
[email protected]61b55b62011-03-24 09:03:10851 }
852 AddExtension(extension);
[email protected]a964e112011-04-14 21:52:51853 return extension;
[email protected]61b55b62011-03-24 09:03:10854}
855
[email protected]eaa7dd182010-12-14 11:09:00856void ExtensionService::LoadAllExtensions() {
[email protected]a29a517a2011-01-21 21:11:12857 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a315ba92010-11-16 14:12:21858
[email protected]cc2c3432009-11-06 17:24:36859 base::TimeTicks start_time = base::TimeTicks::Now();
860
[email protected]1952c7d2010-03-04 23:48:34861 // Load any component extensions.
862 LoadComponentExtensions();
863
[email protected]e72e8eb82009-06-18 17:21:51864 // Load the previously installed extensions.
[email protected]a315ba92010-11-16 14:12:21865 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
[email protected]e6090e42010-03-23 22:44:08866 extension_prefs_->GetInstalledExtensionsInfo());
[email protected]c6d474f82009-12-16 21:11:06867
[email protected]a315ba92010-11-16 14:12:21868 std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0);
869 bool should_write_prefs = false;
870
871 for (size_t i = 0; i < extensions_info->size(); ++i) {
872 ExtensionInfo* info = extensions_info->at(i).get();
873
874 ManifestReloadReason reload_reason = ShouldReloadExtensionManifest(*info);
875 ++reload_reason_counts[reload_reason];
876 UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestReloadEnumValue",
877 reload_reason, 100);
878
879 if (reload_reason != NOT_NEEDED) {
880 // Reloading and extension reads files from disk. We do this on the
881 // UI thread because reloads should be very rare, and the complexity
882 // added by delaying the time when the extensions service knows about
883 // all extensions is significant. See crbug.com/37548 for details.
884 // |allow_io| disables tests that file operations run on the file
885 // thread.
886 base::ThreadRestrictions::ScopedAllowIO allow_io;
887
[email protected]83048a22011-03-29 00:14:13888 int flags = Extension::NO_FLAGS;
889 if (Extension::ShouldDoStrictErrorChecking(info->extension_location))
890 flags |= Extension::STRICT_ERROR_CHECKS;
[email protected]3aff9ad2011-04-01 20:26:48891 if (extension_prefs_->AllowFileAccess(info->extension_id))
892 flags |= Extension::ALLOW_FILE_ACCESS;
[email protected]a315ba92010-11-16 14:12:21893 std::string error;
894 scoped_refptr<const Extension> extension(
895 extension_file_util::LoadExtension(
[email protected]542258c2011-03-04 21:25:31896 info->extension_path,
897 info->extension_location,
[email protected]83048a22011-03-29 00:14:13898 flags,
[email protected]542258c2011-03-04 21:25:31899 &error));
[email protected]a315ba92010-11-16 14:12:21900
901 if (extension.get()) {
902 extensions_info->at(i)->extension_manifest.reset(
903 static_cast<DictionaryValue*>(
904 extension->manifest_value()->DeepCopy()));
905 should_write_prefs = true;
906 }
[email protected]c6d474f82009-12-16 21:11:06907 }
908 }
909
[email protected]a315ba92010-11-16 14:12:21910 for (size_t i = 0; i < extensions_info->size(); ++i) {
911 LoadInstalledExtension(*extensions_info->at(i), should_write_prefs);
[email protected]c6d474f82009-12-16 21:11:06912 }
913
[email protected]ae09ca62009-08-21 19:46:46914 OnLoadedInstalledExtensions();
[email protected]cc2c3432009-11-06 17:24:36915
[email protected]a315ba92010-11-16 14:12:21916 // The histograms Extensions.ManifestReload* allow us to validate
917 // the assumption that reloading manifest is a rare event.
918 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded",
919 reload_reason_counts[NOT_NEEDED]);
920 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir",
921 reload_reason_counts[UNPACKED_DIR]);
922 UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization",
923 reload_reason_counts[NEEDS_RELOCALIZATION]);
924
[email protected]cc2c3432009-11-06 17:24:36925 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", extensions_.size());
926 UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", disabled_extensions_.size());
927
[email protected]1952c7d2010-03-04 23:48:34928 UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime",
929 base::TimeTicks::Now() - start_time);
[email protected]cc2c3432009-11-06 17:24:36930
[email protected]9b217652010-10-08 22:04:23931 int app_count = 0;
932 int hosted_app_count = 0;
933 int packaged_app_count = 0;
[email protected]1952c7d2010-03-04 23:48:34934 int user_script_count = 0;
935 int extension_count = 0;
936 int theme_count = 0;
937 int external_count = 0;
938 int page_action_count = 0;
939 int browser_action_count = 0;
940 ExtensionList::iterator ex;
941 for (ex = extensions_.begin(); ex != extensions_.end(); ++ex) {
[email protected]9b217652010-10-08 22:04:23942 Extension::Location location = (*ex)->location();
[email protected]7fa19f82010-12-21 19:40:08943 Extension::Type type = (*ex)->GetType();
[email protected]9b217652010-10-08 22:04:23944 if ((*ex)->is_app()) {
945 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation",
946 location, 100);
947 } else if (type == Extension::TYPE_EXTENSION) {
948 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation",
949 location, 100);
950 }
951
[email protected]1952c7d2010-03-04 23:48:34952 // Don't count component extensions, since they are only extensions as an
953 // implementation detail.
[email protected]9b217652010-10-08 22:04:23954 if (location == Extension::COMPONENT)
[email protected]1952c7d2010-03-04 23:48:34955 continue;
956
[email protected]e8c729a2010-03-09 19:55:19957 // Don't count unpacked extensions, since they're a developer-specific
958 // feature.
[email protected]9b217652010-10-08 22:04:23959 if (location == Extension::LOAD)
[email protected]e8c729a2010-03-09 19:55:19960 continue;
961
[email protected]9b217652010-10-08 22:04:23962 // Using an enumeration shows us the total installed ratio across all users.
963 // Using the totals per user at each startup tells us the distribution of
964 // usage for each user (e.g. 40% of users have at least one app installed).
965 UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100);
966 switch (type) {
967 case Extension::TYPE_THEME:
[email protected]a315ba92010-11-16 14:12:21968 ++theme_count;
[email protected]9b217652010-10-08 22:04:23969 break;
970 case Extension::TYPE_USER_SCRIPT:
[email protected]a315ba92010-11-16 14:12:21971 ++user_script_count;
[email protected]9b217652010-10-08 22:04:23972 break;
973 case Extension::TYPE_HOSTED_APP:
[email protected]a315ba92010-11-16 14:12:21974 ++app_count;
975 ++hosted_app_count;
[email protected]9b217652010-10-08 22:04:23976 break;
977 case Extension::TYPE_PACKAGED_APP:
[email protected]a315ba92010-11-16 14:12:21978 ++app_count;
979 ++packaged_app_count;
[email protected]9b217652010-10-08 22:04:23980 break;
981 case Extension::TYPE_EXTENSION:
982 default:
[email protected]a315ba92010-11-16 14:12:21983 ++extension_count;
[email protected]9b217652010-10-08 22:04:23984 break;
[email protected]cc2c3432009-11-06 17:24:36985 }
[email protected]9b217652010-10-08 22:04:23986 if (Extension::IsExternalLocation(location))
[email protected]a315ba92010-11-16 14:12:21987 ++external_count;
[email protected]9b217652010-10-08 22:04:23988 if ((*ex)->page_action() != NULL)
[email protected]a315ba92010-11-16 14:12:21989 ++page_action_count;
[email protected]9b217652010-10-08 22:04:23990 if ((*ex)->browser_action() != NULL)
[email protected]a315ba92010-11-16 14:12:21991 ++browser_action_count;
[email protected]fe2dd7742011-04-19 22:52:49992
993 RecordPermissionMessagesHistogram(
994 ex->get(), "Extensions.Permissions_Load");
[email protected]cc2c3432009-11-06 17:24:36995 }
[email protected]9b217652010-10-08 22:04:23996 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp", app_count);
997 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadHostedApp", hosted_app_count);
998 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPackagedApp", packaged_app_count);
[email protected]1952c7d2010-03-04 23:48:34999 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtension", extension_count);
1000 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadUserScript", user_script_count);
1001 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadTheme", theme_count);
1002 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExternal", external_count);
1003 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPageAction", page_action_count);
1004 UMA_HISTOGRAM_COUNTS_100("Extensions.LoadBrowserAction",
1005 browser_action_count);
[email protected]ae09ca62009-08-21 19:46:461006}
1007
[email protected]fe2dd7742011-04-19 22:52:491008// static
1009void ExtensionService::RecordPermissionMessagesHistogram(
1010 const Extension* e, const char* histogram) {
1011 // Since this is called from multiple sources, and since the Histogram macros
1012 // use statics, we need to manually lookup the Histogram ourselves.
1013 base::Histogram* counter = base::LinearHistogram::FactoryGet(
1014 histogram,
1015 1,
1016 Extension::PermissionMessage::ID_ENUM_BOUNDARY,
1017 Extension::PermissionMessage::ID_ENUM_BOUNDARY + 1,
1018 base::Histogram::kUmaTargetedHistogramFlag);
1019
1020 std::vector<Extension::PermissionMessage> permissions =
1021 e->GetPermissionMessages();
1022 if (permissions.empty()) {
1023 counter->Add(Extension::PermissionMessage::ID_NONE);
1024 } else {
1025 std::vector<Extension::PermissionMessage>::iterator it;
1026 for (it = permissions.begin(); it != permissions.end(); ++it)
1027 counter->Add(it->message_id());
1028 }
1029}
1030
[email protected]eaa7dd182010-12-14 11:09:001031void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info,
[email protected]542258c2011-03-04 21:25:311032 bool write_to_prefs) {
[email protected]ae09ca62009-08-21 19:46:461033 std::string error;
[email protected]9adb9692010-10-29 23:14:021034 scoped_refptr<const Extension> extension(NULL);
[email protected]306a2bd2010-08-11 14:56:361035 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) {
1036 error = errors::kDisabledByPolicy;
1037 } else if (info.extension_manifest.get()) {
[email protected]83048a22011-03-29 00:14:131038 int flags = Extension::NO_FLAGS;
1039 if (info.extension_location != Extension::LOAD)
1040 flags |= Extension::REQUIRE_KEY;
1041 if (Extension::ShouldDoStrictErrorChecking(info.extension_location))
1042 flags |= Extension::STRICT_ERROR_CHECKS;
[email protected]3aff9ad2011-04-01 20:26:481043 if (extension_prefs_->AllowFileAccess(info.extension_id))
1044 flags |= Extension::ALLOW_FILE_ACCESS;
[email protected]66e4eb32010-10-27 20:37:411045 extension = Extension::Create(
[email protected]542258c2011-03-04 21:25:311046 info.extension_path,
1047 info.extension_location,
1048 *info.extension_manifest,
[email protected]83048a22011-03-29 00:14:131049 flags,
[email protected]542258c2011-03-04 21:25:311050 &error);
[email protected]ae09ca62009-08-21 19:46:461051 } else {
[email protected]c6d474f82009-12-16 21:11:061052 error = errors::kManifestUnreadable;
[email protected]ae09ca62009-08-21 19:46:461053 }
1054
1055 if (!extension) {
[email protected]c6d474f82009-12-16 21:11:061056 ReportExtensionLoadError(info.extension_path,
[email protected]d11c8e92009-10-20 23:26:401057 error,
1058 NotificationType::EXTENSION_INSTALL_ERROR,
1059 false);
[email protected]ae09ca62009-08-21 19:46:461060 return;
1061 }
1062
[email protected]c6d474f82009-12-16 21:11:061063 if (write_to_prefs)
1064 extension_prefs_->UpdateManifest(extension);
1065
[email protected]49cd1572011-02-08 21:38:451066 AddExtension(extension);
[email protected]9f1087e2009-06-15 17:29:321067}
1068
[email protected]eaa7dd182010-12-14 11:09:001069void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:421070 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:061071 // was loaded, otherwise a race can arise where a renderer that is created
1072 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:421073 // that the request context doesn't yet know about. The profile is responsible
1074 // for ensuring its URLRequestContexts appropriately discover the loaded
1075 // extension.
1076 if (profile_) {
1077 profile_->RegisterExtensionWithRequestContexts(extension);
[email protected]19eb80152011-02-26 00:28:431078 profile_->GetExtensionSpecialStoragePolicy()->
1079 GrantRightsForExtension(extension);
[email protected]62d30f42009-10-01 22:36:061080 }
1081
1082 NotificationService::current()->Notify(
1083 NotificationType::EXTENSION_LOADED,
[email protected]24e7a9d2009-11-04 11:11:341084 Source<Profile>(profile_),
[email protected]9adb9692010-10-29 23:14:021085 Details<const Extension>(extension));
[email protected]2de307592011-04-05 21:16:581086
1087 bool plugins_changed = false;
1088 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1089 const Extension::PluginInfo& plugin = extension->plugins()[i];
1090 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
1091 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(plugin.path);
1092 plugins_changed = true;
1093 if (!plugin.is_public) {
1094 PluginService::GetInstance()->RestrictPluginToUrl(
1095 plugin.path, extension->url());
1096 }
1097 }
[email protected]84396dbc2011-04-14 06:33:421098
1099 bool nacl_modules_changed = false;
1100 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1101 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001102 RegisterNaClModule(module.url, module.mime_type);
[email protected]84396dbc2011-04-14 06:33:421103 nacl_modules_changed = true;
1104 }
1105
1106 if (nacl_modules_changed)
[email protected]cebc3dc2011-04-18 17:15:001107 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421108
1109 if (plugins_changed || nacl_modules_changed)
[email protected]2de307592011-04-05 21:16:581110 PluginService::GetInstance()->PurgePluginListCache(false);
[email protected]62d30f42009-10-01 22:36:061111}
1112
[email protected]a9f39a312010-12-23 22:14:271113void ExtensionService::NotifyExtensionUnloaded(
1114 const Extension* extension, UnloadedExtensionInfo::Reason reason) {
1115 UnloadedExtensionInfo details(extension, reason);
[email protected]62d30f42009-10-01 22:36:061116 NotificationService::current()->Notify(
1117 NotificationType::EXTENSION_UNLOADED,
[email protected]24e7a9d2009-11-04 11:11:341118 Source<Profile>(profile_),
[email protected]a9f39a312010-12-23 22:14:271119 Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061120
[email protected]57a777f72010-03-31 01:09:421121 if (profile_) {
1122 profile_->UnregisterExtensionWithRequestContexts(extension);
[email protected]19eb80152011-02-26 00:28:431123 profile_->GetExtensionSpecialStoragePolicy()->
1124 RevokeRightsForExtension(extension);
[email protected]b777b332011-04-16 04:01:081125#if defined(OS_CHROMEOS)
1126 // Revoke external file access to
[email protected]45194082011-04-16 10:33:191127 if (profile_->GetFileSystemContext() &&
1128 profile_->GetFileSystemContext()->path_manager() &&
[email protected]bbee71d2011-04-16 10:24:541129 profile_->GetFileSystemContext()->path_manager()->external_provider()) {
1130 profile_->GetFileSystemContext()->path_manager()->external_provider()->
1131 RevokeAccessForExtension(extension->id());
1132 }
[email protected]b777b332011-04-16 04:01:081133#endif
[email protected]62d30f42009-10-01 22:36:061134 }
[email protected]2de307592011-04-05 21:16:581135
1136 bool plugins_changed = false;
1137 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1138 const Extension::PluginInfo& plugin = extension->plugins()[i];
1139 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1140 NewRunnableFunction(&ForceShutdownPlugin,
1141 plugin.path));
1142 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
1143 webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath(
1144 plugin.path);
1145 plugins_changed = true;
1146 if (!plugin.is_public)
1147 PluginService::GetInstance()->RestrictPluginToUrl(plugin.path, GURL());
1148 }
[email protected]84396dbc2011-04-14 06:33:421149
1150 bool nacl_modules_changed = false;
1151 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1152 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001153 UnregisterNaClModule(module.url);
[email protected]84396dbc2011-04-14 06:33:421154 nacl_modules_changed = true;
1155 }
1156
1157 if (nacl_modules_changed)
[email protected]cebc3dc2011-04-18 17:15:001158 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421159
1160 if (plugins_changed || nacl_modules_changed)
[email protected]2de307592011-04-05 21:16:581161 PluginService::GetInstance()->PurgePluginListCache(false);
[email protected]62d30f42009-10-01 22:36:061162}
1163
[email protected]eaa7dd182010-12-14 11:09:001164void ExtensionService::UpdateExtensionBlacklist(
[email protected]6b75ec32009-08-14 06:37:181165 const std::vector<std::string>& blacklist) {
1166 // Use this set to indicate if an extension in the blacklist has been used.
1167 std::set<std::string> blacklist_set;
1168 for (unsigned int i = 0; i < blacklist.size(); ++i) {
1169 if (Extension::IdIsValid(blacklist[i])) {
1170 blacklist_set.insert(blacklist[i]);
1171 }
1172 }
1173 extension_prefs_->UpdateBlacklist(blacklist_set);
1174 std::vector<std::string> to_be_removed;
1175 // Loop current extensions, unload installed extensions.
1176 for (ExtensionList::const_iterator iter = extensions_.begin();
1177 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021178 const Extension* extension = (*iter);
[email protected]6b75ec32009-08-14 06:37:181179 if (blacklist_set.find(extension->id()) != blacklist_set.end()) {
1180 to_be_removed.push_back(extension->id());
1181 }
1182 }
1183
1184 // UnloadExtension will change the extensions_ list. So, we should
1185 // call it outside the iterator loop.
1186 for (unsigned int i = 0; i < to_be_removed.size(); ++i) {
[email protected]a9f39a312010-12-23 22:14:271187 UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE);
[email protected]6b75ec32009-08-14 06:37:181188 }
1189}
1190
[email protected]0a071a32011-02-08 00:18:241191Profile* ExtensionService::profile() {
1192 return profile_;
1193}
1194
[email protected]eaa7dd182010-12-14 11:09:001195void ExtensionService::DestroyingProfile() {
[email protected]94b4ffc2011-02-04 05:55:171196 if (updater_.get()) {
1197 updater_->Stop();
1198 }
[email protected]97d2f1d2011-01-15 00:41:081199 browser_event_router_.reset();
[email protected]118de7892011-03-16 13:31:401200 preference_event_router_.reset();
[email protected]2fb7dc982010-09-29 12:24:281201 pref_change_registrar_.RemoveAll();
[email protected]aa96d3a2010-08-21 08:45:251202 profile_ = NULL;
[email protected]2fb7dc982010-09-29 12:24:281203 toolbar_model_.DestroyingProfile();
[email protected]aa96d3a2010-08-21 08:45:251204}
1205
[email protected]eaa7dd182010-12-14 11:09:001206ExtensionPrefs* ExtensionService::extension_prefs() {
[email protected]ddb1e5a2010-12-13 20:10:451207 return extension_prefs_;
1208}
1209
[email protected]2859946f2011-04-04 18:18:061210ExtensionUpdater* ExtensionService::updater() {
1211 return updater_.get();
1212}
1213
[email protected]eaa7dd182010-12-14 11:09:001214void ExtensionService::CheckAdminBlacklist() {
[email protected]aa96d3a2010-08-21 08:45:251215 std::vector<std::string> to_be_removed;
1216 // Loop through extensions list, unload installed extensions.
1217 for (ExtensionList::const_iterator iter = extensions_.begin();
1218 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021219 const Extension* extension = (*iter);
[email protected]aa96d3a2010-08-21 08:45:251220 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id()))
1221 to_be_removed.push_back(extension->id());
1222 }
1223
1224 // UnloadExtension will change the extensions_ list. So, we should
1225 // call it outside the iterator loop.
1226 for (unsigned int i = 0; i < to_be_removed.size(); ++i)
[email protected]a9f39a312010-12-23 22:14:271227 UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE);
[email protected]aa96d3a2010-08-21 08:45:251228}
1229
[email protected]31206602011-04-13 23:07:321230void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351231 if (updater()) {
[email protected]31206602011-04-13 23:07:321232 updater()->CheckSoon();
[email protected]c3cfb012011-04-06 22:07:351233 } else {
[email protected]31206602011-04-13 23:07:321234 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351235 }
1236}
1237
[email protected]90310d92011-04-17 07:35:041238void ExtensionService::ProcessSyncData(
1239 const ExtensionSyncData& extension_sync_data,
1240 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow) {
1241 const std::string& id = extension_sync_data.id;
1242
1243 // Handle uninstalls first.
1244 if (extension_sync_data.uninstalled) {
1245 std::string error;
1246 if (!UninstallExtensionHelper(this, id)) {
1247 LOG(WARNING) << "Could not uninstall extension " << id
1248 << " for sync";
1249 }
1250 return;
1251 }
1252
1253 const Extension* extension = GetExtensionByIdInternal(id, true, true);
1254 // TODO(akalin): Figure out what to do with terminated extensions.
1255
1256 // Handle already-installed extensions (just update settings).
1257 //
1258 // TODO(akalin): Ideally, we should be able to set prefs for an
1259 // extension regardless of whether or not it's installed (and have
1260 // it automatially apply on install).
1261 if (extension) {
1262 if (extension_sync_data.enabled) {
1263 EnableExtension(id);
1264 } else {
1265 DisableExtension(id);
1266 }
1267 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled);
1268 int result = extension->version()->CompareTo(extension_sync_data.version);
1269 if (result < 0) {
1270 // Extension is outdated.
1271 CheckForUpdatesSoon();
1272 } else if (result > 0) {
1273 // Sync version is outdated. Do nothing for now, as sync code
1274 // in other places will eventually update the sync data.
1275 //
1276 // TODO(akalin): Move that code here.
1277 }
1278 return;
1279 }
1280
1281 // Handle not-yet-installed extensions.
1282 //
1283 // TODO(akalin): Replace silent update with a list of enabled
1284 // permissions.
1285 pending_extension_manager()->AddFromSync(
1286 id,
1287 extension_sync_data.update_url,
1288 should_allow,
1289 true, // install_silently
1290 extension_sync_data.enabled,
1291 extension_sync_data.incognito_enabled);
1292 CheckForUpdatesSoon();
1293}
1294
[email protected]c3cfb012011-04-06 22:07:351295bool ExtensionService::IsIncognitoEnabled(
1296 const std::string& extension_id) const {
1297 // If this is an existing component extension we always allow it to
1298 // work in incognito mode.
1299 const Extension* extension = GetExtensionById(extension_id, true);
1300 if (extension && extension->location() == Extension::COMPONENT)
[email protected]cb0ce1e022010-03-10 19:54:411301 return true;
1302
1303 // Check the prefs.
[email protected]c3cfb012011-04-06 22:07:351304 return extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]db7331a2010-02-25 22:10:501305}
[email protected]55a35692010-02-11 23:25:211306
[email protected]c3cfb012011-04-06 22:07:351307void ExtensionService::SetIsIncognitoEnabled(
1308 const std::string& extension_id, bool enabled) {
1309 const Extension* extension = GetExtensionById(extension_id, false);
1310 if (extension && extension->location() == Extension::COMPONENT) {
1311 // This shouldn't be called for component extensions.
1312 NOTREACHED();
1313 return;
1314 }
1315
[email protected]8c6c8c22011-03-09 12:52:341316 // Broadcast unloaded and loaded events to update browser state. Only bother
1317 // if the value changed and the extension is actually enabled, since there is
1318 // no UI otherwise.
[email protected]c3cfb012011-04-06 22:07:351319 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]8c6c8c22011-03-09 12:52:341320 if (enabled == old_enabled)
1321 return;
1322
[email protected]c3cfb012011-04-06 22:07:351323 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
1324 if (extension) {
[email protected]a9f39a312010-12-23 22:14:271325 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE);
[email protected]568f33d2010-08-04 17:06:411326 NotifyExtensionLoaded(extension);
1327 }
[email protected]55a35692010-02-11 23:25:211328}
1329
[email protected]eaa7dd182010-12-14 11:09:001330bool ExtensionService::CanCrossIncognito(const Extension* extension) {
[email protected]2a8f24e2010-11-03 21:37:051331 // We allow the extension to see events and data from another profile iff it
1332 // uses "spanning" behavior and it has incognito access. "split" mode
1333 // extensions only see events for a matching profile.
[email protected]c3cfb012011-04-06 22:07:351334 return IsIncognitoEnabled(extension->id()) &&
1335 !extension->incognito_split_mode();
[email protected]2a8f24e2010-11-03 21:37:051336}
1337
[email protected]eaa7dd182010-12-14 11:09:001338bool ExtensionService::AllowFileAccess(const Extension* extension) {
[email protected]05c82182010-06-24 17:49:081339 return (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]334e04a2010-06-24 23:34:441340 switches::kDisableExtensionsFileAccessCheck) ||
[email protected]05c82182010-06-24 17:49:081341 extension_prefs_->AllowFileAccess(extension->id()));
1342}
1343
[email protected]eaa7dd182010-12-14 11:09:001344void ExtensionService::SetAllowFileAccess(const Extension* extension,
[email protected]3aff9ad2011-04-01 20:26:481345 bool allow) {
1346 // Reload to update browser state. Only bother if the value changed and the
1347 // extension is actually enabled, since there is no UI otherwise.
1348 bool old_allow = AllowFileAccess(extension);
1349 if (allow == old_allow)
1350 return;
1351
[email protected]05c82182010-06-24 17:49:081352 extension_prefs_->SetAllowFileAccess(extension->id(), allow);
[email protected]3aff9ad2011-04-01 20:26:481353
1354 bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
1355 extension) != extensions_.end();
1356 if (extension_is_enabled)
1357 ReloadExtension(extension->id());
[email protected]05c82182010-06-24 17:49:081358}
1359
[email protected]eaa7dd182010-12-14 11:09:001360bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) {
[email protected]f681c782010-11-19 11:19:391361 return extension_prefs_->GetBrowserActionVisibility(extension);
1362}
1363
[email protected]eaa7dd182010-12-14 11:09:001364void ExtensionService::SetBrowserActionVisibility(const Extension* extension,
[email protected]8e4560b62011-01-14 10:09:141365 bool visible) {
[email protected]f681c782010-11-19 11:19:391366 extension_prefs_->SetBrowserActionVisibility(extension, visible);
1367}
1368
[email protected]8e4560b62011-01-14 10:09:141369// Some extensions will autoupdate themselves externally from Chrome. These
1370// are typically part of some larger client application package. To support
1371// these, the extension will register its location in the the preferences file
1372// (and also, on Windows, in the registry) and this code will periodically
1373// check that location for a .crx file, which it will then install locally if
1374// a new version is available.
1375// Errors are reported through ExtensionErrorReporter. Succcess is not
1376// reported.
[email protected]eaa7dd182010-12-14 11:09:001377void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121378 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141379
1380 // Note that this installation is intentionally silent (since it didn't
1381 // go through the front-end). Extensions that are registered in this
1382 // way are effectively considered 'pre-bundled', and so implicitly
1383 // trusted. In general, if something has HKLM or filesystem access,
1384 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121385
1386 // If any external extension records give a URL, a provider will set
1387 // this to true. Used by OnExternalProviderReady() to see if we need
1388 // to start an update check to fetch a new external extension.
1389 external_extension_url_added_ = false;
[email protected]8e4560b62011-01-14 10:09:141390
1391 // Ask each external extension provider to give us a call back for each
1392 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
1393 ProviderCollection::const_iterator i;
1394 for (i = external_extension_providers_.begin();
1395 i != external_extension_providers_.end(); ++i) {
1396 ExternalExtensionProviderInterface* provider = i->get();
1397 provider->VisitRegisteredExtension();
1398 }
1399
1400 // Uninstall of unclaimed extensions will happen after all the providers
[email protected]a29a517a2011-01-21 21:11:121401 // had reported ready. Every provider calls OnExternalProviderReady()
1402 // when it finishes, and OnExternalProviderReady() only acts when all
1403 // providers are ready. In case there are no providers, we call it
1404 // to trigger removal of extensions that used to have an external source.
1405 if (external_extension_providers_.empty())
1406 OnExternalProviderReady();
[email protected]9f1087e2009-06-15 17:29:321407}
1408
[email protected]8e4560b62011-01-14 10:09:141409void ExtensionService::OnExternalProviderReady() {
[email protected]a29a517a2011-01-21 21:11:121410 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1411
1412 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141413 // if all of them are finished. So we check them first.
1414 ProviderCollection::const_iterator i;
1415 for (i = external_extension_providers_.begin();
1416 i != external_extension_providers_.end(); ++i) {
1417 ExternalExtensionProviderInterface* provider = i->get();
[email protected]a29a517a2011-01-21 21:11:121418 if (!provider->IsReady())
[email protected]8e4560b62011-01-14 10:09:141419 return;
[email protected]8e4560b62011-01-14 10:09:141420 }
1421
[email protected]a29a517a2011-01-21 21:11:121422 // All the providers are ready. Install any pending extensions.
1423 if (external_extension_url_added_ && updater()) {
1424 external_extension_url_added_ = false;
[email protected]8e4560b62011-01-14 10:09:141425 updater()->CheckNow();
1426 }
1427
1428 // Uninstall all the unclaimed extensions.
1429 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
1430 extension_prefs_->GetInstalledExtensionsInfo());
1431 for (size_t i = 0; i < extensions_info->size(); ++i) {
1432 ExtensionInfo* info = extensions_info->at(i).get();
1433 if (Extension::IsExternalLocation(info->extension_location))
1434 CheckExternalUninstall(info->extension_id);
1435 }
[email protected]6c751e72010-11-23 10:11:101436}
1437
[email protected]a9f39a312010-12-23 22:14:271438void ExtensionService::UnloadExtension(
1439 const std::string& extension_id,
1440 UnloadedExtensionInfo::Reason reason) {
[email protected]27e469a2010-01-11 20:35:091441 // Make sure the extension gets deleted after we return from this function.
[email protected]9adb9692010-10-29 23:14:021442 scoped_refptr<const Extension> extension(
[email protected]0c6da502009-08-14 22:32:391443 GetExtensionByIdInternal(extension_id, true, true));
[email protected]631cf822009-05-15 07:01:251444
[email protected]fa0c96732010-11-17 00:14:231445 // This method can be called via PostTask, so the extension may have been
1446 // unloaded by the time this runs.
1447 if (!extension)
1448 return;
[email protected]0c6da502009-08-14 22:32:391449
[email protected]1eb175082010-02-10 09:26:161450 // Keep information about the extension so that we can reload it later
1451 // even if it's not permanently installed.
1452 unloaded_extension_paths_[extension->id()] = extension->path();
1453
[email protected]f17dbd42010-08-16 23:21:101454 // Clean up if the extension is meant to be enabled after a reload.
1455 disabled_extension_paths_.erase(extension->id());
1456
[email protected]d7e9a862010-11-03 21:57:491457 // Clean up runtime data.
1458 extension_runtime_data_.erase(extension_id);
1459
[email protected]8f9d4eb2011-02-05 01:39:101460 ExtensionWebUI::UnregisterChromeURLOverrides(profile_,
[email protected]86c008e82009-08-28 20:26:051461 extension->GetChromeURLOverrides());
1462
[email protected]0c6da502009-08-14 22:32:391463 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
1464 disabled_extensions_.end(),
1465 extension.get());
1466 if (iter != disabled_extensions_.end()) {
[email protected]a9f39a312010-12-23 22:14:271467 UnloadedExtensionInfo details(extension, reason);
1468 details.already_disabled = true;
[email protected]0c6da502009-08-14 22:32:391469 disabled_extensions_.erase(iter);
[email protected]866930682009-08-18 22:53:471470 NotificationService::current()->Notify(
[email protected]a9f39a312010-12-23 22:14:271471 NotificationType::EXTENSION_UNLOADED,
[email protected]24e7a9d2009-11-04 11:11:341472 Source<Profile>(profile_),
[email protected]a9f39a312010-12-23 22:14:271473 Details<UnloadedExtensionInfo>(&details));
[email protected]0c6da502009-08-14 22:32:391474 return;
1475 }
1476
1477 iter = std::find(extensions_.begin(), extensions_.end(), extension.get());
[email protected]894bb502009-05-21 22:39:571478
[email protected]631cf822009-05-15 07:01:251479 // Remove the extension from our list.
1480 extensions_.erase(iter);
1481
[email protected]a9f39a312010-12-23 22:14:271482 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]aab98a52009-12-02 03:22:351483 UpdateActiveExtensionsInCrashReporter();
[email protected]631cf822009-05-15 07:01:251484}
1485
[email protected]eaa7dd182010-12-14 11:09:001486void ExtensionService::UnloadAllExtensions() {
[email protected]19eb80152011-02-26 00:28:431487 if (profile_) {
1488 profile_->GetExtensionSpecialStoragePolicy()->
1489 RevokeRightsForAllExtensions();
1490 }
[email protected]9f1087e2009-06-15 17:29:321491 extensions_.clear();
[email protected]cd500f72010-06-25 23:44:321492 disabled_extensions_.clear();
[email protected]bb7f40952011-01-13 00:21:201493 terminated_extension_ids_.clear();
1494 terminated_extensions_.clear();
[email protected]d7e9a862010-11-03 21:57:491495 extension_runtime_data_.clear();
[email protected]cd500f72010-06-25 23:44:321496
[email protected]c6e4a3412009-06-24 15:45:291497 // TODO(erikkay) should there be a notification for this? We can't use
1498 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1499 // or uninstalled, and UnloadAll is just part of shutdown.
[email protected]9f1087e2009-06-15 17:29:321500}
1501
[email protected]eaa7dd182010-12-14 11:09:001502void ExtensionService::ReloadExtensions() {
[email protected]9f1087e2009-06-15 17:29:321503 UnloadAllExtensions();
1504 LoadAllExtensions();
1505}
1506
[email protected]eaa7dd182010-12-14 11:09:001507void ExtensionService::GarbageCollectExtensions() {
[email protected]39d9f62c2010-12-03 10:48:501508 if (extension_prefs_->pref_service()->ReadOnly())
[email protected]ba399672010-04-06 15:42:391509 return;
1510
[email protected]ca3dbf52010-05-19 22:27:061511 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info(
1512 extension_prefs_->GetInstalledExtensionsInfo());
1513
1514 std::map<std::string, FilePath> extension_paths;
1515 for (size_t i = 0; i < info->size(); ++i)
1516 extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path;
1517
[email protected]ca4b5fa32010-10-09 12:42:181518 BrowserThread::PostTask(
1519 BrowserThread::FILE, FROM_HERE,
[email protected]95d29192009-10-30 01:49:061520 NewRunnableFunction(
1521 &extension_file_util::GarbageCollectExtensions, install_directory_,
[email protected]ca3dbf52010-05-19 22:27:061522 extension_paths));
[email protected]f6ccd652010-11-17 00:48:341523
1524 // Also garbage-collect themes. We check |profile_| to be
1525 // defensive; in the future, we may call GarbageCollectExtensions()
1526 // from somewhere other than Init() (e.g., in a timer).
1527 if (profile_) {
[email protected]18280372011-03-22 18:05:221528 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
[email protected]f6ccd652010-11-17 00:48:341529 }
[email protected]3cf4f0992009-02-03 23:00:301530}
1531
[email protected]eaa7dd182010-12-14 11:09:001532void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]93fd78f42009-07-10 16:43:171533 if (updater_.get()) {
1534 updater_->Start();
1535 }
[email protected]fa6a9102010-11-22 15:38:501536
1537 ready_ = true;
[email protected]e72e8eb82009-06-18 17:21:511538 NotificationService::current()->Notify(
1539 NotificationType::EXTENSIONS_READY,
[email protected]24e7a9d2009-11-04 11:11:341540 Source<Profile>(profile_),
[email protected]e72e8eb82009-06-18 17:21:511541 NotificationService::NoDetails());
1542}
1543
[email protected]49cd1572011-02-08 21:38:451544void ExtensionService::AddExtension(const Extension* extension) {
[email protected]ae09ca62009-08-21 19:46:461545 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:021546 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]9f1087e2009-06-15 17:29:321547
[email protected]1eb175082010-02-10 09:26:161548 // The extension is now loaded, remove its data from unloaded extension map.
1549 unloaded_extension_paths_.erase(extension->id());
1550
[email protected]bb7f40952011-01-13 00:21:201551 // If a terminated extension is loaded, remove it from the terminated list.
1552 UntrackTerminatedExtension(extension->id());
1553
[email protected]f17dbd42010-08-16 23:21:101554 // If the extension was disabled for a reload, then enable it.
1555 if (disabled_extension_paths_.erase(extension->id()) > 0)
1556 EnableExtension(extension->id());
1557
[email protected]d728e002010-12-08 04:46:231558 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1559 // default extension state to DISABLED when the --disable-extensions flag
1560 // is set (http://crbug.com/29067).
1561 if (!extensions_enabled() &&
1562 !extension->is_theme() &&
[email protected]aebe23a32010-12-10 22:15:481563 extension->location() != Extension::COMPONENT &&
1564 !Extension::IsExternalLocation(extension->location()))
[email protected]d728e002010-12-08 04:46:231565 return;
1566
1567 // Check if the extension's privileges have changed and disable the
1568 // extension if necessary.
[email protected]8d888c12010-11-30 00:00:251569 DisableIfPrivilegeIncrease(extension);
[email protected]0c6da502009-08-14 22:32:391570
[email protected]8d888c12010-11-30 00:00:251571 switch (extension_prefs_->GetExtensionState(extension->id())) {
1572 case Extension::ENABLED:
1573 extensions_.push_back(scoped_extension);
[email protected]1e8c93f2010-02-08 22:58:311574
[email protected]8d888c12010-11-30 00:00:251575 NotifyExtensionLoaded(extension);
[email protected]0c6da502009-08-14 22:32:391576
[email protected]8f9d4eb2011-02-05 01:39:101577 ExtensionWebUI::RegisterChromeURLOverrides(
[email protected]8d888c12010-11-30 00:00:251578 profile_, extension->GetChromeURLOverrides());
1579 break;
1580 case Extension::DISABLED:
1581 disabled_extensions_.push_back(scoped_extension);
1582 NotificationService::current()->Notify(
1583 NotificationType::EXTENSION_UPDATE_DISABLED,
1584 Source<Profile>(profile_),
1585 Details<const Extension>(extension));
1586 break;
1587 default:
1588 NOTREACHED();
1589 break;
[email protected]e72e8eb82009-06-18 17:21:511590 }
[email protected]aab98a52009-12-02 03:22:351591
[email protected]d7e9a862010-11-03 21:57:491592 SetBeingUpgraded(extension, false);
[email protected]1e8c93f2010-02-08 22:58:311593
[email protected]aab98a52009-12-02 03:22:351594 UpdateActiveExtensionsInCrashReporter();
[email protected]0b004da2010-07-02 17:54:311595
1596 if (profile_->GetTemplateURLModel())
1597 profile_->GetTemplateURLModel()->RegisterExtensionKeyword(extension);
[email protected]b671760b2010-07-15 21:13:471598
1599 // Load the icon for omnibox-enabled extensions so it will be ready to display
1600 // in the URL bar.
[email protected]29d0d4ac2010-09-08 21:10:311601 if (!extension->omnibox_keyword().empty()) {
1602 omnibox_popup_icon_manager_.LoadIcon(extension);
[email protected]b671760b2010-07-15 21:13:471603 omnibox_icon_manager_.LoadIcon(extension);
[email protected]29d0d4ac2010-09-08 21:10:311604 }
[email protected]aab98a52009-12-02 03:22:351605}
1606
[email protected]eaa7dd182010-12-14 11:09:001607void ExtensionService::DisableIfPrivilegeIncrease(const Extension* extension) {
[email protected]8d888c12010-11-30 00:00:251608 // We keep track of all permissions the user has granted each extension.
1609 // This allows extensions to gracefully support backwards compatibility
1610 // by including unknown permissions in their manifests. When the user
1611 // installs the extension, only the recognized permissions are recorded.
1612 // When the unknown permissions become recognized (e.g., through browser
1613 // upgrade), we can prompt the user to accept these new permissions.
1614 // Extensions can also silently upgrade to less permissions, and then
1615 // silently upgrade to a version that adds these permissions back.
1616 //
1617 // For example, pretend that Chrome 10 includes a permission "omnibox"
1618 // for an API that adds suggestions to the omnibox. An extension can
1619 // maintain backwards compatibility while still having "omnibox" in the
1620 // manifest. If a user installs the extension on Chrome 9, the browser
1621 // will record the permissions it recognized, not including "omnibox."
1622 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1623 // will disable the extension and prompt the user to approve the increase
1624 // in privileges. The extension could then release a new version that
1625 // removes the "omnibox" permission. When the user upgrades, Chrome will
1626 // still remember that "omnibox" had been granted, so that if the
1627 // extension once again includes "omnibox" in an upgrade, the extension
1628 // can upgrade without requiring this user's approval.
1629 const Extension* old = GetExtensionByIdInternal(extension->id(),
1630 true, true);
1631 bool granted_full_access;
1632 std::set<std::string> granted_apis;
1633 ExtensionExtent granted_extent;
1634
1635 bool is_extension_upgrade = old != NULL;
1636 bool is_privilege_increase = false;
1637
1638 // We only record the granted permissions for INTERNAL extensions, since
1639 // they can't silently increase privileges.
1640 if (extension->location() == Extension::INTERNAL) {
1641 // Add all the recognized permissions if the granted permissions list
1642 // hasn't been initialized yet.
1643 if (!extension_prefs_->GetGrantedPermissions(extension->id(),
1644 &granted_full_access,
1645 &granted_apis,
1646 &granted_extent)) {
1647 GrantPermissions(extension);
1648 CHECK(extension_prefs_->GetGrantedPermissions(extension->id(),
1649 &granted_full_access,
1650 &granted_apis,
1651 &granted_extent));
1652 }
1653
1654 // Here, we check if an extension's privileges have increased in a manner
1655 // that requires the user's approval. This could occur because the browser
1656 // upgraded and recognized additional privileges, or an extension upgrades
1657 // to a version that requires additional privileges.
1658 is_privilege_increase = Extension::IsPrivilegeIncrease(
1659 granted_full_access, granted_apis, granted_extent, extension);
1660 }
1661
1662 if (is_extension_upgrade) {
[email protected]66e26872010-12-03 20:07:251663 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1664 // that we aren't downgrading.
1665 if (extension->location() != Extension::LOAD)
1666 CHECK(extension->version()->CompareTo(*(old->version())) >= 0);
[email protected]8d888c12010-11-30 00:00:251667
1668 // Extensions get upgraded if the privileges are allowed to increase or
1669 // the privileges haven't increased.
1670 if (!is_privilege_increase) {
1671 SetBeingUpgraded(old, true);
1672 SetBeingUpgraded(extension, true);
1673 }
1674
1675 // To upgrade an extension in place, unload the old one and
1676 // then load the new one.
[email protected]a9f39a312010-12-23 22:14:271677 UnloadExtension(old->id(), UnloadedExtensionInfo::UPDATE);
[email protected]8d888c12010-11-30 00:00:251678 old = NULL;
1679 }
1680
1681 // Extension has changed permissions significantly. Disable it. A
1682 // notification should be sent by the caller.
1683 if (is_privilege_increase) {
[email protected]fe2dd7742011-04-19 22:52:491684 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
1685 RecordPermissionMessagesHistogram(
1686 extension, "Extensions.Permissions_AutoDisable");
1687 }
[email protected]8d888c12010-11-30 00:00:251688 extension_prefs_->SetExtensionState(extension, Extension::DISABLED);
1689 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1690 }
1691}
1692
[email protected]eaa7dd182010-12-14 11:09:001693void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:391694 std::set<std::string> extension_ids;
[email protected]aab98a52009-12-02 03:22:351695 for (size_t i = 0; i < extensions_.size(); ++i) {
[email protected]2a500c1b2010-11-05 15:27:341696 if (!extensions_[i]->is_theme() &&
1697 extensions_[i]->location() != Extension::COMPONENT)
[email protected]c8865962009-12-16 07:47:391698 extension_ids.insert(extensions_[i]->id());
[email protected]aab98a52009-12-02 03:22:351699 }
1700
1701 child_process_logging::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:251702}
1703
[email protected]eaa7dd182010-12-14 11:09:001704void ExtensionService::OnExtensionInstalled(const Extension* extension) {
[email protected]a29a517a2011-01-21 21:11:121705 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:201706
[email protected]4416c5a2010-06-26 01:28:571707 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:021708 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]c3cfb012011-04-06 22:07:351709 const std::string& id = extension->id();
1710 bool initial_enable = false;
[email protected]4416c5a2010-06-26 01:28:571711 bool initial_enable_incognito = false;
[email protected]b2907fd2011-03-25 16:43:371712
1713 PendingExtensionInfo pending_extension_info;
[email protected]c3cfb012011-04-06 22:07:351714 if (pending_extension_manager()->GetById(id, &pending_extension_info)) {
1715 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:321716
[email protected]483d1ff2011-03-03 17:12:021717 if (!pending_extension_info.ShouldAllowInstall(*extension)) {
[email protected]4416c5a2010-06-26 01:28:571718 LOG(WARNING)
[email protected]ae6cb3022011-04-04 20:11:541719 << "ShouldAllowInstall() returned false for "
[email protected]c3cfb012011-04-06 22:07:351720 << id << " of type " << extension->GetType()
[email protected]7fa19f82010-12-21 19:40:081721 << " and update URL " << extension->update_url().spec()
1722 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:541723
1724 NotificationService::current()->Notify(
1725 NotificationType::EXTENSION_INSTALL_NOT_ALLOWED,
1726 Source<Profile>(profile_),
1727 Details<const Extension>(extension));
1728
[email protected]4416c5a2010-06-26 01:28:571729 // Delete the extension directory since we're not going to
1730 // load it.
[email protected]ca4b5fa32010-10-09 12:42:181731 BrowserThread::PostTask(
1732 BrowserThread::FILE, FROM_HERE,
[email protected]b2907fd2011-03-25 16:43:371733 NewRunnableFunction(&extension_file_util::DeleteFile,
1734 extension->path(), true));
[email protected]4416c5a2010-06-26 01:28:571735 return;
1736 }
[email protected]8ef78fd2010-08-19 17:14:321737
[email protected]8ef78fd2010-08-19 17:14:321738 if (extension->is_theme()) {
[email protected]483d1ff2011-03-03 17:12:021739 DCHECK(pending_extension_info.enable_on_install());
[email protected]c3cfb012011-04-06 22:07:351740 initial_enable = true;
[email protected]483d1ff2011-03-03 17:12:021741 DCHECK(!pending_extension_info.enable_incognito_on_install());
[email protected]4416c5a2010-06-26 01:28:571742 initial_enable_incognito = false;
1743 } else {
[email protected]c3cfb012011-04-06 22:07:351744 initial_enable = pending_extension_info.enable_on_install();
[email protected]4416c5a2010-06-26 01:28:571745 initial_enable_incognito =
[email protected]483d1ff2011-03-03 17:12:021746 pending_extension_info.enable_incognito_on_install();
[email protected]4416c5a2010-06-26 01:28:571747 }
[email protected]4416c5a2010-06-26 01:28:571748 } else {
[email protected]c3cfb012011-04-06 22:07:351749 // We explicitly want to re-enable an uninstalled external
1750 // extension; if we're here, that means the user is manually
1751 // installing the extension.
1752 initial_enable =
1753 IsExtensionEnabled(id) || IsExternalExtensionUninstalled(id);
1754 initial_enable_incognito = IsIncognitoEnabled(id);
[email protected]aa142702010-03-26 01:26:331755 }
1756
[email protected]9b217652010-10-08 22:04:231757 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
[email protected]7fa19f82010-12-21 19:40:081758 extension->GetType(), 100);
[email protected]fe2dd7742011-04-19 22:52:491759 RecordPermissionMessagesHistogram(
1760 extension, "Extensions.Permissions_Install");
[email protected]eda3c362010-11-12 08:08:231761 ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension);
[email protected]4416c5a2010-06-26 01:28:571762 extension_prefs_->OnExtensionInstalled(
[email protected]c3cfb012011-04-06 22:07:351763 extension, initial_enable ? Extension::ENABLED : Extension::DISABLED,
1764 initial_enable_incognito);
[email protected]25b34332009-06-05 21:53:191765
[email protected]3aff9ad2011-04-01 20:26:481766 // Unpacked extensions default to allowing file access, but if that has been
1767 // overridden, don't reset the value.
1768 if (Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) &&
[email protected]c3cfb012011-04-06 22:07:351769 !extension_prefs_->HasAllowFileAccessSetting(id)) {
1770 extension_prefs_->SetAllowFileAccess(id, true);
[email protected]3aff9ad2011-04-01 20:26:481771 }
[email protected]92a5b1d2010-07-20 00:42:001772
[email protected]a3e61e82011-04-15 20:32:081773 NotificationService::current()->Notify(
1774 NotificationType::EXTENSION_INSTALLED,
1775 Source<Profile>(profile_),
1776 Details<const Extension>(extension));
[email protected]7577a5c52009-07-30 06:21:581777
[email protected]49cd1572011-02-08 21:38:451778 // Transfer ownership of |extension| to AddExtension.
1779 AddExtension(scoped_extension);
[email protected]4a190632009-05-09 01:07:421780}
1781
[email protected]eaa7dd182010-12-14 11:09:001782const Extension* ExtensionService::GetExtensionByIdInternal(
[email protected]b2907fd2011-03-25 16:43:371783 const std::string& id, bool include_enabled, bool include_disabled) const {
[email protected]e957fe52009-06-23 16:51:051784 std::string lowercase_id = StringToLowerASCII(id);
[email protected]0c6da502009-08-14 22:32:391785 if (include_enabled) {
1786 for (ExtensionList::const_iterator iter = extensions_.begin();
1787 iter != extensions_.end(); ++iter) {
1788 if ((*iter)->id() == lowercase_id)
1789 return *iter;
1790 }
1791 }
1792 if (include_disabled) {
1793 for (ExtensionList::const_iterator iter = disabled_extensions_.begin();
1794 iter != disabled_extensions_.end(); ++iter) {
1795 if ((*iter)->id() == lowercase_id)
1796 return *iter;
1797 }
[email protected]ce5c4502009-05-06 16:46:111798 }
1799 return NULL;
1800}
1801
[email protected]bb7f40952011-01-13 00:21:201802void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
1803 if (terminated_extension_ids_.insert(extension->id()).second)
1804 terminated_extensions_.push_back(make_scoped_refptr(extension));
1805}
1806
1807void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
1808 if (terminated_extension_ids_.erase(id) <= 0)
1809 return;
1810
1811 std::string lowercase_id = StringToLowerASCII(id);
1812 for (ExtensionList::iterator iter = terminated_extensions_.begin();
1813 iter != terminated_extensions_.end(); ++iter) {
1814 if ((*iter)->id() == lowercase_id) {
1815 terminated_extensions_.erase(iter);
1816 return;
1817 }
1818 }
1819}
1820
[email protected]0dfe05c2011-02-23 23:03:361821const Extension* ExtensionService::GetTerminatedExtension(
1822 const std::string& id) {
1823 std::string lowercase_id = StringToLowerASCII(id);
1824 for (ExtensionList::const_iterator iter = terminated_extensions_.begin();
1825 iter != terminated_extensions_.end(); ++iter) {
1826 if ((*iter)->id() == lowercase_id)
1827 return *iter;
1828 }
1829 return NULL;
1830}
1831
[email protected]eaa7dd182010-12-14 11:09:001832const Extension* ExtensionService::GetWebStoreApp() {
[email protected]d3071992010-10-08 15:24:071833 return GetExtensionById(extension_misc::kWebStoreAppId, false);
1834}
1835
[email protected]eaa7dd182010-12-14 11:09:001836const Extension* ExtensionService::GetExtensionByURL(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:571837 return url.scheme() != chrome::kExtensionScheme ? NULL :
1838 GetExtensionById(url.host(), false);
1839}
1840
[email protected]eaa7dd182010-12-14 11:09:001841const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:571842 for (size_t i = 0; i < extensions_.size(); ++i) {
1843 if (extensions_[i]->web_extent().ContainsURL(url))
1844 return extensions_[i];
1845 }
1846 return NULL;
[email protected]9f1087e2009-06-15 17:29:321847}
1848
[email protected]eaa7dd182010-12-14 11:09:001849bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]583d45c12010-08-31 02:48:121850 // Allow bindings for all packaged extension.
1851 if (GetExtensionByURL(url))
1852 return true;
1853
1854 // Allow bindings for all component, hosted apps.
[email protected]9adb9692010-10-29 23:14:021855 const Extension* extension = GetExtensionByWebExtent(url);
[email protected]583d45c12010-08-31 02:48:121856 return (extension && extension->location() == Extension::COMPONENT);
1857}
1858
[email protected]eaa7dd182010-12-14 11:09:001859const Extension* ExtensionService::GetExtensionByOverlappingWebExtent(
[email protected]9f72aa02010-06-25 10:01:051860 const ExtensionExtent& extent) {
[email protected]22c966c2010-06-26 06:35:021861 for (size_t i = 0; i < extensions_.size(); ++i) {
1862 if (extensions_[i]->web_extent().OverlapsWith(extent))
1863 return extensions_[i];
1864 }
1865
[email protected]6d2e60bd2010-06-03 22:37:391866 return NULL;
1867}
1868
[email protected]eaa7dd182010-12-14 11:09:001869const SkBitmap& ExtensionService::GetOmniboxIcon(
[email protected]b671760b2010-07-15 21:13:471870 const std::string& extension_id) {
1871 return omnibox_icon_manager_.GetIcon(extension_id);
1872}
1873
[email protected]eaa7dd182010-12-14 11:09:001874const SkBitmap& ExtensionService::GetOmniboxPopupIcon(
[email protected]29d0d4ac2010-09-08 21:10:311875 const std::string& extension_id) {
1876 return omnibox_popup_icon_manager_.GetIcon(extension_id);
1877}
1878
[email protected]eaa7dd182010-12-14 11:09:001879void ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:321880 const std::string& id,
[email protected]8e4560b62011-01-14 10:09:141881 const Version* version,
[email protected]8ef78fd2010-08-19 17:14:321882 const FilePath& path,
1883 Extension::Location location) {
[email protected]ab22ba42011-01-14 16:36:381884 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1885 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:011886 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]683d0702010-12-06 16:25:571887 return;
[email protected]a8af9fdb2010-10-28 21:52:201888
[email protected]8e4560b62011-01-14 10:09:141889 DCHECK(version);
1890
[email protected]7577a5c52009-07-30 06:21:581891 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:491892 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:581893 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:021894 const Extension* existing = GetExtensionById(id, true);
[email protected]7577a5c52009-07-30 06:21:581895 if (existing) {
[email protected]8e4560b62011-01-14 10:09:141896 switch (existing->version()->CompareTo(*version)) {
[email protected]7577a5c52009-07-30 06:21:581897 case -1: // existing version is older, we should upgrade
1898 break;
1899 case 0: // existing version is same, do nothing
1900 return;
1901 case 1: // existing version is newer, uh-oh
1902 LOG(WARNING) << "Found external version of extension " << id
1903 << "that is older than current version. Current version "
1904 << "is: " << existing->VersionString() << ". New version "
1905 << "is: " << version << ". Keeping current version.";
1906 return;
1907 }
1908 }
1909
[email protected]b2907fd2011-03-25 16:43:371910 pending_extension_manager()->AddFromExternalFile(id, location);
[email protected]9c635f22010-12-02 09:36:361911
[email protected]6dfbbf82010-03-12 23:09:161912 scoped_refptr<CrxInstaller> installer(
[email protected]bb461532010-11-26 21:50:231913 new CrxInstaller(this, // frontend
[email protected]6dfbbf82010-03-12 23:09:161914 NULL)); // no client (silent install)
1915 installer->set_install_source(location);
1916 installer->set_expected_id(id);
[email protected]604322d2011-03-22 16:51:561917 installer->set_expected_version(*version),
[email protected]6dfbbf82010-03-12 23:09:161918 installer->InstallCrx(path);
[email protected]7577a5c52009-07-30 06:21:581919}
1920
[email protected]eaa7dd182010-12-14 11:09:001921void ExtensionService::ReportExtensionLoadError(
[email protected]d11c8e92009-10-20 23:26:401922 const FilePath& extension_path,
1923 const std::string &error,
1924 NotificationType type,
1925 bool be_noisy) {
1926 NotificationService* service = NotificationService::current();
1927 service->Notify(type,
[email protected]24e7a9d2009-11-04 11:11:341928 Source<Profile>(profile_),
[email protected]d11c8e92009-10-20 23:26:401929 Details<const std::string>(&error));
1930
[email protected]8a205c02011-02-04 20:41:331931 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName());
[email protected]18d4b6c2010-09-21 03:21:041932 std::string message = base::StringPrintf(
1933 "Could not load extension from '%s'. %s",
1934 path_str.c_str(), error.c_str());
[email protected]d11c8e92009-10-20 23:26:401935 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
1936}
1937
[email protected]eaa7dd182010-12-14 11:09:001938void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]406027c02010-09-27 08:03:181939 ExtensionHost* host) {
1940 OrphanedDevTools::iterator iter =
1941 orphaned_dev_tools_.find(host->extension()->id());
1942 if (iter == orphaned_dev_tools_.end())
1943 return;
1944
1945 DevToolsManager::GetInstance()->AttachClientHost(
1946 iter->second, host->render_view_host());
1947 orphaned_dev_tools_.erase(iter);
1948}
1949
[email protected]eaa7dd182010-12-14 11:09:001950void ExtensionService::Observe(NotificationType type,
[email protected]4814b512009-11-07 00:12:291951 const NotificationSource& source,
1952 const NotificationDetails& details) {
1953 switch (type.value) {
[email protected]a4ed6282009-12-14 20:51:161954 case NotificationType::EXTENSION_PROCESS_TERMINATED: {
[email protected]bc535ee52010-08-31 18:40:321955 if (profile_ != Source<Profile>(source).ptr()->GetOriginalProfile())
1956 break;
[email protected]a4ed6282009-12-14 20:51:161957
[email protected]f128af42010-08-05 18:05:261958 ExtensionHost* host = Details<ExtensionHost>(details).ptr();
[email protected]bb7f40952011-01-13 00:21:201959 TrackTerminatedExtension(host->extension());
[email protected]f128af42010-08-05 18:05:261960
[email protected]31f77262009-12-02 20:48:531961 // Unload the entire extension. We want it to be in a consistent state:
1962 // either fully working or not loaded at all, but never half-crashed.
[email protected]bc535ee52010-08-31 18:40:321963 // We do it in a PostTask so that other handlers of this notification will
1964 // still have access to the Extension and ExtensionHost.
1965 MessageLoop::current()->PostTask(FROM_HERE,
[email protected]a9f39a312010-12-23 22:14:271966 NewRunnableMethod(this,
1967 &ExtensionService::UnloadExtension,
1968 host->extension()->id(),
1969 UnloadedExtensionInfo::DISABLE));
[email protected]31f77262009-12-02 20:48:531970 break;
1971 }
1972
[email protected]aa96d3a2010-08-21 08:45:251973 case NotificationType::PREF_CHANGED: {
1974 std::string* pref_name = Details<std::string>(details).ptr();
[email protected]6c751e72010-11-23 10:11:101975 if (*pref_name == prefs::kExtensionInstallAllowList ||
1976 *pref_name == prefs::kExtensionInstallDenyList) {
1977 CheckAdminBlacklist();
[email protected]6c751e72010-11-23 10:11:101978 } else {
1979 NOTREACHED() << "Unexpected preference name.";
1980 }
[email protected]aa96d3a2010-08-21 08:45:251981 break;
1982 }
1983
[email protected]4814b512009-11-07 00:12:291984 default:
1985 NOTREACHED() << "Unexpected notification type.";
1986 }
1987}
1988
[email protected]eaa7dd182010-12-14 11:09:001989bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:181990 return !GetAppIds().empty();
1991}
[email protected]377011d2010-07-20 04:18:501992
[email protected]eaa7dd182010-12-14 11:09:001993ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:181994 ExtensionIdSet result;
[email protected]377011d2010-07-20 04:18:501995 for (ExtensionList::const_iterator it = extensions_.begin();
1996 it != extensions_.end(); ++it) {
[email protected]ec5b50d2010-10-09 16:35:181997 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
1998 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:501999 }
2000
[email protected]ec5b50d2010-10-09 16:35:182001 return result;
[email protected]377011d2010-07-20 04:18:502002}
[email protected]d7e9a862010-11-03 21:57:492003
[email protected]eaa7dd182010-12-14 11:09:002004bool ExtensionService::IsBackgroundPageReady(const Extension* extension) {
[email protected]d7e9a862010-11-03 21:57:492005 return (extension->background_url().is_empty() ||
2006 extension_runtime_data_[extension->id()].background_page_ready);
2007}
2008
[email protected]eaa7dd182010-12-14 11:09:002009void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
[email protected]d7e9a862010-11-03 21:57:492010 DCHECK(!extension->background_url().is_empty());
2011 extension_runtime_data_[extension->id()].background_page_ready = true;
2012 NotificationService::current()->Notify(
2013 NotificationType::EXTENSION_BACKGROUND_PAGE_READY,
2014 Source<const Extension>(extension),
2015 NotificationService::NoDetails());
2016}
2017
[email protected]eaa7dd182010-12-14 11:09:002018bool ExtensionService::IsBeingUpgraded(const Extension* extension) {
[email protected]d7e9a862010-11-03 21:57:492019 return extension_runtime_data_[extension->id()].being_upgraded;
2020}
2021
[email protected]eaa7dd182010-12-14 11:09:002022void ExtensionService::SetBeingUpgraded(const Extension* extension,
[email protected]d7e9a862010-11-03 21:57:492023 bool value) {
2024 extension_runtime_data_[extension->id()].being_upgraded = value;
2025}
[email protected]1bead0712010-11-27 17:41:532026
[email protected]eaa7dd182010-12-14 11:09:002027PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) {
[email protected]1bead0712010-11-27 17:41:532028 return &extension_runtime_data_[extension->id()].property_bag;
2029}
[email protected]cebc3dc2011-04-18 17:15:002030
2031void ExtensionService::RegisterNaClModule(const GURL& url,
2032 const std::string& mime_type) {
2033 NaClModuleInfo info;
2034 info.url = url;
2035 info.mime_type = mime_type;
2036
2037 DCHECK(FindNaClModule(url) == nacl_module_list_.end());
2038 nacl_module_list_.push_front(info);
2039}
2040
2041void ExtensionService::UnregisterNaClModule(const GURL& url) {
2042 NaClModuleInfoList::iterator iter = FindNaClModule(url);
2043 DCHECK(iter != nacl_module_list_.end());
2044 nacl_module_list_.erase(iter);
2045}
2046
2047void ExtensionService::UpdatePluginListWithNaClModules() {
2048 FilePath path;
2049 PathService::Get(chrome::FILE_NACL_PLUGIN, &path);
2050
2051 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(path);
2052
2053 const PepperPluginInfo* pepper_info =
2054 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(path);
2055 webkit::npapi::WebPluginInfo info = pepper_info->ToWebPluginInfo();
2056
2057 DCHECK(nacl_module_list_.size() <= 1);
2058 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2059 iter != nacl_module_list_.end(); ++iter) {
2060 webkit::npapi::WebPluginMimeType mime_type_info;
2061 mime_type_info.mime_type = iter->mime_type;
2062 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl"));
2063 mime_type_info.additional_param_values.push_back(
2064 UTF8ToUTF16(iter->url.spec()));
2065 info.mime_types.push_back(mime_type_info);
2066 }
2067
2068 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
2069 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info);
2070}
2071
2072ExtensionService::NaClModuleInfoList::iterator
2073 ExtensionService::FindNaClModule(const GURL& url) {
2074 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2075 iter != nacl_module_list_.end(); ++iter) {
2076 if (iter->url == url)
2077 return iter;
2078 }
2079 return nacl_module_list_.end();
2080}