Upstream version 5.34.92.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 class GURL;
13
14 namespace extensions {
15
16 class APIPermissionSet;
17 class Extension;
18 class FeatureProvider;
19 class ManifestPermissionSet;
20 class PermissionMessage;
21 class PermissionMessageProvider;
22 class PermissionsProvider;
23 class URLPatternSet;
24
25 // Sets up global state for the extensions system. Should be Set() once in each
26 // process. This should be implemented by the client of the extensions system.
27 class ExtensionsClient {
28  public:
29   typedef std::vector<std::string> ScriptingWhitelist;
30
31   virtual ~ExtensionsClient() {}
32
33   // Initializes global state. Not done in the constructor because unit tests
34   // can create additional ExtensionsClients because the utility thread runs
35   // in-process.
36   virtual void Initialize() = 0;
37
38   // Returns a PermissionsProvider to initialize the permissions system.
39   virtual const PermissionsProvider& GetPermissionsProvider() const = 0;
40
41   // Returns the global PermissionMessageProvider to use to provide permission
42   // warning strings.
43   virtual const PermissionMessageProvider& GetPermissionMessageProvider()
44       const = 0;
45
46   // Gets a feature provider for a specific feature type.
47   virtual FeatureProvider* GetFeatureProviderByName(const std::string& name)
48       const = 0;
49
50   // Takes the list of all hosts and filters out those with special
51   // permission strings. Adds the regular hosts to |new_hosts|,
52   // and adds the special permission messages to |messages|.
53   virtual void FilterHostPermissions(
54       const URLPatternSet& hosts,
55       URLPatternSet* new_hosts,
56       std::set<PermissionMessage>* messages) const = 0;
57
58   // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
59   // only used for testing in the browser process.
60   virtual void SetScriptingWhitelist(const ScriptingWhitelist& whitelist) = 0;
61
62   // Return the whitelist of extensions that can run content scripts on
63   // any origin.
64   virtual const ScriptingWhitelist& GetScriptingWhitelist() const = 0;
65
66   // Get the set of chrome:// hosts that |extension| can run content scripts on.
67   virtual URLPatternSet GetPermittedChromeSchemeHosts(
68       const Extension* extension,
69       const APIPermissionSet& api_permissions) const = 0;
70
71   // Returns false if content scripts are forbidden from running on |url|.
72   virtual bool IsScriptableURL(const GURL& url, std::string* error) const = 0;
73
74   // Return the extensions client.
75   static ExtensionsClient* Get();
76
77   // Initialize the extensions system with this extensions client.
78   static void Set(ExtensionsClient* client);
79 };
80
81 }  // namespace extensions
82
83 #endif  // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_