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

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

Issue 2014323002: Use std::unique_ptr<base::Value> in V8ValueConverter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android fixes Created 4 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/activity_log_converter_strategy.cc ('k') | no next file » | 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (!results.isEmpty() && !results[0].IsEmpty()) { 285 if (!results.isEmpty() && !results[0].IsEmpty()) {
286 // Right now, we only support returning single results (per frame). 286 // Right now, we only support returning single results (per frame).
287 std::unique_ptr<content::V8ValueConverter> v8_converter( 287 std::unique_ptr<content::V8ValueConverter> v8_converter(
288 content::V8ValueConverter::create()); 288 content::V8ValueConverter::create());
289 // It's safe to always use the main world context when converting 289 // It's safe to always use the main world context when converting
290 // here. V8ValueConverterImpl shouldn't actually care about the 290 // here. V8ValueConverterImpl shouldn't actually care about the
291 // context scope, and it switches to v8::Object's creation context 291 // context scope, and it switches to v8::Object's creation context
292 // when encountered. 292 // when encountered.
293 v8::Local<v8::Context> context = 293 v8::Local<v8::Context> context =
294 render_frame_->GetWebFrame()->mainWorldScriptContext(); 294 render_frame_->GetWebFrame()->mainWorldScriptContext();
295 execution_result_.reset(v8_converter->FromV8Value(results[0], context)); 295 execution_result_ = v8_converter->FromV8Value(results[0], context);
296 } 296 }
297 if (!execution_result_.get()) 297 if (!execution_result_.get())
298 execution_result_ = base::Value::CreateNullValue(); 298 execution_result_ = base::Value::CreateNullValue();
299 } 299 }
300 did_inject_js_ = true; 300 did_inject_js_ = true;
301 301
302 // If |async_completion_callback_| is set, it means the script finished 302 // If |async_completion_callback_| is set, it means the script finished
303 // asynchronously, and we should run it. 303 // asynchronously, and we should run it.
304 if (!async_completion_callback_.is_null()) { 304 if (!async_completion_callback_.is_null()) {
305 injector_->OnInjectionComplete(std::move(execution_result_), run_location_, 305 injector_->OnInjectionComplete(std::move(execution_result_), run_location_,
306 render_frame_); 306 render_frame_);
307 // Warning: this object can be destroyed after this line! 307 // Warning: this object can be destroyed after this line!
308 async_completion_callback_.Run(this); 308 async_completion_callback_.Run(this);
309 } 309 }
310 } 310 }
311 311
312 void ScriptInjection::InjectCss() { 312 void ScriptInjection::InjectCss() {
313 std::vector<std::string> css_sources = 313 std::vector<std::string> css_sources =
314 injector_->GetCssSources(run_location_); 314 injector_->GetCssSources(run_location_);
315 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); 315 blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame();
316 for (const std::string& css : css_sources) 316 for (const std::string& css : css_sources)
317 web_frame->document().insertStyleSheet(blink::WebString::fromUTF8(css)); 317 web_frame->document().insertStyleSheet(blink::WebString::fromUTF8(css));
318 } 318 }
319 319
320 } // namespace extensions 320 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/activity_log_converter_strategy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698