Upstream version 7.36.149.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 FeatureProvider;
22 class ManifestPermissionSet;
23 class PermissionMessage;
24 class PermissionMessageProvider;
25 class PermissionsProvider;
26 class SimpleFeature;
27 class URLPatternSet;
28
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 {
32  public:
33   typedef std::vector<std::string> ScriptingWhitelist;
34
35   virtual ~ExtensionsClient() {}
36
37   // Initializes global state. Not done in the constructor because unit tests
38   // can create additional ExtensionsClients because the utility thread runs
39   // in-process.
40   virtual void Initialize() = 0;
41
42   // Returns the global PermissionMessageProvider to use to provide permission
43   // warning strings.
44   virtual const PermissionMessageProvider& GetPermissionMessageProvider()
45       const = 0;
46
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;
50
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;
58
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;
62
63   // Return the whitelist of extensions that can run content scripts on
64   // any origin.
65   virtual const ScriptingWhitelist& GetScriptingWhitelist() const = 0;
66
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;
71
72   // Returns false if content scripts are forbidden from running on |url|.
73   virtual bool IsScriptableURL(const GURL& url, std::string* error) const = 0;
74
75   // Returns true iff a schema named |name| is generated.
76   virtual bool IsAPISchemaGenerated(const std::string& name) const = 0;
77
78   // Gets the API schema named |name|.
79   virtual base::StringPiece GetAPISchema(const std::string& name) const = 0;
80
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;
84
85   // Return the extensions client.
86   static ExtensionsClient* Get();
87
88   // Initialize the extensions system with this extensions client.
89   static void Set(ExtensionsClient* client);
90 };
91
92 }  // namespace extensions
93
94 #endif  // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_