Exemplo n.º 1
0
void
JavaBridge::stopSharedTimer()
{    
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return;
    env->CallVoidMethod(obj.get(), mStopSharedTimer);
}
Exemplo n.º 2
0
void
JavaBridge::setSharedTimer(long long timemillis)
{
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return;
    env->CallVoidMethod(obj.get(), mSetSharedTimer, timemillis);
}
Exemplo n.º 3
0
bool
JavaBridge::cookiesEnabled()
{
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return false;
    jboolean ret = env->CallBooleanMethod(obj.get(), mCookiesEnabled);
    return (ret != 0);
}
Exemplo n.º 4
0
void JavaBridge::signalServiceFuncPtrQueue()
{
    // In order to signal the main thread we must go through JNI. This
    // is the only usage on most threads, so we need to ensure a JNI
    // environment is setup.
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return;
    env->CallVoidMethod(obj.get(), mSignalFuncPtrQueue);
}
Exemplo n.º 5
0
WTF::String JavaBridge::resolveFilePathForContentUri(const WTF::String& uri) {
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return String();
    jstring jUri = wtfStringToJstring(env, uri);
    jstring path = static_cast<jstring>(env->CallObjectMethod(obj.get(), mResolveFilePathForContentUri, jUri));
    WTF::String ret = jstringToWtfString(env, path);
    env->DeleteLocalRef(jUri);
    env->DeleteLocalRef(path);
    return ret;
}
Exemplo n.º 6
0
WTF::String
JavaBridge::getPluginSharedDataDirectory()
{
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return String();
    jstring ret = (jstring)env->CallObjectMethod(obj.get(), mGetPluginSharedDataDirectory);
    WTF::String path = jstringToWtfString(env, ret);
    checkException(env);
    return path;
}
Exemplo n.º 7
0
void
JavaBridge::setCookies(WebCore::KURL const& url, WTF::String const& value)
{
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return;

    const WTF::String& urlStr = url.string();
    jstring jUrlStr = wtfStringToJstring(env, urlStr);
    jstring jValueStr = wtfStringToJstring(env, value);

    env->CallVoidMethod(obj.get(), mSetCookies, jUrlStr, jValueStr);
    env->DeleteLocalRef(jUrlStr);
    env->DeleteLocalRef(jValueStr);
}
Exemplo n.º 8
0
WTF::String JavaBridge::getSignedPublicKeyAndChallengeString(unsigned index,
        const WTF::String& challenge, const WebCore::KURL& url) {
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return String();
    jstring jChallenge = wtfStringToJstring(env, challenge);
    const WTF::String& urlStr = url.string();
    jstring jUrl = wtfStringToJstring(env, urlStr);
    jstring key = (jstring) env->CallObjectMethod(obj.get(),
            mGetSignedPublicKey, index, jChallenge, jUrl);
    WTF::String ret = jstringToWtfString(env, key);
    env->DeleteLocalRef(jChallenge);
    env->DeleteLocalRef(jUrl);
    env->DeleteLocalRef(key);
    return ret;
}
Exemplo n.º 9
0
WTF::String
JavaBridge::cookies(WebCore::KURL const& url)
{
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return String();

    const WTF::String& urlStr = url.string();
    jstring jUrlStr = wtfStringToJstring(env, urlStr);
    jstring string = (jstring)(env->CallObjectMethod(obj.get(), mCookies, jUrlStr));
    
    WTF::String ret = jstringToWtfString(env, string);
    env->DeleteLocalRef(jUrlStr);
    env->DeleteLocalRef(string);
    return ret;
}
Exemplo n.º 10
0
WTF::Vector<WTF::String>JavaBridge::getSupportedKeyStrengthList() {
    WTF::Vector<WTF::String> list;
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return list;
    jobjectArray array = (jobjectArray) env->CallObjectMethod(obj.get(),
            mGetKeyStrengthList);
    int count = env->GetArrayLength(array);
    for (int i = 0; i < count; ++i) {
        jstring keyStrength = (jstring) env->GetObjectArrayElement(array, i);
        list.append(jstringToWtfString(env, keyStrength));
        env->DeleteLocalRef(keyStrength);
    }
    env->DeleteLocalRef(array);
    checkException(env);
    return list;
}
Exemplo n.º 11
0
WTF::Vector<WTF::String>
JavaBridge::getPluginDirectories()
{
    WTF::Vector<WTF::String> directories;
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    AutoJObject obj = javaObject(env);
    if (!obj.get())
        return directories;
    jobjectArray array = (jobjectArray)
            env->CallObjectMethod(obj.get(), mGetPluginDirectories);
    int count = env->GetArrayLength(array);
    for (int i = 0; i < count; i++) {
        jstring dir = (jstring) env->GetObjectArrayElement(array, i);
        directories.append(jstringToWtfString(env, dir));
        env->DeleteLocalRef(dir);
    }
    env->DeleteLocalRef(array);
    checkException(env);
    return directories;
}
Exemplo n.º 12
0
/*
 * Class:     org_mahu_proto_jnitest_nativewrapper_HelloJNI
 * Method:    testSpecial
 * Signature: (I)I
 */
jint Java_org_mahu_proto_jnitest_nativewrapper_HelloJNI_testSpecial_helper
  (JNIEnv *env, jobject obj, jint test) 
{
  std::cout << "###  Java_org_mahu_proto_jnitest_nativewrapper_HelloJNI_testSpecial, test " << test << std::endl;

  switch(test) {
  case 0: // call method on object that returns a string. 
    {
	  JavaObject javaObjectDataClass(env,"org/mahu/proto/jnitest/nativewrapper/DataClass");
	  jobject stringObj = javaObjectDataClass.getObject("getStringValue","()Ljava/lang/String;"); 
	  JavaObject stringJavaObj(env, "java/lang/String",stringObj);
	  jint length = stringJavaObj.getInt("length");
	  std::cout << "Length of string is: " << length << std::endl;
      return 0;
    }
  case 1: // call field on object that returns a string. 
    {
	  JavaObject javaObjectDataClass(env,"org/mahu/proto/jnitest/nativewrapper/DataClass1");
	  jobject stringObj = javaObjectDataClass.getObjectField("stringValue","Ljava/lang/String;"); 
	  JavaObject stringJavaObj(env, "java/lang/String",stringObj);
	  jint length = stringJavaObj.getInt("length");
	  std::cout << "Length of string is: " << length << std::endl;
      return 0;
    }	
	case 2:
	{
	  MyClass myClass(env, *myGlobalClass, obj);
	  int value = myClass.test.get()+10;
	  myClass.test.set(value);
	  return myClass.test.get();
	}
	case 3: // JNI_SPECIAL_CASE_MYCLASS_GET_METHOD_INT
	{
	  MyClass myClass(env, *myGlobalClass, obj);
	  int value = myClass.intMethod.get()+10;
	  myClass.intMethod.set(value);
	  return myClass.intMethod.get();
	}	
	case 4: // JNI_SPECIAL_CASE_GET_SIZEOF_VOID_POINTER
	{
	  return sizeof(void *);
	}	
	case 5: // JNI_SPECIAL_CASE_GET_SIZEOF_JLONG
	{
	  return sizeof(jlong);
	}		
	case 6: // JNI_SPECIAL_CASE_LOAD_CLASS
	{
      JavaObject javaObjectDataClass(env,"org/mahu/proto/jnitest/nativewrapper/DataClass2");
	  jint intValue =  javaObjectDataClass.getIntField("intValue");
	  return intValue;
	}	
	case 7: // SEGV
	{
	  // baz();
	  return 1;
	}
	case 8: // JNI_SPECIAL_CASE_PRINT_OBJECTREF
	{
       std::cout << "HelloJNI objRef " << std::hex << std::showbase << obj << std::dec << std::endl;
	   for(int i=0; i<100; i++) {
         JavaObject javaObjectDataClass(env,"org/mahu/proto/jnitest/nativewrapper/DataClass2");	   
		 std::cout << "DataClass2 objRef " << std::hex << std::showbase 
				<< javaObjectDataClass.getJObject() << std::dec << std::endl;
	   }
	   break;
	}	
	case 9: // JNI_SPECIAL_CASE_BIG_ARRAY_READ
	{
		JavaObject javaObject(env, "org/mahu/proto/jnitest/nativewrapper/HelloJNI", obj);
		JByteArrayPtrIn byteArray(env, javaObject.getBytesField("specialBytes"));	
	    return 1;
	}
	default:
	  break;
  }
  return 1;
}