[email protected] | ad8b4ba | 2013-08-09 19:52:44 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_ |
| 6 | #define EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_ |
| 7 | |
dcheng | 7c2ca35 | 2016-04-22 21:15:36 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 9a83ea0 | 2013-10-03 19:13:26 | [diff] [blame] | 9 | #include <set> |
[email protected] | ad8b4ba | 2013-08-09 19:52:44 | [diff] [blame] | 10 | #include <string> |
[email protected] | c81f5d3 | 2013-10-26 10:38:42 | [diff] [blame] | 11 | #include <vector> |
[email protected] | ad8b4ba | 2013-08-09 19:52:44 | [diff] [blame] | 12 | |
[email protected] | 68cb565 | 2014-03-12 06:41:29 | [diff] [blame] | 13 | #include "base/strings/string_piece.h" |
sashab | 7c08b854 | 2014-12-10 10:54:48 | [diff] [blame] | 14 | #include "extensions/common/permissions/api_permission_set.h" |
[email protected] | 68cb565 | 2014-03-12 06:41:29 | [diff] [blame] | 15 | |
[email protected] | ee77a52b | 2013-11-13 03:51:35 | [diff] [blame] | 16 | class GURL; |
| 17 | |
rockot | ec1e64b | 2014-11-13 22:06:51 | [diff] [blame] | 18 | namespace base { |
| 19 | class FilePath; |
| 20 | } |
| 21 | |
[email protected] | ad8b4ba | 2013-08-09 19:52:44 | [diff] [blame] | 22 | namespace extensions { |
| 23 | |
[email protected] | d838826 | 2013-10-30 21:36:35 | [diff] [blame] | 24 | class APIPermissionSet; |
| 25 | class Extension; |
[email protected] | ad8b4ba | 2013-08-09 19:52:44 | [diff] [blame] | 26 | class FeatureProvider; |
[email protected] | bc495a18 | 2014-05-22 04:27:37 | [diff] [blame] | 27 | class JSONFeatureProviderSource; |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 28 | class PermissionMessageProvider; |
[email protected] | 9a83ea0 | 2013-10-03 19:13:26 | [diff] [blame] | 29 | class URLPatternSet; |
[email protected] | ad8b4ba | 2013-08-09 19:52:44 | [diff] [blame] | 30 | |
| 31 | // Sets up global state for the extensions system. Should be Set() once in each |
| 32 | // process. This should be implemented by the client of the extensions system. |
| 33 | class ExtensionsClient { |
| 34 | public: |
[email protected] | c81f5d3 | 2013-10-26 10:38:42 | [diff] [blame] | 35 | typedef std::vector<std::string> ScriptingWhitelist; |
| 36 | |
[email protected] | 08b7139 | 2014-01-07 18:52:09 | [diff] [blame] | 37 | virtual ~ExtensionsClient() {} |
| 38 | |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 39 | // Initializes global state. Not done in the constructor because unit tests |
| 40 | // can create additional ExtensionsClients because the utility thread runs |
| 41 | // in-process. |
| 42 | virtual void Initialize() = 0; |
| 43 | |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 44 | // Returns the global PermissionMessageProvider to use to provide permission |
| 45 | // warning strings. |
| 46 | virtual const PermissionMessageProvider& GetPermissionMessageProvider() |
| 47 | const = 0; |
| 48 | |
hanxi | c7e5520 | 2014-08-28 14:13:21 | [diff] [blame] | 49 | // Returns the application name. For example, "Chromium" or "app_shell". |
| 50 | virtual const std::string GetProductName() = 0; |
| 51 | |
[email protected] | dcedc59 | 2014-04-28 19:49:29 | [diff] [blame] | 52 | // Create a FeatureProvider for a specific feature type, e.g. "permission". |
dcheng | 7c2ca35 | 2016-04-22 21:15:36 | [diff] [blame] | 53 | virtual std::unique_ptr<FeatureProvider> CreateFeatureProvider( |
[email protected] | dcedc59 | 2014-04-28 19:49:29 | [diff] [blame] | 54 | const std::string& name) const = 0; |
[email protected] | ad8b4ba | 2013-08-09 19:52:44 | [diff] [blame] | 55 | |
rdevlin.cronin | 5c684983 | 2016-07-25 18:04:45 | [diff] [blame] | 56 | // Returns the dictionary of the API features json file. |
| 57 | // TODO(devlin): We should find a way to remove this. |
| 58 | virtual std::unique_ptr<JSONFeatureProviderSource> CreateAPIFeatureSource() |
| 59 | const = 0; |
[email protected] | bc495a18 | 2014-05-22 04:27:37 | [diff] [blame] | 60 | |
[email protected] | 9a83ea0 | 2013-10-03 19:13:26 | [diff] [blame] | 61 | // Takes the list of all hosts and filters out those with special |
| 62 | // permission strings. Adds the regular hosts to |new_hosts|, |
sashab | 7c08b854 | 2014-12-10 10:54:48 | [diff] [blame] | 63 | // and adds any additional permissions to |permissions|. |
| 64 | // TODO(sashab): Split this function in two: One to filter out ignored host |
| 65 | // permissions, and one to get permissions for the given hosts. |
| 66 | virtual void FilterHostPermissions(const URLPatternSet& hosts, |
| 67 | URLPatternSet* new_hosts, |
| 68 | PermissionIDSet* permissions) const = 0; |
| 69 | |
[email protected] | c81f5d3 | 2013-10-26 10:38:42 | [diff] [blame] | 70 | // Replaces the scripting whitelist with |whitelist|. Used in the renderer; |
| 71 | // only used for testing in the browser process. |
| 72 | virtual void SetScriptingWhitelist(const ScriptingWhitelist& whitelist) = 0; |
| 73 | |
| 74 | // Return the whitelist of extensions that can run content scripts on |
| 75 | // any origin. |
| 76 | virtual const ScriptingWhitelist& GetScriptingWhitelist() const = 0; |
| 77 | |
[email protected] | d838826 | 2013-10-30 21:36:35 | [diff] [blame] | 78 | // Get the set of chrome:// hosts that |extension| can run content scripts on. |
| 79 | virtual URLPatternSet GetPermittedChromeSchemeHosts( |
| 80 | const Extension* extension, |
| 81 | const APIPermissionSet& api_permissions) const = 0; |
| 82 | |
[email protected] | ee77a52b | 2013-11-13 03:51:35 | [diff] [blame] | 83 | // Returns false if content scripts are forbidden from running on |url|. |
| 84 | virtual bool IsScriptableURL(const GURL& url, std::string* error) const = 0; |
| 85 | |
[email protected] | 68cb565 | 2014-03-12 06:41:29 | [diff] [blame] | 86 | // Returns true iff a schema named |name| is generated. |
| 87 | virtual bool IsAPISchemaGenerated(const std::string& name) const = 0; |
| 88 | |
[email protected] | cce6098 | 2014-05-24 03:14:39 | [diff] [blame] | 89 | // Gets the generated API schema named |name|. |
[email protected] | 68cb565 | 2014-03-12 06:41:29 | [diff] [blame] | 90 | virtual base::StringPiece GetAPISchema(const std::string& name) const = 0; |
| 91 | |
[email protected] | f55c90ee6 | 2014-04-12 00:50:03 | [diff] [blame] | 92 | // Determines if certain fatal extensions errors should be surpressed |
| 93 | // (i.e., only logged) or allowed (i.e., logged before crashing). |
| 94 | virtual bool ShouldSuppressFatalErrors() const = 0; |
| 95 | |
kalman | 309f98b | 2015-04-30 00:12:00 | [diff] [blame] | 96 | // Records that a fatal error was caught and suppressed. It is expected that |
| 97 | // embedders will only do so if ShouldSuppressFatalErrors at some point |
| 98 | // returned true. |
| 99 | virtual void RecordDidSuppressFatalError() = 0; |
| 100 | |
rockot | 9065985 | 2014-09-18 19:31:52 | [diff] [blame] | 101 | // Returns the base webstore URL prefix. |
csharrison | 5d1f214 | 2016-11-22 20:25:47 | [diff] [blame] | 102 | virtual const GURL& GetWebstoreBaseURL() const = 0; |
rockot | 9065985 | 2014-09-18 19:31:52 | [diff] [blame] | 103 | |
| 104 | // Returns the URL to use for update manifest queries. |
csharrison | 4ff7b40 | 2016-11-12 04:41:22 | [diff] [blame] | 105 | virtual const GURL& GetWebstoreUpdateURL() const = 0; |
rockot | 9065985 | 2014-09-18 19:31:52 | [diff] [blame] | 106 | |
| 107 | // Returns a flag indicating whether or not a given URL is a valid |
| 108 | // extension blacklist URL. |
| 109 | virtual bool IsBlacklistUpdateURL(const GURL& url) const = 0; |
| 110 | |
rockot | ec1e64b | 2014-11-13 22:06:51 | [diff] [blame] | 111 | // Returns the set of file paths corresponding to any images within an |
| 112 | // extension's contents that may be displayed directly within the browser UI |
| 113 | // or WebUI, such as icons or theme images. This set of paths is used by the |
| 114 | // extension unpacker to determine which assets should be transcoded safely |
| 115 | // within the utility sandbox. |
asargent | f7f7e3b6 | 2015-01-08 18:10:55 | [diff] [blame] | 116 | // |
| 117 | // The default implementation returns the images used as icons for the |
| 118 | // extension itself, so implementors of ExtensionsClient overriding this may |
| 119 | // want to call the base class version and then add additional paths to that |
| 120 | // result. |
rockot | ec1e64b | 2014-11-13 22:06:51 | [diff] [blame] | 121 | virtual std::set<base::FilePath> GetBrowserImagePaths( |
asargent | f7f7e3b6 | 2015-01-08 18:10:55 | [diff] [blame] | 122 | const Extension* extension); |
rockot | ec1e64b | 2014-11-13 22:06:51 | [diff] [blame] | 123 | |
lazyboy | ee4adef | 2016-05-24 00:55:16 | [diff] [blame] | 124 | // Returns whether or not extension APIs are allowed in extension service |
| 125 | // workers. |
| 126 | // This is currently disallowed as the code to support this is work in |
| 127 | // progress. |
| 128 | // Can be overridden in tests. |
| 129 | virtual bool ExtensionAPIEnabledInExtensionServiceWorkers() const; |
| 130 | |
[email protected] | ad8b4ba | 2013-08-09 19:52:44 | [diff] [blame] | 131 | // Return the extensions client. |
| 132 | static ExtensionsClient* Get(); |
| 133 | |
| 134 | // Initialize the extensions system with this extensions client. |
| 135 | static void Set(ExtensionsClient* client); |
| 136 | }; |
| 137 | |
| 138 | } // namespace extensions |
| 139 | |
| 140 | #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_ |