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 #include "extensions/renderer/script_injection.h" | 5 #include "extensions/renderer/script_injection.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 ScriptsRunInfo* scripts_run_info) { | 212 ScriptsRunInfo* scripts_run_info) { |
213 DCHECK(injection_host_); | 213 DCHECK(injection_host_); |
214 DCHECK(scripts_run_info); | 214 DCHECK(scripts_run_info); |
215 DCHECK(!complete_); | 215 DCHECK(!complete_); |
216 | 216 |
217 bool should_inject_js = injector_->ShouldInjectJs(run_location_); | 217 bool should_inject_js = injector_->ShouldInjectJs(run_location_); |
218 bool should_inject_css = injector_->ShouldInjectCss(run_location_); | 218 bool should_inject_css = injector_->ShouldInjectCss(run_location_); |
219 DCHECK(should_inject_js || should_inject_css); | 219 DCHECK(should_inject_js || should_inject_css); |
220 | 220 |
221 if (should_inject_js) | 221 if (should_inject_js) |
222 InjectJs(); | 222 InjectJs(scripts_run_info); |
223 if (should_inject_css) | 223 if (should_inject_css) |
224 InjectCss(); | 224 InjectCss(scripts_run_info); |
225 | 225 |
226 complete_ = did_inject_js_ || !should_inject_js; | 226 complete_ = did_inject_js_ || !should_inject_js; |
227 | 227 |
228 injector_->GetRunInfo(scripts_run_info, run_location_); | 228 injector_->GetRunInfo(scripts_run_info, run_location_); |
229 | 229 |
230 if (complete_) { | 230 if (complete_) { |
231 injector_->OnInjectionComplete(std::move(execution_result_), run_location_, | 231 injector_->OnInjectionComplete(std::move(execution_result_), run_location_, |
232 render_frame_); | 232 render_frame_); |
233 } else { | 233 } else { |
234 ++scripts_run_info->num_blocking_js; | 234 ++scripts_run_info->num_blocking_js; |
235 } | 235 } |
236 | 236 |
237 return complete_ ? INJECTION_FINISHED : INJECTION_BLOCKED; | 237 return complete_ ? INJECTION_FINISHED : INJECTION_BLOCKED; |
238 } | 238 } |
239 | 239 |
240 void ScriptInjection::InjectJs() { | 240 void ScriptInjection::InjectJs(ScriptsRunInfo* scripts_run_info) { |
241 DCHECK(!did_inject_js_); | 241 DCHECK(!did_inject_js_); |
242 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); | 242 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); |
243 std::vector<blink::WebScriptSource> sources = | 243 std::vector<blink::WebScriptSource> sources = |
244 injector_->GetJsSources(run_location_); | 244 injector_->GetJsSources(run_location_, scripts_run_info); |
245 bool in_main_world = injector_->ShouldExecuteInMainWorld(); | 245 bool in_main_world = injector_->ShouldExecuteInMainWorld(); |
246 int world_id = in_main_world | 246 int world_id = in_main_world |
247 ? DOMActivityLogger::kMainWorldId | 247 ? DOMActivityLogger::kMainWorldId |
248 : GetIsolatedWorldIdForInstance(injection_host_.get(), | 248 : GetIsolatedWorldIdForInstance(injection_host_.get(), |
249 web_frame); | 249 web_frame); |
250 bool is_user_gesture = injector_->IsUserGesture(); | 250 bool is_user_gesture = injector_->IsUserGesture(); |
251 | 251 |
252 std::unique_ptr<blink::WebScriptExecutionCallback> callback( | 252 std::unique_ptr<blink::WebScriptExecutionCallback> callback( |
253 new ScriptInjectionCallback( | 253 new ScriptInjectionCallback( |
254 base::Bind(&ScriptInjection::OnJsInjectionCompleted, | 254 base::Bind(&ScriptInjection::OnJsInjectionCompleted, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // If |async_completion_callback_| is set, it means the script finished | 304 // If |async_completion_callback_| is set, it means the script finished |
305 // asynchronously, and we should run it. | 305 // asynchronously, and we should run it. |
306 if (!async_completion_callback_.is_null()) { | 306 if (!async_completion_callback_.is_null()) { |
307 injector_->OnInjectionComplete(std::move(execution_result_), run_location_, | 307 injector_->OnInjectionComplete(std::move(execution_result_), run_location_, |
308 render_frame_); | 308 render_frame_); |
309 // Warning: this object can be destroyed after this line! | 309 // Warning: this object can be destroyed after this line! |
310 async_completion_callback_.Run(this); | 310 async_completion_callback_.Run(this); |
311 } | 311 } |
312 } | 312 } |
313 | 313 |
314 void ScriptInjection::InjectCss() { | 314 void ScriptInjection::InjectCss(ScriptsRunInfo* scripts_run_info) { |
315 std::vector<std::string> css_sources = | 315 std::vector<std::string> css_sources = |
316 injector_->GetCssSources(run_location_); | 316 injector_->GetCssSources(run_location_, scripts_run_info); |
317 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); | 317 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); |
318 for (const std::string& css : css_sources) | 318 for (const std::string& css : css_sources) |
319 web_frame->document().insertStyleSheet(blink::WebString::fromUTF8(css)); | 319 web_frame->document().insertStyleSheet(blink::WebString::fromUTF8(css)); |
320 } | 320 } |
321 | 321 |
322 } // namespace extensions | 322 } // namespace extensions |
OLD | NEW |