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