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

Side by Side Diff: content/browser/android/java/gin_java_script_to_java_types_coercion.cc

Issue 2792573002: Remove base::Value::CreateNullValue (Closed)
Patch Set: Rebase Created 3 years, 8 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 "content/browser/android/java/gin_java_script_to_java_types_coercion.h" 5 #include "content/browser/android/java/gin_java_script_to_java_types_coercion.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include <limits> 10 #include <limits>
11 11
12 #include "base/android/jni_android.h" 12 #include "base/android/jni_android.h"
13 #include "base/android/jni_string.h" 13 #include "base/android/jni_string.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "content/common/android/gin_java_bridge_value.h" 18 #include "content/common/android/gin_java_bridge_value.h"
18 19
19 using base::android::ConvertUTF8ToJavaString; 20 using base::android::ConvertUTF8ToJavaString;
20 using base::android::ScopedJavaLocalRef; 21 using base::android::ScopedJavaLocalRef;
21 22
22 namespace content { 23 namespace content {
23 24
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 } 459 }
459 460
460 const base::ListValue* list_value; 461 const base::ListValue* list_value;
461 value->GetAsList(&list_value); 462 value->GetAsList(&list_value);
462 // Create the Java array. 463 // Create the Java array.
463 jsize length = static_cast<jsize>(list_value->GetSize()); 464 jsize length = static_cast<jsize>(list_value->GetSize());
464 jobject result = CreateJavaArray(env, target_inner_type, length); 465 jobject result = CreateJavaArray(env, target_inner_type, length);
465 if (!result) { 466 if (!result) {
466 return NULL; 467 return NULL;
467 } 468 }
468 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); 469 auto null_value = base::MakeUnique<base::Value>();
469 for (jsize i = 0; i < length; ++i) { 470 for (jsize i = 0; i < length; ++i) {
470 const base::Value* value_element = null_value.get(); 471 const base::Value* value_element = null_value.get();
471 list_value->Get(i, &value_element); 472 list_value->Get(i, &value_element);
472 jvalue element = CoerceJavaScriptValueToJavaValue( 473 jvalue element = CoerceJavaScriptValueToJavaValue(
473 env, value_element, target_inner_type, false, object_refs, error); 474 env, value_element, target_inner_type, false, object_refs, error);
474 SetArrayElement(env, result, target_inner_type, i, element); 475 SetArrayElement(env, result, target_inner_type, i, element);
475 // CoerceJavaScriptValueToJavaValue() creates new local references to 476 // CoerceJavaScriptValueToJavaValue() creates new local references to
476 // strings, objects and arrays. Of these, only strings can occur here. 477 // strings, objects and arrays. Of these, only strings can occur here.
477 // SetArrayElement() causes the array to take its own reference to the 478 // SetArrayElement() causes the array to take its own reference to the
478 // string, so we can now release the local reference. 479 // string, so we can now release the local reference.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 531 }
531 } 532 }
532 if (length == -1) { 533 if (length == -1) {
533 return NULL; 534 return NULL;
534 } 535 }
535 536
536 jobject result = CreateJavaArray(env, target_inner_type, length); 537 jobject result = CreateJavaArray(env, target_inner_type, length);
537 if (!result) { 538 if (!result) {
538 return NULL; 539 return NULL;
539 } 540 }
540 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); 541 auto null_value = base::MakeUnique<base::Value>();
541 for (jsize i = 0; i < length; ++i) { 542 for (jsize i = 0; i < length; ++i) {
542 const std::string key(base::IntToString(i)); 543 const std::string key(base::IntToString(i));
543 const base::Value* value_element = null_value.get(); 544 const base::Value* value_element = null_value.get();
544 if (dictionary_value->HasKey(key)) { 545 if (dictionary_value->HasKey(key)) {
545 dictionary_value->Get(key, &value_element); 546 dictionary_value->Get(key, &value_element);
546 } 547 }
547 jvalue element = CoerceJavaScriptValueToJavaValue( 548 jvalue element = CoerceJavaScriptValueToJavaValue(
548 env, value_element, target_inner_type, false, object_refs, error); 549 env, value_element, target_inner_type, false, object_refs, error);
549 SetArrayElement(env, result, target_inner_type, i, element); 550 SetArrayElement(env, result, target_inner_type, i, element);
550 // CoerceJavaScriptValueToJavaValue() creates new local references to 551 // CoerceJavaScriptValueToJavaValue() creates new local references to
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 env, value, target_type, coerce_to_string, error); 722 env, value, target_type, coerce_to_string, error);
722 case base::Value::Type::BINARY: 723 case base::Value::Type::BINARY:
723 return CoerceGinJavaBridgeValueToJavaValue( 724 return CoerceGinJavaBridgeValueToJavaValue(
724 env, value, target_type, coerce_to_string, object_refs, error); 725 env, value, target_type, coerce_to_string, object_refs, error);
725 } 726 }
726 NOTREACHED(); 727 NOTREACHED();
727 return jvalue(); 728 return jvalue();
728 } 729 }
729 730
730 } // namespace content 731 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/java/gin_java_method_invocation_helper.cc ('k') | content/browser/devtools/protocol_string.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698