Bug 906088 - part 2 - factor out reading an nsString from a Java string in AndroidJavaWrappers.cpp; r=blassey

We duplicate code in several places, and we're going to need this same code for reading
a String[].
This commit is contained in:
Nathan Froyd 2013-09-04 09:58:00 -04:00
parent 9b166be0c7
commit 5a8ea91082
2 changed files with 15 additions and 21 deletions

View File

@ -428,45 +428,38 @@ AndroidGeckoEvent::ReadRectField(JNIEnv *jenv)
}
void
AndroidGeckoEvent::ReadCharactersField(JNIEnv *jenv)
AndroidGeckoEvent::ReadStringFromJString(nsString &aString, JNIEnv *jenv,
jstring s)
{
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersField);
if (!s) {
mCharacters.SetIsVoid(true);
aString.SetIsVoid(true);
return;
}
int len = jenv->GetStringLength(s);
mCharacters.SetLength(len);
jenv->GetStringRegion(s, 0, len, mCharacters.BeginWriting());
aString.SetLength(len);
jenv->GetStringRegion(s, 0, len, aString.BeginWriting());
}
void
AndroidGeckoEvent::ReadCharactersField(JNIEnv *jenv)
{
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersField);
ReadStringFromJString(mCharacters, jenv, s);
}
void
AndroidGeckoEvent::ReadCharactersExtraField(JNIEnv *jenv)
{
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersExtraField);
if (!s) {
mCharactersExtra.SetIsVoid(true);
return;
}
int len = jenv->GetStringLength(s);
mCharactersExtra.SetLength(len);
jenv->GetStringRegion(s, 0, len, mCharactersExtra.BeginWriting());
ReadStringFromJString(mCharactersExtra, jenv, s);
}
void
AndroidGeckoEvent::ReadDataField(JNIEnv *jenv)
{
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jDataField);
if (!s) {
mData.SetIsVoid(true);
return;
}
int len = jenv->GetStringLength(s);
mData.SetLength(len);
jenv->GetStringRegion(s, 0, len, mData.BeginWriting());
ReadStringFromJString(mData, jenv, s);
}
void

View File

@ -639,6 +639,7 @@ protected:
void ReadCharactersField(JNIEnv *jenv);
void ReadCharactersExtraField(JNIEnv *jenv);
void ReadDataField(JNIEnv *jenv);
void ReadStringFromJString(nsString &aString, JNIEnv *jenv, jstring s);
uint32_t ReadDomKeyLocation(JNIEnv* jenv, jobject jGeckoEventObj);