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