Bug 794981 - Part 4: Consistently pass nsAString into the JNI methods, instead of the veritable smorgasbord of string types previously used. r=kats
authorChris Kitching <ckitching@mozilla.com>
Mon, 09 Sep 2013 08:57:36 -0400
changeset 159089 dd937e69cd401157c54b36697e1007210b371b57
parent 159088 402235f97f68330b75f5c8c7daf29b363a944927
child 159090 78aa104740c16f54551b1ba7a918bdb7a193020f
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs794981
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 794981 - Part 4: Consistently pass nsAString into the JNI methods, instead of the veritable smorgasbord of string types previously used. r=kats
toolkit/components/downloads/nsDownloadManager.cpp
toolkit/components/jsdownloads/src/DownloadPlatform.cpp
uriloader/exthandler/android/nsAndroidHandlerApp.cpp
uriloader/exthandler/android/nsExternalSharingAppService.cpp
uriloader/exthandler/android/nsMIMEInfoAndroid.cpp
uriloader/exthandler/android/nsOSHelperAppService.cpp
widget/android/AndroidBridge.cpp
widget/android/AndroidBridge.h
widget/android/nsWindow.cpp
xpcom/io/nsLocalFileUnix.cpp
--- a/toolkit/components/downloads/nsDownloadManager.cpp
+++ b/toolkit/components/downloads/nsDownloadManager.cpp
@@ -2770,17 +2770,17 @@ nsDownload::SetState(DownloadState aStat
 #ifdef MOZ_WIDGET_ANDROID
         nsCOMPtr<nsIMIMEInfo> mimeInfo;
         nsAutoCString contentType;
         GetMIMEInfo(getter_AddRefs(mimeInfo));
 
         if (mimeInfo)
           mimeInfo->GetMIMEType(contentType);
 
-        mozilla::AndroidBridge::Bridge()->ScanMedia(path, contentType);
+        mozilla::AndroidBridge::Bridge()->ScanMedia(path, NS_ConvertUTF8toUTF16(contentType));
 #endif
       }
 
 #ifdef XP_WIN
       // Adjust file attributes so that by default, new files are indexed
       // by desktop search services. Skip off those that land in the temp
       // folder.
       nsCOMPtr<nsIFile> tempDir, fileDir;
--- a/toolkit/components/jsdownloads/src/DownloadPlatform.cpp
+++ b/toolkit/components/jsdownloads/src/DownloadPlatform.cpp
@@ -113,17 +113,17 @@ nsresult DownloadPlatform::DownloadDone(
                                              kCFStringEncodingUTF8);
     CFNotificationCenterRef center = ::CFNotificationCenterGetDistributedCenter();
     ::CFNotificationCenterPostNotification(center, CFSTR("com.apple.DownloadFileFinished"),
                                            observedObject, NULL, TRUE);
     ::CFRelease(observedObject);
 #endif
 #ifdef MOZ_WIDGET_ANDROID
     if (!aContentType.IsEmpty()) {
-      mozilla::AndroidBridge::Bridge()->ScanMedia(path, aContentType);
+      mozilla::AndroidBridge::Bridge()->ScanMedia(path, NS_ConvertUTF8toUTF16(aContentType));
     }
 #endif
   }
 
 #ifdef XP_WIN
   // Adjust file attributes so that by default, new files are indexed by
   // desktop search services. Skip off those that land in the temp folder.
   nsCOMPtr<nsIFile> tempDir, fileDir;
--- a/uriloader/exthandler/android/nsAndroidHandlerApp.cpp
+++ b/uriloader/exthandler/android/nsAndroidHandlerApp.cpp
@@ -66,23 +66,23 @@ NS_IMETHODIMP
 nsAndroidHandlerApp::LaunchWithURI(nsIURI *aURI, nsIInterfaceRequestor *aWindowContext)
 {
   if (!mozilla::AndroidBridge::Bridge())
     return NS_ERROR_FAILURE;
 
   nsCString uriSpec;
   aURI->GetSpec(uriSpec);
   return mozilla::AndroidBridge::Bridge()->
-    OpenUriExternal(uriSpec, mMimeType, mPackageName, mClassName, mAction) ? 
+    OpenUriExternal(NS_ConvertUTF8toUTF16(uriSpec), NS_ConvertUTF8toUTF16(mMimeType), mPackageName, mClassName, mAction) ? 
     NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsAndroidHandlerApp::Share(const nsAString & data, const nsAString & title)
 {
   if (!mozilla::AndroidBridge::Bridge())
     return NS_ERROR_FAILURE;
 
   return mozilla::AndroidBridge::Bridge()->
-    OpenUriExternal(NS_ConvertUTF16toUTF8(data), mMimeType, mPackageName, 
+    OpenUriExternal(data, NS_ConvertUTF8toUTF16(mMimeType), mPackageName, 
                     mClassName, mAction) ? NS_OK : NS_ERROR_FAILURE;
 }
 
--- a/uriloader/exthandler/android/nsExternalSharingAppService.cpp
+++ b/uriloader/exthandler/android/nsExternalSharingAppService.cpp
@@ -28,35 +28,34 @@ NS_IMETHODIMP
 nsExternalSharingAppService::ShareWithDefault(const nsAString & data,
                                               const nsAString & mime,
                                               const nsAString & title)
 {
   NS_NAMED_LITERAL_STRING(sendAction, "android.intent.action.SEND");
   const nsString emptyString = EmptyString();
   if (AndroidBridge::Bridge())
     return AndroidBridge::Bridge()->
-      OpenUriExternal(NS_ConvertUTF16toUTF8(data), NS_ConvertUTF16toUTF8(mime),
+      OpenUriExternal(data, mime,
                       emptyString,emptyString, sendAction, title) ? NS_OK : NS_ERROR_FAILURE;
 
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsExternalSharingAppService::GetSharingApps(const nsAString & aMIMEType,
                                             uint32_t *aLen,
                                             nsISharingHandlerApp ***aHandlers)
 {
   nsresult rv;
   NS_NAMED_LITERAL_STRING(sendAction, "android.intent.action.SEND");
   nsCOMPtr<nsIMutableArray> array = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
-  NS_ConvertUTF16toUTF8 nMimeType(aMIMEType);
   if (!AndroidBridge::Bridge())
     return NS_OK;
-  AndroidBridge::Bridge()->GetHandlersForMimeType(nMimeType.get(), array,
+  AndroidBridge::Bridge()->GetHandlersForMimeType(aMIMEType, array,
                                                   nullptr, sendAction);
   array->GetLength(aLen);
   *aHandlers =
     static_cast<nsISharingHandlerApp**>(NS_Alloc(sizeof(nsISharingHandlerApp*)
                                                  * *aLen));
   for (uint32_t i = 0; i < *aLen; i++) {
     rv = array->QueryElementAt(i, nsISharingHandlerApp::GetIID(),
                                (void**)(*aHandlers + i));
--- a/uriloader/exthandler/android/nsMIMEInfoAndroid.cpp
+++ b/uriloader/exthandler/android/nsMIMEInfoAndroid.cpp
@@ -25,17 +25,17 @@ nsMIMEInfoAndroid::LoadUriInternal(nsIUR
   nsCString uriSpec;
   aURI->GetSpec(uriSpec);
 
   nsCString uriScheme;
   aURI->GetScheme(uriScheme);
 
   if (mozilla::AndroidBridge::Bridge())
     return mozilla::AndroidBridge::Bridge()->
-      OpenUriExternal(uriSpec, (mType.Equals(uriScheme) || mType.Equals(uriSpec)) ? EmptyCString() : mType) ? NS_OK : NS_ERROR_FAILURE;
+      OpenUriExternal(NS_ConvertUTF8toUTF16(uriSpec), (mType.Equals(uriScheme) || mType.Equals(uriSpec)) ? EmptyString() : NS_ConvertUTF8toUTF16(mType)) ? NS_OK : NS_ERROR_FAILURE;
 
   return NS_ERROR_FAILURE;
 }
 
 
 bool
 nsMIMEInfoAndroid::GetMimeInfoForMimeType(const nsACString& aMimeType,
                                           nsMIMEInfoAndroid** aMimeInfo)
@@ -45,17 +45,17 @@ nsMIMEInfoAndroid::GetMimeInfoForMimeTyp
   // we don't have access to the bridge, so just assume we can handle
   // the mime type for now and let the system deal with it
   if (!bridge){
     info.forget(aMimeInfo);
     return false;
   }
 
   nsIHandlerApp* systemDefault = nullptr;
-  bridge->GetHandlersForMimeType(nsAutoCString(aMimeType).get(), 
+  bridge->GetHandlersForMimeType(NS_ConvertUTF8toUTF16(aMimeType), 
                                  info->mHandlerApps, &systemDefault);
   
   if (systemDefault)
     info->mPrefApp = systemDefault;
 
   nsAutoCString fileExt;
   bridge->GetExtensionFromMimeType(aMimeType, fileExt);
   info->SetPrimaryExtension(fileExt);
@@ -104,17 +104,17 @@ nsMIMEInfoAndroid::GetMimeInfoForURL(con
   mozilla::AndroidBridge* bridge = mozilla::AndroidBridge::Bridge();
   if (!bridge) {
     // we don't have access to the bridge, so just assume we can handle
     // the protocol for now and let the system deal with it
     return NS_OK;
   }
 
   nsIHandlerApp* systemDefault = nullptr;
-  bridge->GetHandlersForURL(nsAutoCString(aURL).get(), 
+  bridge->GetHandlersForURL(NS_ConvertUTF8toUTF16(aURL), 
                             mimeinfo->mHandlerApps, &systemDefault);
   
   if (systemDefault)
     mimeinfo->mPrefApp = systemDefault;
 
 
   nsAutoCString fileExt;
   nsAutoCString mimeType;
--- a/uriloader/exthandler/android/nsOSHelperAppService.cpp
+++ b/uriloader/exthandler/android/nsOSHelperAppService.cpp
@@ -38,17 +38,17 @@ nsOSHelperAppService::GetMIMEInfoFromOS(
 
     return mimeInfo.forget();
 }
 
 nsresult
 nsOSHelperAppService::OSProtocolHandlerExists(const char* aScheme,
                                               bool* aExists)
 {
-    *aExists = mozilla::AndroidBridge::Bridge()->GetHandlersForURL(aScheme);    
+    *aExists = mozilla::AndroidBridge::Bridge()->GetHandlersForURL(NS_ConvertUTF8toUTF16(aScheme));    
     return NS_OK;
 }
 
 nsresult nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
                                       bool *found,
                                       nsIHandlerInfo **info)
 {
     return nsMIMEInfoAndroid::GetMimeInfoForURL(aScheme, found, info);
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -396,30 +396,30 @@ AndroidBridge::NotifyIMEContext(int aSta
     args[2].l = NewJavaString(&jniFrame, aModeHint);
     args[3].l = NewJavaString(&jniFrame, aActionHint);
 
     env->CallStaticVoidMethodA(sBridge->mGeckoAppShellClass,
                                sBridge->jNotifyIMEContext, args);
 }
 
 void
-AndroidBridge::NotifyIMEChange(const PRUnichar *aText, uint32_t aTextLen,
+AndroidBridge::NotifyIMEChange(const nsAString& aText,
                                int aStart, int aEnd, int aNewEnd)
 {
     ALOG_BRIDGE("AndroidBridge::NotifyIMEChange");
     if (!sBridge)
         return;
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
     AutoLocalJNIFrame jniFrame(env);
 
     jvalue args[4];
-    args[0].l = NewJavaString(&jniFrame, aText, aTextLen);
+    args[0].l = NewJavaString(&jniFrame, aText);
     args[1].i = aStart;
     args[2].i = aEnd;
     args[3].i = aNewEnd;
     env->CallStaticVoidMethodA(sBridge->mGeckoAppShellClass,
                                sBridge->jNotifyIMEChange, args);
 }
 
 void
@@ -532,17 +532,17 @@ getHandlersFromStringArray(JNIEnv *aJNIE
 
         aHandlersArray->AppendElement(app, false);
         if (aDefaultApp && isDefault.Length() > 0)
             *aDefaultApp = app;
     }
 }
 
 bool
-AndroidBridge::GetHandlersForMimeType(const char *aMimeType,
+AndroidBridge::GetHandlersForMimeType(const nsAString& aMimeType,
                                       nsIMutableArray *aHandlersArray,
                                       nsIHandlerApp **aDefaultApp,
                                       const nsAString& aAction)
 {
     ALOG_BRIDGE("AndroidBridge::GetHandlersForMimeType");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
@@ -565,22 +565,22 @@ AndroidBridge::GetHandlersForMimeType(co
 
     jsize len = env->GetArrayLength(arr);
 
     if (!aHandlersArray)
         return len > 0;
 
     getHandlersFromStringArray(env, arr, len, aHandlersArray,
                                aDefaultApp, aAction,
-                               nsDependentCString(aMimeType));
+                               NS_ConvertUTF16toUTF8(aMimeType));
     return true;
 }
 
 bool
-AndroidBridge::GetHandlersForURL(const char *aURL,
+AndroidBridge::GetHandlersForURL(const nsAString& aURL,
                                  nsIMutableArray* aHandlersArray,
                                  nsIHandlerApp **aDefaultApp,
                                  const nsAString& aAction)
 {
     ALOG_BRIDGE("AndroidBridge::GetHandlersForURL");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
@@ -606,17 +606,17 @@ AndroidBridge::GetHandlersForURL(const c
         return len > 0;
 
     getHandlersFromStringArray(env, arr, len, aHandlersArray,
                                aDefaultApp, aAction);
     return true;
 }
 
 bool
-AndroidBridge::OpenUriExternal(const nsACString& aUriSpec, const nsACString& aMimeType,
+AndroidBridge::OpenUriExternal(const nsAString& aUriSpec, const nsAString& aMimeType,
                                const nsAString& aPackageName, const nsAString& aClassName,
                                const nsAString& aAction, const nsAString& aTitle)
 {
     ALOG_BRIDGE("AndroidBridge::OpenUriExternal");
 
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return false;
@@ -1346,17 +1346,17 @@ mozilla_AndroidBridge_SetMainThread(void
 }
 
 jclass GetGeckoAppShellClass()
 {
     return mozilla::AndroidBridge::GetGeckoAppShellClass();
 }
 
 void
-AndroidBridge::ScanMedia(const nsAString& aFile, const nsACString& aMimeType)
+AndroidBridge::ScanMedia(const nsAString& aFile, const nsAString& aMimeType)
 {
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env);
     jstring jstrFile = NewJavaString(&jniFrame, aFile);
 
--- a/widget/android/AndroidBridge.h
+++ b/widget/android/AndroidBridge.h
@@ -174,17 +174,17 @@ public:
     bool SetMainThread(void *thr);
 
     /* These are all implemented in Java */
     static void NotifyIME(int aType);
 
     static void NotifyIMEContext(int aState, const nsAString& aTypeHint,
                                  const nsAString& aModeHint, const nsAString& aActionHint);
 
-    static void NotifyIMEChange(const PRUnichar *aText, uint32_t aTextLen, int aStart, int aEnd, int aNewEnd);
+    static void NotifyIMEChange(const nsAString& a0, int32_t a1, int32_t a2, int32_t a3);
 
     void StartJavaProfiling(int aInterval, int aSamples);
     void StopJavaProfiling();
     void PauseJavaProfiling();
     void UnpauseJavaProfiling();
     bool GetThreadNameJavaProfiling(uint32_t aThreadId, nsCString & aResult);
     bool GetFrameNameJavaProfiling(uint32_t aThreadId, uint32_t aSampleId, uint32_t aFrameId, nsCString & aResult);
     double GetSampleTimeJavaProfiling(uint32_t aThreadId, uint32_t aSampleId);
@@ -208,31 +208,31 @@ public:
 
     void NotifyXreExit();
 
     void ScheduleRestart();
 
     void SetLayerClient(JNIEnv* env, jobject jobj);
     AndroidGeckoLayerClient &GetLayerClient() { return *mLayerClient; }
 
-    bool GetHandlersForURL(const char *aURL, 
-                             nsIMutableArray* handlersArray = nullptr,
-                             nsIHandlerApp **aDefaultApp = nullptr,
-                             const nsAString& aAction = EmptyString());
+    bool GetHandlersForURL(const nsAString& aURL,
+                           nsIMutableArray* handlersArray = nullptr,
+                           nsIHandlerApp **aDefaultApp = nullptr,
+                           const nsAString& aAction = EmptyString());
 
-    bool GetHandlersForMimeType(const char *aMimeType,
-                                  nsIMutableArray* handlersArray = nullptr,
-                                  nsIHandlerApp **aDefaultApp = nullptr,
-                                  const nsAString& aAction = EmptyString());
+    bool GetHandlersForMimeType(const nsAString& aMimeType,
+                                nsIMutableArray* handlersArray = nullptr,
+                                nsIHandlerApp **aDefaultApp = nullptr,
+                                const nsAString& aAction = EmptyString());
 
-    bool OpenUriExternal(const nsACString& aUriSpec, const nsACString& aMimeType,
-                           const nsAString& aPackageName = EmptyString(),
-                           const nsAString& aClassName = EmptyString(),
-                           const nsAString& aAction = EmptyString(),
-                           const nsAString& aTitle = EmptyString());
+    bool OpenUriExternal(const nsAString& aUriSpec, const nsAString& aMimeType,
+                         const nsAString& aPackageName = EmptyString(),
+                         const nsAString& aClassName = EmptyString(),
+                         const nsAString& aAction = EmptyString(),
+                         const nsAString& aTitle = EmptyString());
 
     void GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType);
     void GetExtensionFromMimeType(const nsACString& aMimeType, nsACString& aFileExt);
 
     void MoveTaskToBack();
 
     bool GetClipboardText(nsAString& aText);
 
@@ -293,17 +293,17 @@ public:
     EGLSurface ProvideEGLSurface();
 
     bool GetStaticStringField(const char *classID, const char *field, nsAString &result, JNIEnv* env = nullptr);
 
     bool GetStaticIntField(const char *className, const char *fieldName, int32_t* aInt, JNIEnv* env = nullptr);
 
     void SetKeepScreenOn(bool on);
 
-    void ScanMedia(const nsAString& aFile, const nsACString& aMimeType);
+    void ScanMedia(const nsAString& aFile, const nsAString& aMimeType);
 
     void CreateShortcut(const nsAString& aTitle, const nsAString& aURI, const nsAString& aIconData, const nsAString& aIntent);
 
     // These next four functions are for native Bitmap access in Android 2.2+
     bool HasNativeBitmapAccess();
 
     bool ValidateBitmap(jobject bitmap, int width, int height);
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -2250,35 +2250,34 @@ nsWindow::FlushIMEChanges()
         nsQueryContentEvent event(true, NS_QUERY_TEXT_CONTENT, this);
         InitEvent(event, nullptr);
         event.InitForQueryTextContent(change.mStart,
                                       change.mNewEnd - change.mStart);
         DispatchEvent(&event);
         if (!event.mSucceeded)
             return;
 
-        AndroidBridge::NotifyIMEChange(event.mReply.mString.get(),
-                                       event.mReply.mString.Length(),
+        AndroidBridge::NotifyIMEChange(event.mReply.mString,
                                        change.mStart,
                                        change.mOldEnd,
                                        change.mNewEnd);
     }
     mIMETextChanges.Clear();
 
     if (mIMESelectionChanged) {
         nsQueryContentEvent event(true, NS_QUERY_SELECTED_TEXT, this);
         InitEvent(event, nullptr);
 
         DispatchEvent(&event);
         if (!event.mSucceeded)
             return;
 
-        AndroidBridge::NotifyIMEChange(nullptr, 0,
-                                       event.GetSelectionStart(),
-                                       event.GetSelectionEnd(), -1);
+        AndroidBridge::NotifyIMEChange(EmptyString(),
+                             (int32_t) event.GetSelectionStart(),
+                             (int32_t) event.GetSelectionEnd(), -1);
         mIMESelectionChanged = false;
     }
 }
 
 NS_IMETHODIMP
 nsWindow::NotifyIMEOfTextChange(uint32_t aStart,
                                 uint32_t aOldEnd,
                                 uint32_t aNewEnd)
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -1804,17 +1804,17 @@ nsLocalFile::Launch()
     nsAutoCString type;
     nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1", &rv));
     if (NS_SUCCEEDED(rv))
         rv = mimeService->GetTypeFromFile(this, type);
 
     nsDependentCString fileUri = NS_LITERAL_CSTRING("file://");
     fileUri.Append(mPath);
     mozilla::AndroidBridge* bridge = mozilla::AndroidBridge::Bridge();
-    return bridge->OpenUriExternal(fileUri, type) ? NS_OK : NS_ERROR_FAILURE;
+    return bridge->OpenUriExternal(NS_ConvertUTF8toUTF16(fileUri), NS_ConvertUTF8toUTF16(type)) ? NS_OK : NS_ERROR_FAILURE;
 #elif defined(MOZ_WIDGET_COCOA)
     CFURLRef url;
     if (NS_SUCCEEDED(GetCFURL(&url))) {
         nsresult rv = CocoaFileUtils::OpenURL(url);
         ::CFRelease(url);
         return rv;
     }
     return NS_ERROR_FAILURE;