[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [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] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 5 | #include "chrome/browser/extensions/external_provider_impl.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 6 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 9 | #include <memory> |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 10 | #include <set> |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 11 | #include <utility> |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
[email protected] | 83b59325a | 2011-10-14 15:58:07 | [diff] [blame] | 14 | #include "base/command_line.h" |
Jan Wilken Dörrie | b5a41c3 | 2020-12-09 18:55:47 | [diff] [blame] | 15 | #include "base/containers/contains.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 17 | #include "base/logging.h" |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 18 | #include "base/memory/scoped_refptr.h" |
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 19 | #include "base/metrics/field_trial.h" |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 20 | #include "base/strings/string_util.h" |
rkaplow | dd66a134 | 2015-03-05 00:31:49 | [diff] [blame] | 21 | #include "base/trace_event/trace_event.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 22 | #include "base/values.h" |
| 23 | #include "base/version.h" |
Nico Weber | 897593f | 2019-07-25 23:17:55 | [diff] [blame] | 24 | #include "build/branding_buildflags.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 25 | #include "build/build_config.h" |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 26 | #include "build/chromeos_buildflags.h" |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 27 | #include "chrome/browser/app_mode/app_mode_utils.h" |
[email protected] | e601e82 | 2011-10-05 19:25:37 | [diff] [blame] | 28 | #include "chrome/browser/browser_process.h" |
pbond | 43ddd4f | 2015-09-08 16:39:19 | [diff] [blame] | 29 | #include "chrome/browser/browser_process_platform_part.h" |
binjin | 3030106 | 2014-09-08 20:27:34 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_management.h" |
xiyuan | 65b68ab1 | 2015-06-26 19:00:18 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_migrator.h" |
[email protected] | 8aa50c775 | 2013-05-23 12:57:50 | [diff] [blame] | 32 | #include "chrome/browser/extensions/external_component_loader.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 33 | #include "chrome/browser/extensions/external_policy_loader.h" |
| 34 | #include "chrome/browser/extensions/external_pref_loader.h" |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 35 | #include "chrome/browser/extensions/forced_extensions/install_stage_tracker.h" |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 36 | #include "chrome/browser/policy/profile_policy_connector.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 37 | #include "chrome/browser/profiles/profile.h" |
Ben Franz | 1d4cef8 | 2022-05-16 12:38:26 | [diff] [blame] | 38 | #include "chrome/browser/profiles/profiles_state.h" |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame] | 39 | #include "chrome/browser/web_applications/preinstalled_app_install_features.h" |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 40 | #include "chrome/common/chrome_paths.h" |
[email protected] | 83b59325a | 2011-10-14 15:58:07 | [diff] [blame] | 41 | #include "chrome/common/chrome_switches.h" |
xiyuan | 65b68ab1 | 2015-06-26 19:00:18 | [diff] [blame] | 42 | #include "chrome/common/extensions/extension_constants.h" |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 43 | #include "chrome/common/pref_names.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 44 | #include "components/crx_file/id_util.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 45 | #include "components/prefs/pref_service.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 46 | #include "content/public/browser/browser_thread.h" |
David Bertoni | 58c113a | 2019-08-02 19:53:26 | [diff] [blame] | 47 | #include "extensions/browser/extension_registry.h" |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 48 | #include "extensions/browser/external_install_info.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 49 | #include "extensions/browser/external_provider_interface.h" |
Dominique Fauteux-Chapleau | ff3bb35 | 2019-10-16 14:32:34 | [diff] [blame] | 50 | #include "extensions/browser/pref_names.h" |
Phillis Tang | 28427c46 | 2021-10-19 20:50:38 | [diff] [blame] | 51 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 52 | #include "extensions/common/extension.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 53 | #include "extensions/common/manifest.h" |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 54 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 55 | |
Ben Franz | 1d4cef8 | 2022-05-16 12:38:26 | [diff] [blame] | 56 | #if BUILDFLAG(IS_CHROMEOS) |
| 57 | #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" |
| 58 | #endif // BUIDLFLAG(IS_CHROMEOS) |
| 59 | |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 60 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Yao Li | c9cd767d | 2021-11-16 02:17:47 | [diff] [blame] | 61 | #include "ash/components/arc/arc_util.h" |
Henrique Ferreiro | 3777026 | 2021-02-06 01:20:53 | [diff] [blame] | 62 | #include "ash/constants/ash_paths.h" |
Wenzhao Zang | 463f114 | 2018-09-05 22:50:50 | [diff] [blame] | 63 | #include "base/path_service.h" |
Yeunjoo Choi | 9190764 | 2021-04-16 13:18:19 | [diff] [blame] | 64 | #include "chrome/browser/ash/customization/customization_document.h" |
Henrique Ferreiro | 606669a | 2021-02-24 13:36:55 | [diff] [blame] | 65 | #include "chrome/browser/ash/login/demo_mode/demo_extensions_external_loader.h" |
| 66 | #include "chrome/browser/ash/login/demo_mode/demo_session.h" |
Yeunjoo Choi | 7227dba | 2021-08-04 06:35:47 | [diff] [blame] | 67 | #include "chrome/browser/ash/policy/core/browser_policy_connector_ash.h" |
Yeunjoo Choi | 8623e4a | 2021-07-02 01:57:06 | [diff] [blame] | 68 | #include "chrome/browser/ash/policy/core/device_local_account.h" |
| 69 | #include "chrome/browser/ash/policy/core/device_local_account_policy_service.h" |
Yeunjoo Choi | 15ab1ac | 2021-02-04 17:15:07 | [diff] [blame] | 70 | #include "chrome/browser/ash/profiles/profile_helper.h" |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 71 | #include "chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.h" |
Maksim Ivanov | 8738d33 | 2020-01-07 22:19:01 | [diff] [blame] | 72 | #include "chrome/browser/chromeos/extensions/signin_screen_extensions_external_loader.h" |
Swapnil | 5eca041 | 2021-02-12 08:32:54 | [diff] [blame] | 73 | #include "extensions/common/constants.h" |
[email protected] | b39d2571 | 2013-03-14 09:53:40 | [diff] [blame] | 74 | #else |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 75 | #include "chrome/browser/extensions/preinstalled_apps.h" |
[email protected] | 86c6b9e3 | 2011-10-25 17:09:10 | [diff] [blame] | 76 | #endif |
| 77 | |
Xiaohan Wang | be233b6 | 2022-01-14 19:15:53 | [diff] [blame] | 78 | #if BUILDFLAG(IS_WIN) |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 79 | #include "chrome/browser/extensions/external_registry_loader_win.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 80 | #endif |
| 81 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 82 | using content::BrowserThread; |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 83 | using extensions::mojom::ManifestLocation; |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 84 | |
| 85 | namespace extensions { |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 86 | |
Ahmed Fakhry | 9ef29e04 | 2017-09-01 16:32:00 | [diff] [blame] | 87 | namespace { |
| 88 | |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 89 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Ahmed Fakhry | 9ef29e04 | 2017-09-01 16:32:00 | [diff] [blame] | 90 | |
Wei Lee | 799de53 | 2021-11-10 03:33:36 | [diff] [blame] | 91 | const char kCameraAppId[] = "hfhhnacclhffhdffklopdkcgdhifgngh"; |
| 92 | |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 93 | // Certain pre-installed extensions are no longer needed on ARC devices as they |
| 94 | // were replaced by their ARC counterparts. |
Ahmed Fakhry | 9ef29e04 | 2017-09-01 16:32:00 | [diff] [blame] | 95 | bool ShouldUninstallExtensionReplacedByArcApp(const std::string& extension_id) { |
Alex Newcomer | f8c542f | 2018-08-13 23:48:50 | [diff] [blame] | 96 | if (!arc::IsArcAvailable()) |
Ahmed Fakhry | 9ef29e04 | 2017-09-01 16:32:00 | [diff] [blame] | 97 | return false; |
| 98 | |
| 99 | if (extension_id == extension_misc::kGooglePlayBooksAppId || |
| 100 | extension_id == extension_misc::kGooglePlayMoviesAppId || |
| 101 | extension_id == extension_misc::kGooglePlayMusicAppId) { |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | return false; |
| 106 | } |
| 107 | |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 108 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Ahmed Fakhry | 9ef29e04 | 2017-09-01 16:32:00 | [diff] [blame] | 109 | |
| 110 | } // namespace |
| 111 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 112 | // Constants for keeping track of extension preferences in a dictionary. |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 113 | const char ExternalProviderImpl::kInstallParam[] = "install_parameter"; |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 114 | const char ExternalProviderImpl::kExternalCrx[] = "external_crx"; |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 115 | const char ExternalProviderImpl::kExternalVersion[] = "external_version"; |
| 116 | const char ExternalProviderImpl::kExternalUpdateUrl[] = "external_update_url"; |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 117 | const char ExternalProviderImpl::kIsBookmarkApp[] = "is_bookmark_app"; |
| 118 | const char ExternalProviderImpl::kIsFromWebstore[] = "is_from_webstore"; |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 119 | const char ExternalProviderImpl::kKeepIfPresent[] = "keep_if_present"; |
[email protected] | bf9fd5ae | 2014-04-09 22:50:06 | [diff] [blame] | 120 | const char ExternalProviderImpl::kWasInstalledByOem[] = "was_installed_by_oem"; |
Alan Cutter | b81d0e0 | 2020-08-05 09:10:34 | [diff] [blame] | 121 | const char ExternalProviderImpl::kWebAppMigrationFlag[] = |
| 122 | "web_app_migration_flag"; |
[email protected] | bf9fd5ae | 2014-04-09 22:50:06 | [diff] [blame] | 123 | const char ExternalProviderImpl::kSupportedLocales[] = "supported_locales"; |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 124 | const char ExternalProviderImpl::kMayBeUntrusted[] = "may_be_untrusted"; |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 125 | const char ExternalProviderImpl::kMinProfileCreatedByVersion[] = |
| 126 | "min_profile_created_by_version"; |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 127 | const char ExternalProviderImpl::kDoNotInstallForEnterprise[] = |
| 128 | "do_not_install_for_enterprise"; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 129 | |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 130 | ExternalProviderImpl::ExternalProviderImpl( |
| 131 | VisitorInterface* service, |
| 132 | const scoped_refptr<ExternalLoader>& loader, |
| 133 | Profile* profile, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 134 | ManifestLocation crx_location, |
| 135 | ManifestLocation download_location, |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 136 | int creation_flags) |
[email protected] | 4b4c013 | 2013-06-12 17:58:55 | [diff] [blame] | 137 | : crx_location_(crx_location), |
| 138 | download_location_(download_location), |
| 139 | service_(service), |
[email protected] | 4b4c013 | 2013-06-12 17:58:55 | [diff] [blame] | 140 | loader_(loader), |
| 141 | profile_(profile), |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 142 | creation_flags_(creation_flags) { |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 143 | DCHECK(profile_); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 144 | loader_->Init(this); |
| 145 | } |
| 146 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 147 | ExternalProviderImpl::~ExternalProviderImpl() { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 148 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 149 | loader_->OwnerShutdown(); |
| 150 | } |
| 151 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 152 | void ExternalProviderImpl::VisitRegisteredExtension() { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 153 | // The loader will call back to SetPrefs. |
| 154 | loader_->StartLoading(); |
| 155 | } |
| 156 | |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 157 | void ExternalProviderImpl::SetPrefs( |
| 158 | std::unique_ptr<base::DictionaryValue> prefs) { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 159 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 160 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 161 | // Check if the service is still alive. It is possible that it went |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 162 | // away while |loader_| was working on the FILE thread. |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 163 | if (!service_) |
| 164 | return; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 165 | |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 166 | InstallStageTracker* install_stage_tracker = |
| 167 | InstallStageTracker::Get(profile_); |
Peter Kasting | 7c683fe | 2021-06-24 15:12:10 | [diff] [blame] | 168 | for (auto it : prefs->DictItems()) { |
Swapnil | 5e0e0dc | 2020-09-21 14:59:47 | [diff] [blame] | 169 | install_stage_tracker->ReportInstallCreationStage( |
| 170 | it.first, |
| 171 | InstallStageTracker::InstallCreationStage::SEEN_BY_EXTERNAL_PROVIDER); |
Oleg Davydov | 52db874 | 2019-08-20 09:14:40 | [diff] [blame] | 172 | } |
| 173 | |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 174 | prefs_ = std::make_unique<base::Value::Dict>(std::move(prefs->GetDict())); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 175 | ready_ = true; // Queries for extensions are allowed from this point. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 176 | |
Maria Petrisor | bb5226b | 2022-06-02 09:10:51 | [diff] [blame] | 177 | NotifyServiceOnExternalExtensionsFound(); |
Maria Petrisor | dba7ac4 | 2021-10-06 09:01:30 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void ExternalProviderImpl::TriggerOnExternalExtensionFound() { |
| 181 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 182 | |
| 183 | // Check if the service is still alive. It is possible that it went |
| 184 | // away while |loader_| was working on the FILE thread. The prefs can be |
| 185 | // missing if SetPrefs() was not called yet. |
| 186 | if (!service_ || !prefs_) |
| 187 | return; |
| 188 | |
Maria Petrisor | bb5226b | 2022-06-02 09:10:51 | [diff] [blame] | 189 | NotifyServiceOnExternalExtensionsFound(); |
Maria Petrisor | dba7ac4 | 2021-10-06 09:01:30 | [diff] [blame] | 190 | } |
| 191 | |
Maria Petrisor | bb5226b | 2022-06-02 09:10:51 | [diff] [blame] | 192 | void ExternalProviderImpl::NotifyServiceOnExternalExtensionsFound() { |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 193 | std::vector<ExternalInstallInfoUpdateUrl> external_update_url_extensions; |
| 194 | std::vector<ExternalInstallInfoFile> external_file_extensions; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 195 | |
| 196 | RetrieveExtensionsFromPrefs(&external_update_url_extensions, |
| 197 | &external_file_extensions); |
lazyboy | 4aeef20 | 2016-09-07 21:28:59 | [diff] [blame] | 198 | for (const auto& extension : external_update_url_extensions) |
Maria Petrisor | bb5226b | 2022-06-02 09:10:51 | [diff] [blame] | 199 | service_->OnExternalExtensionUpdateUrlFound(extension, |
| 200 | /*force_update=*/true); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 201 | |
lazyboy | 4aeef20 | 2016-09-07 21:28:59 | [diff] [blame] | 202 | for (const auto& extension : external_file_extensions) |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 203 | service_->OnExternalExtensionFileFound(extension); |
Maria Petrisor | bb5226b | 2022-06-02 09:10:51 | [diff] [blame] | 204 | |
| 205 | service_->OnExternalProviderReady(this); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 206 | } |
| 207 | |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 208 | void ExternalProviderImpl::UpdatePrefs( |
| 209 | std::unique_ptr<base::DictionaryValue> prefs) { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 210 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 211 | CHECK(allow_updates_); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 212 | |
| 213 | // Check if the service is still alive. It is possible that it went |
| 214 | // away while |loader_| was working on the FILE thread. |
| 215 | if (!service_) |
| 216 | return; |
| 217 | |
| 218 | std::set<std::string> removed_extensions; |
| 219 | // Find extensions that were removed by this ExternalProvider. |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 220 | for (auto pref : *prefs_) { |
minch | d4e260e | 2022-01-21 19:17:53 | [diff] [blame] | 221 | const std::string& extension_id = pref.first; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 222 | // Don't bother about invalid ids. |
| 223 | if (!crx_file::id_util::IdIsValid(extension_id)) |
| 224 | continue; |
Maks Orlovich | 96e5a34 | 2022-01-05 20:24:36 | [diff] [blame] | 225 | if (!prefs->FindKey(extension_id)) |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 226 | removed_extensions.insert(extension_id); |
| 227 | } |
| 228 | |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 229 | prefs_ = std::make_unique<base::Value::Dict>(std::move(prefs->GetDict())); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 230 | |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 231 | std::vector<ExternalInstallInfoUpdateUrl> external_update_url_extensions; |
| 232 | std::vector<ExternalInstallInfoFile> external_file_extensions; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 233 | RetrieveExtensionsFromPrefs(&external_update_url_extensions, |
| 234 | &external_file_extensions); |
| 235 | |
| 236 | // Notify ExtensionService about completion of finding incremental updates |
| 237 | // from this provider. |
| 238 | // Provide the list of added and removed extensions. |
| 239 | service_->OnExternalProviderUpdateComplete( |
| 240 | this, external_update_url_extensions, external_file_extensions, |
| 241 | removed_extensions); |
| 242 | } |
| 243 | |
| 244 | void ExternalProviderImpl::RetrieveExtensionsFromPrefs( |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 245 | std::vector<ExternalInstallInfoUpdateUrl>* external_update_url_extensions, |
| 246 | std::vector<ExternalInstallInfoFile>* external_file_extensions) { |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 247 | // Set of unsupported extensions that need to be deleted from prefs_. |
| 248 | std::set<std::string> unsupported_extensions; |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 249 | InstallStageTracker* install_stage_tracker = |
| 250 | InstallStageTracker::Get(profile_); |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 251 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 252 | // Discover all the extensions this provider has. |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 253 | for (auto pref : *prefs_) { |
minch | d4e260e | 2022-01-21 19:17:53 | [diff] [blame] | 254 | const std::string& extension_id = pref.first; |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 255 | const base::DictionaryValue* extension_dict = nullptr; |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 256 | |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 257 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Wei Lee | 799de53 | 2021-11-10 03:33:36 | [diff] [blame] | 258 | if (extension_id == kCameraAppId) { |
Swapnil | 5eca041 | 2021-02-12 08:32:54 | [diff] [blame] | 259 | unsupported_extensions.insert(extension_id); |
| 260 | install_stage_tracker->ReportFailure( |
| 261 | extension_id, |
| 262 | InstallStageTracker::FailureReason::REPLACED_BY_SYSTEM_APP); |
| 263 | continue; |
| 264 | } |
| 265 | |
Ahmed Fakhry | 9ef29e04 | 2017-09-01 16:32:00 | [diff] [blame] | 266 | if (ShouldUninstallExtensionReplacedByArcApp(extension_id)) { |
| 267 | VLOG(1) << "Extension with key: " << extension_id << " was replaced " |
| 268 | << "by a default ARC app, and will be uninstalled."; |
| 269 | unsupported_extensions.emplace(extension_id); |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 270 | install_stage_tracker->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 271 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 272 | InstallStageTracker::FailureReason::REPLACED_BY_ARC_APP); |
Ahmed Fakhry | 9ef29e04 | 2017-09-01 16:32:00 | [diff] [blame] | 273 | continue; |
| 274 | } |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 275 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Ahmed Fakhry | 9ef29e04 | 2017-09-01 16:32:00 | [diff] [blame] | 276 | |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 277 | if (!crx_file::id_util::IdIsValid(extension_id)) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 278 | LOG(WARNING) << "Malformed extension dictionary: key " |
| 279 | << extension_id.c_str() << " is not a valid id."; |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 280 | install_stage_tracker->ReportFailure( |
| 281 | extension_id, InstallStageTracker::FailureReason::INVALID_ID); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 282 | continue; |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 283 | } |
| 284 | |
minch | d4e260e | 2022-01-21 19:17:53 | [diff] [blame] | 285 | if (!pref.second.GetAsDictionary(&extension_dict)) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 286 | LOG(WARNING) << "Malformed extension dictionary: key " |
| 287 | << extension_id.c_str() |
| 288 | << " has a value that is not a dictionary."; |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 289 | install_stage_tracker->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 290 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 291 | InstallStageTracker::FailureReason::MALFORMED_EXTENSION_DICT); |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 292 | continue; |
| 293 | } |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 294 | |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 295 | std::string external_crx; |
| 296 | const base::Value* external_version_value = nullptr; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 297 | std::string external_version; |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 298 | std::string external_update_url; |
| 299 | |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 300 | bool has_external_crx = |
| 301 | extension_dict->GetString(kExternalCrx, &external_crx); |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 302 | |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 303 | bool has_external_version = false; |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 304 | if (extension_dict->Get(kExternalVersion, &external_version_value)) { |
jdoerrie | 1f536b2 | 2017-10-23 17:15:11 | [diff] [blame] | 305 | if (external_version_value->is_string()) { |
Alex Rudenko | a4d75ab5 | 2021-07-09 15:39:44 | [diff] [blame] | 306 | external_version = external_version_value->GetString(); |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 307 | has_external_version = true; |
| 308 | } else { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 309 | install_stage_tracker->ReportFailure( |
| 310 | extension_id, InstallStageTracker::FailureReason:: |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 311 | MALFORMED_EXTENSION_DICT_VERSION); |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 312 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 313 | << extension_id.c_str() << ". " << kExternalVersion |
| 314 | << " value must be a string."; |
| 315 | continue; |
| 316 | } |
| 317 | } |
| 318 | |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 319 | bool has_external_update_url = |
| 320 | extension_dict->GetString(kExternalUpdateUrl, &external_update_url); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 321 | if (has_external_crx != has_external_version) { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 322 | install_stage_tracker->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 323 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 324 | InstallStageTracker::FailureReason::MALFORMED_EXTENSION_DICT); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 325 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 326 | << extension_id.c_str() << ". " << kExternalCrx |
| 327 | << " and " << kExternalVersion << " must be used together."; |
| 328 | continue; |
| 329 | } |
| 330 | |
| 331 | if (has_external_crx == has_external_update_url) { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 332 | install_stage_tracker->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 333 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 334 | InstallStageTracker::FailureReason::MALFORMED_EXTENSION_DICT); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 335 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 336 | << extension_id.c_str() << ". Exactly one of the " |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 337 | << "followng keys should be used: " << kExternalCrx |
| 338 | << ", " << kExternalUpdateUrl << "."; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 339 | continue; |
| 340 | } |
| 341 | |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 342 | // Check that extension supports current browser locale. |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 343 | const base::ListValue* supported_locales = nullptr; |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 344 | if (extension_dict->GetList(kSupportedLocales, &supported_locales)) { |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 345 | std::vector<std::string> browser_locales; |
| 346 | l10n_util::GetParentLocales(g_browser_process->GetApplicationLocale(), |
| 347 | &browser_locales); |
| 348 | |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 349 | bool locale_supported = false; |
Daniel Cheng | 354945d | 2022-02-02 23:39:17 | [diff] [blame] | 350 | for (const base::Value& locale : supported_locales->GetListDeprecated()) { |
Maks Orlovich | ab5bbab | 2021-11-26 16:30:35 | [diff] [blame] | 351 | const std::string* current_locale = locale.GetIfString(); |
| 352 | if (current_locale && l10n_util::IsValidLocaleSyntax(*current_locale)) { |
| 353 | std::string normalized_locale = |
| 354 | l10n_util::NormalizeLocale(*current_locale); |
| 355 | if (base::Contains(browser_locales, normalized_locale)) { |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 356 | locale_supported = true; |
| 357 | break; |
| 358 | } |
| 359 | } else { |
Maks Orlovich | ab5bbab | 2021-11-26 16:30:35 | [diff] [blame] | 360 | LOG(WARNING) << "Unrecognized locale '" |
| 361 | << (current_locale ? *current_locale : "(Not a string)") |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 362 | << "' found as supported locale for extension: " |
| 363 | << extension_id; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (!locale_supported) { |
| 368 | unsupported_extensions.insert(extension_id); |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 369 | install_stage_tracker->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 370 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 371 | InstallStageTracker::FailureReason::LOCALE_NOT_SUPPORTED); |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 372 | VLOG(1) << "Skip installing (or uninstall) external extension: " |
| 373 | << extension_id << " because the extension doesn't support " |
| 374 | << "the browser locale."; |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 375 | continue; |
| 376 | } |
| 377 | } |
| 378 | |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 379 | int creation_flags = creation_flags_; |
Nan Lin | c3aff1b9 | 2021-11-08 21:46:38 | [diff] [blame] | 380 | absl::optional<bool> is_bookmark_app = |
| 381 | extension_dict->FindBoolKey(kIsBookmarkApp); |
| 382 | if (is_bookmark_app.value_or(false)) { |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 383 | creation_flags |= Extension::FROM_BOOKMARK; |
| 384 | } |
Nan Lin | c3aff1b9 | 2021-11-08 21:46:38 | [diff] [blame] | 385 | absl::optional<bool> is_from_webstore = |
| 386 | extension_dict->FindBoolKey(kIsFromWebstore); |
| 387 | if (is_from_webstore.value_or(false)) { |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 388 | creation_flags |= Extension::FROM_WEBSTORE; |
| 389 | } |
Alan Cutter | b81d0e0 | 2020-08-05 09:10:34 | [diff] [blame] | 390 | |
| 391 | // If the extension is in a web app migration treat it as "keep_if_present" |
| 392 | // so it can get uninstalled by WebAppUiManager::UninstallAndReplace() once |
| 393 | // the replacement web app has installed and migrated over user preferences. |
| 394 | // TODO(crbug.com/1099150): Remove this field after migration is complete. |
| 395 | const std::string* web_app_migration_flag = |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 396 | extension_dict->FindStringPath(kWebAppMigrationFlag); |
Alan Cutter | b81d0e0 | 2020-08-05 09:10:34 | [diff] [blame] | 397 | bool is_migrating_to_web_app = |
| 398 | web_app_migration_flag && |
Alan Cutter | 52914e7 | 2021-05-05 09:35:48 | [diff] [blame] | 399 | web_app::IsPreinstalledAppInstallFeatureEnabled(*web_app_migration_flag, |
| 400 | *profile_); |
Alan Cutter | b81d0e0 | 2020-08-05 09:10:34 | [diff] [blame] | 401 | bool keep_if_present = |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 402 | extension_dict->FindBoolPath(kKeepIfPresent).value_or(false); |
Alan Cutter | b81d0e0 | 2020-08-05 09:10:34 | [diff] [blame] | 403 | if (keep_if_present || is_migrating_to_web_app) { |
David Bertoni | 58c113a | 2019-08-02 19:53:26 | [diff] [blame] | 404 | ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); |
| 405 | const Extension* extension = |
David Bertoni | a0b3472 | 2019-09-30 20:51:26 | [diff] [blame] | 406 | extension_registry ? extension_registry->GetExtensionById( |
| 407 | extension_id, ExtensionRegistry::EVERYTHING) |
| 408 | : nullptr; |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 409 | if (!extension) { |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 410 | unsupported_extensions.insert(extension_id); |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 411 | install_stage_tracker->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 412 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 413 | InstallStageTracker::FailureReason::NOT_PERFORMING_NEW_INSTALL); |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 414 | VLOG(1) << "Skip installing (or uninstall) external extension: " |
| 415 | << extension_id << " because the extension should be kept " |
| 416 | << "only if it is already installed."; |
| 417 | continue; |
| 418 | } |
| 419 | } |
Alan Cutter | b81d0e0 | 2020-08-05 09:10:34 | [diff] [blame] | 420 | |
Nan Lin | c3aff1b9 | 2021-11-08 21:46:38 | [diff] [blame] | 421 | absl::optional<bool> was_installed_by_oem = |
| 422 | extension_dict->FindBoolKey(kWasInstalledByOem); |
| 423 | if (was_installed_by_oem.value_or(false)) { |
dpolukhin | d0be494a | 2015-05-28 09:43:17 | [diff] [blame] | 424 | creation_flags |= Extension::WAS_INSTALLED_BY_OEM; |
| 425 | } |
Nan Lin | c3aff1b9 | 2021-11-08 21:46:38 | [diff] [blame] | 426 | absl::optional<bool> may_be_untrusted = |
| 427 | extension_dict->FindBoolKey(kMayBeUntrusted); |
| 428 | if (may_be_untrusted.value_or(false)) { |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 429 | creation_flags |= Extension::MAY_BE_UNTRUSTED; |
| 430 | } |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 431 | |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 432 | if (!HandleMinProfileVersion(extension_dict, extension_id, |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 433 | &unsupported_extensions)) { |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 434 | continue; |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 435 | } |
| 436 | |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 437 | if (!HandleDoNotInstallForEnterprise(extension_dict, extension_id, |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 438 | &unsupported_extensions)) { |
| 439 | continue; |
| 440 | } |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 441 | |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 442 | std::string install_parameter; |
Peter Kasting | 42e82e9 | 2021-09-15 16:39:17 | [diff] [blame] | 443 | extension_dict->GetString(kInstallParam, &install_parameter); |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 444 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 445 | if (has_external_crx) { |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 446 | if (crx_location_ == ManifestLocation::kInvalidLocation) { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 447 | install_stage_tracker->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 448 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 449 | InstallStageTracker::FailureReason::NOT_SUPPORTED_EXTENSION_DICT); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 450 | LOG(WARNING) << "This provider does not support installing external " |
| 451 | << "extensions from crx files."; |
| 452 | continue; |
| 453 | } |
Peter Kasting | 141279b | 2021-02-09 22:34:20 | [diff] [blame] | 454 | |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 455 | base::FilePath path = base::FilePath::FromUTF8Unsafe(external_crx); |
Peter Kasting | 141279b | 2021-02-09 22:34:20 | [diff] [blame] | 456 | if (path.value().find(base::FilePath::kParentDirectory) != |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 457 | base::StringPiece::npos) { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 458 | install_stage_tracker->ReportFailure( |
| 459 | extension_id, InstallStageTracker::FailureReason:: |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 460 | MALFORMED_EXTENSION_DICT_FILE_PATH); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 461 | LOG(WARNING) << "Path traversal not allowed in path: " |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 462 | << external_crx.c_str(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 463 | continue; |
| 464 | } |
| 465 | |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 466 | // If the path is relative, and the provider has a base path, |
| 467 | // build the absolute path to the crx file. |
Peter Kasting | 141279b | 2021-02-09 22:34:20 | [diff] [blame] | 468 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 469 | if (!path.IsAbsolute()) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 470 | base::FilePath base_path = loader_->GetBaseCrxFilePath(); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 471 | if (base_path.empty()) { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 472 | install_stage_tracker->ReportFailure( |
| 473 | extension_id, InstallStageTracker::FailureReason:: |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 474 | MALFORMED_EXTENSION_DICT_FILE_PATH); |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 475 | LOG(WARNING) << "File path " << external_crx.c_str() |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 476 | << " is relative. An absolute path is required."; |
| 477 | continue; |
| 478 | } |
Peter Kasting | 141279b | 2021-02-09 22:34:20 | [diff] [blame] | 479 | path = base_path.Append(path); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 480 | } |
| 481 | |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 482 | base::Version version(external_version); |
| 483 | if (!version.IsValid()) { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 484 | install_stage_tracker->ReportFailure( |
| 485 | extension_id, InstallStageTracker::FailureReason:: |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 486 | MALFORMED_EXTENSION_DICT_VERSION); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 487 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
| 488 | << extension_id.c_str() << ". Invalid version string \"" |
| 489 | << external_version << "\"."; |
| 490 | continue; |
| 491 | } |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 492 | external_file_extensions->emplace_back( |
| 493 | extension_id, version, path, crx_location_, creation_flags, |
| 494 | auto_acknowledge_, install_immediately_); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 495 | } else { // if (has_external_update_url) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 496 | CHECK(has_external_update_url); // Checking of keys above ensures this. |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 497 | if (download_location_ == ManifestLocation::kInvalidLocation) { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 498 | install_stage_tracker->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 499 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 500 | InstallStageTracker::FailureReason::NOT_SUPPORTED_EXTENSION_DICT); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 501 | LOG(WARNING) << "This provider does not support installing external " |
| 502 | << "extensions from update URLs."; |
| 503 | continue; |
| 504 | } |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 505 | GURL update_url(external_update_url); |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 506 | if (!update_url.is_valid()) { |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 507 | install_stage_tracker->ReportFailure( |
| 508 | extension_id, InstallStageTracker::FailureReason:: |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 509 | MALFORMED_EXTENSION_DICT_UPDATE_URL); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 510 | LOG(WARNING) << "Malformed extension dictionary for extension: " |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 511 | << extension_id.c_str() << ". Key " << kExternalUpdateUrl |
| 512 | << " has value \"" << external_update_url |
| 513 | << "\", which is not a valid URL."; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 514 | continue; |
| 515 | } |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 516 | external_update_url_extensions->emplace_back( |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 517 | extension_id, install_parameter, std::move(update_url), |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 518 | download_location_, creation_flags, auto_acknowledge_); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
jdoerrie | 13cd648c8 | 2018-10-02 21:21:02 | [diff] [blame] | 522 | for (auto it = unsupported_extensions.begin(); |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 523 | it != unsupported_extensions.end(); ++it) { |
| 524 | // Remove extension for the list of know external extensions. The extension |
| 525 | // will be uninstalled later because provider doesn't provide it anymore. |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 526 | prefs_->Remove(*it); |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 527 | } |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 528 | } |
| 529 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 530 | void ExternalProviderImpl::ServiceShutdown() { |
Bartek Nowierski | 3253b67 | 2020-06-01 20:37:12 | [diff] [blame] | 531 | service_ = nullptr; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 532 | } |
| 533 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 534 | bool ExternalProviderImpl::IsReady() const { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 535 | return ready_; |
| 536 | } |
| 537 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 538 | bool ExternalProviderImpl::HasExtension( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 539 | const std::string& id) const { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 540 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 541 | CHECK(prefs_.get()); |
| 542 | CHECK(ready_); |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 543 | return prefs_->contains(id); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 544 | } |
| 545 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 546 | bool ExternalProviderImpl::GetExtensionDetails( |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 547 | const std::string& id, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 548 | ManifestLocation* location, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 549 | std::unique_ptr<base::Version>* version) const { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 550 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 551 | CHECK(prefs_.get()); |
| 552 | CHECK(ready_); |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 553 | base::Value::Dict* dict = prefs_->FindDict(id); |
| 554 | if (!dict) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 555 | return false; |
| 556 | |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 557 | ManifestLocation loc = ManifestLocation::kInvalidLocation; |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 558 | if (dict->contains(kExternalUpdateUrl)) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 559 | loc = download_location_; |
| 560 | |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 561 | } else if (dict->contains(kExternalCrx)) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 562 | loc = crx_location_; |
| 563 | |
Matt Menke | dc421a9c | 2022-06-07 19:53:02 | [diff] [blame] | 564 | const std::string* external_version = dict->FindString(kExternalVersion); |
Maks Orlovich | 96e5a34 | 2022-01-05 20:24:36 | [diff] [blame] | 565 | if (!external_version) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 566 | return false; |
| 567 | |
| 568 | if (version) |
Maks Orlovich | 96e5a34 | 2022-01-05 20:24:36 | [diff] [blame] | 569 | *version = std::make_unique<base::Version>(*external_version); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 570 | |
| 571 | } else { |
| 572 | NOTREACHED(); // Chrome should not allow prefs to get into this state. |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | if (location) |
| 577 | *location = loc; |
| 578 | |
| 579 | return true; |
| 580 | } |
| 581 | |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 582 | bool ExternalProviderImpl::HandleMinProfileVersion( |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 583 | const base::DictionaryValue* extension, |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 584 | const std::string& extension_id, |
| 585 | std::set<std::string>* unsupported_extensions) { |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 586 | std::string min_profile_created_by_version; |
| 587 | if (extension->GetString(kMinProfileCreatedByVersion, |
| 588 | &min_profile_created_by_version)) { |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 589 | base::Version profile_version( |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 590 | profile_->GetPrefs()->GetString(prefs::kProfileCreatedByVersion)); |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 591 | base::Version min_version(min_profile_created_by_version); |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 592 | if (min_version.IsValid() && profile_version.CompareTo(min_version) < 0) { |
| 593 | unsupported_extensions->insert(extension_id); |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 594 | InstallStageTracker::Get(profile_)->ReportFailure( |
| 595 | extension_id, InstallStageTracker::FailureReason::TOO_OLD_PROFILE); |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 596 | VLOG(1) << "Skip installing (or uninstall) external extension: " |
| 597 | << extension_id |
| 598 | << " profile.created_by_version: " << profile_version.GetString() |
| 599 | << " min_profile_created_by_version: " |
| 600 | << min_profile_created_by_version; |
| 601 | return false; |
| 602 | } |
| 603 | } |
| 604 | return true; |
| 605 | } |
| 606 | |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 607 | bool ExternalProviderImpl::HandleDoNotInstallForEnterprise( |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 608 | const base::DictionaryValue* extension, |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 609 | const std::string& extension_id, |
| 610 | std::set<std::string>* unsupported_extensions) { |
Nan Lin | c3aff1b9 | 2021-11-08 21:46:38 | [diff] [blame] | 611 | absl::optional<bool> do_not_install_for_enterprise = |
| 612 | extension->FindBoolKey(kDoNotInstallForEnterprise); |
| 613 | if (do_not_install_for_enterprise.value_or(false)) { |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 614 | const policy::ProfilePolicyConnector* const connector = |
Xi Han | fe39afc6 | 2019-04-29 14:50:14 | [diff] [blame] | 615 | profile_->GetProfilePolicyConnector(); |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 616 | if (connector->IsManaged()) { |
| 617 | unsupported_extensions->insert(extension_id); |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 618 | InstallStageTracker::Get(profile_)->ReportFailure( |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 619 | extension_id, |
Oleg Davydov | dec175a | 2020-05-25 16:44:29 | [diff] [blame] | 620 | InstallStageTracker::FailureReason::DO_NOT_INSTALL_FOR_ENTERPRISE); |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 621 | VLOG(1) << "Skip installing (or uninstall) external extension " |
| 622 | << extension_id << " restricted for managed user"; |
| 623 | return false; |
| 624 | } |
| 625 | } |
| 626 | return true; |
| 627 | } |
| 628 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 629 | // static |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 630 | void ExternalProviderImpl::CreateExternalProviders( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 631 | VisitorInterface* service, |
| 632 | Profile* profile, |
| 633 | ProviderCollection* provider_list) { |
rkaplow | dd66a134 | 2015-03-05 00:31:49 | [diff] [blame] | 634 | TRACE_EVENT0("browser,startup", |
| 635 | "ExternalProviderImpl::CreateExternalProviders"); |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 636 | scoped_refptr<ExternalLoader> external_loader; |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 637 | scoped_refptr<ExternalLoader> external_recommended_loader; |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 638 | ManifestLocation crx_location = ManifestLocation::kInvalidLocation; |
achuith | d3da4f0 | 2017-03-23 20:05:29 | [diff] [blame] | 639 | |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 640 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Yeunjoo Choi | 36f21d54 | 2022-01-13 03:12:33 | [diff] [blame] | 641 | if (ash::ProfileHelper::IsSigninProfile(profile)) { |
Maksim Ivanov | 12801d0d | 2020-02-18 10:23:41 | [diff] [blame] | 642 | // Download extensions/apps installed by policy in the login profile. |
| 643 | // Extensions (not apps) installed through this path will have type |
| 644 | // |TYPE_LOGIN_SCREEN_EXTENSION| with limited API capabilities. |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 645 | crx_location = ManifestLocation::kExternalPolicyDownload; |
Maksim Ivanov | 8738d33 | 2020-01-07 22:19:01 | [diff] [blame] | 646 | external_loader = |
| 647 | base::MakeRefCounted<chromeos::SigninScreenExtensionsExternalLoader>( |
Oleg Davydov | ba7dd39 | 2021-03-18 09:47:44 | [diff] [blame] | 648 | profile); |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 649 | auto signin_profile_provider = std::make_unique<ExternalProviderImpl>( |
achuith | d3da4f0 | 2017-03-23 20:05:29 | [diff] [blame] | 650 | service, external_loader, profile, crx_location, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 651 | ManifestLocation::kExternalPolicyDownload, Extension::FOR_LOGIN_SCREEN); |
Maksim Ivanov | 8738d33 | 2020-01-07 22:19:01 | [diff] [blame] | 652 | signin_profile_provider->set_auto_acknowledge(true); |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 653 | signin_profile_provider->set_allow_updates(true); |
| 654 | provider_list->push_back(std::move(signin_profile_provider)); |
achuith | d3da4f0 | 2017-03-23 20:05:29 | [diff] [blame] | 655 | return; |
| 656 | } |
| 657 | |
Yeunjoo Choi | 7227dba | 2021-08-04 06:35:47 | [diff] [blame] | 658 | policy::BrowserPolicyConnectorAsh* connector = |
| 659 | g_browser_process->platform_part()->browser_policy_connector_ash(); |
[email protected] | 2d4cfed | 2014-01-14 13:59:57 | [diff] [blame] | 660 | bool is_chrome_os_public_session = false; |
[email protected] | 2fda997 | 2014-07-23 14:51:59 | [diff] [blame] | 661 | const user_manager::User* user = |
Yeunjoo Choi | 36f21d54 | 2022-01-13 03:12:33 | [diff] [blame] | 662 | ash::ProfileHelper::Get()->GetUserByProfile(profile); |
[email protected] | 2d4cfed | 2014-01-14 13:59:57 | [diff] [blame] | 663 | policy::DeviceLocalAccount::Type account_type; |
Roland Bock | 4ce23a92 | 2021-06-11 13:23:11 | [diff] [blame] | 664 | if (user && connector->IsDeviceEnterpriseManaged() && |
alemate | 909aa58a | 2016-11-03 22:49:07 | [diff] [blame] | 665 | policy::IsDeviceLocalAccountUser(user->GetAccountId().GetUserEmail(), |
| 666 | &account_type)) { |
[email protected] | 2d4cfed | 2014-01-14 13:59:57 | [diff] [blame] | 667 | if (account_type == policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION) |
| 668 | is_chrome_os_public_session = true; |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 669 | policy::DeviceLocalAccountPolicyBroker* broker = |
[email protected] | 9727582 | 2014-01-21 19:30:36 | [diff] [blame] | 670 | connector->GetDeviceLocalAccountPolicyService()->GetBrokerForUser( |
alemate | 909aa58a | 2016-11-03 22:49:07 | [diff] [blame] | 671 | user->GetAccountId().GetUserEmail()); |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 672 | if (broker) { |
| 673 | external_loader = broker->extension_loader(); |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 674 | crx_location = ManifestLocation::kExternalPolicy; |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 675 | } else { |
| 676 | NOTREACHED(); |
| 677 | } |
| 678 | } else { |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 679 | external_loader = base::MakeRefCounted<ExternalPolicyLoader>( |
Oleg Davydov | 52db874 | 2019-08-20 09:14:40 | [diff] [blame] | 680 | profile, ExtensionManagementFactory::GetForBrowserContext(profile), |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 681 | ExternalPolicyLoader::FORCED); |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 682 | external_recommended_loader = base::MakeRefCounted<ExternalPolicyLoader>( |
Oleg Davydov | 52db874 | 2019-08-20 09:14:40 | [diff] [blame] | 683 | profile, ExtensionManagementFactory::GetForBrowserContext(profile), |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 684 | ExternalPolicyLoader::RECOMMENDED); |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 685 | } |
| 686 | #else |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 687 | external_loader = base::MakeRefCounted<ExternalPolicyLoader>( |
Oleg Davydov | 52db874 | 2019-08-20 09:14:40 | [diff] [blame] | 688 | profile, ExtensionManagementFactory::GetForBrowserContext(profile), |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 689 | ExternalPolicyLoader::FORCED); |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 690 | external_recommended_loader = base::MakeRefCounted<ExternalPolicyLoader>( |
Oleg Davydov | 52db874 | 2019-08-20 09:14:40 | [diff] [blame] | 691 | profile, ExtensionManagementFactory::GetForBrowserContext(profile), |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 692 | ExternalPolicyLoader::RECOMMENDED); |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 693 | #endif |
| 694 | |
[email protected] | b9f4fe5 | 2012-11-09 21:40:59 | [diff] [blame] | 695 | // Policies are mandatory so they can't be skipped with command line flag. |
dcheng | c704794 | 2014-08-26 05:05:31 | [diff] [blame] | 696 | if (external_loader.get()) { |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 697 | auto policy_provider = std::make_unique<ExternalProviderImpl>( |
lazyboy | f33109d | 2016-08-31 00:37:08 | [diff] [blame] | 698 | service, external_loader, profile, crx_location, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 699 | ManifestLocation::kExternalPolicyDownload, Extension::NO_FLAGS); |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 700 | policy_provider->set_allow_updates(true); |
| 701 | provider_list->push_back(std::move(policy_provider)); |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 702 | } |
[email protected] | b9f4fe5 | 2012-11-09 21:40:59 | [diff] [blame] | 703 | |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 704 | // Load the KioskAppExternalProvider when running in the Chrome App kiosk |
| 705 | // mode. |
[email protected] | ee3da055 | 2014-07-16 05:27:31 | [diff] [blame] | 706 | if (chrome::IsRunningInForcedAppMode()) { |
Ben Franz | 1d4cef8 | 2022-05-16 12:38:26 | [diff] [blame] | 707 | #if BUILDFLAG(IS_CHROMEOS) |
| 708 | if (profiles::IsChromeAppKioskSession()) { |
| 709 | ManifestLocation location = ManifestLocation::kExternalPolicy; |
| 710 | |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 711 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Yeunjoo Choi | 7227dba | 2021-08-04 06:35:47 | [diff] [blame] | 712 | policy::BrowserPolicyConnectorAsh* const connector = |
| 713 | g_browser_process->platform_part()->browser_policy_connector_ash(); |
Ben Franz | 1d4cef8 | 2022-05-16 12:38:26 | [diff] [blame] | 714 | if (!connector || !connector->IsDeviceEnterpriseManaged()) |
| 715 | location = ManifestLocation::kExternalPref; |
| 716 | #endif |
pbond | 43ddd4f | 2015-09-08 16:39:19 | [diff] [blame] | 717 | |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 718 | auto kiosk_app_provider = std::make_unique<ExternalProviderImpl>( |
| 719 | service, |
Henrique Ferreiro | 26ed25a | 2021-02-01 21:59:29 | [diff] [blame] | 720 | base::MakeRefCounted<ash::KioskAppExternalLoader>( |
| 721 | ash::KioskAppExternalLoader::AppClass::kPrimary), |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 722 | profile, location, ManifestLocation::kInvalidLocation, |
| 723 | Extension::NO_FLAGS); |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 724 | kiosk_app_provider->set_auto_acknowledge(true); |
| 725 | kiosk_app_provider->set_install_immediately(true); |
| 726 | kiosk_app_provider->set_allow_updates(true); |
| 727 | provider_list->push_back(std::move(kiosk_app_provider)); |
jennyz | 26b7f43 | 2015-09-03 20:59:27 | [diff] [blame] | 728 | |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 729 | // Kiosk secondary app external provider. |
| 730 | auto secondary_kiosk_app_provider = |
| 731 | std::make_unique<ExternalProviderImpl>( |
| 732 | service, |
Henrique Ferreiro | 26ed25a | 2021-02-01 21:59:29 | [diff] [blame] | 733 | base::MakeRefCounted<ash::KioskAppExternalLoader>( |
| 734 | ash::KioskAppExternalLoader::AppClass::kSecondary), |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 735 | profile, ManifestLocation::kExternalPref, |
| 736 | ManifestLocation::kExternalPrefDownload, Extension::NO_FLAGS); |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 737 | secondary_kiosk_app_provider->set_auto_acknowledge(true); |
| 738 | secondary_kiosk_app_provider->set_install_immediately(true); |
| 739 | secondary_kiosk_app_provider->set_allow_updates(true); |
| 740 | provider_list->push_back(std::move(secondary_kiosk_app_provider)); |
| 741 | } |
[email protected] | ee3da055 | 2014-07-16 05:27:31 | [diff] [blame] | 742 | #endif |
| 743 | return; |
| 744 | } |
| 745 | |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 746 | // Extensions provided by recommended policies. |
| 747 | if (external_recommended_loader.get()) { |
Nicolas Ouellet-Payeur | 93b74ca1d | 2020-12-09 23:33:12 | [diff] [blame] | 748 | auto recommended_provider = std::make_unique<ExternalProviderImpl>( |
lazyboy | f33109d | 2016-08-31 00:37:08 | [diff] [blame] | 749 | service, external_recommended_loader, profile, crx_location, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 750 | ManifestLocation::kExternalPrefDownload, Extension::NO_FLAGS); |
Nicolas Ouellet-Payeur | 93b74ca1d | 2020-12-09 23:33:12 | [diff] [blame] | 751 | recommended_provider->set_auto_acknowledge(true); |
| 752 | provider_list->push_back(std::move(recommended_provider)); |
binjin | cccacef | 2014-10-13 19:00:20 | [diff] [blame] | 753 | } |
| 754 | |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 755 | // In tests don't install pre-installed apps. |
[email protected] | b9f4fe5 | 2012-11-09 21:40:59 | [diff] [blame] | 756 | // It would only slowdown tests and make them flaky. |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 757 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
Alan Cutter | d4c29eee | 2022-03-28 05:50:03 | [diff] [blame] | 758 | ::switches::kDisableDefaultApps)) { |
[email protected] | b9f4fe5 | 2012-11-09 21:40:59 | [diff] [blame] | 759 | return; |
[email protected] | 98820ac7 | 2019-01-24 19:47:16 | [diff] [blame] | 760 | } |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 761 | |
Xiaohan Wang | be233b6 | 2022-01-14 19:15:53 | [diff] [blame] | 762 | #if !BUILDFLAG(IS_WIN) |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 763 | // On Mac OS, items in /Library/... should be written by the superuser. |
| 764 | // Check that all components of the path are writable by root only. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 765 | ExternalPrefLoader::Options check_admin_permissions_on_mac; |
Xiaohan Wang | be233b6 | 2022-01-14 19:15:53 | [diff] [blame] | 766 | #if BUILDFLAG(IS_MAC) |
[email protected] | 0edc5541 | 2011-11-07 16:47:33 | [diff] [blame] | 767 | check_admin_permissions_on_mac = |
Peter Kasting | 9c68b0f | 2021-07-27 09:47:40 | [diff] [blame] | 768 | ExternalPrefLoader::ENSURE_PATH_CONTROLLED_BY_ADMIN; |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 769 | #else |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 770 | check_admin_permissions_on_mac = ExternalPrefLoader::NONE; |
[email protected] | 73e4c36 | 2011-09-22 14:47:18 | [diff] [blame] | 771 | #endif |
[email protected] | d6f7b10 | 2012-05-04 13:59:05 | [diff] [blame] | 772 | int bundled_extension_creation_flags = Extension::NO_FLAGS; |
Peter Kasting | be940e9 | 2014-11-20 23:14:08 | [diff] [blame] | 773 | #endif |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 774 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 5861bcd | 2012-10-16 21:40:19 | [diff] [blame] | 775 | bundled_extension_creation_flags = Extension::FROM_WEBSTORE | |
| 776 | Extension::WAS_INSTALLED_BY_DEFAULT; |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 777 | |
rkc | b526cd6b | 2014-12-18 16:54:37 | [diff] [blame] | 778 | if (!is_chrome_os_public_session) { |
[email protected] | 98820ac7 | 2019-01-24 19:47:16 | [diff] [blame] | 779 | int pref_load_flags = |
ginkage | f66fae52 | 2015-03-03 16:38:16 | [diff] [blame] | 780 | profile->IsNewProfile() |
| 781 | ? ExternalPrefLoader::DELAY_LOAD_UNTIL_PRIORITY_SYNC |
| 782 | : ExternalPrefLoader::NONE; |
[email protected] | 98820ac7 | 2019-01-24 19:47:16 | [diff] [blame] | 783 | pref_load_flags |= ExternalPrefLoader::USE_USER_TYPE_PROFILE_FILTER; |
| 784 | provider_list->push_back(std::make_unique<ExternalProviderImpl>( |
| 785 | service, |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 786 | base::MakeRefCounted<ExternalPrefLoader>( |
| 787 | chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, pref_load_flags, |
| 788 | profile), |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 789 | profile, ManifestLocation::kExternalPref, |
| 790 | ManifestLocation::kExternalPrefDownload, |
[email protected] | 98820ac7 | 2019-01-24 19:47:16 | [diff] [blame] | 791 | bundled_extension_creation_flags)); |
[email protected] | d0b2889 | 2014-03-05 18:56:31 | [diff] [blame] | 792 | |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 793 | // OEM pre-installed apps. |
[email protected] | acc3c7c2 | 2014-03-19 06:23:39 | [diff] [blame] | 794 | int oem_extension_creation_flags = |
| 795 | bundled_extension_creation_flags | Extension::WAS_INSTALLED_BY_OEM; |
Yeunjoo Choi | cf61fba | 2021-04-23 02:43:09 | [diff] [blame] | 796 | ash::ServicesCustomizationDocument* customization = |
| 797 | ash::ServicesCustomizationDocument::GetInstance(); |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 798 | provider_list->push_back(std::make_unique<ExternalProviderImpl>( |
lazyboy | f33109d | 2016-08-31 00:37:08 | [diff] [blame] | 799 | service, customization->CreateExternalLoader(profile), profile, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 800 | ManifestLocation::kExternalPref, |
| 801 | ManifestLocation::kExternalPrefDownload, oem_extension_creation_flags)); |
[email protected] | ebb489f | 2013-09-19 22:08:52 | [diff] [blame] | 802 | } |
Toni Barzic | dff5156 | 2018-07-24 19:55:46 | [diff] [blame] | 803 | |
| 804 | // For Chrome OS demo sessions, add pre-installed demo extensions and apps. |
Henrique Ferreiro | d71de90 | 2021-05-10 18:57:11 | [diff] [blame] | 805 | if (ash::DemoExtensionsExternalLoader::SupportedForProfile(profile)) { |
Wenzhao Zang | 463f114 | 2018-09-05 22:50:50 | [diff] [blame] | 806 | base::FilePath cache_dir; |
Henrique Ferreiro | d08abdf | 2022-01-18 11:35:09 | [diff] [blame] | 807 | CHECK(base::PathService::Get(ash::DIR_DEVICE_EXTENSION_LOCAL_CACHE, |
Wenzhao Zang | 463f114 | 2018-09-05 22:50:50 | [diff] [blame] | 808 | &cache_dir)); |
Henrique Ferreiro | d71de90 | 2021-05-10 18:57:11 | [diff] [blame] | 809 | auto loader = |
| 810 | base::MakeRefCounted<ash::DemoExtensionsExternalLoader>(cache_dir); |
Toni Barzic | dff5156 | 2018-07-24 19:55:46 | [diff] [blame] | 811 | std::unique_ptr<ExternalProviderImpl> demo_apps_provider = |
| 812 | std::make_unique<ExternalProviderImpl>( |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 813 | service, loader, profile, ManifestLocation::kExternalPolicy, |
| 814 | ManifestLocation::kExternalPolicyDownload, Extension::NO_FLAGS); |
Toni Barzic | dff5156 | 2018-07-24 19:55:46 | [diff] [blame] | 815 | demo_apps_provider->set_auto_acknowledge(true); |
| 816 | demo_apps_provider->set_install_immediately(true); |
Henrique Ferreiro | d71de90 | 2021-05-10 18:57:11 | [diff] [blame] | 817 | ash::DemoSession::Get()->SetExtensionsExternalLoader(loader); |
Toni Barzic | dff5156 | 2018-07-24 19:55:46 | [diff] [blame] | 818 | provider_list->push_back(std::move(demo_apps_provider)); |
| 819 | } |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 820 | #endif |
Dominique Fauteux-Chapleau | ff3bb35 | 2019-10-16 14:32:34 | [diff] [blame] | 821 | if (!profile->GetPrefs()->GetBoolean(pref_names::kBlockExternalExtensions)) { |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 822 | // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch |
| 823 | // of lacros-chrome is complete. |
Xiaohan Wang | be233b6 | 2022-01-14 19:15:53 | [diff] [blame] | 824 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) |
Taiju Tsuiki | b1879b7 | 2018-09-21 06:22:47 | [diff] [blame] | 825 | provider_list->push_back(std::make_unique<ExternalProviderImpl>( |
| 826 | service, |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 827 | base::MakeRefCounted<ExternalPrefLoader>( |
Dominique Fauteux-Chapleau | ff3bb35 | 2019-10-16 14:32:34 | [diff] [blame] | 828 | chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, |
| 829 | ExternalPrefLoader::USE_USER_TYPE_PROFILE_FILTER, profile), |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 830 | profile, ManifestLocation::kExternalPref, |
| 831 | ManifestLocation::kExternalPrefDownload, |
Taiju Tsuiki | b1879b7 | 2018-09-21 06:22:47 | [diff] [blame] | 832 | bundled_extension_creation_flags)); |
Dominique Fauteux-Chapleau | ff3bb35 | 2019-10-16 14:32:34 | [diff] [blame] | 833 | #endif |
Xiaohan Wang | be233b6 | 2022-01-14 19:15:53 | [diff] [blame] | 834 | #if BUILDFLAG(IS_WIN) |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 835 | auto registry_provider = std::make_unique<ExternalProviderImpl>( |
| 836 | service, new ExternalRegistryLoader, profile, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 837 | ManifestLocation::kExternalRegistry, |
| 838 | ManifestLocation::kExternalPrefDownload, Extension::NO_FLAGS); |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 839 | registry_provider->set_allow_updates(true); |
| 840 | provider_list->push_back(std::move(registry_provider)); |
Dominique Fauteux-Chapleau | ff3bb35 | 2019-10-16 14:32:34 | [diff] [blame] | 841 | #else |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 842 | provider_list->push_back(std::make_unique<ExternalProviderImpl>( |
| 843 | service, |
| 844 | base::MakeRefCounted<ExternalPrefLoader>( |
| 845 | chrome::DIR_EXTERNAL_EXTENSIONS, check_admin_permissions_on_mac, |
| 846 | nullptr), |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 847 | profile, ManifestLocation::kExternalPref, |
| 848 | ManifestLocation::kExternalPrefDownload, |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 849 | bundled_extension_creation_flags)); |
[email protected] | 5bed2ec3 | 2013-08-29 22:55:46 | [diff] [blame] | 850 | |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 851 | // Define a per-user source of external extensions. |
Xiaohan Wang | be233b6 | 2022-01-14 19:15:53 | [diff] [blame] | 852 | #if BUILDFLAG(IS_MAC) || ((BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && \ |
| 853 | BUILDFLAG(CHROMIUM_BRANDING)) |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 854 | provider_list->push_back(std::make_unique<ExternalProviderImpl>( |
| 855 | service, |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 856 | base::MakeRefCounted<ExternalPrefLoader>( |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 857 | chrome::DIR_USER_EXTERNAL_EXTENSIONS, ExternalPrefLoader::NONE, |
| 858 | nullptr), |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 859 | profile, ManifestLocation::kExternalPref, |
| 860 | ManifestLocation::kExternalPrefDownload, Extension::NO_FLAGS)); |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 861 | #endif |
| 862 | #endif |
| 863 | } |
| 864 | |
| 865 | #if !BUILDFLAG(IS_CHROMEOS_ASH) |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 866 | // The pre-installed apps are installed as INTERNAL but use the external |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 867 | // extension installer codeflow. |
Daniel Murphy | 3657906d | 2021-04-13 20:33:12 | [diff] [blame] | 868 | provider_list->push_back(std::make_unique<preinstalled_apps::Provider>( |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 869 | profile, service, |
| 870 | base::MakeRefCounted<ExternalPrefLoader>( |
| 871 | chrome::DIR_DEFAULT_APPS, ExternalPrefLoader::NONE, nullptr), |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 872 | ManifestLocation::kInternal, ManifestLocation::kInternal, |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 873 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT)); |
[email protected] | 98b4aca6 | 2011-09-28 01:27:23 | [diff] [blame] | 874 | #endif |
xiyuan | 65b68ab1 | 2015-06-26 19:00:18 | [diff] [blame] | 875 | |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 876 | std::unique_ptr<ExternalProviderImpl> drive_migration_provider( |
| 877 | new ExternalProviderImpl( |
| 878 | service, |
| 879 | base::MakeRefCounted<ExtensionMigrator>( |
Phillis Tang | 28427c46 | 2021-10-19 20:50:38 | [diff] [blame] | 880 | profile, extension_misc::kGoogleDriveAppId, |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 881 | extension_misc::kDocsOfflineExtensionId), |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 882 | profile, ManifestLocation::kExternalPref, |
| 883 | ManifestLocation::kExternalPrefDownload, |
Toby Huang | f93f700 | 2021-01-24 01:08:13 | [diff] [blame] | 884 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT)); |
| 885 | drive_migration_provider->set_auto_acknowledge(true); |
| 886 | provider_list->push_back(std::move(drive_migration_provider)); |
treib | cc82ab8 | 2015-03-02 09:41:49 | [diff] [blame] | 887 | |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 888 | provider_list->push_back(std::make_unique<ExternalProviderImpl>( |
Matthew Denton | ef83a62 | 2019-08-30 02:07:00 | [diff] [blame] | 889 | service, base::MakeRefCounted<ExternalComponentLoader>(profile), profile, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 890 | ManifestLocation::kInvalidLocation, ManifestLocation::kExternalComponent, |
lazyboy | f33109d | 2016-08-31 00:37:08 | [diff] [blame] | 891 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 892 | } |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 893 | |
| 894 | } // namespace extensions |