| 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> | 10 #include <memory> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 namespace extensions { | 34 namespace extensions { |
| 35 struct ScriptsRunInfo; | 35 struct ScriptsRunInfo; |
| 36 | 36 |
| 37 // A script wrapper which is aware of whether or not it is allowed to execute, | 37 // A script wrapper which is aware of whether or not it is allowed to execute, |
| 38 // and contains the implementation to do so. | 38 // and contains the implementation to do so. |
| 39 class ScriptInjection { | 39 class ScriptInjection { |
| 40 public: | 40 public: |
| 41 enum InjectionResult { | 41 enum InjectionResult { |
| 42 INJECTION_FINISHED, | 42 INJECTION_FINISHED, |
| 43 INJECTION_BLOCKED, | 43 INJECTION_BLOCKED, |
| 44 INJECTION_CANCELED, |
| 44 INJECTION_WAITING | 45 INJECTION_WAITING |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 using CompletionCallback = base::Callback<void(ScriptInjection*)>; | 48 using CompletionCallback = base::Callback<void(ScriptInjection*)>; |
| 48 | 49 |
| 49 // Return the id of the injection host associated with the given world. | 50 // Return the id of the injection host associated with the given world. |
| 50 static std::string GetHostIdForIsolatedWorld(int world_id); | 51 static std::string GetHostIdForIsolatedWorld(int world_id); |
| 51 | 52 |
| 52 // Remove the isolated world associated with the given injection host. | 53 // Remove the isolated world associated with the given injection host. |
| 53 static void RemoveIsolatedWorld(const std::string& host_id); | 54 static void RemoveIsolatedWorld(const std::string& host_id); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 int64_t request_id() const { return request_id_; } | 89 int64_t request_id() const { return request_id_; } |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 class FrameWatcher; | 92 class FrameWatcher; |
| 92 | 93 |
| 93 // Sends a message to the browser to request permission to inject. | 94 // Sends a message to the browser to request permission to inject. |
| 94 void RequestPermissionFromBrowser(); | 95 void RequestPermissionFromBrowser(); |
| 95 | 96 |
| 96 // Injects the script. Returns INJECTION_FINISHED if injection has finished, | 97 // Injects the script. Returns INJECTION_FINISHED if injection has finished, |
| 97 // otherwise INJECTION_BLOCKED. | 98 // otherwise INJECTION_BLOCKED. |
| 99 // The caller must not destruct this ScriptInjection instance during the call. |
| 100 // Similarly, this instance must not delete itself during the call. |
| 98 InjectionResult Inject(ScriptsRunInfo* scripts_run_info); | 101 InjectionResult Inject(ScriptsRunInfo* scripts_run_info); |
| 99 | 102 |
| 100 // Inject any JS scripts into the frame for the injection. | 103 // Inject any JS scripts into the frame for the injection. |
| 101 void InjectJs(); | 104 void InjectJs(); |
| 102 | 105 |
| 103 // Called when JS injection for the given frame has been completed. | 106 // Called when JS injection for the given frame has been completed. |
| 104 void OnJsInjectionCompleted( | 107 void OnJsInjectionCompleted( |
| 105 const blink::WebVector<v8::Local<v8::Value> >& results); | 108 const blink::WebVector<v8::Local<v8::Value> >& results); |
| 106 | 109 |
| 107 // Inject any CSS source into the frame for the injection. | 110 // Inject any CSS source into the frame for the injection. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 std::unique_ptr<FrameWatcher> frame_watcher_; | 149 std::unique_ptr<FrameWatcher> frame_watcher_; |
| 147 | 150 |
| 148 base::WeakPtrFactory<ScriptInjection> weak_ptr_factory_; | 151 base::WeakPtrFactory<ScriptInjection> weak_ptr_factory_; |
| 149 | 152 |
| 150 DISALLOW_COPY_AND_ASSIGN(ScriptInjection); | 153 DISALLOW_COPY_AND_ASSIGN(ScriptInjection); |
| 151 }; | 154 }; |
| 152 | 155 |
| 153 } // namespace extensions | 156 } // namespace extensions |
| 154 | 157 |
| 155 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ | 158 #endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_ |
| OLD | NEW |