| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/timer/elapsed_timer.h" | 14 #include "base/timer/elapsed_timer.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "content/public/child/v8_value_converter.h" | 16 #include "content/public/child/v8_value_converter.h" |
| 16 #include "content/public/renderer/render_frame.h" | 17 #include "content/public/renderer/render_frame.h" |
| 17 #include "extensions/common/extension_messages.h" | 18 #include "extensions/common/extension_messages.h" |
| 18 #include "extensions/common/feature_switch.h" | 19 #include "extensions/common/feature_switch.h" |
| 19 #include "extensions/common/host_id.h" | 20 #include "extensions/common/host_id.h" |
| 20 #include "extensions/renderer/dom_activity_logger.h" | 21 #include "extensions/renderer/dom_activity_logger.h" |
| 21 #include "extensions/renderer/extension_frame_helper.h" | 22 #include "extensions/renderer/extension_frame_helper.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 content::V8ValueConverter::create()); | 352 content::V8ValueConverter::create()); |
| 352 // It's safe to always use the main world context when converting | 353 // It's safe to always use the main world context when converting |
| 353 // here. V8ValueConverterImpl shouldn't actually care about the | 354 // here. V8ValueConverterImpl shouldn't actually care about the |
| 354 // context scope, and it switches to v8::Object's creation context | 355 // context scope, and it switches to v8::Object's creation context |
| 355 // when encountered. | 356 // when encountered. |
| 356 v8::Local<v8::Context> context = | 357 v8::Local<v8::Context> context = |
| 357 render_frame_->GetWebFrame()->mainWorldScriptContext(); | 358 render_frame_->GetWebFrame()->mainWorldScriptContext(); |
| 358 execution_result_ = v8_converter->FromV8Value(results[0], context); | 359 execution_result_ = v8_converter->FromV8Value(results[0], context); |
| 359 } | 360 } |
| 360 if (!execution_result_.get()) | 361 if (!execution_result_.get()) |
| 361 execution_result_ = base::Value::CreateNullValue(); | 362 execution_result_ = base::MakeUnique<base::Value>(); |
| 362 } | 363 } |
| 363 did_inject_js_ = true; | 364 did_inject_js_ = true; |
| 364 | 365 |
| 365 // If |async_completion_callback_| is set, it means the script finished | 366 // If |async_completion_callback_| is set, it means the script finished |
| 366 // asynchronously, and we should run it. | 367 // asynchronously, and we should run it. |
| 367 if (!async_completion_callback_.is_null()) { | 368 if (!async_completion_callback_.is_null()) { |
| 368 complete_ = true; | 369 complete_ = true; |
| 369 injector_->OnInjectionComplete(std::move(execution_result_), run_location_, | 370 injector_->OnInjectionComplete(std::move(execution_result_), run_location_, |
| 370 render_frame_); | 371 render_frame_); |
| 371 // Warning: this object can be destroyed after this line! | 372 // Warning: this object can be destroyed after this line! |
| 372 async_completion_callback_.Run(this); | 373 async_completion_callback_.Run(this); |
| 373 } | 374 } |
| 374 } | 375 } |
| 375 | 376 |
| 376 void ScriptInjection::InjectCss(std::set<std::string>* injected_stylesheets, | 377 void ScriptInjection::InjectCss(std::set<std::string>* injected_stylesheets, |
| 377 size_t* num_injected_stylesheets) { | 378 size_t* num_injected_stylesheets) { |
| 378 std::vector<blink::WebString> css_sources = injector_->GetCssSources( | 379 std::vector<blink::WebString> css_sources = injector_->GetCssSources( |
| 379 run_location_, injected_stylesheets, num_injected_stylesheets); | 380 run_location_, injected_stylesheets, num_injected_stylesheets); |
| 380 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); | 381 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); |
| 381 for (const blink::WebString& css : css_sources) | 382 for (const blink::WebString& css : css_sources) |
| 382 web_frame->document().insertStyleSheet(css); | 383 web_frame->document().insertStyleSheet(css); |
| 383 } | 384 } |
| 384 | 385 |
| 385 } // namespace extensions | 386 } // namespace extensions |
| OLD | NEW |