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.
5 #ifndef EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_
6 #define EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_piece.h"
14 #include "extensions/common/permissions/api_permission_set.h"
22 namespace extensions
{
24 class APIPermissionSet
;
27 class FeatureProvider
;
28 class JSONFeatureProviderSource
;
29 class ManifestPermissionSet
;
30 class PermissionMessage
;
31 class PermissionMessageProvider
;
35 // Sets up global state for the extensions system. Should be Set() once in each
36 // process. This should be implemented by the client of the extensions system.
37 class ExtensionsClient
{
39 typedef std::vector
<std::string
> ScriptingWhitelist
;
41 virtual ~ExtensionsClient() {}
43 // Initializes global state. Not done in the constructor because unit tests
44 // can create additional ExtensionsClients because the utility thread runs
46 virtual void Initialize() = 0;
48 // Returns the global PermissionMessageProvider to use to provide permission
50 virtual const PermissionMessageProvider
& GetPermissionMessageProvider()
53 // Returns the application name. For example, "Chromium" or "app_shell".
54 virtual const std::string
GetProductName() = 0;
56 // Create a FeatureProvider for a specific feature type, e.g. "permission".
57 virtual scoped_ptr
<FeatureProvider
> CreateFeatureProvider(
58 const std::string
& name
) const = 0;
60 // Create a JSONFeatureProviderSource for a specific feature type,
61 // e.g. "permission". Currently, all features are loaded from
62 // JSONFeatureProviderSources.
63 // This is used primarily in CreateFeatureProvider, above.
64 virtual scoped_ptr
<JSONFeatureProviderSource
> CreateFeatureProviderSource(
65 const std::string
& name
) const = 0;
67 // Takes the list of all hosts and filters out those with special
68 // permission strings. Adds the regular hosts to |new_hosts|,
69 // and adds the special permission messages to |messages|.
70 // TODO(sashab): Deprecate this in favour of FilterHostPermissions() below.
71 virtual void FilterHostPermissions(
72 const URLPatternSet
& hosts
,
73 URLPatternSet
* new_hosts
,
74 std::set
<PermissionMessage
>* messages
) const = 0;
76 // Takes the list of all hosts and filters out those with special
77 // permission strings. Adds the regular hosts to |new_hosts|,
78 // and adds any additional permissions to |permissions|.
79 // TODO(sashab): Split this function in two: One to filter out ignored host
80 // permissions, and one to get permissions for the given hosts.
81 virtual void FilterHostPermissions(const URLPatternSet
& hosts
,
82 URLPatternSet
* new_hosts
,
83 PermissionIDSet
* permissions
) const = 0;
85 // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
86 // only used for testing in the browser process.
87 virtual void SetScriptingWhitelist(const ScriptingWhitelist
& whitelist
) = 0;
89 // Return the whitelist of extensions that can run content scripts on
91 virtual const ScriptingWhitelist
& GetScriptingWhitelist() const = 0;
93 // Get the set of chrome:// hosts that |extension| can run content scripts on.
94 virtual URLPatternSet
GetPermittedChromeSchemeHosts(
95 const Extension
* extension
,
96 const APIPermissionSet
& api_permissions
) const = 0;
98 // Returns false if content scripts are forbidden from running on |url|.
99 virtual bool IsScriptableURL(const GURL
& url
, std::string
* error
) const = 0;
101 // Returns true iff a schema named |name| is generated.
102 virtual bool IsAPISchemaGenerated(const std::string
& name
) const = 0;
104 // Gets the generated API schema named |name|.
105 virtual base::StringPiece
GetAPISchema(const std::string
& name
) const = 0;
107 // Register non-generated API schema resources with the global ExtensionAPI.
108 // Called when the ExtensionAPI is lazily initialized.
109 virtual void RegisterAPISchemaResources(ExtensionAPI
* api
) const = 0;
111 // Determines if certain fatal extensions errors should be surpressed
112 // (i.e., only logged) or allowed (i.e., logged before crashing).
113 virtual bool ShouldSuppressFatalErrors() const = 0;
115 // Records that a fatal error was caught and suppressed. It is expected that
116 // embedders will only do so if ShouldSuppressFatalErrors at some point
118 virtual void RecordDidSuppressFatalError() = 0;
120 // Returns the base webstore URL prefix.
121 virtual std::string
GetWebstoreBaseURL() const = 0;
123 // Returns the URL to use for update manifest queries.
124 virtual std::string
GetWebstoreUpdateURL() const = 0;
126 // Returns a flag indicating whether or not a given URL is a valid
127 // extension blacklist URL.
128 virtual bool IsBlacklistUpdateURL(const GURL
& url
) const = 0;
130 // Returns the set of file paths corresponding to any images within an
131 // extension's contents that may be displayed directly within the browser UI
132 // or WebUI, such as icons or theme images. This set of paths is used by the
133 // extension unpacker to determine which assets should be transcoded safely
134 // within the utility sandbox.
136 // The default implementation returns the images used as icons for the
137 // extension itself, so implementors of ExtensionsClient overriding this may
138 // want to call the base class version and then add additional paths to that
140 virtual std::set
<base::FilePath
> GetBrowserImagePaths(
141 const Extension
* extension
);
143 // Return the extensions client.
144 static ExtensionsClient
* Get();
146 // Initialize the extensions system with this extensions client.
147 static void Set(ExtensionsClient
* client
);
150 } // namespace extensions
152 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_