Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / extensions / common / extensions_client.h
blobf2292b16ab897d2501c2f7d3a29c5b1261e38d05
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_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_piece.h"
15 class GURL;
17 namespace base {
18 class FilePath;
21 namespace extensions {
23 class APIPermissionSet;
24 class Extension;
25 class ExtensionAPI;
26 class FeatureProvider;
27 class JSONFeatureProviderSource;
28 class ManifestPermissionSet;
29 class PermissionMessage;
30 class PermissionMessageProvider;
31 class SimpleFeature;
32 class URLPatternSet;
34 // Sets up global state for the extensions system. Should be Set() once in each
35 // process. This should be implemented by the client of the extensions system.
36 class ExtensionsClient {
37 public:
38 typedef std::vector<std::string> ScriptingWhitelist;
40 virtual ~ExtensionsClient() {}
42 // Initializes global state. Not done in the constructor because unit tests
43 // can create additional ExtensionsClients because the utility thread runs
44 // in-process.
45 virtual void Initialize() = 0;
47 // Returns the global PermissionMessageProvider to use to provide permission
48 // warning strings.
49 virtual const PermissionMessageProvider& GetPermissionMessageProvider()
50 const = 0;
52 // Returns the application name. For example, "Chromium" or "app_shell".
53 virtual const std::string GetProductName() = 0;
55 // Create a FeatureProvider for a specific feature type, e.g. "permission".
56 virtual scoped_ptr<FeatureProvider> CreateFeatureProvider(
57 const std::string& name) const = 0;
59 // Create a JSONFeatureProviderSource for a specific feature type,
60 // e.g. "permission". Currently, all features are loaded from
61 // JSONFeatureProviderSources.
62 // This is used primarily in CreateFeatureProvider, above.
63 virtual scoped_ptr<JSONFeatureProviderSource> CreateFeatureProviderSource(
64 const std::string& name) const = 0;
66 // Takes the list of all hosts and filters out those with special
67 // permission strings. Adds the regular hosts to |new_hosts|,
68 // and adds the special permission messages to |messages|.
69 virtual void FilterHostPermissions(
70 const URLPatternSet& hosts,
71 URLPatternSet* new_hosts,
72 std::set<PermissionMessage>* messages) const = 0;
74 // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
75 // only used for testing in the browser process.
76 virtual void SetScriptingWhitelist(const ScriptingWhitelist& whitelist) = 0;
78 // Return the whitelist of extensions that can run content scripts on
79 // any origin.
80 virtual const ScriptingWhitelist& GetScriptingWhitelist() const = 0;
82 // Get the set of chrome:// hosts that |extension| can run content scripts on.
83 virtual URLPatternSet GetPermittedChromeSchemeHosts(
84 const Extension* extension,
85 const APIPermissionSet& api_permissions) const = 0;
87 // Returns false if content scripts are forbidden from running on |url|.
88 virtual bool IsScriptableURL(const GURL& url, std::string* error) const = 0;
90 // Returns true iff a schema named |name| is generated.
91 virtual bool IsAPISchemaGenerated(const std::string& name) const = 0;
93 // Gets the generated API schema named |name|.
94 virtual base::StringPiece GetAPISchema(const std::string& name) const = 0;
96 // Register non-generated API schema resources with the global ExtensionAPI.
97 // Called when the ExtensionAPI is lazily initialized.
98 virtual void RegisterAPISchemaResources(ExtensionAPI* api) const = 0;
100 // Determines if certain fatal extensions errors should be surpressed
101 // (i.e., only logged) or allowed (i.e., logged before crashing).
102 virtual bool ShouldSuppressFatalErrors() const = 0;
104 // Returns the base webstore URL prefix.
105 virtual std::string GetWebstoreBaseURL() const = 0;
107 // Returns the URL to use for update manifest queries.
108 virtual std::string GetWebstoreUpdateURL() const = 0;
110 // Returns a flag indicating whether or not a given URL is a valid
111 // extension blacklist URL.
112 virtual bool IsBlacklistUpdateURL(const GURL& url) const = 0;
114 // Returns the set of file paths corresponding to any images within an
115 // extension's contents that may be displayed directly within the browser UI
116 // or WebUI, such as icons or theme images. This set of paths is used by the
117 // extension unpacker to determine which assets should be transcoded safely
118 // within the utility sandbox.
119 virtual std::set<base::FilePath> GetBrowserImagePaths(
120 const Extension* extension) = 0;
122 // Return the extensions client.
123 static ExtensionsClient* Get();
125 // Initialize the extensions system with this extensions client.
126 static void Set(ExtensionsClient* client);
129 } // namespace extensions
131 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_