| 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 explicit ScriptInjectionManager( |
| 37 UserScriptSetManager* user_script_set_manager); | 36 UserScriptSetManager* user_script_set_manager); |
| 38 virtual ~ScriptInjectionManager(); | 37 virtual ~ScriptInjectionManager(); |
| 39 | 38 |
| 40 // Notifies that a new render view has been created. | 39 // Notifies that a new render view has been created. |
| 41 void OnRenderFrameCreated(content::RenderFrame* render_frame); | 40 void OnRenderFrameCreated(content::RenderFrame* render_frame); |
| 42 | 41 |
| 43 // Removes pending injections of the unloaded extension. | 42 // Removes pending injections of the unloaded extension. |
| 44 void OnExtensionUnloaded(const std::string& extension_id); | 43 void OnExtensionUnloaded(const std::string& extension_id); |
| 45 | 44 |
| 46 private: | 45 private: |
| 47 // A RenderFrameObserver implementation which watches the various render | 46 // 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. | 84 // Handle the ExecuteDeclarativeScript extension message. |
| 86 void HandleExecuteDeclarativeScript(content::RenderFrame* web_frame, | 85 void HandleExecuteDeclarativeScript(content::RenderFrame* web_frame, |
| 87 int tab_id, | 86 int tab_id, |
| 88 const ExtensionId& extension_id, | 87 const ExtensionId& extension_id, |
| 89 int script_id, | 88 int script_id, |
| 90 const GURL& url); | 89 const GURL& url); |
| 91 | 90 |
| 92 // Handle the GrantInjectionPermission extension message. | 91 // Handle the GrantInjectionPermission extension message. |
| 93 void HandlePermitScriptInjection(int64 request_id); | 92 void HandlePermitScriptInjection(int64 request_id); |
| 94 | 93 |
| 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 | 94 // The map of active web frames to their corresponding statuses. The |
| 99 // RunLocation of the frame corresponds to the last location that has ran. | 95 // RunLocation of the frame corresponds to the last location that has ran. |
| 100 FrameStatusMap frame_statuses_; | 96 FrameStatusMap frame_statuses_; |
| 101 | 97 |
| 102 // The frames currently being injected into, so long as that frame is valid. | 98 // The frames currently being injected into, so long as that frame is valid. |
| 103 std::set<content::RenderFrame*> active_injection_frames_; | 99 std::set<content::RenderFrame*> active_injection_frames_; |
| 104 | 100 |
| 105 // The collection of RFOHelpers. | 101 // The collection of RFOHelpers. |
| 106 ScopedVector<RFOHelper> rfo_helpers_; | 102 ScopedVector<RFOHelper> rfo_helpers_; |
| 107 | 103 |
| 108 // The set of UserScripts associated with extensions. Owned by the Dispatcher. | 104 // The set of UserScripts associated with extensions. Owned by the Dispatcher. |
| 109 UserScriptSetManager* user_script_set_manager_; | 105 UserScriptSetManager* user_script_set_manager_; |
| 110 | 106 |
| 111 // Pending injections which are waiting for either the proper run location or | 107 // Pending injections which are waiting for either the proper run location or |
| 112 // user consent. | 108 // user consent. |
| 113 ScopedVector<ScriptInjection> pending_injections_; | 109 ScopedVector<ScriptInjection> pending_injections_; |
| 114 | 110 |
| 115 // Running injections which are waiting for async callbacks from blink. | 111 // Running injections which are waiting for async callbacks from blink. |
| 116 ScopedVector<ScriptInjection> running_injections_; | 112 ScopedVector<ScriptInjection> running_injections_; |
| 117 | 113 |
| 118 ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer> | 114 ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer> |
| 119 user_script_set_manager_observer_; | 115 user_script_set_manager_observer_; |
| 120 | 116 |
| 121 DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager); | 117 DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager); |
| 122 }; | 118 }; |
| 123 | 119 |
| 124 } // namespace extensions | 120 } // namespace extensions |
| 125 | 121 |
| 126 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ | 122 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_ |
| OLD | NEW |