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 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 298 |
299 void ScriptInjection::OnJsInjectionCompleted( | 299 void ScriptInjection::OnJsInjectionCompleted( |
300 blink::WebLocalFrame* frame, | 300 blink::WebLocalFrame* frame, |
301 const blink::WebVector<v8::Local<v8::Value> >& results) { | 301 const blink::WebVector<v8::Local<v8::Value> >& results) { |
302 DCHECK(running_frames_ > 0); | 302 DCHECK(running_frames_ > 0); |
303 --running_frames_; | 303 --running_frames_; |
304 | 304 |
305 bool expects_results = injector_->ExpectsResults(); | 305 bool expects_results = injector_->ExpectsResults(); |
306 if (expects_results) { | 306 if (expects_results) { |
307 scoped_ptr<base::Value> result; | 307 scoped_ptr<base::Value> result; |
308 if (!results.isEmpty()) { | 308 if (!results.isEmpty() && !results[0].IsEmpty()) { |
309 // Right now, we only support returning single results (per frame). | 309 // Right now, we only support returning single results (per frame). |
310 scoped_ptr<content::V8ValueConverter> v8_converter( | 310 scoped_ptr<content::V8ValueConverter> v8_converter( |
311 content::V8ValueConverter::create()); | 311 content::V8ValueConverter::create()); |
312 // It's safe to always use the main world context when converting | 312 // It's safe to always use the main world context when converting |
313 // here. V8ValueConverterImpl shouldn't actually care about the | 313 // here. V8ValueConverterImpl shouldn't actually care about the |
314 // context scope, and it switches to v8::Object's creation context | 314 // context scope, and it switches to v8::Object's creation context |
315 // when encountered. | 315 // when encountered. |
316 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 316 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
317 result.reset(v8_converter->FromV8Value(results[0], context)); | 317 result.reset(v8_converter->FromV8Value(results[0], context)); |
318 } | 318 } |
(...skipping 24 matching lines...) Expand all Loading... |
343 std::vector<std::string> css_sources = | 343 std::vector<std::string> css_sources = |
344 injector_->GetCssSources(run_location_); | 344 injector_->GetCssSources(run_location_); |
345 for (std::vector<std::string>::const_iterator iter = css_sources.begin(); | 345 for (std::vector<std::string>::const_iterator iter = css_sources.begin(); |
346 iter != css_sources.end(); | 346 iter != css_sources.end(); |
347 ++iter) { | 347 ++iter) { |
348 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter)); | 348 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter)); |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 } // namespace extensions | 352 } // namespace extensions |
OLD | NEW |