• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_RENDERER_DISPATCHER_DELEGATE_H
6 #define EXTENSIONS_RENDERER_DISPATCHER_DELEGATE_H
7 
8 #include <set>
9 #include <string>
10 
11 #include "base/memory/scoped_ptr.h"
12 #include "extensions/common/features/feature.h"
13 #include "v8/include/v8.h"
14 
15 namespace blink {
16 class WebFrame;
17 }
18 
19 namespace extensions {
20 class Dispatcher;
21 class Extension;
22 class ModuleSystem;
23 class ResourceBundleSourceMap;
24 class ScriptContext;
25 class URLPatternSet;
26 
27 // Base class and default implementation for an extensions::Dispacher delegate.
28 // DispatcherDelegate can be used to override and extend the behavior of the
29 // extensions system's renderer side.
30 class DispatcherDelegate {
31  public:
~DispatcherDelegate()32   virtual ~DispatcherDelegate() {}
33 
34   // Creates a new ScriptContext for a given v8 context.
35   virtual scoped_ptr<ScriptContext> CreateScriptContext(
36       const v8::Handle<v8::Context>& v8_context,
37       blink::WebFrame* frame,
38       const Extension* extension,
39       Feature::Context context_type) = 0;
40 
41   // Initializes origin permissions for a newly created extension context.
InitOriginPermissions(const Extension * extension,bool is_extension_active)42   virtual void InitOriginPermissions(const Extension* extension,
43                                      bool is_extension_active) {}
44 
45   // Includes additional native handlers in a given ModuleSystem.
RegisterNativeHandlers(Dispatcher * dispatcher,ModuleSystem * module_system,ScriptContext * context)46   virtual void RegisterNativeHandlers(Dispatcher* dispatcher,
47                                       ModuleSystem* module_system,
48                                       ScriptContext* context) {}
49 
50   // Includes additional source resources into the resource map.
PopulateSourceMap(ResourceBundleSourceMap * source_map)51   virtual void PopulateSourceMap(ResourceBundleSourceMap* source_map) {}
52 
53   // Requires additional modules within an extension context's module system.
RequireAdditionalModules(ModuleSystem * module_system,const Extension * extension,Feature::Context context_type,bool is_within_platform_app)54   virtual void RequireAdditionalModules(ModuleSystem* module_system,
55                                         const Extension* extension,
56                                         Feature::Context context_type,
57                                         bool is_within_platform_app) {}
58 
59   // Allows the delegate to respond to an updated set of active extensions in
60   // the Dispatcher.
OnActiveExtensionsUpdated(const std::set<std::string> & extension_ids)61   virtual void OnActiveExtensionsUpdated(
62       const std::set<std::string>& extension_ids) {}
63 
64   // Sets the current Chrome channel.
65   // TODO(rockot): This doesn't belong in a generic extensions system interface.
66   // See http://crbug.com/368431.
SetChannel(int channel)67   virtual void SetChannel(int channel) {}
68 
69   // Clears extension permissions specific to a given tab.
70   // TODO(rockot): This doesn't belong in a generic extensions system interface.
71   // See http://crbug.com/368431.
ClearTabSpecificPermissions(const extensions::Dispatcher * dispatcher,int tab_id,const std::vector<std::string> & extension_ids)72   virtual void ClearTabSpecificPermissions(
73       const extensions::Dispatcher* dispatcher,
74       int tab_id,
75       const std::vector<std::string>& extension_ids) {}
76 
77   // Updates extension permissions specific to a given tab.
78   // TODO(rockot): This doesn't belong in a generic extensions system interface.
79   // See http://crbug.com/368431.
UpdateTabSpecificPermissions(const extensions::Dispatcher * dispatcher,int page_id,int tab_id,const std::string & extension_id,const extensions::URLPatternSet & origin_set)80   virtual void UpdateTabSpecificPermissions(
81       const extensions::Dispatcher* dispatcher,
82       int page_id,
83       int tab_id,
84       const std::string& extension_id,
85       const extensions::URLPatternSet& origin_set) {}
86 
87   // Allows the delegate to respond to reports from the browser about WebRequest
88   // API usage from within this process.
HandleWebRequestAPIUsage(bool webrequest_used)89   virtual void HandleWebRequestAPIUsage(bool webrequest_used) {}
90 };
91 
92 }  // namespace extensions
93 
94 #endif  // EXTENSIONS_RENDERER_DISPATCHER_DELEGATE_H
95