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