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 // Create a FeatureProvider for a specific feature type, e.g. "permission".
49 virtual scoped_ptr
<FeatureProvider
> CreateFeatureProvider(
50 const std::string
& name
) const = 0;
52 // Create a JSONFeatureProviderSource for a specific feature type,
53 // e.g. "permission". Currently, all features are loaded from
54 // JSONFeatureProviderSources.
55 // This is used primarily in CreateFeatureProvider, above.
56 virtual scoped_ptr
<JSONFeatureProviderSource
> CreateFeatureProviderSource(
57 const std::string
& name
) const = 0;
59 // Takes the list of all hosts and filters out those with special
60 // permission strings. Adds the regular hosts to |new_hosts|,
61 // and adds the special permission messages to |messages|.
62 virtual void FilterHostPermissions(
63 const URLPatternSet
& hosts
,
64 URLPatternSet
* new_hosts
,
65 std::set
<PermissionMessage
>* messages
) const = 0;
67 // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
68 // only used for testing in the browser process.
69 virtual void SetScriptingWhitelist(const ScriptingWhitelist
& whitelist
) = 0;
71 // Return the whitelist of extensions that can run content scripts on
73 virtual const ScriptingWhitelist
& GetScriptingWhitelist() const = 0;
75 // Get the set of chrome:// hosts that |extension| can run content scripts on.
76 virtual URLPatternSet
GetPermittedChromeSchemeHosts(
77 const Extension
* extension
,
78 const APIPermissionSet
& api_permissions
) const = 0;
80 // Returns false if content scripts are forbidden from running on |url|.
81 virtual bool IsScriptableURL(const GURL
& url
, std::string
* error
) const = 0;
83 // Returns true iff a schema named |name| is generated.
84 virtual bool IsAPISchemaGenerated(const std::string
& name
) const = 0;
86 // Gets the generated API schema named |name|.
87 virtual base::StringPiece
GetAPISchema(const std::string
& name
) const = 0;
89 // Register non-generated API schema resources with the global ExtensionAPI.
90 // Called when the ExtensionAPI is lazily initialized.
91 virtual void RegisterAPISchemaResources(ExtensionAPI
* api
) const = 0;
93 // Determines if certain fatal extensions errors should be surpressed
94 // (i.e., only logged) or allowed (i.e., logged before crashing).
95 virtual bool ShouldSuppressFatalErrors() const = 0;
97 // Return the extensions client.
98 static ExtensionsClient
* Get();
100 // Initialize the extensions system with this extensions client.
101 static void Set(ExtensionsClient
* client
);
104 } // namespace extensions
106 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_