[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 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 9 | #include <iterator> |
asargent | e4de9f9 | 2016-09-15 01:40:06 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 97d2f1d | 2011-01-15 00:41:08 | [diff] [blame] | 11 | #include <set> |
asargent | e4de9f9 | 2016-09-15 01:40:06 | [diff] [blame] | 12 | #include <utility> |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 13 | |
Sebastien Marchand | f1349f5 | 2019-01-25 03:16:41 | [diff] [blame] | 14 | #include "base/bind.h" |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 15 | #include "base/command_line.h" |
rdevlin.cronin | 08ada0f | 2017-03-09 23:29:52 | [diff] [blame] | 16 | #include "base/debug/alias.h" |
| 17 | #include "base/debug/dump_without_crashing.h" |
skyostil | f221b7de | 2015-06-11 20:36:32 | [diff] [blame] | 18 | #include "base/location.h" |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 19 | #include "base/metrics/histogram_functions.h" |
rkaplow | fca0f4dc5 | 2015-03-14 21:40:57 | [diff] [blame] | 20 | #include "base/metrics/histogram_macros.h" |
Christopher Lam | ebb9020 | 2019-04-04 03:42:36 | [diff] [blame] | 21 | #include "base/one_shot_event.h" |
skyostil | f221b7de | 2015-06-11 20:36:32 | [diff] [blame] | 22 | #include "base/single_thread_task_runner.h" |
tripta.g | 0ac673a | 2017-07-07 05:45:09 | [diff] [blame] | 23 | #include "base/stl_util.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 24 | #include "base/strings/string_number_conversions.h" |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 25 | #include "base/strings/string_tokenizer.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 26 | #include "base/strings/stringprintf.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
Alexander Nohe | 2c540288 | 2019-04-11 21:56:33 | [diff] [blame] | 28 | #include "base/syslog_logging.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 29 | #include "base/task/post_task.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 30 | #include "base/threading/thread_restrictions.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 31 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 41a17c5 | 2013-06-28 00:27:53 | [diff] [blame] | 32 | #include "base/time/time.h" |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 33 | #include "base/trace_event/trace_event.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 34 | #include "build/build_config.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 35 | #include "chrome/browser/chrome_notification_types.h" |
sunil.ratnu | 21b896c | 2014-11-24 10:09:24 | [diff] [blame] | 36 | #include "chrome/browser/extensions/api/content_settings/content_settings_custom_extension_provider.h" |
mukai | 87a8d40 | 2014-09-15 20:15:09 | [diff] [blame] | 37 | #include "chrome/browser/extensions/api/content_settings/content_settings_service.h" |
ryanackley | 48bedbd | 2015-01-27 23:12:14 | [diff] [blame] | 38 | #include "chrome/browser/extensions/app_data_migrator.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 39 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 40 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 41 | #include "chrome/browser/extensions/data_deleter.h" |
rdevlin.cronin | 2813c1b | 2014-08-26 23:51:08 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_action_storage_manager.h" |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_assets_manager.h" |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_disabled_ui.h" |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_error_controller.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_sync_service.h" |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 49 | #include "chrome/browser/extensions/external_install_manager.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 50 | #include "chrome/browser/extensions/external_provider_impl.h" |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 51 | #include "chrome/browser/extensions/forced_extensions/installation_reporter.h" |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 52 | #include "chrome/browser/extensions/install_verifier.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 53 | #include "chrome/browser/extensions/installed_loader.h" |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 54 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 55 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 56 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 57 | #include "chrome/browser/extensions/unpacked_installer.h" |
rockot | db519299 | 2014-09-16 21:27:02 | [diff] [blame] | 58 | #include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h" |
[email protected] | 13e062e | 2014-08-09 10:21:55 | [diff] [blame] | 59 | #include "chrome/browser/extensions/updater/extension_updater.h" |
rockot | db519299 | 2014-09-16 21:27:02 | [diff] [blame] | 60 | #include "chrome/browser/google/google_brand.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 61 | #include "chrome/browser/profiles/profile.h" |
[email protected] | b5a507b2 | 2013-11-08 20:41:57 | [diff] [blame] | 62 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 63 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 64 | #include "chrome/browser/ui/webui/theme_source.h" |
Greg Thompson | 8bcd799b | 2018-08-10 09:49:33 | [diff] [blame] | 65 | #include "chrome/browser/upgrade_detector/upgrade_detector.h" |
Alan Cutter | 6e963f0 | 2019-05-06 00:33:22 | [diff] [blame] | 66 | #include "chrome/browser/web_applications/components/externally_installed_web_app_prefs.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 67 | #include "chrome/common/buildflags.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 68 | #include "chrome/common/chrome_switches.h" |
[email protected] | f6431be8 | 2013-09-07 02:53:45 | [diff] [blame] | 69 | #include "chrome/common/crash_keys.h" |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 70 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 71 | #include "chrome/common/url_constants.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 72 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 73 | #include "components/crx_file/id_util.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 74 | #include "content/public/browser/browser_task_traits.h" |
Gabriel Charette | 790754c | 2018-03-16 21:32:59 | [diff] [blame] | 75 | #include "content/public/browser/browser_thread.h" |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 76 | #include "content/public/browser/notification_service.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 77 | #include "content/public/browser/render_process_host.h" |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 78 | #include "content/public/browser/storage_partition.h" |
[email protected] | 3442353 | 2013-11-21 18:13:10 | [diff] [blame] | 79 | #include "extensions/browser/event_router.h" |
Devlin Cronin | 40b4cbc | 2017-08-02 01:57:59 | [diff] [blame] | 80 | #include "extensions/browser/extension_file_task_runner.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 81 | #include "extensions/browser/extension_host.h" |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 82 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 83 | #include "extensions/browser/extension_system.h" |
Michael Giuffrida | 7efeed14 | 2017-06-07 06:29:21 | [diff] [blame] | 84 | #include "extensions/browser/extension_util.h" |
rockot | ffa65b1 | 2014-10-14 17:19:06 | [diff] [blame] | 85 | #include "extensions/browser/extensions_browser_client.h" |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 86 | #include "extensions/browser/external_install_info.h" |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 87 | #include "extensions/browser/install_flag.h" |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 88 | #include "extensions/browser/management_policy.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 89 | #include "extensions/browser/runtime_data.h" |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 90 | #include "extensions/browser/uninstall_reason.h" |
[email protected] | a9aa62b31 | 2013-11-29 05:35:06 | [diff] [blame] | 91 | #include "extensions/browser/update_observer.h" |
rockot | ffa65b1 | 2014-10-14 17:19:06 | [diff] [blame] | 92 | #include "extensions/browser/updater/extension_cache.h" |
rockot | 05f40a92 | 2014-10-16 19:40:25 | [diff] [blame] | 93 | #include "extensions/browser/updater/extension_downloader.h" |
Oleg Davydov | 6541a64f | 2019-04-17 13:17:33 | [diff] [blame] | 94 | #include "extensions/browser/updater/manifest_fetch_data.h" |
[email protected] | fb820c0 | 2014-03-13 15:07:08 | [diff] [blame] | 95 | #include "extensions/common/extension_messages.h" |
rockot | 9065985 | 2014-09-18 19:31:52 | [diff] [blame] | 96 | #include "extensions/common/extension_urls.h" |
[email protected] | 5ef835a | 2013-11-08 20:42:57 | [diff] [blame] | 97 | #include "extensions/common/feature_switch.h" |
rdevlin.cronin | 4122753 | 2016-07-13 21:24:34 | [diff] [blame] | 98 | #include "extensions/common/features/feature_channel.h" |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 99 | #include "extensions/common/file_util.h" |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 100 | #include "extensions/common/manifest_constants.h" |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 101 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
rockot | d554614 | 2014-10-15 00:29:08 | [diff] [blame] | 102 | #include "extensions/common/manifest_url_handlers.h" |
treib | 2e0517f9 | 2015-05-07 23:15:36 | [diff] [blame] | 103 | #include "extensions/common/permissions/api_permission.h" |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 104 | #include "extensions/common/permissions/permission_message_provider.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 105 | #include "extensions/common/permissions/permissions_data.h" |
Michael Giuffrida | b158f3f | 2017-07-17 19:53:44 | [diff] [blame] | 106 | #include "extensions/common/switches.h" |
[email protected] | 79a6064 | 2012-10-20 21:03:18 | [diff] [blame] | 107 | |
brettw | 9e85ef4 | 2016-11-01 21:01:24 | [diff] [blame] | 108 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 109 | #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 110 | #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 111 | #endif |
| 112 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 113 | #if defined(OS_CHROMEOS) |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 114 | #include "chrome/browser/chromeos/extensions/install_limiter.h" |
achuith | d3da4f0 | 2017-03-23 20:05:29 | [diff] [blame] | 115 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 116 | #include "storage/browser/fileapi/file_system_backend.h" |
| 117 | #include "storage/browser/fileapi/file_system_context.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 118 | #endif |
| 119 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 120 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 121 | using content::BrowserThread; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 122 | |
| 123 | namespace extensions { |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 124 | |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 125 | using LoadErrorBehavior = ExtensionRegistrar::LoadErrorBehavior; |
| 126 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 127 | namespace { |
| 128 | |
Lei Zhang | 1533915 | 2018-08-09 22:20:44 | [diff] [blame] | 129 | // Wait this long after an extensions becomes idle before updating it. |
| 130 | constexpr base::TimeDelta kUpdateIdleDelay = base::TimeDelta::FromSeconds(5); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 131 | |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 132 | // IDs of extensions that have been replaced by component extensions and need to |
| 133 | // be uninstalled. |
Lei Zhang | 1533915 | 2018-08-09 22:20:44 | [diff] [blame] | 134 | const char* const kMigratedExtensionIds[] = { |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 135 | "boadgeojelhgndaghljhdicfkmllpafd", // Google Cast |
| 136 | "dliochdbjfkdbacpmhlcpmleaejidimm" // Google Cast (Beta) |
| 137 | }; |
| 138 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 139 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 140 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 141 | // ExtensionService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 142 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 143 | void ExtensionService::CheckExternalUninstall(const std::string& id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 144 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 145 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 146 | // Check if the providers know about this extension. |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 147 | for (const auto& provider : external_extension_providers_) { |
| 148 | DCHECK(provider->IsReady()); |
| 149 | if (provider->HasExtension(id)) |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 150 | return; // Yup, known extension, don't uninstall. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 151 | } |
| 152 | |
Giovanni Ortuño Urquidi | 21852286 | 2018-08-28 12:48:04 | [diff] [blame] | 153 | // Historically, the code under //chrome/browser/extensions has |
| 154 | // unsurprisingly managed all extensions. Later, Progressive Web Apps (PWAs) |
| 155 | // were implemented on top of extensions, more out of convenience than out of |
| 156 | // principle. As of mid 2018, there is work underway to separate PWAs's |
| 157 | // implementation details from the //c/b/e code. During the transition |
| 158 | // period, PWA-extensions are no longer managed solely by //c/b/e code. We |
| 159 | // add a special case here so that //c/b/e code doesn't uninstall |
| 160 | // PWA-extensions that it doesn't otherwise know about. |
| 161 | // |
| 162 | // Long term, PWAs will be completely separate from extensions, and we can |
| 163 | // remove this cross-link. |
Alan Cutter | 6e963f0 | 2019-05-06 00:33:22 | [diff] [blame] | 164 | if (web_app::ExternallyInstalledWebAppPrefs::HasAppId(profile_->GetPrefs(), |
| 165 | id)) { |
Giovanni Ortuño Urquidi | 21852286 | 2018-08-28 12:48:04 | [diff] [blame] | 166 | return; |
| 167 | } |
| 168 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 169 | // We get the list of external extensions to check from preferences. |
| 170 | // It is possible that an extension has preferences but is not loaded. |
| 171 | // For example, an extension that requires experimental permissions |
| 172 | // will not be loaded if the experimental command line flag is not used. |
| 173 | // In this case, do not uninstall. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 174 | if (!GetInstalledExtension(id)) { |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 175 | // We can't call UninstallExtension with an unloaded/invalid |
| 176 | // extension ID. |
| 177 | LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 178 | << "with id: " << id; |
| 179 | return; |
| 180 | } |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 181 | UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, nullptr); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 182 | } |
| 183 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 184 | void ExtensionService::ClearProvidersForTesting() { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 185 | external_extension_providers_.clear(); |
| 186 | } |
| 187 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 188 | void ExtensionService::AddProviderForTesting( |
lazyboy | f33109d | 2016-08-31 00:37:08 | [diff] [blame] | 189 | std::unique_ptr<ExternalProviderInterface> test_provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 190 | CHECK(test_provider); |
lazyboy | f33109d | 2016-08-31 00:37:08 | [diff] [blame] | 191 | external_extension_providers_.push_back(std::move(test_provider)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 194 | void ExtensionService::BlacklistExtensionForTest( |
| 195 | const std::string& extension_id) { |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 196 | ExtensionIdSet blacklisted; |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 197 | ExtensionIdSet unchanged; |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 198 | blacklisted.insert(extension_id); |
| 199 | UpdateBlacklistedExtensions(blacklisted, unchanged); |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 200 | } |
| 201 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 202 | bool ExtensionService::OnExternalExtensionUpdateUrlFound( |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 203 | const ExternalInstallInfoUpdateUrl& info, |
| 204 | bool is_initial_load) { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 205 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 206 | CHECK(crx_file::id_util::IdIsValid(info.extension_id)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 207 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 208 | if (Manifest::IsExternalLocation(info.download_location)) { |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 209 | // All extensions that are not user specific can be cached. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 210 | ExtensionsBrowserClient::Get()->GetExtensionCache()->AllowCaching( |
| 211 | info.extension_id); |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 212 | } |
| 213 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 214 | const Extension* extension = GetExtensionById(info.extension_id, true); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 215 | if (extension) { |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 216 | // Already installed. Skip this install if the current location has higher |
| 217 | // priority than |info.download_location|, and we aren't doing a |
| 218 | // reinstall of a corrupt policy force-installed extension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 219 | Manifest::Location current = extension->location(); |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 220 | if (!pending_extension_manager_.IsPolicyReinstallForCorruptionExpected( |
| 221 | info.extension_id) && |
| 222 | current == Manifest::GetHigherPriorityLocation( |
| 223 | current, info.download_location)) { |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 224 | InstallationReporter::ReportFailure( |
Sergey Poromov | 296de0a | 2018-10-11 21:44:08 | [diff] [blame] | 225 | profile_, info.extension_id, |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 226 | InstallationReporter::FailureReason::ALREADY_INSTALLED); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 227 | return false; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 228 | } |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 229 | // Otherwise, overwrite the current installation. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 230 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 231 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 232 | // Add |info.extension_id| to the set of pending extensions. If it can not |
| 233 | // be added, then there is already a pending record from a higher-priority |
| 234 | // install source. In this case, signal that this extension will not be |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 235 | // installed by returning false. |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 236 | InstallationReporter::ReportInstallationStage( |
| 237 | profile_, info.extension_id, InstallationReporter::Stage::PENDING); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 238 | if (!pending_extension_manager()->AddFromExternalUpdateUrl( |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 239 | info.extension_id, info.install_parameter, info.update_url, |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 240 | info.download_location, info.creation_flags, |
| 241 | info.mark_acknowledged)) { |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 242 | InstallationReporter::ReportFailure( |
| 243 | profile_, info.extension_id, |
| 244 | InstallationReporter::FailureReason::PENDING_ADD_FAILED); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 245 | return false; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 246 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 247 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 248 | if (is_initial_load) |
| 249 | update_once_all_providers_are_ready_ = true; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 250 | return true; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 251 | } |
| 252 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 253 | void ExtensionService::OnExternalProviderUpdateComplete( |
| 254 | const ExternalProviderInterface* provider, |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 255 | const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions, |
| 256 | const std::vector<ExternalInstallInfoFile>& file_extensions, |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 257 | const std::set<std::string>& removed_extensions) { |
| 258 | // Update pending_extension_manager() with the new extensions first. |
lazyboy | 4aeef20 | 2016-09-07 21:28:59 | [diff] [blame] | 259 | for (const auto& extension : update_url_extensions) |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 260 | OnExternalExtensionUpdateUrlFound(extension, false); |
lazyboy | 4aeef20 | 2016-09-07 21:28:59 | [diff] [blame] | 261 | for (const auto& extension : file_extensions) |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 262 | OnExternalExtensionFileFound(extension); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 263 | |
| 264 | #if DCHECK_IS_ON() |
| 265 | for (const std::string& id : removed_extensions) { |
lazyboy | 4aeef20 | 2016-09-07 21:28:59 | [diff] [blame] | 266 | for (const auto& extension : update_url_extensions) |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 267 | DCHECK_NE(id, extension.extension_id); |
lazyboy | 4aeef20 | 2016-09-07 21:28:59 | [diff] [blame] | 268 | for (const auto& extension : file_extensions) |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 269 | DCHECK_NE(id, extension.extension_id); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 270 | } |
| 271 | #endif |
| 272 | |
| 273 | // Then uninstall before running |updater_|. |
| 274 | for (const std::string& id : removed_extensions) |
| 275 | CheckExternalUninstall(id); |
| 276 | |
| 277 | if (!update_url_extensions.empty() && updater_) { |
| 278 | // Empty params will cause pending extensions to be updated. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 279 | updater_->CheckNow(ExtensionUpdater::CheckParams()); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | error_controller_->ShowErrorIfNeeded(); |
| 283 | external_install_manager_->UpdateExternalExtensionAlert(); |
| 284 | } |
| 285 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 286 | ExtensionService::ExtensionService(Profile* profile, |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 287 | const base::CommandLine* command_line, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 288 | const base::FilePath& install_directory, |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 289 | ExtensionPrefs* extension_prefs, |
| 290 | Blacklist* blacklist, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 291 | bool autoupdate_enabled, |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 292 | bool extensions_enabled, |
Christopher Lam | ebb9020 | 2019-04-04 03:42:36 | [diff] [blame] | 293 | base::OneShotEvent* ready) |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 294 | : Blacklist::Observer(blacklist), |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 295 | command_line_(command_line), |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 296 | profile_(profile), |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 297 | system_(ExtensionSystem::Get(profile)), |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 298 | extension_prefs_(extension_prefs), |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 299 | blacklist_(blacklist), |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 300 | registry_(ExtensionRegistry::Get(profile)), |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 301 | pending_extension_manager_(profile), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 302 | install_directory_(install_directory), |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 303 | extensions_enabled_(extensions_enabled), |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 304 | ready_(ready), |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 305 | shared_module_service_(new SharedModuleService(profile_)), |
| 306 | app_data_migrator_(new AppDataMigrator(profile_, registry_)), |
Sergey Poromov | 0360b9e7 | 2018-04-19 17:37:29 | [diff] [blame] | 307 | extension_registrar_(profile_, this), |
Sergey Poromov | 296de0a | 2018-10-11 21:44:08 | [diff] [blame] | 308 | forced_extensions_tracker_(registry_, profile_) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 309 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
rkaplow | dd66a134 | 2015-03-05 00:31:49 | [diff] [blame] | 310 | TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor"); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 311 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 312 | // Figure out if extension installation should be enabled. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 313 | if (ExtensionsBrowserClient::Get()->AreExtensionsDisabled(*command_line, |
| 314 | profile)) |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 315 | extensions_enabled_ = false; |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 316 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 317 | registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 318 | content::NotificationService::AllBrowserContextsAndSources()); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 319 | registrar_.Add(this, NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 320 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 321 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 322 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 323 | registrar_.Add(this, |
| 324 | chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 325 | content::Source<Profile>(profile_)); |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 326 | |
weidongg | 0469523 | 2017-06-09 00:01:05 | [diff] [blame] | 327 | UpgradeDetector::GetInstance()->AddObserver(this); |
| 328 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 329 | ExtensionManagementFactory::GetForBrowserContext(profile_)->AddObserver(this); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 330 | |
rkaplow | dd66a134 | 2015-03-05 00:31:49 | [diff] [blame] | 331 | // Set up the ExtensionUpdater. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 332 | if (autoupdate_enabled) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 333 | updater_.reset(new ExtensionUpdater( |
David Bertoni | dccbd35 | 2018-03-20 00:31:04 | [diff] [blame] | 334 | this, extension_prefs, profile->GetPrefs(), profile, |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 335 | kDefaultUpdateFrequencySeconds, |
| 336 | ExtensionsBrowserClient::Get()->GetExtensionCache(), |
rockot | db519299 | 2014-09-16 21:27:02 | [diff] [blame] | 337 | base::Bind(ChromeExtensionDownloaderFactory::CreateForProfile, |
| 338 | profile))); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 339 | } |
| 340 | |
Michael Giuffrida | be1f920 | 2019-06-05 22:36:18 | [diff] [blame] | 341 | component_loader_ = std::make_unique<ComponentLoader>(this, profile); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 342 | |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 343 | if (extensions_enabled_) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 344 | ExternalProviderImpl::CreateExternalProviders( |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 345 | this, profile_, &external_extension_providers_); |
[email protected] | 87353134 | 2011-03-09 12:16:05 | [diff] [blame] | 346 | } |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 347 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 348 | // Set this as the ExtensionService for app sorting to ensure it causes syncs |
| 349 | // if required. |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 350 | is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun(); |
| 351 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 352 | error_controller_.reset( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 353 | new ExtensionErrorController(profile_, is_first_run_)); |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 354 | external_install_manager_.reset( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 355 | new ExternalInstallManager(profile_, is_first_run_)); |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 356 | |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 357 | extension_action_storage_manager_.reset( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 358 | new ExtensionActionStorageManager(profile_)); |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 359 | |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 360 | // How long is the path to the Extensions directory? |
| 361 | UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", |
drbasic | f0d1b26 | 2016-08-23 06:10:42 | [diff] [blame] | 362 | install_directory_.value().length(), 1, 500, 100); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 363 | } |
| 364 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 365 | PendingExtensionManager* ExtensionService::pending_extension_manager() { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 366 | return &pending_extension_manager_; |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 369 | ExtensionService::~ExtensionService() { |
weidongg | 0469523 | 2017-06-09 00:01:05 | [diff] [blame] | 370 | UpgradeDetector::GetInstance()->RemoveObserver(this); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 371 | // No need to unload extensions here because they are profile-scoped, and the |
| 372 | // profile is in the process of being deleted. |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 373 | for (const auto& provider : external_extension_providers_) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 374 | provider->ServiceShutdown(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | 037228a | 2012-10-05 01:36:16 | [diff] [blame] | 377 | void ExtensionService::Shutdown() { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 378 | ExtensionManagementFactory::GetInstance() |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 379 | ->GetForBrowserContext(profile()) |
| 380 | ->RemoveObserver(this); |
[email protected] | 037228a | 2012-10-05 01:36:16 | [diff] [blame] | 381 | } |
| 382 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 383 | const Extension* ExtensionService::GetExtensionById( |
| 384 | const std::string& id, bool include_disabled) const { |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 385 | int include_mask = ExtensionRegistry::ENABLED; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 386 | if (include_disabled) { |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 387 | // Include blacklisted and blocked extensions here because there are |
| 388 | // hundreds of callers of this function, and many might assume that this |
| 389 | // includes those that have been disabled due to blacklisting or blocking. |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 390 | include_mask |= ExtensionRegistry::DISABLED | |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 391 | ExtensionRegistry::BLACKLISTED | ExtensionRegistry::BLOCKED; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 392 | } |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 393 | return registry_->GetExtensionById(id, include_mask); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 396 | void ExtensionService::Init() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 397 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 398 | TRACE_EVENT0("browser,startup", "ExtensionService::Init"); |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 399 | SCOPED_UMA_HISTOGRAM_TIMER("Extensions.ExtensionServiceInitTime"); |
[email protected] | 3350d71 | 2013-11-18 09:32:24 | [diff] [blame] | 400 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 401 | DCHECK(!is_ready()); // Can't redo init. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 402 | DCHECK_EQ(registry_->enabled_extensions().size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 403 | |
benwells | 22ab8ee | 2015-08-21 02:55:08 | [diff] [blame] | 404 | component_loader_->LoadAll(); |
achuith | d3da4f0 | 2017-03-23 20:05:29 | [diff] [blame] | 405 | bool load_saved_extensions = true; |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 406 | bool load_command_line_extensions = extensions_enabled_; |
achuith | d3da4f0 | 2017-03-23 20:05:29 | [diff] [blame] | 407 | #if defined(OS_CHROMEOS) |
tbarzic | d2a741e | 2017-06-28 20:37:54 | [diff] [blame] | 408 | if (chromeos::ProfileHelper::IsSigninProfile(profile_) || |
| 409 | chromeos::ProfileHelper::IsLockScreenAppProfile(profile_)) { |
achuith | d3da4f0 | 2017-03-23 20:05:29 | [diff] [blame] | 410 | load_saved_extensions = false; |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 411 | load_command_line_extensions = false; |
| 412 | } |
achuith | d3da4f0 | 2017-03-23 20:05:29 | [diff] [blame] | 413 | #endif |
rdevlin.cronin | f2e1cb01 | 2017-05-27 01:27:59 | [diff] [blame] | 414 | if (load_saved_extensions) |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 415 | InstalledLoader(this).LoadAllExtensions(); |
rdevlin.cronin | f2e1cb01 | 2017-05-27 01:27:59 | [diff] [blame] | 416 | |
Nick Peterson | 8aa8e05 | 2019-05-22 23:17:01 | [diff] [blame] | 417 | CheckManagementPolicy(); |
rdevlin.cronin | f2e1cb01 | 2017-05-27 01:27:59 | [diff] [blame] | 418 | OnInstalledExtensionsLoaded(); |
| 419 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 420 | LoadExtensionsFromCommandLineFlag(::switches::kDisableExtensionsExcept); |
emaxx | 35e8b82 | 2017-04-11 02:04:29 | [diff] [blame] | 421 | if (load_command_line_extensions) |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 422 | LoadExtensionsFromCommandLineFlag(switches::kLoadExtension); |
benwells | 22ab8ee | 2015-08-21 02:55:08 | [diff] [blame] | 423 | EnabledReloadableExtensions(); |
| 424 | MaybeFinishShutdownDelayed(); |
| 425 | SetReadyAndNotifyListeners(); |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 426 | |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 427 | UninstallMigratedExtensions(); |
| 428 | |
benwells | 22ab8ee | 2015-08-21 02:55:08 | [diff] [blame] | 429 | // TODO(erikkay): this should probably be deferred to a future point |
| 430 | // rather than running immediately at startup. |
| 431 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 432 | |
benwells | 22ab8ee | 2015-08-21 02:55:08 | [diff] [blame] | 433 | LoadGreylistFromPrefs(); |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 434 | } |
[email protected] | 3350d71 | 2013-11-18 09:32:24 | [diff] [blame] | 435 | |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 436 | void ExtensionService::EnabledReloadableExtensions() { |
| 437 | TRACE_EVENT0("browser,startup", |
| 438 | "ExtensionService::EnabledReloadableExtensions"); |
| 439 | |
| 440 | std::vector<std::string> extensions_to_enable; |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 441 | for (const auto& e : registry_->disabled_extensions()) { |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 442 | if (extension_prefs_->GetDisableReasons(e->id()) == |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 443 | disable_reason::DISABLE_RELOAD) |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 444 | extensions_to_enable.push_back(e->id()); |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 445 | } |
| 446 | for (const std::string& extension : extensions_to_enable) { |
| 447 | EnableExtension(extension); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | void ExtensionService::MaybeFinishShutdownDelayed() { |
| 452 | TRACE_EVENT0("browser,startup", |
| 453 | "ExtensionService::MaybeFinishShutdownDelayed"); |
| 454 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 455 | std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info( |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 456 | extension_prefs_->GetAllDelayedInstallInfo()); |
| 457 | for (size_t i = 0; i < delayed_info->size(); ++i) { |
| 458 | ExtensionInfo* info = delayed_info->at(i).get(); |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 459 | scoped_refptr<const Extension> extension(nullptr); |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 460 | if (info->extension_manifest) { |
| 461 | std::string error; |
| 462 | extension = Extension::Create( |
| 463 | info->extension_path, info->extension_location, |
| 464 | *info->extension_manifest, |
| 465 | extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id), |
| 466 | info->extension_id, &error); |
| 467 | if (extension.get()) |
| 468 | delayed_installs_.Insert(extension); |
| 469 | } |
| 470 | } |
| 471 | MaybeFinishDelayedInstallations(); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 472 | std::unique_ptr<ExtensionPrefs::ExtensionsInfo> delayed_info2( |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 473 | extension_prefs_->GetAllDelayedInstallInfo()); |
| 474 | UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", |
| 475 | delayed_info2->size() - delayed_info->size()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 476 | } |
| 477 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 478 | void ExtensionService::LoadGreylistFromPrefs() { |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 479 | TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs"); |
| 480 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 481 | std::unique_ptr<ExtensionSet> all_extensions = |
[email protected] | f47f717 | 2014-03-19 19:27:10 | [diff] [blame] | 482 | registry_->GenerateInstalledExtensionsSet(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 483 | |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 484 | for (const auto& extension : *all_extensions) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 485 | const BlacklistState state = |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 486 | extension_prefs_->GetExtensionBlacklistState(extension->id()); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 487 | if (state == BLACKLISTED_SECURITY_VULNERABILITY || |
| 488 | state == BLACKLISTED_POTENTIALLY_UNWANTED || |
| 489 | state == BLACKLISTED_CWS_POLICY_VIOLATION) |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 490 | greylist_.Insert(extension); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 494 | bool ExtensionService::UpdateExtension(const CRXFileInfo& file, |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 495 | bool file_ownership_passed, |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 496 | CrxInstaller** out_crx_installer) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 497 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 498 | if (browser_terminating_) { |
| 499 | LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown"; |
| 500 | // Leak the temp file at extension_path. We don't want to add to the disk |
| 501 | // I/O burden at shutdown, we can't rely on the I/O completing anyway, and |
| 502 | // the file is in the OS temp directory which should be cleaned up for us. |
| 503 | return false; |
| 504 | } |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 505 | |
ginkage | 553af320 | 2015-02-04 12:39:09 | [diff] [blame] | 506 | const std::string& id = file.extension_id; |
| 507 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 508 | const PendingExtensionInfo* pending_extension_info = |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 509 | pending_extension_manager()->GetById(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 510 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 511 | const Extension* extension = GetInstalledExtension(id); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 512 | if (!pending_extension_info && !extension) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 513 | LOG(WARNING) << "Will not update extension " << id |
| 514 | << " because it is not installed or pending"; |
| 515 | // Delete extension_path since we're not creating a CrxInstaller |
| 516 | // that would do it for us. |
asargent | d50b18c | 2016-04-21 01:17:16 | [diff] [blame] | 517 | if (file_ownership_passed && |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 518 | !GetExtensionFileTaskRunner()->PostTask( |
| 519 | FROM_HERE, |
| 520 | base::BindOnce(&file_util::DeleteFile, file.path, false))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 521 | NOTREACHED(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 522 | |
| 523 | return false; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 524 | } |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 525 | // Either |pending_extension_info| or |extension| or both must not be null. |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 526 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 527 | installer->set_expected_id(id); |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 528 | installer->set_expected_hash(file.expected_hash); |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 529 | int creation_flags = Extension::NO_FLAGS; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 530 | if (pending_extension_info) { |
| 531 | installer->set_install_source(pending_extension_info->install_source()); |
pkotwicz | 31eb1e8ec | 2014-10-08 15:26:46 | [diff] [blame] | 532 | installer->set_allow_silent_install(true); |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 533 | // If the extension came in disabled due to a permission increase, then |
| 534 | // don't grant it all the permissions. crbug.com/484214 |
| 535 | bool has_permissions_increase = |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 536 | ExtensionPrefs::Get(profile_)->HasDisableReason( |
| 537 | id, disable_reason::DISABLE_PERMISSIONS_INCREASE); |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 538 | const base::Version& expected_version = pending_extension_info->version(); |
| 539 | if (has_permissions_increase || |
| 540 | pending_extension_info->remote_install() || |
| 541 | !expected_version.IsValid()) { |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 542 | installer->set_grant_permissions(false); |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 543 | } else { |
| 544 | installer->set_expected_version(expected_version, |
| 545 | false /* fail_install_if_unexpected */); |
| 546 | } |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 547 | creation_flags = pending_extension_info->creation_flags(); |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 548 | if (pending_extension_info->mark_acknowledged()) |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 549 | external_install_manager_->AcknowledgeExternalExtension(id); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 550 | // If the extension was installed from or has migrated to the webstore, or |
| 551 | // its auto-update URL is from the webstore, treat it as a webstore install. |
| 552 | // Note that we ignore some older extensions with blank auto-update URLs |
| 553 | // because we are mostly concerned with restrictions on NaCl extensions, |
| 554 | // which are newer. |
| 555 | if (!extension && extension_urls::IsWebstoreUpdateUrl( |
| 556 | pending_extension_info->update_url())) |
| 557 | creation_flags |= Extension::FROM_WEBSTORE; |
| 558 | } else { |
| 559 | // |extension| must not be null. |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 560 | installer->set_install_source(extension->location()); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 561 | } |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 562 | |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 563 | if (extension) { |
| 564 | installer->InitializeCreationFlagsForUpdate(extension, creation_flags); |
[email protected] | c30bda26 | 2014-06-19 04:10:13 | [diff] [blame] | 565 | installer->set_do_not_sync(extension_prefs_->DoNotSync(id)); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 566 | } else { |
| 567 | installer->set_creation_flags(creation_flags); |
| 568 | } |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 569 | installer->set_delete_source(file_ownership_passed); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 570 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
ginkage | 553af320 | 2015-02-04 12:39:09 | [diff] [blame] | 571 | installer->InstallCrxFile(file); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 572 | |
| 573 | if (out_crx_installer) |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 574 | *out_crx_installer = installer.get(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 575 | |
| 576 | return true; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 577 | } |
| 578 | |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 579 | void ExtensionService::LoadExtensionsFromCommandLineFlag( |
| 580 | const char* switch_name) { |
| 581 | if (command_line_->HasSwitch(switch_name)) { |
| 582 | base::CommandLine::StringType path_list = |
| 583 | command_line_->GetSwitchValueNative(switch_name); |
| 584 | base::StringTokenizerT<base::CommandLine::StringType, |
| 585 | base::CommandLine::StringType::const_iterator> |
| 586 | t(path_list, FILE_PATH_LITERAL(",")); |
| 587 | while (t.GetNext()) { |
| 588 | std::string extension_id; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 589 | UnpackedInstaller::Create(this)->LoadFromCommandLine( |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 590 | base::FilePath(t.token()), &extension_id, false /*only-allow-apps*/); |
| 591 | // Extension id is added to whitelist after its extension is loaded |
michaelpg | a8ea037 | 2017-04-06 20:41:35 | [diff] [blame] | 592 | // because code is executed asynchronously. TODO(michaelpg): Remove this |
| 593 | // assumption so loading extensions does not have to be asynchronous: |
| 594 | // crbug.com/708354. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 595 | if (switch_name == ::switches::kDisableExtensionsExcept) |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 596 | disable_flag_exempted_extensions_.insert(extension_id); |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 601 | // TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides |
| 602 | // according to header file once diffs have settled down. |
| 603 | void ExtensionService::LoadExtensionForReload( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 604 | const ExtensionId& extension_id, |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 605 | const base::FilePath& path, |
| 606 | LoadErrorBehavior load_error_behavior) { |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 607 | if (delayed_installs_.Contains(extension_id) && |
| 608 | FinishDelayedInstallationIfReady(extension_id, |
| 609 | true /*install_immediately*/)) { |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 610 | return; |
| 611 | } |
| 612 | |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 613 | // If we're reloading a component extension, use the component extension |
| 614 | // loader's reloader. |
| 615 | if (component_loader_->Exists(extension_id)) { |
| 616 | component_loader_->Reload(extension_id); |
| 617 | return; |
| 618 | } |
| 619 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 620 | // Check the installed extensions to see if what we're reloading was already |
| 621 | // installed. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 622 | std::unique_ptr<ExtensionInfo> installed_extension( |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 623 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 624 | if (installed_extension.get() && |
| 625 | installed_extension->extension_manifest.get()) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 626 | InstalledLoader(this).Load(*installed_extension, false); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 627 | } else { |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 628 | // Otherwise, the extension is unpacked (location LOAD). We must load it |
| 629 | // from the path. |
| 630 | CHECK(!path.empty()) << "ExtensionRegistrar should never ask to load an " |
| 631 | "unknown extension with no path"; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 632 | scoped_refptr<UnpackedInstaller> unpacked_installer = |
| 633 | UnpackedInstaller::Create(this); |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 634 | unpacked_installer->set_be_noisy_on_failure(load_error_behavior == |
| 635 | LoadErrorBehavior::kNoisy); |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 636 | unpacked_installer->Load(path); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 637 | } |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 638 | } |
| 639 | |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 640 | void ExtensionService::ReloadExtension(const std::string& extension_id) { |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 641 | extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kNoisy); |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | void ExtensionService::ReloadExtensionWithQuietFailure( |
| 645 | const std::string& extension_id) { |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 646 | extension_registrar_.ReloadExtension(extension_id, LoadErrorBehavior::kQuiet); |
[email protected] | bca4b83 | 2014-07-17 20:22:34 | [diff] [blame] | 647 | } |
| 648 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 649 | bool ExtensionService::UninstallExtension( |
| 650 | // "transient" because the process of uninstalling may cause the reference |
| 651 | // to become invalid. Instead, use |extenson->id()|. |
| 652 | const std::string& transient_extension_id, |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 653 | UninstallReason reason, |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 654 | base::string16* error) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 655 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 656 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 657 | scoped_refptr<const Extension> extension = |
| 658 | GetInstalledExtension(transient_extension_id); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 659 | |
[email protected] | e7afe245 | 2010-08-22 16:19:13 | [diff] [blame] | 660 | // Callers should not send us nonexistent extensions. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 661 | CHECK(extension.get()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 662 | |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 663 | ManagementPolicy* by_policy = system_->management_policy(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 664 | // Policy change which triggers an uninstall will always set |
| 665 | // |external_uninstall| to true so this is the only way to uninstall |
| 666 | // managed extensions. |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 667 | // Shared modules being uninstalled will also set |external_uninstall| to true |
| 668 | // so that we can guarantee users don't uninstall a shared module. |
| 669 | // (crbug.com/273300) |
| 670 | // TODO(rdevlin.cronin): This is probably not right. We should do something |
| 671 | // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so |
| 672 | // we don't do this. |
[email protected] | cc2f55c | 2014-07-08 02:19:04 | [diff] [blame] | 673 | bool external_uninstall = |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 674 | (reason == UNINSTALL_REASON_INTERNAL_MANAGEMENT) || |
| 675 | (reason == UNINSTALL_REASON_COMPONENT_REMOVED) || |
| 676 | (reason == UNINSTALL_REASON_REINSTALL) || |
| 677 | (reason == UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) || |
| 678 | (reason == UNINSTALL_REASON_ORPHANED_SHARED_MODULE) || |
| 679 | (reason == UNINSTALL_REASON_SYNC && |
| 680 | util::WasInstalledByCustodian(extension->id(), profile_)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 681 | if (!external_uninstall && |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 682 | (!by_policy->UserMayModifySettings(extension.get(), error) || |
| 683 | by_policy->MustRemainInstalled(extension.get(), error))) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 684 | content::NotificationService::current()->Notify( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 685 | NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 686 | content::Source<Profile>(profile_), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 687 | content::Details<const Extension>(extension.get())); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 688 | return false; |
| 689 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 690 | |
juncai | 33e46210 | 2015-05-18 20:48:44 | [diff] [blame] | 691 | InstallVerifier::Get(GetBrowserContext())->Remove(extension->id()); |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 692 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 693 | UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 694 | extension->GetType(), 100); |
treib | 2e0517f9 | 2015-05-07 23:15:36 | [diff] [blame] | 695 | RecordPermissionMessagesHistogram(extension.get(), "Uninstall"); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 696 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 697 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 698 | // any of these resources. |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 699 | UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL); |
asargent | 96c7ec4 | 2016-05-27 02:45:47 | [diff] [blame] | 700 | if (registry_->blacklisted_extensions().Contains(extension->id())) |
| 701 | registry_->RemoveBlacklisted(extension->id()); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 702 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 703 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 704 | if (!Manifest::IsUnpackedLocation(extension->location())) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 705 | if (!GetExtensionFileTaskRunner()->PostTask( |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 706 | FROM_HERE, |
tzik | 8d880ee | 2017-04-20 19:46:24 | [diff] [blame] | 707 | base::BindOnce(&ExtensionService::UninstallExtensionOnFileThread, |
| 708 | extension->id(), profile_, install_directory_, |
| 709 | extension->path()))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 710 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 711 | } |
| 712 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 713 | DataDeleter::StartDeleting(profile_, extension.get()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 714 | |
Michael Giuffrida | fcb42036 | 2017-10-11 21:50:26 | [diff] [blame] | 715 | extension_registrar_.UntrackTerminatedExtension(extension->id()); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 716 | |
| 717 | // Notify interested parties that we've uninstalled this extension. |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 718 | ExtensionRegistry::Get(profile_) |
| 719 | ->TriggerOnUninstalled(extension.get(), reason); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 720 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 721 | delayed_installs_.Remove(extension->id()); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 722 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 723 | extension_prefs_->OnExtensionUninstalled( |
| 724 | extension->id(), extension->location(), external_uninstall); |
[email protected] | d4eda59 | 2013-09-18 03:37:57 | [diff] [blame] | 725 | |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 726 | // Track the uninstallation. |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 727 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); |
| 728 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 729 | return true; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 730 | } |
| 731 | |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 732 | // static |
| 733 | void ExtensionService::UninstallExtensionOnFileThread( |
| 734 | const std::string& id, |
| 735 | Profile* profile, |
| 736 | const base::FilePath& install_dir, |
| 737 | const base::FilePath& extension_path) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 738 | ExtensionAssetsManager* assets_manager = |
| 739 | ExtensionAssetsManager::GetInstance(); |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 740 | assets_manager->UninstallExtension(id, profile, install_dir, extension_path); |
| 741 | } |
| 742 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 743 | bool ExtensionService::IsExtensionEnabled( |
| 744 | const std::string& extension_id) const { |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 745 | return extension_registrar_.IsExtensionEnabled(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 746 | } |
| 747 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 748 | void ExtensionService::EnableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 749 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 750 | extension_registrar_.EnableExtension(extension_id); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 751 | } |
| 752 | |
treib | c119232 | 2015-05-20 12:56:07 | [diff] [blame] | 753 | void ExtensionService::DisableExtension(const std::string& extension_id, |
| 754 | int disable_reasons) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 755 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 756 | extension_registrar_.DisableExtension(extension_id, disable_reasons); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 757 | } |
| 758 | |
Ivan Sandrk | 4a55dc2 | 2018-05-17 18:14:48 | [diff] [blame] | 759 | void ExtensionService::DisableExtensionWithSource( |
| 760 | const Extension* source_extension, |
| 761 | const std::string& extension_id, |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 762 | disable_reason::DisableReason disable_reasons) { |
Ivan Sandrk | 4a55dc2 | 2018-05-17 18:14:48 | [diff] [blame] | 763 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 764 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 765 | DCHECK(disable_reasons == disable_reason::DISABLE_USER_ACTION || |
| 766 | disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY); |
| 767 | if (disable_reasons == disable_reason::DISABLE_BLOCKED_BY_POLICY) { |
Ivan Sandrk | 4a55dc2 | 2018-05-17 18:14:48 | [diff] [blame] | 768 | DCHECK(Manifest::IsPolicyLocation(source_extension->location()) || |
| 769 | Manifest::IsComponentLocation(source_extension->location())); |
| 770 | } |
| 771 | |
| 772 | const Extension* extension = GetExtensionById(extension_id, true); |
| 773 | CHECK(system_->management_policy()->ExtensionMayModifySettings( |
| 774 | source_extension, extension, nullptr)); |
| 775 | extension_registrar_.DisableExtension(extension_id, disable_reasons); |
| 776 | } |
| 777 | |
mtomasz | 294bb3e | 2017-01-24 02:17:52 | [diff] [blame] | 778 | void ExtensionService::DisableUserExtensionsExcept( |
[email protected] | 1abf05e | 2013-07-09 17:04:36 | [diff] [blame] | 779 | const std::vector<std::string>& except_ids) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 780 | ManagementPolicy* management_policy = system_->management_policy(); |
| 781 | ExtensionList to_disable; |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 782 | |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 783 | for (const auto& extension : registry_->enabled_extensions()) { |
| 784 | if (management_policy->UserMayModifySettings(extension.get(), nullptr)) |
| 785 | to_disable.push_back(extension); |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 786 | } |
| 787 | |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 788 | for (const auto& extension : registry_->terminated_extensions()) { |
| 789 | if (management_policy->UserMayModifySettings(extension.get(), nullptr)) |
| 790 | to_disable.push_back(extension); |
| 791 | } |
| 792 | |
| 793 | for (const auto& extension : to_disable) { |
| 794 | if (extension->was_installed_by_default() && |
[email protected] | 3082fe3 | 2013-08-06 11:12:38 | [diff] [blame] | 795 | extension_urls::IsWebstoreUpdateUrl( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 796 | ManifestURL::GetUpdateURL(extension.get()))) |
[email protected] | 3082fe3 | 2013-08-06 11:12:38 | [diff] [blame] | 797 | continue; |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 798 | const std::string& id = extension->id(); |
Jan Wilken Dörrie | ade7922 | 2019-06-06 19:01:12 | [diff] [blame] | 799 | if (!base::Contains(except_ids, id)) |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 800 | DisableExtension(id, disable_reason::DISABLE_USER_ACTION); |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 804 | // Extensions that are not locked, components or forced by policy should be |
| 805 | // locked. Extensions are no longer considered enabled or disabled. Blacklisted |
| 806 | // extensions are now considered both blacklisted and locked. |
| 807 | void ExtensionService::BlockAllExtensions() { |
| 808 | if (block_extensions_) |
| 809 | return; |
| 810 | block_extensions_ = true; |
| 811 | |
| 812 | // Blacklisted extensions are already unloaded, need not be blocked. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 813 | std::unique_ptr<ExtensionSet> extensions = |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 814 | registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED | |
| 815 | ExtensionRegistry::DISABLED | |
| 816 | ExtensionRegistry::TERMINATED); |
| 817 | |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 818 | for (const auto& extension : *extensions) { |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 819 | const std::string& id = extension->id(); |
| 820 | |
| 821 | if (!CanBlockExtension(extension.get())) |
| 822 | continue; |
| 823 | |
| 824 | registry_->RemoveEnabled(id); |
| 825 | registry_->RemoveDisabled(id); |
| 826 | registry_->RemoveTerminated(id); |
| 827 | |
| 828 | registry_->AddBlocked(extension.get()); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 829 | UnloadExtension(id, UnloadedExtensionReason::LOCK_ALL); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
| 833 | // All locked extensions should revert to being either enabled or disabled |
| 834 | // as appropriate. |
| 835 | void ExtensionService::UnblockAllExtensions() { |
| 836 | block_extensions_ = false; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 837 | std::unique_ptr<ExtensionSet> to_unblock = |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 838 | registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED); |
| 839 | |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 840 | for (const auto& extension : *to_unblock) { |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 841 | registry_->RemoveBlocked(extension->id()); |
| 842 | AddExtension(extension.get()); |
| 843 | } |
Owen Min | b71016d | 2018-01-11 01:51:49 | [diff] [blame] | 844 | // While extensions are blocked, we won't display any external install |
| 845 | // warnings. Now that they are unblocked, we should update the error. |
| 846 | external_install_manager_->UpdateExternalExtensionAlert(); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 847 | } |
| 848 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 849 | void ExtensionService::GrantPermissionsAndEnableExtension( |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 850 | const Extension* extension) { |
| 851 | GrantPermissions(extension); |
treib | 2e0517f9 | 2015-05-07 23:15:36 | [diff] [blame] | 852 | RecordPermissionMessagesHistogram(extension, "ReEnable"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 853 | EnableExtension(extension->id()); |
| 854 | } |
| 855 | |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 856 | void ExtensionService::GrantPermissions(const Extension* extension) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 857 | CHECK(extension); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 858 | PermissionsUpdater(profile()).GrantActivePermissions(extension); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 859 | } |
| 860 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 861 | // static |
| 862 | void ExtensionService::RecordPermissionMessagesHistogram( |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 863 | const Extension* extension, const char* histogram) { |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 864 | // Since this is called from multiple sources, and since the histogram macros |
| 865 | // use statics, we need to manually lookup the histogram ourselves. |
treib | 2e0517f9 | 2015-05-07 23:15:36 | [diff] [blame] | 866 | base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 867 | base::StringPrintf("Extensions.Permissions_%s3", histogram), |
| 868 | 1, |
| 869 | APIPermission::kEnumBoundary, |
| 870 | APIPermission::kEnumBoundary + 1, |
| 871 | base::HistogramBase::kUmaTargetedHistogramFlag); |
| 872 | |
| 873 | base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet( |
| 874 | base::StringPrintf("Extensions.HasPermissions_%s3", histogram), |
| 875 | base::HistogramBase::kUmaTargetedHistogramFlag); |
| 876 | |
| 877 | PermissionIDSet permissions = |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 878 | PermissionMessageProvider::Get()->GetAllPermissionIDs( |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 879 | extension->permissions_data()->active_permissions(), |
treib | 2e0517f9 | 2015-05-07 23:15:36 | [diff] [blame] | 880 | extension->GetType()); |
| 881 | counter_has_any->AddBoolean(!permissions.empty()); |
| 882 | for (const PermissionID& id : permissions) |
| 883 | counter->Add(id.id()); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 884 | } |
| 885 | |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 886 | // TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides |
| 887 | // according to header file once diffs have settled down. |
| 888 | void ExtensionService::PostActivateExtension( |
Michael Giuffrida | 19a5598 | 2018-02-10 03:03:26 | [diff] [blame] | 889 | scoped_refptr<const Extension> extension) { |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 890 | // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a |
| 891 | // BrowserContextKeyedService and use ExtensionRegistryObserver. |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 892 | profile_->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension( |
Devlin Cronin | b2be9a6a | 2019-06-14 20:08:19 | [diff] [blame^] | 893 | extension.get()); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 894 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 895 | // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't |
| 896 | // work properly multi-profile. Besides which, it should be using |
| 897 | // ExtensionRegistryObserver. See http://crbug.com/355029. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 898 | UpdateActiveExtensionsInCrashReporter(); |
| 899 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 900 | const PermissionsData* permissions_data = extension->permissions_data(); |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 901 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 902 | // If the extension has permission to load chrome://favicon/ resources we need |
| 903 | // to make sure that the FaviconSource is registered with the |
| 904 | // ChromeURLDataManager. |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 905 | if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
Lei Zhang | c77274da | 2018-08-28 23:14:00 | [diff] [blame] | 906 | content::URLDataSource::Add(profile_, |
| 907 | std::make_unique<FaviconSource>(profile_)); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 908 | } |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 909 | |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 910 | // Same for chrome://theme/ resources. |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 911 | if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) { |
Lei Zhang | c77274da | 2018-08-28 23:14:00 | [diff] [blame] | 912 | content::URLDataSource::Add(profile_, |
| 913 | std::make_unique<ThemeSource>(profile_)); |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 914 | } |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 915 | } |
| 916 | |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 917 | // TODO(michaelpg): Group with other ExtensionRegistrar::Delegate overrides |
| 918 | // according to header file once diffs have settled down. |
Michael Giuffrida | 023e353 | 2017-09-28 23:21:21 | [diff] [blame] | 919 | void ExtensionService::PostDeactivateExtension( |
| 920 | scoped_refptr<const Extension> extension) { |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 921 | // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a |
| 922 | // BrowserContextKeyedService and use ExtensionRegistryObserver. |
Michael Giuffrida | 023e353 | 2017-09-28 23:21:21 | [diff] [blame] | 923 | profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForExtension( |
| 924 | extension.get()); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 925 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 926 | #if defined(OS_CHROMEOS) |
[email protected] | ac66e45 | 2013-01-11 09:21:23 | [diff] [blame] | 927 | // Revoke external file access for the extension from its file system context. |
| 928 | // It is safe to access the extension's storage partition at this point. The |
| 929 | // storage partition may get destroyed only after the extension gets unloaded. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 930 | GURL site = util::GetSiteForExtensionId(extension->id(), profile_); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 931 | storage::FileSystemContext* filesystem_context = |
| 932 | BrowserContext::GetStoragePartitionForSite(profile_, site) |
| 933 | ->GetFileSystemContext(); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 934 | if (filesystem_context && filesystem_context->external_backend()) { |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 935 | filesystem_context->external_backend()->RevokeAccessForExtension( |
| 936 | extension->id()); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 937 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 938 | #endif |
| 939 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 940 | // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't |
| 941 | // work properly multi-profile. Besides which, it should be using |
| 942 | // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 943 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 944 | } |
| 945 | |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 946 | content::BrowserContext* ExtensionService::GetBrowserContext() const { |
| 947 | // Implemented in the .cc file to avoid adding a profile.h dependency to |
| 948 | // extension_service.h. |
| 949 | return profile_; |
| 950 | } |
| 951 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 952 | bool ExtensionService::is_ready() { |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 953 | return ready_->is_signaled(); |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 954 | } |
| 955 | |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 956 | void ExtensionService::CheckManagementPolicy() { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 957 | std::map<std::string, disable_reason::DisableReason> to_disable; |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 958 | std::vector<std::string> to_enable; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 959 | |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 960 | // Loop through the extensions list, finding extensions we need to disable. |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 961 | for (const auto& extension : registry_->enabled_extensions()) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 962 | disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE; |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 963 | if (system_->management_policy()->MustRemainDisabled( |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 964 | extension.get(), &disable_reason, nullptr)) |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 965 | to_disable[extension->id()] = disable_reason; |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 966 | } |
| 967 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 968 | ExtensionManagement* management = |
| 969 | ExtensionManagementFactory::GetForBrowserContext(profile()); |
| 970 | PermissionsUpdater(profile()).SetDefaultPolicyHostRestrictions( |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 971 | management->GetDefaultPolicyBlockedHosts(), |
| 972 | management->GetDefaultPolicyAllowedHosts()); |
nrpeter | e33d2a5b | 2017-04-25 00:12:31 | [diff] [blame] | 973 | for (const auto& extension : registry_->enabled_extensions()) { |
| 974 | bool uses_default = |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 975 | management->UsesDefaultPolicyHostRestrictions(extension.get()); |
nrpeter | e33d2a5b | 2017-04-25 00:12:31 | [diff] [blame] | 976 | if (uses_default) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 977 | PermissionsUpdater(profile()).SetUsesDefaultHostRestrictions( |
nrpeter | e33d2a5b | 2017-04-25 00:12:31 | [diff] [blame] | 978 | extension.get()); |
| 979 | } else { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 980 | PermissionsUpdater(profile()).SetPolicyHostRestrictions( |
Devlin Cronin | 7e0f41ff | 2018-05-16 17:19:36 | [diff] [blame] | 981 | extension.get(), management->GetPolicyBlockedHosts(extension.get()), |
| 982 | management->GetPolicyAllowedHosts(extension.get())); |
nrpeter | e33d2a5b | 2017-04-25 00:12:31 | [diff] [blame] | 983 | } |
| 984 | } |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 985 | |
| 986 | // Loop through the disabled extension list, find extensions to re-enable |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 987 | // automatically. These extensions are exclusive from the |to_disable| list |
| 988 | // constructed above, since disabled_extensions() and enabled_extensions() are |
| 989 | // supposed to be mutually exclusive. |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 990 | for (const auto& extension : registry_->disabled_extensions()) { |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 991 | int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 992 | |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 993 | // Find all extensions disabled due to minimum version requirement and |
| 994 | // management policy but now satisfying it. |
| 995 | if (management->CheckMinimumVersion(extension.get(), nullptr)) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 996 | disable_reasons &= (~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY); |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | if (!system_->management_policy()->MustRemainDisabled(extension.get(), |
| 1000 | nullptr, nullptr)) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1001 | disable_reasons &= (~disable_reason::DISABLE_BLOCKED_BY_POLICY); |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | extension_prefs_->ReplaceDisableReasons(extension->id(), disable_reasons); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1005 | if (disable_reasons == disable_reason::DISABLE_NONE) |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 1006 | to_enable.push_back(extension->id()); |
| 1007 | } |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1008 | |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1009 | for (const auto& i : to_disable) |
| 1010 | DisableExtension(i.first, i.second); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 1011 | |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 1012 | // No extension is getting re-enabled here after disabling because |to_enable| |
| 1013 | // is mutually exclusive to |to_disable|. |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 1014 | for (const std::string& id : to_enable) |
| 1015 | EnableExtension(id); |
| 1016 | |
| 1017 | if (updater_.get()) { |
| 1018 | // Find all extensions disabled due to minimum version requirement from |
| 1019 | // policy (including the ones that got disabled just now), and check |
| 1020 | // for update. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1021 | ExtensionUpdater::CheckParams to_recheck; |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1022 | for (const auto& extension : registry_->disabled_extensions()) { |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 1023 | if (extension_prefs_->GetDisableReasons(extension->id()) == |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1024 | disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY) { |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 1025 | // The minimum version check is the only thing holding this extension |
| 1026 | // back, so check if it can be updated to fix that. |
| 1027 | to_recheck.ids.push_back(extension->id()); |
| 1028 | } |
| 1029 | } |
| 1030 | if (!to_recheck.ids.empty()) |
Minh X. Nguyen | 722b968 | 2018-04-25 21:46:48 | [diff] [blame] | 1031 | updater_->CheckNow(std::move(to_recheck)); |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 1032 | } |
Alexander Nohe | 2c540288 | 2019-04-11 21:56:33 | [diff] [blame] | 1033 | |
| 1034 | // Check the disabled extensions to see if any should be force uninstalled. |
| 1035 | std::vector<ExtensionId> remove_list; |
| 1036 | for (const auto& extension : registry_->disabled_extensions()) { |
| 1037 | if (system_->management_policy()->ShouldForceUninstall(extension.get(), |
| 1038 | nullptr /*error*/)) { |
| 1039 | remove_list.push_back(extension->id()); |
| 1040 | } |
| 1041 | } |
| 1042 | for (auto extension_id : remove_list) { |
| 1043 | base::string16 error; |
| 1044 | if (!UninstallExtension(extension_id, UNINSTALL_REASON_INTERNAL_MANAGEMENT, |
| 1045 | &error)) { |
| 1046 | SYSLOG(WARNING) << "Extension with id " << extension_id |
| 1047 | << " failed to be uninstalled via policy: " << error; |
| 1048 | } |
| 1049 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1050 | } |
| 1051 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1052 | void ExtensionService::CheckForUpdatesSoon() { |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1053 | // This can legitimately happen in unit tests. |
| 1054 | if (!updater_.get()) |
| 1055 | return; |
| 1056 | |
raphael.kubo.da.costa | 8527f94 | 2016-11-15 17:03:51 | [diff] [blame] | 1057 | updater_->CheckSoon(); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1058 | } |
| 1059 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1060 | // Some extensions will autoupdate themselves externally from Chrome. These |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 1061 | // are typically part of some larger client application package. To support |
| 1062 | // these, the extension will register its location in the preferences file |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1063 | // (and also, on Windows, in the registry) and this code will periodically |
| 1064 | // check that location for a .crx file, which it will then install locally if |
| 1065 | // a new version is available. |
Devlin Cronin | 9722a72 | 2017-12-16 03:35:10 | [diff] [blame] | 1066 | // Errors are reported through LoadErrorReporter. Success is not reported. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1067 | void ExtensionService::CheckForExternalUpdates() { |
lazyboy | 77214d3c | 2017-04-04 16:46:12 | [diff] [blame] | 1068 | if (external_updates_disabled_for_test_) |
| 1069 | return; |
| 1070 | |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1071 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 1072 | TRACE_EVENT0("browser,startup", "ExtensionService::CheckForExternalUpdates"); |
| 1073 | SCOPED_UMA_HISTOGRAM_TIMER("Extensions.CheckForExternalUpdatesTime"); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1074 | |
| 1075 | // Note that this installation is intentionally silent (since it didn't |
| 1076 | // go through the front-end). Extensions that are registered in this |
| 1077 | // way are effectively considered 'pre-bundled', and so implicitly |
| 1078 | // trusted. In general, if something has HKLM or filesystem access, |
| 1079 | // they could install an extension manually themselves anyway. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1080 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1081 | // Ask each external extension provider to give us a call back for each |
| 1082 | // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1083 | for (const auto& provider : external_extension_providers_) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1084 | provider->VisitRegisteredExtension(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1085 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1086 | // Do any required work that we would have done after completion of all |
| 1087 | // providers. |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 1088 | if (external_extension_providers_.empty()) |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1089 | OnAllExternalProvidersReady(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1090 | } |
| 1091 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1092 | void ExtensionService::OnExternalProviderReady( |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1093 | const ExternalProviderInterface* provider) { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 1094 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1095 | CHECK(provider->IsReady()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1096 | |
| 1097 | // An external provider has finished loading. We only take action |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1098 | // if all of them are finished. So we check them first. |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1099 | if (AreAllExternalProvidersReady()) |
| 1100 | OnAllExternalProvidersReady(); |
| 1101 | } |
| 1102 | |
| 1103 | bool ExtensionService::AreAllExternalProvidersReady() const { |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1104 | for (const auto& provider : external_extension_providers_) { |
| 1105 | if (!provider->IsReady()) |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1106 | return false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1107 | } |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1108 | return true; |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | void ExtensionService::OnAllExternalProvidersReady() { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 1112 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1113 | // Install any pending extensions. |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1114 | if (update_once_all_providers_are_ready_ && updater()) { |
| 1115 | update_once_all_providers_are_ready_ = false; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1116 | ExtensionUpdater::CheckParams params; |
Minh X. Nguyen | 722b968 | 2018-04-25 21:46:48 | [diff] [blame] | 1117 | params.callback = |
| 1118 | external_updates_finished_callback_.is_null() |
| 1119 | ? base::OnceClosure() |
| 1120 | : base::BindOnce( |
| 1121 | [](base::RepeatingClosure callback) { callback.Run(); }, |
| 1122 | external_updates_finished_callback_); |
Devlin Cronin | 2b3acda | 2019-05-30 19:11:37 | [diff] [blame] | 1123 | // We have to mark high-priority extensions (such as policy-forced |
| 1124 | // extensions or external component extensions) with foreground fetch |
| 1125 | // priority; otherwise their installation may be throttled by bandwidth |
| 1126 | // limits. |
| 1127 | // See https://crbug.com/904600 and https://crbug.com/965686. |
| 1128 | if (pending_extension_manager_.HasHighPriorityPendingExtension()) { |
Oleg Davydov | 6541a64f | 2019-04-17 13:17:33 | [diff] [blame] | 1129 | params.fetch_priority = ManifestFetchData::FOREGROUND; |
| 1130 | } |
Minh X. Nguyen | 722b968 | 2018-04-25 21:46:48 | [diff] [blame] | 1131 | updater()->CheckNow(std::move(params)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | // Uninstall all the unclaimed extensions. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1135 | std::unique_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1136 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 1137 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1138 | ExtensionInfo* info = extensions_info->at(i).get(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1139 | if (Manifest::IsExternalLocation(info->extension_location)) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1140 | CheckExternalUninstall(info->extension_id); |
| 1141 | } |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1142 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 1143 | error_controller_->ShowErrorIfNeeded(); |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1144 | |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 1145 | external_install_manager_->UpdateExternalExtensionAlert(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1146 | } |
| 1147 | |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 1148 | void ExtensionService::UnloadExtension(const std::string& extension_id, |
| 1149 | UnloadedExtensionReason reason) { |
Devlin Cronin | 5b35a08 | 2017-10-05 20:44:36 | [diff] [blame] | 1150 | extension_registrar_.RemoveExtension(extension_id, reason); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1151 | } |
| 1152 | |
[email protected] | 8b1ec20 | 2013-09-05 02:09:50 | [diff] [blame] | 1153 | void ExtensionService::RemoveComponentExtension( |
| 1154 | const std::string& extension_id) { |
| 1155 | scoped_refptr<const Extension> extension( |
| 1156 | GetExtensionById(extension_id, false)); |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 1157 | UnloadExtension(extension_id, UnloadedExtensionReason::UNINSTALL); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1158 | if (extension.get()) { |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 1159 | ExtensionRegistry::Get(profile_)->TriggerOnUninstalled( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1160 | extension.get(), UNINSTALL_REASON_COMPONENT_REMOVED); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1161 | } |
[email protected] | 8b1ec20 | 2013-09-05 02:09:50 | [diff] [blame] | 1162 | } |
| 1163 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1164 | void ExtensionService::UnloadAllExtensionsForTest() { |
| 1165 | UnloadAllExtensionsInternal(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1166 | } |
| 1167 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1168 | void ExtensionService::ReloadExtensionsForTest() { |
| 1169 | // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit |
| 1170 | // warning about calling test code in production. |
| 1171 | UnloadAllExtensionsInternal(); |
[email protected] | eac8833 | 2012-12-26 17:57:45 | [diff] [blame] | 1172 | component_loader_->LoadAll(); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1173 | InstalledLoader(this).LoadAllExtensions(); |
rdevlin.cronin | f2e1cb01 | 2017-05-27 01:27:59 | [diff] [blame] | 1174 | OnInstalledExtensionsLoaded(); |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1175 | // Don't call SetReadyAndNotifyListeners() since tests call this multiple |
| 1176 | // times. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1177 | } |
| 1178 | |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 1179 | void ExtensionService::SetReadyAndNotifyListeners() { |
rkaplow | a8fd8d3 | 2015-02-25 21:27:56 | [diff] [blame] | 1180 | TRACE_EVENT0("browser,startup", |
| 1181 | "ExtensionService::SetReadyAndNotifyListeners"); |
| 1182 | SCOPED_UMA_HISTOGRAM_TIMER( |
| 1183 | "Extensions.ExtensionServiceNotifyReadyListenersTime"); |
| 1184 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1185 | ready_->Signal(); |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 1186 | content::NotificationService::current()->Notify( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1187 | NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 1188 | content::Source<Profile>(profile_), |
| 1189 | content::NotificationService::NoDetails()); |
| 1190 | } |
| 1191 | |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1192 | void ExtensionService::AddExtension(const Extension* extension) { |
rdevlin.cronin | 08ada0f | 2017-03-09 23:29:52 | [diff] [blame] | 1193 | if (!Manifest::IsValidLocation(extension->location())) { |
| 1194 | // TODO(devlin): We should *never* add an extension with an invalid |
| 1195 | // location, but some bugs (e.g. crbug.com/692069) seem to indicate we do. |
| 1196 | // Track down the cases when this can happen, and remove this |
| 1197 | // DumpWithoutCrashing() (possibly replacing it with a CHECK). |
| 1198 | NOTREACHED(); |
Lukasz Anforowicz | 68c2177 | 2018-01-13 03:42:44 | [diff] [blame] | 1199 | DEBUG_ALIAS_FOR_CSTR(extension_id_copy, extension->id().c_str(), 33); |
rdevlin.cronin | 08ada0f | 2017-03-09 23:29:52 | [diff] [blame] | 1200 | Manifest::Location location = extension->location(); |
| 1201 | int creation_flags = extension->creation_flags(); |
| 1202 | Manifest::Type type = extension->manifest()->type(); |
rdevlin.cronin | 08ada0f | 2017-03-09 23:29:52 | [diff] [blame] | 1203 | base::debug::Alias(&location); |
| 1204 | base::debug::Alias(&creation_flags); |
| 1205 | base::debug::Alias(&type); |
| 1206 | base::debug::DumpWithoutCrashing(); |
| 1207 | return; |
| 1208 | } |
| 1209 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1210 | // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 1211 | // default extension state to DISABLED when the --disable-extensions flag |
| 1212 | // is set (http://crbug.com/29067). |
Devlin Cronin | efe0c88 | 2018-04-20 00:06:48 | [diff] [blame] | 1213 | if (!extensions_enabled_ && |
| 1214 | !Manifest::ShouldAlwaysLoadExtension(extension->location(), |
Devlin Cronin | 8c23eec | 2018-05-01 18:42:28 | [diff] [blame] | 1215 | extension->is_theme()) && |
catmullings | 98cd194 | 2016-08-30 22:31:59 | [diff] [blame] | 1216 | disable_flag_exempted_extensions_.count(extension->id()) == 0) { |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1217 | return; |
[email protected] | 330840c | 2012-08-29 22:21:01 | [diff] [blame] | 1218 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1219 | |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 1220 | extension_registrar_.AddExtension(extension); |
Michael Giuffrida | 023e353 | 2017-09-28 23:21:21 | [diff] [blame] | 1221 | |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 1222 | if (registry_->disabled_extensions().Contains(extension->id())) { |
| 1223 | // Show the extension disabled error if a permissions increase or a remote |
| 1224 | // installation is the reason it was disabled, and no other reasons exist. |
| 1225 | int reasons = extension_prefs_->GetDisableReasons(extension->id()); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1226 | const int kReasonMask = disable_reason::DISABLE_PERMISSIONS_INCREASE | |
| 1227 | disable_reason::DISABLE_REMOTE_INSTALL; |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 1228 | if (reasons & kReasonMask && !(reasons & ~kReasonMask)) { |
| 1229 | AddExtensionDisabledError( |
| 1230 | this, extension, |
| 1231 | extension_prefs_->HasDisableReason( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1232 | extension->id(), disable_reason::DISABLE_REMOTE_INSTALL)); |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 1233 | } |
[email protected] | f574c40 | 2012-12-04 23:20:31 | [diff] [blame] | 1234 | } |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1235 | } |
| 1236 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1237 | void ExtensionService::AddComponentExtension(const Extension* extension) { |
Samuel Huang | 7987ebd | 2019-04-08 13:01:37 | [diff] [blame] | 1238 | extension_prefs_->ClearInapplicableDisableReasonsForComponentExtension( |
| 1239 | extension->id()); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1240 | const std::string old_version_string( |
| 1241 | extension_prefs_->GetVersionString(extension->id())); |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 1242 | const base::Version old_version(old_version_string); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1243 | |
[email protected] | 0181a7d | 2013-11-12 01:08:42 | [diff] [blame] | 1244 | VLOG(1) << "AddComponentExtension " << extension->name(); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 1245 | if (!old_version.IsValid() || old_version != extension->version()) { |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1246 | VLOG(1) << "Component extension " << extension->name() << " (" |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 1247 | << extension->id() << ") installing/upgrading from '" |
| 1248 | << old_version_string << "' to " |
| 1249 | << extension->version().GetString(); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1250 | |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 1251 | // TODO(crbug.com/696822): If needed, add support for Declarative Net |
| 1252 | // Request to component extensions and pass the ruleset checksum here. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1253 | AddNewOrUpdatedExtension(extension, Extension::ENABLED, kInstallFlagNone, |
| 1254 | syncer::StringOrdinal(), std::string(), |
| 1255 | base::nullopt); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1256 | return; |
| 1257 | } |
| 1258 | |
| 1259 | AddExtension(extension); |
| 1260 | } |
| 1261 | |
[email protected] | b914e29 | 2013-04-26 07:10:03 | [diff] [blame] | 1262 | void ExtensionService::CheckPermissionsIncrease(const Extension* extension, |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1263 | bool is_extension_loaded) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1264 | PermissionsUpdater(profile_).InitializePermissions(extension); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1265 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1266 | // We keep track of all permissions the user has granted each extension. |
| 1267 | // This allows extensions to gracefully support backwards compatibility |
| 1268 | // by including unknown permissions in their manifests. When the user |
| 1269 | // installs the extension, only the recognized permissions are recorded. |
| 1270 | // When the unknown permissions become recognized (e.g., through browser |
| 1271 | // upgrade), we can prompt the user to accept these new permissions. |
| 1272 | // Extensions can also silently upgrade to less permissions, and then |
| 1273 | // silently upgrade to a version that adds these permissions back. |
| 1274 | // |
| 1275 | // For example, pretend that Chrome 10 includes a permission "omnibox" |
| 1276 | // for an API that adds suggestions to the omnibox. An extension can |
| 1277 | // maintain backwards compatibility while still having "omnibox" in the |
| 1278 | // manifest. If a user installs the extension on Chrome 9, the browser |
| 1279 | // will record the permissions it recognized, not including "omnibox." |
| 1280 | // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 1281 | // will disable the extension and prompt the user to approve the increase |
| 1282 | // in privileges. The extension could then release a new version that |
| 1283 | // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 1284 | // still remember that "omnibox" had been granted, so that if the |
| 1285 | // extension once again includes "omnibox" in an upgrade, the extension |
| 1286 | // can upgrade without requiring this user's approval. |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 1287 | int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1288 | |
rockot | 1d4a0626 | 2015-02-17 19:39:28 | [diff] [blame] | 1289 | // Silently grant all active permissions to default apps and apps installed |
| 1290 | // in kiosk mode. |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 1291 | bool auto_grant_permission = |
rockot | 1d4a0626 | 2015-02-17 19:39:28 | [diff] [blame] | 1292 | extension->was_installed_by_default() || |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1293 | ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode(); |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 1294 | if (auto_grant_permission) |
[email protected] | b914e29 | 2013-04-26 07:10:03 | [diff] [blame] | 1295 | GrantPermissions(extension); |
| 1296 | |
| 1297 | bool is_privilege_increase = false; |
| 1298 | // We only need to compare the granted permissions to the current permissions |
rockot | 1d4a0626 | 2015-02-17 19:39:28 | [diff] [blame] | 1299 | // if the extension has not been auto-granted its permissions above and is |
| 1300 | // installed internally. |
| 1301 | if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1302 | // Add all the recognized permissions if the granted permissions list |
| 1303 | // hasn't been initialized yet. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1304 | std::unique_ptr<const PermissionSet> granted_permissions = |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1305 | extension_prefs_->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1306 | CHECK(granted_permissions.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1307 | |
| 1308 | // Here, we check if an extension's privileges have increased in a manner |
| 1309 | // that requires the user's approval. This could occur because the browser |
| 1310 | // upgraded and recognized additional privileges, or an extension upgrades |
| 1311 | // to a version that requires additional privileges. |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 1312 | is_privilege_increase = |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1313 | PermissionMessageProvider::Get()->IsPrivilegeIncrease( |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 1314 | *granted_permissions, |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 1315 | extension->permissions_data()->active_permissions(), |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 1316 | extension->GetType()); |
treib | 2c20f944 | 2016-05-18 19:50:28 | [diff] [blame] | 1317 | |
| 1318 | // If there was no privilege increase, the extension might still have new |
| 1319 | // permissions (which either don't generate a warning message, or whose |
| 1320 | // warning messages are suppressed by existing permissions). Grant the new |
| 1321 | // permissions. |
| 1322 | if (!is_privilege_increase) |
| 1323 | GrantPermissions(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1324 | } |
| 1325 | |
Marc Treib | 4bdb790b | 2018-07-07 15:02:48 | [diff] [blame] | 1326 | // TODO(crbug.com/860198): Before M48, extensions that came to us from sync in |
| 1327 | // a disabled state got assigned disable_reason::DISABLE_UNKNOWN_FROM_SYNC. |
| 1328 | // That reason isn't used anymore since the actual disable reason(s) are now |
| 1329 | // synced. This code is here to migrate any existing old state. |
| 1330 | if (disable_reasons & disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC) { |
| 1331 | // Remove the disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC |
| 1332 | // reason. |
| 1333 | disable_reasons &= ~disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC; |
| 1334 | extension_prefs_->RemoveDisableReason( |
| 1335 | extension->id(), disable_reason::DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC); |
| 1336 | // If there was no privilege increase, it was likely disabled by the user. |
| 1337 | // (If there *was* a privilege increase, we'll add an appropriate reason |
| 1338 | // later on, so nothing needs to be done here.) |
| 1339 | if (!is_privilege_increase) |
| 1340 | disable_reasons |= disable_reason::DISABLE_USER_ACTION; |
| 1341 | } |
| 1342 | |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1343 | bool previously_disabled = |
| 1344 | extension_prefs_->IsExtensionDisabled(extension->id()); |
Marc Treib | 4bdb790b | 2018-07-07 15:02:48 | [diff] [blame] | 1345 | // TODO(devlin): Is the |is_extension_loaded| check needed here? |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1346 | if (is_extension_loaded && previously_disabled) { |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 1347 | // Legacy disabled extensions do not have a disable reason. Infer that it |
| 1348 | // was likely disabled by the user. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1349 | if (disable_reasons == disable_reason::DISABLE_NONE) |
| 1350 | disable_reasons |= disable_reason::DISABLE_USER_ACTION; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1351 | } |
| 1352 | |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1353 | // If the extension is disabled due to a permissions increase, but does in |
| 1354 | // fact have all permissions, remove that disable reason. |
| 1355 | // TODO(devlin): This was added to fix crbug.com/616474, but it's unclear |
| 1356 | // if this behavior should stay forever. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1357 | if (disable_reasons & disable_reason::DISABLE_PERMISSIONS_INCREASE) { |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1358 | bool reset_permissions_increase = false; |
| 1359 | if (!is_privilege_increase) { |
| 1360 | reset_permissions_increase = true; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1361 | disable_reasons &= ~disable_reason::DISABLE_PERMISSIONS_INCREASE; |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1362 | extension_prefs_->RemoveDisableReason( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1363 | extension->id(), disable_reason::DISABLE_PERMISSIONS_INCREASE); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1364 | } |
| 1365 | UMA_HISTOGRAM_BOOLEAN("Extensions.ResetPermissionsIncrease", |
| 1366 | reset_permissions_increase); |
| 1367 | } |
| 1368 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1369 | // Extension has changed permissions significantly. Disable it. A |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 1370 | // notification should be sent by the caller. If the extension is already |
| 1371 | // disabled because it was installed remotely, don't add another disable |
treib | aac30ec | 2015-06-10 09:18:09 | [diff] [blame] | 1372 | // reason. |
| 1373 | if (is_privilege_increase && |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1374 | !(disable_reasons & disable_reason::DISABLE_REMOTE_INSTALL)) { |
| 1375 | disable_reasons |= disable_reason::DISABLE_PERMISSIONS_INCREASE; |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 1376 | if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) |
treib | 2e0517f9 | 2015-05-07 23:15:36 | [diff] [blame] | 1377 | RecordPermissionMessagesHistogram(extension, "AutoDisable"); |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 1378 | |
brettw | 9e85ef4 | 2016-11-01 21:01:24 | [diff] [blame] | 1379 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 1380 | // If a custodian-installed extension is disabled for a supervised user due |
mamir | 51e05d0 | 2016-10-06 10:55:01 | [diff] [blame] | 1381 | // to a permissions increase, send a request to the custodian. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1382 | if (util::IsExtensionSupervised(extension, profile_) && |
treib | 40d3ad9 | 2015-10-20 18:15:42 | [diff] [blame] | 1383 | !ExtensionSyncService::Get(profile_)->HasPendingReenable( |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 1384 | extension->id(), extension->version())) { |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 1385 | SupervisedUserService* supervised_user_service = |
| 1386 | SupervisedUserServiceFactory::GetForProfile(profile_); |
treib | 40d3ad9 | 2015-10-20 18:15:42 | [diff] [blame] | 1387 | supervised_user_service->AddExtensionUpdateRequest(extension->id(), |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 1388 | extension->version()); |
treib | 8ecc1eb5 | 2015-03-04 18:29:06 | [diff] [blame] | 1389 | } |
| 1390 | #endif |
[email protected] | b914e29 | 2013-04-26 07:10:03 | [diff] [blame] | 1391 | } |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1392 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1393 | if (disable_reasons == disable_reason::DISABLE_NONE) |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1394 | extension_prefs_->SetExtensionEnabled(extension->id()); |
| 1395 | else |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 1396 | extension_prefs_->SetExtensionDisabled(extension->id(), disable_reasons); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1397 | } |
| 1398 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1399 | void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 1400 | std::set<std::string> extension_ids; |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1401 | for (const auto& extension : registry_->enabled_extensions()) { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1402 | if (!extension->is_theme() && extension->location() != Manifest::COMPONENT) |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1403 | extension_ids.insert(extension->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1404 | } |
| 1405 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1406 | // TODO(kalman): This is broken. ExtensionService is per-profile. |
| 1407 | // crash_keys::SetActiveExtensions is per-process. See |
| 1408 | // http://crbug.com/355029. |
[email protected] | f6431be8 | 2013-09-07 02:53:45 | [diff] [blame] | 1409 | crash_keys::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1410 | } |
| 1411 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 1412 | void ExtensionService::OnExtensionInstalled( |
[email protected] | 36a5c4c | 2011-12-14 16:34:50 | [diff] [blame] | 1413 | const Extension* extension, |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 1414 | const syncer::StringOrdinal& page_ordinal, |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 1415 | int install_flags, |
| 1416 | const base::Optional<int>& dnr_ruleset_checksum) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1417 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1418 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1419 | const std::string& id = extension->id(); |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 1420 | int disable_reasons = GetDisableReasonsOnInstalled(extension); |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1421 | std::string install_parameter; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1422 | const PendingExtensionInfo* pending_extension_info = |
[email protected] | 96aebe2 | 2014-07-16 04:07:51 | [diff] [blame] | 1423 | pending_extension_manager()->GetById(id); |
| 1424 | if (pending_extension_info) { |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 1425 | if (!pending_extension_info->ShouldAllowInstall(extension)) { |
Devlin | ec30d36 | 2018-07-13 18:13:39 | [diff] [blame] | 1426 | // Hack for crbug.com/558299, see comment on DeleteThemeDoNotUse. |
| 1427 | if (extension->is_theme() && pending_extension_info->is_from_sync()) |
| 1428 | ExtensionSyncService::Get(profile_)->DeleteThemeDoNotUse(*extension); |
| 1429 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1430 | pending_extension_manager()->Remove(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 1431 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1432 | LOG(WARNING) << "ShouldAllowInstall() returned false for " << id |
| 1433 | << " of type " << extension->GetType() << " and update URL " |
| 1434 | << ManifestURL::GetUpdateURL(extension).spec() |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1435 | << "; not installing"; |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 1436 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1437 | // Delete the extension directory since we're not going to |
| 1438 | // load it. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1439 | if (!GetExtensionFileTaskRunner()->PostTask( |
| 1440 | FROM_HERE, base::BindOnce(&file_util::DeleteFile, |
tzik | 8d880ee | 2017-04-20 19:46:24 | [diff] [blame] | 1441 | extension->path(), true))) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1442 | NOTREACHED(); |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1443 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1444 | return; |
| 1445 | } |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1446 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1447 | install_parameter = pending_extension_info->install_parameter(); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1448 | pending_extension_manager()->Remove(id); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1449 | } else { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1450 | // We explicitly want to re-enable an uninstalled external |
| 1451 | // extension; if we're here, that means the user is manually |
| 1452 | // installing the extension. |
[email protected] | 46f3e10 | 2014-03-25 01:22:45 | [diff] [blame] | 1453 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1454 | disable_reasons = disable_reason::DISABLE_NONE; |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1455 | } |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 1456 | } |
| 1457 | |
asargent | e4de9f9 | 2016-09-15 01:40:06 | [diff] [blame] | 1458 | // If the old version of the extension was disabled due to corruption, this |
| 1459 | // new install may correct the problem. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1460 | disable_reasons &= ~disable_reason::DISABLE_CORRUPTED; |
asargent | e4de9f9 | 2016-09-15 01:40:06 | [diff] [blame] | 1461 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 1462 | // Unsupported requirements overrides the management policy. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1463 | if (install_flags & kInstallFlagHasRequirementErrors) { |
| 1464 | disable_reasons |= disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT; |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 1465 | } else { |
| 1466 | // Requirement is supported now, remove the corresponding disable reason |
| 1467 | // instead. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1468 | disable_reasons &= ~disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT; |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | // Check if the extension was disabled because of the minimum version |
| 1472 | // requirements from enterprise policy, and satisfies it now. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1473 | if (ExtensionManagementFactory::GetForBrowserContext(profile()) |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 1474 | ->CheckMinimumVersion(extension, nullptr)) { |
| 1475 | // And remove the corresponding disable reason. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1476 | disable_reasons &= ~disable_reason::DISABLE_UPDATE_REQUIRED_BY_POLICY; |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 1477 | } |
| 1478 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1479 | if (install_flags & kInstallFlagIsBlacklistedForMalware) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1480 | // Installation of a blacklisted extension can happen from sync, policy, |
| 1481 | // etc, where to maintain consistency we need to install it, just never |
| 1482 | // load it (see AddExtension). Usually it should be the job of callers to |
treib | aac30ec | 2015-06-10 09:18:09 | [diff] [blame] | 1483 | // intercept blacklisted extensions earlier (e.g. CrxInstaller, before even |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1484 | // showing the install dialogue). |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 1485 | extension_prefs_->AcknowledgeBlacklistedExtension(id); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1486 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", |
| 1487 | extension->location(), |
| 1488 | Manifest::NUM_LOCATIONS); |
| 1489 | } |
| 1490 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1491 | if (!GetInstalledExtension(extension->id())) { |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 1492 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 1493 | extension->GetType(), 100); |
[email protected] | 69084dc | 2012-11-17 07:39:30 | [diff] [blame] | 1494 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1495 | extension->location(), Manifest::NUM_LOCATIONS); |
treib | 2e0517f9 | 2015-05-07 23:15:36 | [diff] [blame] | 1496 | RecordPermissionMessagesHistogram(extension, "Install"); |
[email protected] | 69084dc | 2012-11-17 07:39:30 | [diff] [blame] | 1497 | } else { |
| 1498 | UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
| 1499 | extension->GetType(), 100); |
| 1500 | UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1501 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 1502 | } |
| 1503 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1504 | const Extension::State initial_state = |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1505 | disable_reasons == disable_reason::DISABLE_NONE ? Extension::ENABLED |
| 1506 | : Extension::DISABLED; |
treib | 8a6d989 | 2015-08-26 10:23:19 | [diff] [blame] | 1507 | if (initial_state == Extension::ENABLED) |
| 1508 | extension_prefs_->SetExtensionEnabled(id); |
| 1509 | else |
| 1510 | extension_prefs_->SetExtensionDisabled(id, disable_reasons); |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 1511 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1512 | ExtensionPrefs::DelayReason delay_reason; |
| 1513 | InstallGate::Action action = ShouldDelayExtensionInstall( |
| 1514 | extension, !!(install_flags & kInstallFlagInstallImmediately), |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1515 | &delay_reason); |
| 1516 | switch (action) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1517 | case InstallGate::INSTALL: |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1518 | AddNewOrUpdatedExtension(extension, initial_state, install_flags, |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 1519 | page_ordinal, install_parameter, |
| 1520 | dnr_ruleset_checksum); |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1521 | return; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1522 | case InstallGate::DELAY: |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 1523 | extension_prefs_->SetDelayedInstallInfo( |
| 1524 | extension, initial_state, install_flags, delay_reason, page_ordinal, |
| 1525 | install_parameter, dnr_ruleset_checksum); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1526 | |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1527 | // Transfer ownership of |extension|. |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1528 | delayed_installs_.Insert(extension); |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1529 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1530 | if (delay_reason == ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE) { |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1531 | // Notify observers that app update is available. |
ericwilligers | b5f79de | 2016-10-19 04:15:10 | [diff] [blame] | 1532 | for (auto& observer : update_observers_) |
| 1533 | observer.OnAppUpdateAvailable(extension); |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1534 | } |
| 1535 | return; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1536 | case InstallGate::ABORT: |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1537 | // Do nothing to abort the install. One such case is the shared module |
| 1538 | // service gets IMPORT_STATUS_UNRECOVERABLE status for the pending |
| 1539 | // install. |
| 1540 | return; |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1541 | } |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1542 | |
| 1543 | NOTREACHED() << "Unknown action for delayed install: " << action; |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1544 | } |
| 1545 | |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 1546 | void ExtensionService::OnExtensionManagementSettingsChanged() { |
| 1547 | error_controller_->ShowErrorIfNeeded(); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 1548 | |
| 1549 | // Revokes blocked permissions from active_permissions for all extensions. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1550 | ExtensionManagement* settings = |
| 1551 | ExtensionManagementFactory::GetForBrowserContext(profile()); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 1552 | CHECK(settings); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1553 | std::unique_ptr<ExtensionSet> all_extensions( |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 1554 | registry_->GenerateInstalledExtensionsSet()); |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1555 | for (const auto& extension : *all_extensions) { |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 1556 | if (!settings->IsPermissionSetAllowed( |
binjin | 685ade8 | 2014-11-06 09:53:56 | [diff] [blame] | 1557 | extension.get(), |
Nick Peterson | 0203be4a | 2017-07-19 00:25:14 | [diff] [blame] | 1558 | extension->permissions_data()->active_permissions()) && |
| 1559 | CanBlockExtension(extension.get())) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1560 | PermissionsUpdater(profile()).RemovePermissionsUnsafe( |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 1561 | extension.get(), *settings->GetBlockedPermissions(extension.get())); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 1565 | CheckManagementPolicy(); |
| 1566 | } |
| 1567 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1568 | void ExtensionService::AddNewOrUpdatedExtension( |
| 1569 | const Extension* extension, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1570 | Extension::State initial_state, |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 1571 | int install_flags, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1572 | const syncer::StringOrdinal& page_ordinal, |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 1573 | const std::string& install_parameter, |
| 1574 | const base::Optional<int>& dnr_ruleset_checksum) { |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1575 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 1576 | extension_prefs_->OnExtensionInstalled(extension, initial_state, page_ordinal, |
| 1577 | install_flags, install_parameter, |
| 1578 | dnr_ruleset_checksum); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 1579 | delayed_installs_.Remove(extension->id()); |
[email protected] | 913ffca9 | 2014-03-27 15:26:16 | [diff] [blame] | 1580 | if (InstallVerifier::NeedsVerification(*extension)) |
juncai | 33e46210 | 2015-05-18 20:48:44 | [diff] [blame] | 1581 | InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id()); |
ryanackley | 48bedbd | 2015-01-27 23:12:14 | [diff] [blame] | 1582 | |
| 1583 | const Extension* old = GetInstalledExtension(extension->id()); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1584 | if (AppDataMigrator::NeedsMigration(old, extension)) { |
ryanackley | 48bedbd | 2015-01-27 23:12:14 | [diff] [blame] | 1585 | app_data_migrator_->DoMigrationAndReply( |
vmpstr | a34d1132 | 2016-03-21 20:28:47 | [diff] [blame] | 1586 | old, extension, base::Bind(&ExtensionService::FinishInstallation, |
| 1587 | AsWeakPtr(), base::RetainedRef(extension))); |
ryanackley | 48bedbd | 2015-01-27 23:12:14 | [diff] [blame] | 1588 | return; |
| 1589 | } |
| 1590 | |
benwells | 1dd4acd | 2015-12-09 02:20:24 | [diff] [blame] | 1591 | FinishInstallation(extension); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1592 | } |
| 1593 | |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1594 | bool ExtensionService::FinishDelayedInstallationIfReady( |
| 1595 | const std::string& extension_id, |
| 1596 | bool install_immediately) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1597 | // Check if the extension already got installed. |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1598 | const Extension* extension = delayed_installs_.GetByID(extension_id); |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1599 | if (!extension) |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1600 | return false; |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1601 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1602 | ExtensionPrefs::DelayReason reason; |
| 1603 | const InstallGate::Action action = |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1604 | ShouldDelayExtensionInstall(extension, install_immediately, &reason); |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1605 | switch (action) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1606 | case InstallGate::INSTALL: |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1607 | break; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1608 | case InstallGate::DELAY: |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1609 | // Bail out and continue to delay the install. |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1610 | return false; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1611 | case InstallGate::ABORT: |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1612 | delayed_installs_.Remove(extension_id); |
| 1613 | // Make sure no version of the extension is actually installed, (i.e., |
| 1614 | // that this delayed install was not an update). |
| 1615 | CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get()); |
| 1616 | extension_prefs_->DeleteExtensionPrefs(extension_id); |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1617 | return false; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1618 | } |
| 1619 | |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1620 | scoped_refptr<const Extension> delayed_install = |
| 1621 | GetPendingExtensionUpdate(extension_id); |
| 1622 | CHECK(delayed_install.get()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1623 | delayed_installs_.Remove(extension_id); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1624 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1625 | if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1626 | NOTREACHED(); |
| 1627 | |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1628 | FinishInstallation(delayed_install.get()); |
| 1629 | return true; |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1630 | } |
| 1631 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1632 | void ExtensionService::FinishInstallation( |
benwells | 1dd4acd | 2015-12-09 02:20:24 | [diff] [blame] | 1633 | const Extension* extension) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1634 | const Extension* existing_extension = GetInstalledExtension(extension->id()); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 1635 | bool is_update = false; |
| 1636 | std::string old_name; |
| 1637 | if (existing_extension) { |
| 1638 | is_update = true; |
| 1639 | old_name = existing_extension->name(); |
| 1640 | } |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 1641 | registry_->TriggerOnWillBeInstalled( |
benwells | 1dd4acd | 2015-12-09 02:20:24 | [diff] [blame] | 1642 | extension, is_update, old_name); |
[email protected] | 17f0782 | 2014-05-22 08:45:15 | [diff] [blame] | 1643 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1644 | // Unpacked extensions default to allowing file access, but if that has been |
| 1645 | // overridden, don't reset the value. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1646 | if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1647 | !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { |
| 1648 | extension_prefs_->SetAllowFileAccess(extension->id(), true); |
| 1649 | } |
| 1650 | |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1651 | AddExtension(extension); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1652 | |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 1653 | // Notify observers that need to know when an installation is complete. |
[email protected] | 38e87253 | 2014-07-16 23:27:51 | [diff] [blame] | 1654 | registry_->TriggerOnInstalled(extension, is_update); |
[email protected] | bc44b5da | 2014-06-12 14:20:00 | [diff] [blame] | 1655 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1656 | // Check extensions that may have been delayed only because this shared module |
| 1657 | // was not available. |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 1658 | if (SharedModuleInfo::IsSharedModule(extension)) |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1659 | MaybeFinishDelayedInstallations(); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 1660 | } |
| 1661 | |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 1662 | const Extension* ExtensionService::GetPendingExtensionUpdate( |
| 1663 | const std::string& id) const { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1664 | return delayed_installs_.GetByID(id); |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 1665 | } |
| 1666 | |
mukai | 87a8d40 | 2014-09-15 20:15:09 | [diff] [blame] | 1667 | void ExtensionService::RegisterContentSettings( |
mmenke | ad5094ab | 2017-05-15 19:01:14 | [diff] [blame] | 1668 | HostContentSettingsMap* host_content_settings_map, |
| 1669 | Profile* profile) { |
| 1670 | // Most extension services key off of the original profile. |
| 1671 | Profile* original_profile = profile->GetOriginalProfile(); |
| 1672 | |
rkaplow | e65c2ff | 2015-02-14 16:29:54 | [diff] [blame] | 1673 | TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings"); |
mukai | a1aa351 | 2014-10-22 20:14:11 | [diff] [blame] | 1674 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
mukai | 87a8d40 | 2014-09-15 20:15:09 | [diff] [blame] | 1675 | host_content_settings_map->RegisterProvider( |
mukai | 87a8d40 | 2014-09-15 20:15:09 | [diff] [blame] | 1676 | HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER, |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1677 | std::unique_ptr<content_settings::ObservableProvider>( |
mukai | 87a8d40 | 2014-09-15 20:15:09 | [diff] [blame] | 1678 | new content_settings::CustomExtensionProvider( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1679 | ContentSettingsService::Get(original_profile) |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1680 | ->content_settings_store(), |
mmenke | ad5094ab | 2017-05-15 19:01:14 | [diff] [blame] | 1681 | // TODO(mmenke): CustomExtensionProvider expects this to be true |
| 1682 | // for incognito profiles. |
| 1683 | false))); |
mukai | 87a8d40 | 2014-09-15 20:15:09 | [diff] [blame] | 1684 | } |
| 1685 | |
[email protected] | e9d7496e | 2014-04-18 01:25:46 | [diff] [blame] | 1686 | void ExtensionService::TerminateExtension(const std::string& extension_id) { |
Michael Giuffrida | fcb42036 | 2017-10-11 21:50:26 | [diff] [blame] | 1687 | extension_registrar_.TerminateExtension(extension_id); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1688 | } |
| 1689 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 1690 | const Extension* ExtensionService::GetInstalledExtension( |
| 1691 | const std::string& id) const { |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 1692 | return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 1693 | } |
| 1694 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1695 | bool ExtensionService::OnExternalExtensionFileFound( |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1696 | const ExternalInstallInfoFile& info) { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 1697 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1698 | CHECK(crx_file::id_util::IdIsValid(info.extension_id)); |
| 1699 | if (extension_prefs_->IsExternalExtensionUninstalled(info.extension_id)) |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1700 | return false; |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1701 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1702 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 1703 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1704 | // installed on every startup. |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1705 | const Extension* existing = GetExtensionById(info.extension_id, true); |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1706 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1707 | if (existing) { |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1708 | // The default apps will have the location set as INTERNAL. Since older |
| 1709 | // default apps are installed as EXTERNAL, we override them. However, if the |
| 1710 | // app is already installed as internal, then do the version check. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1711 | // TODO(grv) : Remove after Q1-2013. |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1712 | bool is_default_apps_migration = |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1713 | (info.crx_location == Manifest::INTERNAL && |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1714 | Manifest::IsExternalLocation(existing->location())); |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1715 | |
| 1716 | if (!is_default_apps_migration) { |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 1717 | switch (existing->version().CompareTo(info.version)) { |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1718 | case -1: // existing version is older, we should upgrade |
| 1719 | break; |
| 1720 | case 0: // existing version is same, do nothing |
| 1721 | return false; |
| 1722 | case 1: // existing version is newer, uh-oh |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1723 | LOG(WARNING) << "Found external version of extension " |
| 1724 | << info.extension_id |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1725 | << "that is older than current version. Current version " |
| 1726 | << "is: " << existing->VersionString() << ". New " |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 1727 | << "version is: " << info.version.GetString() |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 1728 | << ". Keeping current version."; |
| 1729 | return false; |
| 1730 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1734 | // If the extension is already pending, don't start an install. |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 1735 | if (!pending_extension_manager()->AddFromExternalFile( |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 1736 | info.extension_id, info.crx_location, info.version, |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1737 | info.creation_flags, info.mark_acknowledged)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1738 | return false; |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 1739 | } |
[email protected] | 9c635f2 | 2010-12-02 09:36:36 | [diff] [blame] | 1740 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1741 | // no client (silent install) |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 1742 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1743 | installer->set_install_source(info.crx_location); |
| 1744 | installer->set_expected_id(info.extension_id); |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 1745 | installer->set_expected_version(info.version, |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 1746 | true /* fail_install_if_unexpected */); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 1747 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1748 | installer->set_install_immediately(info.install_immediately); |
| 1749 | installer->set_creation_flags(info.creation_flags); |
Oleg Davydov | fd848c0 | 2019-05-10 16:51:38 | [diff] [blame] | 1750 | |
| 1751 | CRXFileInfo file_info( |
| 1752 | info.path, |
| 1753 | info.crx_location == Manifest::EXTERNAL_POLICY |
| 1754 | ? GetPolicyVerifierFormat(ExtensionPrefs::Get(profile_) |
| 1755 | ->InsecureExtensionUpdatesEnabled()) |
| 1756 | : GetExternalVerifierFormat()); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 1757 | #if defined(OS_CHROMEOS) |
Oleg Davydov | fd848c0 | 2019-05-10 16:51:38 | [diff] [blame] | 1758 | InstallLimiter::Get(profile_)->Add(installer, file_info); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 1759 | #else |
Oleg Davydov | fd848c0 | 2019-05-10 16:51:38 | [diff] [blame] | 1760 | installer->InstallCrxFile(file_info); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 1761 | #endif |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1762 | |
| 1763 | // Depending on the source, a new external extension might not need a user |
| 1764 | // notification on installation. For such extensions, mark them acknowledged |
| 1765 | // now to suppress the notification. |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 1766 | if (info.mark_acknowledged) |
| 1767 | external_install_manager_->AcknowledgeExternalExtension(info.extension_id); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1768 | |
| 1769 | return true; |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1770 | } |
| 1771 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1772 | void ExtensionService::DidCreateRenderViewForBackgroundPage( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1773 | ExtensionHost* host) { |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 1774 | extension_registrar_.DidCreateRenderViewForBackgroundPage(host); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 1775 | } |
| 1776 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1777 | void ExtensionService::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1778 | const content::NotificationSource& source, |
| 1779 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1780 | switch (type) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1781 | case chrome::NOTIFICATION_APP_TERMINATING: |
| 1782 | // Shutdown has started. Don't start any more extension installs. |
| 1783 | // (We cannot use ExtensionService::Shutdown() for this because it |
| 1784 | // happens too late in browser teardown.) |
| 1785 | browser_terminating_ = true; |
| 1786 | break; |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1787 | case NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1788 | if (profile_ != |
| 1789 | content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 1790 | break; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1791 | } |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 1792 | |
Michael Giuffrida | fcb42036 | 2017-10-11 21:50:26 | [diff] [blame] | 1793 | // Mark the extension as terminated and deactivated. We want it to |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1794 | // be in a consistent state: either fully working or not loaded |
| 1795 | // at all, but never half-crashed. We do it in a PostTask so |
| 1796 | // that other handlers of this notification will still have |
| 1797 | // access to the Extension and ExtensionHost. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1798 | ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
skyostil | f221b7de | 2015-06-11 20:36:32 | [diff] [blame] | 1799 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
Michael Giuffrida | fcb42036 | 2017-10-11 21:50:26 | [diff] [blame] | 1800 | FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension, |
| 1801 | AsWeakPtr(), host->extension_id())); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 1802 | break; |
| 1803 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1804 | case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1805 | content::RenderProcessHost* process = |
| 1806 | content::Source<content::RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 1807 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1808 | Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 1809 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 1810 | break; |
| 1811 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1812 | ProcessMap* process_map = ProcessMap::Get(profile_); |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1813 | if (process_map->Contains(process->GetID())) { |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 1814 | // An extension process was terminated, this might have resulted in an |
| 1815 | // app or extension becoming idle. |
| 1816 | std::set<std::string> extension_ids = |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1817 | process_map->GetExtensionsInProcess(process->GetID()); |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 1818 | // In addition to the extensions listed in the process map, one of those |
| 1819 | // extensions could be referencing a shared module which is waiting for |
| 1820 | // idle to update. Check all imports of these extensions, too. |
| 1821 | std::set<std::string> import_ids; |
jdoerrie | 13cd648c8 | 2018-10-02 21:21:02 | [diff] [blame] | 1822 | for (auto it = extension_ids.begin(); it != extension_ids.end(); ++it) { |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 1823 | const Extension* extension = GetExtensionById(*it, true); |
| 1824 | if (!extension) |
| 1825 | continue; |
| 1826 | const std::vector<SharedModuleInfo::ImportInfo>& imports = |
| 1827 | SharedModuleInfo::GetImports(extension); |
| 1828 | std::vector<SharedModuleInfo::ImportInfo>::const_iterator import_it; |
| 1829 | for (import_it = imports.begin(); import_it != imports.end(); |
| 1830 | import_it++) { |
| 1831 | import_ids.insert((*import_it).extension_id); |
| 1832 | } |
| 1833 | } |
| 1834 | extension_ids.insert(import_ids.begin(), import_ids.end()); |
| 1835 | |
jdoerrie | 13cd648c8 | 2018-10-02 21:21:02 | [diff] [blame] | 1836 | for (auto it = extension_ids.begin(); it != extension_ids.end(); ++it) { |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 1837 | if (delayed_installs_.Contains(*it)) { |
skyostil | f221b7de | 2015-06-11 20:36:32 | [diff] [blame] | 1838 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 1839 | FROM_HERE, |
tzik | 8d880ee | 2017-04-20 19:46:24 | [diff] [blame] | 1840 | base::BindOnce( |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1841 | base::IgnoreResult( |
| 1842 | &ExtensionService::FinishDelayedInstallationIfReady), |
| 1843 | AsWeakPtr(), *it, false /*install_immediately*/), |
Lei Zhang | 1533915 | 2018-08-09 22:20:44 | [diff] [blame] | 1844 | kUpdateIdleDelay); |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1849 | process_map->RemoveAllFromProcess(process->GetID()); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 1850 | base::PostTaskWithTraits( |
| 1851 | FROM_HERE, {BrowserThread::IO}, |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1852 | base::BindOnce(&InfoMap::UnregisterAllExtensionsInProcess, |
tzik | 8d880ee | 2017-04-20 19:46:24 | [diff] [blame] | 1853 | system_->info_map(), process->GetID())); |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 1854 | break; |
| 1855 | } |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1856 | case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: { |
| 1857 | OnProfileDestructionStarted(); |
| 1858 | break; |
| 1859 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1860 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 1861 | default: |
| 1862 | NOTREACHED() << "Unexpected notification type."; |
| 1863 | } |
| 1864 | } |
| 1865 | |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 1866 | int ExtensionService::GetDisableReasonsOnInstalled(const Extension* extension) { |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 1867 | bool is_update_from_same_type = false; |
| 1868 | { |
| 1869 | const Extension* existing_extension = |
| 1870 | GetInstalledExtension(extension->id()); |
| 1871 | is_update_from_same_type = |
| 1872 | existing_extension && |
| 1873 | existing_extension->manifest()->type() == extension->manifest()->type(); |
| 1874 | } |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1875 | disable_reason::DisableReason disable_reason = disable_reason::DISABLE_NONE; |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 1876 | // Extensions disabled by management policy should always be disabled, even |
| 1877 | // if it's force-installed. |
| 1878 | if (system_->management_policy()->MustRemainDisabled( |
| 1879 | extension, &disable_reason, nullptr)) { |
| 1880 | // A specified reason is required to disable the extension. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1881 | DCHECK(disable_reason != disable_reason::DISABLE_NONE); |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 1882 | return disable_reason; |
| 1883 | } |
| 1884 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1885 | // Extensions installed by policy can't be disabled. So even if a previous |
| 1886 | // installation disabled the extension, make sure it is now enabled. |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 1887 | if (system_->management_policy()->MustRemainEnabled(extension, nullptr)) |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1888 | return disable_reason::DISABLE_NONE; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1889 | |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 1890 | // An already disabled extension should inherit the disable reasons and |
| 1891 | // remain disabled. |
| 1892 | if (extension_prefs_->IsExtensionDisabled(extension->id())) { |
| 1893 | int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); |
| 1894 | // If an extension was disabled without specified reason, presume it's |
| 1895 | // disabled by user. |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1896 | return disable_reasons == disable_reason::DISABLE_NONE |
| 1897 | ? disable_reason::DISABLE_USER_ACTION |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 1898 | : disable_reasons; |
| 1899 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1900 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1901 | if (ExternalInstallManager::IsPromptingEnabled()) { |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1902 | // External extensions are initially disabled. We prompt the user before |
[email protected] | 2c495c4 | 2013-01-04 21:49:54 | [diff] [blame] | 1903 | // enabling them. Hosted apps are excepted because they are not dangerous |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 1904 | // (they need to be launched by the user anyway). We also don't prompt for |
| 1905 | // extensions updating; this is because the extension will be disabled from |
| 1906 | // the initial install if it is supposed to be, and this allows us to turn |
| 1907 | // this on for other platforms without disabling already-installed |
| 1908 | // extensions. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1909 | if (extension->GetType() != Manifest::TYPE_HOSTED_APP && |
| 1910 | Manifest::IsExternalLocation(extension->location()) && |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 1911 | !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) && |
| 1912 | !is_update_from_same_type) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1913 | return disable_reason::DISABLE_EXTERNAL_EXTENSION; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1914 | } |
| 1915 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1916 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1917 | return disable_reason::DISABLE_NONE; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1918 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1919 | |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 1920 | // Helper method to determine if an extension can be blocked. |
| 1921 | bool ExtensionService::CanBlockExtension(const Extension* extension) const { |
mlerman | 3690e5be | 2014-12-01 22:57:44 | [diff] [blame] | 1922 | DCHECK(extension); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 1923 | return extension->location() != Manifest::COMPONENT && |
| 1924 | extension->location() != Manifest::EXTERNAL_COMPONENT && |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1925 | !system_->management_policy()->MustRemainEnabled(extension, nullptr); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 1926 | } |
| 1927 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1928 | InstallGate::Action ExtensionService::ShouldDelayExtensionInstall( |
| 1929 | const Extension* extension, |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1930 | bool install_immediately, |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1931 | ExtensionPrefs::DelayReason* reason) const { |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1932 | for (const auto& entry : install_delayer_registry_) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1933 | InstallGate* const delayer = entry.second; |
| 1934 | InstallGate::Action action = |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1935 | delayer->ShouldDelay(extension, install_immediately); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1936 | if (action != InstallGate::INSTALL) { |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 1937 | *reason = entry.first; |
| 1938 | return action; |
| 1939 | } |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 1940 | } |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 1941 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1942 | return InstallGate::INSTALL; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void ExtensionService::MaybeFinishDelayedInstallations() { |
| 1946 | std::vector<std::string> to_be_installed; |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1947 | for (const auto& extension : delayed_installs_) { |
| 1948 | to_be_installed.push_back(extension->id()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1949 | } |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 1950 | for (const auto& extension_id : to_be_installed) { |
Toni Barzic | 667db0d3 | 2018-01-09 18:00:19 | [diff] [blame] | 1951 | FinishDelayedInstallationIfReady(extension_id, |
| 1952 | false /*install_immediately*/); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1953 | } |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1954 | } |
| 1955 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 1956 | void ExtensionService::OnBlacklistUpdated() { |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 1957 | blacklist_->GetBlacklistedIDs( |
[email protected] | f47f717 | 2014-03-19 19:27:10 | [diff] [blame] | 1958 | registry_->GenerateInstalledExtensionsSet()->GetIDs(), |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1959 | base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr())); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1960 | } |
| 1961 | |
weidongg | 0469523 | 2017-06-09 00:01:05 | [diff] [blame] | 1962 | void ExtensionService::OnUpgradeRecommended() { |
| 1963 | // Notify observers that chrome update is available. |
| 1964 | for (auto& observer : update_observers_) |
| 1965 | observer.OnChromeUpdateAvailable(); |
| 1966 | } |
| 1967 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 1968 | void ExtensionService::PreAddExtension(const Extension* extension, |
| 1969 | const Extension* old_extension) { |
Michael Giuffrida | 573992d | 2018-02-08 00:48:44 | [diff] [blame] | 1970 | // Check if the extension's privileges have changed and mark the |
| 1971 | // extension disabled if necessary. |
| 1972 | CheckPermissionsIncrease(extension, !!old_extension); |
| 1973 | } |
| 1974 | |
Michael Giuffrida | 6397c59 | 2017-10-09 20:46:53 | [diff] [blame] | 1975 | bool ExtensionService::CanEnableExtension(const Extension* extension) { |
| 1976 | return !system_->management_policy()->MustRemainDisabled(extension, nullptr, |
| 1977 | nullptr); |
| 1978 | } |
| 1979 | |
| 1980 | bool ExtensionService::CanDisableExtension(const Extension* extension) { |
| 1981 | // Some extensions cannot be disabled by users: |
| 1982 | // - |extension| can be null if sync disables an extension that is not |
| 1983 | // installed yet; allow disablement in this case. |
| 1984 | if (!extension) |
| 1985 | return true; |
| 1986 | |
| 1987 | // - Shared modules are just resources used by other extensions, and are not |
| 1988 | // user-controlled. |
| 1989 | if (SharedModuleInfo::IsSharedModule(extension)) |
| 1990 | return false; |
| 1991 | |
| 1992 | // - EXTERNAL_COMPONENT extensions are not generally modifiable by users, but |
| 1993 | // can be uninstalled by the browser if the user sets extension-specific |
| 1994 | // preferences. |
| 1995 | if (extension->location() == Manifest::EXTERNAL_COMPONENT) |
| 1996 | return true; |
| 1997 | |
| 1998 | return system_->management_policy()->UserMayModifySettings(extension, |
| 1999 | nullptr); |
| 2000 | } |
| 2001 | |
| 2002 | bool ExtensionService::ShouldBlockExtension(const Extension* extension) { |
| 2003 | if (!block_extensions_) |
| 2004 | return false; |
| 2005 | |
| 2006 | // Blocked extensions aren't marked as such in prefs, thus if |
| 2007 | // |block_extensions_| is true then CanBlockExtension() must be called with an |
| 2008 | // Extension object. If |extension| is not loaded, assume it should be |
| 2009 | // blocked. |
| 2010 | return !extension || CanBlockExtension(extension); |
| 2011 | } |
| 2012 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2013 | void ExtensionService::ManageBlacklist( |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2014 | const Blacklist::BlacklistStateMap& state_map) { |
[email protected] | 54ee819 | 2014-03-29 17:37:24 | [diff] [blame] | 2015 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2016 | |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 2017 | std::set<std::string> blacklisted; |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2018 | ExtensionIdSet greylist; |
| 2019 | ExtensionIdSet unchanged; |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 2020 | for (const auto& it : state_map) { |
| 2021 | switch (it.second) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2022 | case NOT_BLACKLISTED: |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2023 | break; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2024 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2025 | case BLACKLISTED_MALWARE: |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 2026 | blacklisted.insert(it.first); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2027 | break; |
| 2028 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2029 | case BLACKLISTED_SECURITY_VULNERABILITY: |
| 2030 | case BLACKLISTED_CWS_POLICY_VIOLATION: |
| 2031 | case BLACKLISTED_POTENTIALLY_UNWANTED: |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 2032 | greylist.insert(it.first); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2033 | break; |
| 2034 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2035 | case BLACKLISTED_UNKNOWN: |
achuith | 2f5578b | 2016-02-26 21:57:13 | [diff] [blame] | 2036 | unchanged.insert(it.first); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2037 | break; |
| 2038 | } |
| 2039 | } |
| 2040 | |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 2041 | UpdateBlacklistedExtensions(blacklisted, unchanged); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2042 | UpdateGreylistedExtensions(greylist, unchanged, state_map); |
| 2043 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 2044 | error_controller_->ShowErrorIfNeeded(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | namespace { |
| 2048 | void Partition(const ExtensionIdSet& before, |
| 2049 | const ExtensionIdSet& after, |
| 2050 | const ExtensionIdSet& unchanged, |
| 2051 | ExtensionIdSet* no_longer, |
| 2052 | ExtensionIdSet* not_yet) { |
| 2053 | *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before); |
| 2054 | *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after); |
| 2055 | *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged); |
| 2056 | } |
| 2057 | } // namespace |
| 2058 | |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 2059 | void ExtensionService::UpdateBlacklistedExtensions( |
| 2060 | const ExtensionIdSet& blacklisted, |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2061 | const ExtensionIdSet& unchanged) { |
| 2062 | ExtensionIdSet not_yet_blocked, no_longer_blocked; |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 2063 | Partition(registry_->blacklisted_extensions().GetIDs(), blacklisted, |
| 2064 | unchanged, &no_longer_blocked, ¬_yet_blocked); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2065 | |
jdoerrie | 13cd648c8 | 2018-10-02 21:21:02 | [diff] [blame] | 2066 | for (auto it = no_longer_blocked.begin(); it != no_longer_blocked.end(); |
| 2067 | ++it) { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2068 | scoped_refptr<const Extension> extension = |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2069 | registry_->blacklisted_extensions().GetByID(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2070 | if (!extension.get()) { |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 2071 | NOTREACHED() << "Extension " << *it << " no longer blacklisted, " |
| 2072 | << "but it was never blacklisted."; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2073 | continue; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2074 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2075 | registry_->RemoveBlacklisted(*it); |
atuchin | 6dc7c44 | 2016-07-20 07:04:34 | [diff] [blame] | 2076 | extension_prefs_->SetExtensionBlacklistState(extension->id(), |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2077 | NOT_BLACKLISTED); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2078 | AddExtension(extension.get()); |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 2079 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled", |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2080 | extension->location(), |
| 2081 | Manifest::NUM_LOCATIONS); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2082 | } |
| 2083 | |
jdoerrie | 13cd648c8 | 2018-10-02 21:21:02 | [diff] [blame] | 2084 | for (auto it = not_yet_blocked.begin(); it != not_yet_blocked.end(); ++it) { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2085 | scoped_refptr<const Extension> extension = GetInstalledExtension(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2086 | if (!extension.get()) { |
| 2087 | NOTREACHED() << "Extension " << *it << " needs to be " |
| 2088 | << "blacklisted, but it's not installed."; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2089 | continue; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2090 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2091 | registry_->AddBlacklisted(extension); |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2092 | extension_prefs_->SetExtensionBlacklistState(extension->id(), |
| 2093 | BLACKLISTED_MALWARE); |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 2094 | UnloadExtension(*it, UnloadedExtensionReason::BLACKLIST); |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 2095 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled", |
| 2096 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2097 | } |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2098 | } |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2099 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2100 | // TODO(oleg): UMA logging |
| 2101 | void ExtensionService::UpdateGreylistedExtensions( |
| 2102 | const ExtensionIdSet& greylist, |
| 2103 | const ExtensionIdSet& unchanged, |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2104 | const Blacklist::BlacklistStateMap& state_map) { |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2105 | ExtensionIdSet not_yet_greylisted, no_longer_greylisted; |
| 2106 | Partition(greylist_.GetIDs(), |
| 2107 | greylist, unchanged, |
| 2108 | &no_longer_greylisted, ¬_yet_greylisted); |
| 2109 | |
jdoerrie | 13cd648c8 | 2018-10-02 21:21:02 | [diff] [blame] | 2110 | for (auto it = no_longer_greylisted.begin(); it != no_longer_greylisted.end(); |
| 2111 | ++it) { |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2112 | scoped_refptr<const Extension> extension = greylist_.GetByID(*it); |
| 2113 | if (!extension.get()) { |
| 2114 | NOTREACHED() << "Extension " << *it << " no longer greylisted, " |
| 2115 | << "but it was not marked as greylisted."; |
| 2116 | continue; |
| 2117 | } |
| 2118 | |
| 2119 | greylist_.Remove(*it); |
| 2120 | extension_prefs_->SetExtensionBlacklistState(extension->id(), |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2121 | NOT_BLACKLISTED); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2122 | if (extension_prefs_->GetDisableReasons(extension->id()) & |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2123 | disable_reason::DISABLE_GREYLIST) |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2124 | EnableExtension(*it); |
| 2125 | } |
| 2126 | |
jdoerrie | 13cd648c8 | 2018-10-02 21:21:02 | [diff] [blame] | 2127 | for (auto it = not_yet_greylisted.begin(); it != not_yet_greylisted.end(); |
| 2128 | ++it) { |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2129 | scoped_refptr<const Extension> extension = GetInstalledExtension(*it); |
| 2130 | if (!extension.get()) { |
| 2131 | NOTREACHED() << "Extension " << *it << " needs to be " |
| 2132 | << "disabled, but it's not installed."; |
| 2133 | continue; |
| 2134 | } |
| 2135 | greylist_.Insert(extension); |
| 2136 | extension_prefs_->SetExtensionBlacklistState(extension->id(), |
| 2137 | state_map.find(*it)->second); |
| 2138 | if (registry_->enabled_extensions().Contains(extension->id())) |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2139 | DisableExtension(*it, disable_reason::DISABLE_GREYLIST); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2140 | } |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 2141 | } |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2142 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2143 | void ExtensionService::AddUpdateObserver(UpdateObserver* observer) { |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2144 | update_observers_.AddObserver(observer); |
| 2145 | } |
| 2146 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2147 | void ExtensionService::RemoveUpdateObserver(UpdateObserver* observer) { |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2148 | update_observers_.RemoveObserver(observer); |
| 2149 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2150 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2151 | void ExtensionService::RegisterInstallGate(ExtensionPrefs::DelayReason reason, |
| 2152 | InstallGate* install_delayer) { |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 2153 | DCHECK(install_delayer_registry_.end() == |
| 2154 | install_delayer_registry_.find(reason)); |
| 2155 | install_delayer_registry_[reason] = install_delayer; |
| 2156 | } |
| 2157 | |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2158 | void ExtensionService::UnregisterInstallGate(InstallGate* install_delayer) { |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 2159 | for (auto it = install_delayer_registry_.begin(); |
| 2160 | it != install_delayer_registry_.end(); ++it) { |
| 2161 | if (it->second == install_delayer) { |
| 2162 | install_delayer_registry_.erase(it); |
| 2163 | return; |
| 2164 | } |
| 2165 | } |
| 2166 | } |
| 2167 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2168 | // Used only by test code. |
| 2169 | void ExtensionService::UnloadAllExtensionsInternal() { |
| 2170 | profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
| 2171 | |
| 2172 | registry_->ClearAll(); |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 2173 | system_->runtime_data()->ClearAll(); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2174 | |
| 2175 | // TODO(erikkay) should there be a notification for this? We can't use |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2176 | // EXTENSION_UNLOADED since that implies that the extension has |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 2177 | // been disabled or uninstalled. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2178 | } |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 2179 | |
| 2180 | void ExtensionService::OnProfileDestructionStarted() { |
| 2181 | ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
jdoerrie | 13cd648c8 | 2018-10-02 21:21:02 | [diff] [blame] | 2182 | for (auto it = ids_to_unload.begin(); it != ids_to_unload.end(); ++it) { |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 2183 | UnloadExtension(*it, UnloadedExtensionReason::PROFILE_SHUTDOWN); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 2184 | } |
| 2185 | } |
rdevlin.cronin | f2e1cb01 | 2017-05-27 01:27:59 | [diff] [blame] | 2186 | |
| 2187 | void ExtensionService::OnInstalledExtensionsLoaded() { |
| 2188 | if (updater_) |
| 2189 | updater_->Start(); |
| 2190 | |
| 2191 | // Enable any Shared Modules that incorrectly got disabled previously. |
| 2192 | // This is temporary code to fix incorrect behavior from previous versions of |
| 2193 | // Chrome and can be removed after several releases (perhaps M60). |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2194 | ExtensionList to_enable; |
rdevlin.cronin | f2e1cb01 | 2017-05-27 01:27:59 | [diff] [blame] | 2195 | for (const auto& extension : registry_->disabled_extensions()) { |
| 2196 | if (SharedModuleInfo::IsSharedModule(extension.get())) |
| 2197 | to_enable.push_back(extension); |
| 2198 | } |
| 2199 | for (const auto& extension : to_enable) { |
| 2200 | EnableExtension(extension->id()); |
| 2201 | } |
| 2202 | |
| 2203 | OnBlacklistUpdated(); |
| 2204 | } |
lazyboy | 75b9def | 2017-06-06 18:56:59 | [diff] [blame] | 2205 | |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 2206 | void ExtensionService::UninstallMigratedExtensions() { |
| 2207 | std::unique_ptr<ExtensionSet> installed_extensions = |
| 2208 | registry_->GenerateInstalledExtensionsSet(); |
| 2209 | |
| 2210 | for (const std::string& extension_id : kMigratedExtensionIds) { |
| 2211 | if (installed_extensions->Contains(extension_id)) { |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2212 | UninstallExtension(extension_id, UNINSTALL_REASON_MIGRATED, nullptr); |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 2213 | } |
| 2214 | } |
| 2215 | } |
Devlin Cronin | eea1b7a | 2018-05-26 02:46:21 | [diff] [blame] | 2216 | |
| 2217 | } // namespace extensions |