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_
14 namespace extensions
{
16 class APIPermissionSet
;
18 class FeatureProvider
;
19 class ManifestPermissionSet
;
20 class PermissionMessage
;
21 class PermissionMessageProvider
;
22 class PermissionsProvider
;
25 // Sets up global state for the extensions system. Should be Set() once in each
26 // process. This should be implemented by the client of the extensions system.
27 class ExtensionsClient
{
29 typedef std::vector
<std::string
> ScriptingWhitelist
;
31 // Initializes global state. Not done in the constructor because unit tests
32 // can create additional ExtensionsClients because the utility thread runs
34 virtual void Initialize() = 0;
36 // Returns a PermissionsProvider to initialize the permissions system.
37 virtual const PermissionsProvider
& GetPermissionsProvider() const = 0;
39 // Returns the global PermissionMessageProvider to use to provide permission
41 virtual const PermissionMessageProvider
& GetPermissionMessageProvider()
44 // Gets a feature provider for a specific feature type.
45 virtual FeatureProvider
* GetFeatureProviderByName(const std::string
& name
)
48 // Takes the list of all hosts and filters out those with special
49 // permission strings. Adds the regular hosts to |new_hosts|,
50 // and adds the special permission messages to |messages|.
51 virtual void FilterHostPermissions(
52 const URLPatternSet
& hosts
,
53 URLPatternSet
* new_hosts
,
54 std::set
<PermissionMessage
>* messages
) const = 0;
56 // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
57 // only used for testing in the browser process.
58 virtual void SetScriptingWhitelist(const ScriptingWhitelist
& whitelist
) = 0;
60 // Return the whitelist of extensions that can run content scripts on
62 virtual const ScriptingWhitelist
& GetScriptingWhitelist() const = 0;
64 // Get the set of chrome:// hosts that |extension| can run content scripts on.
65 virtual URLPatternSet
GetPermittedChromeSchemeHosts(
66 const Extension
* extension
,
67 const APIPermissionSet
& api_permissions
) const = 0;
69 // Returns false if content scripts are forbidden from running on |url|.
70 virtual bool IsScriptableURL(const GURL
& url
, std::string
* error
) const = 0;
72 // Return the extensions client.
73 static ExtensionsClient
* Get();
75 // Initialize the extensions system with this extensions client.
76 static void Set(ExtensionsClient
* client
);
79 } // namespace extensions
81 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_