Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: extensions/renderer/script_injection.cc

Issue 2931393003: [Content] Update V8ValueConverter::create to return a std::unique_ptr (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/renderer/script_context.cc ('k') | extensions/renderer/send_request_natives.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 break; 345 break;
346 default: 346 default:
347 break; 347 break;
348 } 348 }
349 } 349 }
350 350
351 bool expects_results = injector_->ExpectsResults(); 351 bool expects_results = injector_->ExpectsResults();
352 if (expects_results) { 352 if (expects_results) {
353 if (!results.empty() && !results[0].IsEmpty()) { 353 if (!results.empty() && !results[0].IsEmpty()) {
354 // Right now, we only support returning single results (per frame). 354 // Right now, we only support returning single results (per frame).
355 std::unique_ptr<content::V8ValueConverter> v8_converter(
356 content::V8ValueConverter::create());
357 // It's safe to always use the main world context when converting 355 // It's safe to always use the main world context when converting
358 // here. V8ValueConverterImpl shouldn't actually care about the 356 // here. V8ValueConverterImpl shouldn't actually care about the
359 // context scope, and it switches to v8::Object's creation context 357 // context scope, and it switches to v8::Object's creation context
360 // when encountered. 358 // when encountered.
361 v8::Local<v8::Context> context = 359 v8::Local<v8::Context> context =
362 render_frame_->GetWebFrame()->MainWorldScriptContext(); 360 render_frame_->GetWebFrame()->MainWorldScriptContext();
363 execution_result_ = v8_converter->FromV8Value(results[0], context); 361 execution_result_ =
362 content::V8ValueConverter::Create()->FromV8Value(results[0], context);
364 } 363 }
365 if (!execution_result_.get()) 364 if (!execution_result_.get())
366 execution_result_ = base::MakeUnique<base::Value>(); 365 execution_result_ = base::MakeUnique<base::Value>();
367 } 366 }
368 did_inject_js_ = true; 367 did_inject_js_ = true;
369 368
370 // If |async_completion_callback_| is set, it means the script finished 369 // If |async_completion_callback_| is set, it means the script finished
371 // asynchronously, and we should run it. 370 // asynchronously, and we should run it.
372 if (!async_completion_callback_.is_null()) { 371 if (!async_completion_callback_.is_null()) {
373 complete_ = true; 372 complete_ = true;
374 injector_->OnInjectionComplete(std::move(execution_result_), run_location_, 373 injector_->OnInjectionComplete(std::move(execution_result_), run_location_,
375 render_frame_); 374 render_frame_);
376 // Warning: this object can be destroyed after this line! 375 // Warning: this object can be destroyed after this line!
377 async_completion_callback_.Run(this); 376 async_completion_callback_.Run(this);
378 } 377 }
379 } 378 }
380 379
381 void ScriptInjection::InjectCss(std::set<std::string>* injected_stylesheets, 380 void ScriptInjection::InjectCss(std::set<std::string>* injected_stylesheets,
382 size_t* num_injected_stylesheets) { 381 size_t* num_injected_stylesheets) {
383 std::vector<blink::WebString> css_sources = injector_->GetCssSources( 382 std::vector<blink::WebString> css_sources = injector_->GetCssSources(
384 run_location_, injected_stylesheets, num_injected_stylesheets); 383 run_location_, injected_stylesheets, num_injected_stylesheets);
385 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); 384 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame();
386 for (const blink::WebString& css : css_sources) 385 for (const blink::WebString& css : css_sources)
387 web_frame->GetDocument().InsertStyleSheet(css); 386 web_frame->GetDocument().InsertStyleSheet(css);
388 } 387 }
389 388
390 } // namespace extensions 389 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context.cc ('k') | extensions/renderer/send_request_natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698