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