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

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

Issue 2931393003: [Content] Update V8ValueConverter::create to return a std::unique_ptr (Closed)
Patch Set: 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
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_context.h" 5 #include "extensions/renderer/script_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 15 matching lines...) Expand all
26 #include "extensions/renderer/v8_helpers.h" 26 #include "extensions/renderer/v8_helpers.h"
27 #include "gin/per_context_data.h" 27 #include "gin/per_context_data.h"
28 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 28 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
29 #include "third_party/WebKit/public/platform/WebURLRequest.h" 29 #include "third_party/WebKit/public/platform/WebURLRequest.h"
30 #include "third_party/WebKit/public/web/WebDataSource.h" 30 #include "third_party/WebKit/public/web/WebDataSource.h"
31 #include "third_party/WebKit/public/web/WebDocument.h" 31 #include "third_party/WebKit/public/web/WebDocument.h"
32 #include "third_party/WebKit/public/web/WebLocalFrame.h" 32 #include "third_party/WebKit/public/web/WebLocalFrame.h"
33 #include "third_party/WebKit/public/web/WebView.h" 33 #include "third_party/WebKit/public/web/WebView.h"
34 #include "v8/include/v8.h" 34 #include "v8/include/v8.h"
35 35
36 using content::V8ValueConverter;
37
38 namespace extensions { 36 namespace extensions {
39 37
40 namespace { 38 namespace {
41 39
42 std::string GetContextTypeDescriptionString(Feature::Context context_type) { 40 std::string GetContextTypeDescriptionString(Feature::Context context_type) {
43 switch (context_type) { 41 switch (context_type) {
44 case Feature::UNSPECIFIED_CONTEXT: 42 case Feature::UNSPECIFIED_CONTEXT:
45 return "UNSPECIFIED"; 43 return "UNSPECIFIED";
46 case Feature::BLESSED_EXTENSION_CONTEXT: 44 case Feature::BLESSED_EXTENSION_CONTEXT:
47 return "BLESSED_EXTENSION"; 45 return "BLESSED_EXTENSION";
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 361 }
364 362
365 void ScriptContext::OnResponseReceived(const std::string& name, 363 void ScriptContext::OnResponseReceived(const std::string& name,
366 int request_id, 364 int request_id,
367 bool success, 365 bool success,
368 const base::ListValue& response, 366 const base::ListValue& response,
369 const std::string& error) { 367 const std::string& error) {
370 DCHECK(thread_checker_.CalledOnValidThread()); 368 DCHECK(thread_checker_.CalledOnValidThread());
371 v8::HandleScope handle_scope(isolate()); 369 v8::HandleScope handle_scope(isolate());
372 370
373 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create());
374 v8::Local<v8::Value> argv[] = { 371 v8::Local<v8::Value> argv[] = {
375 v8::Integer::New(isolate(), request_id), 372 v8::Integer::New(isolate(), request_id),
376 v8::String::NewFromUtf8(isolate(), name.c_str()), 373 v8::String::NewFromUtf8(isolate(), name.c_str()),
377 v8::Boolean::New(isolate(), success), 374 v8::Boolean::New(isolate(), success),
378 converter->ToV8Value(&response, 375 content::V8ValueConverter::Create()->ToV8Value(
379 v8::Local<v8::Context>::New(isolate(), v8_context_)), 376 &response, v8::Local<v8::Context>::New(isolate(), v8_context_)),
380 v8::String::NewFromUtf8(isolate(), error.c_str())}; 377 v8::String::NewFromUtf8(isolate(), error.c_str())};
381 378
382 v8::Local<v8::Value> retval = module_system()->CallModuleMethod( 379 v8::Local<v8::Value> retval = module_system()->CallModuleMethod(
383 "sendRequest", "handleResponse", arraysize(argv), argv); 380 "sendRequest", "handleResponse", arraysize(argv), argv);
384 381
385 // In debug, the js will validate the callback parameters and return a 382 // In debug, the js will validate the callback parameters and return a
386 // string if a validation error has occured. 383 // string if a validation error has occured.
387 DCHECK(retval.IsEmpty() || retval->IsUndefined()) 384 DCHECK(retval.IsEmpty() || retval->IsUndefined())
388 << *v8::String::Utf8Value(retval); 385 << *v8::String::Utf8Value(retval);
389 } 386 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 v8::Local<v8::Value> argv[]) { 524 v8::Local<v8::Value> argv[]) {
528 return context_->CallFunction(function, argc, argv); 525 return context_->CallFunction(function, argc, argv);
529 } 526 }
530 527
531 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 528 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
532 v8::HandleScope handle_scope(context_->isolate()); 529 v8::HandleScope handle_scope(context_->isolate());
533 return gin::PerContextData::From(context_->v8_context())->context_holder(); 530 return gin::PerContextData::From(context_->v8_context())->context_holder();
534 } 531 }
535 532
536 } // namespace extensions 533 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698