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