Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
| 15 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
| 16 #include "extensions/common/user_script.h" | 16 #include "extensions/common/user_script.h" |
| 17 #include "extensions/renderer/script_injection.h" | 17 #include "extensions/renderer/script_injection.h" |
| 18 #include "extensions/renderer/user_script_set_manager.h" | 18 #include "extensions/renderer/user_script_set_manager.h" |
| 19 | 19 |
| 20 struct ExtensionMsg_ExecuteCode_Params; | 20 struct ExtensionMsg_ExecuteCode_Params; |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class RenderFrame; | 23 class RenderFrame; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 class Extension; | 27 class Extension; |
| 28 class ExtensionSet; | |
| 29 | 28 |
| 30 // The ScriptInjectionManager manages extensions injecting scripts into frames | 29 // The ScriptInjectionManager manages extensions injecting scripts into frames |
| 31 // via both content/user scripts and tabs.executeScript(). It is responsible for | 30 // via both content/user scripts and tabs.executeScript(). It is responsible for |
| 32 // maintaining any pending injections awaiting permission or the appropriate | 31 // maintaining any pending injections awaiting permission or the appropriate |
| 33 // load point, and injecting them when ready. | 32 // load point, and injecting them when ready. |
| 34 class ScriptInjectionManager : public UserScriptSetManager::Observer { | 33 class ScriptInjectionManager : public UserScriptSetManager::Observer { |
| 35 public: | 34 public: |
| 36 ScriptInjectionManager(const ExtensionSet* extensions, | 35 ScriptInjectionManager(UserScriptSetManager* user_script_set_manager); |
|
Devlin
2015/08/18 15:40:55
explicit
annekao
2015/08/18 17:43:31
Done.
| |
| 37 UserScriptSetManager* user_script_set_manager); | |
| 38 virtual ~ScriptInjectionManager(); | 36 virtual ~ScriptInjectionManager(); |
| 39 | 37 |
| 40 // Notifies that a new render view has been created. | 38 // Notifies that a new render view has been created. |
| 41 void OnRenderFrameCreated(content::RenderFrame* render_frame); | 39 void OnRenderFrameCreated(content::RenderFrame* render_frame); |
| 42 | 40 |
| 43 // Removes pending injections of the unloaded extension. | 41 // Removes pending injections of the unloaded extension. |
| 44 void OnExtensionUnloaded(const std::string& extension_id); | 42 void OnExtensionUnloaded(const std::string& extension_id); |
| 45 | 43 |
| 46 private: | 44 private: |
| 47 // A RenderFrameObserver implementation which watches the various render | 45 // A RenderFrameObserver implementation which watches the various render |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 // Handle the ExecuteDeclarativeScript extension message. | 83 // Handle the ExecuteDeclarativeScript extension message. |
| 86 void HandleExecuteDeclarativeScript(content::RenderFrame* web_frame, | 84 void HandleExecuteDeclarativeScript(content::RenderFrame* web_frame, |
| 87 int tab_id, | 85 int tab_id, |
| 88 const ExtensionId& extension_id, | 86 const ExtensionId& extension_id, |
| 89 int script_id, | 87 int script_id, |
| 90 const GURL& url); | 88 const GURL& url); |
| 91 | 89 |
| 92 // Handle the GrantInjectionPermission extension message. | 90 // Handle the GrantInjectionPermission extension message. |
| 93 void HandlePermitScriptInjection(int64 request_id); | 91 void HandlePermitScriptInjection(int64 request_id); |
| 94 | 92 |
| 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. The | 93 // The map of active web frames to their corresponding statuses. The |
| 99 // RunLocation of the frame corresponds to the last location that has ran. | 94 // RunLocation of the frame corresponds to the last location that has ran. |
| 100 FrameStatusMap frame_statuses_; | 95 FrameStatusMap frame_statuses_; |
| 101 | 96 |
| 102 // The frames currently being injected into, so long as that frame is valid. | 97 // The frames currently being injected into, so long as that frame is valid. |
| 103 std::set<content::RenderFrame*> active_injection_frames_; | 98 std::set<content::RenderFrame*> active_injection_frames_; |
| 104 | 99 |
| 105 // The collection of RFOHelpers. | 100 // The collection of RFOHelpers. |
| 106 ScopedVector<RFOHelper> rfo_helpers_; | 101 ScopedVector<RFOHelper> rfo_helpers_; |
| 107 | 102 |
| 108 // The set of UserScripts associated with extensions. Owned by the Dispatcher. | 103 // The set of UserScripts associated with extensions. Owned by the Dispatcher. |
| 109 UserScriptSetManager* user_script_set_manager_; | 104 UserScriptSetManager* user_script_set_manager_; |
| 110 | 105 |
| 111 // Pending injections which are waiting for either the proper run location or | 106 // Pending injections which are waiting for either the proper run location or |
| 112 // user consent. | 107 // user consent. |
| 113 ScopedVector<ScriptInjection> pending_injections_; | 108 ScopedVector<ScriptInjection> pending_injections_; |
| 114 | 109 |
| 115 // Running injections which are waiting for async callbacks from blink. | 110 // Running injections which are waiting for async callbacks from blink. |
| 116 ScopedVector<ScriptInjection> running_injections_; | 111 ScopedVector<ScriptInjection> running_injections_; |
| 117 | 112 |
| 118 ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer> | 113 ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer> |
| 119 user_script_set_manager_observer_; | 114 user_script_set_manager_observer_; |
| 120 | 115 |
| 121 DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager); | 116 DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager); |
| 122 }; | 117 }; |
| 123 | 118 |
| 124 } // namespace extensions | 119 } // namespace extensions |
| 125 | 120 |
| 126 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ | 121 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ |
| OLD | NEW |