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_SCRIPT_INJECTION_MANAGER_H_ | 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ |
6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ | 6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 27 matching lines...) Expand all Loading... |
38 // load point, and injecting them when ready. | 38 // load point, and injecting them when ready. |
39 class ScriptInjectionManager : public UserScriptSetManager::Observer { | 39 class ScriptInjectionManager : public UserScriptSetManager::Observer { |
40 public: | 40 public: |
41 ScriptInjectionManager(const ExtensionSet* extensions, | 41 ScriptInjectionManager(const ExtensionSet* extensions, |
42 UserScriptSetManager* user_script_set_manager); | 42 UserScriptSetManager* user_script_set_manager); |
43 virtual ~ScriptInjectionManager(); | 43 virtual ~ScriptInjectionManager(); |
44 | 44 |
45 // Notifies that a new render view has been created. | 45 // Notifies that a new render view has been created. |
46 void OnRenderViewCreated(content::RenderView* render_view); | 46 void OnRenderViewCreated(content::RenderView* render_view); |
47 | 47 |
| 48 // Notifies that an injection has been finished |
| 49 void OnInjectionFinished(ScriptInjection* injection); |
| 50 |
48 private: | 51 private: |
49 // A RenderViewObserver implementation which watches the various render views | 52 // A RenderViewObserver implementation which watches the various render views |
50 // in order to notify the ScriptInjectionManager of different document load | 53 // in order to notify the ScriptInjectionManager of different document load |
51 // states. | 54 // states. |
52 class RVOHelper; | 55 class RVOHelper; |
53 | 56 |
54 typedef std::map<blink::WebFrame*, UserScript::RunLocation> FrameStatusMap; | 57 typedef std::map<blink::WebFrame*, UserScript::RunLocation> FrameStatusMap; |
55 | 58 |
56 // UserScriptSetManager::Observer implementation. | 59 // UserScriptSetManager::Observer implementation. |
57 void OnUserScriptsUpdated(const std::set<std::string>& changed_extensions, | 60 void OnUserScriptsUpdated(const std::set<std::string>& changed_extensions, |
58 const std::vector<UserScript*>& scripts) override; | 61 const std::vector<UserScript*>& scripts) override; |
59 | 62 |
60 // Notifies that an RVOHelper should be removed. | 63 // Notifies that an RVOHelper should be removed. |
61 void RemoveObserver(RVOHelper* helper); | 64 void RemoveObserver(RVOHelper* helper); |
62 | 65 |
63 // Invalidate any pending tasks associated with |frame|. | 66 // Invalidate any pending tasks associated with |frame|. |
64 void InvalidateForFrame(blink::WebFrame* frame); | 67 void InvalidateForFrame(blink::WebFrame* frame); |
65 | 68 |
66 // Returns true if the given |frame| is still valid. | |
67 bool IsFrameValid(blink::WebFrame* frame) const; | |
68 | |
69 // Starts the process to inject appropriate scripts into |frame|. | 69 // Starts the process to inject appropriate scripts into |frame|. |
70 void StartInjectScripts(blink::WebFrame* frame, | 70 void StartInjectScripts(blink::WebFrame* frame, |
71 UserScript::RunLocation run_location); | 71 UserScript::RunLocation run_location); |
72 | 72 |
73 // Actually injects the scripts into |frame|. | 73 // Actually injects the scripts into |frame|. |
74 void InjectScripts(blink::WebFrame* frame, | 74 void InjectScripts(blink::WebFrame* frame, |
75 UserScript::RunLocation run_location); | 75 UserScript::RunLocation run_location); |
76 | 76 |
| 77 // Try to inject and store injection if it has not finished |
| 78 void TryToInject(scoped_ptr<ScriptInjection> injection, |
| 79 UserScript::RunLocation run_location, |
| 80 ScriptsRunInfo* scripts_run_info, |
| 81 bool store_waiting); |
| 82 |
77 // Handle the ExecuteCode extension message. | 83 // Handle the ExecuteCode extension message. |
78 void HandleExecuteCode(const ExtensionMsg_ExecuteCode_Params& params, | 84 void HandleExecuteCode(const ExtensionMsg_ExecuteCode_Params& params, |
79 content::RenderView* render_view); | 85 content::RenderView* render_view); |
80 | 86 |
81 // Handle the ExecuteDeclarativeScript extension message. | 87 // Handle the ExecuteDeclarativeScript extension message. |
82 void HandleExecuteDeclarativeScript(blink::WebFrame* web_frame, | 88 void HandleExecuteDeclarativeScript(blink::WebFrame* web_frame, |
83 int tab_id, | 89 int tab_id, |
84 const ExtensionId& extension_id, | 90 const ExtensionId& extension_id, |
85 int script_id, | 91 int script_id, |
86 const GURL& url); | 92 const GURL& url); |
87 | 93 |
88 // Handle the GrantInjectionPermission extension message. | 94 // Handle the GrantInjectionPermission extension message. |
89 void HandlePermitScriptInjection(int64 request_id); | 95 void HandlePermitScriptInjection(int64 request_id); |
90 | 96 |
91 // Extensions metadata, owned by Dispatcher (which owns this object). | 97 // Extensions metadata, owned by Dispatcher (which owns this object). |
92 const ExtensionSet* extensions_; | 98 const ExtensionSet* extensions_; |
93 | 99 |
94 // The map of active web frames to their corresponding statuses. The | 100 // The map of active web frames to their corresponding statuses. The |
95 // RunLocation of the frame corresponds to the last location that has ran. | 101 // RunLocation of the frame corresponds to the last location that has ran. |
96 FrameStatusMap frame_statuses_; | 102 FrameStatusMap frame_statuses_; |
97 | 103 |
98 // The collection of RVOHelpers. | 104 // The collection of RVOHelpers. |
99 ScopedVector<RVOHelper> rvo_helpers_; | 105 ScopedVector<RVOHelper> rvo_helpers_; |
100 | 106 |
101 // True when the manager is actively injecting scripts into a web frame. | |
102 bool injecting_scripts_; | |
103 | |
104 // The set of extensions that have been updated (and thus any injections have | |
105 // been invalidated) while the manager was |injecting_scripts_|. | |
106 std::set<std::string> invalidated_while_injecting_; | |
107 | |
108 // The set of UserScripts associated with extensions. Owned by the Dispatcher. | 107 // The set of UserScripts associated with extensions. Owned by the Dispatcher. |
109 UserScriptSetManager* user_script_set_manager_; | 108 UserScriptSetManager* user_script_set_manager_; |
110 | 109 |
111 // Pending injections which are waiting for either the proper run location or | 110 // Pending injections which are waiting for either the proper run location or |
112 // user consent. | 111 // user consent. |
113 ScopedVector<ScriptInjection> pending_injections_; | 112 ScopedVector<ScriptInjection> pending_injections_; |
114 | 113 |
| 114 // Running injections which are waiting for async callbacks from blink |
| 115 ScopedVector<ScriptInjection> running_injections_; |
| 116 |
115 ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer> | 117 ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer> |
116 user_script_set_manager_observer_; | 118 user_script_set_manager_observer_; |
117 | 119 |
118 DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager); | 120 DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager); |
119 }; | 121 }; |
120 | 122 |
121 } // namespace extensions | 123 } // namespace extensions |
122 | 124 |
123 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ | 125 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ |
OLD | NEW |