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

Side by Side Diff: content/browser/renderer_host/java/java_bound_object.cc

Issue 8726005: Fix an incorrect comment in the Java Bridge when calling array methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clarifies existing comments Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/renderer_host/java/java_bound_object.h" 5 #include "content/browser/renderer_host/java/java_bound_object.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 bool JavaNPObject::Invoke(NPObject* np_object, NPIdentifier np_identifier, 93 bool JavaNPObject::Invoke(NPObject* np_object, NPIdentifier np_identifier,
94 const NPVariant* args, uint32_t arg_count, 94 const NPVariant* args, uint32_t arg_count,
95 NPVariant* result) { 95 NPVariant* result) {
96 std::string name = NPIdentifierToString(np_identifier); 96 std::string name = NPIdentifierToString(np_identifier);
97 JavaNPObject* obj = reinterpret_cast<JavaNPObject*>(np_object); 97 JavaNPObject* obj = reinterpret_cast<JavaNPObject*>(np_object);
98 return obj->bound_object->Invoke(name, args, arg_count, result); 98 return obj->bound_object->Invoke(name, args, arg_count, result);
99 } 99 }
100 100
101 bool JavaNPObject::HasProperty(NPObject* np_object, 101 bool JavaNPObject::HasProperty(NPObject* np_object,
102 NPIdentifier np_identifier) { 102 NPIdentifier np_identifier) {
103 // LIVECONNECT_COMPLIANCE: Return false to indicate that the property is not 103 // LIVECONNECT_COMPLIANCE: Existing behavior is to return false to indicate
104 // present. We should support this correctly. 104 // that the property is not present. Spec requires supporting this correctly.
105 return false; 105 return false;
106 } 106 }
107 107
108 bool JavaNPObject::GetProperty(NPObject* np_object, 108 bool JavaNPObject::GetProperty(NPObject* np_object,
109 NPIdentifier np_identifier, 109 NPIdentifier np_identifier,
110 NPVariant* result) { 110 NPVariant* result) {
111 // LIVECONNECT_COMPLIANCE: Return false to indicate that the property is 111 // LIVECONNECT_COMPLIANCE: Existing behavior is to return false to indicate
112 // undefined. We should support this correctly. 112 // that the property is undefined. Spec requires supporting this correctly.
113 return false; 113 return false;
114 } 114 }
115 115
116 // Calls a Java method through JNI and returns the result as an NPVariant. Note 116 // Calls a Java method through JNI and returns the result as an NPVariant. Note
117 // that this method does not do any type coercion. The Java return value is 117 // that this method does not do any type coercion. The Java return value is
118 // simply converted to the corresponding NPAPI type. 118 // simply converted to the corresponding NPAPI type.
119 NPVariant CallJNIMethod(jobject object, JavaType::Type return_type, 119 NPVariant CallJNIMethod(jobject object, JavaType::Type return_type,
120 jmethodID id, jvalue* parameters) { 120 jmethodID id, jvalue* parameters) {
121 JNIEnv* env = AttachCurrentThread(); 121 JNIEnv* env = AttachCurrentThread();
122 NPVariant result; 122 NPVariant result;
(...skipping 23 matching lines...) Expand all
146 break; 146 break;
147 case JavaType::TypeDouble: 147 case JavaType::TypeDouble:
148 DOUBLE_TO_NPVARIANT(env->CallDoubleMethodA(object, id, parameters), 148 DOUBLE_TO_NPVARIANT(env->CallDoubleMethodA(object, id, parameters),
149 result); 149 result);
150 break; 150 break;
151 case JavaType::TypeVoid: 151 case JavaType::TypeVoid:
152 env->CallVoidMethodA(object, id, parameters); 152 env->CallVoidMethodA(object, id, parameters);
153 VOID_TO_NPVARIANT(result); 153 VOID_TO_NPVARIANT(result);
154 break; 154 break;
155 case JavaType::TypeArray: 155 case JavaType::TypeArray:
156 // TODO(steveblock): Handle arrays 156 // LIVECONNECT_COMPLIANCE: Existing behavior is to not call methods that
157 // return arrays. Spec requires calling the method and converting the
158 // result to a JavaScript array.
157 VOID_TO_NPVARIANT(result); 159 VOID_TO_NPVARIANT(result);
158 break; 160 break;
159 case JavaType::TypeString: { 161 case JavaType::TypeString: {
160 ScopedJavaLocalRef<jstring> java_string(env, static_cast<jstring>( 162 ScopedJavaLocalRef<jstring> java_string(env, static_cast<jstring>(
161 env->CallObjectMethodA(object, id, parameters))); 163 env->CallObjectMethodA(object, id, parameters)));
162 if (!java_string.obj()) { 164 if (!java_string.obj()) {
163 // LIVECONNECT_COMPLIANCE: Return undefined to maintain existing 165 // LIVECONNECT_COMPLIANCE: Existing behavior is to return undefined.
164 // behavior. We should return a null string. 166 // Spec requires returning a null string.
165 VOID_TO_NPVARIANT(result); 167 VOID_TO_NPVARIANT(result);
166 break; 168 break;
167 } 169 }
168 std::string str = 170 std::string str =
169 base::android::ConvertJavaStringToUTF8(env, java_string.obj()); 171 base::android::ConvertJavaStringToUTF8(env, java_string.obj());
170 // Take a copy and pass ownership to the variant. We must allocate using 172 // Take a copy and pass ownership to the variant. We must allocate using
171 // NPN_MemAlloc, to match NPN_ReleaseVariant, which uses NPN_MemFree. 173 // NPN_MemAlloc, to match NPN_ReleaseVariant, which uses NPN_MemFree.
172 size_t length = str.length(); 174 size_t length = str.length();
173 char* buffer = static_cast<char*>(NPN_MemAlloc(length)); 175 char* buffer = static_cast<char*>(NPN_MemAlloc(length));
174 str.copy(buffer, length, 0); 176 str.copy(buffer, length, 0);
(...skipping 21 matching lines...) Expand all
196 jvalue result; 198 jvalue result;
197 DCHECK(variant.type == NPVariantType_Int32 || 199 DCHECK(variant.type == NPVariantType_Int32 ||
198 variant.type == NPVariantType_Double); 200 variant.type == NPVariantType_Double);
199 bool is_double = variant.type == NPVariantType_Double; 201 bool is_double = variant.type == NPVariantType_Double;
200 switch (target_type) { 202 switch (target_type) {
201 case JavaType::TypeByte: 203 case JavaType::TypeByte:
202 result.b = is_double ? static_cast<jbyte>(NPVARIANT_TO_DOUBLE(variant)) : 204 result.b = is_double ? static_cast<jbyte>(NPVARIANT_TO_DOUBLE(variant)) :
203 static_cast<jbyte>(NPVARIANT_TO_INT32(variant)); 205 static_cast<jbyte>(NPVARIANT_TO_INT32(variant));
204 break; 206 break;
205 case JavaType::TypeChar: 207 case JavaType::TypeChar:
206 // LIVECONNECT_COMPLIANCE: Convert double to 0 to maintain existing 208 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert double to 0.
207 // behavior. 209 // Spec requires converting doubles the same as int32.
208 result.c = is_double ? 0 : 210 result.c = is_double ? 0 :
209 static_cast<jchar>(NPVARIANT_TO_INT32(variant)); 211 static_cast<jchar>(NPVARIANT_TO_INT32(variant));
210 break; 212 break;
211 case JavaType::TypeShort: 213 case JavaType::TypeShort:
212 result.s = is_double ? static_cast<jshort>(NPVARIANT_TO_DOUBLE(variant)) : 214 result.s = is_double ? static_cast<jshort>(NPVARIANT_TO_DOUBLE(variant)) :
213 static_cast<jshort>(NPVARIANT_TO_INT32(variant)); 215 static_cast<jshort>(NPVARIANT_TO_INT32(variant));
214 break; 216 break;
215 case JavaType::TypeInt: 217 case JavaType::TypeInt:
216 result.i = is_double ? static_cast<jint>(NPVARIANT_TO_DOUBLE(variant)) : 218 result.i = is_double ? static_cast<jint>(NPVARIANT_TO_DOUBLE(variant)) :
217 NPVARIANT_TO_INT32(variant); 219 NPVARIANT_TO_INT32(variant);
218 break; 220 break;
219 case JavaType::TypeLong: 221 case JavaType::TypeLong:
220 result.j = is_double ? static_cast<jlong>(NPVARIANT_TO_DOUBLE(variant)) : 222 result.j = is_double ? static_cast<jlong>(NPVARIANT_TO_DOUBLE(variant)) :
221 NPVARIANT_TO_INT32(variant); 223 NPVARIANT_TO_INT32(variant);
222 break; 224 break;
223 case JavaType::TypeFloat: 225 case JavaType::TypeFloat:
224 result.f = is_double ? static_cast<jfloat>(NPVARIANT_TO_DOUBLE(variant)) : 226 result.f = is_double ? static_cast<jfloat>(NPVARIANT_TO_DOUBLE(variant)) :
225 NPVARIANT_TO_INT32(variant); 227 NPVARIANT_TO_INT32(variant);
226 break; 228 break;
227 case JavaType::TypeDouble: 229 case JavaType::TypeDouble:
228 result.d = is_double ? NPVARIANT_TO_DOUBLE(variant) : 230 result.d = is_double ? NPVARIANT_TO_DOUBLE(variant) :
229 NPVARIANT_TO_INT32(variant); 231 NPVARIANT_TO_INT32(variant);
230 break; 232 break;
231 case JavaType::TypeObject: 233 case JavaType::TypeObject:
232 // LIVECONNECT_COMPLIANCE: Convert to null to maintain existing behavior. 234 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to null. Spec
233 // We should handle object equivalents of primitive types. 235 // requires handling object equivalents of primitive types.
234 result.l = NULL; 236 result.l = NULL;
235 break; 237 break;
236 case JavaType::TypeString: 238 case JavaType::TypeString:
237 result.l = ConvertUTF8ToJavaString( 239 result.l = ConvertUTF8ToJavaString(
238 AttachCurrentThread(), 240 AttachCurrentThread(),
239 is_double ? StringPrintf("%.6lg", NPVARIANT_TO_DOUBLE(variant)) : 241 is_double ? StringPrintf("%.6lg", NPVARIANT_TO_DOUBLE(variant)) :
240 base::IntToString(NPVARIANT_TO_INT32(variant))); 242 base::IntToString(NPVARIANT_TO_INT32(variant)));
241 break; 243 break;
242 case JavaType::TypeBoolean: 244 case JavaType::TypeBoolean:
243 // LIVECONNECT_COMPLIANCE: Convert to false to maintain existing behavior. 245 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to false. Spec
244 // We should convert to false for o or NaN, true otherwise. 246 // requires converting to false for 0 or NaN, true otherwise.
245 result.z = JNI_FALSE; 247 result.z = JNI_FALSE;
246 break; 248 break;
247 case JavaType::TypeArray: 249 case JavaType::TypeArray:
248 // LIVECONNECT_COMPLIANCE: Convert to null to maintain existing behavior. 250 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to null. Spec
249 // We should raise a JavaScript exception. 251 // requires raising a JavaScript exception.
250 result.l = NULL; 252 result.l = NULL;
251 break; 253 break;
252 case JavaType::TypeVoid: 254 case JavaType::TypeVoid:
253 // Conversion to void must never happen. 255 // Conversion to void must never happen.
254 NOTREACHED(); 256 NOTREACHED();
255 break; 257 break;
256 } 258 }
257 return result; 259 return result;
258 } 260 }
259 261
260 jvalue CoerceJavaScriptBooleanToJavaValue(const NPVariant& variant, 262 jvalue CoerceJavaScriptBooleanToJavaValue(const NPVariant& variant,
261 JavaType::Type target_type) { 263 JavaType::Type target_type) {
262 // See http://jdk6.java.net/plugin2/liveconnect/#JS_BOOLEAN_VALUES. 264 // See http://jdk6.java.net/plugin2/liveconnect/#JS_BOOLEAN_VALUES.
263 DCHECK_EQ(NPVariantType_Bool, variant.type); 265 DCHECK_EQ(NPVariantType_Bool, variant.type);
264 bool boolean_value = NPVARIANT_TO_BOOLEAN(variant); 266 bool boolean_value = NPVARIANT_TO_BOOLEAN(variant);
265 jvalue result; 267 jvalue result;
266 switch (target_type) { 268 switch (target_type) {
267 case JavaType::TypeBoolean: 269 case JavaType::TypeBoolean:
268 result.z = boolean_value ? JNI_TRUE : JNI_FALSE; 270 result.z = boolean_value ? JNI_TRUE : JNI_FALSE;
269 break; 271 break;
270 case JavaType::TypeObject: 272 case JavaType::TypeObject:
271 // LIVECONNECT_COMPLIANCE: Convert to NULL to maintain existing behavior. 273 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to NULL. Spec
272 // We should handle java.lang.Boolean and java.lang.Object. 274 // requires handling java.lang.Boolean and java.lang.Object.
273 result.l = NULL; 275 result.l = NULL;
274 break; 276 break;
275 case JavaType::TypeString: 277 case JavaType::TypeString:
276 result.l = ConvertUTF8ToJavaString(AttachCurrentThread(), 278 result.l = ConvertUTF8ToJavaString(AttachCurrentThread(),
277 boolean_value ? "true" : "false"); 279 boolean_value ? "true" : "false");
278 break; 280 break;
279 case JavaType::TypeByte: 281 case JavaType::TypeByte:
280 case JavaType::TypeChar: 282 case JavaType::TypeChar:
281 case JavaType::TypeShort: 283 case JavaType::TypeShort:
282 case JavaType::TypeInt: 284 case JavaType::TypeInt:
283 case JavaType::TypeLong: 285 case JavaType::TypeLong:
284 case JavaType::TypeFloat: 286 case JavaType::TypeFloat:
285 case JavaType::TypeDouble: { 287 case JavaType::TypeDouble: {
286 // LIVECONNECT_COMPLIANCE: Convert to 0 to maintain existing behavior. We 288 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to 0. Spec
287 // should convert to 0 or 1. 289 // requires converting to 0 or 1.
288 jvalue null_value = {0}; 290 jvalue null_value = {0};
289 result = null_value; 291 result = null_value;
290 break; 292 break;
291 } 293 }
292 case JavaType::TypeArray: 294 case JavaType::TypeArray:
293 // LIVECONNECT_COMPLIANCE: Convert to NULL to maintain existing behavior. 295 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to NULL. Spec
294 // We should raise a JavaScript exception. 296 // requires raising a JavaScript exception.
295 result.l = NULL; 297 result.l = NULL;
296 break; 298 break;
297 case JavaType::TypeVoid: 299 case JavaType::TypeVoid:
298 // Conversion to void must never happen. 300 // Conversion to void must never happen.
299 NOTREACHED(); 301 NOTREACHED();
300 break; 302 break;
301 } 303 }
302 return result; 304 return result;
303 } 305 }
304 306
305 jvalue CoerceJavaScriptStringToJavaValue(const NPVariant& variant, 307 jvalue CoerceJavaScriptStringToJavaValue(const NPVariant& variant,
306 JavaType::Type target_type) { 308 JavaType::Type target_type) {
307 // See http://jdk6.java.net/plugin2/liveconnect/#JS_STRING_VALUES. 309 // See http://jdk6.java.net/plugin2/liveconnect/#JS_STRING_VALUES.
308 DCHECK_EQ(NPVariantType_String, variant.type); 310 DCHECK_EQ(NPVariantType_String, variant.type);
309 jvalue result; 311 jvalue result;
310 switch (target_type) { 312 switch (target_type) {
311 case JavaType::TypeString: 313 case JavaType::TypeString:
312 result.l = ConvertUTF8ToJavaString( 314 result.l = ConvertUTF8ToJavaString(
313 AttachCurrentThread(), 315 AttachCurrentThread(),
314 base::StringPiece(NPVARIANT_TO_STRING(variant).UTF8Characters, 316 base::StringPiece(NPVARIANT_TO_STRING(variant).UTF8Characters,
315 NPVARIANT_TO_STRING(variant).UTF8Length)); 317 NPVARIANT_TO_STRING(variant).UTF8Length));
316 break; 318 break;
317 case JavaType::TypeObject: 319 case JavaType::TypeObject:
318 // LIVECONNECT_COMPLIANCE: Convert to NULL to maintain existing behavior. 320 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to NULL. Spec
319 // We should handle java.lang.Object. 321 // requires handling java.lang.Object.
320 result.l = NULL; 322 result.l = NULL;
321 break; 323 break;
322 case JavaType::TypeByte: 324 case JavaType::TypeByte:
323 case JavaType::TypeShort: 325 case JavaType::TypeShort:
324 case JavaType::TypeInt: 326 case JavaType::TypeInt:
325 case JavaType::TypeLong: 327 case JavaType::TypeLong:
326 case JavaType::TypeFloat: 328 case JavaType::TypeFloat:
327 case JavaType::TypeDouble: { 329 case JavaType::TypeDouble: {
328 // LIVECONNECT_COMPLIANCE: Convert to 0 to maintain existing behavior. we 330 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to 0. Spec
329 // should use valueOf() method of corresponding object type. 331 // requires using valueOf() method of corresponding object type.
330 jvalue null_value = {0}; 332 jvalue null_value = {0};
331 result = null_value; 333 result = null_value;
332 break; 334 break;
333 } 335 }
334 case JavaType::TypeChar: 336 case JavaType::TypeChar:
335 // LIVECONNECT_COMPLIANCE: Convert to 0 to maintain existing behavior. we 337 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to 0. Spec
336 // should use java.lang.Short.decode(). 338 // requires using java.lang.Short.decode().
337 result.c = 0; 339 result.c = 0;
338 break; 340 break;
339 case JavaType::TypeBoolean: 341 case JavaType::TypeBoolean:
340 // LIVECONNECT_COMPLIANCE: Convert to false to maintain existing behavior. 342 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to false. Spec
341 // We should convert the empty string to false, otherwise true. 343 // requires converting the empty string to false, otherwise true.
342 result.z = JNI_FALSE; 344 result.z = JNI_FALSE;
343 break; 345 break;
344 case JavaType::TypeArray: 346 case JavaType::TypeArray:
345 // LIVECONNECT_COMPLIANCE: Convert to NULL to maintain existing behavior. 347 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to NULL. Spec
346 // We should raise a JavaScript exception. 348 // requires raising a JavaScript exception.
347 result.l = NULL; 349 result.l = NULL;
348 break; 350 break;
349 case JavaType::TypeVoid: 351 case JavaType::TypeVoid:
350 // Conversion to void must never happen. 352 // Conversion to void must never happen.
351 NOTREACHED(); 353 NOTREACHED();
352 break; 354 break;
353 } 355 }
354 return result; 356 return result;
355 } 357 }
356 358
357 jvalue CoerceJavaScriptObjectToJavaValue(const NPVariant& variant, 359 jvalue CoerceJavaScriptObjectToJavaValue(const NPVariant& variant,
358 JavaType::Type target_type) { 360 JavaType::Type target_type) {
359 // We only handle Java objects. See 361 // We only handle Java objects. See
360 // http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_OBJECTS. 362 // http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_OBJECTS.
361 // TODO(steveblock): Handle arrays. 363 // TODO(steveblock): Handle arrays.
362 // TODO(steveblock): Handle JavaScript objects. 364 // TODO(steveblock): Handle JavaScript objects.
363 DCHECK_EQ(NPVariantType_Object, variant.type); 365 DCHECK_EQ(NPVariantType_Object, variant.type);
364 366
365 // The only type of object we should encounter is a Java object, as 367 // The only type of object we should encounter is a Java object, as
366 // other objects should have been converted to NULL in the renderer. 368 // other objects should have been converted to NULL in the renderer.
367 // See CreateNPVariantParam(). 369 // See CreateNPVariantParam().
368 // TODO(steveblock): This will have to change once we support arrays and 370 // TODO(steveblock): This will have to change once we support arrays and
369 // JavaScript objects. 371 // JavaScript objects.
370 NPObject* object = NPVARIANT_TO_OBJECT(variant); 372 NPObject* object = NPVARIANT_TO_OBJECT(variant);
371 DCHECK_EQ(&JavaNPObject::kNPClass, object->_class); 373 DCHECK_EQ(&JavaNPObject::kNPClass, object->_class);
372 374
373 jvalue result; 375 jvalue result;
374 switch (target_type) { 376 switch (target_type) {
375 case JavaType::TypeObject: 377 case JavaType::TypeObject:
376 // LIVECONNECT_COMPLIANCE: Pass all Java objects to maintain existing 378 // LIVECONNECT_COMPLIANCE: Existing behavior is to pass all Java objects.
377 // behavior. We should pass only Java objects which are 379 // Spec requires passing only Java objects which are
378 // assignment-compatibile. 380 // assignment-compatibile.
379 result.l = AttachCurrentThread()->NewLocalRef( 381 result.l = AttachCurrentThread()->NewLocalRef(
380 JavaBoundObject::GetJavaObject(object)); 382 JavaBoundObject::GetJavaObject(object));
381 break; 383 break;
382 case JavaType::TypeString: 384 case JavaType::TypeString:
383 // LIVECONNECT_COMPLIANCE: Convert to "undefined" to maintain existing 385 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to
384 // behavior. We should call toString() on the Java object. 386 // "undefined". Spec requires calling toString() on the Java object.
385 result.l = ConvertUTF8ToJavaString(AttachCurrentThread(), "undefined"); 387 result.l = ConvertUTF8ToJavaString(AttachCurrentThread(), "undefined");
386 break; 388 break;
387 case JavaType::TypeByte: 389 case JavaType::TypeByte:
388 case JavaType::TypeShort: 390 case JavaType::TypeShort:
389 case JavaType::TypeInt: 391 case JavaType::TypeInt:
390 case JavaType::TypeLong: 392 case JavaType::TypeLong:
391 case JavaType::TypeFloat: 393 case JavaType::TypeFloat:
392 case JavaType::TypeDouble: 394 case JavaType::TypeDouble:
393 case JavaType::TypeChar: { 395 case JavaType::TypeChar: {
394 // LIVECONNECT_COMPLIANCE: Convert to 0 to maintain existing behavior. We 396 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to 0. Spec
395 // should raise a JavaScript exception. 397 // requires raising a JavaScript exception.
396 jvalue null_value = {0}; 398 jvalue null_value = {0};
397 result = null_value; 399 result = null_value;
398 break; 400 break;
399 } 401 }
400 case JavaType::TypeBoolean: 402 case JavaType::TypeBoolean:
401 // LIVECONNECT_COMPLIANCE: Convert to false to maintain existing behavior. 403 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to false. Spec
402 // We should raise a JavaScript exception. 404 // requires raising a JavaScript exception.
403 result.z = JNI_FALSE; 405 result.z = JNI_FALSE;
404 break; 406 break;
405 case JavaType::TypeArray: 407 case JavaType::TypeArray:
406 // LIVECONNECT_COMPLIANCE: Convert to NULL to maintain existing behavior. 408 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to NULL. Spec
407 // We should raise a JavaScript exception. 409 // requires raising a JavaScript exception.
408 result.l = NULL; 410 result.l = NULL;
409 break; 411 break;
410 case JavaType::TypeVoid: 412 case JavaType::TypeVoid:
411 // Conversion to void must never happen. 413 // Conversion to void must never happen.
412 NOTREACHED(); 414 NOTREACHED();
413 break; 415 break;
414 } 416 }
415 return result; 417 return result;
416 } 418 }
417 419
418 jvalue CoerceJavaScriptNullOrUndefinedToJavaValue(const NPVariant& variant, 420 jvalue CoerceJavaScriptNullOrUndefinedToJavaValue(const NPVariant& variant,
419 JavaType::Type target_type) { 421 JavaType::Type target_type) {
420 // See http://jdk6.java.net/plugin2/liveconnect/#JS_NULL. 422 // See http://jdk6.java.net/plugin2/liveconnect/#JS_NULL.
421 DCHECK(variant.type == NPVariantType_Null || 423 DCHECK(variant.type == NPVariantType_Null ||
422 variant.type == NPVariantType_Void); 424 variant.type == NPVariantType_Void);
423 jvalue result; 425 jvalue result;
424 switch (target_type) { 426 switch (target_type) {
425 case JavaType::TypeObject: 427 case JavaType::TypeObject:
426 result.l = NULL; 428 result.l = NULL;
427 break; 429 break;
428 case JavaType::TypeString: 430 case JavaType::TypeString:
429 if (variant.type == NPVariantType_Void) { 431 if (variant.type == NPVariantType_Void) {
430 // LIVECONNECT_COMPLIANCE: Convert undefined to "undefined" to maintain 432 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert undefined to
431 // existing behavior. We should convert undefined to NULL. 433 // "undefined". Spec requires converting undefined to NULL.
432 result.l = ConvertUTF8ToJavaString(AttachCurrentThread(), "undefined"); 434 result.l = ConvertUTF8ToJavaString(AttachCurrentThread(), "undefined");
433 } else { 435 } else {
434 result.l = NULL; 436 result.l = NULL;
435 } 437 }
436 break; 438 break;
437 case JavaType::TypeByte: 439 case JavaType::TypeByte:
438 case JavaType::TypeChar: 440 case JavaType::TypeChar:
439 case JavaType::TypeShort: 441 case JavaType::TypeShort:
440 case JavaType::TypeInt: 442 case JavaType::TypeInt:
441 case JavaType::TypeLong: 443 case JavaType::TypeLong:
442 case JavaType::TypeFloat: 444 case JavaType::TypeFloat:
443 case JavaType::TypeDouble: { 445 case JavaType::TypeDouble: {
444 jvalue null_value = {0}; 446 jvalue null_value = {0};
445 result = null_value; 447 result = null_value;
446 break; 448 break;
447 } 449 }
448 case JavaType::TypeBoolean: 450 case JavaType::TypeBoolean:
449 result.z = JNI_FALSE; 451 result.z = JNI_FALSE;
450 break; 452 break;
451 case JavaType::TypeArray: 453 case JavaType::TypeArray:
452 // LIVECONNECT_COMPLIANCE: Convert to NULL to maintain existing behavior. 454 // LIVECONNECT_COMPLIANCE: Existing behavior is to convert to NULL. Spec
453 // We should raise a JavaScript exception. 455 // requires raising a JavaScript exception.
454 result.l = NULL; 456 result.l = NULL;
455 break; 457 break;
456 case JavaType::TypeVoid: 458 case JavaType::TypeVoid:
457 // Conversion to void must never happen. 459 // Conversion to void must never happen.
458 NOTREACHED(); 460 NOTREACHED();
459 break; 461 break;
460 } 462 }
461 return result; 463 return result;
462 } 464 }
463 465
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 size_t num_methods = env->GetArrayLength(methods.obj()); 607 size_t num_methods = env->GetArrayLength(methods.obj());
606 DCHECK(num_methods) << "Java objects always have public methods"; 608 DCHECK(num_methods) << "Java objects always have public methods";
607 for (size_t i = 0; i < num_methods; ++i) { 609 for (size_t i = 0; i < num_methods; ++i) {
608 ScopedJavaLocalRef<jobject> java_method( 610 ScopedJavaLocalRef<jobject> java_method(
609 env, 611 env,
610 env->GetObjectArrayElement(methods.obj(), i)); 612 env->GetObjectArrayElement(methods.obj(), i));
611 JavaMethod* method = new JavaMethod(java_method); 613 JavaMethod* method = new JavaMethod(java_method);
612 methods_.insert(std::make_pair(method->name(), method)); 614 methods_.insert(std::make_pair(method->name(), method));
613 } 615 }
614 } 616 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698