Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / extensions / common / extensions_client.h
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.
4
5 #ifndef EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_
6 #define EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_piece.h"
14
15 class GURL;
16
17 namespace extensions {
18
19 class APIPermissionSet;
20 class Extension;
21 class ExtensionAPI;
22 class FeatureProvider;
23 class JSONFeatureProviderSource;
24 class ManifestPermissionSet;
25 class PermissionMessage;
26 class PermissionMessageProvider;
27 class SimpleFeature;
28 class URLPatternSet;
29
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 {
33  public:
34   typedef std::vector<std::string> ScriptingWhitelist;
35
36   virtual ~ExtensionsClient() {}
37
38   // Initializes global state. Not done in the constructor because unit tests
39   // can create additional ExtensionsClients because the utility thread runs
40   // in-process.
41   virtual void Initialize() = 0;
42
43   // Returns the global PermissionMessageProvider to use to provide permission
44   // warning strings.
45   virtual const PermissionMessageProvider& GetPermissionMessageProvider()
46       const = 0;
47
48   // Returns the application name. For example, "Chromium" or "app_shell".
49   virtual const std::string GetProductName() = 0;
50
51   // Create a FeatureProvider for a specific feature type, e.g. "permission".
52   virtual scoped_ptr<FeatureProvider> CreateFeatureProvider(
53       const std::string& name) const = 0;
54
55   // Create a JSONFeatureProviderSource for a specific feature type,
56   // e.g. "permission". Currently, all features are loaded from
57   // JSONFeatureProviderSources.
58   // This is used primarily in CreateFeatureProvider, above.
59   virtual scoped_ptr<JSONFeatureProviderSource> CreateFeatureProviderSource(
60       const std::string& name) const = 0;
61
62   // Takes the list of all hosts and filters out those with special
63   // permission strings. Adds the regular hosts to |new_hosts|,
64   // and adds the special permission messages to |messages|.
65   virtual void FilterHostPermissions(
66       const URLPatternSet& hosts,
67       URLPatternSet* new_hosts,
68       std::set<PermissionMessage>* messages) const = 0;
69
70   // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
71   // only used for testing in the browser process.
72   virtual void SetScriptingWhitelist(const ScriptingWhitelist& whitelist) = 0;
73
74   // Return the whitelist of extensions that can run content scripts on
75   // any origin.
76   virtual const ScriptingWhitelist& GetScriptingWhitelist() const = 0;
77
78   // Get the set of chrome:// hosts that |extension| can run content scripts on.
79   virtual URLPatternSet GetPermittedChromeSchemeHosts(
80       const Extension* extension,
81       const APIPermissionSet& api_permissions) const = 0;
82
83   // Returns false if content scripts are forbidden from running on |url|.
84   virtual bool IsScriptableURL(const GURL& url, std::string* error) const = 0;
85
86   // Returns true iff a schema named |name| is generated.
87   virtual bool IsAPISchemaGenerated(const std::string& name) const = 0;
88
89   // Gets the generated API schema named |name|.
90   virtual base::StringPiece GetAPISchema(const std::string& name) const = 0;
91
92   // Register non-generated API schema resources with the global ExtensionAPI.
93   // Called when the ExtensionAPI is lazily initialized.
94   virtual void RegisterAPISchemaResources(ExtensionAPI* api) const = 0;
95
96   // Determines if certain fatal extensions errors should be surpressed
97   // (i.e., only logged) or allowed (i.e., logged before crashing).
98   virtual bool ShouldSuppressFatalErrors() const = 0;
99
100   // Returns the base webstore URL prefix.
101   virtual std::string GetWebstoreBaseURL() const = 0;
102
103   // Returns the URL to use for update manifest queries.
104   virtual std::string GetWebstoreUpdateURL() const = 0;
105
106   // Returns a flag indicating whether or not a given URL is a valid
107   // extension blacklist URL.
108   virtual bool IsBlacklistUpdateURL(const GURL& url) const = 0;
109
110   // Return the extensions client.
111   static ExtensionsClient* Get();
112
113   // Initialize the extensions system with this extensions client.
114   static void Set(ExtensionsClient* client);
115 };
116
117 }  // namespace extensions
118
119 #endif  // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_