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