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

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

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

Powered by Google App Engine
This is Rietveld 408576698