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

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

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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>
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 value->GetAsDictionary(&dictionary_value); 508 value->GetAsDictionary(&dictionary_value);
509 const base::Value* length_value; 509 const base::Value* length_value;
510 // If the object does not have a length property, return null. 510 // If the object does not have a length property, return null.
511 if (!dictionary_value->Get("length", &length_value)) { 511 if (!dictionary_value->Get("length", &length_value)) {
512 return NULL; 512 return NULL;
513 } 513 }
514 514
515 // If the length property does not have numeric type, or is outside the valid 515 // If the length property does not have numeric type, or is outside the valid
516 // range for a Java array length, return null. 516 // range for a Java array length, return null.
517 jsize length = -1; 517 jsize length = -1;
518 if (length_value->IsType(base::Value::TYPE_INTEGER)) { 518 if (length_value->IsType(base::Value::Type::INTEGER)) {
519 int int_length; 519 int int_length;
520 length_value->GetAsInteger(&int_length); 520 length_value->GetAsInteger(&int_length);
521 if (int_length >= 0 && int_length <= std::numeric_limits<int32_t>::max()) { 521 if (int_length >= 0 && int_length <= std::numeric_limits<int32_t>::max()) {
522 length = static_cast<jsize>(int_length); 522 length = static_cast<jsize>(int_length);
523 } 523 }
524 } else if (length_value->IsType(base::Value::TYPE_DOUBLE)) { 524 } else if (length_value->IsType(base::Value::Type::DOUBLE)) {
525 double double_length; 525 double double_length;
526 length_value->GetAsDouble(&double_length); 526 length_value->GetAsDouble(&double_length);
527 if (double_length >= 0.0 && 527 if (double_length >= 0.0 &&
528 double_length <= std::numeric_limits<int32_t>::max()) { 528 double_length <= std::numeric_limits<int32_t>::max()) {
529 length = static_cast<jsize>(double_length); 529 length = static_cast<jsize>(double_length);
530 } 530 }
531 } 531 }
532 if (length == -1) { 532 if (length == -1) {
533 return NULL; 533 return NULL;
534 } 534 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 jvalue null_value = {0}; 622 jvalue null_value = {0};
623 result = null_value; 623 result = null_value;
624 break; 624 break;
625 } 625 }
626 case JavaType::TypeBoolean: 626 case JavaType::TypeBoolean:
627 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to false. Spec 627 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to false. Spec
628 // requires raising a JavaScript exception. 628 // requires raising a JavaScript exception.
629 result.z = JNI_FALSE; 629 result.z = JNI_FALSE;
630 break; 630 break;
631 case JavaType::TypeArray: 631 case JavaType::TypeArray:
632 if (value->IsType(base::Value::TYPE_DICTIONARY)) { 632 if (value->IsType(base::Value::Type::DICTIONARY)) {
633 result.l = CoerceJavaScriptDictionaryToArray( 633 result.l = CoerceJavaScriptDictionaryToArray(
634 env, value, target_type, object_refs, error); 634 env, value, target_type, object_refs, error);
635 } else if (value->IsType(base::Value::TYPE_LIST)) { 635 } else if (value->IsType(base::Value::Type::LIST)) {
636 result.l = CoerceJavaScriptListToArray( 636 result.l = CoerceJavaScriptListToArray(
637 env, value, target_type, object_refs, error); 637 env, value, target_type, object_refs, error);
638 } else { 638 } else {
639 result.l = NULL; 639 result.l = NULL;
640 } 640 }
641 break; 641 break;
642 case JavaType::TypeVoid: 642 case JavaType::TypeVoid:
643 // Conversion to void must never happen. 643 // Conversion to void must never happen.
644 NOTREACHED(); 644 NOTREACHED();
645 break; 645 break;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 jvalue CoerceJavaScriptValueToJavaValue(JNIEnv* env, 691 jvalue CoerceJavaScriptValueToJavaValue(JNIEnv* env,
692 const base::Value* value, 692 const base::Value* value,
693 const JavaType& target_type, 693 const JavaType& target_type,
694 bool coerce_to_string, 694 bool coerce_to_string,
695 const ObjectRefs& object_refs, 695 const ObjectRefs& object_refs,
696 GinJavaBridgeError* error) { 696 GinJavaBridgeError* error) {
697 // Note that in all these conversions, the relevant field of the jvalue must 697 // Note that in all these conversions, the relevant field of the jvalue must
698 // always be explicitly set, as jvalue does not initialize its fields. 698 // always be explicitly set, as jvalue does not initialize its fields.
699 699
700 switch (value->GetType()) { 700 switch (value->GetType()) {
701 case base::Value::TYPE_INTEGER: 701 case base::Value::Type::INTEGER:
702 return CoerceJavaScriptIntegerToJavaValue( 702 return CoerceJavaScriptIntegerToJavaValue(
703 env, value, target_type, coerce_to_string, error); 703 env, value, target_type, coerce_to_string, error);
704 case base::Value::TYPE_DOUBLE: { 704 case base::Value::Type::DOUBLE: {
705 double double_value; 705 double double_value;
706 value->GetAsDouble(&double_value); 706 value->GetAsDouble(&double_value);
707 return CoerceJavaScriptDoubleToJavaValue( 707 return CoerceJavaScriptDoubleToJavaValue(
708 env, double_value, target_type, coerce_to_string, error); 708 env, double_value, target_type, coerce_to_string, error);
709 } 709 }
710 case base::Value::TYPE_BOOLEAN: 710 case base::Value::Type::BOOLEAN:
711 return CoerceJavaScriptBooleanToJavaValue( 711 return CoerceJavaScriptBooleanToJavaValue(
712 env, value, target_type, coerce_to_string, error); 712 env, value, target_type, coerce_to_string, error);
713 case base::Value::TYPE_STRING: 713 case base::Value::Type::STRING:
714 return CoerceJavaScriptStringToJavaValue(env, value, target_type, error); 714 return CoerceJavaScriptStringToJavaValue(env, value, target_type, error);
715 case base::Value::TYPE_DICTIONARY: 715 case base::Value::Type::DICTIONARY:
716 case base::Value::TYPE_LIST: 716 case base::Value::Type::LIST:
717 return CoerceJavaScriptObjectToJavaValue( 717 return CoerceJavaScriptObjectToJavaValue(
718 env, value, target_type, coerce_to_string, object_refs, error); 718 env, value, target_type, coerce_to_string, object_refs, error);
719 case base::Value::TYPE_NULL: 719 case base::Value::Type::NONE:
720 return CoerceJavaScriptNullOrUndefinedToJavaValue( 720 return CoerceJavaScriptNullOrUndefinedToJavaValue(
721 env, value, target_type, coerce_to_string, error); 721 env, value, target_type, coerce_to_string, error);
722 case base::Value::TYPE_BINARY: 722 case base::Value::Type::BINARY:
723 return CoerceGinJavaBridgeValueToJavaValue( 723 return CoerceGinJavaBridgeValueToJavaValue(
724 env, value, target_type, coerce_to_string, object_refs, error); 724 env, value, target_type, coerce_to_string, object_refs, error);
725 } 725 }
726 NOTREACHED(); 726 NOTREACHED();
727 return jvalue(); 727 return jvalue();
728 } 728 }
729 729
730 } // namespace content 730 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698