[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 | |
[email protected] | c5122563 | 2011-11-11 21:40:37 | [diff] [blame] | 8 | #include <string> |
| 9 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 11 | #include "chrome/browser/extensions/external_loader.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 12 | #include "extensions/browser/external_provider_interface.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 13 | #include "extensions/common/manifest.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 14 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 15 | class Profile; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 16 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 17 | namespace base { |
| 18 | class DictionaryValue; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 19 | class Version; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 20 | } |
| 21 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 22 | namespace extensions { |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 23 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 24 | // A specialization of the ExternalProvider that uses an instance of |
| 25 | // ExternalLoader to provide external extensions. This class can be seen as a |
| 26 | // bridge between the extension system and an ExternalLoader. Instances live |
| 27 | // their entire life on the UI thread. |
| 28 | class ExternalProviderImpl : public ExternalProviderInterface { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 29 | public: |
| 30 | // The constructed provider will provide the extensions loaded from |loader| |
| 31 | // to |service|, that will deal with the installation. The location |
| 32 | // attributes of the provided extensions are also specified here: |
| 33 | // |crx_location|: extensions originating from crx files |
| 34 | // |download_location|: extensions originating from update URLs |
| 35 | // If either of the origins is not supported by this provider, then it should |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 36 | // be initialized as Manifest::INVALID_LOCATION. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 37 | ExternalProviderImpl(VisitorInterface* service, |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 38 | const scoped_refptr<ExternalLoader>& loader, |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 39 | Profile* profile, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 40 | Manifest::Location crx_location, |
| 41 | Manifest::Location download_location, |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 42 | int creation_flags); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 43 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 44 | virtual ~ExternalProviderImpl(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 45 | |
| 46 | // Populates a list with providers for all known sources. |
| 47 | static void CreateExternalProviders( |
| 48 | VisitorInterface* service, |
| 49 | Profile* profile, |
| 50 | ProviderCollection* provider_list); |
| 51 | |
| 52 | // Sets underlying prefs and notifies provider. Only to be called by the |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 53 | // owned ExternalLoader instance. |
[email protected] | 937cf9d | 2012-08-30 03:51:55 | [diff] [blame] | 54 | virtual void SetPrefs(base::DictionaryValue* prefs); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 55 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 56 | // ExternalProvider implementation: |
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 57 | virtual void ServiceShutdown() OVERRIDE; |
[email protected] | d190cef | 2011-11-09 02:09:24 | [diff] [blame] | 58 | virtual void VisitRegisteredExtension() OVERRIDE; |
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 59 | virtual bool HasExtension(const std::string& id) const OVERRIDE; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 60 | virtual bool GetExtensionDetails( |
| 61 | const std::string& id, |
| 62 | Manifest::Location* location, |
| 63 | scoped_ptr<base::Version>* version) const OVERRIDE; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 64 | |
[email protected] | 1cc91fe | 2011-11-21 14:48:43 | [diff] [blame] | 65 | virtual bool IsReady() const OVERRIDE; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 66 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 67 | static const char kExternalCrx[]; |
| 68 | static const char kExternalVersion[]; |
| 69 | static const char kExternalUpdateUrl[]; |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 70 | static const char kInstallParam[]; |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 71 | static const char kIsBookmarkApp[]; |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 72 | static const char kIsFromWebstore[]; |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 73 | static const char kKeepIfPresent[]; |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 74 | static const char kSupportedLocales[]; |
[email protected] | bf9fd5ae | 2014-04-09 22:50:06 | [diff] [blame^] | 75 | static const char kWasInstalledByOem[]; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 76 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 77 | void set_auto_acknowledge(bool auto_acknowledge) { |
| 78 | auto_acknowledge_ = auto_acknowledge; |
| 79 | } |
| 80 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 81 | private: |
| 82 | // Location for external extensions that are provided by this provider from |
| 83 | // local crx files. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 84 | const Manifest::Location crx_location_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 85 | |
| 86 | // Location for external extensions that are provided by this provider from |
| 87 | // update URLs. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 88 | const Manifest::Location download_location_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 89 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 90 | // Weak pointer to the object that consumes the external extensions. |
| 91 | // This is zeroed out by: ServiceShutdown() |
| 92 | VisitorInterface* service_; // weak |
| 93 | |
| 94 | // Dictionary of the external extensions that are provided by this provider. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 95 | scoped_ptr<base::DictionaryValue> prefs_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 96 | |
| 97 | // Indicates that the extensions provided by this provider are loaded |
| 98 | // entirely. |
| 99 | bool ready_; |
| 100 | |
| 101 | // The loader that loads the list of external extensions and reports them |
| 102 | // via |SetPrefs|. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 103 | scoped_refptr<ExternalLoader> loader_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 104 | |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 105 | // The profile that will be used to install external extensions. |
| 106 | Profile* profile_; |
| 107 | |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 108 | // Creation flags to use for the extension. These flags will be used |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 109 | // when calling Extension::Create() by the crx installer. |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 110 | int creation_flags_; |
| 111 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 112 | // Whether loaded extensions should be automatically acknowledged, so that |
| 113 | // the user doesn't see an alert about them. |
| 114 | bool auto_acknowledge_; |
| 115 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 116 | DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 117 | }; |
| 118 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 119 | } // namespace extensions |
| 120 | |
| 121 | #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_ |