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