blob: 3d5d0541fbcf535e198d4c0e9bf6cf11850dfa97 [file] [log] [blame]
[email protected]16d900042012-01-04 21:24:321// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6014d672008-12-05 00:38:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]eaa7dd182010-12-14 11:09:005#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]05aad2da2011-10-28 10:12:3711#include "base/bind.h"
[email protected]e5af875f2011-10-10 21:09:1412#include "base/callback.h"
[email protected]62433d32011-10-12 22:33:1213#include "base/command_line.h"
[email protected]6014d672008-12-05 00:38:2514#include "base/file_util.h"
[email protected]14908b72011-04-20 06:54:3615#include "base/logging.h"
[email protected]49098f702011-10-13 03:47:1816#include "base/metrics/field_trial.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]1e127022011-11-29 21:11:4718#include "base/path_service.h"
[email protected]7286e3fc2011-07-19 22:13:2419#include "base/stl_util.h"
[email protected]e83326f2010-07-31 17:29:2520#include "base/string_number_conversions.h"
[email protected]6014d672008-12-05 00:38:2521#include "base/string_util.h"
[email protected]18d4b6c2010-09-21 03:21:0422#include "base/stringprintf.h"
[email protected]34b99632011-01-01 01:01:0623#include "base/threading/thread_restrictions.h"
[email protected]cc2c3432009-11-06 17:24:3624#include "base/time.h"
[email protected]ce7f62e32010-08-10 23:43:5925#include "base/utf_string_conversions.h"
[email protected]cc655912009-01-29 23:19:1926#include "base/values.h"
[email protected]aa142702010-03-26 01:26:3327#include "base/version.h"
[email protected]a692a952011-11-28 08:23:5428#include "chrome/browser/accessibility/accessibility_extension_api.h"
[email protected]23d5f172011-10-25 05:49:5329#include "chrome/browser/bookmarks/bookmark_extension_api.h"
[email protected]15730c42009-09-03 00:03:2030#include "chrome/browser/browser_process.h"
[email protected]dfba8762011-09-02 12:49:5431#include "chrome/browser/chrome_plugin_service_filter.h"
[email protected]cdcf60242011-11-04 15:53:4332#include "chrome/browser/download/download_extension_api.h"
[email protected]58edca52012-02-16 21:51:3833#include "chrome/browser/extensions/api/api_resource_controller.h"
[email protected]92ba7b012012-05-16 03:36:1734#include "chrome/browser/extensions/api/cookies/cookies_api.h"
[email protected]895a1e52012-05-15 02:50:1235#include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
36#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
[email protected]af9db5f2011-10-05 05:13:1537#include "chrome/browser/extensions/app_notification_manager.h"
[email protected]5db9ada2012-04-11 13:48:2038#include "chrome/browser/extensions/app_sync_data.h"
[email protected]18cc5a52011-04-15 16:03:3839#include "chrome/browser/extensions/apps_promo.h"
[email protected]d8c8f25f2011-11-02 18:18:0140#include "chrome/browser/extensions/component_loader.h"
[email protected]e0785902011-05-19 23:34:1741#include "chrome/browser/extensions/crx_installer.h"
[email protected]49098f702011-10-13 03:47:1842#include "chrome/browser/extensions/default_apps_trial.h"
[email protected]b68d5ed2009-04-16 02:41:2843#include "chrome/browser/extensions/extension_browser_event_router.h"
[email protected]c10da4b02010-03-25 14:38:3244#include "chrome/browser/extensions/extension_data_deleter.h"
[email protected]62f051c2012-03-29 17:04:4445#include "chrome/browser/extensions/extension_disabled_ui.h"
[email protected]14a000d2010-04-29 21:44:2446#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]bdd34452012-04-16 15:58:4047#include "chrome/browser/extensions/extension_font_settings_api.h"
[email protected]e5af875f2011-10-10 21:09:1448#include "chrome/browser/extensions/extension_global_error.h"
[email protected]b1748b1d82009-11-30 20:32:5649#include "chrome/browser/extensions/extension_host.h"
[email protected]8baf0dbb2011-11-27 22:47:0250#include "chrome/browser/extensions/extension_input_ime_api.h"
[email protected]8a4cf842012-05-16 13:35:3051#include "chrome/browser/extensions/extension_managed_mode_api.h"
[email protected]7596ce72010-08-30 05:10:4652#include "chrome/browser/extensions/extension_management_api.h"
[email protected]118de7892011-03-16 13:31:4053#include "chrome/browser/extensions/extension_preference_api.h"
[email protected]4814b512009-11-07 00:12:2954#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]8a661f82010-10-19 21:47:1155#include "chrome/browser/extensions/extension_processes_api.h"
[email protected]3569b502012-01-12 20:08:2356#include "chrome/browser/extensions/extension_sorting.h"
[email protected]19eb80152011-02-26 00:28:4357#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]90310d92011-04-17 07:35:0458#include "chrome/browser/extensions/extension_sync_data.h"
[email protected]31d8f5f22012-04-02 15:22:0859#include "chrome/browser/extensions/extension_system.h"
[email protected]8f9d4eb2011-02-05 01:39:1060#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]8e4560b62011-01-14 10:09:1461#include "chrome/browser/extensions/external_extension_provider_impl.h"
[email protected]42b795652011-02-22 23:32:3862#include "chrome/browser/extensions/external_extension_provider_interface.h"
[email protected]d8c8f25f2011-11-02 18:18:0163#include "chrome/browser/extensions/installed_loader.h"
[email protected]b2907fd2011-03-25 16:43:3764#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]c333e792012-01-06 16:57:3965#include "chrome/browser/extensions/permissions_updater.h"
[email protected]cccdf0aa2011-11-11 03:43:3866#include "chrome/browser/extensions/settings/settings_frontend.h"
[email protected]d8c8f25f2011-11-02 18:18:0167#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]42a08162012-03-16 18:09:1168#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]d2e6bd62011-10-24 20:29:0769#include "chrome/browser/history/history_extension_api.h"
[email protected]56ad3792010-05-28 17:45:3370#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]37858e52010-08-26 00:22:0271#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3372#include "chrome/browser/profiles/profile.h"
[email protected]cf593af2011-12-30 05:44:3973#include "chrome/browser/profiles/profile_manager.h"
[email protected]8e5c89a2011-06-07 18:13:3374#include "chrome/browser/search_engines/template_url_service.h"
75#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]18280372011-03-22 18:05:2276#include "chrome/browser/themes/theme_service.h"
[email protected]a0ea76c2011-03-23 17:36:4277#include "chrome/browser/themes/theme_service_factory.h"
[email protected]e5af875f2011-10-10 21:09:1478#include "chrome/browser/ui/browser.h"
[email protected]d8748142012-05-16 21:13:4379#include "chrome/browser/ui/browser_finder.h"
[email protected]e5af875f2011-10-10 21:09:1480#include "chrome/browser/ui/global_error_service.h"
81#include "chrome/browser/ui/global_error_service_factory.h"
[email protected]c8d407e2011-04-28 21:27:1782#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
83#include "chrome/browser/ui/webui/favicon_source.h"
[email protected]5eddc3e2011-10-26 04:33:3184#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
[email protected]aab98a52009-12-02 03:22:3585#include "chrome/common/child_process_logging.h"
[email protected]432115822011-07-10 15:52:2786#include "chrome/common/chrome_notification_types.h"
[email protected]1e127022011-11-29 21:11:4787#include "chrome/common/chrome_paths.h"
[email protected]e2eb43112009-05-29 21:19:5488#include "chrome/common/chrome_switches.h"
[email protected]15397b42012-05-16 23:56:0689#include "chrome/common/chrome_version_info.h"
[email protected]5b1a0e22009-05-26 19:00:5890#include "chrome/common/extensions/extension.h"
[email protected]05c82182010-06-24 17:49:0891#include "chrome/common/extensions/extension_error_utils.h"
[email protected]7c927b62010-02-24 09:54:1392#include "chrome/common/extensions/extension_file_util.h"
[email protected]895a1e52012-05-15 02:50:1293#include "chrome/common/extensions/extension_manifest_constants.h"
[email protected]77a6970c2011-04-23 16:58:5694#include "chrome/common/extensions/extension_messages.h"
[email protected]a315ba92010-11-16 14:12:2195#include "chrome/common/extensions/extension_resource.h"
[email protected]25b34332009-06-05 21:53:1996#include "chrome/common/pref_names.h"
[email protected]a57209872009-05-04 22:53:1497#include "chrome/common/url_constants.h"
[email protected]c38831a12011-10-28 12:44:4998#include "content/public/browser/browser_thread.h"
[email protected]0e12d7d2011-12-01 16:21:4499#include "content/public/browser/devtools_agent_host_registry.h"
100#include "content/public/browser/devtools_manager.h"
[email protected]05aad2da2011-10-28 10:12:37101#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:16102#include "content/public/browser/notification_types.h"
[email protected]3a5180ae2011-12-21 02:39:38103#include "content/public/browser/plugin_service.h"
[email protected]f3b1a082011-11-18 00:34:30104#include "content/public/browser/render_process_host.h"
[email protected]1e127022011-11-29 21:11:47105#include "content/public/common/pepper_plugin_info.h"
[email protected]c10da4b02010-03-25 14:38:32106#include "googleurl/src/gurl.h"
[email protected]65187152012-06-02 13:14:14107#include "grit/generated_resources.h"
[email protected]1debbbb62010-10-06 17:23:44108#include "net/base/registry_controlled_domain.h"
[email protected]895a1e52012-05-15 02:50:12109#include "sync/api/sync_change.h"
110#include "sync/api/sync_error_factory.h"
[email protected]65187152012-06-02 13:14:14111#include "ui/base/l10n/l10n_util.h"
[email protected]24b538a2010-02-27 01:22:44112#include "webkit/database/database_tracker.h"
113#include "webkit/database/database_util.h"
[email protected]c64631652009-04-29 22:24:31114
[email protected]eed367e2011-04-12 03:43:31115#if defined(OS_CHROMEOS)
[email protected]14da67b02011-08-02 05:49:13116#include "chrome/browser/chromeos/cros/cros_library.h"
[email protected]f463bc92012-03-22 16:38:23117#include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
[email protected]eed367e2011-04-12 03:43:31118#include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
[email protected]be5bd5742011-07-14 07:21:01119#include "chrome/browser/chromeos/extensions/input_method_event_router.h"
[email protected]ce9802042011-05-27 10:11:40120#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
[email protected]14da67b02011-08-02 05:49:13121#include "chrome/browser/chromeos/input_method/input_method_manager.h"
[email protected]614d18c22012-04-26 16:59:22122#include "chrome/browser/extensions/extension_input_ime_api.h"
[email protected]b777b332011-04-16 04:01:08123#include "webkit/fileapi/file_system_context.h"
124#include "webkit/fileapi/file_system_mount_point_provider.h"
[email protected]eed367e2011-04-12 03:43:31125#endif
126
[email protected]5ef47ec2010-01-28 05:58:05127using base::Time;
[email protected]55eb70e762012-02-20 17:38:39128using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39129using content::BrowserThread;
[email protected]0e12d7d2011-12-01 16:21:44130using content::DevToolsAgentHost;
131using content::DevToolsAgentHostRegistry;
[email protected]3a5180ae2011-12-21 02:39:38132using content::PluginService;
[email protected]1c321ee2012-05-21 03:02:34133using extensions::Extension;
134using extensions::ExtensionIdSet;
135using extensions::ExtensionInfo;
136using extensions::UnloadedExtensionInfo;
[email protected]5ef47ec2010-01-28 05:58:05137
[email protected]c6d474f82009-12-16 21:11:06138namespace errors = extension_manifest_errors;
139
[email protected]b6ab96d2009-08-20 18:58:19140namespace {
141
[email protected]29d0d4ac2010-09-08 21:10:31142#if defined(OS_LINUX)
143static const int kOmniboxIconPaddingLeft = 2;
144static const int kOmniboxIconPaddingRight = 2;
145#elif defined(OS_MACOSX)
146static const int kOmniboxIconPaddingLeft = 0;
147static const int kOmniboxIconPaddingRight = 2;
148#else
149static const int kOmniboxIconPaddingLeft = 0;
150static const int kOmniboxIconPaddingRight = 0;
151#endif
152
[email protected]300c0ea2011-07-15 23:04:33153const char* kNaClPluginMimeType = "application/x-nacl";
154
[email protected]3bdba0d2011-08-23 07:17:30155static bool IsSyncableExtension(const Extension& extension) {
156 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION;
157}
158
159static bool IsSyncableApp(const Extension& extension) {
160 return extension.GetSyncType() == Extension::SYNC_TYPE_APP;
161}
162
[email protected]c6d474f82009-12-16 21:11:06163} // namespace
[email protected]b6ab96d2009-08-20 18:58:19164
[email protected]eaa7dd182010-12-14 11:09:00165ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
[email protected]d7e9a862010-11-03 21:57:49166 : background_page_ready(false),
[email protected]f8bf5992011-10-24 22:38:57167 being_upgraded(false),
168 has_used_webrequest(false) {
[email protected]d7e9a862010-11-03 21:57:49169}
170
[email protected]eaa7dd182010-12-14 11:09:00171ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() {
[email protected]d7e9a862010-11-03 21:57:49172}
173
[email protected]cebc3dc2011-04-18 17:15:00174ExtensionService::NaClModuleInfo::NaClModuleInfo() {
175}
176
177ExtensionService::NaClModuleInfo::~NaClModuleInfo() {
178}
179
[email protected]eaa7dd182010-12-14 11:09:00180// ExtensionService.
[email protected]6014d672008-12-05 00:38:25181
[email protected]eaa7dd182010-12-14 11:09:00182const char* ExtensionService::kInstallDirectoryName = "Extensions";
[email protected]15d5b472011-11-24 04:17:24183
184const char* ExtensionService::kLocalAppSettingsDirectoryName =
185 "Local App Settings";
186const char* ExtensionService::kLocalExtensionSettingsDirectoryName =
187 "Local Extension Settings";
188const char* ExtensionService::kSyncAppSettingsDirectoryName =
189 "Sync App Settings";
190const char* ExtensionService::kSyncExtensionSettingsDirectoryName =
191 "Sync Extension Settings";
[email protected]494c06e2009-07-25 01:06:42192
[email protected]8e4560b62011-01-14 10:09:14193void ExtensionService::CheckExternalUninstall(const std::string& id) {
[email protected]a29a517a2011-01-21 21:11:12194 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20195
[email protected]7a4c6852010-09-16 03:44:22196 // Check if the providers know about this extension.
[email protected]0a60a2e2010-10-25 16:15:21197 ProviderCollection::const_iterator i;
198 for (i = external_extension_providers_.begin();
199 i != external_extension_providers_.end(); ++i) {
[email protected]8e4560b62011-01-14 10:09:14200 DCHECK(i->get()->IsReady());
[email protected]0a60a2e2010-10-25 16:15:21201 if (i->get()->HasExtension(id))
202 return; // Yup, known extension, don't uninstall.
[email protected]7a4c6852010-09-16 03:44:22203 }
204
[email protected]0f48fca2011-05-19 18:46:35205 // We get the list of external extensions to check from preferences.
206 // It is possible that an extension has preferences but is not loaded.
207 // For example, an extension that requires experimental permissions
208 // will not be loaded if the experimental command line flag is not used.
209 // In this case, do not uninstall.
210 const Extension* extension = GetInstalledExtension(id);
211 if (!extension) {
212 // We can't call UninstallExtension with an unloaded/invalid
213 // extension ID.
214 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension "
215 << "with id: " << id;
216 return;
217 }
[email protected]d6ebc9792011-04-07 18:18:33218 UninstallExtension(id, true, NULL);
[email protected]7a4c6852010-09-16 03:44:22219}
220
[email protected]8e4560b62011-01-14 10:09:14221void ExtensionService::ClearProvidersForTesting() {
[email protected]7a4c6852010-09-16 03:44:22222 external_extension_providers_.clear();
223}
224
[email protected]8e4560b62011-01-14 10:09:14225void ExtensionService::AddProviderForTesting(
226 ExternalExtensionProviderInterface* test_provider) {
[email protected]a29a517a2011-01-21 21:11:12227 CHECK(test_provider);
[email protected]0a60a2e2010-10-25 16:15:21228 external_extension_providers_.push_back(
[email protected]8e4560b62011-01-14 10:09:14229 linked_ptr<ExternalExtensionProviderInterface>(test_provider));
[email protected]7a4c6852010-09-16 03:44:22230}
231
[email protected]9060d8b02012-01-13 02:14:30232bool ExtensionService::OnExternalExtensionUpdateUrlFound(
[email protected]7a4c6852010-09-16 03:44:22233 const std::string& id,
[email protected]21a5a672010-11-04 10:47:42234 const GURL& update_url,
235 Extension::Location location) {
[email protected]ab22ba42011-01-14 16:36:38236 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
237 CHECK(Extension::IdIsValid(id));
[email protected]a8af9fdb2010-10-28 21:52:20238
[email protected]8a87a5332011-08-11 17:54:59239 const Extension* extension = GetExtensionById(id, true);
240 if (extension) {
241 // Already installed. Skip this install if the current location has
242 // higher priority than |location|.
243 Extension::Location current = extension->location();
244 if (current == Extension::GetHigherPriorityLocation(current, location))
[email protected]9060d8b02012-01-13 02:14:30245 return false;
[email protected]8a87a5332011-08-11 17:54:59246 // Otherwise, overwrite the current installation.
[email protected]7a4c6852010-09-16 03:44:22247 }
[email protected]9060d8b02012-01-13 02:14:30248
249 // Add |id| to the set of pending extensions. If it can not be added,
250 // then there is already a pending record from a higher-priority install
251 // source. In this case, signal that this extension will not be
252 // installed by returning false.
253 if (!pending_extension_manager()->AddFromExternalUpdateUrl(
254 id, update_url, location))
255 return false;
256
[email protected]94fde232012-04-27 10:22:30257 update_once_all_providers_are_ready_ = true;
[email protected]9060d8b02012-01-13 02:14:30258 return true;
[email protected]7a4c6852010-09-16 03:44:22259}
260
[email protected]d9696672011-03-15 22:45:09261const Extension* ExtensionService::GetInstalledApp(const GURL& url) {
[email protected]615d88f2011-12-13 01:47:44262 const Extension* extension = extensions_.GetExtensionOrAppByURL(
263 ExtensionURLInfo(url));
264 if (extension && extension->is_app())
265 return extension;
[email protected]d9696672011-03-15 22:45:09266
267 return NULL;
268}
269
270bool ExtensionService::IsInstalledApp(const GURL& url) {
271 return !!GetInstalledApp(url);
[email protected]ffb204f22010-12-05 23:20:27272}
273
[email protected]da5683db2011-04-23 17:12:21274void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id,
275 const Extension* app) {
276 installed_app_hosts_[renderer_child_id] = app;
277}
278
279const Extension* ExtensionService::GetInstalledAppForRenderer(
280 int renderer_child_id) {
281 InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id);
282 if (i == installed_app_hosts_.end())
283 return NULL;
284 return i->second;
285}
286
[email protected]6aeac8342010-10-01 20:21:18287// static
[email protected]d6ebc9792011-04-07 18:18:33288// This function is used to implement the command-line switch
[email protected]3bdba0d2011-08-23 07:17:30289// --uninstall-extension, and to uninstall an extension via sync. The LOG
290// statements within this function are used to inform the user if the uninstall
291// cannot be done.
[email protected]eaa7dd182010-12-14 11:09:00292bool ExtensionService::UninstallExtensionHelper(
293 ExtensionService* extensions_service,
[email protected]6aeac8342010-10-01 20:21:18294 const std::string& extension_id) {
[email protected]6aeac8342010-10-01 20:21:18295
[email protected]95da88c42011-03-31 10:07:33296 const Extension* extension =
[email protected]8001df22011-04-28 19:59:47297 extensions_service->GetInstalledExtension(extension_id);
[email protected]95da88c42011-03-31 10:07:33298
[email protected]d6ebc9792011-04-07 18:18:33299 // We can't call UninstallExtension with an invalid extension ID.
[email protected]95da88c42011-03-31 10:07:33300 if (!extension) {
[email protected]6aeac8342010-10-01 20:21:18301 LOG(WARNING) << "Attempted uninstallation of non-existent extension with "
[email protected]95da88c42011-03-31 10:07:33302 << "id: " << extension_id;
303 return false;
[email protected]6aeac8342010-10-01 20:21:18304 }
305
[email protected]d6ebc9792011-04-07 18:18:33306 // The following call to UninstallExtension will not allow an uninstall of a
307 // policy-controlled extension.
[email protected]65187152012-06-02 13:14:14308 string16 error;
[email protected]d6ebc9792011-04-07 18:18:33309 if (!extensions_service->UninstallExtension(extension_id, false, &error)) {
310 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id
311 << ": " << error;
312 return false;
313 }
[email protected]95da88c42011-03-31 10:07:33314
[email protected]6aeac8342010-10-01 20:21:18315 return true;
316}
317
[email protected]eaa7dd182010-12-14 11:09:00318ExtensionService::ExtensionService(Profile* profile,
[email protected]f0841cd2011-01-19 15:07:24319 const CommandLine* command_line,
320 const FilePath& install_directory,
321 ExtensionPrefs* extension_prefs,
[email protected]0436b102011-04-15 18:30:03322 bool autoupdate_enabled,
323 bool extensions_enabled)
[email protected]d8c8f25f2011-11-02 18:18:01324 : profile_(profile),
[email protected]749d59a2012-04-05 00:23:24325 system_(ExtensionSystem::Get(profile)),
[email protected]73c47932010-12-06 18:13:43326 extension_prefs_(extension_prefs),
[email protected]cccdf0aa2011-11-11 03:43:38327 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
[email protected]14908b72011-04-20 06:54:36328 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]a9b00ac2009-06-25 21:03:23329 install_directory_(install_directory),
[email protected]0436b102011-04-15 18:30:03330 extensions_enabled_(extensions_enabled),
[email protected]e81dba32009-06-19 20:19:13331 show_extensions_prompts_(true),
[email protected]3ecda252010-11-18 19:50:55332 ready_(false),
[email protected]14908b72011-04-20 06:54:36333 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]8b280302011-10-13 22:22:23334 menu_manager_(profile),
[email protected]af9db5f2011-10-05 05:13:15335 app_notification_manager_(new AppNotificationManager(profile)),
[email protected]18cc5a52011-04-15 16:03:38336 apps_promo_(profile->GetPrefs()),
[email protected]7c1490da2011-10-11 18:53:25337 event_routers_initialized_(false),
[email protected]dff1e042012-04-27 10:59:18338 update_once_all_providers_are_ready_(false),
[email protected]5db9ada2012-04-11 13:48:20339 app_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
340 extension_sync_bundle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
[email protected]a1755bd2011-12-09 00:40:20341 extension_warnings_(profile),
[email protected]58edca52012-02-16 21:51:38342 api_resource_controller_(NULL),
[email protected]178f8512012-02-09 01:49:36343 app_shortcut_manager_(profile) {
[email protected]a29a517a2011-01-21 21:11:12344 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20345
[email protected]36a784c2009-06-23 06:21:08346 // Figure out if extension installation should be enabled.
[email protected]6d60703b2009-08-29 01:29:23347 if (command_line->HasSwitch(switches::kDisableExtensions)) {
348 extensions_enabled_ = false;
349 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) {
350 extensions_enabled_ = false;
[email protected]6b75ec32009-08-14 06:37:18351 }
[email protected]36a784c2009-06-23 06:21:08352
[email protected]432115822011-07-10 15:52:27353 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07354 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27355 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
[email protected]ad50def52011-10-19 23:17:07356 content::NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:27357 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
[email protected]ad50def52011-10-19 23:17:07358 content::NotificationService::AllBrowserContextsAndSources());
[email protected]2fb7dc982010-09-29 12:24:28359 pref_change_registrar_.Init(profile->GetPrefs());
360 pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this);
361 pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this);
[email protected]4814b512009-11-07 00:12:29362
[email protected]93fd78f42009-07-10 16:43:17363 // Set up the ExtensionUpdater
364 if (autoupdate_enabled) {
365 int update_frequency = kDefaultUpdateFrequencySeconds;
366 if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
[email protected]e83326f2010-07-31 17:29:25367 base::StringToInt(command_line->GetSwitchValueASCII(
368 switches::kExtensionsUpdateFrequency),
369 &update_frequency);
[email protected]93fd78f42009-07-10 16:43:17370 }
[email protected]42a08162012-03-16 18:09:11371 updater_.reset(new extensions::ExtensionUpdater(this,
372 extension_prefs,
373 profile->GetPrefs(),
374 profile,
375 update_frequency));
[email protected]93fd78f42009-07-10 16:43:17376 }
377
[email protected]25ae0152011-11-18 14:40:02378 component_loader_.reset(
379 new extensions::ComponentLoader(this,
380 profile->GetPrefs(),
381 g_browser_process->local_state()));
[email protected]8e4560b62011-01-14 10:09:14382
[email protected]af9db5f2011-10-05 05:13:15383 app_notification_manager_->Init();
384
[email protected]0436b102011-04-15 18:30:03385 if (extensions_enabled_) {
[email protected]1f2f3002011-12-28 00:40:21386 if (!command_line->HasSwitch(switches::kImport) &&
387 !command_line->HasSwitch(switches::kImportFromFile)) {
388 ExternalExtensionProviderImpl::CreateExternalProviders(
389 this, profile_, &external_extension_providers_);
390 }
[email protected]873531342011-03-09 12:16:05391 }
[email protected]b671760b2010-07-15 21:13:47392
[email protected]aa96d3a2010-08-21 08:45:25393 // Use monochrome icons for Omnibox icons.
[email protected]29d0d4ac2010-09-08 21:10:31394 omnibox_popup_icon_manager_.set_monochrome(true);
[email protected]b671760b2010-07-15 21:13:47395 omnibox_icon_manager_.set_monochrome(true);
[email protected]29d0d4ac2010-09-08 21:10:31396 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft,
397 0, kOmniboxIconPaddingRight));
[email protected]cb0e50312011-05-09 15:03:07398
[email protected]fb82dcd2012-03-21 14:15:46399 // Set this as the ExtensionService for extension sorting to ensure it
400 // cause syncs if required.
401 extension_prefs_->extension_sorting()->SetExtensionService(this);
402
[email protected]cb0e50312011-05-09 15:03:07403 // How long is the path to the Extensions directory?
404 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
405 install_directory_.value().length(), 0, 500, 100);
[email protected]6014d672008-12-05 00:38:25406}
407
[email protected]84df8332011-12-06 18:22:46408const ExtensionSet* ExtensionService::extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45409 return &extensions_;
410}
411
[email protected]84df8332011-12-06 18:22:46412const ExtensionSet* ExtensionService::disabled_extensions() const {
[email protected]ddb1e5a2010-12-13 20:10:45413 return &disabled_extensions_;
414}
415
[email protected]84df8332011-12-06 18:22:46416const ExtensionSet* ExtensionService::terminated_extensions() const {
[email protected]bb7f40952011-01-13 00:21:20417 return &terminated_extensions_;
418}
419
[email protected]7f4308d2012-01-18 07:43:01420const ExtensionSet* ExtensionService::GenerateInstalledExtensionsSet() const {
421 ExtensionSet* installed_extensions = new ExtensionSet();
422 installed_extensions->InsertAll(extensions_);
423 installed_extensions->InsertAll(disabled_extensions_);
424 installed_extensions->InsertAll(terminated_extensions_);
425 return installed_extensions;
426}
427
[email protected]b2907fd2011-03-25 16:43:37428PendingExtensionManager* ExtensionService::pending_extension_manager() {
429 return &pending_extension_manager_;
[email protected]ddb1e5a2010-12-13 20:10:45430}
431
[email protected]eaa7dd182010-12-14 11:09:00432ExtensionService::~ExtensionService() {
[email protected]c8d407e2011-04-28 21:27:17433 // No need to unload extensions here because they are profile-scoped, and the
434 // profile is in the process of being deleted.
[email protected]94b4ffc2011-02-04 05:55:17435
[email protected]8e4560b62011-01-14 10:09:14436 ProviderCollection::const_iterator i;
437 for (i = external_extension_providers_.begin();
438 i != external_extension_providers_.end(); ++i) {
439 ExternalExtensionProviderInterface* provider = i->get();
440 provider->ServiceShutdown();
441 }
[email protected]6014d672008-12-05 00:38:25442}
443
[email protected]d91268022011-08-26 13:17:37444void ExtensionService::InitEventRoutersAfterImport() {
[email protected]cf593af2011-12-30 05:44:39445 RegisterForImportFinished();
446}
447
448void ExtensionService::RegisterForImportFinished() {
449 if (!registrar_.IsRegistered(this, chrome::NOTIFICATION_IMPORT_FINISHED,
450 content::Source<Profile>(profile_))) {
451 registrar_.Add(this, chrome::NOTIFICATION_IMPORT_FINISHED,
452 content::Source<Profile>(profile_));
453 }
454}
455
456void ExtensionService::InitAfterImport() {
457 CheckForExternalUpdates();
458
459 GarbageCollectExtensions();
460
461 // Idempotent, so although there is a possible race if the import
462 // process finished sometime in the middle of ProfileImpl::InitExtensions,
463 // it cannot happen twice.
464 InitEventRouters();
[email protected]d91268022011-08-26 13:17:37465}
466
[email protected]eaa7dd182010-12-14 11:09:00467void ExtensionService::InitEventRouters() {
[email protected]b3d62312b12010-10-14 21:10:18468 if (event_routers_initialized_)
469 return;
470
[email protected]6a3cd37e2012-04-17 17:13:34471#if defined(ENABLE_EXTENSIONS)
[email protected]370e9502011-09-14 19:31:44472 downloads_event_router_.reset(new ExtensionDownloadsEventRouter(profile_));
[email protected]d2e6bd62011-10-24 20:29:07473 history_event_router_.reset(new HistoryExtensionEventRouter());
[email protected]f825df22011-06-28 17:36:10474 history_event_router_->ObserveProfile(profile_);
[email protected]97d2f1d2011-01-15 00:41:08475 browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_));
[email protected]34517242012-05-25 02:37:18476 browser_event_router_->Init();
[email protected]118de7892011-03-16 13:31:40477 preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_));
[email protected]23d5f172011-10-25 05:49:53478 bookmark_event_router_.reset(new BookmarkExtensionEventRouter(
[email protected]f825df22011-06-28 17:36:10479 profile_->GetBookmarkModel()));
480 bookmark_event_router_->Init();
[email protected]92ba7b012012-05-16 03:36:17481 cookies_event_router_.reset(new
482 extensions::ExtensionCookiesEventRouter(profile_));
[email protected]f825df22011-06-28 17:36:10483 cookies_event_router_->Init();
484 management_event_router_.reset(new ExtensionManagementEventRouter(profile_));
485 management_event_router_->Init();
[email protected]7da9a8232011-05-27 21:07:11486 ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_);
[email protected]f825df22011-06-28 17:36:10487 web_navigation_event_router_.reset(
[email protected]017ecde92012-04-04 09:11:26488 new extensions::WebNavigationEventRouter(profile_));
[email protected]f825df22011-06-28 17:36:10489 web_navigation_event_router_->Init();
[email protected]bdd34452012-04-16 15:58:40490 font_settings_event_router_.reset(
491 new ExtensionFontSettingsEventRouter(profile_));
492 font_settings_event_router_->Init();
[email protected]8a4cf842012-05-16 13:35:30493 managed_mode_event_router_.reset(
494 new ExtensionManagedModeEventRouter(profile_));
495 managed_mode_event_router_->Init();
[email protected]27072cad2011-05-09 19:46:40496
[email protected]eed367e2011-04-12 03:43:31497#if defined(OS_CHROMEOS)
[email protected]2a72c9f2012-03-17 15:10:30498 FileBrowserEventRouterFactory::GetForProfile(
499 profile_)->ObserveFileSystemEvents();
[email protected]771a6182011-10-05 16:32:52500
[email protected]f463bc92012-03-22 16:38:23501 bluetooth_event_router_.reset(
502 new chromeos::ExtensionBluetoothEventRouter(profile_));
503
[email protected]771a6182011-10-05 16:32:52504 input_method_event_router_.reset(
505 new chromeos::ExtensionInputMethodEventRouter);
[email protected]be5bd5742011-07-14 07:21:01506
[email protected]c8bf09be2011-06-25 03:22:27507 ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_);
[email protected]8baf0dbb2011-11-27 22:47:02508 ExtensionInputImeEventRouter::GetInstance()->Init();
[email protected]eed367e2011-04-12 03:43:31509#endif
[email protected]6a3cd37e2012-04-17 17:13:34510#endif // defined(ENABLE_EXTENSIONS)
[email protected]b3d62312b12010-10-14 21:10:18511 event_routers_initialized_ = true;
[email protected]c5ae74ab2010-04-15 18:14:37512}
513
[email protected]b2907fd2011-03-25 16:43:37514const Extension* ExtensionService::GetExtensionById(
515 const std::string& id, bool include_disabled) const {
[email protected]8001df22011-04-28 19:59:47516 return GetExtensionByIdInternal(id, true, include_disabled, false);
[email protected]78994ab02010-12-08 18:06:44517}
518
[email protected]eaa7dd182010-12-14 11:09:00519void ExtensionService::Init() {
[email protected]a29a517a2011-01-21 21:11:12520 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20521
[email protected]fa6a9102010-11-22 15:38:50522 DCHECK(!ready_); // Can't redo init.
[email protected]93fd78f42009-07-10 16:43:17523 DCHECK_EQ(extensions_.size(), 0u);
[email protected]9f1087e2009-06-15 17:29:32524
[email protected]d8c8f25f2011-11-02 18:18:01525 component_loader_->LoadAll();
526 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]894bb502009-05-21 22:39:57527
[email protected]7a161db2011-12-15 20:45:51528 // If we are running in the import process, don't bother initializing the
529 // extension service since this can interfere with the main browser process
530 // that is already running an extension service for this profile.
531 // TODO(aa): can we start up even less of ExtensionService?
532 // http://crbug.com/107636
[email protected]1f2f3002011-12-28 00:40:21533 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kImport) &&
534 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kImportFromFile)) {
[email protected]cf593af2011-12-30 05:44:39535 if (g_browser_process->profile_manager() &&
536 g_browser_process->profile_manager()->will_import()) {
537 RegisterForImportFinished();
538 } else {
539 // TODO(erikkay) this should probably be deferred to a future point
540 // rather than running immediately at startup.
541 CheckForExternalUpdates();
[email protected]894bb502009-05-21 22:39:57542
[email protected]cf593af2011-12-30 05:44:39543 // TODO(erikkay) this should probably be deferred as well.
544 GarbageCollectExtensions();
545 }
[email protected]7a161db2011-12-15 20:45:51546 }
[email protected]6014d672008-12-05 00:38:25547}
548
[email protected]420a0ec2011-06-01 01:07:03549bool ExtensionService::UpdateExtension(
550 const std::string& id,
551 const FilePath& extension_path,
552 const GURL& download_url,
553 CrxInstaller** out_crx_installer) {
[email protected]a29a517a2011-01-21 21:11:12554 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20555
[email protected]b2907fd2011-03-25 16:43:37556 PendingExtensionInfo pending_extension_info;
557 bool is_pending_extension = pending_extension_manager_.GetById(
558 id, &pending_extension_info);
[email protected]8ef78fd2010-08-19 17:14:32559
[email protected]8001df22011-04-28 19:59:47560 const Extension* extension =
561 GetExtensionByIdInternal(id, true, true, false);
[email protected]5eb375e92010-11-26 07:50:41562 if (!is_pending_extension && !extension) {
[email protected]aa142702010-03-26 01:26:33563 LOG(WARNING) << "Will not update extension " << id
564 << " because it is not installed or pending";
565 // Delete extension_path since we're not creating a CrxInstaller
566 // that would do it for us.
[email protected]14908b72011-04-20 06:54:36567 if (!BrowserThread::PostTask(
568 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:36569 base::Bind(
[email protected]7296f2762011-11-21 19:23:44570 &extension_file_util::DeleteFile, extension_path, false)))
[email protected]14908b72011-04-20 06:54:36571 NOTREACHED();
[email protected]420a0ec2011-06-01 01:07:03572
573 return false;
[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]d8c8f25f2011-11-02 18:18:01582 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client));
[email protected]6dfbbf82010-03-12 23:09:16583 installer->set_expected_id(id);
[email protected]ec5b50d2010-10-09 16:35:18584 if (is_pending_extension)
[email protected]b2907fd2011-03-25 16:43:37585 installer->set_install_source(pending_extension_info.install_source());
[email protected]5eb375e92010-11-26 07:50:41586 else if (extension)
587 installer->set_install_source(extension->location());
[email protected]0d3e4a22011-06-23 19:02:52588 if (pending_extension_info.install_silently())
589 installer->set_allow_silent_install(true);
[email protected]7d8b7072012-04-07 01:07:46590 // If the extension was installed from or has migrated to the webstore, or
591 // if the extension came from sync and its auto-update URL is from the
[email protected]75764512011-12-19 19:54:28592 // webstore, treat it as a webstore install. Note that we ignore some older
593 // extensions with blank auto-update URLs because we are mostly concerned
594 // with restrictions on NaCl extensions, which are newer.
[email protected]a12ce8b22012-01-17 18:40:53595 int creation_flags = Extension::NO_FLAGS;
[email protected]75764512011-12-19 19:54:28596 if ((extension && extension->from_webstore()) ||
[email protected]7d8b7072012-04-07 01:07:46597 (extension && extension->UpdatesFromGallery()) ||
[email protected]75764512011-12-19 19:54:28598 (!extension && pending_extension_info.is_from_sync() &&
599 extension_urls::IsWebstoreUpdateUrl(
[email protected]a12ce8b22012-01-17 18:40:53600 pending_extension_info.update_url()))) {
601 creation_flags |= Extension::FROM_WEBSTORE;
602 }
603
604 // Bookmark apps being updated is kind of a contradiction, but that's because
605 // we mark the default apps as bookmark apps, and they're hosted in the web
606 // store, thus they can get updated. See http://crbug.com/101605 for more
607 // details.
608 if (extension && extension->from_bookmark())
609 creation_flags |= Extension::FROM_BOOKMARK;
610
[email protected]a12ce8b22012-01-17 18:40:53611 installer->set_creation_flags(creation_flags);
612
[email protected]6dfbbf82010-03-12 23:09:16613 installer->set_delete_source(true);
[email protected]655b2b1a2011-10-13 17:13:06614 installer->set_download_url(download_url);
[email protected]cb0e50312011-05-09 15:03:07615 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE);
[email protected]6dfbbf82010-03-12 23:09:16616 installer->InstallCrx(extension_path);
[email protected]420a0ec2011-06-01 01:07:03617
618 if (out_crx_installer)
619 *out_crx_installer = installer;
620
621 return true;
[email protected]e957fe52009-06-23 16:51:05622}
623
[email protected]eaa7dd182010-12-14 11:09:00624void ExtensionService::ReloadExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12625 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]b65272f2009-08-31 15:47:06626 FilePath path;
[email protected]9adb9692010-10-29 23:14:02627 const Extension* current_extension = GetExtensionById(extension_id, false);
[email protected]9cddd4702009-07-27 22:09:40628
[email protected]f17dbd42010-08-16 23:21:10629 // Disable the extension if it's loaded. It might not be loaded if it crashed.
[email protected]b65272f2009-08-31 15:47:06630 if (current_extension) {
[email protected]4814b512009-11-07 00:12:29631 // If the extension has an inspector open for its background page, detach
632 // the inspector and hang onto a cookie for it, so that we can reattach
633 // later.
[email protected]31d8f5f22012-04-02 15:22:08634 // TODO(yoz): this is not incognito-safe!
635 ExtensionProcessManager* manager = system_->process_manager();
[email protected]06024c62011-10-20 20:57:12636 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id);
[email protected]0e12d7d2011-12-01 16:21:44637 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost(
638 host->render_view_host())) {
[email protected]4814b512009-11-07 00:12:29639 // Look for an open inspector for the background page.
[email protected]0e12d7d2011-12-01 16:21:44640 DevToolsAgentHost* agent =
641 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
642 host->render_view_host());
643 int devtools_cookie =
644 content::DevToolsManager::GetInstance()->DetachClientHost(agent);
[email protected]4814b512009-11-07 00:12:29645 if (devtools_cookie >= 0)
646 orphaned_dev_tools_[extension_id] = devtools_cookie;
647 }
648
[email protected]b65272f2009-08-31 15:47:06649 path = current_extension->path();
[email protected]44d62b62012-04-11 00:06:03650 DisableExtension(extension_id, Extension::DISABLE_RELOAD);
[email protected]f17dbd42010-08-16 23:21:10651 disabled_extension_paths_[extension_id] = path;
[email protected]1eb175082010-02-10 09:26:16652 } else {
653 path = unloaded_extension_paths_[extension_id];
[email protected]b65272f2009-08-31 15:47:06654 }
655
[email protected]43ceb002012-02-10 23:19:15656 // If we're reloading a component extension, use the component extension
657 // loader's reloader.
658 if (component_loader_->Exists(extension_id)) {
659 component_loader_->Reload(extension_id);
660 return;
661 }
662
[email protected]e6090e42010-03-23 22:44:08663 // Check the installed extensions to see if what we're reloading was already
664 // installed.
665 scoped_ptr<ExtensionInfo> installed_extension(
666 extension_prefs_->GetInstalledExtensionInfo(extension_id));
667 if (installed_extension.get() &&
668 installed_extension->extension_manifest.get()) {
[email protected]d8c8f25f2011-11-02 18:18:01669 extensions::InstalledLoader(this).Load(*installed_extension, false);
[email protected]e6090e42010-03-23 22:44:08670 } else {
[email protected]d8c8f25f2011-11-02 18:18:01671 // Otherwise, the extension is unpacked (location LOAD).
[email protected]e6090e42010-03-23 22:44:08672 // We should always be able to remember the extension's path. If it's not in
673 // the map, someone failed to update |unloaded_extension_paths_|.
674 CHECK(!path.empty());
[email protected]d8c8f25f2011-11-02 18:18:01675 extensions::UnpackedInstaller::Create(this)->Load(path);
[email protected]e6090e42010-03-23 22:44:08676 }
[email protected]9cddd4702009-07-27 22:09:40677}
678
[email protected]fa2416f2011-05-03 08:41:20679bool ExtensionService::UninstallExtension(
[email protected]a12c706e2011-12-01 00:58:08680 std::string extension_id,
[email protected]fa2416f2011-05-03 08:41:20681 bool external_uninstall,
[email protected]65187152012-06-02 13:14:14682 string16* error) {
[email protected]a29a517a2011-01-21 21:11:12683 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20684
[email protected]0d6ec3a72011-09-02 02:09:43685 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id));
[email protected]631cf822009-05-15 07:01:25686
[email protected]e7afe2452010-08-22 16:19:13687 // Callers should not send us nonexistent extensions.
[email protected]aebe23a32010-12-10 22:15:48688 CHECK(extension);
[email protected]9f1087e2009-06-15 17:29:32689
[email protected]95da88c42011-03-31 10:07:33690 // Policy change which triggers an uninstall will always set
691 // |external_uninstall| to true so this is the only way to uninstall
692 // managed extensions.
[email protected]65187152012-06-02 13:14:14693 if (!external_uninstall &&
694 !system_->management_policy()->UserMayModifySettings(
695 extension.get(), error)) {
[email protected]ad50def52011-10-19 23:17:07696 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27697 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:53698 content::Source<Profile>(profile_),
699 content::Details<const Extension>(extension));
[email protected]d6ebc9792011-04-07 18:18:33700 return false;
701 }
[email protected]95da88c42011-03-31 10:07:33702
[email protected]3bdba0d2011-08-23 07:17:30703 // Extract the data we need for sync now, but don't actually sync until we've
704 // completed the uninstallation.
[email protected]3bdba0d2011-08-23 07:17:30705 SyncChange sync_change;
[email protected]5db9ada2012-04-11 13:48:20706 if (app_sync_bundle_.HandlesApp(*extension)) {
707 sync_change = app_sync_bundle_.CreateSyncChangeToDelete(extension);
708 } else if (extension_sync_bundle_.HandlesExtension(*extension)) {
709 sync_change = extension_sync_bundle_.CreateSyncChangeToDelete(extension);
[email protected]3bdba0d2011-08-23 07:17:30710 }
711
[email protected]9b217652010-10-08 22:04:23712 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType",
[email protected]7fa19f82010-12-21 19:40:08713 extension->GetType(), 100);
[email protected]fe2dd7742011-04-19 22:52:49714 RecordPermissionMessagesHistogram(
715 extension, "Extensions.Permissions_Uninstall");
[email protected]9b217652010-10-08 22:04:23716
[email protected]8e5c89a2011-06-07 18:13:33717 TemplateURLService* url_service =
718 TemplateURLServiceFactory::GetForProfile(profile_);
719 if (url_service)
720 url_service->UnregisterExtensionKeyword(extension);
[email protected]56ad3792010-05-28 17:45:33721
[email protected]831aa212010-03-26 13:55:19722 // Unload before doing more cleanup to ensure that nothing is hanging on to
723 // any of these resources.
[email protected]814a7bf0f2011-08-13 05:30:59724 UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL);
[email protected]831aa212010-03-26 13:55:19725
[email protected]0d6ec3a72011-09-02 02:09:43726 extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(),
[email protected]831aa212010-03-26 13:55:19727 external_uninstall);
[email protected]9f1087e2009-06-15 17:29:32728
729 // Tell the backend to start deleting installed extensions on the file thread.
[email protected]0d6ec3a72011-09-02 02:09:43730 if (Extension::LOAD != extension->location()) {
[email protected]14908b72011-04-20 06:54:36731 if (!BrowserThread::PostTask(
732 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:36733 base::Bind(
[email protected]14908b72011-04-20 06:54:36734 &extension_file_util::UninstallExtension,
735 install_directory_,
[email protected]fa2416f2011-05-03 08:41:20736 extension_id)))
[email protected]14908b72011-04-20 06:54:36737 NOTREACHED();
[email protected]9f1087e2009-06-15 17:29:32738 }
739
[email protected]0d6ec3a72011-09-02 02:09:43740 GURL launch_web_url_origin(extension->launch_web_url());
741 launch_web_url_origin = launch_web_url_origin.GetOrigin();
[email protected]605fb8102012-05-04 01:36:55742 bool is_storage_isolated = extension->is_storage_isolated();
[email protected]0d6ec3a72011-09-02 02:09:43743
744 if (extension->is_hosted_app() &&
745 !profile_->GetExtensionSpecialStoragePolicy()->
746 IsStorageProtected(launch_web_url_origin)) {
[email protected]dc0b5a12011-10-14 00:06:13747 ExtensionDataDeleter::StartDeleting(
748 profile_, extension_id, launch_web_url_origin, is_storage_isolated);
[email protected]0d6ec3a72011-09-02 02:09:43749 }
[email protected]dc0b5a12011-10-14 00:06:13750 ExtensionDataDeleter::StartDeleting(
751 profile_, extension_id, extension->url(), is_storage_isolated);
[email protected]0d6ec3a72011-09-02 02:09:43752
[email protected]0dfe05c2011-02-23 23:03:36753 UntrackTerminatedExtension(extension_id);
[email protected]211030342010-09-30 18:41:06754
755 // Notify interested parties that we've uninstalled this extension.
[email protected]ad50def52011-10-19 23:17:07756 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27757 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
[email protected]6c2381d2011-10-19 02:52:53758 content::Source<Profile>(profile_),
759 content::Details<const std::string>(&extension_id));
[email protected]d6ebc9792011-04-07 18:18:33760
[email protected]5db9ada2012-04-11 13:48:20761 if (app_sync_bundle_.HasExtensionId(extension_id) &&
762 sync_change.sync_data().GetDataType() == syncable::APPS) {
763 app_sync_bundle_.ProcessDeletion(extension_id, sync_change);
764 } else if (extension_sync_bundle_.HasExtensionId(extension_id) &&
765 sync_change.sync_data().GetDataType() == syncable::EXTENSIONS) {
766 extension_sync_bundle_.ProcessDeletion(extension_id, sync_change);
[email protected]3bdba0d2011-08-23 07:17:30767 }
768
[email protected]333b1de2011-09-12 18:28:50769 // Track the uninstallation.
[email protected]49098f702011-10-13 03:47:18770 UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2);
771
772 static bool default_apps_trial_exists =
[email protected]568c3312011-12-06 15:36:04773 base::FieldTrialList::TrialExists(kDefaultAppsTrialName);
[email protected]49098f702011-10-13 03:47:18774 if (default_apps_trial_exists) {
775 UMA_HISTOGRAM_ENUMERATION(
776 base::FieldTrial::MakeName("Extensions.ExtensionUninstalled",
[email protected]568c3312011-12-06 15:36:04777 kDefaultAppsTrialName),
[email protected]49098f702011-10-13 03:47:18778 1, 2);
779 }
[email protected]333b1de2011-09-12 18:28:50780
[email protected]7c1490da2011-10-11 18:53:25781 // Uninstalling one extension might have solved the problems of others.
782 // Therefore, we clear warnings of this type for all extensions.
783 std::set<ExtensionWarningSet::WarningType> warnings;
784 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
785 extension_warnings_.ClearWarnings(warnings);
786
[email protected]d6ebc9792011-04-07 18:18:33787 return true;
[email protected]c10da4b02010-03-25 14:38:32788}
789
[email protected]c3cfb012011-04-06 22:07:35790bool ExtensionService::IsExtensionEnabled(
791 const std::string& extension_id) const {
[email protected]84df8332011-12-06 18:22:46792 if (extensions_.Contains(extension_id) ||
793 terminated_extensions_.Contains(extension_id))
[email protected]36429da2011-07-11 20:25:18794 return true;
795
[email protected]84df8332011-12-06 18:22:46796 if (disabled_extensions_.Contains(extension_id))
[email protected]ad83ca242011-07-29 01:32:25797 return false;
798
799 // If the extension hasn't been loaded yet, check the prefs for it. Assume
800 // enabled unless otherwise noted.
801 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
802 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
[email protected]c3cfb012011-04-06 22:07:35803}
804
805bool ExtensionService::IsExternalExtensionUninstalled(
806 const std::string& extension_id) const {
807 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
808}
809
[email protected]eaa7dd182010-12-14 11:09:00810void ExtensionService::EnableExtension(const std::string& extension_id) {
[email protected]a29a517a2011-01-21 21:11:12811 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20812
[email protected]06f92562011-04-29 19:27:31813 if (IsExtensionEnabled(extension_id))
[email protected]0c6da502009-08-14 22:32:39814 return;
[email protected]0c6da502009-08-14 22:32:39815
[email protected]b3317ad2011-04-28 23:46:00816 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
[email protected]44d62b62012-04-11 00:06:03817 extension_prefs_->RemoveDisableReason(extension_id);
[email protected]1784e83a2009-09-08 21:01:52818
[email protected]06f92562011-04-29 19:27:31819 const Extension* extension =
820 GetExtensionByIdInternal(extension_id, false, true, false);
821 // This can happen if sync enables an extension that is not
822 // installed yet.
823 if (!extension)
824 return;
825
[email protected]0c6da502009-08-14 22:32:39826 // Move it over to the enabled list.
[email protected]84df8332011-12-06 18:22:46827 extensions_.Insert(make_scoped_refptr(extension));
828 disabled_extensions_.Remove(extension->id());
[email protected]0c6da502009-08-14 22:32:39829
[email protected]f681c782010-11-19 11:19:39830 // Make sure any browser action contained within it is not hidden.
831 extension_prefs_->SetBrowserActionVisibility(extension, true);
832
[email protected]62d30f42009-10-01 22:36:06833 NotifyExtensionLoaded(extension);
[email protected]3bdba0d2011-08-23 07:17:30834
835 SyncExtensionChangeIfNeeded(*extension);
[email protected]0c6da502009-08-14 22:32:39836}
837
[email protected]44d62b62012-04-11 00:06:03838void ExtensionService::DisableExtension(
839 const std::string& extension_id,
840 Extension::DisableReason disable_reason) {
[email protected]a29a517a2011-01-21 21:11:12841 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:20842
[email protected]b2ba9962009-12-10 20:10:15843 // The extension may have been disabled already.
[email protected]06f92562011-04-29 19:27:31844 if (!IsExtensionEnabled(extension_id))
[email protected]1784e83a2009-09-08 21:01:52845 return;
[email protected]1784e83a2009-09-08 21:01:52846
[email protected]06f92562011-04-29 19:27:31847 const Extension* extension = GetInstalledExtension(extension_id);
848 // |extension| can be NULL if sync disables an extension that is not
849 // installed yet.
[email protected]65187152012-06-02 13:14:14850 if (extension &&
851 !system_->management_policy()->UserMayModifySettings(extension, NULL)) {
[email protected]95da88c42011-03-31 10:07:33852 return;
[email protected]65187152012-06-02 13:14:14853 }
[email protected]95da88c42011-03-31 10:07:33854
[email protected]b3317ad2011-04-28 23:46:00855 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
[email protected]44d62b62012-04-11 00:06:03856 extension_prefs_->SetDisableReason(extension_id, disable_reason);
[email protected]1784e83a2009-09-08 21:01:52857
[email protected]06f92562011-04-29 19:27:31858 extension = GetExtensionByIdInternal(extension_id, true, false, true);
859 if (!extension)
860 return;
861
[email protected]1784e83a2009-09-08 21:01:52862 // Move it over to the disabled list.
[email protected]84df8332011-12-06 18:22:46863 disabled_extensions_.Insert(make_scoped_refptr(extension));
864 if (extensions_.Contains(extension->id()))
865 extensions_.Remove(extension->id());
866 else
867 terminated_extensions_.Remove(extension->id());
[email protected]1784e83a2009-09-08 21:01:52868
[email protected]814a7bf0f2011-08-13 05:30:59869 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
[email protected]3bdba0d2011-08-23 07:17:30870
871 SyncExtensionChangeIfNeeded(*extension);
[email protected]7c1490da2011-10-11 18:53:25872
873 // Deactivating one extension might have solved the problems of others.
874 // Therefore, we clear warnings of this type for all extensions.
875 std::set<ExtensionWarningSet::WarningType> warnings;
876 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
877 extension_warnings_.ClearWarnings(warnings);
[email protected]1784e83a2009-09-08 21:01:52878}
879
[email protected]eaa7dd182010-12-14 11:09:00880void ExtensionService::GrantPermissionsAndEnableExtension(
[email protected]8d888c12010-11-30 00:00:25881 const Extension* extension) {
882 CHECK(extension);
[email protected]fe2dd7742011-04-19 22:52:49883 RecordPermissionMessagesHistogram(
884 extension, "Extensions.Permissions_ReEnable");
[email protected]c333e792012-01-06 16:57:39885 extensions::PermissionsUpdater perms_updater(profile());
886 perms_updater.GrantActivePermissions(extension);
[email protected]8d888c12010-11-30 00:00:25887 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
888 EnableExtension(extension->id());
889}
890
[email protected]fe2dd7742011-04-19 22:52:49891// static
892void ExtensionService::RecordPermissionMessagesHistogram(
893 const Extension* e, const char* histogram) {
894 // Since this is called from multiple sources, and since the Histogram macros
895 // use statics, we need to manually lookup the Histogram ourselves.
896 base::Histogram* counter = base::LinearHistogram::FactoryGet(
897 histogram,
898 1,
[email protected]0d3e4a22011-06-23 19:02:52899 ExtensionPermissionMessage::kEnumBoundary,
900 ExtensionPermissionMessage::kEnumBoundary + 1,
[email protected]fe2dd7742011-04-19 22:52:49901 base::Histogram::kUmaTargetedHistogramFlag);
902
[email protected]0d3e4a22011-06-23 19:02:52903 ExtensionPermissionMessages permissions = e->GetPermissionMessages();
[email protected]fe2dd7742011-04-19 22:52:49904 if (permissions.empty()) {
[email protected]0d3e4a22011-06-23 19:02:52905 counter->Add(ExtensionPermissionMessage::kNone);
[email protected]fe2dd7742011-04-19 22:52:49906 } else {
[email protected]0d3e4a22011-06-23 19:02:52907 for (ExtensionPermissionMessages::iterator it = permissions.begin();
908 it != permissions.end(); ++it)
909 counter->Add(it->id());
[email protected]fe2dd7742011-04-19 22:52:49910 }
911}
912
[email protected]eaa7dd182010-12-14 11:09:00913void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
[email protected]57a777f72010-03-31 01:09:42914 // The ChromeURLRequestContexts need to be first to know that the extension
[email protected]62d30f42009-10-01 22:36:06915 // was loaded, otherwise a race can arise where a renderer that is created
916 // for the extension may try to load an extension URL with an extension id
[email protected]57a777f72010-03-31 01:09:42917 // that the request context doesn't yet know about. The profile is responsible
918 // for ensuring its URLRequestContexts appropriately discover the loaded
919 // extension.
[email protected]31d8f5f22012-04-02 15:22:08920 system_->RegisterExtensionWithRequestContexts(extension);
[email protected]62d30f42009-10-01 22:36:06921
[email protected]19647262011-12-16 09:57:49922 // Tell renderers about the new extension, unless it's a theme (renderers
923 // don't need to know about themes).
924 if (!extension->is_theme()) {
925 for (content::RenderProcessHost::iterator i(
926 content::RenderProcessHost::AllHostsIterator());
927 !i.IsAtEnd(); i.Advance()) {
928 content::RenderProcessHost* host = i.GetCurrentValue();
929 Profile* host_profile =
930 Profile::FromBrowserContext(host->GetBrowserContext());
931 if (host_profile->GetOriginalProfile() ==
932 profile_->GetOriginalProfile()) {
933 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
934 1, ExtensionMsg_Loaded_Params(extension));
935 host->Send(
936 new ExtensionMsg_Loaded(loaded_extensions));
937 }
[email protected]c8d407e2011-04-28 21:27:17938 }
[email protected]77a6970c2011-04-23 16:58:56939 }
940
[email protected]3442a662012-01-12 08:06:17941 // Tell subsystems that use the EXTENSION_LOADED notification about the new
942 // extension.
943 //
944 // NOTE: It is important that this happen after notifying the renderers about
945 // the new extensions so that if we navigate to an extension URL in
946 // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it.
947 content::NotificationService::current()->Notify(
948 chrome::NOTIFICATION_EXTENSION_LOADED,
949 content::Source<Profile>(profile_),
950 content::Details<const Extension>(extension));
951
[email protected]c8d407e2011-04-28 21:27:17952 // Tell a random-ass collection of other subsystems about the new extension.
953 // TODO(aa): What should we do with all this goop? Can it move into the
954 // relevant objects via EXTENSION_LOADED?
955
956 profile_->GetExtensionSpecialStoragePolicy()->
957 GrantRightsForExtension(extension);
958
959 UpdateActiveExtensionsInCrashReporter();
960
961 ExtensionWebUI::RegisterChromeURLOverrides(
962 profile_, extension->GetChromeURLOverrides());
963
[email protected]8e5c89a2011-06-07 18:13:33964 TemplateURLService* url_service =
965 TemplateURLServiceFactory::GetForProfile(profile_);
966 if (url_service)
967 url_service->RegisterExtensionKeyword(extension);
[email protected]c8d407e2011-04-28 21:27:17968
969 // Load the icon for omnibox-enabled extensions so it will be ready to display
970 // in the URL bar.
971 if (!extension->omnibox_keyword().empty()) {
972 omnibox_popup_icon_manager_.LoadIcon(extension);
973 omnibox_icon_manager_.LoadIcon(extension);
974 }
975
976 // If the extension has permission to load chrome://favicon/ resources we need
977 // to make sure that the FaviconSource is registered with the
978 // ChromeURLDataManager.
979 if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) {
980 FaviconSource* favicon_source = new FaviconSource(profile_,
981 FaviconSource::FAVICON);
[email protected]ef92e172012-04-25 19:40:41982 ChromeURLDataManager::AddDataSource(profile_, favicon_source);
[email protected]c8d407e2011-04-28 21:27:17983 }
[email protected]5eddc3e2011-10-26 04:33:31984 // Same for chrome://thumb/ resources.
985 if (extension->HasHostPermission(GURL(chrome::kChromeUIThumbnailURL))) {
986 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_);
[email protected]ef92e172012-04-25 19:40:41987 ChromeURLDataManagerFactory::GetForProfile(profile_)->
988 AddDataSource(thumbnail_source);
[email protected]5eddc3e2011-10-26 04:33:31989 }
[email protected]c8d407e2011-04-28 21:27:17990
991 // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757.
[email protected]2de307592011-04-05 21:16:58992 bool plugins_changed = false;
993 for (size_t i = 0; i < extension->plugins().size(); ++i) {
994 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]f520b5b2011-11-08 02:42:14995 PluginService::GetInstance()->RefreshPlugins();
996 PluginService::GetInstance()->AddExtraPluginPath(plugin.path);
[email protected]2de307592011-04-05 21:16:58997 plugins_changed = true;
[email protected]476a27032011-09-13 13:40:49998 ChromePluginServiceFilter* filter =
999 ChromePluginServiceFilter::GetInstance();
1000 if (plugin.is_public) {
1001 filter->RestrictPluginToProfileAndOrigin(
1002 plugin.path, profile_, GURL());
1003 } else {
1004 filter->RestrictPluginToProfileAndOrigin(
1005 plugin.path, profile_, extension->url());
[email protected]2de307592011-04-05 21:16:581006 }
1007 }
[email protected]84396dbc2011-04-14 06:33:421008
1009 bool nacl_modules_changed = false;
1010 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1011 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001012 RegisterNaClModule(module.url, module.mime_type);
[email protected]84396dbc2011-04-14 06:33:421013 nacl_modules_changed = true;
1014 }
1015
[email protected]ed0ba002011-05-26 16:55:131016 if (nacl_modules_changed)
1017 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421018
1019 if (plugins_changed || nacl_modules_changed)
[email protected]45a22e62011-10-12 09:48:021020 PluginService::GetInstance()->PurgePluginListCache(profile_, false);
[email protected]b4d9d122011-06-17 01:58:541021
[email protected]14da67b02011-08-02 05:49:131022#if defined(OS_CHROMEOS)
[email protected]b4d9d122011-06-17 01:58:541023 for (std::vector<Extension::InputComponentInfo>::const_iterator component =
1024 extension->input_components().begin();
1025 component != extension->input_components().end();
1026 ++component) {
[email protected]14da67b02011-08-02 05:49:131027 if (component->type == Extension::INPUT_COMPONENT_TYPE_IME) {
[email protected]8baf0dbb2011-11-27 22:47:021028 ExtensionInputImeEventRouter::GetInstance()->RegisterIme(
[email protected]14da67b02011-08-02 05:49:131029 profile_, extension->id(), *component);
1030 }
[email protected]b4d9d122011-06-17 01:58:541031 }
1032#endif
[email protected]62d30f42009-10-01 22:36:061033}
1034
[email protected]a9f39a312010-12-23 22:14:271035void ExtensionService::NotifyExtensionUnloaded(
[email protected]814a7bf0f2011-08-13 05:30:591036 const Extension* extension,
1037 extension_misc::UnloadedExtensionReason reason) {
[email protected]a9f39a312010-12-23 22:14:271038 UnloadedExtensionInfo details(extension, reason);
[email protected]ad50def52011-10-19 23:17:071039 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271040 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531041 content::Source<Profile>(profile_),
1042 content::Details<UnloadedExtensionInfo>(&details));
[email protected]62d30f42009-10-01 22:36:061043
[email protected]f3b1a082011-11-18 00:34:301044 for (content::RenderProcessHost::iterator i(
1045 content::RenderProcessHost::AllHostsIterator());
[email protected]77a6970c2011-04-23 16:58:561046 !i.IsAtEnd(); i.Advance()) {
[email protected]f3b1a082011-11-18 00:34:301047 content::RenderProcessHost* host = i.GetCurrentValue();
[email protected]9b62ecf2011-07-27 20:23:081048 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:301049 Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]9b62ecf2011-07-27 20:23:081050 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
[email protected]c8d407e2011-04-28 21:27:171051 host->Send(new ExtensionMsg_Unloaded(extension->id()));
[email protected]77a6970c2011-04-23 16:58:561052 }
1053
[email protected]31d8f5f22012-04-02 15:22:081054 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
[email protected]c8d407e2011-04-28 21:27:171055 profile_->GetExtensionSpecialStoragePolicy()->
1056 RevokeRightsForExtension(extension);
1057
1058 ExtensionWebUI::UnregisterChromeURLOverrides(
1059 profile_, extension->GetChromeURLOverrides());
1060
[email protected]b777b332011-04-16 04:01:081061#if defined(OS_CHROMEOS)
1062 // Revoke external file access to
[email protected]55eb70e762012-02-20 17:38:391063 if (BrowserContext::GetFileSystemContext(profile_) &&
1064 BrowserContext::GetFileSystemContext(profile_)->external_provider()) {
1065 BrowserContext::GetFileSystemContext(profile_)->external_provider()->
[email protected]c8d407e2011-04-28 21:27:171066 RevokeAccessForExtension(extension->id());
[email protected]62d30f42009-10-01 22:36:061067 }
[email protected]54ccafa2011-12-06 23:36:321068
1069 if (extension->input_components().size() > 0) {
1070 ExtensionInputImeEventRouter::GetInstance()->UnregisterAllImes(
1071 profile_, extension->id());
1072 }
[email protected]c8d407e2011-04-28 21:27:171073#endif
1074
1075 UpdateActiveExtensionsInCrashReporter();
[email protected]2de307592011-04-05 21:16:581076
1077 bool plugins_changed = false;
1078 for (size_t i = 0; i < extension->plugins().size(); ++i) {
1079 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]b6a2f8de2012-01-31 17:28:491080 PluginService::GetInstance()->ForcePluginShutdown(plugin.path);
[email protected]f520b5b2011-11-08 02:42:141081 PluginService::GetInstance()->RefreshPlugins();
1082 PluginService::GetInstance()->RemoveExtraPluginPath(plugin.path);
[email protected]2de307592011-04-05 21:16:581083 plugins_changed = true;
[email protected]476a27032011-09-13 13:40:491084 ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin.path);
[email protected]2de307592011-04-05 21:16:581085 }
[email protected]84396dbc2011-04-14 06:33:421086
1087 bool nacl_modules_changed = false;
1088 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) {
1089 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i];
[email protected]cebc3dc2011-04-18 17:15:001090 UnregisterNaClModule(module.url);
[email protected]84396dbc2011-04-14 06:33:421091 nacl_modules_changed = true;
1092 }
1093
[email protected]ed0ba002011-05-26 16:55:131094 if (nacl_modules_changed)
1095 UpdatePluginListWithNaClModules();
[email protected]84396dbc2011-04-14 06:33:421096
1097 if (plugins_changed || nacl_modules_changed)
[email protected]45a22e62011-10-12 09:48:021098 PluginService::GetInstance()->PurgePluginListCache(profile_, false);
[email protected]62d30f42009-10-01 22:36:061099}
1100
[email protected]eaa7dd182010-12-14 11:09:001101void ExtensionService::UpdateExtensionBlacklist(
[email protected]6b75ec32009-08-14 06:37:181102 const std::vector<std::string>& blacklist) {
1103 // Use this set to indicate if an extension in the blacklist has been used.
1104 std::set<std::string> blacklist_set;
1105 for (unsigned int i = 0; i < blacklist.size(); ++i) {
1106 if (Extension::IdIsValid(blacklist[i])) {
1107 blacklist_set.insert(blacklist[i]);
1108 }
1109 }
1110 extension_prefs_->UpdateBlacklist(blacklist_set);
1111 std::vector<std::string> to_be_removed;
1112 // Loop current extensions, unload installed extensions.
[email protected]84df8332011-12-06 18:22:461113 for (ExtensionSet::const_iterator iter = extensions_.begin();
[email protected]6b75ec32009-08-14 06:37:181114 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021115 const Extension* extension = (*iter);
[email protected]6b75ec32009-08-14 06:37:181116 if (blacklist_set.find(extension->id()) != blacklist_set.end()) {
1117 to_be_removed.push_back(extension->id());
1118 }
1119 }
1120
1121 // UnloadExtension will change the extensions_ list. So, we should
1122 // call it outside the iterator loop.
1123 for (unsigned int i = 0; i < to_be_removed.size(); ++i) {
[email protected]814a7bf0f2011-08-13 05:30:591124 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE);
[email protected]6b75ec32009-08-14 06:37:181125 }
1126}
1127
[email protected]0a071a32011-02-08 00:18:241128Profile* ExtensionService::profile() {
1129 return profile_;
1130}
1131
[email protected]eaa7dd182010-12-14 11:09:001132ExtensionPrefs* ExtensionService::extension_prefs() {
[email protected]ddb1e5a2010-12-13 20:10:451133 return extension_prefs_;
1134}
1135
[email protected]0d9a2202011-11-09 13:48:411136extensions::SettingsFrontend* ExtensionService::settings_frontend() {
[email protected]cccdf0aa2011-11-11 03:43:381137 return settings_frontend_.get();
[email protected]b7f853e282011-08-10 09:24:201138}
1139
[email protected]e2d720aa2012-05-17 00:11:351140extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() {
[email protected]b790b072011-05-20 09:46:441141 return extension_prefs()->content_settings_store();
1142}
1143
[email protected]25ae0152011-11-18 14:40:021144bool ExtensionService::is_ready() {
1145 return ready_;
1146}
1147
[email protected]42a08162012-03-16 18:09:111148extensions::ExtensionUpdater* ExtensionService::updater() {
[email protected]2859946f2011-04-04 18:18:061149 return updater_.get();
1150}
1151
[email protected]eaa7dd182010-12-14 11:09:001152void ExtensionService::CheckAdminBlacklist() {
[email protected]aa96d3a2010-08-21 08:45:251153 std::vector<std::string> to_be_removed;
1154 // Loop through extensions list, unload installed extensions.
[email protected]84df8332011-12-06 18:22:461155 for (ExtensionSet::const_iterator iter = extensions_.begin();
[email protected]aa96d3a2010-08-21 08:45:251156 iter != extensions_.end(); ++iter) {
[email protected]9adb9692010-10-29 23:14:021157 const Extension* extension = (*iter);
[email protected]65187152012-06-02 13:14:141158 if (!system_->management_policy()->UserMayLoad(extension, NULL)) {
[email protected]aa96d3a2010-08-21 08:45:251159 to_be_removed.push_back(extension->id());
[email protected]05aad2da2011-10-28 10:12:371160 }
[email protected]aa96d3a2010-08-21 08:45:251161 }
1162
1163 // UnloadExtension will change the extensions_ list. So, we should
1164 // call it outside the iterator loop.
1165 for (unsigned int i = 0; i < to_be_removed.size(); ++i)
[email protected]814a7bf0f2011-08-13 05:30:591166 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE);
[email protected]aa96d3a2010-08-21 08:45:251167}
1168
[email protected]31206602011-04-13 23:07:321169void ExtensionService::CheckForUpdatesSoon() {
[email protected]c3cfb012011-04-06 22:07:351170 if (updater()) {
[email protected]94fde232012-04-27 10:22:301171 if (AreAllExternalProvidersReady()) {
1172 updater()->CheckSoon();
1173 } else {
1174 // Sync can start updating before all the external providers are ready
1175 // during startup. Start the update as soon as those providers are ready,
1176 // but not before.
1177 update_once_all_providers_are_ready_ = true;
1178 }
[email protected]c3cfb012011-04-06 22:07:351179 } else {
[email protected]31206602011-04-13 23:07:321180 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
[email protected]c3cfb012011-04-06 22:07:351181 }
1182}
1183
[email protected]3bdba0d2011-08-23 07:17:301184SyncError ExtensionService::MergeDataAndStartSyncing(
1185 syncable::ModelType type,
1186 const SyncDataList& initial_sync_data,
[email protected]5d36e052012-04-20 20:12:281187 scoped_ptr<SyncChangeProcessor> sync_processor,
1188 scoped_ptr<SyncErrorFactory> sync_error_factory) {
[email protected]5db9ada2012-04-11 13:48:201189 CHECK(sync_processor.get());
[email protected]5d36e052012-04-20 20:12:281190 CHECK(sync_error_factory.get());
[email protected]3bdba0d2011-08-23 07:17:301191
1192 switch (type) {
1193 case syncable::EXTENSIONS:
[email protected]5db9ada2012-04-11 13:48:201194 extension_sync_bundle_.SetupSync(sync_processor.release(),
[email protected]5d36e052012-04-20 20:12:281195 sync_error_factory.release(),
[email protected]5db9ada2012-04-11 13:48:201196 initial_sync_data);
[email protected]3bdba0d2011-08-23 07:17:301197 break;
1198
1199 case syncable::APPS:
[email protected]5d36e052012-04-20 20:12:281200 app_sync_bundle_.SetupSync(sync_processor.release(),
1201 sync_error_factory.release(),
1202 initial_sync_data);
[email protected]3bdba0d2011-08-23 07:17:301203 break;
1204
1205 default:
1206 LOG(FATAL) << "Got " << type << " ModelType";
1207 }
[email protected]3bdba0d2011-08-23 07:17:301208
[email protected]b1417ab2011-12-15 17:09:111209 // Process local extensions.
1210 // TODO(yoz): Determine whether pending extensions should be considered too.
1211 // See crbug.com/104399.
[email protected]3bdba0d2011-08-23 07:17:301212 SyncDataList sync_data_list = GetAllSyncData(type);
1213 SyncChangeList sync_change_list;
1214 for (SyncDataList::const_iterator i = sync_data_list.begin();
1215 i != sync_data_list.end();
1216 ++i) {
[email protected]5db9ada2012-04-11 13:48:201217 switch (type) {
1218 case syncable::EXTENSIONS:
1219 sync_change_list.push_back(
1220 extension_sync_bundle_.CreateSyncChange(*i));
1221 break;
1222 case syncable::APPS:
1223 sync_change_list.push_back(app_sync_bundle_.CreateSyncChange(*i));
1224 break;
1225 default:
1226 LOG(FATAL) << "Got " << type << " ModelType";
1227 }
[email protected]3bdba0d2011-08-23 07:17:301228 }
[email protected]3bdba0d2011-08-23 07:17:301229
[email protected]5db9ada2012-04-11 13:48:201230
1231 if (type == syncable::EXTENSIONS) {
1232 extension_sync_bundle_.ProcessSyncChangeList(sync_change_list);
1233 } else if (type == syncable::APPS) {
1234 app_sync_bundle_.ProcessSyncChangeList(sync_change_list);
1235 }
[email protected]0ffd9e52012-01-26 21:44:341236
[email protected]3bdba0d2011-08-23 07:17:301237 return SyncError();
1238}
1239
1240void ExtensionService::StopSyncing(syncable::ModelType type) {
[email protected]5db9ada2012-04-11 13:48:201241 if (type == syncable::APPS) {
1242 app_sync_bundle_.Reset();
1243 } else if (type == syncable::EXTENSIONS) {
1244 extension_sync_bundle_.Reset();
1245 }
[email protected]3bdba0d2011-08-23 07:17:301246}
1247
1248SyncDataList ExtensionService::GetAllSyncData(syncable::ModelType type) const {
[email protected]5db9ada2012-04-11 13:48:201249 if (type == syncable::EXTENSIONS) {
1250 return extension_sync_bundle_.GetAllSyncData();
1251
1252 } else if (type == syncable::APPS) {
1253 return app_sync_bundle_.GetAllSyncData();
[email protected]3bdba0d2011-08-23 07:17:301254 }
[email protected]5db9ada2012-04-11 13:48:201255
1256 // We should only get sync data for extensions and apps.
1257 NOTREACHED();
1258
1259 return SyncDataList();
[email protected]3bdba0d2011-08-23 07:17:301260}
1261
1262SyncError ExtensionService::ProcessSyncChanges(
1263 const tracked_objects::Location& from_here,
1264 const SyncChangeList& change_list) {
1265 for (SyncChangeList::const_iterator i = change_list.begin();
1266 i != change_list.end();
1267 ++i) {
[email protected]5db9ada2012-04-11 13:48:201268 syncable::ModelType type = i->sync_data().GetDataType();
1269 if (type == syncable::EXTENSIONS) {
1270 extension_sync_bundle_.ProcessSyncChange(
1271 extensions::ExtensionSyncData(*i));
1272 } else if (type == syncable::APPS) {
1273 app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i));
1274 }
[email protected]3bdba0d2011-08-23 07:17:301275 }
1276
[email protected]0ffd9e52012-01-26 21:44:341277 extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions();
1278
[email protected]3bdba0d2011-08-23 07:17:301279 return SyncError();
[email protected]b05fb9ff2011-04-23 00:07:561280}
1281
[email protected]5db9ada2012-04-11 13:48:201282extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData(
1283 const Extension& extension) const {
1284 return extensions::ExtensionSyncData(extension,
1285 IsExtensionEnabled(extension.id()),
1286 IsIncognitoEnabled(extension.id()));
[email protected]b05fb9ff2011-04-23 00:07:561287}
1288
[email protected]5db9ada2012-04-11 13:48:201289extensions::AppSyncData ExtensionService::GetAppSyncData(
1290 const Extension& extension) const {
1291 return extensions::AppSyncData(
1292 extension,
1293 IsExtensionEnabled(extension.id()),
1294 IsIncognitoEnabled(extension.id()),
1295 extension_prefs_->GetAppNotificationClientId(extension.id()),
1296 extension_prefs_->IsAppNotificationDisabled(extension.id()),
1297 extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(
1298 extension.id()),
1299 extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id()));
1300}
[email protected]3bdba0d2011-08-23 07:17:301301
[email protected]5db9ada2012-04-11 13:48:201302std::vector<extensions::ExtensionSyncData>
1303 ExtensionService::GetExtensionSyncDataList() const {
1304 std::vector<extensions::ExtensionSyncData> extension_sync_list;
1305 extension_sync_bundle_.GetExtensionSyncDataListHelper(extensions_,
1306 &extension_sync_list);
1307 extension_sync_bundle_.GetExtensionSyncDataListHelper(disabled_extensions_,
1308 &extension_sync_list);
1309 extension_sync_bundle_.GetExtensionSyncDataListHelper(terminated_extensions_,
1310 &extension_sync_list);
1311
1312 std::vector<extensions::ExtensionSyncData> pending_extensions =
1313 extension_sync_bundle_.GetPendingData();
1314 extension_sync_list.insert(extension_sync_list.begin(),
1315 pending_extensions.begin(),
1316 pending_extensions.end());
[email protected]3bdba0d2011-08-23 07:17:301317
1318 return extension_sync_list;
[email protected]b05fb9ff2011-04-23 00:07:561319}
1320
[email protected]5db9ada2012-04-11 13:48:201321std::vector<extensions::AppSyncData> ExtensionService::GetAppSyncDataList()
1322 const {
1323 std::vector<extensions::AppSyncData> app_sync_list;
1324 app_sync_bundle_.GetAppSyncDataListHelper(extensions_, &app_sync_list);
1325 app_sync_bundle_.GetAppSyncDataListHelper(disabled_extensions_,
1326 &app_sync_list);
1327 app_sync_bundle_.GetAppSyncDataListHelper(terminated_extensions_,
1328 &app_sync_list);
1329
1330 std::vector<extensions::AppSyncData> pending_apps =
1331 app_sync_bundle_.GetPendingData();
1332 app_sync_list.insert(app_sync_list.begin(),
1333 pending_apps.begin(),
1334 pending_apps.end());
1335
1336 return app_sync_list;
1337}
1338
1339bool ExtensionService::ProcessExtensionSyncData(
1340 const extensions::ExtensionSyncData& extension_sync_data) {
1341 if (!ProcessExtensionSyncDataHelper(extension_sync_data,
1342 syncable::EXTENSIONS)) {
1343 extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(),
1344 extension_sync_data);
1345 CheckForUpdatesSoon();
1346 return false;
1347 }
1348
1349 return true;
1350}
1351
1352bool ExtensionService::ProcessAppSyncData(
1353 const extensions::AppSyncData& app_sync_data) {
1354 const std::string& id = app_sync_data.id();
1355 const Extension* extension = GetInstalledExtension(id);
1356 bool extension_installed = (extension != NULL);
1357
1358 if (app_sync_data.app_launch_ordinal().IsValid() &&
1359 app_sync_data.page_ordinal().IsValid()) {
1360 extension_prefs_->extension_sorting()->SetAppLaunchOrdinal(
1361 id,
1362 app_sync_data.app_launch_ordinal());
1363 extension_prefs_->extension_sorting()->SetPageOrdinal(
1364 id,
1365 app_sync_data.page_ordinal());
1366 }
1367
1368 if (extension_installed) {
1369 if (app_sync_data.notifications_disabled() !=
1370 extension_prefs_->IsAppNotificationDisabled(id)) {
1371 extension_prefs_->SetAppNotificationDisabled(
1372 id, app_sync_data.notifications_disabled());
1373 }
1374 }
1375
1376 if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(),
1377 syncable::APPS)) {
1378 app_sync_bundle_.AddPendingApp(id, app_sync_data);
1379 CheckForUpdatesSoon();
1380 return false;
1381 }
1382
1383 return true;
1384}
1385
1386bool ExtensionService::IsCorrectSyncType(const Extension& extension,
1387 syncable::ModelType type) const {
1388 if (type == syncable::EXTENSIONS &&
1389 extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION)
1390 return true;
1391
1392 if (type == syncable::APPS &&
1393 extension.GetSyncType() == Extension::SYNC_TYPE_APP)
1394 return true;
1395
1396 return false;
1397}
1398
1399bool ExtensionService::ProcessExtensionSyncDataHelper(
1400 const extensions::ExtensionSyncData& extension_sync_data,
1401 syncable::ModelType type) {
[email protected]3bdba0d2011-08-23 07:17:301402 const std::string& id = extension_sync_data.id();
[email protected]96e989b2011-08-30 19:35:061403 const Extension* extension = GetInstalledExtension(id);
1404
1405 // TODO(bolms): we should really handle this better. The particularly bad
1406 // case is where an app becomes an extension or vice versa, and we end up with
1407 // a zombie extension that won't go away.
[email protected]5db9ada2012-04-11 13:48:201408 if (extension && !IsCorrectSyncType(*extension, type))
1409 return true;
[email protected]90310d92011-04-17 07:35:041410
1411 // Handle uninstalls first.
[email protected]3bdba0d2011-08-23 07:17:301412 if (extension_sync_data.uninstalled()) {
[email protected]90310d92011-04-17 07:35:041413 std::string error;
1414 if (!UninstallExtensionHelper(this, id)) {
1415 LOG(WARNING) << "Could not uninstall extension " << id
1416 << " for sync";
1417 }
[email protected]5db9ada2012-04-11 13:48:201418 return true;
[email protected]90310d92011-04-17 07:35:041419 }
1420
[email protected]caf2d442012-05-04 10:00:501421 // Extension from sync was uninstalled by the user as external extensions.
1422 // Honor user choice and skip installation/enabling.
1423 if (IsExternalExtensionUninstalled(id)) {
1424 LOG(WARNING) << "Extension with id " << id
1425 << " from sync was uninstalled as external extension";
1426 return true;
1427 }
1428
[email protected]06f92562011-04-29 19:27:311429 // Set user settings.
[email protected]3bdba0d2011-08-23 07:17:301430 if (extension_sync_data.enabled()) {
[email protected]06f92562011-04-29 19:27:311431 EnableExtension(id);
1432 } else {
[email protected]44d62b62012-04-11 00:06:031433 DisableExtension(id, Extension::DISABLE_USER_ACTION);
[email protected]06f92562011-04-29 19:27:311434 }
[email protected]81b14cc2011-04-29 00:39:371435
[email protected]406b5a92011-11-08 11:58:261436 // We need to cache some version information here because setting the
1437 // incognito flag invalidates the |extension| pointer (it reloads the
1438 // extension).
[email protected]9060d8b02012-01-13 02:14:301439 bool extension_installed = (extension != NULL);
[email protected]406b5a92011-11-08 11:58:261440 int result = extension ?
1441 extension->version()->CompareTo(extension_sync_data.version()) : 0;
1442 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled());
1443 extension = NULL; // No longer safe to use.
1444
1445 if (extension_installed) {
[email protected]06f92562011-04-29 19:27:311446 // If the extension is already installed, check if it's outdated.
[email protected]90310d92011-04-17 07:35:041447 if (result < 0) {
1448 // Extension is outdated.
[email protected]5db9ada2012-04-11 13:48:201449 return false;
[email protected]b020dc12011-12-06 04:35:421450 }
[email protected]06f92562011-04-29 19:27:311451 } else {
[email protected]06f92562011-04-29 19:27:311452 // TODO(akalin): Replace silent update with a list of enabled
1453 // permissions.
[email protected]6cc7dbae2011-04-29 21:18:331454 const bool kInstallSilently = true;
[email protected]5db9ada2012-04-11 13:48:201455
1456 CHECK(type == syncable::EXTENSIONS || type == syncable::APPS);
1457 ExtensionFilter filter =
1458 (type == syncable::APPS) ? IsSyncableApp : IsSyncableExtension;
1459
[email protected]06f92562011-04-29 19:27:311460 if (!pending_extension_manager()->AddFromSync(
1461 id,
[email protected]3bdba0d2011-08-23 07:17:301462 extension_sync_data.update_url(),
[email protected]5db9ada2012-04-11 13:48:201463 filter,
[email protected]6cc7dbae2011-04-29 21:18:331464 kInstallSilently)) {
[email protected]06f92562011-04-29 19:27:311465 LOG(WARNING) << "Could not add pending extension for " << id;
[email protected]3bdba0d2011-08-23 07:17:301466 // This means that the extension is already pending installation, with a
1467 // non-INTERNAL location. Add to pending_sync_data, even though it will
1468 // never be removed (we'll never install a syncable version of the
1469 // extension), so that GetAllSyncData() continues to send it.
[email protected]06f92562011-04-29 19:27:311470 }
[email protected]3bdba0d2011-08-23 07:17:301471 // Track pending extensions so that we can return them in GetAllSyncData().
[email protected]5db9ada2012-04-11 13:48:201472 return false;
[email protected]90310d92011-04-17 07:35:041473 }
[email protected]5db9ada2012-04-11 13:48:201474
1475 return true;
[email protected]90310d92011-04-17 07:35:041476}
1477
[email protected]c3cfb012011-04-06 22:07:351478bool ExtensionService::IsIncognitoEnabled(
1479 const std::string& extension_id) const {
1480 // If this is an existing component extension we always allow it to
1481 // work in incognito mode.
[email protected]81b14cc2011-04-29 00:39:371482 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]c3cfb012011-04-06 22:07:351483 if (extension && extension->location() == Extension::COMPONENT)
[email protected]cb0ce1e022010-03-10 19:54:411484 return true;
1485
1486 // Check the prefs.
[email protected]c3cfb012011-04-06 22:07:351487 return extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]db7331a2010-02-25 22:10:501488}
[email protected]55a35692010-02-11 23:25:211489
[email protected]c3cfb012011-04-06 22:07:351490void ExtensionService::SetIsIncognitoEnabled(
1491 const std::string& extension_id, bool enabled) {
[email protected]81b14cc2011-04-29 00:39:371492 const Extension* extension = GetInstalledExtension(extension_id);
[email protected]c3cfb012011-04-06 22:07:351493 if (extension && extension->location() == Extension::COMPONENT) {
[email protected]b873cd92012-02-09 21:51:481494 // This shouldn't be called for component extensions unless they are
1495 // syncable.
1496 DCHECK(extension->IsSyncable());
1497
1498 // If we are here, make sure the we aren't trying to change the value.
1499 DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id));
1500
[email protected]c3cfb012011-04-06 22:07:351501 return;
1502 }
1503
[email protected]8c6c8c22011-03-09 12:52:341504 // Broadcast unloaded and loaded events to update browser state. Only bother
1505 // if the value changed and the extension is actually enabled, since there is
1506 // no UI otherwise.
[email protected]c3cfb012011-04-06 22:07:351507 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
[email protected]8c6c8c22011-03-09 12:52:341508 if (enabled == old_enabled)
1509 return;
1510
[email protected]c3cfb012011-04-06 22:07:351511 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
[email protected]81b14cc2011-04-29 00:39:371512
[email protected]ffbf3f12011-12-09 22:10:331513 bool extension_is_enabled = extensions_.Contains(extension_id);
[email protected]bd9892eb2011-11-11 19:41:341514
1515 // When we reload the extension the ID may be invalidated if we've passed it
1516 // by const ref everywhere. Make a copy to be safe.
1517 std::string id = extension_id;
[email protected]406b5a92011-11-08 11:58:261518 if (extension_is_enabled)
[email protected]ffbf3f12011-12-09 22:10:331519 ReloadExtension(id);
[email protected]3bdba0d2011-08-23 07:17:301520
[email protected]406b5a92011-11-08 11:58:261521 // Reloading the extension invalidates the |extension| pointer.
[email protected]bd9892eb2011-11-11 19:41:341522 extension = GetInstalledExtension(id);
[email protected]3bdba0d2011-08-23 07:17:301523 if (extension)
1524 SyncExtensionChangeIfNeeded(*extension);
[email protected]55a35692010-02-11 23:25:211525}
1526
[email protected]aa7599d2011-10-28 07:24:321527void ExtensionService::SetAppNotificationSetupDone(
1528 const std::string& extension_id,
[email protected]b2689a902011-12-01 00:41:091529 const std::string& oauth_client_id) {
[email protected]aa7599d2011-10-28 07:24:321530 const Extension* extension = GetInstalledExtension(extension_id);
1531 // This method is called when the user sets up app notifications.
1532 // So it is not expected to be called until the extension is installed.
1533 if (!extension) {
1534 NOTREACHED();
1535 return;
1536 }
[email protected]b2689a902011-12-01 00:41:091537 extension_prefs_->SetAppNotificationClientId(extension_id, oauth_client_id);
[email protected]aa7599d2011-10-28 07:24:321538 SyncExtensionChangeIfNeeded(*extension);
1539}
1540
1541void ExtensionService::SetAppNotificationDisabled(
1542 const std::string& extension_id,
1543 bool value) {
1544 const Extension* extension = GetInstalledExtension(extension_id);
1545 // This method is called when the user enables/disables app notifications.
1546 // So it is not expected to be called until the extension is installed.
1547 if (!extension) {
1548 NOTREACHED();
1549 return;
1550 }
[email protected]97e856b12011-12-14 00:21:131551 if (value)
1552 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsDisabled", 1);
1553 else
1554 UMA_HISTOGRAM_COUNTS("Apps.SetAppNotificationsEnabled", 1);
[email protected]aa7599d2011-10-28 07:24:321555 extension_prefs_->SetAppNotificationDisabled(extension_id, value);
1556 SyncExtensionChangeIfNeeded(*extension);
1557}
1558
[email protected]eaa7dd182010-12-14 11:09:001559bool ExtensionService::CanCrossIncognito(const Extension* extension) {
[email protected]2a8f24e2010-11-03 21:37:051560 // We allow the extension to see events and data from another profile iff it
1561 // uses "spanning" behavior and it has incognito access. "split" mode
1562 // extensions only see events for a matching profile.
[email protected]0c41298f2011-09-13 21:17:221563 CHECK(extension);
[email protected]c3cfb012011-04-06 22:07:351564 return IsIncognitoEnabled(extension->id()) &&
1565 !extension->incognito_split_mode();
[email protected]2a8f24e2010-11-03 21:37:051566}
1567
[email protected]5ef7b002011-05-12 23:16:201568bool ExtensionService::CanLoadInIncognito(const Extension* extension) const {
1569 if (extension->is_hosted_app())
1570 return true;
1571 // Packaged apps and regular extensions need to be enabled specifically for
1572 // incognito (and split mode should be set).
1573 return extension->incognito_split_mode() &&
1574 IsIncognitoEnabled(extension->id());
1575}
1576
[email protected]168389f2011-12-20 17:12:481577void ExtensionService::OnExtensionMoved(
1578 const std::string& moved_extension_id,
1579 const std::string& predecessor_extension_id,
1580 const std::string& successor_extension_id) {
[email protected]3569b502012-01-12 20:08:231581 extension_prefs_->extension_sorting()->OnExtensionMoved(
1582 moved_extension_id,
1583 predecessor_extension_id,
1584 successor_extension_id);
[email protected]168389f2011-12-20 17:12:481585
1586 const Extension* extension = GetInstalledExtension(moved_extension_id);
1587 if (extension)
1588 SyncExtensionChangeIfNeeded(*extension);
1589}
1590
[email protected]eaa7dd182010-12-14 11:09:001591bool ExtensionService::AllowFileAccess(const Extension* extension) {
[email protected]05c82182010-06-24 17:49:081592 return (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]334e04a2010-06-24 23:34:441593 switches::kDisableExtensionsFileAccessCheck) ||
[email protected]05c82182010-06-24 17:49:081594 extension_prefs_->AllowFileAccess(extension->id()));
1595}
1596
[email protected]eaa7dd182010-12-14 11:09:001597void ExtensionService::SetAllowFileAccess(const Extension* extension,
[email protected]3aff9ad2011-04-01 20:26:481598 bool allow) {
1599 // Reload to update browser state. Only bother if the value changed and the
1600 // extension is actually enabled, since there is no UI otherwise.
1601 bool old_allow = AllowFileAccess(extension);
1602 if (allow == old_allow)
1603 return;
1604
[email protected]05c82182010-06-24 17:49:081605 extension_prefs_->SetAllowFileAccess(extension->id(), allow);
[email protected]3aff9ad2011-04-01 20:26:481606
[email protected]84df8332011-12-06 18:22:461607 bool extension_is_enabled = extensions_.Contains(extension->id());
[email protected]3aff9ad2011-04-01 20:26:481608 if (extension_is_enabled)
1609 ReloadExtension(extension->id());
[email protected]05c82182010-06-24 17:49:081610}
1611
[email protected]8e4560b62011-01-14 10:09:141612// Some extensions will autoupdate themselves externally from Chrome. These
1613// are typically part of some larger client application package. To support
1614// these, the extension will register its location in the the preferences file
1615// (and also, on Windows, in the registry) and this code will periodically
1616// check that location for a .crx file, which it will then install locally if
1617// a new version is available.
1618// Errors are reported through ExtensionErrorReporter. Succcess is not
1619// reported.
[email protected]eaa7dd182010-12-14 11:09:001620void ExtensionService::CheckForExternalUpdates() {
[email protected]a29a517a2011-01-21 21:11:121621 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]8e4560b62011-01-14 10:09:141622
1623 // Note that this installation is intentionally silent (since it didn't
1624 // go through the front-end). Extensions that are registered in this
1625 // way are effectively considered 'pre-bundled', and so implicitly
1626 // trusted. In general, if something has HKLM or filesystem access,
1627 // they could install an extension manually themselves anyway.
[email protected]a29a517a2011-01-21 21:11:121628
[email protected]8e4560b62011-01-14 10:09:141629 // Ask each external extension provider to give us a call back for each
1630 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found.
1631 ProviderCollection::const_iterator i;
1632 for (i = external_extension_providers_.begin();
1633 i != external_extension_providers_.end(); ++i) {
1634 ExternalExtensionProviderInterface* provider = i->get();
1635 provider->VisitRegisteredExtension();
1636 }
1637
[email protected]50067e52011-10-20 23:17:071638 // Do any required work that we would have done after completion of all
1639 // providers.
1640 if (external_extension_providers_.empty()) {
1641 OnAllExternalProvidersReady();
1642 }
[email protected]9f1087e2009-06-15 17:29:321643}
1644
[email protected]50067e52011-10-20 23:17:071645void ExtensionService::OnExternalProviderReady(
1646 const ExternalExtensionProviderInterface* provider) {
[email protected]a29a517a2011-01-21 21:11:121647 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]50067e52011-10-20 23:17:071648 CHECK(provider->IsReady());
[email protected]a29a517a2011-01-21 21:11:121649
1650 // An external provider has finished loading. We only take action
[email protected]8e4560b62011-01-14 10:09:141651 // if all of them are finished. So we check them first.
[email protected]94fde232012-04-27 10:22:301652 if (AreAllExternalProvidersReady())
1653 OnAllExternalProvidersReady();
1654}
1655
1656bool ExtensionService::AreAllExternalProvidersReady() const {
[email protected]8e4560b62011-01-14 10:09:141657 ProviderCollection::const_iterator i;
1658 for (i = external_extension_providers_.begin();
1659 i != external_extension_providers_.end(); ++i) {
[email protected]94fde232012-04-27 10:22:301660 if (!i->get()->IsReady())
1661 return false;
[email protected]8e4560b62011-01-14 10:09:141662 }
[email protected]94fde232012-04-27 10:22:301663 return true;
[email protected]50067e52011-10-20 23:17:071664}
1665
1666void ExtensionService::OnAllExternalProvidersReady() {
1667 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]94fde232012-04-27 10:22:301668 base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime();
1669 UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed);
[email protected]50067e52011-10-20 23:17:071670
1671 // Install any pending extensions.
[email protected]94fde232012-04-27 10:22:301672 if (update_once_all_providers_are_ready_ && updater()) {
1673 update_once_all_providers_are_ready_ = false;
[email protected]8e4560b62011-01-14 10:09:141674 updater()->CheckNow();
1675 }
1676
1677 // Uninstall all the unclaimed extensions.
1678 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info(
1679 extension_prefs_->GetInstalledExtensionsInfo());
1680 for (size_t i = 0; i < extensions_info->size(); ++i) {
1681 ExtensionInfo* info = extensions_info->at(i).get();
1682 if (Extension::IsExternalLocation(info->extension_location))
1683 CheckExternalUninstall(info->extension_id);
1684 }
[email protected]e5af875f2011-10-10 21:09:141685 IdentifyAlertableExtensions();
[email protected]e5af875f2011-10-10 21:09:141686}
1687
1688void ExtensionService::IdentifyAlertableExtensions() {
1689 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1690
[email protected]07c9f2f42012-02-29 18:45:221691 // Build up the lists of extensions that require acknowledgment. If this is
1692 // the first time, grandfather extensions that would have caused
1693 // notification.
[email protected]a9aa5932012-01-25 08:27:401694 extension_global_error_.reset(new ExtensionGlobalError(this));
[email protected]e5af875f2011-10-10 21:09:141695
[email protected]a9aa5932012-01-25 08:27:401696 bool did_show_alert = false;
[email protected]07c9f2f42012-02-29 18:45:221697 if (PopulateExtensionGlobalError(extension_global_error_.get())) {
[email protected]e5af875f2011-10-10 21:09:141698 if (extension_prefs_->SetAlertSystemFirstRun()) {
[email protected]a9aa5932012-01-25 08:27:401699 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]d8748142012-05-16 21:13:431700 Browser* browser = browser::FindLastActiveWithProfile(profile_);
[email protected]a9aa5932012-01-25 08:27:401701 if (browser) {
1702 extension_global_error_->ShowBubbleView(browser);
1703 did_show_alert = true;
1704 }
[email protected]e5af875f2011-10-10 21:09:141705 } else {
1706 // First run. Just acknowledge all the extensions, silently, by
1707 // shortcutting the display of the UI and going straight to the
1708 // callback for pressing the Accept button.
[email protected]a9aa5932012-01-25 08:27:401709 HandleExtensionAlertAccept();
[email protected]e5af875f2011-10-10 21:09:141710 }
1711 }
[email protected]a9aa5932012-01-25 08:27:401712
1713 if (!did_show_alert)
1714 extension_global_error_.reset();
[email protected]e5af875f2011-10-10 21:09:141715}
1716
[email protected]07c9f2f42012-02-29 18:45:221717bool ExtensionService::PopulateExtensionGlobalError(
1718 ExtensionGlobalError* extension_global_error) {
1719 bool needs_alert = false;
1720 for (ExtensionSet::const_iterator iter = extensions_.begin();
1721 iter != extensions_.end(); ++iter) {
1722 const Extension* e = *iter;
1723 if (Extension::IsExternalLocation(e->location())) {
1724 if (!e->is_hosted_app()) {
1725 if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) {
1726 extension_global_error->AddExternalExtension(e->id());
1727 needs_alert = true;
1728 }
1729 }
1730 }
1731 if (extension_prefs_->IsExtensionBlacklisted(e->id())) {
1732 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
1733 extension_global_error->AddBlacklistedExtension(e->id());
1734 needs_alert = true;
1735 }
1736 }
1737 if (extension_prefs_->IsExtensionOrphaned(e->id())) {
1738 if (!extension_prefs_->IsOrphanedExtensionAcknowledged(e->id())) {
1739 extension_global_error->AddOrphanedExtension(e->id());
1740 needs_alert = true;
1741 }
1742 }
1743 }
1744 return needs_alert;
1745}
1746
[email protected]a9aa5932012-01-25 08:27:401747void ExtensionService::HandleExtensionAlertClosed() {
1748 extension_global_error_.reset();
[email protected]62433d32011-10-12 22:33:121749}
1750
[email protected]a9aa5932012-01-25 08:27:401751void ExtensionService::HandleExtensionAlertAccept() {
[email protected]e5af875f2011-10-10 21:09:141752 const ExtensionIdSet *extension_ids =
[email protected]a9aa5932012-01-25 08:27:401753 extension_global_error_->get_external_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141754 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1755 iter != extension_ids->end(); ++iter) {
[email protected]47fc70c2011-12-06 07:29:511756 AcknowledgeExternalExtension(*iter);
[email protected]e5af875f2011-10-10 21:09:141757 }
[email protected]a9aa5932012-01-25 08:27:401758 extension_ids = extension_global_error_->get_blacklisted_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141759 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1760 iter != extension_ids->end(); ++iter) {
1761 extension_prefs_->AcknowledgeBlacklistedExtension(*iter);
1762 }
[email protected]a9aa5932012-01-25 08:27:401763 extension_ids = extension_global_error_->get_orphaned_extension_ids();
[email protected]e5af875f2011-10-10 21:09:141764 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1765 iter != extension_ids->end(); ++iter) {
1766 extension_prefs_->AcknowledgeOrphanedExtension(*iter);
1767 }
1768}
1769
[email protected]47fc70c2011-12-06 07:29:511770void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1771 extension_prefs_->AcknowledgeExternalExtension(id);
1772}
1773
[email protected]a9aa5932012-01-25 08:27:401774void ExtensionService::HandleExtensionAlertDetails(Browser* browser) {
1775 DCHECK(browser);
1776 browser->ShowExtensionsTab();
[email protected]6c751e72010-11-23 10:11:101777}
1778
[email protected]a9f39a312010-12-23 22:14:271779void ExtensionService::UnloadExtension(
1780 const std::string& extension_id,
[email protected]814a7bf0f2011-08-13 05:30:591781 extension_misc::UnloadedExtensionReason reason) {
[email protected]27e469a2010-01-11 20:35:091782 // Make sure the extension gets deleted after we return from this function.
[email protected]9adb9692010-10-29 23:14:021783 scoped_refptr<const Extension> extension(
[email protected]8001df22011-04-28 19:59:471784 GetExtensionByIdInternal(extension_id, true, true, false));
[email protected]631cf822009-05-15 07:01:251785
[email protected]fa0c96732010-11-17 00:14:231786 // This method can be called via PostTask, so the extension may have been
1787 // unloaded by the time this runs.
[email protected]dd163fb02011-05-04 22:22:171788 if (!extension) {
1789 // In case the extension may have crashed/uninstalled. Allow the profile to
1790 // clean up its RequestContexts.
[email protected]31d8f5f22012-04-02 15:22:081791 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]fa0c96732010-11-17 00:14:231792 return;
[email protected]dd163fb02011-05-04 22:22:171793 }
[email protected]0c6da502009-08-14 22:32:391794
[email protected]1eb175082010-02-10 09:26:161795 // Keep information about the extension so that we can reload it later
1796 // even if it's not permanently installed.
1797 unloaded_extension_paths_[extension->id()] = extension->path();
1798
[email protected]f17dbd42010-08-16 23:21:101799 // Clean up if the extension is meant to be enabled after a reload.
1800 disabled_extension_paths_.erase(extension->id());
1801
[email protected]d7e9a862010-11-03 21:57:491802 // Clean up runtime data.
1803 extension_runtime_data_.erase(extension_id);
1804
[email protected]614d18c22012-04-26 16:59:221805if (disabled_extensions_.Contains(extension->id())) {
[email protected]a9f39a312010-12-23 22:14:271806 UnloadedExtensionInfo details(extension, reason);
1807 details.already_disabled = true;
[email protected]84df8332011-12-06 18:22:461808 disabled_extensions_.Remove(extension->id());
[email protected]ad50def52011-10-19 23:17:071809 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271810 chrome::NOTIFICATION_EXTENSION_UNLOADED,
[email protected]6c2381d2011-10-19 02:52:531811 content::Source<Profile>(profile_),
1812 content::Details<UnloadedExtensionInfo>(&details));
[email protected]dd163fb02011-05-04 22:22:171813 // Make sure the profile cleans up its RequestContexts when an already
1814 // disabled extension is unloaded (since they are also tracking the disabled
1815 // extensions).
[email protected]31d8f5f22012-04-02 15:22:081816 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
[email protected]0c6da502009-08-14 22:32:391817 return;
1818 }
1819
[email protected]84df8332011-12-06 18:22:461820// Remove the extension from our list.
1821 extensions_.Remove(extension->id());
[email protected]631cf822009-05-15 07:01:251822
[email protected]a9f39a312010-12-23 22:14:271823 NotifyExtensionUnloaded(extension.get(), reason);
[email protected]631cf822009-05-15 07:01:251824}
1825
[email protected]eaa7dd182010-12-14 11:09:001826void ExtensionService::UnloadAllExtensions() {
[email protected]c8d407e2011-04-28 21:27:171827 profile_->GetExtensionSpecialStoragePolicy()->
1828 RevokeRightsForAllExtensions();
1829
[email protected]84df8332011-12-06 18:22:461830 extensions_.Clear();
1831 disabled_extensions_.Clear();
1832 terminated_extensions_.Clear();
[email protected]d7e9a862010-11-03 21:57:491833 extension_runtime_data_.clear();
[email protected]cd500f72010-06-25 23:44:321834
[email protected]c6e4a3412009-06-24 15:45:291835 // TODO(erikkay) should there be a notification for this? We can't use
1836 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1837 // or uninstalled, and UnloadAll is just part of shutdown.
[email protected]9f1087e2009-06-15 17:29:321838}
1839
[email protected]eaa7dd182010-12-14 11:09:001840void ExtensionService::ReloadExtensions() {
[email protected]9f1087e2009-06-15 17:29:321841 UnloadAllExtensions();
[email protected]d8c8f25f2011-11-02 18:18:011842 component_loader_->LoadAll();
1843 extensions::InstalledLoader(this).LoadAllExtensions();
[email protected]9f1087e2009-06-15 17:29:321844}
1845
[email protected]eaa7dd182010-12-14 11:09:001846void ExtensionService::GarbageCollectExtensions() {
[email protected]614d18c22012-04-26 16:59:221847 if (extension_prefs_->pref_service()->ReadOnly())
1848 return;
1849
1850 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info(
1851 extension_prefs_->GetInstalledExtensionsInfo());
1852
1853 std::map<std::string, FilePath> extension_paths;
1854 for (size_t i = 0; i < info->size(); ++i)
1855 extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path;
1856
1857 if (!BrowserThread::PostTask(
1858 BrowserThread::FILE, FROM_HERE,
1859 base::Bind(
1860 &extension_file_util::GarbageCollectExtensions,
1861 install_directory_,
1862 extension_paths)))
1863 NOTREACHED();
[email protected]f6ccd652010-11-17 00:48:341864
1865 // Also garbage-collect themes. We check |profile_| to be
1866 // defensive; in the future, we may call GarbageCollectExtensions()
1867 // from somewhere other than Init() (e.g., in a timer).
1868 if (profile_) {
[email protected]18280372011-03-22 18:05:221869 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
[email protected]f6ccd652010-11-17 00:48:341870 }
[email protected]3cf4f0992009-02-03 23:00:301871}
1872
[email protected]fb82dcd2012-03-21 14:15:461873void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
[email protected]5db9ada2012-04-11 13:48:201874 if (app_sync_bundle_.HandlesApp(extension)) {
1875 app_sync_bundle_.SyncChangeIfNeeded(extension);
1876 } else if (extension_sync_bundle_.HandlesExtension(extension)) {
1877 extension_sync_bundle_.SyncChangeIfNeeded(extension);
[email protected]fb82dcd2012-03-21 14:15:461878 }
1879}
1880
[email protected]eaa7dd182010-12-14 11:09:001881void ExtensionService::OnLoadedInstalledExtensions() {
[email protected]93fd78f42009-07-10 16:43:171882 if (updater_.get()) {
1883 updater_->Start();
1884 }
[email protected]fa6a9102010-11-22 15:38:501885
1886 ready_ = true;
[email protected]ad50def52011-10-19 23:17:071887 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271888 chrome::NOTIFICATION_EXTENSIONS_READY,
[email protected]6c2381d2011-10-19 02:52:531889 content::Source<Profile>(profile_),
[email protected]ad50def52011-10-19 23:17:071890 content::NotificationService::NoDetails());
[email protected]e72e8eb82009-06-18 17:21:511891}
1892
[email protected]fcb58a862012-05-01 01:03:151893void ExtensionService::AddExtension(const Extension* extension) {
[email protected]ae09ca62009-08-21 19:46:461894 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:021895 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]9f1087e2009-06-15 17:29:321896
[email protected]c8d407e2011-04-28 21:27:171897 // TODO(jstritar): We may be able to get rid of this branch by overriding the
1898 // default extension state to DISABLED when the --disable-extensions flag
1899 // is set (http://crbug.com/29067).
1900 if (!extensions_enabled() &&
1901 !extension->is_theme() &&
1902 extension->location() != Extension::COMPONENT &&
1903 !Extension::IsExternalLocation(extension->location()))
[email protected]fcb58a862012-05-01 01:03:151904 return;
[email protected]c8d407e2011-04-28 21:27:171905
1906 SetBeingUpgraded(extension, false);
1907
[email protected]1eb175082010-02-10 09:26:161908 // The extension is now loaded, remove its data from unloaded extension map.
1909 unloaded_extension_paths_.erase(extension->id());
1910
[email protected]bb7f40952011-01-13 00:21:201911 // If a terminated extension is loaded, remove it from the terminated list.
1912 UntrackTerminatedExtension(extension->id());
1913
[email protected]f17dbd42010-08-16 23:21:101914 // If the extension was disabled for a reload, then enable it.
1915 if (disabled_extension_paths_.erase(extension->id()) > 0)
1916 EnableExtension(extension->id());
1917
[email protected]d728e002010-12-08 04:46:231918 // Check if the extension's privileges have changed and disable the
1919 // extension if necessary.
[email protected]902fd7b2011-07-27 18:42:311920 InitializePermissions(extension);
[email protected]0c6da502009-08-14 22:32:391921
[email protected]ad83ca242011-07-29 01:32:251922 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id());
[email protected]36429da2011-07-11 20:25:181923 if (disabled) {
[email protected]84df8332011-12-06 18:22:461924 disabled_extensions_.Insert(scoped_extension);
[email protected]3bdba0d2011-08-23 07:17:301925 SyncExtensionChangeIfNeeded(*extension);
[email protected]44d62b62012-04-11 00:06:031926 content::NotificationService::current()->Notify(
1927 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
1928 content::Source<Profile>(profile_),
1929 content::Details<const Extension>(extension));
[email protected]62f051c2012-03-29 17:04:441930
[email protected]44d62b62012-04-11 00:06:031931 if (extension_prefs_->GetDisableReason(extension->id()) ==
1932 Extension::DISABLE_PERMISSIONS_INCREASE) {
[email protected]62f051c2012-03-29 17:04:441933 extensions::AddExtensionDisabledError(this, extension);
1934 }
[email protected]fcb58a862012-05-01 01:03:151935 return;
[email protected]e72e8eb82009-06-18 17:21:511936 }
[email protected]aab98a52009-12-02 03:22:351937
[email protected]b873cd92012-02-09 21:51:481938 // All apps that are displayed in the launcher are ordered by their ordinals
1939 // so we must ensure they have valid ordinals.
1940 if (extension->ShouldDisplayInLauncher())
1941 extension_prefs_->extension_sorting()->EnsureValidOrdinals(extension->id());
1942
[email protected]84df8332011-12-06 18:22:461943 extensions_.Insert(scoped_extension);
[email protected]3bdba0d2011-08-23 07:17:301944 SyncExtensionChangeIfNeeded(*extension);
[email protected]c8d407e2011-04-28 21:27:171945 NotifyExtensionLoaded(extension);
[email protected]aab98a52009-12-02 03:22:351946}
1947
[email protected]902fd7b2011-07-27 18:42:311948void ExtensionService::InitializePermissions(const Extension* extension) {
1949 // If the extension has used the optional permissions API, it will have a
1950 // custom set of active permissions defined in the extension prefs. Here,
1951 // we update the extension's active permissions based on the prefs.
1952 scoped_refptr<ExtensionPermissionSet> active_permissions =
1953 extension_prefs()->GetActivePermissions(extension->id());
1954
1955 if (active_permissions.get()) {
1956 // We restrict the active permissions to be within the bounds defined in the
1957 // extension's manifest.
1958 // a) active permissions must be a subset of optional + default permissions
1959 // b) active permissions must contains all default permissions
1960 scoped_refptr<ExtensionPermissionSet> total_permissions =
1961 ExtensionPermissionSet::CreateUnion(
1962 extension->required_permission_set(),
1963 extension->optional_permission_set());
1964
1965 // Make sure the active permissions contain no more than optional + default.
1966 scoped_refptr<ExtensionPermissionSet> adjusted_active =
1967 ExtensionPermissionSet::CreateIntersection(
1968 total_permissions.get(), active_permissions.get());
1969
1970 // Make sure the active permissions contain the default permissions.
1971 adjusted_active = ExtensionPermissionSet::CreateUnion(
1972 extension->required_permission_set(), adjusted_active.get());
1973
[email protected]c333e792012-01-06 16:57:391974 extensions::PermissionsUpdater perms_updater(profile());
1975 perms_updater.UpdateActivePermissions(extension, adjusted_active);
[email protected]902fd7b2011-07-27 18:42:311976 }
1977
[email protected]8d888c12010-11-30 00:00:251978 // We keep track of all permissions the user has granted each extension.
1979 // This allows extensions to gracefully support backwards compatibility
1980 // by including unknown permissions in their manifests. When the user
1981 // installs the extension, only the recognized permissions are recorded.
1982 // When the unknown permissions become recognized (e.g., through browser
1983 // upgrade), we can prompt the user to accept these new permissions.
1984 // Extensions can also silently upgrade to less permissions, and then
1985 // silently upgrade to a version that adds these permissions back.
1986 //
1987 // For example, pretend that Chrome 10 includes a permission "omnibox"
1988 // for an API that adds suggestions to the omnibox. An extension can
1989 // maintain backwards compatibility while still having "omnibox" in the
1990 // manifest. If a user installs the extension on Chrome 9, the browser
1991 // will record the permissions it recognized, not including "omnibox."
1992 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1993 // will disable the extension and prompt the user to approve the increase
1994 // in privileges. The extension could then release a new version that
1995 // removes the "omnibox" permission. When the user upgrades, Chrome will
1996 // still remember that "omnibox" had been granted, so that if the
1997 // extension once again includes "omnibox" in an upgrade, the extension
1998 // can upgrade without requiring this user's approval.
1999 const Extension* old = GetExtensionByIdInternal(extension->id(),
[email protected]8001df22011-04-28 19:59:472000 true, true, false);
[email protected]8d888c12010-11-30 00:00:252001 bool is_extension_upgrade = old != NULL;
2002 bool is_privilege_increase = false;
[email protected]44d62b62012-04-11 00:06:032003 bool previously_disabled = false;
2004 Extension::DisableReason disable_reason =
2005 extension_prefs_->GetDisableReason(extension->id());
[email protected]8d888c12010-11-30 00:00:252006
[email protected]902fd7b2011-07-27 18:42:312007 // We only need to compare the granted permissions to the current permissions
2008 // if the extension is not allowed to silently increase its permissions.
2009 if (!extension->CanSilentlyIncreasePermissions()) {
[email protected]8d888c12010-11-30 00:00:252010 // Add all the recognized permissions if the granted permissions list
2011 // hasn't been initialized yet.
[email protected]902fd7b2011-07-27 18:42:312012 scoped_refptr<ExtensionPermissionSet> granted_permissions =
2013 extension_prefs_->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:522014 CHECK(granted_permissions.get());
[email protected]8d888c12010-11-30 00:00:252015
2016 // Here, we check if an extension's privileges have increased in a manner
2017 // that requires the user's approval. This could occur because the browser
2018 // upgraded and recognized additional privileges, or an extension upgrades
2019 // to a version that requires additional privileges.
[email protected]0d3e4a22011-06-23 19:02:522020 is_privilege_increase =
[email protected]902fd7b2011-07-27 18:42:312021 granted_permissions->HasLessPrivilegesThan(
2022 extension->GetActivePermissions());
[email protected]8d888c12010-11-30 00:00:252023 }
2024
2025 if (is_extension_upgrade) {
[email protected]66e26872010-12-03 20:07:252026 // Other than for unpacked extensions, CrxInstaller should have guaranteed
2027 // that we aren't downgrading.
2028 if (extension->location() != Extension::LOAD)
[email protected]614d18c22012-04-26 16:59:222029 CHECK(extension->version()->CompareTo(*(old->version())) >= 0);
[email protected]8d888c12010-11-30 00:00:252030
2031 // Extensions get upgraded if the privileges are allowed to increase or
2032 // the privileges haven't increased.
2033 if (!is_privilege_increase) {
2034 SetBeingUpgraded(old, true);
2035 SetBeingUpgraded(extension, true);
2036 }
2037
[email protected]44d62b62012-04-11 00:06:032038 // If the extension was already disabled, suppress any alerts for becoming
2039 // disabled on permissions increase.
2040 previously_disabled = extension_prefs_->IsExtensionDisabled(old->id());
2041 if (previously_disabled) {
2042 Extension::DisableReason reason = extension_prefs_->GetDisableReason(
2043 old->id());
2044 if (reason == Extension::DISABLE_UNKNOWN) {
2045 // Initialize the reason for legacy disabled extensions from whether the
2046 // extension already exceeded granted permissions.
2047 if (extension_prefs_->DidExtensionEscalatePermissions(old->id()))
2048 disable_reason = Extension::DISABLE_PERMISSIONS_INCREASE;
2049 else
2050 disable_reason = Extension::DISABLE_USER_ACTION;
2051 }
2052 } else {
2053 disable_reason = Extension::DISABLE_PERMISSIONS_INCREASE;
2054 }
2055
[email protected]8d888c12010-11-30 00:00:252056 // To upgrade an extension in place, unload the old one and
2057 // then load the new one.
[email protected]814a7bf0f2011-08-13 05:30:592058 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE);
[email protected]8d888c12010-11-30 00:00:252059 old = NULL;
2060 }
2061
2062 // Extension has changed permissions significantly. Disable it. A
2063 // notification should be sent by the caller.
2064 if (is_privilege_increase) {
[email protected]fe2dd7742011-04-19 22:52:492065 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
2066 RecordPermissionMessagesHistogram(
2067 extension, "Extensions.Permissions_AutoDisable");
2068 }
[email protected]b3317ad2011-04-28 23:46:002069 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
[email protected]8d888c12010-11-30 00:00:252070 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
[email protected]44d62b62012-04-11 00:06:032071 extension_prefs_->SetDisableReason(extension->id(), disable_reason);
[email protected]8d888c12010-11-30 00:00:252072 }
2073}
2074
[email protected]eaa7dd182010-12-14 11:09:002075void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
[email protected]c8865962009-12-16 07:47:392076 std::set<std::string> extension_ids;
[email protected]84df8332011-12-06 18:22:462077 for (ExtensionSet::const_iterator iter = extensions_.begin();
2078 iter != extensions_.end(); ++iter) {
2079 const Extension* extension = *iter;
2080 if (!extension->is_theme() && extension->location() != Extension::COMPONENT)
2081 extension_ids.insert(extension->id());
[email protected]aab98a52009-12-02 03:22:352082 }
2083
2084 child_process_logging::SetActiveExtensions(extension_ids);
[email protected]6014d672008-12-05 00:38:252085}
2086
[email protected]8266d662011-07-12 21:53:262087void ExtensionService::OnExtensionInstalled(
[email protected]36a5c4c2011-12-14 16:34:502088 const Extension* extension,
2089 bool from_webstore,
2090 const StringOrdinal& page_ordinal) {
[email protected]a29a517a2011-01-21 21:11:122091 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]a8af9fdb2010-10-28 21:52:202092
[email protected]4416c5a2010-06-26 01:28:572093 // Ensure extension is deleted unless we transfer ownership.
[email protected]9adb9692010-10-29 23:14:022094 scoped_refptr<const Extension> scoped_extension(extension);
[email protected]c3cfb012011-04-06 22:07:352095 const std::string& id = extension->id();
[email protected]8a87a5332011-08-11 17:54:592096 // Extensions installed by policy can't be disabled. So even if a previous
2097 // installation disabled the extension, make sure it is now enabled.
2098 bool initial_enable =
2099 !extension_prefs_->IsExtensionDisabled(id) ||
[email protected]65187152012-06-02 13:14:142100 system_->management_policy()->MustRemainEnabled(extension, NULL);
[email protected]b2907fd2011-03-25 16:43:372101 PendingExtensionInfo pending_extension_info;
[email protected]c3cfb012011-04-06 22:07:352102 if (pending_extension_manager()->GetById(id, &pending_extension_info)) {
2103 pending_extension_manager()->Remove(id);
[email protected]8ef78fd2010-08-19 17:14:322104
[email protected]483d1ff2011-03-03 17:12:022105 if (!pending_extension_info.ShouldAllowInstall(*extension)) {
[email protected]4416c5a2010-06-26 01:28:572106 LOG(WARNING)
[email protected]ae6cb3022011-04-04 20:11:542107 << "ShouldAllowInstall() returned false for "
[email protected]c3cfb012011-04-06 22:07:352108 << id << " of type " << extension->GetType()
[email protected]7fa19f82010-12-21 19:40:082109 << " and update URL " << extension->update_url().spec()
2110 << "; not installing";
[email protected]ae6cb3022011-04-04 20:11:542111
[email protected]ad50def52011-10-19 23:17:072112 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272113 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED,
[email protected]6c2381d2011-10-19 02:52:532114 content::Source<Profile>(profile_),
2115 content::Details<const Extension>(extension));
[email protected]ae6cb3022011-04-04 20:11:542116
[email protected]4416c5a2010-06-26 01:28:572117 // Delete the extension directory since we're not going to
2118 // load it.
[email protected]14908b72011-04-20 06:54:362119 if (!BrowserThread::PostTask(
2120 BrowserThread::FILE, FROM_HERE,
[email protected]53612e82011-10-18 18:00:362121 base::Bind(&extension_file_util::DeleteFile,
2122 extension->path(), true)))
[email protected]14908b72011-04-20 06:54:362123 NOTREACHED();
[email protected]4416c5a2010-06-26 01:28:572124 return;
2125 }
[email protected]4416c5a2010-06-26 01:28:572126 } else {
[email protected]c3cfb012011-04-06 22:07:352127 // We explicitly want to re-enable an uninstalled external
2128 // extension; if we're here, that means the user is manually
2129 // installing the extension.
[email protected]6cc7dbae2011-04-29 21:18:332130 if (IsExternalExtensionUninstalled(id)) {
2131 initial_enable = true;
2132 }
[email protected]aa142702010-03-26 01:26:332133 }
2134
[email protected]07533022011-06-27 20:42:552135 // Do not record the install histograms for upgrades.
2136 if (!GetExtensionByIdInternal(extension->id(), true, true, false)) {
2137 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
2138 extension->GetType(), 100);
2139 RecordPermissionMessagesHistogram(
2140 extension, "Extensions.Permissions_Install");
2141 }
2142
[email protected]a39921b42012-02-28 03:42:542143 // Certain extension locations are specific enough that we can
2144 // auto-acknowledge any extension that came from one of them.
2145 if (extension->location() == Extension::EXTERNAL_POLICY_DOWNLOAD) {
2146 AcknowledgeExternalExtension(extension->id());
2147 }
2148
[email protected]4416c5a2010-06-26 01:28:572149 extension_prefs_->OnExtensionInstalled(
[email protected]8266d662011-07-12 21:53:262150 extension,
2151 initial_enable ? Extension::ENABLED : Extension::DISABLED,
[email protected]cc829cf2011-08-22 21:01:352152 from_webstore,
[email protected]36a5c4c2011-12-14 16:34:502153 page_ordinal);
[email protected]25b34332009-06-05 21:53:192154
[email protected]cdfca9702011-08-08 16:07:012155 // Unpacked extensions default to allowing file access, but if that has been
2156 // overridden, don't reset the value.
[email protected]b6e64fd2011-08-09 19:49:192157 if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) &&
[email protected]cdfca9702011-08-08 16:07:012158 !extension_prefs_->HasAllowFileAccessSetting(id)) {
2159 extension_prefs_->SetAllowFileAccess(id, true);
2160 }
2161
[email protected]fcb58a862012-05-01 01:03:152162 content::NotificationService::current()->Notify(
2163 chrome::NOTIFICATION_EXTENSION_INSTALLED,
2164 content::Source<Profile>(profile_),
2165 content::Details<const Extension>(extension));
2166
[email protected]49cd1572011-02-08 21:38:452167 // Transfer ownership of |extension| to AddExtension.
[email protected]fcb58a862012-05-01 01:03:152168 AddExtension(scoped_extension);
[email protected]4a190632009-05-09 01:07:422169}
2170
[email protected]eaa7dd182010-12-14 11:09:002171const Extension* ExtensionService::GetExtensionByIdInternal(
[email protected]8001df22011-04-28 19:59:472172 const std::string& id, bool include_enabled, bool include_disabled,
2173 bool include_terminated) const {
[email protected]e957fe52009-06-23 16:51:052174 std::string lowercase_id = StringToLowerASCII(id);
[email protected]0c6da502009-08-14 22:32:392175 if (include_enabled) {
[email protected]84df8332011-12-06 18:22:462176 const Extension* extension = extensions_.GetByID(lowercase_id);
2177 if (extension)
2178 return extension;
[email protected]0c6da502009-08-14 22:32:392179 }
2180 if (include_disabled) {
[email protected]84df8332011-12-06 18:22:462181 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
2182 if (extension)
2183 return extension;
[email protected]ce5c4502009-05-06 16:46:112184 }
[email protected]8001df22011-04-28 19:59:472185 if (include_terminated) {
[email protected]84df8332011-12-06 18:22:462186 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
2187 if (extension)
2188 return extension;
[email protected]8001df22011-04-28 19:59:472189 }
[email protected]ce5c4502009-05-06 16:46:112190 return NULL;
2191}
2192
[email protected]bb7f40952011-01-13 00:21:202193void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
[email protected]84df8332011-12-06 18:22:462194 if (!terminated_extensions_.Contains(extension->id()))
2195 terminated_extensions_.Insert(make_scoped_refptr(extension));
[email protected]fa2416f2011-05-03 08:41:202196
[email protected]b3f7fe22011-11-11 19:27:562197 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE);
[email protected]bb7f40952011-01-13 00:21:202198}
2199
2200void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
[email protected]fa2416f2011-05-03 08:41:202201 std::string lowercase_id = StringToLowerASCII(id);
[email protected]84df8332011-12-06 18:22:462202 terminated_extensions_.Remove(lowercase_id);
[email protected]bb7f40952011-01-13 00:21:202203}
2204
[email protected]0dfe05c2011-02-23 23:03:362205const Extension* ExtensionService::GetTerminatedExtension(
[email protected]8001df22011-04-28 19:59:472206 const std::string& id) const {
2207 return GetExtensionByIdInternal(id, false, false, true);
2208}
2209
2210const Extension* ExtensionService::GetInstalledExtension(
2211 const std::string& id) const {
2212 return GetExtensionByIdInternal(id, true, true, true);
[email protected]0dfe05c2011-02-23 23:03:362213}
2214
[email protected]eaa7dd182010-12-14 11:09:002215bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
[email protected]615d88f2011-12-13 01:47:442216 // Allow bindings for all packaged extensions and component hosted apps.
2217 const Extension* extension = extensions_.GetExtensionOrAppByURL(
2218 ExtensionURLInfo(url));
2219 return extension && (!extension->is_hosted_app() ||
2220 extension->location() == Extension::COMPONENT);
[email protected]6d2e60bd2010-06-03 22:37:392221}
2222
[email protected]eaa7dd182010-12-14 11:09:002223const SkBitmap& ExtensionService::GetOmniboxIcon(
[email protected]b671760b2010-07-15 21:13:472224 const std::string& extension_id) {
2225 return omnibox_icon_manager_.GetIcon(extension_id);
2226}
2227
[email protected]eaa7dd182010-12-14 11:09:002228const SkBitmap& ExtensionService::GetOmniboxPopupIcon(
[email protected]29d0d4ac2010-09-08 21:10:312229 const std::string& extension_id) {
2230 return omnibox_popup_icon_manager_.GetIcon(extension_id);
2231}
2232
[email protected]9060d8b02012-01-13 02:14:302233bool ExtensionService::OnExternalExtensionFileFound(
[email protected]8ef78fd2010-08-19 17:14:322234 const std::string& id,
[email protected]8e4560b62011-01-14 10:09:142235 const Version* version,
[email protected]8ef78fd2010-08-19 17:14:322236 const FilePath& path,
[email protected]1bf73cc2011-10-26 22:38:312237 Extension::Location location,
[email protected]47fc70c2011-12-06 07:29:512238 int creation_flags,
2239 bool mark_acknowledged) {
[email protected]ab22ba42011-01-14 16:36:382240 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2241 CHECK(Extension::IdIsValid(id));
[email protected]79c833b52011-04-05 18:31:012242 if (extension_prefs_->IsExternalExtensionUninstalled(id))
[email protected]9060d8b02012-01-13 02:14:302243 return false;
[email protected]a8af9fdb2010-10-28 21:52:202244
[email protected]8e4560b62011-01-14 10:09:142245 DCHECK(version);
2246
[email protected]7577a5c52009-07-30 06:21:582247 // Before even bothering to unpack, check and see if we already have this
[email protected]4c967932009-07-31 01:15:492248 // version. This is important because these extensions are going to get
[email protected]7577a5c52009-07-30 06:21:582249 // installed on every startup.
[email protected]9adb9692010-10-29 23:14:022250 const Extension* existing = GetExtensionById(id, true);
[email protected]7577a5c52009-07-30 06:21:582251 if (existing) {
[email protected]8e4560b62011-01-14 10:09:142252 switch (existing->version()->CompareTo(*version)) {
[email protected]7577a5c52009-07-30 06:21:582253 case -1: // existing version is older, we should upgrade
2254 break;
2255 case 0: // existing version is same, do nothing
[email protected]9060d8b02012-01-13 02:14:302256 return false;
[email protected]7577a5c52009-07-30 06:21:582257 case 1: // existing version is newer, uh-oh
2258 LOG(WARNING) << "Found external version of extension " << id
2259 << "that is older than current version. Current version "
2260 << "is: " << existing->VersionString() << ". New version "
[email protected]16d900042012-01-04 21:24:322261 << "is: " << version->GetString()
2262 << ". Keeping current version.";
[email protected]9060d8b02012-01-13 02:14:302263 return false;
[email protected]7577a5c52009-07-30 06:21:582264 }
2265 }
2266
[email protected]9060d8b02012-01-13 02:14:302267 // If the extension is already pending, don't start an install.
[email protected]e3987852012-05-04 10:06:302268 if (!pending_extension_manager()->AddFromExternalFile(
2269 id, location, *version)) {
[email protected]9060d8b02012-01-13 02:14:302270 return false;
[email protected]e3987852012-05-04 10:06:302271 }
[email protected]9c635f22010-12-02 09:36:362272
[email protected]14908b72011-04-20 06:54:362273 // no client (silent install)
[email protected]d8c8f25f2011-11-02 18:18:012274 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, NULL));
[email protected]6dfbbf82010-03-12 23:09:162275 installer->set_install_source(location);
2276 installer->set_expected_id(id);
[email protected]cb0e50312011-05-09 15:03:072277 installer->set_expected_version(*version);
2278 installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
[email protected]1bf73cc2011-10-26 22:38:312279 installer->set_creation_flags(creation_flags);
[email protected]6dfbbf82010-03-12 23:09:162280 installer->InstallCrx(path);
[email protected]47fc70c2011-12-06 07:29:512281
2282 // Depending on the source, a new external extension might not need a user
2283 // notification on installation. For such extensions, mark them acknowledged
2284 // now to suppress the notification.
2285 if (mark_acknowledged)
2286 AcknowledgeExternalExtension(id);
[email protected]9060d8b02012-01-13 02:14:302287
2288 return true;
[email protected]7577a5c52009-07-30 06:21:582289}
2290
[email protected]eaa7dd182010-12-14 11:09:002291void ExtensionService::ReportExtensionLoadError(
[email protected]d11c8e92009-10-20 23:26:402292 const FilePath& extension_path,
2293 const std::string &error,
[email protected]d11c8e92009-10-20 23:26:402294 bool be_noisy) {
[email protected]d8c8f25f2011-11-02 18:18:012295 content::NotificationService::current()->Notify(
2296 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
2297 content::Source<Profile>(profile_),
2298 content::Details<const std::string>(&error));
[email protected]d11c8e92009-10-20 23:26:402299
[email protected]8a205c02011-02-04 20:41:332300 std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName());
[email protected]fc670822011-12-17 09:33:492301 string16 message = ASCIIToUTF16(base::StringPrintf(
[email protected]18d4b6c2010-09-21 03:21:042302 "Could not load extension from '%s'. %s",
[email protected]fc670822011-12-17 09:33:492303 path_str.c_str(), error.c_str()));
[email protected]d11c8e92009-10-20 23:26:402304 ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
2305}
2306
[email protected]eaa7dd182010-12-14 11:09:002307void ExtensionService::DidCreateRenderViewForBackgroundPage(
[email protected]406027c02010-09-27 08:03:182308 ExtensionHost* host) {
2309 OrphanedDevTools::iterator iter =
[email protected]2d2f6cfc2011-05-06 21:09:332310 orphaned_dev_tools_.find(host->extension_id());
[email protected]406027c02010-09-27 08:03:182311 if (iter == orphaned_dev_tools_.end())
2312 return;
2313
[email protected]0e12d7d2011-12-01 16:21:442314 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
2315 host->render_view_host());
2316 content::DevToolsManager::GetInstance()->AttachClientHost(iter->second,
2317 agent);
[email protected]406027c02010-09-27 08:03:182318 orphaned_dev_tools_.erase(iter);
2319}
2320
[email protected]432115822011-07-10 15:52:272321void ExtensionService::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:532322 const content::NotificationSource& source,
2323 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:272324 switch (type) {
2325 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
[email protected]6c2381d2011-10-19 02:52:532326 if (profile_ !=
2327 content::Source<Profile>(source).ptr()->GetOriginalProfile()) {
[email protected]bc535ee52010-08-31 18:40:322328 break;
[email protected]6c2381d2011-10-19 02:52:532329 }
[email protected]a4ed6282009-12-14 20:51:162330
[email protected]6c2381d2011-10-19 02:52:532331 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
[email protected]f128af42010-08-05 18:05:262332
[email protected]fa2416f2011-05-03 08:41:202333 // Mark the extension as terminated and Unload it. We want it to
2334 // be in a consistent state: either fully working or not loaded
2335 // at all, but never half-crashed. We do it in a PostTask so
2336 // that other handlers of this notification will still have
2337 // access to the Extension and ExtensionHost.
[email protected]14908b72011-04-20 06:54:362338 MessageLoop::current()->PostTask(
2339 FROM_HERE,
[email protected]53612e82011-10-18 18:00:362340 base::Bind(
[email protected]fa2416f2011-05-03 08:41:202341 &ExtensionService::TrackTerminatedExtension,
[email protected]d8c8f25f2011-11-02 18:18:012342 AsWeakPtr(),
[email protected]fa2416f2011-05-03 08:41:202343 host->extension()));
[email protected]31f77262009-12-02 20:48:532344 break;
2345 }
[email protected]432115822011-07-10 15:52:272346 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
[email protected]f3b1a082011-11-18 00:34:302347 content::RenderProcessHost* process =
2348 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192349 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302350 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192351 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2352 break;
2353
[email protected]15397b42012-05-16 23:56:062354 // Extensions need to know the channel for API restrictions.
2355 process->Send(new ExtensionMsg_SetChannel(
2356 chrome::VersionInfo::GetChannel()));
2357
[email protected]77a6970c2011-04-23 16:58:562358 // Valid extension function names, used to setup bindings in renderer.
2359 std::vector<std::string> function_names;
2360 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
2361 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
[email protected]31f77262009-12-02 20:48:532362
[email protected]77a6970c2011-04-23 16:58:562363 // Scripting whitelist. This is modified by tests and must be communicated
2364 // to renderers.
2365 process->Send(new ExtensionMsg_SetScriptingWhitelist(
2366 *Extension::GetScriptingWhitelist()));
2367
2368 // Loaded extensions.
[email protected]9776e82e2011-11-15 02:17:532369 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
[email protected]84df8332011-12-06 18:22:462370 for (ExtensionSet::const_iterator iter = extensions_.begin();
2371 iter != extensions_.end(); ++iter) {
[email protected]19647262011-12-16 09:57:492372 // Renderers don't need to know about themes.
2373 if (!(*iter)->is_theme())
2374 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter));
[email protected]77a6970c2011-04-23 16:58:562375 }
[email protected]9776e82e2011-11-15 02:17:532376 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
[email protected]77a6970c2011-04-23 16:58:562377 break;
2378 }
[email protected]432115822011-07-10 15:52:272379 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
[email protected]f3b1a082011-11-18 00:34:302380 content::RenderProcessHost* process =
2381 content::Source<content::RenderProcessHost>(source).ptr();
[email protected]fc30ef082011-08-18 04:07:192382 Profile* host_profile =
[email protected]f3b1a082011-11-18 00:34:302383 Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]fc30ef082011-08-18 04:07:192384 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2385 break;
2386
[email protected]f3b1a082011-11-18 00:34:302387 installed_app_hosts_.erase(process->GetID());
[email protected]6f371442011-11-09 06:45:462388
[email protected]6bc04fd82011-12-04 02:29:352389 process_map_.RemoveAllFromProcess(process->GetID());
[email protected]6f371442011-11-09 06:45:462390 BrowserThread::PostTask(
2391 BrowserThread::IO, FROM_HERE,
2392 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess,
[email protected]31d8f5f22012-04-02 15:22:082393 system_->info_map(),
[email protected]f3b1a082011-11-18 00:34:302394 process->GetID()));
[email protected]da5683db2011-04-23 17:12:212395 break;
2396 }
[email protected]432115822011-07-10 15:52:272397 case chrome::NOTIFICATION_PREF_CHANGED: {
[email protected]6c2381d2011-10-19 02:52:532398 std::string* pref_name = content::Details<std::string>(details).ptr();
[email protected]6c751e72010-11-23 10:11:102399 if (*pref_name == prefs::kExtensionInstallAllowList ||
2400 *pref_name == prefs::kExtensionInstallDenyList) {
2401 CheckAdminBlacklist();
[email protected]6c751e72010-11-23 10:11:102402 } else {
2403 NOTREACHED() << "Unexpected preference name.";
2404 }
[email protected]aa96d3a2010-08-21 08:45:252405 break;
2406 }
[email protected]d91268022011-08-26 13:17:372407 case chrome::NOTIFICATION_IMPORT_FINISHED: {
[email protected]cf593af2011-12-30 05:44:392408 InitAfterImport();
[email protected]d91268022011-08-26 13:17:372409 break;
2410 }
[email protected]aa96d3a2010-08-21 08:45:252411
[email protected]4814b512009-11-07 00:12:292412 default:
2413 NOTREACHED() << "Unexpected notification type.";
2414 }
2415}
2416
[email protected]eaa7dd182010-12-14 11:09:002417bool ExtensionService::HasApps() const {
[email protected]ec5b50d2010-10-09 16:35:182418 return !GetAppIds().empty();
2419}
[email protected]377011d2010-07-20 04:18:502420
[email protected]eaa7dd182010-12-14 11:09:002421ExtensionIdSet ExtensionService::GetAppIds() const {
[email protected]ec5b50d2010-10-09 16:35:182422 ExtensionIdSet result;
[email protected]84df8332011-12-06 18:22:462423 for (ExtensionSet::const_iterator it = extensions_.begin();
[email protected]377011d2010-07-20 04:18:502424 it != extensions_.end(); ++it) {
[email protected]ec5b50d2010-10-09 16:35:182425 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
2426 result.insert((*it)->id());
[email protected]377011d2010-07-20 04:18:502427 }
2428
[email protected]ec5b50d2010-10-09 16:35:182429 return result;
[email protected]377011d2010-07-20 04:18:502430}
[email protected]d7e9a862010-11-03 21:57:492431
[email protected]eaa7dd182010-12-14 11:09:002432bool ExtensionService::IsBackgroundPageReady(const Extension* extension) {
[email protected]4762e7902012-03-28 23:34:042433 return (!extension->has_persistent_background_page() ||
[email protected]d7e9a862010-11-03 21:57:492434 extension_runtime_data_[extension->id()].background_page_ready);
2435}
2436
[email protected]eaa7dd182010-12-14 11:09:002437void ExtensionService::SetBackgroundPageReady(const Extension* extension) {
[email protected]a03d4448f2012-01-10 23:25:282438 DCHECK(extension->has_background_page());
[email protected]d7e9a862010-11-03 21:57:492439 extension_runtime_data_[extension->id()].background_page_ready = true;
[email protected]ad50def52011-10-19 23:17:072440 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272441 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
[email protected]6c2381d2011-10-19 02:52:532442 content::Source<const Extension>(extension),
[email protected]ad50def52011-10-19 23:17:072443 content::NotificationService::NoDetails());
[email protected]d7e9a862010-11-03 21:57:492444}
2445
[email protected]eaa7dd182010-12-14 11:09:002446bool ExtensionService::IsBeingUpgraded(const Extension* extension) {
[email protected]d7e9a862010-11-03 21:57:492447 return extension_runtime_data_[extension->id()].being_upgraded;
2448}
2449
[email protected]eaa7dd182010-12-14 11:09:002450void ExtensionService::SetBeingUpgraded(const Extension* extension,
[email protected]d7e9a862010-11-03 21:57:492451 bool value) {
2452 extension_runtime_data_[extension->id()].being_upgraded = value;
2453}
[email protected]1bead0712010-11-27 17:41:532454
[email protected]39a5b532011-10-22 01:47:072455bool ExtensionService::HasUsedWebRequest(const Extension* extension) {
2456 return extension_runtime_data_[extension->id()].has_used_webrequest;
2457}
2458
2459void ExtensionService::SetHasUsedWebRequest(const Extension* extension,
2460 bool value) {
2461 extension_runtime_data_[extension->id()].has_used_webrequest = value;
2462}
2463
[email protected]45644f62011-11-23 00:58:232464base::PropertyBag* ExtensionService::GetPropertyBag(
2465 const Extension* extension) {
[email protected]1bead0712010-11-27 17:41:532466 return &extension_runtime_data_[extension->id()].property_bag;
2467}
[email protected]cebc3dc2011-04-18 17:15:002468
2469void ExtensionService::RegisterNaClModule(const GURL& url,
2470 const std::string& mime_type) {
2471 NaClModuleInfo info;
2472 info.url = url;
2473 info.mime_type = mime_type;
2474
2475 DCHECK(FindNaClModule(url) == nacl_module_list_.end());
2476 nacl_module_list_.push_front(info);
2477}
2478
2479void ExtensionService::UnregisterNaClModule(const GURL& url) {
2480 NaClModuleInfoList::iterator iter = FindNaClModule(url);
2481 DCHECK(iter != nacl_module_list_.end());
2482 nacl_module_list_.erase(iter);
2483}
2484
[email protected]ed0ba002011-05-26 16:55:132485void ExtensionService::UpdatePluginListWithNaClModules() {
[email protected]300c0ea2011-07-15 23:04:332486 // An extension has been added which has a nacl_module component, which means
2487 // there is a MIME type that module wants to handle, so we need to add that
2488 // MIME type to plugins which handle NaCl modules in order to allow the
2489 // individual modules to handle these types.
[email protected]1e127022011-11-29 21:11:472490 FilePath path;
2491 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &path))
2492 return;
2493 const content::PepperPluginInfo* pepper_info =
2494 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(path);
2495 if (!pepper_info)
2496 return;
[email protected]300c0ea2011-07-15 23:04:332497
[email protected]1e127022011-11-29 21:11:472498 std::vector<webkit::WebPluginMimeType>::const_iterator mime_iter;
2499 // Check each MIME type the plugins handle for the NaCl MIME type.
2500 for (mime_iter = pepper_info->mime_types.begin();
2501 mime_iter != pepper_info->mime_types.end(); ++mime_iter) {
2502 if (mime_iter->mime_type == kNaClPluginMimeType) {
2503 // This plugin handles "application/x-nacl".
[email protected]300c0ea2011-07-15 23:04:332504
[email protected]1e127022011-11-29 21:11:472505 PluginService::GetInstance()->
2506 UnregisterInternalPlugin(pepper_info->path);
[email protected]300c0ea2011-07-15 23:04:332507
[email protected]1e127022011-11-29 21:11:472508 webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo();
[email protected]300c0ea2011-07-15 23:04:332509
[email protected]1e127022011-11-29 21:11:472510 for (ExtensionService::NaClModuleInfoList::const_iterator iter =
2511 nacl_module_list_.begin();
2512 iter != nacl_module_list_.end(); ++iter) {
2513 // Add the MIME type specified in the extension to this NaCl plugin,
2514 // With an extra "nacl" argument to specify the location of the NaCl
2515 // manifest file.
2516 webkit::WebPluginMimeType mime_type_info;
2517 mime_type_info.mime_type = iter->mime_type;
2518 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl"));
2519 mime_type_info.additional_param_values.push_back(
2520 UTF8ToUTF16(iter->url.spec()));
2521 info.mime_types.push_back(mime_type_info);
[email protected]300c0ea2011-07-15 23:04:332522 }
[email protected]1e127022011-11-29 21:11:472523
2524 PluginService::GetInstance()->RefreshPlugins();
[email protected]c6f3dea2012-01-14 02:23:112525 PluginService::GetInstance()->RegisterInternalPlugin(info, true);
[email protected]1e127022011-11-29 21:11:472526 // This plugin has been modified, no need to check the rest of its
2527 // types, but continue checking other plugins.
2528 break;
[email protected]ed0ba002011-05-26 16:55:132529 }
2530 }
[email protected]ed0ba002011-05-26 16:55:132531}
2532
[email protected]cebc3dc2011-04-18 17:15:002533ExtensionService::NaClModuleInfoList::iterator
2534 ExtensionService::FindNaClModule(const GURL& url) {
2535 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2536 iter != nacl_module_list_.end(); ++iter) {
2537 if (iter->url == url)
2538 return iter;
2539 }
2540 return nacl_module_list_.end();
2541}
[email protected]9de83282011-12-12 11:06:372542
[email protected]58edca52012-02-16 21:51:382543extensions::APIResourceController*
2544ExtensionService::api_resource_controller() {
[email protected]2404a28272012-05-30 02:31:142545 // TODO(miket): Find a better place for this thing to live. Like every other
2546 // piece of baggage on ExtensionService, it's scoped along with a Profile.
2547
2548 // To coexist with certain unit tests that don't have a work-thread message
[email protected]e1fae1c2011-12-13 22:17:172549 // loop available at ExtensionService shutdown, we lazy-initialize this
[email protected]58edca52012-02-16 21:51:382550 // object so that those cases neither create nor destroy an
2551 // APIResourceController.
[email protected]2404a28272012-05-30 02:31:142552 if (!api_resource_controller_.get()) {
2553 api_resource_controller_.reset(new extensions::APIResourceController());
[email protected]e1fae1c2011-12-13 22:17:172554 }
[email protected]2404a28272012-05-30 02:31:142555 return api_resource_controller_.get();
[email protected]e1fae1c2011-12-13 22:17:172556}