Fix sort order of unlaunched apps on app list start page.
[chromium-blink-merge.git] / extensions / common / extensions_client.h
blob9a9bedf6dd59a7b8666d17c3af1eeb1ef166a7af
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"
14 #include "extensions/common/permissions/api_permission_set.h"
16 class GURL;
18 namespace base {
19 class FilePath;
22 namespace extensions {
24 class APIPermissionSet;
25 class Extension;
26 class ExtensionAPI;
27 class FeatureProvider;
28 class JSONFeatureProviderSource;
29 class ManifestPermissionSet;
30 class PermissionMessage;
31 class PermissionMessageProvider;
32 class SimpleFeature;
33 class URLPatternSet;
35 // Sets up global state for the extensions system. Should be Set() once in each
36 // process. This should be implemented by the client of the extensions system.
37 class ExtensionsClient {
38 public:
39 typedef std::vector<std::string> ScriptingWhitelist;
41 virtual ~ExtensionsClient() {}
43 // Initializes global state. Not done in the constructor because unit tests
44 // can create additional ExtensionsClients because the utility thread runs
45 // in-process.
46 virtual void Initialize() = 0;
48 // Returns the global PermissionMessageProvider to use to provide permission
49 // warning strings.
50 virtual const PermissionMessageProvider& GetPermissionMessageProvider()
51 const = 0;
53 // Returns the application name. For example, "Chromium" or "app_shell".
54 virtual const std::string GetProductName() = 0;
56 // Create a FeatureProvider for a specific feature type, e.g. "permission".
57 virtual scoped_ptr<FeatureProvider> CreateFeatureProvider(
58 const std::string& name) const = 0;
60 // Create a JSONFeatureProviderSource for a specific feature type,
61 // e.g. "permission". Currently, all features are loaded from
62 // JSONFeatureProviderSources.
63 // This is used primarily in CreateFeatureProvider, above.
64 virtual scoped_ptr<JSONFeatureProviderSource> CreateFeatureProviderSource(
65 const std::string& name) const = 0;
67 // Takes the list of all hosts and filters out those with special
68 // permission strings. Adds the regular hosts to |new_hosts|,
69 // and adds the special permission messages to |messages|.
70 // TODO(sashab): Deprecate this in favour of FilterHostPermissions() below.
71 virtual void FilterHostPermissions(
72 const URLPatternSet& hosts,
73 URLPatternSet* new_hosts,
74 std::set<PermissionMessage>* messages) const = 0;
76 // Takes the list of all hosts and filters out those with special
77 // permission strings. Adds the regular hosts to |new_hosts|,
78 // and adds any additional permissions to |permissions|.
79 // TODO(sashab): Split this function in two: One to filter out ignored host
80 // permissions, and one to get permissions for the given hosts.
81 virtual void FilterHostPermissions(const URLPatternSet& hosts,
82 URLPatternSet* new_hosts,
83 PermissionIDSet* permissions) const = 0;
85 // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
86 // only used for testing in the browser process.
87 virtual void SetScriptingWhitelist(const ScriptingWhitelist& whitelist) = 0;
89 // Return the whitelist of extensions that can run content scripts on
90 // any origin.
91 virtual const ScriptingWhitelist& GetScriptingWhitelist() const = 0;
93 // Get the set of chrome:// hosts that |extension| can run content scripts on.
94 virtual URLPatternSet GetPermittedChromeSchemeHosts(
95 const Extension* extension,
96 const APIPermissionSet& api_permissions) const = 0;
98 // Returns false if content scripts are forbidden from running on |url|.
99 virtual bool IsScriptableURL(const GURL& url, std::string* error) const = 0;
101 // Returns true iff a schema named |name| is generated.
102 virtual bool IsAPISchemaGenerated(const std::string& name) const = 0;
104 // Gets the generated API schema named |name|.
105 virtual base::StringPiece GetAPISchema(const std::string& name) const = 0;
107 // Register non-generated API schema resources with the global ExtensionAPI.
108 // Called when the ExtensionAPI is lazily initialized.
109 virtual void RegisterAPISchemaResources(ExtensionAPI* api) const = 0;
111 // Determines if certain fatal extensions errors should be surpressed
112 // (i.e., only logged) or allowed (i.e., logged before crashing).
113 virtual bool ShouldSuppressFatalErrors() const = 0;
115 // Returns the base webstore URL prefix.
116 virtual std::string GetWebstoreBaseURL() const = 0;
118 // Returns the URL to use for update manifest queries.
119 virtual std::string GetWebstoreUpdateURL() const = 0;
121 // Returns a flag indicating whether or not a given URL is a valid
122 // extension blacklist URL.
123 virtual bool IsBlacklistUpdateURL(const GURL& url) const = 0;
125 // Returns the set of file paths corresponding to any images within an
126 // extension's contents that may be displayed directly within the browser UI
127 // or WebUI, such as icons or theme images. This set of paths is used by the
128 // extension unpacker to determine which assets should be transcoded safely
129 // within the utility sandbox.
131 // The default implementation returns the images used as icons for the
132 // extension itself, so implementors of ExtensionsClient overriding this may
133 // want to call the base class version and then add additional paths to that
134 // result.
135 virtual std::set<base::FilePath> GetBrowserImagePaths(
136 const Extension* extension);
138 // Return the extensions client.
139 static ExtensionsClient* Get();
141 // Initialize the extensions system with this extensions client.
142 static void Set(ExtensionsClient* client);
145 } // namespace extensions
147 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_