[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 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_ |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 7 | |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 8 | #include <memory> |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 9 | #include <set> |
[email protected] | c5122563 | 2011-11-11 21:40:37 | [diff] [blame] | 10 | #include <string> |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 11 | #include <vector> |
[email protected] | c5122563 | 2011-11-11 21:40:37 | [diff] [blame] | 12 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 15 | #include "chrome/browser/extensions/external_loader.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 16 | #include "extensions/browser/external_provider_interface.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 17 | #include "extensions/common/manifest.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 18 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 19 | class Profile; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 20 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 21 | namespace base { |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 22 | class DictionaryValue; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 23 | class Version; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 24 | } |
| 25 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 26 | namespace extensions { |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 27 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 28 | // A specialization of the ExternalProvider that uses an instance of |
| 29 | // ExternalLoader to provide external extensions. This class can be seen as a |
| 30 | // bridge between the extension system and an ExternalLoader. Instances live |
| 31 | // their entire life on the UI thread. |
| 32 | class ExternalProviderImpl : public ExternalProviderInterface { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 33 | public: |
| 34 | // The constructed provider will provide the extensions loaded from |loader| |
| 35 | // to |service|, that will deal with the installation. The location |
| 36 | // attributes of the provided extensions are also specified here: |
| 37 | // |crx_location|: extensions originating from crx files |
| 38 | // |download_location|: extensions originating from update URLs |
| 39 | // If either of the origins is not supported by this provider, then it should |
Gyuyoung Kim | 9c82d5bb3 | 2021-03-20 01:28:01 | [diff] [blame] | 40 | // be initialized as mojom::ManifestLocation::kInvalidLocation. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 41 | ExternalProviderImpl(VisitorInterface* service, |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 42 | const scoped_refptr<ExternalLoader>& loader, |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 43 | Profile* profile, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 44 | mojom::ManifestLocation crx_location, |
| 45 | mojom::ManifestLocation download_location, |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 46 | int creation_flags); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 47 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 48 | ~ExternalProviderImpl() override; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 49 | |
| 50 | // Populates a list with providers for all known sources. |
| 51 | static void CreateExternalProviders( |
| 52 | VisitorInterface* service, |
| 53 | Profile* profile, |
| 54 | ProviderCollection* provider_list); |
| 55 | |
| 56 | // Sets underlying prefs and notifies provider. Only to be called by the |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 57 | // owned ExternalLoader instance. |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 58 | virtual void SetPrefs(std::unique_ptr<base::DictionaryValue> prefs); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 59 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 60 | // Updates the underlying prefs and notifies provider. |
| 61 | // Only to be called by the owned ExternalLoader instance. |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 62 | void UpdatePrefs(std::unique_ptr<base::DictionaryValue> prefs); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 63 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 64 | // ExternalProvider implementation: |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 65 | void ServiceShutdown() override; |
| 66 | void VisitRegisteredExtension() override; |
| 67 | bool HasExtension(const std::string& id) const override; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 68 | bool GetExtensionDetails( |
| 69 | const std::string& id, |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 70 | mojom::ManifestLocation* location, |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 71 | std::unique_ptr<base::Version>* version) const override; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 72 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 73 | bool IsReady() const override; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 74 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 75 | static const char kExternalCrx[]; |
| 76 | static const char kExternalVersion[]; |
| 77 | static const char kExternalUpdateUrl[]; |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 78 | static const char kInstallParam[]; |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 79 | static const char kIsBookmarkApp[]; |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 80 | static const char kIsFromWebstore[]; |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 81 | static const char kKeepIfPresent[]; |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 82 | static const char kSupportedLocales[]; |
[email protected] | bf9fd5ae | 2014-04-09 22:50:06 | [diff] [blame] | 83 | static const char kWasInstalledByOem[]; |
Alan Cutter | b81d0e0 | 2020-08-05 09:10:34 | [diff] [blame] | 84 | static const char kWebAppMigrationFlag[]; |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 85 | static const char kMayBeUntrusted[]; |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 86 | static const char kMinProfileCreatedByVersion[]; |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 87 | static const char kDoNotInstallForEnterprise[]; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 88 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 89 | void set_auto_acknowledge(bool auto_acknowledge) { |
| 90 | auto_acknowledge_ = auto_acknowledge; |
| 91 | } |
| 92 | |
xiyuan | 4d82f7b6 | 2015-03-04 02:29:22 | [diff] [blame] | 93 | void set_install_immediately(bool install_immediately) { |
| 94 | install_immediately_ = install_immediately; |
| 95 | } |
| 96 | |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 97 | void set_allow_updates(bool allow_updates) { allow_updates_ = allow_updates; } |
| 98 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 99 | private: |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 100 | bool HandleMinProfileVersion(const base::DictionaryValue* extension, |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 101 | const std::string& extension_id, |
| 102 | std::set<std::string>* unsupported_extensions); |
| 103 | |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 104 | bool HandleDoNotInstallForEnterprise( |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 105 | const base::DictionaryValue* extension, |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 106 | const std::string& extension_id, |
| 107 | std::set<std::string>* unsupported_extensions); |
| 108 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 109 | // Retrieves the extensions that were found in this provider. |
| 110 | void RetrieveExtensionsFromPrefs( |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 111 | std::vector<ExternalInstallInfoUpdateUrl>* external_update_url_extensions, |
| 112 | std::vector<ExternalInstallInfoFile>* external_file_extensions); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 113 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 114 | // Location for external extensions that are provided by this provider from |
| 115 | // local crx files. |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 116 | const mojom::ManifestLocation crx_location_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 117 | |
| 118 | // Location for external extensions that are provided by this provider from |
| 119 | // update URLs. |
Gyuyoung Kim | 2e954c4 | 2021-03-19 14:06:29 | [diff] [blame] | 120 | const mojom::ManifestLocation download_location_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 121 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 122 | // Weak pointer to the object that consumes the external extensions. |
| 123 | // This is zeroed out by: ServiceShutdown() |
| 124 | VisitorInterface* service_; // weak |
| 125 | |
| 126 | // Dictionary of the external extensions that are provided by this provider. |
Anina Koehler | 100794e2 | 2021-09-08 13:09:52 | [diff] [blame] | 127 | std::unique_ptr<base::DictionaryValue> prefs_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 128 | |
| 129 | // Indicates that the extensions provided by this provider are loaded |
| 130 | // entirely. |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 131 | bool ready_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 132 | |
| 133 | // The loader that loads the list of external extensions and reports them |
| 134 | // via |SetPrefs|. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 135 | scoped_refptr<ExternalLoader> loader_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 136 | |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 137 | // The profile that will be used to install external extensions. |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 138 | Profile* const profile_; |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 139 | |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 140 | // Creation flags to use for the extension. These flags will be used |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 141 | // when calling Extension::Create() by the crx installer. |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 142 | int creation_flags_; |
| 143 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 144 | // Whether loaded extensions should be automatically acknowledged, so that |
| 145 | // the user doesn't see an alert about them. |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 146 | bool auto_acknowledge_ = false; |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 147 | |
xiyuan | 4d82f7b6 | 2015-03-04 02:29:22 | [diff] [blame] | 148 | // Whether the extensions from this provider should be installed immediately. |
Toni Barzic | 8702668 | 2018-01-08 23:21:04 | [diff] [blame] | 149 | bool install_immediately_ = false; |
| 150 | |
| 151 | // Whether the provider should be allowed to update the set of external |
| 152 | // extensions it provides. |
| 153 | bool allow_updates_ = false; |
xiyuan | 4d82f7b6 | 2015-03-04 02:29:22 | [diff] [blame] | 154 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 155 | DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 156 | }; |
| 157 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 158 | } // namespace extensions |
| 159 | |
| 160 | #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_ |