OLD | NEW |
---|---|
(Empty) | |
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_SCRIPT_INJECTION_MANAGER_H_ | |
6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/memory/scoped_vector.h" | |
14 #include "base/memory/shared_memory.h" | |
15 #include "base/scoped_observer.h" | |
16 #include "extensions/common/user_script.h" | |
17 #include "extensions/renderer/script_injection.h" | |
18 #include "extensions/renderer/user_script_injection_list.h" | |
19 | |
20 struct ExtensionMsg_ExecuteCode_Params; | |
21 | |
22 namespace blink { | |
23 class WebFrame; | |
24 class WebLocalFrame; | |
25 } | |
26 | |
27 namespace content { | |
28 class RenderView; | |
29 } | |
30 | |
31 namespace extensions { | |
32 class Extension; | |
33 class ExtensionSet; | |
34 | |
35 // The ScriptInjectionManager manages extensions injecting scripts into frames | |
36 // via both content/user scripts and tabs.executeScript(). It is responsible for | |
37 // maintaining any pending injections awaiting permission or the appropriate | |
38 // load point, and injecting them when ready. | |
39 class ScriptInjectionManager : public UserScriptInjectionList::Observer { | |
40 public: | |
41 explicit ScriptInjectionManager(const ExtensionSet* extensions); | |
42 virtual ~ScriptInjectionManager(); | |
43 | |
44 // Notifies that a new render view has been created. | |
45 void OnRenderViewCreated(content::RenderView* render_view); | |
46 | |
47 UserScriptInjectionList* user_script_injection_list() { | |
not at google - send to devlin
2014/06/15 23:53:38
it would make more sense to me for Dispatcher to o
Devlin
2014/06/16 18:11:16
Done.
| |
48 return user_script_injection_list_.get(); | |
49 } | |
50 | |
51 private: | |
52 // A RenderViewObserver implementation which watches the various render views | |
53 // in order to notify the ScriptInjectionManager of different document load | |
54 // states. | |
55 class RVOHelper; | |
56 | |
57 // A struct to hold the current RunLocation for each frame, and whether or | |
58 // not scripts set to document_idle have been run. | |
59 struct FrameStatus { | |
60 FrameStatus(); | |
61 | |
62 UserScript::RunLocation current_location; | |
63 bool has_run_idle; | |
64 }; | |
65 typedef std::map<blink::WebFrame*, FrameStatus> FrameStatusMap; | |
66 | |
67 // UserScriptInjectionList::Observer implementation. | |
68 virtual void OnUserScriptsUpdated( | |
69 const std::set<std::string>& changed_extensions, | |
70 const std::vector<UserScript*>& scripts) OVERRIDE; | |
71 | |
72 // Notifies that an RVOHelper should be removed. | |
73 void RemoveObserver(RVOHelper* helper); | |
74 | |
75 // Invalidate any pending tasks associated with |frame|. | |
76 void InvalidateForFrame(blink::WebFrame* frame); | |
77 | |
78 // Inject appropriate scripts into |frame|. | |
79 void InjectScripts(blink::WebFrame* frame, | |
80 UserScript::RunLocation run_location); | |
81 | |
82 // Requests permission for the given |injection| or immediately injects, | |
83 // depending on whether or not the feature is enabled. | |
84 void RequestPermissionOrInject(scoped_ptr<ScriptInjection> injection, | |
85 ScriptInjection::ScriptsRunInfo*, | |
86 const Extension* extension); | |
87 | |
88 // Handle the ExecuteCode extension message. | |
89 void HandleExecuteCode(const ExtensionMsg_ExecuteCode_Params& params, | |
90 content::RenderView* render_view); | |
91 | |
92 // Handle the GrantInjectionPermission extension message. | |
93 void HandlePermitScriptInjection(int request_id); | |
94 | |
95 // Extensions metadata, owned by Dispatcher (which owns this object). | |
96 const ExtensionSet* extensions_; | |
97 | |
98 // The map of active web frames to their corresponding statuses. | |
99 FrameStatusMap frame_statuses_; | |
100 | |
101 // The collection of RVOHelpers. | |
102 ScopedVector<RVOHelper> rvo_helpers_; | |
103 | |
104 // The UserScriptInjectionList, to create the ScriptInjections for extensions' | |
105 // UserScripts. | |
106 scoped_ptr<UserScriptInjectionList> user_script_injection_list_; | |
107 | |
108 // Pending injections which are waiting for the proper RunLocation. | |
109 ScopedVector<ScriptInjection> injections_awaiting_location_; | |
110 | |
111 // Pending injections which are waiting for user consent. | |
112 ScopedVector<ScriptInjection> injections_awaiting_permission_; | |
113 | |
114 // Note: This must be declared after UserScriptInjectionList so that the | |
115 // observer is removed before UserScriptInjectionList is destroyed. | |
116 ScopedObserver<UserScriptInjectionList, UserScriptInjectionList::Observer> | |
117 user_script_injection_list_observer_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager); | |
120 }; | |
121 | |
122 } // namespace extensions | |
123 | |
124 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ | |
OLD | NEW |