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 any additional permissions to |permissions|.
70 // TODO(sashab): Split this function in two: One to filter out ignored host
71 // permissions, and one to get permissions for the given hosts.
72 virtual void FilterHostPermissions(const URLPatternSet
& hosts
,
73 URLPatternSet
* new_hosts
,
74 PermissionIDSet
* permissions
) const = 0;
76 // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
77 // only used for testing in the browser process.
78 virtual void SetScriptingWhitelist(const ScriptingWhitelist
& whitelist
) = 0;
80 // Return the whitelist of extensions that can run content scripts on
82 virtual const ScriptingWhitelist
& GetScriptingWhitelist() const = 0;
84 // Get the set of chrome:// hosts that |extension| can run content scripts on.
85 virtual URLPatternSet
GetPermittedChromeSchemeHosts(
86 const Extension
* extension
,
87 const APIPermissionSet
& api_permissions
) const = 0;
89 // Returns false if content scripts are forbidden from running on |url|.
90 virtual bool IsScriptableURL(const GURL
& url
, std::string
* error
) const = 0;
92 // Returns true iff a schema named |name| is generated.
93 virtual bool IsAPISchemaGenerated(const std::string
& name
) const = 0;
95 // Gets the generated API schema named |name|.
96 virtual base::StringPiece
GetAPISchema(const std::string
& name
) const = 0;
98 // Register non-generated API schema resources with the global ExtensionAPI.
99 // Called when the ExtensionAPI is lazily initialized.
100 virtual void RegisterAPISchemaResources(ExtensionAPI
* api
) const = 0;
102 // Determines if certain fatal extensions errors should be surpressed
103 // (i.e., only logged) or allowed (i.e., logged before crashing).
104 virtual bool ShouldSuppressFatalErrors() const = 0;
106 // Records that a fatal error was caught and suppressed. It is expected that
107 // embedders will only do so if ShouldSuppressFatalErrors at some point
109 virtual void RecordDidSuppressFatalError() = 0;
111 // Returns the base webstore URL prefix.
112 virtual std::string
GetWebstoreBaseURL() const = 0;
114 // Returns the URL to use for update manifest queries.
115 virtual std::string
GetWebstoreUpdateURL() const = 0;
117 // Returns a flag indicating whether or not a given URL is a valid
118 // extension blacklist URL.
119 virtual bool IsBlacklistUpdateURL(const GURL
& url
) const = 0;
121 // Returns the set of file paths corresponding to any images within an
122 // extension's contents that may be displayed directly within the browser UI
123 // or WebUI, such as icons or theme images. This set of paths is used by the
124 // extension unpacker to determine which assets should be transcoded safely
125 // within the utility sandbox.
127 // The default implementation returns the images used as icons for the
128 // extension itself, so implementors of ExtensionsClient overriding this may
129 // want to call the base class version and then add additional paths to that
131 virtual std::set
<base::FilePath
> GetBrowserImagePaths(
132 const Extension
* extension
);
134 // Return the extensions client.
135 static ExtensionsClient
* Get();
137 // Initialize the extensions system with this extensions client.
138 static void Set(ExtensionsClient
* client
);
141 } // namespace extensions
143 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_