Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: chrome/renderer/extensions/dispatcher.h

Issue 10821133: Move c/r/extensions/* into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for cq Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_DISPATCHER_H_
6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ 6 #define CHROME_RENDERER_EXTENSIONS_DISPATCHER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/shared_memory.h" 12 #include "base/shared_memory.h"
13 #include "base/timer.h" 13 #include "base/timer.h"
14 #include "content/public/renderer/render_process_observer.h" 14 #include "content/public/renderer/render_process_observer.h"
15 #include "chrome/common/extensions/event_filter.h" 15 #include "chrome/common/extensions/event_filter.h"
16 #include "chrome/common/extensions/extension_set.h" 16 #include "chrome/common/extensions/extension_set.h"
17 #include "chrome/common/extensions/features/feature.h" 17 #include "chrome/common/extensions/features/feature.h"
18 #include "chrome/renderer/extensions/chrome_v8_context.h" 18 #include "chrome/renderer/extensions/chrome_v8_context.h"
19 #include "chrome/renderer/extensions/chrome_v8_context_set.h" 19 #include "chrome/renderer/extensions/chrome_v8_context_set.h"
20 #include "chrome/renderer/extensions/v8_schema_registry.h" 20 #include "chrome/renderer/extensions/v8_schema_registry.h"
21 #include "chrome/renderer/resource_bundle_source_map.h" 21 #include "chrome/renderer/resource_bundle_source_map.h"
22 #include "v8/include/v8.h" 22 #include "v8/include/v8.h"
23 23
24 class ExtensionRequestSender;
25 class GURL; 24 class GURL;
26 class ModuleSystem; 25 class ModuleSystem;
27 class URLPattern; 26 class URLPattern;
28 struct ExtensionMsg_Loaded_Params; 27 struct ExtensionMsg_Loaded_Params;
29 28
30 namespace extensions {
31 class FilteredEventRouter;
32 class UserScriptSlave;
33 }
34
35 namespace WebKit { 29 namespace WebKit {
36 class WebFrame; 30 class WebFrame;
37 } 31 }
38 32
39 namespace base { 33 namespace base {
40 class ListValue; 34 class ListValue;
41 } 35 }
42 36
43 namespace content { 37 namespace content {
44 class RenderThread; 38 class RenderThread;
45 } 39 }
46 40
47 namespace extension { 41 namespace extensions {
48 class Extension; 42 class Extension;
49 } 43 class FilteredEventRouter;
44 class RequestSender;
45 class UserScriptSlave;
50 46
51 // Dispatches extension control messages sent to the renderer and stores 47 // Dispatches extension control messages sent to the renderer and stores
52 // renderer extension related state. 48 // renderer extension related state.
53 class ExtensionDispatcher : public content::RenderProcessObserver { 49 class Dispatcher : public content::RenderProcessObserver {
54 public: 50 public:
55 ExtensionDispatcher(); 51 Dispatcher();
56 virtual ~ExtensionDispatcher(); 52 virtual ~Dispatcher();
57 53
58 const std::set<std::string>& function_names() const { 54 const std::set<std::string>& function_names() const {
59 return function_names_; 55 return function_names_;
60 } 56 }
61 57
62 bool is_extension_process() const { return is_extension_process_; } 58 bool is_extension_process() const { return is_extension_process_; }
63 const ExtensionSet* extensions() const { return &extensions_; } 59 const ExtensionSet* extensions() const { return &extensions_; }
64 const ChromeV8ContextSet& v8_context_set() const { 60 const ChromeV8ContextSet& v8_context_set() const {
65 return v8_context_set_; 61 return v8_context_set_;
66 } 62 }
67 extensions::UserScriptSlave* user_script_slave() { 63 UserScriptSlave* user_script_slave() {
68 return user_script_slave_.get(); 64 return user_script_slave_.get();
69 } 65 }
70 extensions::V8SchemaRegistry* v8_schema_registry() { 66 V8SchemaRegistry* v8_schema_registry() {
71 return &v8_schema_registry_; 67 return &v8_schema_registry_;
72 } 68 }
73 69
74 bool IsExtensionActive(const std::string& extension_id) const; 70 bool IsExtensionActive(const std::string& extension_id) const;
75 71
76 // Finds the extension ID for the JavaScript context associated with the 72 // Finds the extension ID for the JavaScript context associated with the
77 // specified |frame| and isolated world. If |world_id| is zero, finds the 73 // specified |frame| and isolated world. If |world_id| is zero, finds the
78 // extension ID associated with the main world's JavaScript context. If the 74 // extension ID associated with the main world's JavaScript context. If the
79 // JavaScript context isn't from an extension, returns empty string. 75 // JavaScript context isn't from an extension, returns empty string.
80 std::string GetExtensionID(const WebKit::WebFrame* frame, int world_id); 76 std::string GetExtensionID(const WebKit::WebFrame* frame, int world_id);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 const std::string& tab_json, 139 const std::string& tab_json,
144 const std::string& source_extension_id, 140 const std::string& source_extension_id,
145 const std::string& target_extension_id); 141 const std::string& target_extension_id);
146 void OnDeliverMessage(int target_port_id, const std::string& message); 142 void OnDeliverMessage(int target_port_id, const std::string& message);
147 void OnDispatchOnDisconnect(int port_id, bool connection_error); 143 void OnDispatchOnDisconnect(int port_id, bool connection_error);
148 void OnSetFunctionNames(const std::vector<std::string>& names); 144 void OnSetFunctionNames(const std::vector<std::string>& names);
149 void OnLoaded( 145 void OnLoaded(
150 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions); 146 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions);
151 void OnUnloaded(const std::string& id); 147 void OnUnloaded(const std::string& id);
152 void OnSetScriptingWhitelist( 148 void OnSetScriptingWhitelist(
153 const extensions::Extension::ScriptingWhitelist& extension_ids); 149 const Extension::ScriptingWhitelist& extension_ids);
154 void OnPageActionsUpdated(const std::string& extension_id, 150 void OnPageActionsUpdated(const std::string& extension_id,
155 const std::vector<std::string>& page_actions); 151 const std::vector<std::string>& page_actions);
156 void OnActivateExtension(const std::string& extension_id); 152 void OnActivateExtension(const std::string& extension_id);
157 void OnUpdatePermissions(int reason_id, 153 void OnUpdatePermissions(int reason_id,
158 const std::string& extension_id, 154 const std::string& extension_id,
159 const extensions::APIPermissionSet& apis, 155 const APIPermissionSet& apis,
160 const URLPatternSet& explicit_hosts, 156 const URLPatternSet& explicit_hosts,
161 const URLPatternSet& scriptable_hosts); 157 const URLPatternSet& scriptable_hosts);
162 void OnUpdateTabSpecificPermissions(int page_id, 158 void OnUpdateTabSpecificPermissions(int page_id,
163 int tab_id, 159 int tab_id,
164 const std::string& extension_id, 160 const std::string& extension_id,
165 const URLPatternSet& origin_set); 161 const URLPatternSet& origin_set);
166 void OnClearTabSpecificPermissions( 162 void OnClearTabSpecificPermissions(
167 int tab_id, 163 int tab_id,
168 const std::vector<std::string>& extension_ids); 164 const std::vector<std::string>& extension_ids);
169 void OnUpdateUserScripts(base::SharedMemoryHandle table); 165 void OnUpdateUserScripts(base::SharedMemoryHandle table);
170 void OnUsingWebRequestAPI( 166 void OnUsingWebRequestAPI(
171 bool adblock, 167 bool adblock,
172 bool adblock_plus, 168 bool adblock_plus,
173 bool other_webrequest); 169 bool other_webrequest);
174 void OnShouldUnload(const std::string& extension_id, int sequence_id); 170 void OnShouldUnload(const std::string& extension_id, int sequence_id);
175 void OnUnload(const std::string& extension_id); 171 void OnUnload(const std::string& extension_id);
176 void OnCancelUnload(const std::string& extension_id); 172 void OnCancelUnload(const std::string& extension_id);
177 173
178 // Update the list of active extensions that will be reported when we crash. 174 // Update the list of active extensions that will be reported when we crash.
179 void UpdateActiveExtensions(); 175 void UpdateActiveExtensions();
180 176
181 // Calls RenderThread's RegisterExtension and keeps tracks of which v8 177 // Calls RenderThread's RegisterExtension and keeps tracks of which v8
182 // extension is for Chrome Extensions only. 178 // extension is for Chrome Extensions only.
183 void RegisterExtension(v8::Extension* extension, bool restrict_to_extensions); 179 void RegisterExtension(v8::Extension* extension, bool restrict_to_extensions);
184 180
185 // Sets up the host permissions for |extension|. 181 // Sets up the host permissions for |extension|.
186 void InitOriginPermissions(const extensions::Extension* extension); 182 void InitOriginPermissions(const Extension* extension);
187 void AddOrRemoveOriginPermissions( 183 void AddOrRemoveOriginPermissions(
188 extensions::UpdatedExtensionPermissionsInfo::Reason reason, 184 UpdatedExtensionPermissionsInfo::Reason reason,
189 const extensions::Extension* extension, 185 const Extension* extension,
190 const URLPatternSet& origins); 186 const URLPatternSet& origins);
191 187
192 void RegisterNativeHandlers(ModuleSystem* module_system, 188 void RegisterNativeHandlers(ModuleSystem* module_system,
193 ChromeV8Context* context); 189 ChromeV8Context* context);
194 190
195 // Inserts static source code into |source_map_|. 191 // Inserts static source code into |source_map_|.
196 void PopulateSourceMap(); 192 void PopulateSourceMap();
197 193
198 // Inserts BindingInstallers into |lazy_bindings_map_|. 194 // Inserts BindingInstallers into |lazy_bindings_map_|.
199 void PopulateLazyBindingsMap(); 195 void PopulateLazyBindingsMap();
200 196
201 // Sets up the bindings for the given api. 197 // Sets up the bindings for the given api.
202 void InstallBindings(ModuleSystem* module_system, 198 void InstallBindings(ModuleSystem* module_system,
203 v8::Handle<v8::Context> v8_context, 199 v8::Handle<v8::Context> v8_context,
204 const std::string& api); 200 const std::string& api);
205 201
206 // Determeines whether |frame| is being run inside a platform app 202 // Determeines whether |frame| is being run inside a platform app
207 // (this evaluates to true for iframes in platform apps). 203 // (this evaluates to true for iframes in platform apps).
208 bool IsWithinPlatformApp(const WebKit::WebFrame* frame); 204 bool IsWithinPlatformApp(const WebKit::WebFrame* frame);
209 205
210 // Returns the Feature::Context type of context for a JavaScript context. 206 // Returns the Feature::Context type of context for a JavaScript context.
211 extensions::Feature::Context ClassifyJavaScriptContext( 207 Feature::Context ClassifyJavaScriptContext(const std::string& extension_id,
212 const std::string& extension_id, 208 int extension_group,
213 int extension_group, 209 const ExtensionURLInfo& url_info);
214 const ExtensionURLInfo& url_info);
215 210
216 // True if this renderer is running extensions. 211 // True if this renderer is running extensions.
217 bool is_extension_process_; 212 bool is_extension_process_;
218 213
219 // Contains all loaded extensions. This is essentially the renderer 214 // Contains all loaded extensions. This is essentially the renderer
220 // counterpart to ExtensionService in the browser. It contains information 215 // counterpart to ExtensionService in the browser. It contains information
221 // about all extensions currently loaded by the browser. 216 // about all extensions currently loaded by the browser.
222 ExtensionSet extensions_; 217 ExtensionSet extensions_;
223 218
224 // All the bindings contexts that are currently loaded for this renderer. 219 // All the bindings contexts that are currently loaded for this renderer.
225 // There is zero or one for each v8 context. 220 // There is zero or one for each v8 context.
226 ChromeV8ContextSet v8_context_set_; 221 ChromeV8ContextSet v8_context_set_;
227 222
228 scoped_ptr<extensions::UserScriptSlave> user_script_slave_; 223 scoped_ptr<UserScriptSlave> user_script_slave_;
229 224
230 // Same as above, but on a longer timer and will run even if the process is 225 // Same as above, but on a longer timer and will run even if the process is
231 // not idle, to ensure that IdleHandle gets called eventually. 226 // not idle, to ensure that IdleHandle gets called eventually.
232 base::RepeatingTimer<content::RenderThread> forced_idle_timer_; 227 base::RepeatingTimer<content::RenderThread> forced_idle_timer_;
233 228
234 // The v8 extensions which are restricted to extension-related contexts. 229 // The v8 extensions which are restricted to extension-related contexts.
235 std::set<std::string> restricted_v8_extensions_; 230 std::set<std::string> restricted_v8_extensions_;
236 231
237 // All declared function names. 232 // All declared function names.
238 std::set<std::string> function_names_; 233 std::set<std::string> function_names_;
239 234
240 // The extensions and apps that are active in this process. 235 // The extensions and apps that are active in this process.
241 std::set<std::string> active_extension_ids_; 236 std::set<std::string> active_extension_ids_;
242 237
243 // True once WebKit has been initialized (and it is therefore safe to poke). 238 // True once WebKit has been initialized (and it is therefore safe to poke).
244 bool is_webkit_initialized_; 239 bool is_webkit_initialized_;
245 240
246 // Status of webrequest usage for known extensions. 241 // Status of webrequest usage for known extensions.
247 // TODO(mpcomplete): remove. http://crbug.com/100411 242 // TODO(mpcomplete): remove. http://crbug.com/100411
248 bool webrequest_adblock_; 243 bool webrequest_adblock_;
249 bool webrequest_adblock_plus_; 244 bool webrequest_adblock_plus_;
250 bool webrequest_other_; 245 bool webrequest_other_;
251 246
252 ResourceBundleSourceMap source_map_; 247 ResourceBundleSourceMap source_map_;
253 248
254 // Cache for the v8 representation of extension API schemas. 249 // Cache for the v8 representation of extension API schemas.
255 extensions::V8SchemaRegistry v8_schema_registry_; 250 V8SchemaRegistry v8_schema_registry_;
256 251
257 // Bindings that are defined lazily and have BindingInstallers to install 252 // Bindings that are defined lazily and have BindingInstallers to install
258 // them. 253 // them.
259 std::map<std::string, BindingInstaller> lazy_bindings_map_; 254 std::map<std::string, BindingInstaller> lazy_bindings_map_;
260 255
261 // Sends API requests to the extension host. 256 // Sends API requests to the extension host.
262 scoped_ptr<ExtensionRequestSender> request_sender_; 257 scoped_ptr<RequestSender> request_sender_;
263 258
264 // The current channel. From VersionInfo::GetChannel(). 259 // The current channel. From VersionInfo::GetChannel().
265 // TODO(aa): Remove when we can restrict non-permission APIs to dev-only. 260 // TODO(aa): Remove when we can restrict non-permission APIs to dev-only.
266 int chrome_channel_; 261 int chrome_channel_;
267 262
268 DISALLOW_COPY_AND_ASSIGN(ExtensionDispatcher); 263 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
269 }; 264 };
270 265
271 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_DISPATCHER_H_ 266 } // namespace extensions
267
268 #endif // CHROME_RENDERER_EXTENSIONS_DISPATCHER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/chrome_v8_extension_handler.cc ('k') | chrome/renderer/extensions/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698