blob: adb652fae8b917db69da9c688fa073a133b03ef6 [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 {
22class 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
[email protected]1d5e58b2013-01-31 08:41:4040 // be initialized as Manifest::INVALID_LOCATION.
[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,
[email protected]1d5e58b2013-01-31 08:41:4044 Manifest::Location crx_location,
45 Manifest::Location 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.
Istiaque Ahmeda7431b32017-08-20 18:33:3758 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.
Istiaque Ahmeda7431b32017-08-20 18:33:3762 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,
70 Manifest::Location* location,
71 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[];
[email protected]2b6a5802014-08-16 07:58:0884 static const char kMayBeUntrusted[];
dpolukhin2c6ef2932015-05-12 16:06:1385 static const char kMinProfileCreatedByVersion[];
dpolukhin1687ef32015-06-22 11:12:3786 static const char kDoNotInstallForEnterprise[];
[email protected]8e4560b62011-01-14 10:09:1487
[email protected]47fc70c2011-12-06 07:29:5188 void set_auto_acknowledge(bool auto_acknowledge) {
89 auto_acknowledge_ = auto_acknowledge;
90 }
91
xiyuan4d82f7b62015-03-04 02:29:2292 void set_install_immediately(bool install_immediately) {
93 install_immediately_ = install_immediately;
94 }
95
Toni Barzic87026682018-01-08 23:21:0496 void set_allow_updates(bool allow_updates) { allow_updates_ = allow_updates; }
97
[email protected]8e4560b62011-01-14 10:09:1498 private:
dpolukhin2c6ef2932015-05-12 16:06:1399 bool HandleMinProfileVersion(const base::DictionaryValue* extension,
100 const std::string& extension_id,
101 std::set<std::string>* unsupported_extensions);
102
dpolukhin1687ef32015-06-22 11:12:37103 bool HandleDoNotInstallForEnterprise(
104 const base::DictionaryValue* extension,
105 const std::string& extension_id,
106 std::set<std::string>* unsupported_extensions);
107
lazyboye8634172016-01-28 00:10:48108 // Retrieves the extensions that were found in this provider.
109 void RetrieveExtensionsFromPrefs(
Devlin Cronin19f70b6a2017-10-01 04:14:05110 std::vector<ExternalInstallInfoUpdateUrl>* external_update_url_extensions,
111 std::vector<ExternalInstallInfoFile>* external_file_extensions);
lazyboye8634172016-01-28 00:10:48112
[email protected]8e4560b62011-01-14 10:09:14113 // Location for external extensions that are provided by this provider from
114 // local crx files.
[email protected]1d5e58b2013-01-31 08:41:40115 const Manifest::Location crx_location_;
[email protected]8e4560b62011-01-14 10:09:14116
117 // Location for external extensions that are provided by this provider from
118 // update URLs.
[email protected]1d5e58b2013-01-31 08:41:40119 const Manifest::Location download_location_;
[email protected]8e4560b62011-01-14 10:09:14120
[email protected]8e4560b62011-01-14 10:09:14121 // Weak pointer to the object that consumes the external extensions.
122 // This is zeroed out by: ServiceShutdown()
123 VisitorInterface* service_; // weak
124
125 // Dictionary of the external extensions that are provided by this provider.
dchengc963c7142016-04-08 03:55:22126 std::unique_ptr<base::DictionaryValue> prefs_;
[email protected]8e4560b62011-01-14 10:09:14127
128 // Indicates that the extensions provided by this provider are loaded
129 // entirely.
Toni Barzic87026682018-01-08 23:21:04130 bool ready_ = false;
[email protected]8e4560b62011-01-14 10:09:14131
132 // The loader that loads the list of external extensions and reports them
133 // via |SetPrefs|.
[email protected]5df038b2012-07-16 19:03:27134 scoped_refptr<ExternalLoader> loader_;
[email protected]8e4560b62011-01-14 10:09:14135
[email protected]19eac6d2013-05-30 06:51:03136 // The profile that will be used to install external extensions.
Toni Barzic87026682018-01-08 23:21:04137 Profile* const profile_;
[email protected]19eac6d2013-05-30 06:51:03138
[email protected]1bf73cc2011-10-26 22:38:31139 // Creation flags to use for the extension. These flags will be used
[email protected]1d5e58b2013-01-31 08:41:40140 // when calling Extension::Create() by the crx installer.
[email protected]1bf73cc2011-10-26 22:38:31141 int creation_flags_;
142
[email protected]47fc70c2011-12-06 07:29:51143 // Whether loaded extensions should be automatically acknowledged, so that
144 // the user doesn't see an alert about them.
Toni Barzic87026682018-01-08 23:21:04145 bool auto_acknowledge_ = false;
[email protected]47fc70c2011-12-06 07:29:51146
xiyuan4d82f7b62015-03-04 02:29:22147 // Whether the extensions from this provider should be installed immediately.
Toni Barzic87026682018-01-08 23:21:04148 bool install_immediately_ = false;
149
150 // Whether the provider should be allowed to update the set of external
151 // extensions it provides.
152 bool allow_updates_ = false;
xiyuan4d82f7b62015-03-04 02:29:22153
[email protected]5df038b2012-07-16 19:03:27154 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl);
[email protected]8e4560b62011-01-14 10:09:14155};
156
[email protected]5df038b2012-07-16 19:03:27157} // namespace extensions
158
159#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_