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;
21 class FeatureProvider;
22 class ManifestPermissionSet;
23 class PermissionMessage;
24 class PermissionMessageProvider;
25 class PermissionsProvider;
29 // Sets up global state for the extensions system. Should be Set() once in each
30 // process. This should be implemented by the client of the extensions system.
31 class ExtensionsClient {
33 typedef std::vector<std::string> ScriptingWhitelist;
35 virtual ~ExtensionsClient() {}
37 // Initializes global state. Not done in the constructor because unit tests
38 // can create additional ExtensionsClients because the utility thread runs
40 virtual void Initialize() = 0;
42 // Returns the global PermissionMessageProvider to use to provide permission
44 virtual const PermissionMessageProvider& GetPermissionMessageProvider()
47 // Create a FeatureProvider for a specific feature type, e.g. "permission".
48 virtual scoped_ptr<FeatureProvider> CreateFeatureProvider(
49 const std::string& name) const = 0;
51 // Takes the list of all hosts and filters out those with special
52 // permission strings. Adds the regular hosts to |new_hosts|,
53 // and adds the special permission messages to |messages|.
54 virtual void FilterHostPermissions(
55 const URLPatternSet& hosts,
56 URLPatternSet* new_hosts,
57 std::set<PermissionMessage>* messages) const = 0;
59 // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
60 // only used for testing in the browser process.
61 virtual void SetScriptingWhitelist(const ScriptingWhitelist& whitelist) = 0;
63 // Return the whitelist of extensions that can run content scripts on
65 virtual const ScriptingWhitelist& GetScriptingWhitelist() const = 0;
67 // Get the set of chrome:// hosts that |extension| can run content scripts on.
68 virtual URLPatternSet GetPermittedChromeSchemeHosts(
69 const Extension* extension,
70 const APIPermissionSet& api_permissions) const = 0;
72 // Returns false if content scripts are forbidden from running on |url|.
73 virtual bool IsScriptableURL(const GURL& url, std::string* error) const = 0;
75 // Returns true iff a schema named |name| is generated.
76 virtual bool IsAPISchemaGenerated(const std::string& name) const = 0;
78 // Gets the API schema named |name|.
79 virtual base::StringPiece GetAPISchema(const std::string& name) const = 0;
81 // Determines if certain fatal extensions errors should be surpressed
82 // (i.e., only logged) or allowed (i.e., logged before crashing).
83 virtual bool ShouldSuppressFatalErrors() const = 0;
85 // Return the extensions client.
86 static ExtensionsClient* Get();
88 // Initialize the extensions system with this extensions client.
89 static void Set(ExtensionsClient* client);
92 } // namespace extensions
94 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_