| 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_H_ | 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ |
| 6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ | 6 #define EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> |
| 11 |
| 10 #include "base/callback.h" | 12 #include "base/callback.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "extensions/common/user_script.h" | 15 #include "extensions/common/user_script.h" |
| 15 #include "extensions/renderer/injection_host.h" | 16 #include "extensions/renderer/injection_host.h" |
| 16 #include "extensions/renderer/script_injector.h" | 17 #include "extensions/renderer/script_injector.h" |
| 17 | 18 |
| 18 struct HostID; | 19 struct HostID; |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 template<typename T> class WebVector; | 22 template<typename T> class WebVector; |
| 22 } | 23 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 using CompletionCallback = base::Callback<void(ScriptInjection*)>; | 47 using CompletionCallback = base::Callback<void(ScriptInjection*)>; |
| 47 | 48 |
| 48 // Return the id of the injection host associated with the given world. | 49 // Return the id of the injection host associated with the given world. |
| 49 static std::string GetHostIdForIsolatedWorld(int world_id); | 50 static std::string GetHostIdForIsolatedWorld(int world_id); |
| 50 | 51 |
| 51 // Remove the isolated world associated with the given injection host. | 52 // Remove the isolated world associated with the given injection host. |
| 52 static void RemoveIsolatedWorld(const std::string& host_id); | 53 static void RemoveIsolatedWorld(const std::string& host_id); |
| 53 | 54 |
| 54 ScriptInjection(scoped_ptr<ScriptInjector> injector, | 55 ScriptInjection(std::unique_ptr<ScriptInjector> injector, |
| 55 content::RenderFrame* render_frame, | 56 content::RenderFrame* render_frame, |
| 56 scoped_ptr<const InjectionHost> injection_host, | 57 std::unique_ptr<const InjectionHost> injection_host, |
| 57 UserScript::RunLocation run_location); | 58 UserScript::RunLocation run_location); |
| 58 ~ScriptInjection(); | 59 ~ScriptInjection(); |
| 59 | 60 |
| 60 // Try to inject the script at the |current_location|. This returns | 61 // Try to inject the script at the |current_location|. This returns |
| 61 // INJECTION_FINISHED if injection has injected or will never inject, returns | 62 // INJECTION_FINISHED if injection has injected or will never inject, returns |
| 62 // INJECTION_BLOCKED if injection is running asynchronously and has not | 63 // INJECTION_BLOCKED if injection is running asynchronously and has not |
| 63 // finished yet, returns INJECTION_WAITING if injections is delayed (either | 64 // finished yet, returns INJECTION_WAITING if injections is delayed (either |
| 64 // for permission purposes or because |current_location| is not the designated | 65 // for permission purposes or because |current_location| is not the designated |
| 65 // |run_location_|). | 66 // |run_location_|). |
| 66 // If INJECTION_BLOCKED is returned, |async_completion_callback| will be | 67 // If INJECTION_BLOCKED is returned, |async_completion_callback| will be |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 void OnJsInjectionCompleted( | 103 void OnJsInjectionCompleted( |
| 103 const blink::WebVector<v8::Local<v8::Value> >& results); | 104 const blink::WebVector<v8::Local<v8::Value> >& results); |
| 104 | 105 |
| 105 // Inject any CSS source into the frame for the injection. | 106 // Inject any CSS source into the frame for the injection. |
| 106 void InjectCss(); | 107 void InjectCss(); |
| 107 | 108 |
| 108 // Notify that we will not inject, and mark it as acknowledged. | 109 // Notify that we will not inject, and mark it as acknowledged. |
| 109 void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason); | 110 void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason); |
| 110 | 111 |
| 111 // The injector for this injection. | 112 // The injector for this injection. |
| 112 scoped_ptr<ScriptInjector> injector_; | 113 std::unique_ptr<ScriptInjector> injector_; |
| 113 | 114 |
| 114 // The RenderFrame into which this should inject the script. | 115 // The RenderFrame into which this should inject the script. |
| 115 content::RenderFrame* render_frame_; | 116 content::RenderFrame* render_frame_; |
| 116 | 117 |
| 117 // The associated injection host. | 118 // The associated injection host. |
| 118 scoped_ptr<const InjectionHost> injection_host_; | 119 std::unique_ptr<const InjectionHost> injection_host_; |
| 119 | 120 |
| 120 // The location in the document load at which we inject the script. | 121 // The location in the document load at which we inject the script. |
| 121 UserScript::RunLocation run_location_; | 122 UserScript::RunLocation run_location_; |
| 122 | 123 |
| 123 // This injection's request id. This will be -1 unless the injection is | 124 // This injection's request id. This will be -1 unless the injection is |
| 124 // currently waiting on permission. | 125 // currently waiting on permission. |
| 125 int64_t request_id_; | 126 int64_t request_id_; |
| 126 | 127 |
| 127 // Whether or not the injection is complete, either via injecting the script | 128 // Whether or not the injection is complete, either via injecting the script |
| 128 // or because it will never complete. | 129 // or because it will never complete. |
| 129 bool complete_; | 130 bool complete_; |
| 130 | 131 |
| 131 // Whether or not the injection successfully injected JS. | 132 // Whether or not the injection successfully injected JS. |
| 132 bool did_inject_js_; | 133 bool did_inject_js_; |
| 133 | 134 |
| 134 // Results storage. | 135 // Results storage. |
| 135 scoped_ptr<base::Value> execution_result_; | 136 std::unique_ptr<base::Value> execution_result_; |
| 136 | 137 |
| 137 // The callback to run upon completing asynchronously. | 138 // The callback to run upon completing asynchronously. |
| 138 CompletionCallback async_completion_callback_; | 139 CompletionCallback async_completion_callback_; |
| 139 | 140 |
| 140 // A helper class to hold the render frame and watch for its deletion. | 141 // A helper class to hold the render frame and watch for its deletion. |
| 141 scoped_ptr<FrameWatcher> frame_watcher_; | 142 std::unique_ptr<FrameWatcher> frame_watcher_; |
| 142 | 143 |
| 143 base::WeakPtrFactory<ScriptInjection> weak_ptr_factory_; | 144 base::WeakPtrFactory<ScriptInjection> weak_ptr_factory_; |
| 144 | 145 |
| 145 DISALLOW_COPY_AND_ASSIGN(ScriptInjection); | 146 DISALLOW_COPY_AND_ASSIGN(ScriptInjection); |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 } // namespace extensions | 149 } // namespace extensions |
| 149 | 150 |
| 150 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ | 151 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ |
| OLD | NEW |