Bug 819154 Clean up string usage in Android Bridge r=blassey
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Thu, 13 Dec 2012 22:03:44 +0000
changeset 121558 c603d181b69eb02fa16ebfe11c6cceb5db582795
parent 121557 35e4ec23293cf0092ea0e61ecb2803d07c8274b2
child 121559 55b2d38ac36c986f3d76117be170f17e7dbde297
push idunknown
push userunknown
push dateunknown
reviewersblassey
bugs819154
milestone20.0a1
Bug 819154 Clean up string usage in Android Bridge r=blassey
widget/android/AndroidBridge.cpp
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -260,45 +260,47 @@ AndroidBridge::NotifyIME(int aType, int 
 
 jstring NewJavaString(AutoLocalJNIFrame* frame, const PRUnichar* string, uint32_t len) {
     jstring ret = frame->GetEnv()->NewString(string, len);
     if (frame->CheckForException())
         return NULL;
     return ret;
 }
 
-jstring NewJavaStringUTF(AutoLocalJNIFrame* frame, const char* string) {
-    jstring ret = frame->GetEnv()->NewStringUTF(string);
-    if (frame->CheckForException())
-        return NULL;
-    return ret;
+jstring NewJavaString(AutoLocalJNIFrame* frame, const nsAString& string) {
+    return NewJavaString(frame, string.BeginReading(), string.Length());
+}
+
+jstring NewJavaString(AutoLocalJNIFrame* frame, const char* string) {
+    return NewJavaString(frame, NS_ConvertUTF8toUTF16(string));
+}
+
+jstring NewJavaString(AutoLocalJNIFrame* frame, const nsACString& string) {
+    return NewJavaString(frame, NS_ConvertUTF8toUTF16(string));
 }
 
 void
 AndroidBridge::NotifyIMEEnabled(int aState, const nsAString& aTypeHint,
                                 const nsAString& aModeHint, const nsAString& aActionHint)
 {
     ALOG_BRIDGE("AndroidBridge::NotifyIMEEnabled");
     if (!sBridge)
         return;
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    nsPromiseFlatString typeHint(aTypeHint);
-    nsPromiseFlatString modeHint(aModeHint);
-    nsPromiseFlatString actionHint(aActionHint);
 
     jvalue args[5];
     args[0].i = aState;
-    args[1].l = NewJavaString(&jniFrame, typeHint.get(), typeHint.Length());
-    args[2].l = env->NewString(modeHint.get(), modeHint.Length());
-    args[3].l = env->NewString(actionHint.get(), actionHint.Length());
+    args[1].l = NewJavaString(&jniFrame, aTypeHint);
+    args[2].l = NewJavaString(&jniFrame, aModeHint);
+    args[3].l = NewJavaString(&jniFrame, aActionHint);
     args[4].z = false;
 
     int32_t landscapeFS;
     if (NS_SUCCEEDED(Preferences::GetInt(IME_FULLSCREEN_PREF, &landscapeFS))) {
         if (landscapeFS == 1) {
             args[4].z = true;
         } else if (landscapeFS == -1){
             if (NS_SUCCEEDED(
@@ -463,22 +465,19 @@ AndroidBridge::GetHandlersForMimeType(co
 {
     ALOG_BRIDGE("AndroidBridge::GetHandlersForMimeType");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return false;
 
     AutoLocalJNIFrame jniFrame(env);
-    NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
-    jstring jstrMimeType =
-        NewJavaString(&jniFrame, wMimeType.get(), wMimeType.Length());
-
-    jstring jstrAction = NewJavaString(&jniFrame, nsPromiseFlatString(aAction).get(),
-                                       aAction.Length());
+    jstring jstrMimeType = NewJavaString(&jniFrame, aMimeType);
+
+    jstring jstrAction = NewJavaString(&jniFrame, aAction);
 
     jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass,
                                               jGetHandlersForMimeType,
                                               jstrMimeType, jstrAction);
     if (jniFrame.CheckForException())
         return false;
 
     jobjectArray arr = static_cast<jobjectArray>(obj);
@@ -504,20 +503,18 @@ AndroidBridge::GetHandlersForURL(const c
 {
     ALOG_BRIDGE("AndroidBridge::GetHandlersForURL");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return false;
 
     AutoLocalJNIFrame jniFrame(env);
-    NS_ConvertUTF8toUTF16 wScheme(aURL);
-    jstring jstrScheme = NewJavaString(&jniFrame, wScheme.get(), wScheme.Length());
-    jstring jstrAction = NewJavaString(&jniFrame, nsPromiseFlatString(aAction).get(),
-                                       aAction.Length());
+    jstring jstrScheme = NewJavaString(&jniFrame, aURL);
+    jstring jstrAction = NewJavaString(&jniFrame, aAction);
 
     jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass,
                                               jGetHandlersForURL,
                                               jstrScheme, jstrAction);
     if (jniFrame.CheckForException())
         return false;
 
     jobjectArray arr = static_cast<jobjectArray>(obj);
@@ -541,30 +538,24 @@ AndroidBridge::OpenUriExternal(const nsA
 {
     ALOG_BRIDGE("AndroidBridge::OpenUriExternal");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return false;
 
     AutoLocalJNIFrame jniFrame(env);
-    NS_ConvertUTF8toUTF16 wUriSpec(aUriSpec);
-    NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
-
-    jstring jstrUri = NewJavaString(&jniFrame, wUriSpec.get(), wUriSpec.Length());
-    jstring jstrType = NewJavaString(&jniFrame, wMimeType.get(), wMimeType.Length());
-
-    jstring jstrPackage = NewJavaString(&jniFrame, nsPromiseFlatString(aPackageName).get(),
-                                        aPackageName.Length());
-    jstring jstrClass = NewJavaString(&jniFrame, nsPromiseFlatString(aClassName).get(),
-                                      aClassName.Length());
-    jstring jstrAction = NewJavaString(&jniFrame, nsPromiseFlatString(aAction).get(),
-                                       aAction.Length());
-    jstring jstrTitle = NewJavaString(&jniFrame, nsPromiseFlatString(aTitle).get(),
-                                      aTitle.Length());
+
+    jstring jstrUri = NewJavaString(&jniFrame, aUriSpec);
+    jstring jstrType = NewJavaString(&jniFrame, aMimeType);
+
+    jstring jstrPackage = NewJavaString(&jniFrame, aPackageName);
+    jstring jstrClass = NewJavaString(&jniFrame, aClassName);
+    jstring jstrAction = NewJavaString(&jniFrame, aAction);
+    jstring jstrTitle = NewJavaString(&jniFrame, aTitle);
 
     bool ret = env->CallStaticBooleanMethod(mGeckoAppShellClass,
                                             jOpenUriExternal,
                                             jstrUri, jstrType, jstrPackage,
                                             jstrClass, jstrAction, jstrTitle);
     if (jniFrame.CheckForException())
         return false;
 
@@ -576,50 +567,48 @@ AndroidBridge::GetMimeTypeFromExtensions
 {
     ALOG_BRIDGE("AndroidBridge::GetMimeTypeFromExtensions");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    NS_ConvertUTF8toUTF16 wFileExt(aFileExt);
-    jstring jstrExt = NewJavaString(&jniFrame, wFileExt.get(), wFileExt.Length());
+    jstring jstrExt = NewJavaString(&jniFrame, aFileExt);
     jstring jstrType =  static_cast<jstring>(
         env->CallStaticObjectMethod(mGeckoAppShellClass,
                                     jGetMimeTypeFromExtensions,
                                     jstrExt));
     if (jniFrame.CheckForException())
         return;
 
     nsJNIString jniStr(jstrType, env);
-    aMimeType.Assign(NS_ConvertUTF16toUTF8(jniStr.get()));
+    CopyUTF16toUTF8(jniStr.get(), aMimeType);
 }
 
 void
 AndroidBridge::GetExtensionFromMimeType(const nsACString& aMimeType, nsACString& aFileExt)
 {
     ALOG_BRIDGE("AndroidBridge::GetExtensionFromMimeType");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
-    jstring jstrType = NewJavaString(&jniFrame, wMimeType.get(), wMimeType.Length());
+    jstring jstrType = NewJavaString(&jniFrame, aMimeType);
     jstring jstrExt = static_cast<jstring>(
         env->CallStaticObjectMethod(mGeckoAppShellClass,
                                     jGetExtensionFromMimeType,
                                     jstrType));
     if (jniFrame.CheckForException())
         return;
 
     nsJNIString jniStr(jstrExt, env);
-    aFileExt.Assign(NS_ConvertUTF16toUTF8(jniStr.get()));
+    CopyUTF16toUTF8(jniStr.get(), aFileExt);
 }
 
 void
 AndroidBridge::MoveTaskToBack()
 {
     ALOG_BRIDGE("AndroidBridge::MoveTaskToBack");
 
     JNIEnv *env = GetJNIEnv();
@@ -656,18 +645,17 @@ AndroidBridge::SetClipboardText(const ns
 {
     ALOG_BRIDGE("AndroidBridge::SetClipboardText");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jstr = NewJavaString(&jniFrame, nsPromiseFlatString(aText).get(),
-                                 aText.Length());
+    jstring jstr = NewJavaString(&jniFrame, aText);
     env->CallStaticVoidMethod(mGeckoAppShellClass, jSetClipboardText, jstr);
 }
 
 bool
 AndroidBridge::ClipboardHasText()
 {
     ALOG_BRIDGE("AndroidBridge::ClipboardHasText");
 
@@ -713,55 +701,55 @@ AndroidBridge::ShowAlertNotification(con
         return;
 
     AutoLocalJNIFrame jniFrame(env);
 
     if (nsAppShell::gAppShell && aAlertListener)
         nsAppShell::gAppShell->AddObserver(aAlertName, aAlertListener);
 
     jvalue args[5];
-    args[0].l = NewJavaString(&jniFrame, nsPromiseFlatString(aImageUrl).get(), aImageUrl.Length());
-    args[1].l = NewJavaString(&jniFrame, nsPromiseFlatString(aAlertTitle).get(), aAlertTitle.Length());
-    args[2].l = NewJavaString(&jniFrame, nsPromiseFlatString(aAlertText).get(), aAlertText.Length());
-    args[3].l = NewJavaString(&jniFrame, nsPromiseFlatString(aAlertCookie).get(), aAlertCookie.Length());
-    args[4].l = NewJavaString(&jniFrame, nsPromiseFlatString(aAlertName).get(), aAlertName.Length());
+    args[0].l = NewJavaString(&jniFrame, aImageUrl);
+    args[1].l = NewJavaString(&jniFrame, aAlertTitle);
+    args[2].l = NewJavaString(&jniFrame, aAlertText);
+    args[3].l = NewJavaString(&jniFrame, aAlertCookie);
+    args[4].l = NewJavaString(&jniFrame, aAlertName);
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jShowAlertNotification, args);
 }
 
 void
 AndroidBridge::AlertsProgressListener_OnProgress(const nsAString& aAlertName,
                                                  int64_t aProgress,
                                                  int64_t aProgressMax,
                                                  const nsAString& aAlertText)
 {
     ALOG_BRIDGE("AlertsProgressListener_OnProgress");
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
 
-    jstring jstrName = NewJavaString(&jniFrame, nsPromiseFlatString(aAlertName).get(), aAlertName.Length());
-    jstring jstrText = NewJavaString(&jniFrame, nsPromiseFlatString(aAlertText).get(), aAlertText.Length());
+    jstring jstrName = NewJavaString(&jniFrame, aAlertName);
+    jstring jstrText = NewJavaString(&jniFrame, aAlertText);
     env->CallStaticVoidMethod(mGeckoAppShellClass, jAlertsProgressListener_OnProgress,
                               jstrName, aProgress, aProgressMax, jstrText);
 }
 
 void
 AndroidBridge::AlertsProgressListener_OnCancel(const nsAString& aAlertName)
 {
     ALOG_BRIDGE("AlertsProgressListener_OnCancel");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
 
-    jstring jstrName = NewJavaString(&jniFrame, nsPromiseFlatString(aAlertName).get(), aAlertName.Length());
+    jstring jstrName = NewJavaString(&jniFrame, aAlertName);
     env->CallStaticVoidMethod(mGeckoAppShellClass, jAlertsProgressListener_OnCancel, jstrName);
 }
 
 
 int
 AndroidBridge::GetDPI()
 {
     static int sDPI = 0;
@@ -789,18 +777,17 @@ AndroidBridge::ShowFilePickerForExtensio
 {
     ALOG_BRIDGE("AndroidBridge::ShowFilePickerForExtensions");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jstrFilers = NewJavaString(&jniFrame, nsPromiseFlatString(aExtensions).get(),
-                                       aExtensions.Length());
+    jstring jstrFilers = NewJavaString(&jniFrame, aExtensions);
     jstring jstr = static_cast<jstring>(env->CallStaticObjectMethod(
                                             mGeckoAppShellClass,
                                             jShowFilePickerForExtensions, jstrFilers));
     if (jniFrame.CheckForException())
         return;
 
     aFilePath.Assign(nsJNIString(jstr, env));
 }
@@ -810,18 +797,17 @@ AndroidBridge::ShowFilePickerForMimeType
 {
     ALOG_BRIDGE("AndroidBridge::ShowFilePickerForMimeType");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jstrFilers = NewJavaString(&jniFrame, nsPromiseFlatString(aMimeType).get(),
-                                       aMimeType.Length());
+    jstring jstrFilers = NewJavaString(&jniFrame, aMimeType);
     jstring jstr = static_cast<jstring>(env->CallStaticObjectMethod(
                                             mGeckoAppShellClass,
                                             jShowFilePickerForMimeType, jstrFilers));
     if (jniFrame.CheckForException())
         return;
 
     aFilePath.Assign(nsJNIString(jstr, env));
 }
@@ -829,18 +815,17 @@ AndroidBridge::ShowFilePickerForMimeType
 void
 AndroidBridge::ShowFilePickerAsync(const nsAString& aMimeType, nsFilePickerCallback* callback)
 {
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jMimeType = NewJavaString(&jniFrame, nsPromiseFlatString(aMimeType).get(),
-                                      aMimeType.Length());
+    jstring jMimeType = NewJavaString(&jniFrame, aMimeType);
     callback->AddRef();
     env->CallStaticVoidMethod(mGeckoAppShellClass, jShowFilePickerAsync, jMimeType, (jlong) callback);
 }
 
 void
 AndroidBridge::SetFullScreen(bool aFullScreen)
 {
     ALOG_BRIDGE("AndroidBridge::SetFullScreen");
@@ -990,17 +975,17 @@ AndroidBridge::SetSelectedLocale(const n
 {
     ALOG_BRIDGE("AndroidBridge::SetSelectedLocale");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jLocale = NewJavaString(&jniFrame, PromiseFlatString(aLocale).get(), aLocale.Length());
+    jstring jLocale = NewJavaString(&jniFrame, aLocale);
     env->CallStaticVoidMethod(mGeckoAppShellClass, jSetSelectedLocale, jLocale);
 }
 
 void
 AndroidBridge::GetSystemColors(AndroidSystemColors *aColors)
 {
     ALOG_BRIDGE("AndroidBridge::GetSystemColors");
 
@@ -1051,19 +1036,17 @@ AndroidBridge::GetIconForExtension(const
         return;
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
 
-    nsString fileExt;
-    CopyUTF8toUTF16(aFileExt, fileExt);
-    jstring jstrFileExt = NewJavaString(&jniFrame, nsPromiseFlatString(fileExt).get(), fileExt.Length());
+    jstring jstrFileExt = NewJavaString(&jniFrame, aFileExt);
 
     jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetIconForExtension, jstrFileExt, aIconSize);
     if (jniFrame.CheckForException())
         return;
 
     jbyteArray arr = static_cast<jbyteArray>(obj);
     NS_ASSERTION(arr != nullptr, "AndroidBridge::GetIconForExtension: Returned pixels array is null!");
     if (!arr)
@@ -1309,37 +1292,35 @@ jclass GetGeckoAppShellClass()
 void
 AndroidBridge::ScanMedia(const nsAString& aFile, const nsACString& aMimeType)
 {
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jstrFile = NewJavaString(&jniFrame, nsPromiseFlatString(aFile).get(), aFile.Length());
-
-    nsString mimeType2;
-    CopyUTF8toUTF16(aMimeType, mimeType2);
-    jstring jstrMimeTypes = NewJavaString(&jniFrame, nsPromiseFlatString(mimeType2).get(), mimeType2.Length());
+    jstring jstrFile = NewJavaString(&jniFrame, aFile);
+
+    jstring jstrMimeTypes = NewJavaString(&jniFrame, aMimeType);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jScanMedia, jstrFile, jstrMimeTypes);
 }
 
 void
 AndroidBridge::CreateShortcut(const nsAString& aTitle, const nsAString& aURI, const nsAString& aIconData, const nsAString& aIntent)
 {
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jstrTitle = NewJavaString(&jniFrame, nsPromiseFlatString(aTitle).get(), aTitle.Length());
-    jstring jstrURI = NewJavaString(&jniFrame, nsPromiseFlatString(aURI).get(), aURI.Length());
-    jstring jstrIconData = NewJavaString(&jniFrame, nsPromiseFlatString(aIconData).get(), aIconData.Length());
-    jstring jstrIntent = NewJavaString(&jniFrame, nsPromiseFlatString(aIntent).get(), aIntent.Length());
+    jstring jstrTitle = NewJavaString(&jniFrame, aTitle);
+    jstring jstrURI = NewJavaString(&jniFrame, aURI);
+    jstring jstrIconData = NewJavaString(&jniFrame, aIconData);
+    jstring jstrIntent = NewJavaString(&jniFrame, aIntent);
 
     if (!jstrURI || !jstrTitle || !jstrIconData)
         return;
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jCreateShortcut, jstrTitle, jstrURI, jstrIconData, jstrIntent);
 }
 
 void*
@@ -1534,18 +1515,17 @@ bool
 AndroidBridge::InitCamera(const nsCString& contentType, uint32_t camera, uint32_t *width, uint32_t *height, uint32_t *fps)
 {
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return false;
 
     AutoLocalJNIFrame jniFrame(env);
 
-    NS_ConvertASCIItoUTF16 s(contentType);
-    jstring jstrContentType = NewJavaString(&jniFrame, s.get(), NS_strlen(s.get()));
+    jstring jstrContentType = NewJavaString(&jniFrame, contentType);
 
     jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass, jInitCamera, jstrContentType, camera, *width, *height);
     if (jniFrame.CheckForException())
         return false;
 
     jintArray arr = static_cast<jintArray>(obj);
     if (!arr)
         return false;
@@ -1637,17 +1617,17 @@ AndroidBridge::HandleGeckoMessage(const 
 {
     ALOG_BRIDGE("%s", __PRETTY_FUNCTION__);
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jMessage = NewJavaString(&jniFrame, nsPromiseFlatString(aMessage).get(), aMessage.Length());
+    jstring jMessage = NewJavaString(&jniFrame, aMessage);
     jstring returnMessage =  static_cast<jstring>(env->CallStaticObjectMethod(mGeckoAppShellClass, jHandleGeckoMessage, jMessage));
     if (jniFrame.CheckForException())
         return;
 
     nsJNIString jniStr(returnMessage, env);
     aRet.Assign(jniStr);
     ALOG_BRIDGE("leaving %s", __PRETTY_FUNCTION__);
 }
@@ -1655,45 +1635,45 @@ AndroidBridge::HandleGeckoMessage(const 
 void
 AndroidBridge::CheckURIVisited(const nsAString& aURI)
 {
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env, 1);
-    jstring jstrURI = NewJavaString(&jniFrame, nsPromiseFlatString(aURI).get(), aURI.Length());
+    jstring jstrURI = NewJavaString(&jniFrame, aURI);
     // If creating the string fails, just bail
     if (jstrURI)
         env->CallStaticVoidMethod(mGeckoAppShellClass, jCheckUriVisited, jstrURI);
 }
 
 void
 AndroidBridge::MarkURIVisited(const nsAString& aURI)
 {
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jstrURI = NewJavaString(&jniFrame, nsPromiseFlatString(aURI).get(), aURI.Length());
+    jstring jstrURI = NewJavaString(&jniFrame, aURI);
     env->CallStaticVoidMethod(mGeckoAppShellClass, jMarkUriVisited, jstrURI);
 }
 
 uint16_t
 AndroidBridge::GetNumberOfMessagesForText(const nsAString& aText)
 {
     ALOG_BRIDGE("AndroidBridge::GetNumberOfMessagesForText");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return 0;
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jText = NewJavaString(&jniFrame, PromiseFlatString(aText).get(), aText.Length());
+    jstring jText = NewJavaString(&jniFrame, aText);
     uint16_t ret = env->CallStaticIntMethod(mGeckoAppShellClass, jNumberOfMessages, jText);
     if (jniFrame.CheckForException())
         return 0;
 
     return ret;
 }
 
 void
@@ -1704,18 +1684,18 @@ AndroidBridge::SendMessage(const nsAStri
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     int32_t requestId = QueueSmsRequest(aRequest);
     NS_ENSURE_TRUE_VOID(requestId >= 0);
 
     AutoLocalJNIFrame jniFrame(env);
-    jstring jNumber = NewJavaString(&jniFrame, PromiseFlatString(aNumber).get(), aNumber.Length());
-    jstring jMessage = NewJavaString(&jniFrame, PromiseFlatString(aMessage).get(), aMessage.Length());
+    jstring jNumber = NewJavaString(&jniFrame, aNumber);
+    jstring jMessage = NewJavaString(&jniFrame, aMessage);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jSendMessage, jNumber, jMessage, requestId);
 }
 
 void
 AndroidBridge::GetMessage(int32_t aMessageId, nsISmsRequest* aRequest)
 {
     ALOG_BRIDGE("AndroidBridge::GetMessage");
@@ -1760,21 +1740,21 @@ AndroidBridge::CreateMessageList(const d
     int32_t requestId = QueueSmsRequest(aRequest);
     NS_ENSURE_TRUE_VOID(requestId >= 0);
 
     AutoLocalJNIFrame jniFrame(env);
 
     jobjectArray numbers =
         (jobjectArray)env->NewObjectArray(aFilter.numbers().Length(),
                                           jStringClass,
-                                          NewJavaStringUTF(&jniFrame, ""));
+                                          NewJavaString(&jniFrame, EmptyString()));
 
     for (uint32_t i = 0; i < aFilter.numbers().Length(); ++i) {
         env->SetObjectArrayElement(numbers, i,
-                                   NewJavaStringUTF(&jniFrame, NS_ConvertUTF16toUTF8(aFilter.numbers()[i]).get()));
+                                   NewJavaString(&jniFrame, aFilter.numbers()[i]));
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jCreateMessageList,
                               aFilter.startDate(), aFilter.endDate(),
                               numbers, aFilter.numbers().Length(),
                               aFilter.delivery(), aReverse, requestId);
 }
 
@@ -2315,20 +2295,18 @@ void
 AndroidBridge::NotifyWakeLockChanged(const nsAString& topic, const nsAString& state)
 {
     JNIEnv* env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
 
-    jstring jstrTopic = NewJavaString(&jniFrame, nsPromiseFlatString(topic).get(),
-                                      topic.Length());
-    jstring jstrState = NewJavaString(&jniFrame, nsPromiseFlatString(state).get(),
-                                      state.Length());
+    jstring jstrTopic = NewJavaString(&jniFrame, topic);
+    jstring jstrState = NewJavaString(&jniFrame, state);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jNotifyWakeLockChanged, jstrTopic, jstrState);
 }
 
 void
 AndroidBridge::ScheduleComposite()
 {
 #if MOZ_ANDROID_OMTC
@@ -2374,34 +2352,32 @@ AndroidBridge::GetGfxInfoData(nsACString
         (env->CallStaticObjectMethod(mGeckoAppShellClass, jGetGfxInfoData));
     if (jniFrame.CheckForException())
         return;
 
     nsJNIString jniStr(jstrRet, env);
     CopyUTF16toUTF8(jniStr, aRet);
 }
 
-#define CREATE_JAVA_STRING(name) jstring j##name = NewJavaStringUTF(&jniFrame, nsPromiseFlatCString(a##name).get())
-
 nsresult
 AndroidBridge::GetProxyForURI(const nsACString & aSpec,
                               const nsACString & aScheme,
                               const nsACString & aHost,
                               const int32_t      aPort,
                               nsACString & aResult)
 {
     JNIEnv* env = GetJNIEnv();
     if (!env)
         return NS_ERROR_FAILURE;
 
     AutoLocalJNIFrame jniFrame(env);
 
-    CREATE_JAVA_STRING(Spec);
-    CREATE_JAVA_STRING(Scheme);
-    CREATE_JAVA_STRING(Host);
+    jstring jSpec = NewJavaString(&jniFrame, aSpec);
+    jstring jScheme = NewJavaString(&jniFrame, aScheme);
+    jstring jHost = NewJavaString(&jniFrame, aHost);
     jstring jstrRet = static_cast<jstring>
         (env->CallStaticObjectMethod(mGeckoAppShellClass, jGetProxyForURI, jSpec, jScheme, jHost, aPort));
 
     if (jniFrame.CheckForException())
         return NS_ERROR_FAILURE;
 
     nsJNIString jniStr(jstrRet, env);
     CopyUTF16toUTF8(jniStr, aResult);