blob: 0f20160b33e8ac80376a45afce89b530efa55556 [file] [log] [blame]
[email protected]a12ce8b22012-01-17 18:40:531// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]8e4560b62011-01-14 10:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5df038b2012-07-16 19:03:275#ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
[email protected]8e4560b62011-01-14 10:09:147
Toni Barzic87026682018-01-08 23:21:048#include <memory>
dpolukhin2c6ef2932015-05-12 16:06:139#include <set>
[email protected]c51225632011-11-11 21:40:3710#include <string>
Toni Barzic87026682018-01-08 23:21:0411#include <vector>
[email protected]c51225632011-11-11 21:40:3712
avia2f4804a2015-12-24 23:11:1313#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/ref_counted.h"
[email protected]5df038b2012-07-16 19:03:2715#include "chrome/browser/extensions/external_loader.h"
[email protected]301116c62013-11-26 10:37:4516#include "extensions/browser/external_provider_interface.h"
[email protected]d42c11152013-08-22 19:36:3217#include "extensions/common/manifest.h"
[email protected]8e4560b62011-01-14 10:09:1418
[email protected]8e4560b62011-01-14 10:09:1419class Profile;
[email protected]8e4560b62011-01-14 10:09:1420
[email protected]f3a1c642011-07-12 19:15:0321namespace base {
Anina Koehler100794e22021-09-08 13:09:5222class DictionaryValue;
[email protected]1f04ef42013-04-22 07:35:5023class Version;
[email protected]f3a1c642011-07-12 19:15:0324}
25
[email protected]1c321ee2012-05-21 03:02:3426namespace extensions {
[email protected]1c321ee2012-05-21 03:02:3427
[email protected]5df038b2012-07-16 19:03:2728// 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.
32class ExternalProviderImpl : public ExternalProviderInterface {
[email protected]8e4560b62011-01-14 10:09:1433 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 Kim9c82d5bb32021-03-20 01:28:0140 // be initialized as mojom::ManifestLocation::kInvalidLocation.
[email protected]5df038b2012-07-16 19:03:2741 ExternalProviderImpl(VisitorInterface* service,
[email protected]af984882013-10-21 21:08:5142 const scoped_refptr<ExternalLoader>& loader,
[email protected]19eac6d2013-05-30 06:51:0343 Profile* profile,
Gyuyoung Kim2e954c42021-03-19 14:06:2944 mojom::ManifestLocation crx_location,
45 mojom::ManifestLocation download_location,
[email protected]5df038b2012-07-16 19:03:2746 int creation_flags);
[email protected]8e4560b62011-01-14 10:09:1447
dchengae36a4a2014-10-21 12:36:3648 ~ExternalProviderImpl() override;
[email protected]8e4560b62011-01-14 10:09:1449
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]5df038b2012-07-16 19:03:2757 // owned ExternalLoader instance.
Anina Koehler100794e22021-09-08 13:09:5258 virtual void SetPrefs(std::unique_ptr<base::DictionaryValue> prefs);
[email protected]8e4560b62011-01-14 10:09:1459
lazyboye8634172016-01-28 00:10:4860 // Updates the underlying prefs and notifies provider.
61 // Only to be called by the owned ExternalLoader instance.
Anina Koehler100794e22021-09-08 13:09:5262 void UpdatePrefs(std::unique_ptr<base::DictionaryValue> prefs);
lazyboye8634172016-01-28 00:10:4863
[email protected]5df038b2012-07-16 19:03:2764 // ExternalProvider implementation:
dchengae36a4a2014-10-21 12:36:3665 void ServiceShutdown() override;
66 void VisitRegisteredExtension() override;
67 bool HasExtension(const std::string& id) const override;
dchengc963c7142016-04-08 03:55:2268 bool GetExtensionDetails(
69 const std::string& id,
Gyuyoung Kim2e954c42021-03-19 14:06:2970 mojom::ManifestLocation* location,
dchengc963c7142016-04-08 03:55:2271 std::unique_ptr<base::Version>* version) const override;
[email protected]8e4560b62011-01-14 10:09:1472
dchengae36a4a2014-10-21 12:36:3673 bool IsReady() const override;
[email protected]8e4560b62011-01-14 10:09:1474
[email protected]8e4560b62011-01-14 10:09:1475 static const char kExternalCrx[];
76 static const char kExternalVersion[];
77 static const char kExternalUpdateUrl[];
[email protected]d8fd0fd2014-03-24 13:16:0678 static const char kInstallParam[];
[email protected]f121003b2012-05-04 21:57:4779 static const char kIsBookmarkApp[];
[email protected]7425d7df2012-11-28 14:35:4280 static const char kIsFromWebstore[];
[email protected]19eac6d2013-05-30 06:51:0381 static const char kKeepIfPresent[];
[email protected]d8fd0fd2014-03-24 13:16:0682 static const char kSupportedLocales[];
[email protected]bf9fd5ae2014-04-09 22:50:0683 static const char kWasInstalledByOem[];
Alan Cutterb81d0e02020-08-05 09:10:3484 static const char kWebAppMigrationFlag[];
[email protected]2b6a5802014-08-16 07:58:0885 static const char kMayBeUntrusted[];
dpolukhin2c6ef2932015-05-12 16:06:1386 static const char kMinProfileCreatedByVersion[];
dpolukhin1687ef32015-06-22 11:12:3787 static const char kDoNotInstallForEnterprise[];
[email protected]8e4560b62011-01-14 10:09:1488
[email protected]47fc70c2011-12-06 07:29:5189 void set_auto_acknowledge(bool auto_acknowledge) {
90 auto_acknowledge_ = auto_acknowledge;
91 }
92
xiyuan4d82f7b62015-03-04 02:29:2293 void set_install_immediately(bool install_immediately) {
94 install_immediately_ = install_immediately;
95 }
96
Toni Barzic87026682018-01-08 23:21:0497 void set_allow_updates(bool allow_updates) { allow_updates_ = allow_updates; }
98
[email protected]8e4560b62011-01-14 10:09:1499 private:
Anina Koehler100794e22021-09-08 13:09:52100 bool HandleMinProfileVersion(const base::DictionaryValue* extension,
dpolukhin2c6ef2932015-05-12 16:06:13101 const std::string& extension_id,
102 std::set<std::string>* unsupported_extensions);
103
dpolukhin1687ef32015-06-22 11:12:37104 bool HandleDoNotInstallForEnterprise(
Anina Koehler100794e22021-09-08 13:09:52105 const base::DictionaryValue* extension,
dpolukhin1687ef32015-06-22 11:12:37106 const std::string& extension_id,
107 std::set<std::string>* unsupported_extensions);
108
lazyboye8634172016-01-28 00:10:48109 // Retrieves the extensions that were found in this provider.
110 void RetrieveExtensionsFromPrefs(
Devlin Cronin19f70b6a2017-10-01 04:14:05111 std::vector<ExternalInstallInfoUpdateUrl>* external_update_url_extensions,
112 std::vector<ExternalInstallInfoFile>* external_file_extensions);
lazyboye8634172016-01-28 00:10:48113
[email protected]8e4560b62011-01-14 10:09:14114 // Location for external extensions that are provided by this provider from
115 // local crx files.
Gyuyoung Kim2e954c42021-03-19 14:06:29116 const mojom::ManifestLocation crx_location_;
[email protected]8e4560b62011-01-14 10:09:14117
118 // Location for external extensions that are provided by this provider from
119 // update URLs.
Gyuyoung Kim2e954c42021-03-19 14:06:29120 const mojom::ManifestLocation download_location_;
[email protected]8e4560b62011-01-14 10:09:14121
[email protected]8e4560b62011-01-14 10:09:14122 // 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 Koehler100794e22021-09-08 13:09:52127 std::unique_ptr<base::DictionaryValue> prefs_;
[email protected]8e4560b62011-01-14 10:09:14128
129 // Indicates that the extensions provided by this provider are loaded
130 // entirely.
Toni Barzic87026682018-01-08 23:21:04131 bool ready_ = false;
[email protected]8e4560b62011-01-14 10:09:14132
133 // The loader that loads the list of external extensions and reports them
134 // via |SetPrefs|.
[email protected]5df038b2012-07-16 19:03:27135 scoped_refptr<ExternalLoader> loader_;
[email protected]8e4560b62011-01-14 10:09:14136
[email protected]19eac6d2013-05-30 06:51:03137 // The profile that will be used to install external extensions.
Toni Barzic87026682018-01-08 23:21:04138 Profile* const profile_;
[email protected]19eac6d2013-05-30 06:51:03139
[email protected]1bf73cc2011-10-26 22:38:31140 // Creation flags to use for the extension. These flags will be used
[email protected]1d5e58b2013-01-31 08:41:40141 // when calling Extension::Create() by the crx installer.
[email protected]1bf73cc2011-10-26 22:38:31142 int creation_flags_;
143
[email protected]47fc70c2011-12-06 07:29:51144 // Whether loaded extensions should be automatically acknowledged, so that
145 // the user doesn't see an alert about them.
Toni Barzic87026682018-01-08 23:21:04146 bool auto_acknowledge_ = false;
[email protected]47fc70c2011-12-06 07:29:51147
xiyuan4d82f7b62015-03-04 02:29:22148 // Whether the extensions from this provider should be installed immediately.
Toni Barzic87026682018-01-08 23:21:04149 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;
xiyuan4d82f7b62015-03-04 02:29:22154
[email protected]5df038b2012-07-16 19:03:27155 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl);
[email protected]8e4560b62011-01-14 10:09:14156};
157
[email protected]5df038b2012-07-16 19:03:27158} // namespace extensions
159
160#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_