OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_RENDERER_DISPATCHER_H_ | 5 #ifndef EXTENSIONS_RENDERER_DISPATCHER_H_ |
6 #define EXTENSIONS_RENDERER_DISPATCHER_H_ | 6 #define EXTENSIONS_RENDERER_DISPATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
16 #include "content/public/renderer/render_process_observer.h" | 17 #include "content/public/renderer/render_process_observer.h" |
17 #include "extensions/common/event_filter.h" | 18 #include "extensions/common/event_filter.h" |
| 19 #include "extensions/common/extension.h" |
18 #include "extensions/common/extension_set.h" | 20 #include "extensions/common/extension_set.h" |
19 #include "extensions/common/extensions_client.h" | 21 #include "extensions/common/extensions_client.h" |
20 #include "extensions/common/features/feature.h" | 22 #include "extensions/common/features/feature.h" |
21 #include "extensions/renderer/resource_bundle_source_map.h" | 23 #include "extensions/renderer/resource_bundle_source_map.h" |
22 #include "extensions/renderer/script_context.h" | 24 #include "extensions/renderer/script_context.h" |
23 #include "extensions/renderer/script_context_set.h" | 25 #include "extensions/renderer/script_context_set.h" |
24 #include "extensions/renderer/user_script_set_manager.h" | 26 #include "extensions/renderer/user_script_set_manager.h" |
25 #include "extensions/renderer/v8_schema_registry.h" | 27 #include "extensions/renderer/v8_schema_registry.h" |
26 #include "third_party/WebKit/public/platform/WebString.h" | 28 #include "third_party/WebKit/public/platform/WebString.h" |
27 #include "third_party/WebKit/public/platform/WebVector.h" | 29 #include "third_party/WebKit/public/platform/WebVector.h" |
(...skipping 18 matching lines...) Expand all Loading... |
46 class ListValue; | 48 class ListValue; |
47 } | 49 } |
48 | 50 |
49 namespace content { | 51 namespace content { |
50 class RenderThread; | 52 class RenderThread; |
51 } | 53 } |
52 | 54 |
53 namespace extensions { | 55 namespace extensions { |
54 class ContentWatcher; | 56 class ContentWatcher; |
55 class DispatcherDelegate; | 57 class DispatcherDelegate; |
56 class Extension; | |
57 class FilteredEventRouter; | 58 class FilteredEventRouter; |
58 class ManifestPermissionSet; | 59 class ManifestPermissionSet; |
59 class RequestSender; | 60 class RequestSender; |
60 class ScriptContext; | 61 class ScriptContext; |
61 class ScriptInjectionManager; | 62 class ScriptInjectionManager; |
62 struct Message; | 63 struct Message; |
63 | 64 |
64 // Dispatches extension control messages sent to the renderer and stores | 65 // Dispatches extension control messages sent to the renderer and stores |
65 // renderer extension related state. | 66 // renderer extension related state. |
66 class Dispatcher : public content::RenderProcessObserver, | 67 class Dispatcher : public content::RenderProcessObserver, |
67 public UserScriptSetManager::Observer { | 68 public UserScriptSetManager::Observer { |
68 public: | 69 public: |
69 explicit Dispatcher(DispatcherDelegate* delegate); | 70 explicit Dispatcher(DispatcherDelegate* delegate); |
70 ~Dispatcher() override; | 71 ~Dispatcher() override; |
71 | 72 |
72 const std::set<std::string>& function_names() const { | 73 const std::set<std::string>& function_names() const { |
73 return function_names_; | 74 return function_names_; |
74 } | 75 } |
75 | 76 |
76 const ExtensionSet* extensions() const { return &extensions_; } | 77 const ExtensionSet* extensions() const { return &extensions_; } |
77 | 78 |
78 const ScriptContextSet& script_context_set() const { | 79 const ScriptContextSet& script_context_set() const { |
79 return script_context_set_; | 80 return *script_context_set_; |
80 } | 81 } |
81 | 82 |
82 V8SchemaRegistry* v8_schema_registry() { return v8_schema_registry_.get(); } | 83 V8SchemaRegistry* v8_schema_registry() { return v8_schema_registry_.get(); } |
83 | 84 |
84 ContentWatcher* content_watcher() { return content_watcher_.get(); } | 85 ContentWatcher* content_watcher() { return content_watcher_.get(); } |
85 | 86 |
86 RequestSender* request_sender() { return request_sender_.get(); } | 87 RequestSender* request_sender() { return request_sender_.get(); } |
87 | 88 |
88 void OnRenderViewCreated(content::RenderView* render_view); | 89 void OnRenderViewCreated(content::RenderView* render_view); |
89 | 90 |
90 bool IsExtensionActive(const std::string& extension_id) const; | 91 bool IsExtensionActive(const std::string& extension_id) const; |
91 | 92 |
92 // Finds the extension for the JavaScript context associated with the | |
93 // specified |frame| and isolated world. If |world_id| is zero, finds the | |
94 // extension ID associated with the main world's JavaScript context. If the | |
95 // JavaScript context isn't from an extension, returns empty string. | |
96 const Extension* GetExtensionFromFrameAndWorld(const blink::WebFrame* frame, | |
97 int world_id, | |
98 bool use_effective_url); | |
99 | |
100 void DidCreateScriptContext(blink::WebLocalFrame* frame, | 93 void DidCreateScriptContext(blink::WebLocalFrame* frame, |
101 const v8::Handle<v8::Context>& context, | 94 const v8::Handle<v8::Context>& context, |
102 int extension_group, | 95 int extension_group, |
103 int world_id); | 96 int world_id); |
104 | 97 |
105 void WillReleaseScriptContext(blink::WebLocalFrame* frame, | 98 void WillReleaseScriptContext(blink::WebLocalFrame* frame, |
106 const v8::Handle<v8::Context>& context, | 99 const v8::Handle<v8::Context>& context, |
107 int world_id); | 100 int world_id); |
108 | 101 |
109 void DidCreateDocumentElement(blink::WebFrame* frame); | 102 void DidCreateDocumentElement(blink::WebFrame* frame); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // Updates a web page context with any content capabilities granted by active | 228 // Updates a web page context with any content capabilities granted by active |
236 // extensions. | 229 // extensions. |
237 void UpdateContentCapabilities(ScriptContext* context); | 230 void UpdateContentCapabilities(ScriptContext* context); |
238 | 231 |
239 // Inserts static source code into |source_map_|. | 232 // Inserts static source code into |source_map_|. |
240 void PopulateSourceMap(); | 233 void PopulateSourceMap(); |
241 | 234 |
242 // Returns whether the current renderer hosts a platform app. | 235 // Returns whether the current renderer hosts a platform app. |
243 bool IsWithinPlatformApp(); | 236 bool IsWithinPlatformApp(); |
244 | 237 |
245 bool IsSandboxedPage(const GURL& url) const; | |
246 | |
247 // Returns the Feature::Context type of context for a JavaScript context. | |
248 Feature::Context ClassifyJavaScriptContext( | |
249 const Extension* extension, | |
250 int extension_group, | |
251 const GURL& url, | |
252 const blink::WebSecurityOrigin& origin); | |
253 | |
254 // Gets |field| from |object| or creates it as an empty object if it doesn't | 238 // Gets |field| from |object| or creates it as an empty object if it doesn't |
255 // exist. | 239 // exist. |
256 v8::Handle<v8::Object> GetOrCreateObject(const v8::Handle<v8::Object>& object, | 240 v8::Handle<v8::Object> GetOrCreateObject(const v8::Handle<v8::Object>& object, |
257 const std::string& field, | 241 const std::string& field, |
258 v8::Isolate* isolate); | 242 v8::Isolate* isolate); |
259 | 243 |
260 v8::Handle<v8::Object> GetOrCreateBindObjectIfAvailable( | 244 v8::Handle<v8::Object> GetOrCreateBindObjectIfAvailable( |
261 const std::string& api_name, | 245 const std::string& api_name, |
262 std::string* bind_name, | 246 std::string* bind_name, |
263 ScriptContext* context); | 247 ScriptContext* context); |
(...skipping 13 matching lines...) Expand all Loading... |
277 // counterpart to ExtensionService in the browser. It contains information | 261 // counterpart to ExtensionService in the browser. It contains information |
278 // about all extensions currently loaded by the browser. | 262 // about all extensions currently loaded by the browser. |
279 ExtensionSet extensions_; | 263 ExtensionSet extensions_; |
280 | 264 |
281 // The IDs of extensions that failed to load, mapped to the error message | 265 // The IDs of extensions that failed to load, mapped to the error message |
282 // generated on failure. | 266 // generated on failure. |
283 std::map<std::string, std::string> extension_load_errors_; | 267 std::map<std::string, std::string> extension_load_errors_; |
284 | 268 |
285 // All the bindings contexts that are currently loaded for this renderer. | 269 // All the bindings contexts that are currently loaded for this renderer. |
286 // There is zero or one for each v8 context. | 270 // There is zero or one for each v8 context. |
287 ScriptContextSet script_context_set_; | 271 scoped_ptr<ScriptContextSet> script_context_set_; |
288 | 272 |
289 scoped_ptr<ContentWatcher> content_watcher_; | 273 scoped_ptr<ContentWatcher> content_watcher_; |
290 | 274 |
291 scoped_ptr<UserScriptSetManager> user_script_set_manager_; | 275 scoped_ptr<UserScriptSetManager> user_script_set_manager_; |
292 | 276 |
293 scoped_ptr<ScriptInjectionManager> script_injection_manager_; | 277 scoped_ptr<ScriptInjectionManager> script_injection_manager_; |
294 | 278 |
295 // Same as above, but on a longer timer and will run even if the process is | 279 // Same as above, but on a longer timer and will run even if the process is |
296 // not idle, to ensure that IdleHandle gets called eventually. | 280 // not idle, to ensure that IdleHandle gets called eventually. |
297 scoped_ptr<base::RepeatingTimer<content::RenderThread> > forced_idle_timer_; | 281 scoped_ptr<base::RepeatingTimer<content::RenderThread> > forced_idle_timer_; |
298 | 282 |
299 // All declared function names. | 283 // All declared function names. |
300 std::set<std::string> function_names_; | 284 std::set<std::string> function_names_; |
301 | 285 |
302 // The extensions and apps that are active in this process. | 286 // The extensions and apps that are active in this process. |
303 std::set<std::string> active_extension_ids_; | 287 ExtensionIdSet active_extension_ids_; |
304 | 288 |
305 ResourceBundleSourceMap source_map_; | 289 ResourceBundleSourceMap source_map_; |
306 | 290 |
307 // Cache for the v8 representation of extension API schemas. | 291 // Cache for the v8 representation of extension API schemas. |
308 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; | 292 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; |
309 | 293 |
310 // Sends API requests to the extension host. | 294 // Sends API requests to the extension host. |
311 scoped_ptr<RequestSender> request_sender_; | 295 scoped_ptr<RequestSender> request_sender_; |
312 | 296 |
313 // The platforms system font family and size; | 297 // The platforms system font family and size; |
(...skipping 13 matching lines...) Expand all Loading... |
327 | 311 |
328 // Status of webrequest usage. | 312 // Status of webrequest usage. |
329 bool webrequest_used_; | 313 bool webrequest_used_; |
330 | 314 |
331 DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 315 DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
332 }; | 316 }; |
333 | 317 |
334 } // namespace extensions | 318 } // namespace extensions |
335 | 319 |
336 #endif // EXTENSIONS_RENDERER_DISPATCHER_H_ | 320 #endif // EXTENSIONS_RENDERER_DISPATCHER_H_ |
OLD | NEW |