blob: f99636af9b6323f213bd20b24722153d105a62bd [file] [log] [blame]
[email protected]ad8b4ba2013-08-09 19:52:441// 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
dcheng7c2ca352016-04-22 21:15:368#include <memory>
[email protected]9a83ea02013-10-03 19:13:269#include <set>
[email protected]ad8b4ba2013-08-09 19:52:4410#include <string>
[email protected]c81f5d32013-10-26 10:38:4211#include <vector>
[email protected]ad8b4ba2013-08-09 19:52:4412
[email protected]68cb5652014-03-12 06:41:2913#include "base/strings/string_piece.h"
sashab7c08b8542014-12-10 10:54:4814#include "extensions/common/permissions/api_permission_set.h"
[email protected]68cb5652014-03-12 06:41:2915
[email protected]ee77a52b2013-11-13 03:51:3516class GURL;
17
rockotec1e64b2014-11-13 22:06:5118namespace base {
19class FilePath;
20}
21
[email protected]ad8b4ba2013-08-09 19:52:4422namespace extensions {
23
[email protected]d8388262013-10-30 21:36:3524class APIPermissionSet;
25class Extension;
[email protected]ad8b4ba2013-08-09 19:52:4426class FeatureProvider;
[email protected]bc495a182014-05-22 04:27:3727class JSONFeatureProviderSource;
[email protected]c41003472013-10-19 15:37:2528class PermissionMessageProvider;
[email protected]9a83ea02013-10-03 19:13:2629class URLPatternSet;
[email protected]ad8b4ba2013-08-09 19:52:4430
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.
33class ExtensionsClient {
34 public:
[email protected]c81f5d32013-10-26 10:38:4235 typedef std::vector<std::string> ScriptingWhitelist;
36
[email protected]08b71392014-01-07 18:52:0937 virtual ~ExtensionsClient() {}
38
[email protected]c41003472013-10-19 15:37:2539 // 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]c41003472013-10-19 15:37:2544 // Returns the global PermissionMessageProvider to use to provide permission
45 // warning strings.
46 virtual const PermissionMessageProvider& GetPermissionMessageProvider()
47 const = 0;
48
hanxic7e55202014-08-28 14:13:2149 // Returns the application name. For example, "Chromium" or "app_shell".
50 virtual const std::string GetProductName() = 0;
51
[email protected]dcedc592014-04-28 19:49:2952 // Create a FeatureProvider for a specific feature type, e.g. "permission".
dcheng7c2ca352016-04-22 21:15:3653 virtual std::unique_ptr<FeatureProvider> CreateFeatureProvider(
[email protected]dcedc592014-04-28 19:49:2954 const std::string& name) const = 0;
[email protected]ad8b4ba2013-08-09 19:52:4455
rdevlin.cronin5c6849832016-07-25 18:04:4556 // 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]bc495a182014-05-22 04:27:3760
[email protected]9a83ea02013-10-03 19:13:2661 // Takes the list of all hosts and filters out those with special
62 // permission strings. Adds the regular hosts to |new_hosts|,
sashab7c08b8542014-12-10 10:54:4863 // 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]c81f5d32013-10-26 10:38:4270 // 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]d8388262013-10-30 21:36:3578 // 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]ee77a52b2013-11-13 03:51:3583 // 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]68cb5652014-03-12 06:41:2986 // Returns true iff a schema named |name| is generated.
87 virtual bool IsAPISchemaGenerated(const std::string& name) const = 0;
88
[email protected]cce60982014-05-24 03:14:3989 // Gets the generated API schema named |name|.
[email protected]68cb5652014-03-12 06:41:2990 virtual base::StringPiece GetAPISchema(const std::string& name) const = 0;
91
[email protected]f55c90ee62014-04-12 00:50:0392 // 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
kalman309f98b2015-04-30 00:12:0096 // 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
rockot90659852014-09-18 19:31:52101 // Returns the base webstore URL prefix.
csharrison5d1f2142016-11-22 20:25:47102 virtual const GURL& GetWebstoreBaseURL() const = 0;
rockot90659852014-09-18 19:31:52103
104 // Returns the URL to use for update manifest queries.
csharrison4ff7b402016-11-12 04:41:22105 virtual const GURL& GetWebstoreUpdateURL() const = 0;
rockot90659852014-09-18 19:31:52106
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
rockotec1e64b2014-11-13 22:06:51111 // 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.
asargentf7f7e3b62015-01-08 18:10:55116 //
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.
rockotec1e64b2014-11-13 22:06:51121 virtual std::set<base::FilePath> GetBrowserImagePaths(
asargentf7f7e3b62015-01-08 18:10:55122 const Extension* extension);
rockotec1e64b2014-11-13 22:06:51123
lazyboyee4adef2016-05-24 00:55:16124 // 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]ad8b4ba2013-08-09 19:52:44131 // 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_