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"
17 namespace extensions
{
19 class APIPermissionSet
;
22 class FeatureProvider
;
23 class JSONFeatureProviderSource
;
24 class ManifestPermissionSet
;
25 class PermissionMessage
;
26 class PermissionMessageProvider
;
30 // Sets up global state for the extensions system. Should be Set() once in each
31 // process. This should be implemented by the client of the extensions system.
32 class ExtensionsClient
{
34 typedef std::vector
<std::string
> ScriptingWhitelist
;
36 virtual ~ExtensionsClient() {}
38 // Initializes global state. Not done in the constructor because unit tests
39 // can create additional ExtensionsClients because the utility thread runs
41 virtual void Initialize() = 0;
43 // Returns the global PermissionMessageProvider to use to provide permission
45 virtual const PermissionMessageProvider
& GetPermissionMessageProvider()
48 // Returns the application name. For example, "Chromium" or "app_shell".
49 virtual const std::string
GetProductName() = 0;
51 // Create a FeatureProvider for a specific feature type, e.g. "permission".
52 virtual scoped_ptr
<FeatureProvider
> CreateFeatureProvider(
53 const std::string
& name
) const = 0;
55 // Create a JSONFeatureProviderSource for a specific feature type,
56 // e.g. "permission". Currently, all features are loaded from
57 // JSONFeatureProviderSources.
58 // This is used primarily in CreateFeatureProvider, above.
59 virtual scoped_ptr
<JSONFeatureProviderSource
> CreateFeatureProviderSource(
60 const std::string
& name
) const = 0;
62 // Takes the list of all hosts and filters out those with special
63 // permission strings. Adds the regular hosts to |new_hosts|,
64 // and adds the special permission messages to |messages|.
65 virtual void FilterHostPermissions(
66 const URLPatternSet
& hosts
,
67 URLPatternSet
* new_hosts
,
68 std::set
<PermissionMessage
>* messages
) const = 0;
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;
74 // Return the whitelist of extensions that can run content scripts on
76 virtual const ScriptingWhitelist
& GetScriptingWhitelist() const = 0;
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;
83 // Returns false if content scripts are forbidden from running on |url|.
84 virtual bool IsScriptableURL(const GURL
& url
, std::string
* error
) const = 0;
86 // Returns true iff a schema named |name| is generated.
87 virtual bool IsAPISchemaGenerated(const std::string
& name
) const = 0;
89 // Gets the generated API schema named |name|.
90 virtual base::StringPiece
GetAPISchema(const std::string
& name
) const = 0;
92 // Register non-generated API schema resources with the global ExtensionAPI.
93 // Called when the ExtensionAPI is lazily initialized.
94 virtual void RegisterAPISchemaResources(ExtensionAPI
* api
) const = 0;
96 // Determines if certain fatal extensions errors should be surpressed
97 // (i.e., only logged) or allowed (i.e., logged before crashing).
98 virtual bool ShouldSuppressFatalErrors() const = 0;
100 // Return the extensions client.
101 static ExtensionsClient
* Get();
103 // Initialize the extensions system with this extensions client.
104 static void Set(ExtensionsClient
* client
);
107 } // namespace extensions
109 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_