[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 6 | |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 8 | #include <iterator> |
[email protected] | 97d2f1d | 2011-01-15 00:41:08 | [diff] [blame] | 9 | #include <set> |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 10 | |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 12 | #include "base/metrics/histogram.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 13 | #include "base/strings/string_number_conversions.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 14 | #include "base/strings/stringprintf.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 15 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 16 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 17 | #include "base/threading/thread_restrictions.h" |
[email protected] | 41a17c5 | 2013-06-28 00:27:53 | [diff] [blame] | 18 | #include "base/time/time.h" |
[email protected] | 15730c4 | 2009-09-03 00:03:20 | [diff] [blame] | 19 | #include "chrome/browser/browser_process.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 20 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | ad44576 | 2013-01-23 00:47:44 | [diff] [blame] | 21 | #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 22 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame^] | 23 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 24 | #include "chrome/browser/extensions/data_deleter.h" |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 25 | #include "chrome/browser/extensions/extension_assets_manager.h" |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_disabled_ui.h" |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_error_controller.h" |
[email protected] | 00b3824 | 2012-07-18 18:43:22 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_sync_service.h" |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 32 | #include "chrome/browser/extensions/external_install_manager.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 33 | #include "chrome/browser/extensions/external_provider_impl.h" |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 34 | #include "chrome/browser/extensions/install_verifier.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 35 | #include "chrome/browser/extensions/installed_loader.h" |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 36 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame^] | 37 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 38 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame^] | 39 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 40 | #include "chrome/browser/extensions/updater/extension_cache.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame^] | 41 | #include "chrome/browser/extensions/updater/extension_updater.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 42 | #include "chrome/browser/profiles/profile.h" |
[email protected] | c852197 | 2014-08-08 08:35:07 | [diff] [blame] | 43 | #include "chrome/browser/signin/profile_identity_provider.h" |
| 44 | #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 45 | #include "chrome/browser/signin/signin_manager_factory.h" |
[email protected] | b5a507b2 | 2013-11-08 20:41:57 | [diff] [blame] | 46 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 47 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 48 | #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
[email protected] | c852197 | 2014-08-08 08:35:07 | [diff] [blame] | 49 | #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 50 | #include "chrome/browser/ui/webui/theme_source.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 51 | #include "chrome/common/chrome_switches.h" |
[email protected] | f6431be8 | 2013-09-07 02:53:45 | [diff] [blame] | 52 | #include "chrome/common/crash_keys.h" |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 53 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 15d4d2d | 2013-08-09 06:49:03 | [diff] [blame] | 54 | #include "chrome/common/extensions/features/feature_channel.h" |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 55 | #include "chrome/common/extensions/manifest_url_handler.h" |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 56 | #include "chrome/common/pref_names.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 57 | #include "chrome/common/url_constants.h" |
[email protected] | c852197 | 2014-08-08 08:35:07 | [diff] [blame] | 58 | #include "components/signin/core/browser/signin_manager.h" |
[email protected] | 7a83dd07 | 2013-09-03 12:09:17 | [diff] [blame] | 59 | #include "components/startup_metric_utils/startup_metric_utils.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 60 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 61 | #include "content/public/browser/notification_service.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 62 | #include "content/public/browser/render_process_host.h" |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 63 | #include "content/public/browser/storage_partition.h" |
[email protected] | 3442353 | 2013-11-21 18:13:10 | [diff] [blame] | 64 | #include "extensions/browser/event_router.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 65 | #include "extensions/browser/extension_host.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 66 | #include "extensions/browser/extension_prefs.h" |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 67 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 68 | #include "extensions/browser/extension_system.h" |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 69 | #include "extensions/browser/install_flag.h" |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 70 | #include "extensions/browser/pref_names.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 71 | #include "extensions/browser/runtime_data.h" |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 72 | #include "extensions/browser/uninstall_reason.h" |
[email protected] | a9aa62b31 | 2013-11-29 05:35:06 | [diff] [blame] | 73 | #include "extensions/browser/update_observer.h" |
[email protected] | fb820c0 | 2014-03-13 15:07:08 | [diff] [blame] | 74 | #include "extensions/common/extension_messages.h" |
[email protected] | 5ef835a | 2013-11-08 20:42:57 | [diff] [blame] | 75 | #include "extensions/common/feature_switch.h" |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 76 | #include "extensions/common/file_util.h" |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 77 | #include "extensions/common/manifest_constants.h" |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 78 | #include "extensions/common/manifest_handlers/background_info.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 79 | #include "extensions/common/one_shot_event.h" |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 80 | #include "extensions/common/permissions/permission_message_provider.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 81 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | 79a6064 | 2012-10-20 21:03:18 | [diff] [blame] | 82 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 83 | #if defined(OS_CHROMEOS) |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 84 | #include "chrome/browser/chromeos/extensions/install_limiter.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 85 | #include "webkit/browser/fileapi/file_system_backend.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 86 | #include "webkit/browser/fileapi/file_system_context.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 87 | #endif |
| 88 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 89 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 90 | using content::BrowserThread; |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 91 | using content::DevToolsAgentHost; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 92 | using extensions::CrxInstaller; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 93 | using extensions::Extension; |
| 94 | using extensions::ExtensionIdSet; |
| 95 | using extensions::ExtensionInfo; |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 96 | using extensions::ExtensionRegistry; |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 97 | using extensions::ExtensionSet; |
[email protected] | 215a7be | 2012-10-22 19:53:42 | [diff] [blame] | 98 | using extensions::FeatureSwitch; |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 99 | using extensions::InstallVerifier; |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 100 | using extensions::ManagementPolicy; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 101 | using extensions::Manifest; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 102 | using extensions::PermissionMessage; |
| 103 | using extensions::PermissionMessages; |
| 104 | using extensions::PermissionSet; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 105 | using extensions::SharedModuleInfo; |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 106 | using extensions::SharedModuleService; |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 107 | using extensions::UnloadedExtensionInfo; |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 108 | |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 109 | namespace errors = extensions::manifest_errors; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 110 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 111 | namespace { |
| 112 | |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 113 | // Wait this many seconds after an extensions becomes idle before updating it. |
[email protected] | ddc6a12 | 2014-06-27 04:52:32 | [diff] [blame] | 114 | const int kUpdateIdleDelay = 5; |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 115 | |
[email protected] | c852197 | 2014-08-08 08:35:07 | [diff] [blame] | 116 | #if defined(ENABLE_EXTENSIONS) |
| 117 | scoped_ptr<IdentityProvider> CreateWebstoreIdentityProvider(Profile* profile) { |
| 118 | return make_scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( |
| 119 | SigninManagerFactory::GetForProfile(profile), |
| 120 | ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 121 | LoginUIServiceFactory::GetForProfile(profile))); |
| 122 | } |
| 123 | #endif // defined(ENABLE_EXTENSIONS) |
| 124 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 125 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 126 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 127 | // ExtensionService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 128 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 129 | void ExtensionService::CheckExternalUninstall(const std::string& id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 130 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 131 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 132 | // Check if the providers know about this extension. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 133 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 134 | for (i = external_extension_providers_.begin(); |
| 135 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 136 | DCHECK(i->get()->IsReady()); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 137 | if (i->get()->HasExtension(id)) |
| 138 | return; // Yup, known extension, don't uninstall. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 141 | // We get the list of external extensions to check from preferences. |
| 142 | // It is possible that an extension has preferences but is not loaded. |
| 143 | // For example, an extension that requires experimental permissions |
| 144 | // will not be loaded if the experimental command line flag is not used. |
| 145 | // In this case, do not uninstall. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 146 | if (!GetInstalledExtension(id)) { |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 147 | // We can't call UninstallExtension with an unloaded/invalid |
| 148 | // extension ID. |
| 149 | LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 150 | << "with id: " << id; |
| 151 | return; |
| 152 | } |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 153 | UninstallExtension(id, |
| 154 | extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, |
| 155 | base::Bind(&base::DoNothing), |
| 156 | NULL); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 157 | } |
| 158 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 159 | void ExtensionService::SetFileTaskRunnerForTesting( |
| 160 | base::SequencedTaskRunner* task_runner) { |
| 161 | file_task_runner_ = task_runner; |
| 162 | } |
| 163 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 164 | void ExtensionService::ClearProvidersForTesting() { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 165 | external_extension_providers_.clear(); |
| 166 | } |
| 167 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 168 | void ExtensionService::AddProviderForTesting( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 169 | extensions::ExternalProviderInterface* test_provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 170 | CHECK(test_provider); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 171 | external_extension_providers_.push_back( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 172 | linked_ptr<extensions::ExternalProviderInterface>(test_provider)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 173 | } |
| 174 | |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 175 | void ExtensionService::BlacklistExtensionForTest( |
| 176 | const std::string& extension_id) { |
| 177 | ExtensionIdSet blocked; |
| 178 | ExtensionIdSet unchanged; |
| 179 | blocked.insert(extension_id); |
| 180 | UpdateBlockedExtensions(blocked, unchanged); |
| 181 | } |
| 182 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 183 | bool ExtensionService::OnExternalExtensionUpdateUrlFound( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 184 | const std::string& id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 185 | const std::string& install_parameter, |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 186 | const GURL& update_url, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 187 | Manifest::Location location, |
| 188 | int creation_flags, |
| 189 | bool mark_acknowledged) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 190 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 191 | CHECK(Extension::IdIsValid(id)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 192 | |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 193 | if (Manifest::IsExternalLocation(location)) { |
| 194 | // All extensions that are not user specific can be cached. |
| 195 | extensions::ExtensionCache::GetInstance()->AllowCaching(id); |
| 196 | } |
| 197 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 198 | const Extension* extension = GetExtensionById(id, true); |
| 199 | if (extension) { |
| 200 | // Already installed. Skip this install if the current location has |
| 201 | // higher priority than |location|. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 202 | Manifest::Location current = extension->location(); |
| 203 | if (current == Manifest::GetHigherPriorityLocation(current, location)) |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 204 | return false; |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 205 | // Otherwise, overwrite the current installation. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 206 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 207 | |
| 208 | // Add |id| to the set of pending extensions. If it can not be added, |
| 209 | // then there is already a pending record from a higher-priority install |
| 210 | // source. In this case, signal that this extension will not be |
| 211 | // installed by returning false. |
| 212 | if (!pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 213 | id, |
| 214 | install_parameter, |
| 215 | update_url, |
| 216 | location, |
| 217 | creation_flags, |
| 218 | mark_acknowledged)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 219 | return false; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 220 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 221 | |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 222 | update_once_all_providers_are_ready_ = true; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 223 | return true; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 224 | } |
| 225 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 226 | // static |
[email protected] | cc2f55c | 2014-07-08 02:19:04 | [diff] [blame] | 227 | // This function is used to uninstall an extension via sync. The LOG statements |
| 228 | // within this function are used to inform the user if the uninstall cannot be |
| 229 | // done. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 230 | bool ExtensionService::UninstallExtensionHelper( |
| 231 | ExtensionService* extensions_service, |
[email protected] | cc2f55c | 2014-07-08 02:19:04 | [diff] [blame] | 232 | const std::string& extension_id, |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 233 | extensions::UninstallReason reason) { |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 234 | // We can't call UninstallExtension with an invalid extension ID. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 235 | if (!extensions_service->GetInstalledExtension(extension_id)) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 236 | LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 237 | << "id: " << extension_id; |
| 238 | return false; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 241 | // The following call to UninstallExtension will not allow an uninstall of a |
| 242 | // policy-controlled extension. |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 243 | base::string16 error; |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 244 | if (!extensions_service->UninstallExtension( |
| 245 | extension_id, reason, base::Bind(&base::DoNothing), &error)) { |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 246 | LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 247 | << ": " << error; |
| 248 | return false; |
| 249 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 250 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 251 | return true; |
| 252 | } |
| 253 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 254 | ExtensionService::ExtensionService(Profile* profile, |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 255 | const CommandLine* command_line, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 256 | const base::FilePath& install_directory, |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 257 | extensions::ExtensionPrefs* extension_prefs, |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 258 | extensions::Blacklist* blacklist, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 259 | bool autoupdate_enabled, |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 260 | bool extensions_enabled, |
| 261 | extensions::OneShotEvent* ready) |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 262 | : extensions::Blacklist::Observer(blacklist), |
| 263 | profile_(profile), |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 264 | system_(extensions::ExtensionSystem::Get(profile)), |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 265 | extension_prefs_(extension_prefs), |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 266 | blacklist_(blacklist), |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 267 | extension_sync_service_(NULL), |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 268 | registry_(extensions::ExtensionRegistry::Get(profile)), |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 269 | pending_extension_manager_(profile), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 270 | install_directory_(install_directory), |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 271 | extensions_enabled_(extensions_enabled), |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 272 | show_extensions_prompts_(true), |
[email protected] | fc332ae | 2012-11-14 20:17:33 | [diff] [blame] | 273 | install_updates_when_idle_(true), |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 274 | ready_(ready), |
[email protected] | dff1e04 | 2012-04-27 10:59:18 | [diff] [blame] | 275 | update_once_all_providers_are_ready_(false), |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 276 | browser_terminating_(false), |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 277 | installs_delayed_for_gc_(false), |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 278 | is_first_run_(false), |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 279 | shared_module_service_(new extensions::SharedModuleService(profile_)) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 280 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 281 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 282 | // Figure out if extension installation should be enabled. |
[email protected] | 367d9b17 | 2013-12-03 00:31:02 | [diff] [blame] | 283 | if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled( |
| 284 | *command_line, profile)) |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 285 | extensions_enabled_ = false; |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 286 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 287 | registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 288 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 289 | registrar_.Add(this, |
| 290 | extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 291 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 292 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 293 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 294 | registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 295 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 296 | registrar_.Add(this, |
| 297 | chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 298 | content::Source<Profile>(profile_)); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 299 | pref_change_registrar_.Init(profile->GetPrefs()); |
[email protected] | 90bb38d | 2012-11-14 18:36:03 | [diff] [blame] | 300 | base::Closure callback = |
| 301 | base::Bind(&ExtensionService::OnExtensionInstallPrefChanged, |
| 302 | base::Unretained(this)); |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 303 | pref_change_registrar_.Add(extensions::pref_names::kInstallAllowList, |
| 304 | callback); |
| 305 | pref_change_registrar_.Add(extensions::pref_names::kInstallDenyList, |
| 306 | callback); |
| 307 | pref_change_registrar_.Add(extensions::pref_names::kAllowedTypes, callback); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 308 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 309 | // Set up the ExtensionUpdater |
| 310 | if (autoupdate_enabled) { |
[email protected] | 501105b | 2013-09-26 05:42:02 | [diff] [blame] | 311 | int update_frequency = extensions::kDefaultUpdateFrequencySeconds; |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 312 | if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 313 | base::StringToInt(command_line->GetSwitchValueASCII( |
| 314 | switches::kExtensionsUpdateFrequency), |
| 315 | &update_frequency); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 316 | } |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 317 | updater_.reset(new extensions::ExtensionUpdater( |
| 318 | this, |
| 319 | extension_prefs, |
| 320 | profile->GetPrefs(), |
| 321 | profile, |
| 322 | update_frequency, |
[email protected] | c852197 | 2014-08-08 08:35:07 | [diff] [blame] | 323 | extensions::ExtensionCache::GetInstance(), |
| 324 | CreateWebstoreIdentityProvider(profile_))); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 325 | } |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 326 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 327 | component_loader_.reset( |
| 328 | new extensions::ComponentLoader(this, |
| 329 | profile->GetPrefs(), |
[email protected] | 55e16cd | 2013-12-18 04:36:08 | [diff] [blame] | 330 | g_browser_process->local_state(), |
| 331 | profile)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 332 | |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 333 | if (extensions_enabled_) { |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 334 | extensions::ExternalProviderImpl::CreateExternalProviders( |
| 335 | this, profile_, &external_extension_providers_); |
[email protected] | 87353134 | 2011-03-09 12:16:05 | [diff] [blame] | 336 | } |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 337 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 338 | // Set this as the ExtensionService for app sorting to ensure it causes syncs |
| 339 | // if required. |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 340 | is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun(); |
| 341 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 342 | error_controller_.reset( |
| 343 | new extensions::ExtensionErrorController(profile_, is_first_run_)); |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 344 | external_install_manager_.reset( |
| 345 | new extensions::ExternalInstallManager(profile_, is_first_run_)); |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 346 | |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 347 | extension_action_storage_manager_.reset( |
| 348 | new extensions::ExtensionActionStorageManager(profile_)); |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 349 | |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 350 | // How long is the path to the Extensions directory? |
| 351 | UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", |
| 352 | install_directory_.value().length(), 0, 500, 100); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 353 | } |
| 354 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 355 | const ExtensionSet* ExtensionService::extensions() const { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 356 | return ®istry_->enabled_extensions(); |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 357 | } |
| 358 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 359 | extensions::PendingExtensionManager* |
| 360 | ExtensionService::pending_extension_manager() { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 361 | return &pending_extension_manager_; |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 364 | ExtensionService::~ExtensionService() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 365 | // No need to unload extensions here because they are profile-scoped, and the |
| 366 | // profile is in the process of being deleted. |
[email protected] | 94b4ffc | 2011-02-04 05:55:17 | [diff] [blame] | 367 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 368 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 369 | for (i = external_extension_providers_.begin(); |
| 370 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 371 | extensions::ExternalProviderInterface* provider = i->get(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 372 | provider->ServiceShutdown(); |
| 373 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | 037228a | 2012-10-05 01:36:16 | [diff] [blame] | 376 | void ExtensionService::Shutdown() { |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 377 | system_->management_policy()->UnregisterProvider( |
| 378 | shared_module_policy_provider_.get()); |
[email protected] | 037228a | 2012-10-05 01:36:16 | [diff] [blame] | 379 | } |
| 380 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 381 | const Extension* ExtensionService::GetExtensionById( |
| 382 | const std::string& id, bool include_disabled) const { |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 383 | int include_mask = ExtensionRegistry::ENABLED; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 384 | if (include_disabled) { |
| 385 | // Include blacklisted extensions here because there are hundreds of |
| 386 | // callers of this function, and many might assume that this includes those |
| 387 | // that have been disabled due to blacklisting. |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 388 | include_mask |= ExtensionRegistry::DISABLED | |
| 389 | ExtensionRegistry::BLACKLISTED; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 390 | } |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 391 | return registry_->GetExtensionById(id, include_mask); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 392 | } |
| 393 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 394 | void ExtensionService::Init() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 395 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 396 | |
[email protected] | 3350d71 | 2013-11-18 09:32:24 | [diff] [blame] | 397 | base::Time begin_time = base::Time::Now(); |
| 398 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 399 | DCHECK(!is_ready()); // Can't redo init. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 400 | DCHECK_EQ(registry_->enabled_extensions().size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 401 | |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 402 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 403 | if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || |
| 404 | cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) { |
| 405 | // The sole purpose of this launch is to install a new extension from CWS |
| 406 | // and immediately terminate: loading already installed extensions is |
| 407 | // unnecessary and may interfere with the inline install dialog (e.g. if an |
| 408 | // extension listens to onStartup and opens a window). |
| 409 | SetReadyAndNotifyListeners(); |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 410 | } else { |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 411 | // LoadAllExtensions() calls OnLoadedInstalledExtensions(). |
| 412 | component_loader_->LoadAll(); |
| 413 | extensions::InstalledLoader(this).LoadAllExtensions(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 414 | |
[email protected] | 2edd5785 | 2013-08-14 22:07:40 | [diff] [blame] | 415 | // Attempt to re-enable extensions whose only disable reason is reloading. |
| 416 | std::vector<std::string> extensions_to_enable; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 417 | const ExtensionSet& disabled_extensions = registry_->disabled_extensions(); |
| 418 | for (ExtensionSet::const_iterator iter = disabled_extensions.begin(); |
| 419 | iter != disabled_extensions.end(); ++iter) { |
[email protected] | 2edd5785 | 2013-08-14 22:07:40 | [diff] [blame] | 420 | const Extension* e = iter->get(); |
| 421 | if (extension_prefs_->GetDisableReasons(e->id()) == |
| 422 | Extension::DISABLE_RELOAD) { |
| 423 | extensions_to_enable.push_back(e->id()); |
| 424 | } |
| 425 | } |
| 426 | for (std::vector<std::string>::iterator it = extensions_to_enable.begin(); |
| 427 | it != extensions_to_enable.end(); ++it) { |
| 428 | EnableExtension(*it); |
| 429 | } |
| 430 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 431 | // Finish install (if possible) of extensions that were still delayed while |
| 432 | // the browser was shut down. |
| 433 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info( |
| 434 | extension_prefs_->GetAllDelayedInstallInfo()); |
| 435 | for (size_t i = 0; i < delayed_info->size(); ++i) { |
| 436 | ExtensionInfo* info = delayed_info->at(i).get(); |
| 437 | scoped_refptr<const Extension> extension(NULL); |
| 438 | if (info->extension_manifest) { |
| 439 | std::string error; |
| 440 | extension = Extension::Create( |
| 441 | info->extension_path, |
| 442 | info->extension_location, |
| 443 | *info->extension_manifest, |
| 444 | extension_prefs_->GetDelayedInstallCreationFlags( |
| 445 | info->extension_id), |
| 446 | info->extension_id, |
| 447 | &error); |
| 448 | if (extension.get()) |
| 449 | delayed_installs_.Insert(extension); |
| 450 | } |
| 451 | } |
| 452 | MaybeFinishDelayedInstallations(); |
| 453 | |
| 454 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2( |
| 455 | extension_prefs_->GetAllDelayedInstallInfo()); |
| 456 | UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", |
| 457 | delayed_info2->size() - delayed_info->size()); |
| 458 | |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 459 | SetReadyAndNotifyListeners(); |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 460 | |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 461 | // TODO(erikkay) this should probably be deferred to a future point |
| 462 | // rather than running immediately at startup. |
| 463 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 464 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 465 | LoadGreylistFromPrefs(); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 466 | } |
[email protected] | 3350d71 | 2013-11-18 09:32:24 | [diff] [blame] | 467 | |
| 468 | UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", |
| 469 | base::Time::Now() - begin_time); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 470 | } |
| 471 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 472 | void ExtensionService::LoadGreylistFromPrefs() { |
[email protected] | f47f717 | 2014-03-19 19:27:10 | [diff] [blame] | 473 | scoped_ptr<ExtensionSet> all_extensions = |
| 474 | registry_->GenerateInstalledExtensionsSet(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 475 | |
| 476 | for (ExtensionSet::const_iterator it = all_extensions->begin(); |
| 477 | it != all_extensions->end(); ++it) { |
| 478 | extensions::BlacklistState state = |
| 479 | extension_prefs_->GetExtensionBlacklistState((*it)->id()); |
| 480 | if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY || |
| 481 | state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED || |
| 482 | state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION) |
| 483 | greylist_.Insert(*it); |
| 484 | } |
| 485 | } |
| 486 | |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 487 | bool ExtensionService::UpdateExtension(const std::string& id, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 488 | const base::FilePath& extension_path, |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 489 | bool file_ownership_passed, |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 490 | CrxInstaller** out_crx_installer) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 491 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 492 | if (browser_terminating_) { |
| 493 | LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown"; |
| 494 | // Leak the temp file at extension_path. We don't want to add to the disk |
| 495 | // I/O burden at shutdown, we can't rely on the I/O completing anyway, and |
| 496 | // the file is in the OS temp directory which should be cleaned up for us. |
| 497 | return false; |
| 498 | } |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 499 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 500 | const extensions::PendingExtensionInfo* pending_extension_info = |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 501 | pending_extension_manager()->GetById(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 502 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 503 | const Extension* extension = GetInstalledExtension(id); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 504 | if (!pending_extension_info && !extension) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 505 | LOG(WARNING) << "Will not update extension " << id |
| 506 | << " because it is not installed or pending"; |
| 507 | // Delete extension_path since we're not creating a CrxInstaller |
| 508 | // that would do it for us. |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 509 | if (!GetFileTaskRunner()->PostTask( |
| 510 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 511 | base::Bind( |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 512 | &extensions::file_util::DeleteFile, extension_path, false))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 513 | NOTREACHED(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 514 | |
| 515 | return false; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 516 | } |
| 517 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 518 | // We want a silent install only for non-pending extensions and |
| 519 | // pending extensions that have install_silently set. |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 520 | scoped_ptr<ExtensionInstallPrompt> client; |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 521 | if (pending_extension_info && !pending_extension_info->install_silently()) |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 522 | client.reset(ExtensionInstallUI::CreateInstallPromptWithProfile(profile_)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 523 | |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 524 | scoped_refptr<CrxInstaller> installer( |
| 525 | CrxInstaller::Create(this, client.Pass())); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 526 | installer->set_expected_id(id); |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 527 | int creation_flags = Extension::NO_FLAGS; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 528 | if (pending_extension_info) { |
| 529 | installer->set_install_source(pending_extension_info->install_source()); |
| 530 | if (pending_extension_info->install_silently()) |
| 531 | installer->set_allow_silent_install(true); |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 532 | if (pending_extension_info->remote_install()) |
| 533 | installer->set_grant_permissions(false); |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 534 | creation_flags = pending_extension_info->creation_flags(); |
| 535 | if (pending_extension_info->mark_acknowledged()) |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 536 | external_install_manager_->AcknowledgeExternalExtension(id); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 537 | } else if (extension) { |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 538 | installer->set_install_source(extension->location()); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 539 | } |
[email protected] | 7d8b707 | 2012-04-07 01:07:46 | [diff] [blame] | 540 | // If the extension was installed from or has migrated to the webstore, or |
[email protected] | fcb2c2c | 2012-10-17 21:08:45 | [diff] [blame] | 541 | // its auto-update URL is from the webstore, treat it as a webstore install. |
| 542 | // Note that we ignore some older extensions with blank auto-update URLs |
| 543 | // because we are mostly concerned with restrictions on NaCl extensions, |
| 544 | // which are newer. |
[email protected] | 7576451 | 2011-12-19 19:54:28 | [diff] [blame] | 545 | if ((extension && extension->from_webstore()) || |
[email protected] | 4a5fe3e2 | 2013-06-04 07:06:38 | [diff] [blame] | 546 | (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) || |
[email protected] | 963d13c | 2012-09-29 17:13:35 | [diff] [blame] | 547 | (!extension && extension_urls::IsWebstoreUpdateUrl( |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 548 | pending_extension_info->update_url()))) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 549 | creation_flags |= Extension::FROM_WEBSTORE; |
| 550 | } |
| 551 | |
| 552 | // Bookmark apps being updated is kind of a contradiction, but that's because |
| 553 | // we mark the default apps as bookmark apps, and they're hosted in the web |
| 554 | // store, thus they can get updated. See http://crbug.com/101605 for more |
| 555 | // details. |
| 556 | if (extension && extension->from_bookmark()) |
| 557 | creation_flags |= Extension::FROM_BOOKMARK; |
| 558 | |
[email protected] | e33bbc2 | 2012-08-27 22:05:46 | [diff] [blame] | 559 | if (extension && extension->was_installed_by_default()) |
| 560 | creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; |
| 561 | |
[email protected] | acc3c7c2 | 2014-03-19 06:23:39 | [diff] [blame] | 562 | if (extension && extension->was_installed_by_oem()) |
| 563 | creation_flags |= Extension::WAS_INSTALLED_BY_OEM; |
| 564 | |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 565 | if (extension && extension->was_installed_by_custodian()) |
| 566 | creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN; |
| 567 | |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 568 | if (extension) { |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 569 | installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id)); |
[email protected] | c30bda26 | 2014-06-19 04:10:13 | [diff] [blame] | 570 | installer->set_do_not_sync(extension_prefs_->DoNotSync(id)); |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 571 | } |
[email protected] | ab6c7be4 | 2014-01-16 02:05:54 | [diff] [blame] | 572 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 573 | installer->set_creation_flags(creation_flags); |
| 574 | |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 575 | installer->set_delete_source(file_ownership_passed); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 576 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 577 | installer->InstallCrx(extension_path); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 578 | |
| 579 | if (out_crx_installer) |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 580 | *out_crx_installer = installer.get(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 581 | |
| 582 | return true; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 583 | } |
| 584 | |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 585 | void ExtensionService::ReloadExtensionImpl( |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 586 | // "transient" because the process of reloading may cause the reference |
| 587 | // to become invalid. Instead, use |extension_id|, a copy. |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 588 | const std::string& transient_extension_id, |
| 589 | bool be_noisy) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 590 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 591 | |
| 592 | // If the extension is already reloading, don't reload again. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 593 | if (extension_prefs_->GetDisableReasons(transient_extension_id) & |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 594 | Extension::DISABLE_RELOAD) { |
| 595 | return; |
| 596 | } |
| 597 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 598 | // Ignore attempts to reload a blacklisted extension. Sometimes this can |
| 599 | // happen in a convoluted reload sequence triggered by the termination of a |
| 600 | // blacklisted extension and a naive attempt to reload it. For an example see |
| 601 | // http://crbug.com/373842. |
| 602 | if (registry_->blacklisted_extensions().Contains(transient_extension_id)) |
| 603 | return; |
| 604 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 605 | base::FilePath path; |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 606 | |
| 607 | std::string extension_id = transient_extension_id; |
| 608 | const Extension* transient_current_extension = |
| 609 | GetExtensionById(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 610 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 611 | // Disable the extension if it's loaded. It might not be loaded if it crashed. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 612 | if (transient_current_extension) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 613 | // If the extension has an inspector open for its background page, detach |
| 614 | // the inspector and hang onto a cookie for it, so that we can reattach |
| 615 | // later. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 616 | // TODO(yoz): this is not incognito-safe! |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 617 | extensions::ProcessManager* manager = system_->process_manager(); |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 618 | extensions::ExtensionHost* host = |
| 619 | manager->GetBackgroundHostForExtension(extension_id); |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 620 | if (host && DevToolsAgentHost::HasFor(host->host_contents())) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 621 | // Look for an open inspector for the background page. |
[email protected] | 04ea1bb | 2013-07-10 09:26:09 | [diff] [blame] | 622 | scoped_refptr<DevToolsAgentHost> agent_host = |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 623 | DevToolsAgentHost::GetOrCreateFor(host->host_contents()); |
| 624 | agent_host->DisconnectWebContents(); |
[email protected] | 04ea1bb | 2013-07-10 09:26:09 | [diff] [blame] | 625 | orphaned_dev_tools_[extension_id] = agent_host; |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 626 | } |
| 627 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 628 | path = transient_current_extension->path(); |
[email protected] | 5807619 | 2013-07-19 19:43:50 | [diff] [blame] | 629 | // BeingUpgraded is set back to false when the extension is added. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 630 | system_->runtime_data()->SetBeingUpgraded(transient_current_extension, |
| 631 | true); |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 632 | DisableExtension(extension_id, Extension::DISABLE_RELOAD); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 633 | reloading_extensions_.insert(extension_id); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 634 | } else { |
[email protected] | d32c02a | 2014-06-16 22:58:36 | [diff] [blame] | 635 | std::map<std::string, base::FilePath>::const_iterator iter = |
| 636 | unloaded_extension_paths_.find(extension_id); |
| 637 | if (iter == unloaded_extension_paths_.end()) { |
| 638 | return; |
| 639 | } |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 640 | path = unloaded_extension_paths_[extension_id]; |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 641 | } |
| 642 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 643 | transient_current_extension = NULL; |
| 644 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 645 | if (delayed_installs_.Contains(extension_id)) { |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 646 | FinishDelayedInstallation(extension_id); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 647 | return; |
| 648 | } |
| 649 | |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 650 | // If we're reloading a component extension, use the component extension |
| 651 | // loader's reloader. |
| 652 | if (component_loader_->Exists(extension_id)) { |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 653 | component_loader_->Reload(extension_id); |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 654 | return; |
| 655 | } |
| 656 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 657 | // Check the installed extensions to see if what we're reloading was already |
| 658 | // installed. |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 659 | scoped_ptr<ExtensionInfo> installed_extension( |
| 660 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 661 | if (installed_extension.get() && |
| 662 | installed_extension->extension_manifest.get()) { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 663 | extensions::InstalledLoader(this).Load(*installed_extension, false); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 664 | } else { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 665 | // Otherwise, the extension is unpacked (location LOAD). |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 666 | // We should always be able to remember the extension's path. If it's not in |
| 667 | // the map, someone failed to update |unloaded_extension_paths_|. |
| 668 | CHECK(!path.empty()); |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 669 | scoped_refptr<extensions::UnpackedInstaller> unpacked_installer = |
| 670 | extensions::UnpackedInstaller::Create(this); |
| 671 | unpacked_installer->set_be_noisy_on_failure(be_noisy); |
| 672 | unpacked_installer->Load(path); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 673 | } |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 674 | } |
| 675 | |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 676 | void ExtensionService::ReloadExtension(const std::string& extension_id) { |
| 677 | ReloadExtensionImpl(extension_id, true); // be_noisy |
| 678 | } |
| 679 | |
| 680 | void ExtensionService::ReloadExtensionWithQuietFailure( |
| 681 | const std::string& extension_id) { |
| 682 | ReloadExtensionImpl(extension_id, false); // be_noisy |
| 683 | } |
| 684 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 685 | bool ExtensionService::UninstallExtension( |
| 686 | // "transient" because the process of uninstalling may cause the reference |
| 687 | // to become invalid. Instead, use |extenson->id()|. |
| 688 | const std::string& transient_extension_id, |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 689 | extensions::UninstallReason reason, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 690 | const base::Closure& deletion_done_callback, |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 691 | base::string16* error) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 692 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 693 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 694 | scoped_refptr<const Extension> extension = |
| 695 | GetInstalledExtension(transient_extension_id); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 696 | |
[email protected] | e7afe245 | 2010-08-22 16:19:13 | [diff] [blame] | 697 | // Callers should not send us nonexistent extensions. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 698 | CHECK(extension.get()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 699 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 700 | // Policy change which triggers an uninstall will always set |
| 701 | // |external_uninstall| to true so this is the only way to uninstall |
| 702 | // managed extensions. |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 703 | // Shared modules being uninstalled will also set |external_uninstall| to true |
| 704 | // so that we can guarantee users don't uninstall a shared module. |
| 705 | // (crbug.com/273300) |
| 706 | // TODO(rdevlin.cronin): This is probably not right. We should do something |
| 707 | // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so |
| 708 | // we don't do this. |
[email protected] | cc2f55c | 2014-07-08 02:19:04 | [diff] [blame] | 709 | bool external_uninstall = |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 710 | (reason == extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT) || |
| 711 | (reason == extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) || |
[email protected] | 6ef6001 | 2014-07-22 19:08:12 | [diff] [blame] | 712 | (reason == extensions::UNINSTALL_REASON_ORPHANED_SHARED_MODULE) || |
| 713 | (reason == extensions::UNINSTALL_REASON_SYNC && |
| 714 | extension->was_installed_by_custodian()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 715 | if (!external_uninstall && |
| 716 | !system_->management_policy()->UserMayModifySettings( |
| 717 | extension.get(), error)) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 718 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 719 | extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 720 | content::Source<Profile>(profile_), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 721 | content::Details<const Extension>(extension.get())); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 722 | return false; |
| 723 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 724 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 725 | syncer::SyncChange sync_change; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 726 | if (extension_sync_service_) { |
| 727 | sync_change = extension_sync_service_->PrepareToSyncUninstallExtension( |
| 728 | extension.get(), is_ready()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 729 | } |
| 730 | |
[email protected] | d820bc5 | 2014-03-13 05:35:23 | [diff] [blame] | 731 | system_->install_verifier()->Remove(extension->id()); |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 732 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 733 | UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 734 | extension->GetType(), 100); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 735 | RecordPermissionMessagesHistogram(extension.get(), |
[email protected] | 4c86be58 | 2014-06-04 08:39:11 | [diff] [blame] | 736 | "Extensions.Permissions_Uninstall2"); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 737 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 738 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 739 | // any of these resources. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 740 | UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 741 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 742 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 743 | if (!Manifest::IsUnpackedLocation(extension->location())) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 744 | if (!GetFileTaskRunner()->PostTask( |
| 745 | FROM_HERE, |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 746 | base::Bind(&ExtensionService::UninstallExtensionOnFileThread, |
| 747 | extension->id(), |
| 748 | profile_, |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 749 | install_directory_, |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 750 | extension->path()))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 751 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 752 | } |
| 753 | |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 754 | extensions::DataDeleter::StartDeleting( |
| 755 | profile_, extension.get(), deletion_done_callback); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 756 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 757 | UntrackTerminatedExtension(extension->id()); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 758 | |
| 759 | // Notify interested parties that we've uninstalled this extension. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 760 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 761 | extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 762 | content::Source<Profile>(profile_), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 763 | content::Details<const Extension>(extension.get())); |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 764 | ExtensionRegistry::Get(profile_) |
| 765 | ->TriggerOnUninstalled(extension.get(), reason); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 766 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 767 | if (extension_sync_service_) { |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 768 | extension_sync_service_->ProcessSyncUninstallExtension(extension->id(), |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 769 | sync_change); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 770 | } |
| 771 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 772 | delayed_installs_.Remove(extension->id()); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 773 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 774 | extension_prefs_->OnExtensionUninstalled( |
| 775 | extension->id(), extension->location(), external_uninstall); |
[email protected] | d4eda59 | 2013-09-18 03:37:57 | [diff] [blame] | 776 | |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 777 | // Track the uninstallation. |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 778 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); |
| 779 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 780 | return true; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 781 | } |
| 782 | |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 783 | // static |
| 784 | void ExtensionService::UninstallExtensionOnFileThread( |
| 785 | const std::string& id, |
| 786 | Profile* profile, |
| 787 | const base::FilePath& install_dir, |
| 788 | const base::FilePath& extension_path) { |
| 789 | extensions::ExtensionAssetsManager* assets_manager = |
| 790 | extensions::ExtensionAssetsManager::GetInstance(); |
| 791 | assets_manager->UninstallExtension(id, profile, install_dir, extension_path); |
| 792 | } |
| 793 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 794 | bool ExtensionService::IsExtensionEnabled( |
| 795 | const std::string& extension_id) const { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 796 | if (registry_->enabled_extensions().Contains(extension_id) || |
| 797 | registry_->terminated_extensions().Contains(extension_id)) { |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 798 | return true; |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 799 | } |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 800 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 801 | if (registry_->disabled_extensions().Contains(extension_id) || |
| 802 | registry_->blacklisted_extensions().Contains(extension_id)) { |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 803 | return false; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 804 | } |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 805 | |
| 806 | // If the extension hasn't been loaded yet, check the prefs for it. Assume |
| 807 | // enabled unless otherwise noted. |
| 808 | return !extension_prefs_->IsExtensionDisabled(extension_id) && |
[email protected] | 27e52832 | 2014-05-27 20:54:30 | [diff] [blame] | 809 | !extension_prefs_->IsExtensionBlacklisted(extension_id) && |
[email protected] | f574c40 | 2012-12-04 23:20:31 | [diff] [blame] | 810 | !extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 811 | } |
| 812 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 813 | void ExtensionService::EnableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 814 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 815 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 816 | if (IsExtensionEnabled(extension_id)) |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 817 | return; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 818 | const Extension* extension = |
| 819 | registry_->disabled_extensions().GetByID(extension_id); |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 820 | |
| 821 | ManagementPolicy* policy = system_->management_policy(); |
| 822 | if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) { |
| 823 | UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1); |
| 824 | return; |
| 825 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 826 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 827 | extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 828 | extension_prefs_->ClearDisableReasons(extension_id); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 829 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 830 | // This can happen if sync enables an extension that is not |
| 831 | // installed yet. |
| 832 | if (!extension) |
| 833 | return; |
| 834 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 835 | // Move it over to the enabled list. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 836 | registry_->AddEnabled(make_scoped_refptr(extension)); |
| 837 | registry_->RemoveDisabled(extension->id()); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 838 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 839 | NotifyExtensionLoaded(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 840 | |
[email protected] | f74d7f3 | 2012-06-19 19:22:51 | [diff] [blame] | 841 | // Notify listeners that the extension was enabled. |
| 842 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 843 | extensions::NOTIFICATION_EXTENSION_ENABLED, |
[email protected] | f74d7f3 | 2012-06-19 19:22:51 | [diff] [blame] | 844 | content::Source<Profile>(profile_), |
| 845 | content::Details<const Extension>(extension)); |
| 846 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 847 | if (extension_sync_service_) |
| 848 | extension_sync_service_->SyncEnableExtension(*extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 849 | } |
| 850 | |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 851 | void ExtensionService::DisableExtension( |
| 852 | const std::string& extension_id, |
| 853 | Extension::DisableReason disable_reason) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 854 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 855 | |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 856 | // The extension may have been disabled already. Just add a disable reason. |
| 857 | if (!IsExtensionEnabled(extension_id)) { |
| 858 | extension_prefs_->AddDisableReason(extension_id, disable_reason); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 859 | return; |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 860 | } |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 861 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 862 | const Extension* extension = GetInstalledExtension(extension_id); |
| 863 | // |extension| can be NULL if sync disables an extension that is not |
| 864 | // installed yet. |
[email protected] | ab89454 | 2014-07-03 12:35:39 | [diff] [blame] | 865 | // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but |
| 866 | // can be uninstalled by the browser if the user sets extension-specific |
| 867 | // preferences. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 868 | if (extension && |
[email protected] | 505ccdc | 2013-06-20 20:15:35 | [diff] [blame] | 869 | disable_reason != Extension::DISABLE_RELOAD && |
[email protected] | ab89454 | 2014-07-03 12:35:39 | [diff] [blame] | 870 | !system_->management_policy()->UserMayModifySettings(extension, NULL) && |
| 871 | extension->location() != Manifest::EXTERNAL_COMPONENT) { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 872 | return; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 873 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 874 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 875 | extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 876 | extension_prefs_->AddDisableReason(extension_id, disable_reason); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 877 | |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 878 | int include_mask = |
| 879 | ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; |
| 880 | extension = registry_->GetExtensionById(extension_id, include_mask); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 881 | if (!extension) |
| 882 | return; |
| 883 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 884 | // The extension is either enabled or terminated. |
| 885 | DCHECK(registry_->enabled_extensions().Contains(extension->id()) || |
| 886 | registry_->terminated_extensions().Contains(extension->id())); |
[email protected] | 64742de3 | 2013-04-22 08:44:34 | [diff] [blame] | 887 | |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 888 | // Move it over to the disabled list. Don't send a second unload notification |
| 889 | // for terminated extensions being disabled. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 890 | registry_->AddDisabled(make_scoped_refptr(extension)); |
| 891 | if (registry_->enabled_extensions().Contains(extension->id())) { |
| 892 | registry_->RemoveEnabled(extension->id()); |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 893 | NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 894 | } else { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 895 | registry_->RemoveTerminated(extension->id()); |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 896 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 897 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 898 | if (extension_sync_service_) |
| 899 | extension_sync_service_->SyncDisableExtension(*extension); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 900 | } |
| 901 | |
[email protected] | 1abf05e | 2013-07-09 17:04:36 | [diff] [blame] | 902 | void ExtensionService::DisableUserExtensions( |
| 903 | const std::vector<std::string>& except_ids) { |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 904 | extensions::ManagementPolicy* management_policy = |
| 905 | system_->management_policy(); |
| 906 | extensions::ExtensionList to_disable; |
| 907 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 908 | const ExtensionSet& enabled_set = registry_->enabled_extensions(); |
| 909 | for (ExtensionSet::const_iterator extension = enabled_set.begin(); |
| 910 | extension != enabled_set.end(); ++extension) { |
[email protected] | ab89454 | 2014-07-03 12:35:39 | [diff] [blame] | 911 | if (management_policy->UserMayModifySettings(extension->get(), NULL)) |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 912 | to_disable.push_back(*extension); |
| 913 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 914 | const ExtensionSet& terminated_set = registry_->terminated_extensions(); |
| 915 | for (ExtensionSet::const_iterator extension = terminated_set.begin(); |
| 916 | extension != terminated_set.end(); ++extension) { |
[email protected] | ab89454 | 2014-07-03 12:35:39 | [diff] [blame] | 917 | if (management_policy->UserMayModifySettings(extension->get(), NULL)) |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 918 | to_disable.push_back(*extension); |
| 919 | } |
| 920 | |
| 921 | for (extensions::ExtensionList::const_iterator extension = to_disable.begin(); |
| 922 | extension != to_disable.end(); ++extension) { |
[email protected] | 3082fe3 | 2013-08-06 11:12:38 | [diff] [blame] | 923 | if ((*extension)->was_installed_by_default() && |
| 924 | extension_urls::IsWebstoreUpdateUrl( |
| 925 | extensions::ManifestURL::GetUpdateURL(*extension))) |
| 926 | continue; |
[email protected] | 1abf05e | 2013-07-09 17:04:36 | [diff] [blame] | 927 | const std::string& id = (*extension)->id(); |
| 928 | if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id)) |
| 929 | DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION); |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 933 | void ExtensionService::GrantPermissionsAndEnableExtension( |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 934 | const Extension* extension) { |
| 935 | GrantPermissions(extension); |
[email protected] | 4c86be58 | 2014-06-04 08:39:11 | [diff] [blame] | 936 | RecordPermissionMessagesHistogram(extension, |
| 937 | "Extensions.Permissions_ReEnable2"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 938 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 939 | EnableExtension(extension->id()); |
| 940 | } |
| 941 | |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 942 | void ExtensionService::GrantPermissions(const Extension* extension) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 943 | CHECK(extension); |
[email protected] | 8d42db5 | 2014-06-20 21:50:50 | [diff] [blame] | 944 | extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 945 | } |
| 946 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 947 | // static |
| 948 | void ExtensionService::RecordPermissionMessagesHistogram( |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 949 | const Extension* extension, const char* histogram) { |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 950 | // Since this is called from multiple sources, and since the histogram macros |
| 951 | // use statics, we need to manually lookup the histogram ourselves. |
| 952 | base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 953 | histogram, |
| 954 | 1, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 955 | PermissionMessage::kEnumBoundary, |
| 956 | PermissionMessage::kEnumBoundary + 1, |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 957 | base::HistogramBase::kUmaTargetedHistogramFlag); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 958 | |
[email protected] | a6910e7 | 2014-06-06 05:04:36 | [diff] [blame] | 959 | PermissionMessages permissions = |
| 960 | extension->permissions_data()->GetPermissionMessages(); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 961 | if (permissions.empty()) { |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 962 | counter->Add(PermissionMessage::kNone); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 963 | } else { |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 964 | for (PermissionMessages::iterator it = permissions.begin(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 965 | it != permissions.end(); ++it) |
| 966 | counter->Add(it->id()); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 970 | void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
[email protected] | f9c8c7c7 | 2014-07-31 16:42:31 | [diff] [blame] | 971 | // The URLRequestContexts need to be first to know that the extension |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 972 | // was loaded, otherwise a race can arise where a renderer that is created |
| 973 | // for the extension may try to load an extension URL with an extension id |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 974 | // that the request context doesn't yet know about. The profile is responsible |
| 975 | // for ensuring its URLRequestContexts appropriately discover the loaded |
| 976 | // extension. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 977 | system_->RegisterExtensionWithRequestContexts(extension); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 978 | |
[email protected] | d594931 | 2012-12-03 22:13:30 | [diff] [blame] | 979 | // Tell renderers about the new extension, unless it's a theme (renderers |
| 980 | // don't need to know about themes). |
[email protected] | a58f599c | 2012-12-01 03:08:19 | [diff] [blame] | 981 | if (!extension->is_theme()) { |
[email protected] | 1964726 | 2011-12-16 09:57:49 | [diff] [blame] | 982 | for (content::RenderProcessHost::iterator i( |
| 983 | content::RenderProcessHost::AllHostsIterator()); |
| 984 | !i.IsAtEnd(); i.Advance()) { |
| 985 | content::RenderProcessHost* host = i.GetCurrentValue(); |
| 986 | Profile* host_profile = |
| 987 | Profile::FromBrowserContext(host->GetBrowserContext()); |
| 988 | if (host_profile->GetOriginalProfile() == |
| 989 | profile_->GetOriginalProfile()) { |
| 990 | std::vector<ExtensionMsg_Loaded_Params> loaded_extensions( |
| 991 | 1, ExtensionMsg_Loaded_Params(extension)); |
| 992 | host->Send( |
| 993 | new ExtensionMsg_Loaded(loaded_extensions)); |
| 994 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 995 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 996 | } |
| 997 | |
[email protected] | 3442a66 | 2012-01-12 08:06:17 | [diff] [blame] | 998 | // Tell subsystems that use the EXTENSION_LOADED notification about the new |
| 999 | // extension. |
| 1000 | // |
| 1001 | // NOTE: It is important that this happen after notifying the renderers about |
| 1002 | // the new extensions so that if we navigate to an extension URL in |
[email protected] | fdc7619 | 2014-04-20 21:54:41 | [diff] [blame] | 1003 | // ExtensionRegistryObserver::OnLoaded or |
| 1004 | // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1005 | // renderer is guaranteed to know about it. |
| 1006 | registry_->TriggerOnLoaded(extension); |
| 1007 | |
[email protected] | 3442a66 | 2012-01-12 08:06:17 | [diff] [blame] | 1008 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1009 | extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
[email protected] | 3442a66 | 2012-01-12 08:06:17 | [diff] [blame] | 1010 | content::Source<Profile>(profile_), |
| 1011 | content::Details<const Extension>(extension)); |
| 1012 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1013 | // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a |
| 1014 | // BrowserContextKeyedService and use ExtensionRegistryObserver. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1015 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1016 | GrantRightsForExtension(extension); |
| 1017 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1018 | // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't |
| 1019 | // work properly multi-profile. Besides which, it should be using |
| 1020 | // ExtensionRegistryObserver. See http://crbug.com/355029. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1021 | UpdateActiveExtensionsInCrashReporter(); |
| 1022 | |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1023 | const extensions::PermissionsData* permissions_data = |
[email protected] | a6910e7 | 2014-06-06 05:04:36 | [diff] [blame] | 1024 | extension->permissions_data(); |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1025 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1026 | // If the extension has permission to load chrome://favicon/ resources we need |
| 1027 | // to make sure that the FaviconSource is registered with the |
| 1028 | // ChromeURLDataManager. |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1029 | if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1030 | FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1031 | FaviconSource::FAVICON); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1032 | content::URLDataSource::Add(profile_, favicon_source); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1033 | } |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1034 | |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1035 | // Same for chrome://theme/ resources. |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1036 | if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) { |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1037 | ThemeSource* theme_source = new ThemeSource(profile_); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1038 | content::URLDataSource::Add(profile_, theme_source); |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1039 | } |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1040 | |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 1041 | // Same for chrome://thumb/ resources. |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1042 | if (permissions_data->HasHostPermission( |
| 1043 | GURL(chrome::kChromeUIThumbnailURL))) { |
[email protected] | 420e6d9 | 2013-09-17 01:48:51 | [diff] [blame] | 1044 | ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1045 | content::URLDataSource::Add(profile_, thumbnail_source); |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 1046 | } |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1047 | } |
| 1048 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1049 | void ExtensionService::NotifyExtensionUnloaded( |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1050 | const Extension* extension, |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1051 | UnloadedExtensionInfo::Reason reason) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1052 | UnloadedExtensionInfo details(extension, reason); |
[email protected] | e51232f3 | 2014-04-18 20:05:36 | [diff] [blame] | 1053 | |
| 1054 | registry_->TriggerOnUnloaded(extension, reason); |
| 1055 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1056 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1057 | extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1058 | content::Source<Profile>(profile_), |
| 1059 | content::Details<UnloadedExtensionInfo>(&details)); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1060 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1061 | for (content::RenderProcessHost::iterator i( |
| 1062 | content::RenderProcessHost::AllHostsIterator()); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1063 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1064 | content::RenderProcessHost* host = i.GetCurrentValue(); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1065 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1066 | Profile::FromBrowserContext(host->GetBrowserContext()); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1067 | if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1068 | host->Send(new ExtensionMsg_Unloaded(extension->id())); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1069 | } |
| 1070 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1071 | system_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1072 | |
| 1073 | // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a |
| 1074 | // BrowserContextKeyedService and use ExtensionRegistryObserver. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1075 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1076 | RevokeRightsForExtension(extension); |
| 1077 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 1078 | #if defined(OS_CHROMEOS) |
[email protected] | ac66e45 | 2013-01-11 09:21:23 | [diff] [blame] | 1079 | // Revoke external file access for the extension from its file system context. |
| 1080 | // It is safe to access the extension's storage partition at this point. The |
| 1081 | // storage partition may get destroyed only after the extension gets unloaded. |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 1082 | GURL site = |
| 1083 | extensions::util::GetSiteForExtensionId(extension->id(), profile_); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 1084 | fileapi::FileSystemContext* filesystem_context = |
[email protected] | ac66e45 | 2013-01-11 09:21:23 | [diff] [blame] | 1085 | BrowserContext::GetStoragePartitionForSite(profile_, site)-> |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 1086 | GetFileSystemContext(); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 1087 | if (filesystem_context && filesystem_context->external_backend()) { |
| 1088 | filesystem_context->external_backend()-> |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1089 | RevokeAccessForExtension(extension->id()); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1090 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1091 | #endif |
| 1092 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1093 | // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't |
| 1094 | // work properly multi-profile. Besides which, it should be using |
| 1095 | // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1096 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1097 | } |
| 1098 | |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 1099 | content::BrowserContext* ExtensionService::GetBrowserContext() const { |
| 1100 | // Implemented in the .cc file to avoid adding a profile.h dependency to |
| 1101 | // extension_service.h. |
| 1102 | return profile_; |
| 1103 | } |
| 1104 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 1105 | bool ExtensionService::is_ready() { |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1106 | return ready_->is_signaled(); |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 1107 | } |
| 1108 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1109 | base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1110 | if (file_task_runner_.get()) |
| 1111 | return file_task_runner_.get(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1112 | |
| 1113 | // We should be able to interrupt any part of extension install process during |
| 1114 | // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks |
| 1115 | // will be ignored/deleted while we will block on started tasks. |
| 1116 | std::string token("ext_install-"); |
| 1117 | token.append(profile_->GetPath().AsUTF8Unsafe()); |
| 1118 | file_task_runner_ = BrowserThread::GetBlockingPool()-> |
| 1119 | GetSequencedTaskRunnerWithShutdownBehavior( |
| 1120 | BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), |
| 1121 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1122 | return file_task_runner_.get(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1123 | } |
| 1124 | |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 1125 | void ExtensionService::CheckManagementPolicy() { |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1126 | std::vector<std::string> to_unload; |
| 1127 | std::map<std::string, Extension::DisableReason> to_disable; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1128 | |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1129 | // Loop through the extensions list, finding extensions we need to unload or |
| 1130 | // disable. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1131 | const ExtensionSet& extensions = registry_->enabled_extensions(); |
| 1132 | for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 1133 | iter != extensions.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1134 | const Extension* extension = (iter->get()); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 1135 | if (!system_->management_policy()->UserMayLoad(extension, NULL)) |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1136 | to_unload.push_back(extension->id()); |
| 1137 | Extension::DisableReason disable_reason = Extension::DISABLE_NONE; |
| 1138 | if (system_->management_policy()->MustRemainDisabled( |
| 1139 | extension, &disable_reason, NULL)) |
| 1140 | to_disable[extension->id()] = disable_reason; |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1141 | } |
| 1142 | |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1143 | for (size_t i = 0; i < to_unload.size(); ++i) |
| 1144 | UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); |
| 1145 | |
| 1146 | for (std::map<std::string, Extension::DisableReason>::const_iterator i = |
| 1147 | to_disable.begin(); i != to_disable.end(); ++i) |
| 1148 | DisableExtension(i->first, i->second); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1149 | } |
| 1150 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1151 | void ExtensionService::CheckForUpdatesSoon() { |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1152 | // This can legitimately happen in unit tests. |
| 1153 | if (!updater_.get()) |
| 1154 | return; |
| 1155 | |
| 1156 | if (AreAllExternalProvidersReady()) { |
| 1157 | updater_->CheckSoon(); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1158 | } else { |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1159 | // Sync can start updating before all the external providers are ready |
| 1160 | // during startup. Start the update as soon as those providers are ready, |
| 1161 | // but not before. |
| 1162 | update_once_all_providers_are_ready_ = true; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1163 | } |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1164 | } |
| 1165 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1166 | // Some extensions will autoupdate themselves externally from Chrome. These |
| 1167 | // are typically part of some larger client application package. To support |
| 1168 | // these, the extension will register its location in the the preferences file |
| 1169 | // (and also, on Windows, in the registry) and this code will periodically |
| 1170 | // check that location for a .crx file, which it will then install locally if |
| 1171 | // a new version is available. |
| 1172 | // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 1173 | // reported. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1174 | void ExtensionService::CheckForExternalUpdates() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1175 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1176 | |
| 1177 | // Note that this installation is intentionally silent (since it didn't |
| 1178 | // go through the front-end). Extensions that are registered in this |
| 1179 | // way are effectively considered 'pre-bundled', and so implicitly |
| 1180 | // trusted. In general, if something has HKLM or filesystem access, |
| 1181 | // they could install an extension manually themselves anyway. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1182 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1183 | // Ask each external extension provider to give us a call back for each |
| 1184 | // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1185 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1186 | for (i = external_extension_providers_.begin(); |
| 1187 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1188 | extensions::ExternalProviderInterface* provider = i->get(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1189 | provider->VisitRegisteredExtension(); |
| 1190 | } |
| 1191 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1192 | // Do any required work that we would have done after completion of all |
| 1193 | // providers. |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 1194 | if (external_extension_providers_.empty()) |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1195 | OnAllExternalProvidersReady(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1196 | } |
| 1197 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1198 | void ExtensionService::OnExternalProviderReady( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1199 | const extensions::ExternalProviderInterface* provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1200 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1201 | CHECK(provider->IsReady()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1202 | |
| 1203 | // An external provider has finished loading. We only take action |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1204 | // if all of them are finished. So we check them first. |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1205 | if (AreAllExternalProvidersReady()) |
| 1206 | OnAllExternalProvidersReady(); |
| 1207 | } |
| 1208 | |
| 1209 | bool ExtensionService::AreAllExternalProvidersReady() const { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1210 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1211 | for (i = external_extension_providers_.begin(); |
| 1212 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1213 | if (!i->get()->IsReady()) |
| 1214 | return false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1215 | } |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1216 | return true; |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | void ExtensionService::OnAllExternalProvidersReady() { |
| 1220 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1221 | base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime(); |
| 1222 | UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1223 | |
| 1224 | // Install any pending extensions. |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1225 | if (update_once_all_providers_are_ready_ && updater()) { |
| 1226 | update_once_all_providers_are_ready_ = false; |
[email protected] | 4e9b59d | 2013-12-18 06:47:14 | [diff] [blame] | 1227 | extensions::ExtensionUpdater::CheckParams params; |
| 1228 | params.callback = external_updates_finished_callback_; |
| 1229 | updater()->CheckNow(params); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | // Uninstall all the unclaimed extensions. |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 1233 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1234 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 1235 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1236 | ExtensionInfo* info = extensions_info->at(i).get(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1237 | if (Manifest::IsExternalLocation(info->extension_location)) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1238 | CheckExternalUninstall(info->extension_id); |
| 1239 | } |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1240 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 1241 | error_controller_->ShowErrorIfNeeded(); |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1242 | |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 1243 | external_install_manager_->UpdateExternalExtensionAlert(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1244 | } |
| 1245 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1246 | void ExtensionService::UnloadExtension( |
| 1247 | const std::string& extension_id, |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1248 | UnloadedExtensionInfo::Reason reason) { |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 1249 | // Make sure the extension gets deleted after we return from this function. |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 1250 | int include_mask = |
| 1251 | ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1252 | scoped_refptr<const Extension> extension( |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 1253 | registry_->GetExtensionById(extension_id, include_mask)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1254 | |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1255 | // This method can be called via PostTask, so the extension may have been |
| 1256 | // unloaded by the time this runs. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1257 | if (!extension.get()) { |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1258 | // In case the extension may have crashed/uninstalled. Allow the profile to |
| 1259 | // clean up its RequestContexts. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1260 | system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1261 | return; |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1262 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1263 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1264 | // Keep information about the extension so that we can reload it later |
| 1265 | // even if it's not permanently installed. |
| 1266 | unloaded_extension_paths_[extension->id()] = extension->path(); |
| 1267 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1268 | // Clean up if the extension is meant to be enabled after a reload. |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1269 | reloading_extensions_.erase(extension->id()); |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1270 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1271 | if (registry_->disabled_extensions().Contains(extension->id())) { |
| 1272 | registry_->RemoveDisabled(extension->id()); |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1273 | // Make sure the profile cleans up its RequestContexts when an already |
| 1274 | // disabled extension is unloaded (since they are also tracking the disabled |
| 1275 | // extensions). |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1276 | system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 1277 | // Don't send the unloaded notification. It was sent when the extension |
| 1278 | // was disabled. |
[email protected] | 60a174a | 2013-08-02 20:29:28 | [diff] [blame] | 1279 | } else { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1280 | // Remove the extension from the enabled list. |
| 1281 | registry_->RemoveEnabled(extension->id()); |
[email protected] | 60a174a | 2013-08-02 20:29:28 | [diff] [blame] | 1282 | NotifyExtensionUnloaded(extension.get(), reason); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1283 | } |
| 1284 | |
[email protected] | fb78953 | 2013-08-27 02:40:21 | [diff] [blame] | 1285 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1286 | extensions::NOTIFICATION_EXTENSION_REMOVED, |
[email protected] | fb78953 | 2013-08-27 02:40:21 | [diff] [blame] | 1287 | content::Source<Profile>(profile_), |
| 1288 | content::Details<const Extension>(extension.get())); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1289 | } |
| 1290 | |
[email protected] | 8b1ec20 | 2013-09-05 02:09:50 | [diff] [blame] | 1291 | void ExtensionService::RemoveComponentExtension( |
| 1292 | const std::string& extension_id) { |
| 1293 | scoped_refptr<const Extension> extension( |
| 1294 | GetExtensionById(extension_id, false)); |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1295 | UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1296 | if (extension.get()) { |
| 1297 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1298 | extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1299 | content::Source<Profile>(profile_), |
| 1300 | content::Details<const Extension>(extension.get())); |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 1301 | ExtensionRegistry::Get(profile_)->TriggerOnUninstalled( |
| 1302 | extension.get(), extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1303 | } |
[email protected] | 8b1ec20 | 2013-09-05 02:09:50 | [diff] [blame] | 1304 | } |
| 1305 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1306 | void ExtensionService::UnloadAllExtensionsForTest() { |
| 1307 | UnloadAllExtensionsInternal(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1308 | } |
| 1309 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1310 | void ExtensionService::ReloadExtensionsForTest() { |
| 1311 | // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit |
| 1312 | // warning about calling test code in production. |
| 1313 | UnloadAllExtensionsInternal(); |
[email protected] | eac8833 | 2012-12-26 17:57:45 | [diff] [blame] | 1314 | component_loader_->LoadAll(); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 1315 | extensions::InstalledLoader(this).LoadAllExtensions(); |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1316 | // Don't call SetReadyAndNotifyListeners() since tests call this multiple |
| 1317 | // times. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1318 | } |
| 1319 | |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 1320 | void ExtensionService::SetReadyAndNotifyListeners() { |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1321 | ready_->Signal(); |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 1322 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1323 | extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 1324 | content::Source<Profile>(profile_), |
| 1325 | content::NotificationService::NoDetails()); |
| 1326 | } |
| 1327 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1328 | void ExtensionService::OnLoadedInstalledExtensions() { |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 1329 | if (updater_) |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 1330 | updater_->Start(); |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 1331 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 1332 | OnBlacklistUpdated(); |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 1333 | } |
| 1334 | |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1335 | void ExtensionService::AddExtension(const Extension* extension) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1336 | // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 1337 | // default extension state to DISABLED when the --disable-extensions flag |
| 1338 | // is set (http://crbug.com/29067). |
| 1339 | if (!extensions_enabled() && |
| 1340 | !extension->is_theme() && |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1341 | extension->location() != Manifest::COMPONENT && |
| 1342 | !Manifest::IsExternalLocation(extension->location())) { |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1343 | return; |
[email protected] | 330840c | 2012-08-29 22:21:01 | [diff] [blame] | 1344 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1345 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1346 | bool is_extension_upgrade = false; |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1347 | bool is_extension_installed = false; |
| 1348 | const Extension* old = GetInstalledExtension(extension->id()); |
| 1349 | if (old) { |
| 1350 | is_extension_installed = true; |
| 1351 | int version_compare_result = |
| 1352 | extension->version()->CompareTo(*(old->version())); |
| 1353 | is_extension_upgrade = version_compare_result > 0; |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1354 | // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 1355 | // that we aren't downgrading. |
| 1356 | if (!Manifest::IsUnpackedLocation(extension->location())) |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1357 | CHECK_GE(version_compare_result, 0); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1358 | } |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 1359 | system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1360 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1361 | // The extension is now loaded, remove its data from unloaded extension map. |
| 1362 | unloaded_extension_paths_.erase(extension->id()); |
| 1363 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1364 | // If a terminated extension is loaded, remove it from the terminated list. |
| 1365 | UntrackTerminatedExtension(extension->id()); |
| 1366 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1367 | // If the extension was disabled for a reload, then enable it. |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1368 | bool reloading = reloading_extensions_.erase(extension->id()) > 0; |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1369 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1370 | // Check if the extension's privileges have changed and mark the |
| 1371 | // extension disabled if necessary. |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1372 | CheckPermissionsIncrease(extension, is_extension_installed); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1373 | |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1374 | if (is_extension_installed && !reloading) { |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1375 | // To upgrade an extension in place, unload the old one and then load the |
| 1376 | // new one. ReloadExtension disables the extension, which is sufficient. |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1377 | UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1378 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1379 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1380 | if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 1381 | // Only prefs is checked for the blacklist. We rely on callers to check the |
| 1382 | // blacklist before calling into here, e.g. CrxInstaller checks before |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1383 | // installation then threads through the install and pending install flow |
| 1384 | // of this class, and we check when loading installed extensions. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1385 | registry_->AddBlacklisted(extension); |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1386 | } else if (!reloading && |
| 1387 | extension_prefs_->IsExtensionDisabled(extension->id())) { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1388 | registry_->AddDisabled(extension); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 1389 | if (extension_sync_service_) |
| 1390 | extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 1391 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1392 | extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 1393 | content::Source<Profile>(profile_), |
| 1394 | content::Details<const Extension>(extension)); |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 1395 | |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 1396 | // Show the extension disabled error if a permissions increase or a remote |
| 1397 | // installation is the reason it was disabled, and no other reasons exist. |
| 1398 | int reasons = extension_prefs_->GetDisableReasons(extension->id()); |
| 1399 | const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE | |
| 1400 | Extension::DISABLE_REMOTE_INSTALL; |
| 1401 | if (reasons & kReasonMask && !(reasons & ~kReasonMask)) { |
| 1402 | extensions::AddExtensionDisabledError( |
| 1403 | this, |
| 1404 | extension, |
| 1405 | extension_prefs_->HasDisableReason( |
| 1406 | extension->id(), Extension::DISABLE_REMOTE_INSTALL)); |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 1407 | } |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1408 | } else if (reloading) { |
| 1409 | // Replace the old extension with the new version. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1410 | CHECK(!registry_->AddDisabled(extension)); |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1411 | EnableExtension(extension->id()); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1412 | } else { |
| 1413 | // All apps that are displayed in the launcher are ordered by their ordinals |
| 1414 | // so we must ensure they have valid ordinals. |
| 1415 | if (extension->RequiresSortOrdinal()) { |
[email protected] | db37832 | 2014-07-21 23:19:34 | [diff] [blame] | 1416 | extension_prefs_->app_sorting()->SetExtensionVisible( |
| 1417 | extension->id(), |
| 1418 | extension->ShouldDisplayInNewTabPage() && |
| 1419 | !extension_prefs_->IsEphemeralApp(extension->id())); |
| 1420 | if (!extension_prefs_->IsEphemeralApp(extension->id())) { |
| 1421 | extension_prefs_->app_sorting()->EnsureValidOrdinals( |
| 1422 | extension->id(), syncer::StringOrdinal()); |
[email protected] | bd36b65 | 2013-02-27 02:13:25 | [diff] [blame] | 1423 | } |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1424 | } |
| 1425 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1426 | registry_->AddEnabled(extension); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 1427 | if (extension_sync_service_) |
| 1428 | extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1429 | NotifyExtensionLoaded(extension); |
[email protected] | f574c40 | 2012-12-04 23:20:31 | [diff] [blame] | 1430 | } |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 1431 | system_->runtime_data()->SetBeingUpgraded(extension, false); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1432 | } |
| 1433 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1434 | void ExtensionService::AddComponentExtension(const Extension* extension) { |
| 1435 | const std::string old_version_string( |
| 1436 | extension_prefs_->GetVersionString(extension->id())); |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1437 | const Version old_version(old_version_string); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1438 | |
[email protected] | 0181a7d | 2013-11-12 01:08:42 | [diff] [blame] | 1439 | VLOG(1) << "AddComponentExtension " << extension->name(); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1440 | if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
| 1441 | VLOG(1) << "Component extension " << extension->name() << " (" |
| 1442 | << extension->id() << ") installing/upgrading from '" |
| 1443 | << old_version_string << "' to " << extension->version()->GetString(); |
| 1444 | |
| 1445 | AddNewOrUpdatedExtension(extension, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1446 | Extension::ENABLED_COMPONENT, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1447 | extensions::kInstallFlagNone, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1448 | syncer::StringOrdinal(), |
| 1449 | std::string()); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1450 | return; |
| 1451 | } |
| 1452 | |
| 1453 | AddExtension(extension); |
| 1454 | } |
| 1455 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1456 | void ExtensionService::CheckPermissionsIncrease(const Extension* extension, |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1457 | bool is_extension_installed) { |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 1458 | extensions::PermissionsUpdater(profile_).InitializePermissions(extension); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1459 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1460 | // We keep track of all permissions the user has granted each extension. |
| 1461 | // This allows extensions to gracefully support backwards compatibility |
| 1462 | // by including unknown permissions in their manifests. When the user |
| 1463 | // installs the extension, only the recognized permissions are recorded. |
| 1464 | // When the unknown permissions become recognized (e.g., through browser |
| 1465 | // upgrade), we can prompt the user to accept these new permissions. |
| 1466 | // Extensions can also silently upgrade to less permissions, and then |
| 1467 | // silently upgrade to a version that adds these permissions back. |
| 1468 | // |
| 1469 | // For example, pretend that Chrome 10 includes a permission "omnibox" |
| 1470 | // for an API that adds suggestions to the omnibox. An extension can |
| 1471 | // maintain backwards compatibility while still having "omnibox" in the |
| 1472 | // manifest. If a user installs the extension on Chrome 9, the browser |
| 1473 | // will record the permissions it recognized, not including "omnibox." |
| 1474 | // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 1475 | // will disable the extension and prompt the user to approve the increase |
| 1476 | // in privileges. The extension could then release a new version that |
| 1477 | // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 1478 | // still remember that "omnibox" had been granted, so that if the |
| 1479 | // extension once again includes "omnibox" in an upgrade, the extension |
| 1480 | // can upgrade without requiring this user's approval. |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 1481 | int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1482 | |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 1483 | bool auto_grant_permission = |
[email protected] | 1b563df | 2013-10-30 16:49:36 | [diff] [blame] | 1484 | (!is_extension_installed && extension->was_installed_by_default()) || |
[email protected] | 45928b68 | 2013-11-28 08:20:27 | [diff] [blame] | 1485 | extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode(); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1486 | // Silently grant all active permissions to default apps only on install. |
| 1487 | // After install they should behave like other apps. |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 1488 | // Silently grant all active permissions to apps install in kiosk mode on both |
| 1489 | // install and update. |
| 1490 | if (auto_grant_permission) |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1491 | GrantPermissions(extension); |
| 1492 | |
| 1493 | bool is_privilege_increase = false; |
| 1494 | // We only need to compare the granted permissions to the current permissions |
| 1495 | // if the extension is not allowed to silently increase its permissions. |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 1496 | if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) && |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 1497 | !auto_grant_permission) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1498 | // Add all the recognized permissions if the granted permissions list |
| 1499 | // hasn't been initialized yet. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1500 | scoped_refptr<PermissionSet> granted_permissions = |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1501 | extension_prefs_->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1502 | CHECK(granted_permissions.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1503 | |
| 1504 | // Here, we check if an extension's privileges have increased in a manner |
| 1505 | // that requires the user's approval. This could occur because the browser |
| 1506 | // upgraded and recognized additional privileges, or an extension upgrades |
| 1507 | // to a version that requires additional privileges. |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 1508 | is_privilege_increase = |
| 1509 | extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease( |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 1510 | granted_permissions, |
| 1511 | extension->permissions_data()->active_permissions().get(), |
| 1512 | extension->GetType()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1513 | } |
| 1514 | |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1515 | if (is_extension_installed) { |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 1516 | // If the extension was already disabled, suppress any alerts for becoming |
| 1517 | // disabled on permissions increase. |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1518 | bool previously_disabled = |
| 1519 | extension_prefs_->IsExtensionDisabled(extension->id()); |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1520 | // Legacy disabled extensions do not have a disable reason. Infer that if |
| 1521 | // there was no permission increase, it was likely disabled by the user. |
| 1522 | if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1523 | !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1524 | disable_reasons |= Extension::DISABLE_USER_ACTION; |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 1525 | } |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1526 | // Extensions that came to us disabled from sync need a similar inference, |
| 1527 | // except based on the new version's permissions. |
| 1528 | if (previously_disabled && |
| 1529 | disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) { |
| 1530 | // Remove the DISABLE_UNKNOWN_FROM_SYNC reason. |
| 1531 | extension_prefs_->ClearDisableReasons(extension->id()); |
| 1532 | if (!is_privilege_increase) |
| 1533 | disable_reasons |= Extension::DISABLE_USER_ACTION; |
| 1534 | } |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1535 | disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | // Extension has changed permissions significantly. Disable it. A |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 1539 | // notification should be sent by the caller. If the extension is already |
| 1540 | // disabled because it was installed remotely, don't add another disable |
| 1541 | // reason, but instead always set the "did escalate permissions" flag, to |
| 1542 | // ensure enabling it will always show a warning. |
| 1543 | if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) { |
| 1544 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 1545 | } else if (is_privilege_increase) { |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1546 | disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1547 | if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
[email protected] | 4c86be58 | 2014-06-04 08:39:11 | [diff] [blame] | 1548 | RecordPermissionMessagesHistogram(extension, |
| 1549 | "Extensions.Permissions_AutoDisable2"); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1550 | } |
[email protected] | 195c158 | 2013-10-29 18:42:23 | [diff] [blame] | 1551 | extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1552 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1553 | } |
| 1554 | if (disable_reasons != Extension::DISABLE_NONE) { |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 1555 | extension_prefs_->AddDisableReason( |
| 1556 | extension->id(), |
| 1557 | static_cast<Extension::DisableReason>(disable_reasons)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1558 | } |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1559 | } |
| 1560 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1561 | void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 1562 | std::set<std::string> extension_ids; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1563 | const ExtensionSet& extensions = registry_->enabled_extensions(); |
| 1564 | for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 1565 | iter != extensions.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1566 | const Extension* extension = iter->get(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1567 | if (!extension->is_theme() && extension->location() != Manifest::COMPONENT) |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1568 | extension_ids.insert(extension->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1569 | } |
| 1570 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1571 | // TODO(kalman): This is broken. ExtensionService is per-profile. |
| 1572 | // crash_keys::SetActiveExtensions is per-process. See |
| 1573 | // http://crbug.com/355029. |
[email protected] | f6431be8 | 2013-09-07 02:53:45 | [diff] [blame] | 1574 | crash_keys::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1575 | } |
| 1576 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 1577 | void ExtensionService::OnExtensionInstalled( |
[email protected] | 36a5c4c | 2011-12-14 16:34:50 | [diff] [blame] | 1578 | const Extension* extension, |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 1579 | const syncer::StringOrdinal& page_ordinal, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1580 | int install_flags) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1581 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1582 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1583 | const std::string& id = extension->id(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1584 | bool initial_enable = ShouldEnableOnInstall(extension); |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1585 | std::string install_parameter; |
[email protected] | 96aebe2 | 2014-07-16 04:07:51 | [diff] [blame] | 1586 | const extensions::PendingExtensionInfo* pending_extension_info = |
| 1587 | pending_extension_manager()->GetById(id); |
| 1588 | if (pending_extension_info) { |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 1589 | if (!pending_extension_info->ShouldAllowInstall(extension)) { |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1590 | pending_extension_manager()->Remove(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 1591 | |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1592 | LOG(WARNING) << "ShouldAllowInstall() returned false for " |
| 1593 | << id << " of type " << extension->GetType() |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 1594 | << " and update URL " |
| 1595 | << extensions::ManifestURL::GetUpdateURL(extension).spec() |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1596 | << "; not installing"; |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 1597 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1598 | // Delete the extension directory since we're not going to |
| 1599 | // load it. |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1600 | if (!GetFileTaskRunner()->PostTask( |
| 1601 | FROM_HERE, |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 1602 | base::Bind(&extensions::file_util::DeleteFile, |
| 1603 | extension->path(), |
| 1604 | true))) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1605 | NOTREACHED(); |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1606 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1607 | return; |
| 1608 | } |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1609 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1610 | install_parameter = pending_extension_info->install_parameter(); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1611 | pending_extension_manager()->Remove(id); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1612 | } else { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1613 | // We explicitly want to re-enable an uninstalled external |
| 1614 | // extension; if we're here, that means the user is manually |
| 1615 | // installing the extension. |
[email protected] | 46f3e10 | 2014-03-25 01:22:45 | [diff] [blame] | 1616 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) { |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1617 | initial_enable = true; |
| 1618 | } |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 1619 | } |
| 1620 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 1621 | // Unsupported requirements overrides the management policy. |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1622 | if (install_flags & extensions::kInstallFlagHasRequirementErrors) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 1623 | initial_enable = false; |
| 1624 | extension_prefs_->AddDisableReason( |
| 1625 | id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); |
| 1626 | // If the extension was disabled because of unsupported requirements but |
| 1627 | // now supports all requirements after an update and there are not other |
| 1628 | // disable reasons, enable it. |
| 1629 | } else if (extension_prefs_->GetDisableReasons(id) == |
| 1630 | Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { |
| 1631 | initial_enable = true; |
| 1632 | extension_prefs_->ClearDisableReasons(id); |
| 1633 | } |
| 1634 | |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1635 | if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1636 | // Installation of a blacklisted extension can happen from sync, policy, |
| 1637 | // etc, where to maintain consistency we need to install it, just never |
| 1638 | // load it (see AddExtension). Usually it should be the job of callers to |
| 1639 | // incercept blacklisted extension earlier (e.g. CrxInstaller, before even |
| 1640 | // showing the install dialogue). |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 1641 | extension_prefs_->AcknowledgeBlacklistedExtension(id); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1642 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", |
| 1643 | extension->location(), |
| 1644 | Manifest::NUM_LOCATIONS); |
| 1645 | } |
| 1646 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1647 | if (!GetInstalledExtension(extension->id())) { |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 1648 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 1649 | extension->GetType(), 100); |
[email protected] | 69084dc | 2012-11-17 07:39:30 | [diff] [blame] | 1650 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1651 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 4c86be58 | 2014-06-04 08:39:11 | [diff] [blame] | 1652 | RecordPermissionMessagesHistogram(extension, |
| 1653 | "Extensions.Permissions_Install2"); |
[email protected] | 69084dc | 2012-11-17 07:39:30 | [diff] [blame] | 1654 | } else { |
| 1655 | UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
| 1656 | extension->GetType(), 100); |
| 1657 | UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1658 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 1659 | |
| 1660 | // A fully installed app cannot be demoted to an ephemeral app. |
| 1661 | if ((install_flags & extensions::kInstallFlagIsEphemeral) && |
| 1662 | !extension_prefs_->IsEphemeralApp(id)) { |
| 1663 | install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); |
| 1664 | } |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 1665 | } |
| 1666 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1667 | const Extension::State initial_state = |
| 1668 | initial_enable ? Extension::ENABLED : Extension::DISABLED; |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1669 | if (ShouldDelayExtensionUpdate( |
| 1670 | id, |
| 1671 | !!(install_flags & extensions::kInstallFlagInstallImmediately))) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1672 | extension_prefs_->SetDelayedInstallInfo( |
| 1673 | extension, |
| 1674 | initial_state, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1675 | install_flags, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1676 | extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1677 | page_ordinal, |
| 1678 | install_parameter); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1679 | |
| 1680 | // Transfer ownership of |extension|. |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1681 | delayed_installs_.Insert(extension); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1682 | |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 1683 | // Notify observers that app update is available. |
| 1684 | FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
[email protected] | a9aa62b31 | 2013-11-29 05:35:06 | [diff] [blame] | 1685 | OnAppUpdateAvailable(extension)); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1686 | return; |
| 1687 | } |
| 1688 | |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1689 | extensions::SharedModuleService::ImportStatus status = |
| 1690 | shared_module_service_->SatisfyImports(extension); |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 1691 | if (installs_delayed_for_gc_) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1692 | extension_prefs_->SetDelayedInstallInfo( |
| 1693 | extension, |
| 1694 | initial_state, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1695 | install_flags, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1696 | extensions::ExtensionPrefs::DELAY_REASON_GC, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1697 | page_ordinal, |
| 1698 | install_parameter); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1699 | delayed_installs_.Insert(extension); |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1700 | } else if (status != SharedModuleService::IMPORT_STATUS_OK) { |
| 1701 | if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1702 | extension_prefs_->SetDelayedInstallInfo( |
| 1703 | extension, |
| 1704 | initial_state, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1705 | install_flags, |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1706 | extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1707 | page_ordinal, |
| 1708 | install_parameter); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1709 | delayed_installs_.Insert(extension); |
| 1710 | } |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1711 | } else { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1712 | AddNewOrUpdatedExtension(extension, |
| 1713 | initial_state, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1714 | install_flags, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1715 | page_ordinal, |
| 1716 | install_parameter); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1717 | } |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | void ExtensionService::AddNewOrUpdatedExtension( |
| 1721 | const Extension* extension, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1722 | Extension::State initial_state, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1723 | int install_flags, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1724 | const syncer::StringOrdinal& page_ordinal, |
| 1725 | const std::string& install_parameter) { |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1726 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1727 | bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1728 | extension_prefs_->OnExtensionInstalled( |
| 1729 | extension, initial_state, page_ordinal, install_flags, install_parameter); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 1730 | delayed_installs_.Remove(extension->id()); |
[email protected] | 913ffca9 | 2014-03-27 15:26:16 | [diff] [blame] | 1731 | if (InstallVerifier::NeedsVerification(*extension)) |
| 1732 | system_->install_verifier()->VerifyExtension(extension->id()); |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1733 | FinishInstallation(extension, was_ephemeral); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | void ExtensionService::MaybeFinishDelayedInstallation( |
| 1737 | const std::string& extension_id) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1738 | // Check if the extension already got installed. |
| 1739 | if (!delayed_installs_.Contains(extension_id)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1740 | return; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1741 | extensions::ExtensionPrefs::DelayReason reason = |
| 1742 | extension_prefs_->GetDelayedInstallReason(extension_id); |
| 1743 | |
| 1744 | // Check if the extension is idle. DELAY_REASON_NONE is used for older |
| 1745 | // preferences files that will not have set this field but it was previously |
| 1746 | // only used for idle updates. |
| 1747 | if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE || |
| 1748 | reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) && |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 1749 | is_ready() && !extensions::util::IsExtensionIdle(extension_id, profile_)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1750 | return; |
| 1751 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1752 | const Extension* extension = delayed_installs_.GetByID(extension_id); |
| 1753 | if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) { |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1754 | extensions::SharedModuleService::ImportStatus status = |
| 1755 | shared_module_service_->SatisfyImports(extension); |
| 1756 | if (status != SharedModuleService::IMPORT_STATUS_OK) { |
| 1757 | if (status == SharedModuleService::IMPORT_STATUS_UNRECOVERABLE) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1758 | delayed_installs_.Remove(extension_id); |
| 1759 | // Make sure no version of the extension is actually installed, (i.e., |
| 1760 | // that this delayed install was not an update). |
| 1761 | CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get()); |
| 1762 | extension_prefs_->DeleteExtensionPrefs(extension_id); |
| 1763 | } |
| 1764 | return; |
| 1765 | } |
| 1766 | } |
| 1767 | |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1768 | FinishDelayedInstallation(extension_id); |
| 1769 | } |
| 1770 | |
| 1771 | void ExtensionService::FinishDelayedInstallation( |
| 1772 | const std::string& extension_id) { |
| 1773 | scoped_refptr<const Extension> extension( |
| 1774 | GetPendingExtensionUpdate(extension_id)); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1775 | CHECK(extension.get()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1776 | delayed_installs_.Remove(extension_id); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1777 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1778 | bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1779 | if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1780 | NOTREACHED(); |
| 1781 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1782 | FinishInstallation(extension.get(), was_ephemeral); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1783 | } |
| 1784 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1785 | void ExtensionService::FinishInstallation( |
| 1786 | const Extension* extension, bool was_ephemeral) { |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 1787 | const extensions::Extension* existing_extension = |
| 1788 | GetInstalledExtension(extension->id()); |
| 1789 | bool is_update = false; |
| 1790 | std::string old_name; |
| 1791 | if (existing_extension) { |
| 1792 | is_update = true; |
| 1793 | old_name = existing_extension->name(); |
| 1794 | } |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1795 | bool from_ephemeral = |
| 1796 | was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id()); |
| 1797 | extensions::InstalledExtensionInfo details( |
| 1798 | extension, is_update, from_ephemeral, old_name); |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1799 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1800 | extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1801 | content::Source<Profile>(profile_), |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1802 | content::Details<const extensions::InstalledExtensionInfo>(&details)); |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1803 | |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 1804 | registry_->TriggerOnWillBeInstalled( |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1805 | extension, is_update, from_ephemeral, old_name); |
[email protected] | 17f0782 | 2014-05-22 08:45:15 | [diff] [blame] | 1806 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1807 | // Unpacked extensions default to allowing file access, but if that has been |
| 1808 | // overridden, don't reset the value. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1809 | if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1810 | !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { |
| 1811 | extension_prefs_->SetAllowFileAccess(extension->id(), true); |
| 1812 | } |
| 1813 | |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1814 | AddExtension(extension); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1815 | |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 1816 | // Notify observers that need to know when an installation is complete. |
[email protected] | 38e87253 | 2014-07-16 23:27:51 | [diff] [blame] | 1817 | registry_->TriggerOnInstalled(extension, is_update); |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 1818 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1819 | // Check extensions that may have been delayed only because this shared module |
| 1820 | // was not available. |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 1821 | if (SharedModuleInfo::IsSharedModule(extension)) |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1822 | MaybeFinishDelayedInstallations(); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 1823 | } |
| 1824 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1825 | void ExtensionService::PromoteEphemeralApp( |
| 1826 | const extensions::Extension* extension, bool is_from_sync) { |
| 1827 | DCHECK(GetInstalledExtension(extension->id()) && |
| 1828 | extension_prefs_->IsEphemeralApp(extension->id())); |
| 1829 | |
[email protected] | db37832 | 2014-07-21 23:19:34 | [diff] [blame] | 1830 | if (extension->RequiresSortOrdinal()) { |
| 1831 | extension_prefs_->app_sorting()->SetExtensionVisible( |
| 1832 | extension->id(), extension->ShouldDisplayInNewTabPage()); |
| 1833 | |
| 1834 | if (!is_from_sync) { |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1835 | // Reset the sort ordinals of the app to ensure it is added to the default |
| 1836 | // position, like newly installed apps would. |
| 1837 | extension_prefs_->app_sorting()->ClearOrdinals(extension->id()); |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1838 | } |
| 1839 | |
[email protected] | db37832 | 2014-07-21 23:19:34 | [diff] [blame] | 1840 | extension_prefs_->app_sorting()->EnsureValidOrdinals( |
| 1841 | extension->id(), syncer::StringOrdinal()); |
| 1842 | } |
| 1843 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1844 | // Remove the ephemeral flags from the preferences. |
| 1845 | extension_prefs_->OnEphemeralAppPromoted(extension->id()); |
| 1846 | |
| 1847 | // Fire install-related events to allow observers to handle the promotion |
| 1848 | // of the ephemeral app. |
| 1849 | extensions::InstalledExtensionInfo details( |
| 1850 | extension, |
| 1851 | true /* is update */, |
| 1852 | true /* from ephemeral */, |
| 1853 | extension->name() /* old name */); |
| 1854 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1855 | extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1856 | content::Source<Profile>(profile_), |
| 1857 | content::Details<const extensions::InstalledExtensionInfo>(&details)); |
| 1858 | |
| 1859 | registry_->TriggerOnWillBeInstalled( |
| 1860 | extension, |
| 1861 | true /* is update */, |
| 1862 | true /* from ephemeral */, |
| 1863 | extension->name() /* old name */); |
| 1864 | |
| 1865 | if (registry_->enabled_extensions().Contains(extension->id())) { |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 1866 | // If the app is already enabled and loaded, fire the load events to allow |
| 1867 | // observers to handle the promotion of the ephemeral app. |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1868 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1869 | extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1870 | content::Source<Profile>(profile_), |
| 1871 | content::Details<const Extension>(extension)); |
| 1872 | |
| 1873 | registry_->TriggerOnLoaded(extension); |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 1874 | } else { |
| 1875 | // Cached ephemeral apps may be updated and disabled due to permissions |
| 1876 | // increase. The app can be enabled (as long as no other disable reasons |
| 1877 | // exist) as the install was user-acknowledged. |
| 1878 | int disable_mask = Extension::DISABLE_NONE; |
| 1879 | if (!is_from_sync) |
| 1880 | disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE; |
| 1881 | |
| 1882 | int other_disable_reasons = |
| 1883 | extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask; |
| 1884 | if (!other_disable_reasons) { |
| 1885 | if (extension_prefs_->DidExtensionEscalatePermissions(extension->id())) |
| 1886 | GrantPermissionsAndEnableExtension(extension); |
| 1887 | else |
| 1888 | EnableExtension(extension->id()); |
| 1889 | } |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1890 | } |
| 1891 | |
[email protected] | 38e87253 | 2014-07-16 23:27:51 | [diff] [blame] | 1892 | registry_->TriggerOnInstalled(extension, true); |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 1893 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1894 | if (!is_from_sync && extension_sync_service_) |
| 1895 | extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
| 1896 | } |
| 1897 | |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 1898 | const Extension* ExtensionService::GetPendingExtensionUpdate( |
| 1899 | const std::string& id) const { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1900 | return delayed_installs_.GetByID(id); |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 1901 | } |
| 1902 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1903 | void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1904 | // No need to check for duplicates; inserting a duplicate is a no-op. |
| 1905 | registry_->AddTerminated(make_scoped_refptr(extension)); |
[email protected] | 3964e57 | 2014-02-13 21:57:41 | [diff] [blame] | 1906 | extensions_being_terminated_.erase(extension->id()); |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1907 | UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1908 | } |
| 1909 | |
[email protected] | e9d7496e | 2014-04-18 01:25:46 | [diff] [blame] | 1910 | void ExtensionService::TerminateExtension(const std::string& extension_id) { |
| 1911 | const Extension* extension = GetInstalledExtension(extension_id); |
| 1912 | TrackTerminatedExtension(extension); |
| 1913 | } |
| 1914 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1915 | void ExtensionService::UntrackTerminatedExtension(const std::string& id) { |
[email protected] | cb1f4ac | 2014-08-07 16:55:42 | [diff] [blame] | 1916 | std::string lowercase_id = base::StringToLowerASCII(id); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1917 | const Extension* extension = |
| 1918 | registry_->terminated_extensions().GetByID(lowercase_id); |
| 1919 | registry_->RemoveTerminated(lowercase_id); |
[email protected] | fb78953 | 2013-08-27 02:40:21 | [diff] [blame] | 1920 | if (extension) { |
| 1921 | content::NotificationService::current()->Notify( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1922 | extensions::NOTIFICATION_EXTENSION_REMOVED, |
[email protected] | fb78953 | 2013-08-27 02:40:21 | [diff] [blame] | 1923 | content::Source<Profile>(profile_), |
| 1924 | content::Details<const Extension>(extension)); |
| 1925 | } |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1926 | } |
| 1927 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 1928 | const Extension* ExtensionService::GetInstalledExtension( |
| 1929 | const std::string& id) const { |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 1930 | return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 1931 | } |
| 1932 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1933 | bool ExtensionService::OnExternalExtensionFileFound( |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 1934 | const std::string& id, |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1935 | const Version* version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1936 | const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1937 | Manifest::Location location, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1938 | int creation_flags, |
| 1939 | bool mark_acknowledged) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 1940 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 1941 | CHECK(Extension::IdIsValid(id)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1942 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1943 | return false; |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1944 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1945 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 1946 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1947 | // installed on every startup. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1948 | const Extension* existing = GetExtensionById(id, true); |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1949 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1950 | if (existing) { |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1951 | // The default apps will have the location set as INTERNAL. Since older |
| 1952 | // default apps are installed as EXTERNAL, we override them. However, if the |
| 1953 | // app is already installed as internal, then do the version check. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1954 | // TODO(grv) : Remove after Q1-2013. |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1955 | bool is_default_apps_migration = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1956 | (location == Manifest::INTERNAL && |
| 1957 | Manifest::IsExternalLocation(existing->location())); |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1958 | |
| 1959 | if (!is_default_apps_migration) { |
| 1960 | DCHECK(version); |
| 1961 | |
| 1962 | switch (existing->version()->CompareTo(*version)) { |
| 1963 | case -1: // existing version is older, we should upgrade |
| 1964 | break; |
| 1965 | case 0: // existing version is same, do nothing |
| 1966 | return false; |
| 1967 | case 1: // existing version is newer, uh-oh |
| 1968 | LOG(WARNING) << "Found external version of extension " << id |
| 1969 | << "that is older than current version. Current version " |
| 1970 | << "is: " << existing->VersionString() << ". New " |
| 1971 | << "version is: " << version->GetString() |
| 1972 | << ". Keeping current version."; |
| 1973 | return false; |
| 1974 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1975 | } |
| 1976 | } |
| 1977 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1978 | // If the extension is already pending, don't start an install. |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 1979 | if (!pending_extension_manager()->AddFromExternalFile( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 1980 | id, location, *version, creation_flags, mark_acknowledged)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1981 | return false; |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 1982 | } |
[email protected] | 9c635f2 | 2010-12-02 09:36:36 | [diff] [blame] | 1983 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1984 | // no client (silent install) |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 1985 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1986 | installer->set_install_source(location); |
| 1987 | installer->set_expected_id(id); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 1988 | installer->set_expected_version(*version); |
| 1989 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1990 | installer->set_creation_flags(creation_flags); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 1991 | #if defined(OS_CHROMEOS) |
| 1992 | extensions::InstallLimiter::Get(profile_)->Add(installer, path); |
| 1993 | #else |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1994 | installer->InstallCrx(path); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 1995 | #endif |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1996 | |
| 1997 | // Depending on the source, a new external extension might not need a user |
| 1998 | // notification on installation. For such extensions, mark them acknowledged |
| 1999 | // now to suppress the notification. |
| 2000 | if (mark_acknowledged) |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 2001 | external_install_manager_->AcknowledgeExternalExtension(id); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2002 | |
| 2003 | return true; |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2004 | } |
| 2005 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2006 | void ExtensionService::DidCreateRenderViewForBackgroundPage( |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 2007 | extensions::ExtensionHost* host) { |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2008 | OrphanedDevTools::iterator iter = |
[email protected] | 2d2f6cfc | 2011-05-06 21:09:33 | [diff] [blame] | 2009 | orphaned_dev_tools_.find(host->extension_id()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2010 | if (iter == orphaned_dev_tools_.end()) |
| 2011 | return; |
| 2012 | |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 2013 | iter->second->ConnectWebContents(host->host_contents()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2014 | orphaned_dev_tools_.erase(iter); |
| 2015 | } |
| 2016 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2017 | void ExtensionService::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2018 | const content::NotificationSource& source, |
| 2019 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2020 | switch (type) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2021 | case chrome::NOTIFICATION_APP_TERMINATING: |
| 2022 | // Shutdown has started. Don't start any more extension installs. |
| 2023 | // (We cannot use ExtensionService::Shutdown() for this because it |
| 2024 | // happens too late in browser teardown.) |
| 2025 | browser_terminating_ = true; |
| 2026 | break; |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 2027 | case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2028 | if (profile_ != |
| 2029 | content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 2030 | break; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2031 | } |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 2032 | |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 2033 | extensions::ExtensionHost* host = |
| 2034 | content::Details<extensions::ExtensionHost>(details).ptr(); |
[email protected] | f128af4 | 2010-08-05 18:05:26 | [diff] [blame] | 2035 | |
[email protected] | 3964e57 | 2014-02-13 21:57:41 | [diff] [blame] | 2036 | // If the extension is already being terminated, there is nothing left to |
| 2037 | // do. |
| 2038 | if (!extensions_being_terminated_.insert(host->extension_id()).second) |
| 2039 | break; |
| 2040 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2041 | // Mark the extension as terminated and Unload it. We want it to |
| 2042 | // be in a consistent state: either fully working or not loaded |
| 2043 | // at all, but never half-crashed. We do it in a PostTask so |
| 2044 | // that other handlers of this notification will still have |
| 2045 | // access to the Extension and ExtensionHost. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 2046 | base::MessageLoop::current()->PostTask( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2047 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 2048 | base::Bind( |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2049 | &ExtensionService::TrackTerminatedExtension, |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2050 | AsWeakPtr(), |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2051 | host->extension())); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2052 | break; |
| 2053 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2054 | case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2055 | content::RenderProcessHost* process = |
| 2056 | content::Source<content::RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2057 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2058 | Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2059 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2060 | break; |
| 2061 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 2062 | extensions::ProcessMap* process_map = |
| 2063 | extensions::ProcessMap::Get(profile_); |
| 2064 | if (process_map->Contains(process->GetID())) { |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 2065 | // An extension process was terminated, this might have resulted in an |
| 2066 | // app or extension becoming idle. |
| 2067 | std::set<std::string> extension_ids = |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 2068 | process_map->GetExtensionsInProcess(process->GetID()); |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 2069 | for (std::set<std::string>::const_iterator it = extension_ids.begin(); |
| 2070 | it != extension_ids.end(); ++it) { |
| 2071 | if (delayed_installs_.Contains(*it)) { |
| 2072 | base::MessageLoop::current()->PostDelayedTask( |
| 2073 | FROM_HERE, |
| 2074 | base::Bind(&ExtensionService::MaybeFinishDelayedInstallation, |
| 2075 | AsWeakPtr(), *it), |
| 2076 | base::TimeDelta::FromSeconds(kUpdateIdleDelay)); |
| 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 2081 | process_map->RemoveAllFromProcess(process->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 2082 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 2083 | BrowserThread::IO, |
| 2084 | FROM_HERE, |
| 2085 | base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess, |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 2086 | system_->info_map(), |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2087 | process->GetID())); |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2088 | break; |
| 2089 | } |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 2090 | case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2091 | // Notify observers that chrome update is available. |
| 2092 | FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
| 2093 | OnChromeUpdateAvailable()); |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 2094 | break; |
| 2095 | } |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 2096 | case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: { |
| 2097 | OnProfileDestructionStarted(); |
| 2098 | break; |
| 2099 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2100 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 2101 | default: |
| 2102 | NOTREACHED() << "Unexpected notification type."; |
| 2103 | } |
| 2104 | } |
| 2105 | |
[email protected] | 90bb38d | 2012-11-14 18:36:03 | [diff] [blame] | 2106 | void ExtensionService::OnExtensionInstallPrefChanged() { |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 2107 | error_controller_->ShowErrorIfNeeded(); |
[email protected] | a6a7ced | 2012-11-01 17:24:18 | [diff] [blame] | 2108 | CheckManagementPolicy(); |
| 2109 | } |
| 2110 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2111 | bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { |
| 2112 | // Extensions installed by policy can't be disabled. So even if a previous |
| 2113 | // installation disabled the extension, make sure it is now enabled. |
[email protected] | ab89454 | 2014-07-03 12:35:39 | [diff] [blame] | 2114 | if (system_->management_policy()->MustRemainEnabled(extension, NULL)) |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2115 | return true; |
| 2116 | |
| 2117 | if (extension_prefs_->IsExtensionDisabled(extension->id())) |
| 2118 | return false; |
| 2119 | |
[email protected] | 41070e8d | 2012-10-24 01:34:36 | [diff] [blame] | 2120 | if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2121 | // External extensions are initially disabled. We prompt the user before |
[email protected] | 2c495c4 | 2013-01-04 21:49:54 | [diff] [blame] | 2122 | // enabling them. Hosted apps are excepted because they are not dangerous |
| 2123 | // (they need to be launched by the user anyway). |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2124 | if (extension->GetType() != Manifest::TYPE_HOSTED_APP && |
| 2125 | Manifest::IsExternalLocation(extension->location()) && |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2126 | !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) { |
| 2127 | return false; |
| 2128 | } |
| 2129 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2130 | |
| 2131 | return true; |
| 2132 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2133 | |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2134 | bool ExtensionService::ShouldDelayExtensionUpdate( |
| 2135 | const std::string& extension_id, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 2136 | bool install_immediately) const { |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2137 | const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
| 2138 | |
| 2139 | // If delayed updates are globally disabled, or just for this extension, |
| 2140 | // don't delay. |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 2141 | if (!install_updates_when_idle_ || install_immediately) |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2142 | return false; |
| 2143 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2144 | const Extension* old = GetInstalledExtension(extension_id); |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2145 | // If there is no old extension, this is not an update, so don't delay. |
| 2146 | if (!old) |
| 2147 | return false; |
| 2148 | |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2149 | if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) { |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2150 | // Delay installation if the extension listens for the onUpdateAvailable |
| 2151 | // event. |
| 2152 | return system_->event_router()->ExtensionHasEventListener( |
| 2153 | extension_id, kOnUpdateAvailableEvent); |
| 2154 | } else { |
| 2155 | // Delay installation if the extension is not idle. |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 2156 | return !extensions::util::IsExtensionIdle(extension_id, profile_); |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2157 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2158 | } |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 2159 | |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 2160 | void ExtensionService::OnGarbageCollectIsolatedStorageStart() { |
| 2161 | DCHECK(!installs_delayed_for_gc_); |
| 2162 | installs_delayed_for_gc_ = true; |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | void ExtensionService::OnGarbageCollectIsolatedStorageFinished() { |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 2166 | DCHECK(installs_delayed_for_gc_); |
| 2167 | installs_delayed_for_gc_ = false; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2168 | MaybeFinishDelayedInstallations(); |
| 2169 | } |
| 2170 | |
| 2171 | void ExtensionService::MaybeFinishDelayedInstallations() { |
| 2172 | std::vector<std::string> to_be_installed; |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2173 | for (ExtensionSet::const_iterator it = delayed_installs_.begin(); |
| 2174 | it != delayed_installs_.end(); |
| 2175 | ++it) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2176 | to_be_installed.push_back((*it)->id()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2177 | } |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2178 | for (std::vector<std::string>::const_iterator it = to_be_installed.begin(); |
| 2179 | it != to_be_installed.end(); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2180 | ++it) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2181 | MaybeFinishDelayedInstallation(*it); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2182 | } |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2183 | } |
| 2184 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 2185 | void ExtensionService::OnBlacklistUpdated() { |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2186 | blacklist_->GetBlacklistedIDs( |
[email protected] | f47f717 | 2014-03-19 19:27:10 | [diff] [blame] | 2187 | registry_->GenerateInstalledExtensionsSet()->GetIDs(), |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2188 | base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr())); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2189 | } |
| 2190 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2191 | void ExtensionService::ManageBlacklist( |
| 2192 | const extensions::Blacklist::BlacklistStateMap& state_map) { |
[email protected] | 54ee819 | 2014-03-29 17:37:24 | [diff] [blame] | 2193 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2194 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2195 | std::set<std::string> blocked; |
| 2196 | ExtensionIdSet greylist; |
| 2197 | ExtensionIdSet unchanged; |
| 2198 | for (extensions::Blacklist::BlacklistStateMap::const_iterator it = |
| 2199 | state_map.begin(); |
| 2200 | it != state_map.end(); |
| 2201 | ++it) { |
| 2202 | switch (it->second) { |
| 2203 | case extensions::NOT_BLACKLISTED: |
| 2204 | break; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2205 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2206 | case extensions::BLACKLISTED_MALWARE: |
| 2207 | blocked.insert(it->first); |
| 2208 | break; |
| 2209 | |
| 2210 | case extensions::BLACKLISTED_SECURITY_VULNERABILITY: |
| 2211 | case extensions::BLACKLISTED_CWS_POLICY_VIOLATION: |
| 2212 | case extensions::BLACKLISTED_POTENTIALLY_UNWANTED: |
| 2213 | greylist.insert(it->first); |
| 2214 | break; |
| 2215 | |
| 2216 | case extensions::BLACKLISTED_UNKNOWN: |
| 2217 | unchanged.insert(it->first); |
| 2218 | break; |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | UpdateBlockedExtensions(blocked, unchanged); |
| 2223 | UpdateGreylistedExtensions(greylist, unchanged, state_map); |
| 2224 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 2225 | error_controller_->ShowErrorIfNeeded(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | namespace { |
| 2229 | void Partition(const ExtensionIdSet& before, |
| 2230 | const ExtensionIdSet& after, |
| 2231 | const ExtensionIdSet& unchanged, |
| 2232 | ExtensionIdSet* no_longer, |
| 2233 | ExtensionIdSet* not_yet) { |
| 2234 | *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before); |
| 2235 | *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after); |
| 2236 | *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged); |
| 2237 | } |
| 2238 | } // namespace |
| 2239 | |
| 2240 | void ExtensionService::UpdateBlockedExtensions( |
| 2241 | const ExtensionIdSet& blocked, |
| 2242 | const ExtensionIdSet& unchanged) { |
| 2243 | ExtensionIdSet not_yet_blocked, no_longer_blocked; |
| 2244 | Partition(registry_->blacklisted_extensions().GetIDs(), |
| 2245 | blocked, unchanged, |
| 2246 | &no_longer_blocked, ¬_yet_blocked); |
| 2247 | |
| 2248 | for (ExtensionIdSet::iterator it = no_longer_blocked.begin(); |
| 2249 | it != no_longer_blocked.end(); ++it) { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2250 | scoped_refptr<const Extension> extension = |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2251 | registry_->blacklisted_extensions().GetByID(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2252 | if (!extension.get()) { |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2253 | NOTREACHED() << "Extension " << *it << " no longer blocked, " |
| 2254 | << "but it was never blocked."; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2255 | continue; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2256 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2257 | registry_->RemoveBlacklisted(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2258 | extension_prefs_->SetExtensionBlacklisted(extension->id(), false); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2259 | AddExtension(extension.get()); |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 2260 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled", |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2261 | extension->location(), |
| 2262 | Manifest::NUM_LOCATIONS); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2263 | } |
| 2264 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2265 | for (ExtensionIdSet::iterator it = not_yet_blocked.begin(); |
| 2266 | it != not_yet_blocked.end(); ++it) { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2267 | scoped_refptr<const Extension> extension = GetInstalledExtension(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2268 | if (!extension.get()) { |
| 2269 | NOTREACHED() << "Extension " << *it << " needs to be " |
| 2270 | << "blacklisted, but it's not installed."; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2271 | continue; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2272 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2273 | registry_->AddBlacklisted(extension); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2274 | extension_prefs_->SetExtensionBlacklistState( |
| 2275 | extension->id(), extensions::BLACKLISTED_MALWARE); |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 2276 | UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST); |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 2277 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled", |
| 2278 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2279 | } |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2280 | } |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2281 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2282 | // TODO(oleg): UMA logging |
| 2283 | void ExtensionService::UpdateGreylistedExtensions( |
| 2284 | const ExtensionIdSet& greylist, |
| 2285 | const ExtensionIdSet& unchanged, |
| 2286 | const extensions::Blacklist::BlacklistStateMap& state_map) { |
| 2287 | ExtensionIdSet not_yet_greylisted, no_longer_greylisted; |
| 2288 | Partition(greylist_.GetIDs(), |
| 2289 | greylist, unchanged, |
| 2290 | &no_longer_greylisted, ¬_yet_greylisted); |
| 2291 | |
| 2292 | for (ExtensionIdSet::iterator it = no_longer_greylisted.begin(); |
| 2293 | it != no_longer_greylisted.end(); ++it) { |
| 2294 | scoped_refptr<const Extension> extension = greylist_.GetByID(*it); |
| 2295 | if (!extension.get()) { |
| 2296 | NOTREACHED() << "Extension " << *it << " no longer greylisted, " |
| 2297 | << "but it was not marked as greylisted."; |
| 2298 | continue; |
| 2299 | } |
| 2300 | |
| 2301 | greylist_.Remove(*it); |
| 2302 | extension_prefs_->SetExtensionBlacklistState(extension->id(), |
| 2303 | extensions::NOT_BLACKLISTED); |
| 2304 | if (extension_prefs_->GetDisableReasons(extension->id()) & |
| 2305 | extensions::Extension::DISABLE_GREYLIST) |
| 2306 | EnableExtension(*it); |
| 2307 | } |
| 2308 | |
| 2309 | for (ExtensionIdSet::iterator it = not_yet_greylisted.begin(); |
| 2310 | it != not_yet_greylisted.end(); ++it) { |
| 2311 | scoped_refptr<const Extension> extension = GetInstalledExtension(*it); |
| 2312 | if (!extension.get()) { |
| 2313 | NOTREACHED() << "Extension " << *it << " needs to be " |
| 2314 | << "disabled, but it's not installed."; |
| 2315 | continue; |
| 2316 | } |
| 2317 | greylist_.Insert(extension); |
| 2318 | extension_prefs_->SetExtensionBlacklistState(extension->id(), |
| 2319 | state_map.find(*it)->second); |
| 2320 | if (registry_->enabled_extensions().Contains(extension->id())) |
| 2321 | DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST); |
| 2322 | } |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 2323 | } |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2324 | |
| 2325 | void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
| 2326 | update_observers_.AddObserver(observer); |
| 2327 | } |
| 2328 | |
| 2329 | void ExtensionService::RemoveUpdateObserver( |
| 2330 | extensions::UpdateObserver* observer) { |
| 2331 | update_observers_.RemoveObserver(observer); |
| 2332 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2333 | |
| 2334 | // Used only by test code. |
| 2335 | void ExtensionService::UnloadAllExtensionsInternal() { |
| 2336 | profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
| 2337 | |
| 2338 | registry_->ClearAll(); |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 2339 | system_->runtime_data()->ClearAll(); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2340 | |
| 2341 | // TODO(erikkay) should there be a notification for this? We can't use |
| 2342 | // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 2343 | // or uninstalled. |
| 2344 | } |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 2345 | |
| 2346 | void ExtensionService::OnProfileDestructionStarted() { |
| 2347 | ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2348 | for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2349 | it != ids_to_unload.end(); |
| 2350 | ++it) { |
| 2351 | UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2352 | } |
| 2353 | } |