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 ~ExtensionsClient()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 // Create a FeatureProvider for a specific feature type, e.g. "permission". 49 virtual scoped_ptr<FeatureProvider> CreateFeatureProvider( 50 const std::string& name) const = 0; 51 52 // Create a JSONFeatureProviderSource for a specific feature type, 53 // e.g. "permission". Currently, all features are loaded from 54 // JSONFeatureProviderSources. 55 // This is used primarily in CreateFeatureProvider, above. 56 virtual scoped_ptr<JSONFeatureProviderSource> CreateFeatureProviderSource( 57 const std::string& name) const = 0; 58 59 // Takes the list of all hosts and filters out those with special 60 // permission strings. Adds the regular hosts to |new_hosts|, 61 // and adds the special permission messages to |messages|. 62 virtual void FilterHostPermissions( 63 const URLPatternSet& hosts, 64 URLPatternSet* new_hosts, 65 std::set<PermissionMessage>* messages) const = 0; 66 67 // Replaces the scripting whitelist with |whitelist|. Used in the renderer; 68 // only used for testing in the browser process. 69 virtual void SetScriptingWhitelist(const ScriptingWhitelist& whitelist) = 0; 70 71 // Return the whitelist of extensions that can run content scripts on 72 // any origin. 73 virtual const ScriptingWhitelist& GetScriptingWhitelist() const = 0; 74 75 // Get the set of chrome:// hosts that |extension| can run content scripts on. 76 virtual URLPatternSet GetPermittedChromeSchemeHosts( 77 const Extension* extension, 78 const APIPermissionSet& api_permissions) const = 0; 79 80 // Returns false if content scripts are forbidden from running on |url|. 81 virtual bool IsScriptableURL(const GURL& url, std::string* error) const = 0; 82 83 // Returns true iff a schema named |name| is generated. 84 virtual bool IsAPISchemaGenerated(const std::string& name) const = 0; 85 86 // Gets the generated API schema named |name|. 87 virtual base::StringPiece GetAPISchema(const std::string& name) const = 0; 88 89 // Register non-generated API schema resources with the global ExtensionAPI. 90 // Called when the ExtensionAPI is lazily initialized. 91 virtual void RegisterAPISchemaResources(ExtensionAPI* api) const = 0; 92 93 // Determines if certain fatal extensions errors should be surpressed 94 // (i.e., only logged) or allowed (i.e., logged before crashing). 95 virtual bool ShouldSuppressFatalErrors() const = 0; 96 97 // Return the extensions client. 98 static ExtensionsClient* Get(); 99 100 // Initialize the extensions system with this extensions client. 101 static void Set(ExtensionsClient* client); 102 }; 103 104 } // namespace extensions 105 106 #endif // EXTENSIONS_COMMON_EXTENSIONS_CLIENT_H_ 107