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

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

Issue 995283004: Move Extension ScriptContext creation into ScriptContextSet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ready Created 5 years, 9 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 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
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
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);
264 248
265 // The delegate for this dispatcher. Not owned, but must extend beyond the 249 // The delegate for this dispatcher. Not owned, but must extend beyond the
266 // Dispatcher's own lifetime. 250 // Dispatcher's own lifetime.
267 DispatcherDelegate* delegate_; 251 DispatcherDelegate* delegate_;
268 252
269 // True if the IdleNotification timer should be set. 253 // True if the IdleNotification timer should be set.
270 bool set_idle_notifications_; 254 bool set_idle_notifications_;
271 255
272 // Contains all loaded extensions. This is essentially the renderer 256 // Contains all loaded extensions. This is essentially the renderer
273 // counterpart to ExtensionService in the browser. It contains information 257 // counterpart to ExtensionService in the browser. It contains information
274 // about all extensions currently loaded by the browser. 258 // about all extensions currently loaded by the browser.
275 ExtensionSet extensions_; 259 ExtensionSet extensions_;
276 260
277 // The IDs of extensions that failed to load, mapped to the error message 261 // The IDs of extensions that failed to load, mapped to the error message
278 // generated on failure. 262 // generated on failure.
279 std::map<std::string, std::string> extension_load_errors_; 263 std::map<std::string, std::string> extension_load_errors_;
280 264
281 // All the bindings contexts that are currently loaded for this renderer. 265 // All the bindings contexts that are currently loaded for this renderer.
282 // There is zero or one for each v8 context. 266 // There is zero or one for each v8 context.
283 ScriptContextSet script_context_set_; 267 scoped_ptr<ScriptContextSet> script_context_set_;
284 268
285 scoped_ptr<ContentWatcher> content_watcher_; 269 scoped_ptr<ContentWatcher> content_watcher_;
286 270
287 scoped_ptr<UserScriptSetManager> user_script_set_manager_; 271 scoped_ptr<UserScriptSetManager> user_script_set_manager_;
288 272
289 scoped_ptr<ScriptInjectionManager> script_injection_manager_; 273 scoped_ptr<ScriptInjectionManager> script_injection_manager_;
290 274
291 // Same as above, but on a longer timer and will run even if the process is 275 // Same as above, but on a longer timer and will run even if the process is
292 // not idle, to ensure that IdleHandle gets called eventually. 276 // not idle, to ensure that IdleHandle gets called eventually.
293 scoped_ptr<base::RepeatingTimer<content::RenderThread> > forced_idle_timer_; 277 scoped_ptr<base::RepeatingTimer<content::RenderThread> > forced_idle_timer_;
294 278
295 // All declared function names. 279 // All declared function names.
296 std::set<std::string> function_names_; 280 std::set<std::string> function_names_;
297 281
298 // The extensions and apps that are active in this process. 282 // The extensions and apps that are active in this process.
299 std::set<std::string> active_extension_ids_; 283 ExtensionIdSet active_extension_ids_;
300 284
301 ResourceBundleSourceMap source_map_; 285 ResourceBundleSourceMap source_map_;
302 286
303 // Cache for the v8 representation of extension API schemas. 287 // Cache for the v8 representation of extension API schemas.
304 scoped_ptr<V8SchemaRegistry> v8_schema_registry_; 288 scoped_ptr<V8SchemaRegistry> v8_schema_registry_;
305 289
306 // Sends API requests to the extension host. 290 // Sends API requests to the extension host.
307 scoped_ptr<RequestSender> request_sender_; 291 scoped_ptr<RequestSender> request_sender_;
308 292
309 // The platforms system font family and size; 293 // The platforms system font family and size;
(...skipping 13 matching lines...) Expand all
323 307
324 // Status of webrequest usage. 308 // Status of webrequest usage.
325 bool webrequest_used_; 309 bool webrequest_used_;
326 310
327 DISALLOW_COPY_AND_ASSIGN(Dispatcher); 311 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
328 }; 312 };
329 313
330 } // namespace extensions 314 } // namespace extensions
331 315
332 #endif // EXTENSIONS_RENDERER_DISPATCHER_H_ 316 #endif // EXTENSIONS_RENDERER_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698