| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Tests for jni_generator.py. | 7 """Tests for jni_generator.py. |
| 8 | 8 |
| 9 This test suite contains various tests for the JNI generator. | 9 This test suite contains various tests for the JNI generator. |
| 10 It exercises the low-level parser all the way up to the | 10 It exercises the low-level parser all the way up to the |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 else: | 40 else: |
| 41 self.assertEquals(first[i], second[i]) | 41 self.assertEquals(first[i], second[i]) |
| 42 | 42 |
| 43 def assertTextEquals(self, golden_text, generated_text): | 43 def assertTextEquals(self, golden_text, generated_text): |
| 44 stripped_golden = [l.strip() for l in golden_text.split('\n')] | 44 stripped_golden = [l.strip() for l in golden_text.split('\n')] |
| 45 stripped_generated = [l.strip() for l in generated_text.split('\n')] | 45 stripped_generated = [l.strip() for l in generated_text.split('\n')] |
| 46 if stripped_golden != stripped_generated: | 46 if stripped_golden != stripped_generated: |
| 47 print self.id() | 47 print self.id() |
| 48 for line in difflib.context_diff(stripped_golden, stripped_generated): | 48 for line in difflib.context_diff(stripped_golden, stripped_generated): |
| 49 print line | 49 print line |
| 50 print '\n\nGenerated' |
| 51 print '=' * 80 |
| 52 print generated_text |
| 53 print '=' * 80 |
| 50 self.fail('Golden text mismatch') | 54 self.fail('Golden text mismatch') |
| 51 | 55 |
| 52 def testNatives(self): | 56 def testNatives(self): |
| 53 test_data = """" | 57 test_data = """" |
| 54 private native int nativeInit(); | 58 private native int nativeInit(); |
| 55 private native void nativeDestroy(int nativeChromeBrowserProvider); | 59 private native void nativeDestroy(int nativeChromeBrowserProvider); |
| 56 private native long nativeAddBookmark( | 60 private native long nativeAddBookmark( |
| 57 int nativeChromeBrowserProvider, | 61 int nativeChromeBrowserProvider, |
| 58 String url, String title, boolean isFolder, long parentId); | 62 String url, String title, boolean isFolder, long parentId); |
| 59 private static native String nativeGetDomainAndRegistry(String url); | 63 private static native String nativeGetDomainAndRegistry(String url); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 224 |
| 221 #include "base/android/jni_android.h" | 225 #include "base/android/jni_android.h" |
| 222 #include "base/android/scoped_java_ref.h" | 226 #include "base/android/scoped_java_ref.h" |
| 223 #include "base/basictypes.h" | 227 #include "base/basictypes.h" |
| 224 #include "base/logging.h" | 228 #include "base/logging.h" |
| 225 | 229 |
| 226 using base::android::ScopedJavaLocalRef; | 230 using base::android::ScopedJavaLocalRef; |
| 227 | 231 |
| 228 // Step 1: forward declarations. | 232 // Step 1: forward declarations. |
| 229 namespace { | 233 namespace { |
| 230 const char* const kTestJniClassPath = "org/chromium/TestJni"; | 234 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
| 231 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | 235 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 232 base::android::ScopedJavaGlobalRef<jclass>& | 236 jclass g_TestJni_clazz = NULL; |
| 233 g_TestJni_clazz = | |
| 234 *(new base::android::ScopedJavaGlobalRef<jclass>()); | |
| 235 } // namespace | 237 } // namespace |
| 236 | 238 |
| 237 static jint Init(JNIEnv* env, jobject obj); | 239 static jint Init(JNIEnv* env, jobject obj); |
| 238 | 240 |
| 239 | 241 |
| 240 static jstring GetDomainAndRegistry(JNIEnv* env, jclass clazz, | 242 static jstring GetDomainAndRegistry(JNIEnv* env, jclass clazz, |
| 241 jstring url); | 243 jstring url); |
| 242 | 244 |
| 243 | 245 |
| 244 static void CreateHistoricalTabFromState(JNIEnv* env, jclass clazz, | 246 static void CreateHistoricalTabFromState(JNIEnv* env, jclass clazz, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 device_orientation::DeviceOrientationAndroid* native = | 326 device_orientation::DeviceOrientationAndroid* native = |
| 325 reinterpret_cast<device_orientation::DeviceOrientationAndroid*>(nativePtr); | 327 reinterpret_cast<device_orientation::DeviceOrientationAndroid*>(nativePtr); |
| 326 return native->GotOrientation(env, obj, alpha, beta, gamma); | 328 return native->GotOrientation(env, obj, alpha, beta, gamma); |
| 327 } | 329 } |
| 328 | 330 |
| 329 | 331 |
| 330 // Step 3: GetMethodIDs and RegisterNatives. | 332 // Step 3: GetMethodIDs and RegisterNatives. |
| 331 | 333 |
| 332 | 334 |
| 333 static void GetMethodIDsImpl(JNIEnv* env) { | 335 static void GetMethodIDsImpl(JNIEnv* env) { |
| 334 g_TestJni_clazz.Reset( | 336 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 335 base::android::GetClass(env, kTestJniClassPath)); | 337 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
| 336 } | 338 } |
| 337 | 339 |
| 338 static bool RegisterNativesImpl(JNIEnv* env) { | 340 static bool RegisterNativesImpl(JNIEnv* env) { |
| 339 GetMethodIDsImpl(env); | 341 GetMethodIDsImpl(env); |
| 340 | 342 |
| 341 static const JNINativeMethod kMethodsTestJni[] = { | 343 static const JNINativeMethod kMethodsTestJni[] = { |
| 342 { "nativeInit", | 344 { "nativeInit", |
| 343 "(" | 345 "(" |
| 344 ")" | 346 ")" |
| 345 "I", reinterpret_cast<void*>(Init) }, | 347 "I", reinterpret_cast<void*>(Init) }, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 "(" | 421 "(" |
| 420 "I" | 422 "I" |
| 421 "D" | 423 "D" |
| 422 "D" | 424 "D" |
| 423 "D" | 425 "D" |
| 424 ")" | 426 ")" |
| 425 "V", reinterpret_cast<void*>(GotOrientation) }, | 427 "V", reinterpret_cast<void*>(GotOrientation) }, |
| 426 }; | 428 }; |
| 427 const int kMethodsTestJniSize = arraysize(kMethodsTestJni); | 429 const int kMethodsTestJniSize = arraysize(kMethodsTestJni); |
| 428 | 430 |
| 429 if (env->RegisterNatives(g_TestJni_clazz.obj(), | 431 if (env->RegisterNatives(g_TestJni_clazz, |
| 430 kMethodsTestJni, | 432 kMethodsTestJni, |
| 431 kMethodsTestJniSize) < 0) { | 433 kMethodsTestJniSize) < 0) { |
| 432 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 434 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
| 433 return false; | 435 return false; |
| 434 } | 436 } |
| 435 | 437 |
| 436 return true; | 438 return true; |
| 437 } | 439 } |
| 438 | 440 |
| 439 #endif // org_chromium_TestJni_JNI | 441 #endif // org_chromium_TestJni_JNI |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 477 |
| 476 #include "base/android/jni_android.h" | 478 #include "base/android/jni_android.h" |
| 477 #include "base/android/scoped_java_ref.h" | 479 #include "base/android/scoped_java_ref.h" |
| 478 #include "base/basictypes.h" | 480 #include "base/basictypes.h" |
| 479 #include "base/logging.h" | 481 #include "base/logging.h" |
| 480 | 482 |
| 481 using base::android::ScopedJavaLocalRef; | 483 using base::android::ScopedJavaLocalRef; |
| 482 | 484 |
| 483 // Step 1: forward declarations. | 485 // Step 1: forward declarations. |
| 484 namespace { | 486 namespace { |
| 485 const char* const kTestJniClassPath = "org/chromium/TestJni"; | 487 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
| 486 const char* const kMyInnerClassClassPath = "org/chromium/TestJni$MyInnerClass"; | 488 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; |
| 487 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | 489 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 488 base::android::ScopedJavaGlobalRef<jclass>& | 490 jclass g_TestJni_clazz = NULL; |
| 489 g_TestJni_clazz = | |
| 490 *(new base::android::ScopedJavaGlobalRef<jclass>()); | |
| 491 } // namespace | 491 } // namespace |
| 492 | 492 |
| 493 static jint Init(JNIEnv* env, jobject obj); | 493 static jint Init(JNIEnv* env, jobject obj); |
| 494 | 494 |
| 495 | 495 |
| 496 // Step 2: method stubs. | 496 // Step 2: method stubs. |
| 497 | 497 |
| 498 | 498 |
| 499 // Step 3: GetMethodIDs and RegisterNatives. | 499 // Step 3: GetMethodIDs and RegisterNatives. |
| 500 | 500 |
| 501 | 501 |
| 502 static void GetMethodIDsImpl(JNIEnv* env) { | 502 static void GetMethodIDsImpl(JNIEnv* env) { |
| 503 g_TestJni_clazz.Reset( | 503 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 504 base::android::GetClass(env, kTestJniClassPath)); | 504 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
| 505 } | 505 } |
| 506 | 506 |
| 507 static bool RegisterNativesImpl(JNIEnv* env) { | 507 static bool RegisterNativesImpl(JNIEnv* env) { |
| 508 GetMethodIDsImpl(env); | 508 GetMethodIDsImpl(env); |
| 509 | 509 |
| 510 static const JNINativeMethod kMethodsMyInnerClass[] = { | 510 static const JNINativeMethod kMethodsMyInnerClass[] = { |
| 511 { "nativeInit", | 511 { "nativeInit", |
| 512 "(" | 512 "(" |
| 513 ")" | 513 ")" |
| 514 "I", reinterpret_cast<void*>(Init) }, | 514 "I", reinterpret_cast<void*>(Init) }, |
| 515 }; | 515 }; |
| 516 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); | 516 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); |
| 517 | 517 |
| 518 if (env->RegisterNatives(g_MyInnerClass_clazz.obj(), | 518 if (env->RegisterNatives(g_MyInnerClass_clazz, |
| 519 kMethodsMyInnerClass, | 519 kMethodsMyInnerClass, |
| 520 kMethodsMyInnerClassSize) < 0) { | 520 kMethodsMyInnerClassSize) < 0) { |
| 521 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 521 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
| 522 return false; | 522 return false; |
| 523 } | 523 } |
| 524 | 524 |
| 525 return true; | 525 return true; |
| 526 } | 526 } |
| 527 | 527 |
| 528 #endif // org_chromium_TestJni_JNI | 528 #endif // org_chromium_TestJni_JNI |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 572 |
| 573 #include "base/android/jni_android.h" | 573 #include "base/android/jni_android.h" |
| 574 #include "base/android/scoped_java_ref.h" | 574 #include "base/android/scoped_java_ref.h" |
| 575 #include "base/basictypes.h" | 575 #include "base/basictypes.h" |
| 576 #include "base/logging.h" | 576 #include "base/logging.h" |
| 577 | 577 |
| 578 using base::android::ScopedJavaLocalRef; | 578 using base::android::ScopedJavaLocalRef; |
| 579 | 579 |
| 580 // Step 1: forward declarations. | 580 // Step 1: forward declarations. |
| 581 namespace { | 581 namespace { |
| 582 const char* const kMyOtherInnerClassClassPath = | 582 const char kMyOtherInnerClassClassPath[] = |
| 583 "org/chromium/TestJni$MyOtherInnerClass"; | 583 "org/chromium/TestJni$MyOtherInnerClass"; |
| 584 const char* const kTestJniClassPath = "org/chromium/TestJni"; | 584 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
| 585 const char* const kMyInnerClassClassPath = "org/chromium/TestJni$MyInnerClass"; | 585 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; |
| 586 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | 586 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 587 base::android::ScopedJavaGlobalRef<jclass>& | 587 jclass g_TestJni_clazz = NULL; |
| 588 g_TestJni_clazz = | |
| 589 *(new base::android::ScopedJavaGlobalRef<jclass>()); | |
| 590 } // namespace | 588 } // namespace |
| 591 | 589 |
| 592 static jint Init(JNIEnv* env, jobject obj); | 590 static jint Init(JNIEnv* env, jobject obj); |
| 593 | 591 |
| 594 | 592 |
| 595 static jint Init(JNIEnv* env, jobject obj); | 593 static jint Init(JNIEnv* env, jobject obj); |
| 596 | 594 |
| 597 | 595 |
| 598 // Step 2: method stubs. | 596 // Step 2: method stubs. |
| 599 | 597 |
| 600 | 598 |
| 601 // Step 3: GetMethodIDs and RegisterNatives. | 599 // Step 3: GetMethodIDs and RegisterNatives. |
| 602 | 600 |
| 603 | 601 |
| 604 static void GetMethodIDsImpl(JNIEnv* env) { | 602 static void GetMethodIDsImpl(JNIEnv* env) { |
| 605 g_TestJni_clazz.Reset( | 603 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 606 base::android::GetClass(env, kTestJniClassPath)); | 604 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
| 607 } | 605 } |
| 608 | 606 |
| 609 static bool RegisterNativesImpl(JNIEnv* env) { | 607 static bool RegisterNativesImpl(JNIEnv* env) { |
| 610 GetMethodIDsImpl(env); | 608 GetMethodIDsImpl(env); |
| 611 | 609 |
| 612 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { | 610 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { |
| 613 { "nativeInit", | 611 { "nativeInit", |
| 614 "(" | 612 "(" |
| 615 ")" | 613 ")" |
| 616 "I", reinterpret_cast<void*>(Init) }, | 614 "I", reinterpret_cast<void*>(Init) }, |
| 617 }; | 615 }; |
| 618 const int kMethodsMyOtherInnerClassSize = | 616 const int kMethodsMyOtherInnerClassSize = |
| 619 arraysize(kMethodsMyOtherInnerClass); | 617 arraysize(kMethodsMyOtherInnerClass); |
| 620 | 618 |
| 621 if (env->RegisterNatives(g_MyOtherInnerClass_clazz.obj(), | 619 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, |
| 622 kMethodsMyOtherInnerClass, | 620 kMethodsMyOtherInnerClass, |
| 623 kMethodsMyOtherInnerClassSize) < 0) { | 621 kMethodsMyOtherInnerClassSize) < 0) { |
| 624 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 622 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
| 625 return false; | 623 return false; |
| 626 } | 624 } |
| 627 | 625 |
| 628 static const JNINativeMethod kMethodsMyInnerClass[] = { | 626 static const JNINativeMethod kMethodsMyInnerClass[] = { |
| 629 { "nativeInit", | 627 { "nativeInit", |
| 630 "(" | 628 "(" |
| 631 ")" | 629 ")" |
| 632 "I", reinterpret_cast<void*>(Init) }, | 630 "I", reinterpret_cast<void*>(Init) }, |
| 633 }; | 631 }; |
| 634 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); | 632 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); |
| 635 | 633 |
| 636 if (env->RegisterNatives(g_MyInnerClass_clazz.obj(), | 634 if (env->RegisterNatives(g_MyInnerClass_clazz, |
| 637 kMethodsMyInnerClass, | 635 kMethodsMyInnerClass, |
| 638 kMethodsMyInnerClassSize) < 0) { | 636 kMethodsMyInnerClassSize) < 0) { |
| 639 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 637 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
| 640 return false; | 638 return false; |
| 641 } | 639 } |
| 642 | 640 |
| 643 return true; | 641 return true; |
| 644 } | 642 } |
| 645 | 643 |
| 646 #endif // org_chromium_TestJni_JNI | 644 #endif // org_chromium_TestJni_JNI |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 | 687 |
| 690 #include "base/android/jni_android.h" | 688 #include "base/android/jni_android.h" |
| 691 #include "base/android/scoped_java_ref.h" | 689 #include "base/android/scoped_java_ref.h" |
| 692 #include "base/basictypes.h" | 690 #include "base/basictypes.h" |
| 693 #include "base/logging.h" | 691 #include "base/logging.h" |
| 694 | 692 |
| 695 using base::android::ScopedJavaLocalRef; | 693 using base::android::ScopedJavaLocalRef; |
| 696 | 694 |
| 697 // Step 1: forward declarations. | 695 // Step 1: forward declarations. |
| 698 namespace { | 696 namespace { |
| 699 const char* const kMyOtherInnerClassClassPath = | 697 const char kMyOtherInnerClassClassPath[] = |
| 700 "org/chromium/TestJni$MyOtherInnerClass"; | 698 "org/chromium/TestJni$MyOtherInnerClass"; |
| 701 const char* const kTestJniClassPath = "org/chromium/TestJni"; | 699 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
| 702 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | 700 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 703 base::android::ScopedJavaGlobalRef<jclass>& | 701 jclass g_TestJni_clazz = NULL; |
| 704 g_TestJni_clazz = | |
| 705 *(new base::android::ScopedJavaGlobalRef<jclass>()); | |
| 706 } // namespace | 702 } // namespace |
| 707 | 703 |
| 708 static jint Init(JNIEnv* env, jobject obj); | 704 static jint Init(JNIEnv* env, jobject obj); |
| 709 | 705 |
| 710 | 706 |
| 711 static jint Init(JNIEnv* env, jobject obj); | 707 static jint Init(JNIEnv* env, jobject obj); |
| 712 | 708 |
| 713 | 709 |
| 714 // Step 2: method stubs. | 710 // Step 2: method stubs. |
| 715 | 711 |
| 716 | 712 |
| 717 // Step 3: GetMethodIDs and RegisterNatives. | 713 // Step 3: GetMethodIDs and RegisterNatives. |
| 718 | 714 |
| 719 | 715 |
| 720 static void GetMethodIDsImpl(JNIEnv* env) { | 716 static void GetMethodIDsImpl(JNIEnv* env) { |
| 721 g_TestJni_clazz.Reset( | 717 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 722 base::android::GetClass(env, kTestJniClassPath)); | 718 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
| 723 } | 719 } |
| 724 | 720 |
| 725 static bool RegisterNativesImpl(JNIEnv* env) { | 721 static bool RegisterNativesImpl(JNIEnv* env) { |
| 726 GetMethodIDsImpl(env); | 722 GetMethodIDsImpl(env); |
| 727 | 723 |
| 728 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { | 724 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { |
| 729 { "nativeInit", | 725 { "nativeInit", |
| 730 "(" | 726 "(" |
| 731 ")" | 727 ")" |
| 732 "I", reinterpret_cast<void*>(Init) }, | 728 "I", reinterpret_cast<void*>(Init) }, |
| 733 }; | 729 }; |
| 734 const int kMethodsMyOtherInnerClassSize = | 730 const int kMethodsMyOtherInnerClassSize = |
| 735 arraysize(kMethodsMyOtherInnerClass); | 731 arraysize(kMethodsMyOtherInnerClass); |
| 736 | 732 |
| 737 if (env->RegisterNatives(g_MyOtherInnerClass_clazz.obj(), | 733 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, |
| 738 kMethodsMyOtherInnerClass, | 734 kMethodsMyOtherInnerClass, |
| 739 kMethodsMyOtherInnerClassSize) < 0) { | 735 kMethodsMyOtherInnerClassSize) < 0) { |
| 740 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 736 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
| 741 return false; | 737 return false; |
| 742 } | 738 } |
| 743 | 739 |
| 744 static const JNINativeMethod kMethodsTestJni[] = { | 740 static const JNINativeMethod kMethodsTestJni[] = { |
| 745 { "nativeInit", | 741 { "nativeInit", |
| 746 "(" | 742 "(" |
| 747 ")" | 743 ")" |
| 748 "I", reinterpret_cast<void*>(Init) }, | 744 "I", reinterpret_cast<void*>(Init) }, |
| 749 }; | 745 }; |
| 750 const int kMethodsTestJniSize = arraysize(kMethodsTestJni); | 746 const int kMethodsTestJniSize = arraysize(kMethodsTestJni); |
| 751 | 747 |
| 752 if (env->RegisterNatives(g_TestJni_clazz.obj(), | 748 if (env->RegisterNatives(g_TestJni_clazz, |
| 753 kMethodsTestJni, | 749 kMethodsTestJni, |
| 754 kMethodsTestJniSize) < 0) { | 750 kMethodsTestJniSize) < 0) { |
| 755 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 751 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
| 756 return false; | 752 return false; |
| 757 } | 753 } |
| 758 | 754 |
| 759 return true; | 755 return true; |
| 760 } | 756 } |
| 761 | 757 |
| 762 #endif // org_chromium_TestJni_JNI | 758 #endif // org_chromium_TestJni_JNI |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 | 923 |
| 928 #include "base/android/jni_android.h" | 924 #include "base/android/jni_android.h" |
| 929 #include "base/android/scoped_java_ref.h" | 925 #include "base/android/scoped_java_ref.h" |
| 930 #include "base/basictypes.h" | 926 #include "base/basictypes.h" |
| 931 #include "base/logging.h" | 927 #include "base/logging.h" |
| 932 | 928 |
| 933 using base::android::ScopedJavaLocalRef; | 929 using base::android::ScopedJavaLocalRef; |
| 934 | 930 |
| 935 // Step 1: forward declarations. | 931 // Step 1: forward declarations. |
| 936 namespace { | 932 namespace { |
| 937 const char* const kTestJniClassPath = "org/chromium/TestJni"; | 933 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
| 938 const char* const kInfoBarClassPath = "org/chromium/TestJni$InfoBar"; | 934 const char kInfoBarClassPath[] = "org/chromium/TestJni$InfoBar"; |
| 939 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | 935 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 940 base::android::ScopedJavaGlobalRef<jclass>& | 936 jclass g_TestJni_clazz = NULL; |
| 941 g_TestJni_clazz = | 937 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 942 *(new base::android::ScopedJavaGlobalRef<jclass>()); | 938 jclass g_InfoBar_clazz = NULL; |
| 943 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | |
| 944 base::android::ScopedJavaGlobalRef<jclass>& | |
| 945 g_InfoBar_clazz = | |
| 946 *(new base::android::ScopedJavaGlobalRef<jclass>()); | |
| 947 } // namespace | 939 } // namespace |
| 948 | 940 |
| 949 | 941 |
| 950 // Step 2: method stubs. | 942 // Step 2: method stubs. |
| 951 | 943 |
| 952 static jmethodID g_TestJni_showConfirmInfoBar = 0; | 944 static jmethodID g_TestJni_showConfirmInfoBar = 0; |
| 953 static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, | 945 static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, |
| 954 jobject obj, jint nativeInfoBar, | 946 jobject obj, jint nativeInfoBar, |
| 955 jstring buttonOk, | 947 jstring buttonOk, |
| 956 jstring buttonCancel, | 948 jstring buttonCancel, |
| 957 jstring title, | 949 jstring title, |
| 958 jobject icon) { | 950 jobject icon) { |
| 959 /* Must call RegisterNativesImpl() */ | 951 /* Must call RegisterNativesImpl() */ |
| 960 DCHECK(!g_TestJni_clazz.is_null()); | 952 DCHECK(g_TestJni_clazz); |
| 961 DCHECK(g_TestJni_showConfirmInfoBar); | 953 DCHECK(g_TestJni_showConfirmInfoBar); |
| 962 jobject ret = | 954 jobject ret = |
| 963 env->CallObjectMethod(obj, | 955 env->CallObjectMethod(obj, |
| 964 g_TestJni_showConfirmInfoBar, nativeInfoBar, buttonOk, buttonCancel, | 956 g_TestJni_showConfirmInfoBar, nativeInfoBar, buttonOk, buttonCancel, |
| 965 title, icon); | 957 title, icon); |
| 966 base::android::CheckException(env); | 958 base::android::CheckException(env); |
| 967 return ScopedJavaLocalRef<jobject>(env, ret); | 959 return ScopedJavaLocalRef<jobject>(env, ret); |
| 968 } | 960 } |
| 969 | 961 |
| 970 static jmethodID g_TestJni_showAutoLoginInfoBar = 0; | 962 static jmethodID g_TestJni_showAutoLoginInfoBar = 0; |
| 971 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* | 963 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* |
| 972 env, jobject obj, jint nativeInfoBar, | 964 env, jobject obj, jint nativeInfoBar, |
| 973 jstring realm, | 965 jstring realm, |
| 974 jstring account, | 966 jstring account, |
| 975 jstring args) { | 967 jstring args) { |
| 976 /* Must call RegisterNativesImpl() */ | 968 /* Must call RegisterNativesImpl() */ |
| 977 DCHECK(!g_TestJni_clazz.is_null()); | 969 DCHECK(g_TestJni_clazz); |
| 978 DCHECK(g_TestJni_showAutoLoginInfoBar); | 970 DCHECK(g_TestJni_showAutoLoginInfoBar); |
| 979 jobject ret = | 971 jobject ret = |
| 980 env->CallObjectMethod(obj, | 972 env->CallObjectMethod(obj, |
| 981 g_TestJni_showAutoLoginInfoBar, nativeInfoBar, realm, account, args); | 973 g_TestJni_showAutoLoginInfoBar, nativeInfoBar, realm, account, args); |
| 982 base::android::CheckException(env); | 974 base::android::CheckException(env); |
| 983 return ScopedJavaLocalRef<jobject>(env, ret); | 975 return ScopedJavaLocalRef<jobject>(env, ret); |
| 984 } | 976 } |
| 985 | 977 |
| 986 static jmethodID g_InfoBar_dismiss = 0; | 978 static jmethodID g_InfoBar_dismiss = 0; |
| 987 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { | 979 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { |
| 988 /* Must call RegisterNativesImpl() */ | 980 /* Must call RegisterNativesImpl() */ |
| 989 DCHECK(!g_InfoBar_clazz.is_null()); | 981 DCHECK(g_InfoBar_clazz); |
| 990 DCHECK(g_InfoBar_dismiss); | 982 DCHECK(g_InfoBar_dismiss); |
| 991 | 983 |
| 992 env->CallVoidMethod(obj, | 984 env->CallVoidMethod(obj, |
| 993 g_InfoBar_dismiss); | 985 g_InfoBar_dismiss); |
| 994 base::android::CheckException(env); | 986 base::android::CheckException(env); |
| 995 | 987 |
| 996 } | 988 } |
| 997 | 989 |
| 998 static jmethodID g_TestJni_shouldShowAutoLogin = 0; | 990 static jmethodID g_TestJni_shouldShowAutoLogin = 0; |
| 999 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject | 991 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject |
| 1000 chromeView, | 992 chromeView, |
| 1001 jstring realm, | 993 jstring realm, |
| 1002 jstring account, | 994 jstring account, |
| 1003 jstring args) { | 995 jstring args) { |
| 1004 /* Must call RegisterNativesImpl() */ | 996 /* Must call RegisterNativesImpl() */ |
| 1005 DCHECK(!g_TestJni_clazz.is_null()); | 997 DCHECK(g_TestJni_clazz); |
| 1006 DCHECK(g_TestJni_shouldShowAutoLogin); | 998 DCHECK(g_TestJni_shouldShowAutoLogin); |
| 1007 jboolean ret = | 999 jboolean ret = |
| 1008 env->CallStaticBooleanMethod(g_TestJni_clazz.obj(), | 1000 env->CallStaticBooleanMethod(g_TestJni_clazz, |
| 1009 g_TestJni_shouldShowAutoLogin, chromeView, realm, account, args); | 1001 g_TestJni_shouldShowAutoLogin, chromeView, realm, account, args); |
| 1010 base::android::CheckException(env); | 1002 base::android::CheckException(env); |
| 1011 return ret; | 1003 return ret; |
| 1012 } | 1004 } |
| 1013 | 1005 |
| 1014 static jmethodID g_TestJni_openUrl = 0; | 1006 static jmethodID g_TestJni_openUrl = 0; |
| 1015 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring | 1007 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring |
| 1016 url) { | 1008 url) { |
| 1017 /* Must call RegisterNativesImpl() */ | 1009 /* Must call RegisterNativesImpl() */ |
| 1018 DCHECK(!g_TestJni_clazz.is_null()); | 1010 DCHECK(g_TestJni_clazz); |
| 1019 DCHECK(g_TestJni_openUrl); | 1011 DCHECK(g_TestJni_openUrl); |
| 1020 jobject ret = | 1012 jobject ret = |
| 1021 env->CallStaticObjectMethod(g_TestJni_clazz.obj(), | 1013 env->CallStaticObjectMethod(g_TestJni_clazz, |
| 1022 g_TestJni_openUrl, url); | 1014 g_TestJni_openUrl, url); |
| 1023 base::android::CheckException(env); | 1015 base::android::CheckException(env); |
| 1024 return ScopedJavaLocalRef<jobject>(env, ret); | 1016 return ScopedJavaLocalRef<jobject>(env, ret); |
| 1025 } | 1017 } |
| 1026 | 1018 |
| 1027 static jmethodID g_TestJni_activateHardwareAcceleration = 0; | 1019 static jmethodID g_TestJni_activateHardwareAcceleration = 0; |
| 1028 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, | 1020 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, |
| 1029 jboolean activated, | 1021 jboolean activated, |
| 1030 jint iPid, | 1022 jint iPid, |
| 1031 jint iType, | 1023 jint iType, |
| 1032 jint iPrimaryID, | 1024 jint iPrimaryID, |
| 1033 jint iSecondaryID) { | 1025 jint iSecondaryID) { |
| 1034 /* Must call RegisterNativesImpl() */ | 1026 /* Must call RegisterNativesImpl() */ |
| 1035 DCHECK(!g_TestJni_clazz.is_null()); | 1027 DCHECK(g_TestJni_clazz); |
| 1036 DCHECK(g_TestJni_activateHardwareAcceleration); | 1028 DCHECK(g_TestJni_activateHardwareAcceleration); |
| 1037 | 1029 |
| 1038 env->CallVoidMethod(obj, | 1030 env->CallVoidMethod(obj, |
| 1039 g_TestJni_activateHardwareAcceleration, activated, iPid, iType, | 1031 g_TestJni_activateHardwareAcceleration, activated, iPid, iType, |
| 1040 iPrimaryID, iSecondaryID); | 1032 iPrimaryID, iSecondaryID); |
| 1041 base::android::CheckException(env); | 1033 base::android::CheckException(env); |
| 1042 | 1034 |
| 1043 } | 1035 } |
| 1044 | 1036 |
| 1045 static jmethodID g_TestJni_uncheckedCall = 0; | 1037 static jmethodID g_TestJni_uncheckedCall = 0; |
| 1046 static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) { | 1038 static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) { |
| 1047 /* Must call RegisterNativesImpl() */ | 1039 /* Must call RegisterNativesImpl() */ |
| 1048 DCHECK(!g_TestJni_clazz.is_null()); | 1040 DCHECK(g_TestJni_clazz); |
| 1049 DCHECK(g_TestJni_uncheckedCall); | 1041 DCHECK(g_TestJni_uncheckedCall); |
| 1050 | 1042 |
| 1051 env->CallVoidMethod(obj, | 1043 env->CallVoidMethod(obj, |
| 1052 g_TestJni_uncheckedCall, iParam); | 1044 g_TestJni_uncheckedCall, iParam); |
| 1053 | 1045 |
| 1054 | 1046 |
| 1055 } | 1047 } |
| 1056 | 1048 |
| 1057 // Step 3: GetMethodIDs and RegisterNatives. | 1049 // Step 3: GetMethodIDs and RegisterNatives. |
| 1058 | 1050 |
| 1059 | 1051 |
| 1060 static void GetMethodIDsImpl(JNIEnv* env) { | 1052 static void GetMethodIDsImpl(JNIEnv* env) { |
| 1061 g_TestJni_clazz.Reset( | 1053 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1062 base::android::GetClass(env, kTestJniClassPath)); | 1054 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
| 1063 g_InfoBar_clazz.Reset( | 1055 g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1064 base::android::GetClass(env, kInfoBarClassPath)); | 1056 base::android::GetUnscopedClass(env, kInfoBarClassPath))); |
| 1065 g_TestJni_showConfirmInfoBar = base::android::GetMethodID( | 1057 g_TestJni_showConfirmInfoBar = |
| 1066 env, g_TestJni_clazz, | 1058 base::android::GetMethodID( |
| 1067 "showConfirmInfoBar", | 1059 env, g_TestJni_clazz, |
| 1060 "showConfirmInfoBar", |
| 1068 | 1061 |
| 1069 "(" | 1062 "(" |
| 1070 "I" | 1063 "I" |
| 1071 "Ljava/lang/String;" | 1064 "Ljava/lang/String;" |
| 1072 "Ljava/lang/String;" | 1065 "Ljava/lang/String;" |
| 1073 "Ljava/lang/String;" | 1066 "Ljava/lang/String;" |
| 1074 "Landroid/graphics/Bitmap;" | 1067 "Landroid/graphics/Bitmap;" |
| 1075 ")" | 1068 ")" |
| 1076 "Lcom/android/chrome/infobar/InfoBarContainer$NativeInfoBar;"); | 1069 "Lcom/android/chrome/infobar/InfoBarContainer$NativeInfoBar;"); |
| 1077 | 1070 |
| 1078 g_TestJni_showAutoLoginInfoBar = base::android::GetMethodID( | 1071 g_TestJni_showAutoLoginInfoBar = |
| 1079 env, g_TestJni_clazz, | 1072 base::android::GetMethodID( |
| 1080 "showAutoLoginInfoBar", | 1073 env, g_TestJni_clazz, |
| 1074 "showAutoLoginInfoBar", |
| 1081 | 1075 |
| 1082 "(" | 1076 "(" |
| 1083 "I" | 1077 "I" |
| 1084 "Ljava/lang/String;" | 1078 "Ljava/lang/String;" |
| 1085 "Ljava/lang/String;" | 1079 "Ljava/lang/String;" |
| 1086 "Ljava/lang/String;" | 1080 "Ljava/lang/String;" |
| 1087 ")" | 1081 ")" |
| 1088 "Lcom/android/chrome/infobar/InfoBarContainer$NativeInfoBar;"); | 1082 "Lcom/android/chrome/infobar/InfoBarContainer$NativeInfoBar;"); |
| 1089 | 1083 |
| 1090 g_InfoBar_dismiss = base::android::GetMethodID( | 1084 g_InfoBar_dismiss = |
| 1091 env, g_InfoBar_clazz, | 1085 base::android::GetMethodID( |
| 1092 "dismiss", | 1086 env, g_InfoBar_clazz, |
| 1087 "dismiss", |
| 1093 | 1088 |
| 1094 "(" | 1089 "(" |
| 1095 ")" | 1090 ")" |
| 1096 "V"); | 1091 "V"); |
| 1097 | 1092 |
| 1098 g_TestJni_shouldShowAutoLogin = base::android::GetStaticMethodID( | 1093 g_TestJni_shouldShowAutoLogin = |
| 1099 env, g_TestJni_clazz, | 1094 base::android::GetStaticMethodID( |
| 1100 "shouldShowAutoLogin", | 1095 env, g_TestJni_clazz, |
| 1096 "shouldShowAutoLogin", |
| 1101 | 1097 |
| 1102 "(" | 1098 "(" |
| 1103 "Lorg/chromium/chromeview/ChromeView;" | 1099 "Lorg/chromium/chromeview/ChromeView;" |
| 1104 "Ljava/lang/String;" | 1100 "Ljava/lang/String;" |
| 1105 "Ljava/lang/String;" | 1101 "Ljava/lang/String;" |
| 1106 "Ljava/lang/String;" | 1102 "Ljava/lang/String;" |
| 1107 ")" | 1103 ")" |
| 1108 "Z"); | 1104 "Z"); |
| 1109 | 1105 |
| 1110 g_TestJni_openUrl = base::android::GetStaticMethodID( | 1106 g_TestJni_openUrl = |
| 1111 env, g_TestJni_clazz, | 1107 base::android::GetStaticMethodID( |
| 1112 "openUrl", | 1108 env, g_TestJni_clazz, |
| 1109 "openUrl", |
| 1113 | 1110 |
| 1114 "(" | 1111 "(" |
| 1115 "Ljava/lang/String;" | 1112 "Ljava/lang/String;" |
| 1116 ")" | 1113 ")" |
| 1117 "Ljava/io/InputStream;"); | 1114 "Ljava/io/InputStream;"); |
| 1118 | 1115 |
| 1119 g_TestJni_activateHardwareAcceleration = base::android::GetMethodID( | 1116 g_TestJni_activateHardwareAcceleration = |
| 1120 env, g_TestJni_clazz, | 1117 base::android::GetMethodID( |
| 1121 "activateHardwareAcceleration", | 1118 env, g_TestJni_clazz, |
| 1119 "activateHardwareAcceleration", |
| 1122 | 1120 |
| 1123 "(" | 1121 "(" |
| 1124 "Z" | 1122 "Z" |
| 1125 "I" | 1123 "I" |
| 1126 "I" | 1124 "I" |
| 1127 "I" | 1125 "I" |
| 1128 "I" | 1126 "I" |
| 1129 ")" | 1127 ")" |
| 1130 "V"); | 1128 "V"); |
| 1131 | 1129 |
| 1132 g_TestJni_uncheckedCall = base::android::GetMethodID( | 1130 g_TestJni_uncheckedCall = |
| 1133 env, g_TestJni_clazz, | 1131 base::android::GetMethodID( |
| 1134 "uncheckedCall", | 1132 env, g_TestJni_clazz, |
| 1133 "uncheckedCall", |
| 1135 | 1134 |
| 1136 "(" | 1135 "(" |
| 1137 "I" | 1136 "I" |
| 1138 ")" | 1137 ")" |
| 1139 "V"); | 1138 "V"); |
| 1140 | 1139 |
| 1141 } | 1140 } |
| 1142 | 1141 |
| 1143 static bool RegisterNativesImpl(JNIEnv* env) { | 1142 static bool RegisterNativesImpl(JNIEnv* env) { |
| 1144 GetMethodIDsImpl(env); | 1143 GetMethodIDsImpl(env); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 | 1228 |
| 1230 #include "base/android/jni_android.h" | 1229 #include "base/android/jni_android.h" |
| 1231 #include "base/android/scoped_java_ref.h" | 1230 #include "base/android/scoped_java_ref.h" |
| 1232 #include "base/basictypes.h" | 1231 #include "base/basictypes.h" |
| 1233 #include "base/logging.h" | 1232 #include "base/logging.h" |
| 1234 | 1233 |
| 1235 using base::android::ScopedJavaLocalRef; | 1234 using base::android::ScopedJavaLocalRef; |
| 1236 | 1235 |
| 1237 // Step 1: forward declarations. | 1236 // Step 1: forward declarations. |
| 1238 namespace { | 1237 namespace { |
| 1239 const char* const kInputStreamClassPath = "java/io/InputStream"; | 1238 const char kInputStreamClassPath[] = "java/io/InputStream"; |
| 1240 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | 1239 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 1241 base::android::ScopedJavaGlobalRef<jclass>& | 1240 jclass g_InputStream_clazz = NULL; |
| 1242 g_InputStream_clazz = | |
| 1243 *(new base::android::ScopedJavaGlobalRef<jclass>()); | |
| 1244 } // namespace | 1241 } // namespace |
| 1245 | 1242 |
| 1246 | 1243 |
| 1247 // Step 2: method stubs. | 1244 // Step 2: method stubs. |
| 1248 | 1245 |
| 1249 static jmethodID g_InputStream_available = 0; | 1246 static jmethodID g_InputStream_available = 0; |
| 1250 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ | 1247 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ |
| 1251 ((unused)); | 1248 ((unused)); |
| 1252 static jint Java_InputStream_available(JNIEnv* env, jobject obj) { | 1249 static jint Java_InputStream_available(JNIEnv* env, jobject obj) { |
| 1253 /* Must call RegisterNativesImpl() */ | 1250 /* Must call RegisterNativesImpl() */ |
| 1254 DCHECK(!g_InputStream_clazz.is_null()); | 1251 DCHECK(g_InputStream_clazz); |
| 1255 DCHECK(g_InputStream_available); | 1252 DCHECK(g_InputStream_available); |
| 1256 jint ret = | 1253 jint ret = |
| 1257 env->CallIntMethod(obj, | 1254 env->CallIntMethod(obj, |
| 1258 g_InputStream_available); | 1255 g_InputStream_available); |
| 1259 base::android::CheckException(env); | 1256 base::android::CheckException(env); |
| 1260 return ret; | 1257 return ret; |
| 1261 } | 1258 } |
| 1262 | 1259 |
| 1263 static jmethodID g_InputStream_close = 0; | 1260 static jmethodID g_InputStream_close = 0; |
| 1264 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ | 1261 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ |
| 1265 ((unused)); | 1262 ((unused)); |
| 1266 static void Java_InputStream_close(JNIEnv* env, jobject obj) { | 1263 static void Java_InputStream_close(JNIEnv* env, jobject obj) { |
| 1267 /* Must call RegisterNativesImpl() */ | 1264 /* Must call RegisterNativesImpl() */ |
| 1268 DCHECK(!g_InputStream_clazz.is_null()); | 1265 DCHECK(g_InputStream_clazz); |
| 1269 DCHECK(g_InputStream_close); | 1266 DCHECK(g_InputStream_close); |
| 1270 | 1267 |
| 1271 env->CallVoidMethod(obj, | 1268 env->CallVoidMethod(obj, |
| 1272 g_InputStream_close); | 1269 g_InputStream_close); |
| 1273 base::android::CheckException(env); | 1270 base::android::CheckException(env); |
| 1274 | 1271 |
| 1275 } | 1272 } |
| 1276 | 1273 |
| 1277 static jmethodID g_InputStream_mark = 0; | 1274 static jmethodID g_InputStream_mark = 0; |
| 1278 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) | 1275 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) |
| 1279 __attribute__ ((unused)); | 1276 __attribute__ ((unused)); |
| 1280 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { | 1277 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { |
| 1281 /* Must call RegisterNativesImpl() */ | 1278 /* Must call RegisterNativesImpl() */ |
| 1282 DCHECK(!g_InputStream_clazz.is_null()); | 1279 DCHECK(g_InputStream_clazz); |
| 1283 DCHECK(g_InputStream_mark); | 1280 DCHECK(g_InputStream_mark); |
| 1284 | 1281 |
| 1285 env->CallVoidMethod(obj, | 1282 env->CallVoidMethod(obj, |
| 1286 g_InputStream_mark, p0); | 1283 g_InputStream_mark, p0); |
| 1287 base::android::CheckException(env); | 1284 base::android::CheckException(env); |
| 1288 | 1285 |
| 1289 } | 1286 } |
| 1290 | 1287 |
| 1291 static jmethodID g_InputStream_markSupported = 0; | 1288 static jmethodID g_InputStream_markSupported = 0; |
| 1292 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) | 1289 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) |
| 1293 __attribute__ ((unused)); | 1290 __attribute__ ((unused)); |
| 1294 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { | 1291 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { |
| 1295 /* Must call RegisterNativesImpl() */ | 1292 /* Must call RegisterNativesImpl() */ |
| 1296 DCHECK(!g_InputStream_clazz.is_null()); | 1293 DCHECK(g_InputStream_clazz); |
| 1297 DCHECK(g_InputStream_markSupported); | 1294 DCHECK(g_InputStream_markSupported); |
| 1298 jboolean ret = | 1295 jboolean ret = |
| 1299 env->CallBooleanMethod(obj, | 1296 env->CallBooleanMethod(obj, |
| 1300 g_InputStream_markSupported); | 1297 g_InputStream_markSupported); |
| 1301 base::android::CheckException(env); | 1298 base::android::CheckException(env); |
| 1302 return ret; | 1299 return ret; |
| 1303 } | 1300 } |
| 1304 | 1301 |
| 1305 static jmethodID g_InputStream_read_pqI = 0; | 1302 static jmethodID g_InputStream_read_pqI = 0; |
| 1306 static jint Java_InputStream_read(JNIEnv* env, jobject obj) __attribute__ | 1303 static jint Java_InputStream_read(JNIEnv* env, jobject obj) __attribute__ |
| 1307 ((unused)); | 1304 ((unused)); |
| 1308 static jint Java_InputStream_read(JNIEnv* env, jobject obj) { | 1305 static jint Java_InputStream_read(JNIEnv* env, jobject obj) { |
| 1309 /* Must call RegisterNativesImpl() */ | 1306 /* Must call RegisterNativesImpl() */ |
| 1310 DCHECK(!g_InputStream_clazz.is_null()); | 1307 DCHECK(g_InputStream_clazz); |
| 1311 DCHECK(g_InputStream_read_pqI); | 1308 DCHECK(g_InputStream_read_pqI); |
| 1312 jint ret = | 1309 jint ret = |
| 1313 env->CallIntMethod(obj, | 1310 env->CallIntMethod(obj, |
| 1314 g_InputStream_read_pqI); | 1311 g_InputStream_read_pqI); |
| 1315 base::android::CheckException(env); | 1312 base::android::CheckException(env); |
| 1316 return ret; | 1313 return ret; |
| 1317 } | 1314 } |
| 1318 | 1315 |
| 1319 static jmethodID g_InputStream_read_paBqI = 0; | 1316 static jmethodID g_InputStream_read_paBqI = 0; |
| 1320 static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0) | 1317 static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0) |
| 1321 __attribute__ ((unused)); | 1318 __attribute__ ((unused)); |
| 1322 static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0) { | 1319 static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0) { |
| 1323 /* Must call RegisterNativesImpl() */ | 1320 /* Must call RegisterNativesImpl() */ |
| 1324 DCHECK(!g_InputStream_clazz.is_null()); | 1321 DCHECK(g_InputStream_clazz); |
| 1325 DCHECK(g_InputStream_read_paBqI); | 1322 DCHECK(g_InputStream_read_paBqI); |
| 1326 jint ret = | 1323 jint ret = |
| 1327 env->CallIntMethod(obj, | 1324 env->CallIntMethod(obj, |
| 1328 g_InputStream_read_paBqI, p0); | 1325 g_InputStream_read_paBqI, p0); |
| 1329 base::android::CheckException(env); | 1326 base::android::CheckException(env); |
| 1330 return ret; | 1327 return ret; |
| 1331 } | 1328 } |
| 1332 | 1329 |
| 1333 static jmethodID g_InputStream_read_paBIIqI = 0; | 1330 static jmethodID g_InputStream_read_paBIIqI = 0; |
| 1334 static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0, | 1331 static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0, |
| 1335 jint p1, | 1332 jint p1, |
| 1336 jint p2) __attribute__ ((unused)); | 1333 jint p2) __attribute__ ((unused)); |
| 1337 static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0, | 1334 static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0, |
| 1338 jint p1, | 1335 jint p1, |
| 1339 jint p2) { | 1336 jint p2) { |
| 1340 /* Must call RegisterNativesImpl() */ | 1337 /* Must call RegisterNativesImpl() */ |
| 1341 DCHECK(!g_InputStream_clazz.is_null()); | 1338 DCHECK(g_InputStream_clazz); |
| 1342 DCHECK(g_InputStream_read_paBIIqI); | 1339 DCHECK(g_InputStream_read_paBIIqI); |
| 1343 jint ret = | 1340 jint ret = |
| 1344 env->CallIntMethod(obj, | 1341 env->CallIntMethod(obj, |
| 1345 g_InputStream_read_paBIIqI, p0, p1, p2); | 1342 g_InputStream_read_paBIIqI, p0, p1, p2); |
| 1346 base::android::CheckException(env); | 1343 base::android::CheckException(env); |
| 1347 return ret; | 1344 return ret; |
| 1348 } | 1345 } |
| 1349 | 1346 |
| 1350 static jmethodID g_InputStream_reset = 0; | 1347 static jmethodID g_InputStream_reset = 0; |
| 1351 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ | 1348 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ |
| 1352 ((unused)); | 1349 ((unused)); |
| 1353 static void Java_InputStream_reset(JNIEnv* env, jobject obj) { | 1350 static void Java_InputStream_reset(JNIEnv* env, jobject obj) { |
| 1354 /* Must call RegisterNativesImpl() */ | 1351 /* Must call RegisterNativesImpl() */ |
| 1355 DCHECK(!g_InputStream_clazz.is_null()); | 1352 DCHECK(g_InputStream_clazz); |
| 1356 DCHECK(g_InputStream_reset); | 1353 DCHECK(g_InputStream_reset); |
| 1357 | 1354 |
| 1358 env->CallVoidMethod(obj, | 1355 env->CallVoidMethod(obj, |
| 1359 g_InputStream_reset); | 1356 g_InputStream_reset); |
| 1360 base::android::CheckException(env); | 1357 base::android::CheckException(env); |
| 1361 | 1358 |
| 1362 } | 1359 } |
| 1363 | 1360 |
| 1364 static jmethodID g_InputStream_skip = 0; | 1361 static jmethodID g_InputStream_skip = 0; |
| 1365 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) | 1362 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) |
| 1366 __attribute__ ((unused)); | 1363 __attribute__ ((unused)); |
| 1367 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { | 1364 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { |
| 1368 /* Must call RegisterNativesImpl() */ | 1365 /* Must call RegisterNativesImpl() */ |
| 1369 DCHECK(!g_InputStream_clazz.is_null()); | 1366 DCHECK(g_InputStream_clazz); |
| 1370 DCHECK(g_InputStream_skip); | 1367 DCHECK(g_InputStream_skip); |
| 1371 jlong ret = | 1368 jlong ret = |
| 1372 env->CallLongMethod(obj, | 1369 env->CallLongMethod(obj, |
| 1373 g_InputStream_skip, p0); | 1370 g_InputStream_skip, p0); |
| 1374 base::android::CheckException(env); | 1371 base::android::CheckException(env); |
| 1375 return ret; | 1372 return ret; |
| 1376 } | 1373 } |
| 1377 | 1374 |
| 1378 // Step 3: GetMethodIDs and RegisterNatives. | 1375 // Step 3: GetMethodIDs and RegisterNatives. |
| 1379 namespace JNI_InputStream { | 1376 namespace JNI_InputStream { |
| 1380 | 1377 |
| 1381 static void GetMethodIDsImpl(JNIEnv* env) { | 1378 static void GetMethodIDsImpl(JNIEnv* env) { |
| 1382 g_InputStream_clazz.Reset( | 1379 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1383 base::android::GetClass(env, kInputStreamClassPath)); | 1380 base::android::GetUnscopedClass(env, kInputStreamClassPath))); |
| 1384 g_InputStream_available = base::android::GetMethodID( | 1381 g_InputStream_available = |
| 1385 env, g_InputStream_clazz, | 1382 base::android::GetMethodID( |
| 1386 "available", | 1383 env, g_InputStream_clazz, |
| 1384 "available", |
| 1387 | 1385 |
| 1388 "(" | 1386 "(" |
| 1389 ")" | 1387 ")" |
| 1390 "I"); | 1388 "I"); |
| 1391 | 1389 |
| 1392 g_InputStream_close = base::android::GetMethodID( | 1390 g_InputStream_close = |
| 1393 env, g_InputStream_clazz, | 1391 base::android::GetMethodID( |
| 1394 "close", | 1392 env, g_InputStream_clazz, |
| 1393 "close", |
| 1395 | 1394 |
| 1396 "(" | 1395 "(" |
| 1397 ")" | 1396 ")" |
| 1398 "V"); | 1397 "V"); |
| 1399 | 1398 |
| 1400 g_InputStream_mark = base::android::GetMethodID( | 1399 g_InputStream_mark = |
| 1401 env, g_InputStream_clazz, | 1400 base::android::GetMethodID( |
| 1402 "mark", | 1401 env, g_InputStream_clazz, |
| 1402 "mark", |
| 1403 | 1403 |
| 1404 "(" | 1404 "(" |
| 1405 "I" | 1405 "I" |
| 1406 ")" | 1406 ")" |
| 1407 "V"); | 1407 "V"); |
| 1408 | 1408 |
| 1409 g_InputStream_markSupported = base::android::GetMethodID( | 1409 g_InputStream_markSupported = |
| 1410 env, g_InputStream_clazz, | 1410 base::android::GetMethodID( |
| 1411 "markSupported", | 1411 env, g_InputStream_clazz, |
| 1412 "markSupported", |
| 1412 | 1413 |
| 1413 "(" | 1414 "(" |
| 1414 ")" | 1415 ")" |
| 1415 "Z"); | 1416 "Z"); |
| 1416 | 1417 |
| 1417 g_InputStream_read_pqI = base::android::GetMethodID( | 1418 g_InputStream_read_pqI = |
| 1418 env, g_InputStream_clazz, | 1419 base::android::GetMethodID( |
| 1419 "read", | 1420 env, g_InputStream_clazz, |
| 1421 "read", |
| 1420 | 1422 |
| 1421 "(" | 1423 "(" |
| 1422 ")" | 1424 ")" |
| 1423 "I"); | 1425 "I"); |
| 1424 | 1426 |
| 1425 g_InputStream_read_paBqI = base::android::GetMethodID( | 1427 g_InputStream_read_paBqI = |
| 1426 env, g_InputStream_clazz, | 1428 base::android::GetMethodID( |
| 1427 "read", | 1429 env, g_InputStream_clazz, |
| 1430 "read", |
| 1428 | 1431 |
| 1429 "(" | 1432 "(" |
| 1430 "[B" | 1433 "[B" |
| 1431 ")" | 1434 ")" |
| 1432 "I"); | 1435 "I"); |
| 1433 | 1436 |
| 1434 g_InputStream_read_paBIIqI = base::android::GetMethodID( | 1437 g_InputStream_read_paBIIqI = |
| 1435 env, g_InputStream_clazz, | 1438 base::android::GetMethodID( |
| 1436 "read", | 1439 env, g_InputStream_clazz, |
| 1440 "read", |
| 1437 | 1441 |
| 1438 "(" | 1442 "(" |
| 1439 "[B" | 1443 "[B" |
| 1440 "I" | 1444 "I" |
| 1441 "I" | 1445 "I" |
| 1442 ")" | 1446 ")" |
| 1443 "I"); | 1447 "I"); |
| 1444 | 1448 |
| 1445 g_InputStream_reset = base::android::GetMethodID( | 1449 g_InputStream_reset = |
| 1446 env, g_InputStream_clazz, | 1450 base::android::GetMethodID( |
| 1447 "reset", | 1451 env, g_InputStream_clazz, |
| 1452 "reset", |
| 1448 | 1453 |
| 1449 "(" | 1454 "(" |
| 1450 ")" | 1455 ")" |
| 1451 "V"); | 1456 "V"); |
| 1452 | 1457 |
| 1453 g_InputStream_skip = base::android::GetMethodID( | 1458 g_InputStream_skip = |
| 1454 env, g_InputStream_clazz, | 1459 base::android::GetMethodID( |
| 1455 "skip", | 1460 env, g_InputStream_clazz, |
| 1461 "skip", |
| 1456 | 1462 |
| 1457 "(" | 1463 "(" |
| 1458 "J" | 1464 "J" |
| 1459 ")" | 1465 ")" |
| 1460 "J"); | 1466 "J"); |
| 1461 | 1467 |
| 1462 } | 1468 } |
| 1463 | 1469 |
| 1464 static bool RegisterNativesImpl(JNIEnv* env) { | 1470 static bool RegisterNativesImpl(JNIEnv* env) { |
| 1465 JNI_InputStream::GetMethodIDsImpl(env); | 1471 JNI_InputStream::GetMethodIDsImpl(env); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 self.assertRaises(SystemExit, jni_generator.CheckFilenames, | 1524 self.assertRaises(SystemExit, jni_generator.CheckFilenames, |
| 1519 ['NotTheSame.java'], ['not_good.h']) | 1525 ['NotTheSame.java'], ['not_good.h']) |
| 1520 self.assertRaises(SystemExit, jni_generator.CheckFilenames, | 1526 self.assertRaises(SystemExit, jni_generator.CheckFilenames, |
| 1521 ['MissingJniSuffix.java'], ['missing_jni_suffix.h']) | 1527 ['MissingJniSuffix.java'], ['missing_jni_suffix.h']) |
| 1522 jni_generator.CheckFilenames(['ThisIsFine.java'], ['this_is_fine_jni.h']) | 1528 jni_generator.CheckFilenames(['ThisIsFine.java'], ['this_is_fine_jni.h']) |
| 1523 jni_generator.CheckFilenames([], []) | 1529 jni_generator.CheckFilenames([], []) |
| 1524 | 1530 |
| 1525 | 1531 |
| 1526 if __name__ == '__main__': | 1532 if __name__ == '__main__': |
| 1527 unittest.main() | 1533 unittest.main() |
| OLD | NEW |