| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 EXTENSION_GROUP_CONTENT_SCRIPTS, | 281 EXTENSION_GROUP_CONTENT_SCRIPTS, |
| 282 is_user_gesture, | 282 is_user_gesture, |
| 283 callback.release()); | 283 callback.release()); |
| 284 } | 284 } |
| 285 | 285 |
| 286 if (injection_host_->id().type() == HostID::EXTENSIONS) | 286 if (injection_host_->id().type() == HostID::EXTENSIONS) |
| 287 UMA_HISTOGRAM_TIMES("Extensions.InjectScriptTime", exec_timer.Elapsed()); | 287 UMA_HISTOGRAM_TIMES("Extensions.InjectScriptTime", exec_timer.Elapsed()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void ScriptInjection::OnJsInjectionCompleted( | 290 void ScriptInjection::OnJsInjectionCompleted( |
| 291 const blink::WebVector<v8::Local<v8::Value> >& results) { | 291 const std::vector<v8::Local<v8::Value>>& results) { |
| 292 DCHECK(!did_inject_js_); | 292 DCHECK(!did_inject_js_); |
| 293 | 293 |
| 294 bool expects_results = injector_->ExpectsResults(); | 294 bool expects_results = injector_->ExpectsResults(); |
| 295 if (expects_results) { | 295 if (expects_results) { |
| 296 if (!results.isEmpty() && !results[0].IsEmpty()) { | 296 if (!results.empty() && !results[0].IsEmpty()) { |
| 297 // Right now, we only support returning single results (per frame). | 297 // Right now, we only support returning single results (per frame). |
| 298 std::unique_ptr<content::V8ValueConverter> v8_converter( | 298 std::unique_ptr<content::V8ValueConverter> v8_converter( |
| 299 content::V8ValueConverter::create()); | 299 content::V8ValueConverter::create()); |
| 300 // It's safe to always use the main world context when converting | 300 // It's safe to always use the main world context when converting |
| 301 // here. V8ValueConverterImpl shouldn't actually care about the | 301 // here. V8ValueConverterImpl shouldn't actually care about the |
| 302 // context scope, and it switches to v8::Object's creation context | 302 // context scope, and it switches to v8::Object's creation context |
| 303 // when encountered. | 303 // when encountered. |
| 304 v8::Local<v8::Context> context = | 304 v8::Local<v8::Context> context = |
| 305 render_frame_->GetWebFrame()->mainWorldScriptContext(); | 305 render_frame_->GetWebFrame()->mainWorldScriptContext(); |
| 306 execution_result_ = v8_converter->FromV8Value(results[0], context); | 306 execution_result_ = v8_converter->FromV8Value(results[0], context); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 323 void ScriptInjection::InjectCss(std::set<std::string>* injected_stylesheets, | 323 void ScriptInjection::InjectCss(std::set<std::string>* injected_stylesheets, |
| 324 size_t* num_injected_stylesheets) { | 324 size_t* num_injected_stylesheets) { |
| 325 std::vector<blink::WebString> css_sources = injector_->GetCssSources( | 325 std::vector<blink::WebString> css_sources = injector_->GetCssSources( |
| 326 run_location_, injected_stylesheets, num_injected_stylesheets); | 326 run_location_, injected_stylesheets, num_injected_stylesheets); |
| 327 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); | 327 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); |
| 328 for (const blink::WebString& css : css_sources) | 328 for (const blink::WebString& css : css_sources) |
| 329 web_frame->document().insertStyleSheet(css); | 329 web_frame->document().insertStyleSheet(css); |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace extensions | 332 } // namespace extensions |
| OLD | NEW |