Bug 1288821 - Remove Android-specific code from nsAlertsService; r=kitcambridge
authorJim Chen <nchen@mozilla.com>
Thu, 04 Aug 2016 09:17:54 -0400
changeset 308208 d8ed6dd3fbbd4e3c3a80fef36b12b102934fc0ef
parent 308207 d327a34d94d723c5af2fdedb56bab22e6b7bc463
child 308209 ca7a13d72c4132cc6375ccf067100a14ac34842c
push id31092
push usercbook@mozilla.com
push dateFri, 05 Aug 2016 10:16:59 +0000
treeherderautoland@b97dd7dd3cb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskitcambridge
bugs1288821
milestone51.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 1288821 - Remove Android-specific code from nsAlertsService; r=kitcambridge Remove Android-specific code from nsAlertsService now that we have a proper nsIAlertsService backend on Android. However, we cannot use nsXULAlerts because XUL windows are not fully supported on Android, so we return nullptr in nsXULAlerts::GetInstance.
toolkit/components/alerts/nsAlertsService.cpp
toolkit/components/alerts/nsXULAlerts.cpp
--- a/toolkit/components/alerts/nsAlertsService.cpp
+++ b/toolkit/components/alerts/nsAlertsService.cpp
@@ -6,28 +6,22 @@
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/PermissionMessageUtils.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 #include "nsXULAppAPI.h"
 
 #include "nsAlertsService.h"
 
-#ifdef MOZ_WIDGET_ANDROID
-#include "AndroidBridge.h"
-#else
-
 #include "nsXPCOM.h"
 #include "nsIServiceManager.h"
 #include "nsIDOMWindow.h"
 #include "nsPromiseFlatString.h"
 #include "nsToolkitCompsCID.h"
 
-#endif // !MOZ_WIDGET_ANDROID
-
 #ifdef MOZ_PLACES
 #include "mozIAsyncFavicons.h"
 #include "nsIFaviconService.h"
 #endif // MOZ_PLACES
 
 using namespace mozilla;
 
 using mozilla::dom::ContentChild;
@@ -80,18 +74,16 @@ private:
   nsCOMPtr<nsIAlertNotification> mAlert;
   nsCOMPtr<nsIObserver> mAlertListener;
 };
 
 NS_IMPL_ISUPPORTS(IconCallback, nsIFaviconDataCallback)
 
 #endif // MOZ_PLACES
 
-#ifndef MOZ_WIDGET_ANDROID
-
 nsresult
 ShowWithIconBackend(nsIAlertsService* aBackend, nsIAlertNotification* aAlert,
                     nsIObserver* aAlertListener)
 {
 #ifdef MOZ_PLACES
   nsCOMPtr<nsIURI> uri;
   nsresult rv = aAlert->GetURI(getter_AddRefs(uri));
   if (NS_FAILED(rv) || !uri) {
@@ -120,41 +112,43 @@ ShowWithIconBackend(nsIAlertsService* aB
   return favicons->GetFaviconURLForPage(uri, callback);
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif // !MOZ_PLACES
 }
 
 nsresult
 ShowWithBackend(nsIAlertsService* aBackend, nsIAlertNotification* aAlert,
-                nsIObserver* aAlertListener)
+                nsIObserver* aAlertListener, const nsAString& aPersistentData)
 {
+  if (!aPersistentData.IsEmpty()) {
+    return aBackend->ShowPersistentNotification(
+        aPersistentData, aAlert, aAlertListener);
+  }
+
   if (Preferences::GetBool("alerts.showFavicons")) {
     nsresult rv = ShowWithIconBackend(aBackend, aAlert, aAlertListener);
     if (NS_SUCCEEDED(rv)) {
       return rv;
     }
   }
+
   // If favicons are disabled, or the backend doesn't support them, show the
   // alert without one.
   return aBackend->ShowAlert(aAlert, aAlertListener);
 }
 
-#endif // MOZ_WIDGET_ANDROID
-
 } // anonymous namespace
 
 NS_IMPL_ISUPPORTS(nsAlertsService, nsIAlertsService, nsIAlertsDoNotDisturb)
 
 nsAlertsService::nsAlertsService() :
   mBackend(nullptr)
 {
-#ifndef MOZ_WIDGET_ANDROID
   mBackend = do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID);
-#endif // MOZ_WIDGET_ANDROID
 }
 
 nsAlertsService::~nsAlertsService()
 {}
 
 bool nsAlertsService::ShouldShowAlert()
 {
   bool result = true;
@@ -226,50 +220,19 @@ NS_IMETHODIMP nsAlertsService::ShowPersi
 
     if (aAlertListener)
       cpc->AddRemoteAlertObserver(cookie, aAlertListener);
 
     cpc->SendShowAlert(aAlert);
     return NS_OK;
   }
 
-#ifdef MOZ_WIDGET_ANDROID
-  nsAutoString imageUrl;
-  rv = aAlert->GetImageURL(imageUrl);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsAutoString title;
-  rv = aAlert->GetTitle(title);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsAutoString text;
-  rv = aAlert->GetText(text);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsAutoString name;
-  rv = aAlert->GetName(name);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIPrincipal> principal;
-  rv = aAlert->GetPrincipal(getter_AddRefs(principal));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!aPersistentData.IsEmpty()) {
-    mozilla::AndroidBridge::Bridge()->ShowPersistentAlertNotification
-        (aPersistentData, imageUrl, title, text, cookie, name, principal);
-  } else {
-    mozilla::AndroidBridge::Bridge()->ShowAlertNotification
-        (imageUrl, title, text, cookie, aAlertListener, name, principal);
-  }
-
-  return NS_OK;
-#else
   // Check if there is an optional service that handles system-level notifications
   if (mBackend) {
-    rv = ShowWithBackend(mBackend, aAlert, aAlertListener);
+    rv = ShowWithBackend(mBackend, aAlert, aAlertListener, aPersistentData);
     if (NS_SUCCEEDED(rv)) {
       return rv;
     }
     // If the system backend failed to show the alert, clear the backend and
     // retry with XUL notifications. Future alerts will always use XUL.
     mBackend = nullptr;
   }
 
@@ -278,50 +241,43 @@ NS_IMETHODIMP nsAlertsService::ShowPersi
     if (aAlertListener)
       aAlertListener->Observe(nullptr, "alertfinished", cookie.get());
     return NS_OK;
   }
 
   // Use XUL notifications as a fallback if above methods have failed.
   nsCOMPtr<nsIAlertsService> xulBackend(nsXULAlerts::GetInstance());
   NS_ENSURE_TRUE(xulBackend, NS_ERROR_FAILURE);
-  return ShowWithBackend(xulBackend, aAlert, aAlertListener);
-#endif // !MOZ_WIDGET_ANDROID
+  return ShowWithBackend(xulBackend, aAlert, aAlertListener, aPersistentData);
 }
 
 NS_IMETHODIMP nsAlertsService::CloseAlert(const nsAString& aAlertName,
                                           nsIPrincipal* aPrincipal)
 {
   if (XRE_IsContentProcess()) {
     ContentChild* cpc = ContentChild::GetSingleton();
     cpc->SendCloseAlert(nsAutoString(aAlertName), IPC::Principal(aPrincipal));
     return NS_OK;
   }
 
-#ifdef MOZ_WIDGET_ANDROID
-  java::GeckoAppShell::CloseNotification(aAlertName);
-  return NS_OK;
-#else
-
   nsresult rv;
   // Try the system notification service.
   if (mBackend) {
     rv = mBackend->CloseAlert(aAlertName, aPrincipal);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       // If the system backend failed to close the alert, fall back to XUL for
       // future alerts.
       mBackend = nullptr;
     }
   } else {
     nsCOMPtr<nsIAlertsService> xulBackend(nsXULAlerts::GetInstance());
     NS_ENSURE_TRUE(xulBackend, NS_ERROR_FAILURE);
     rv = xulBackend->CloseAlert(aAlertName, aPrincipal);
   }
   return rv;
-#endif // !MOZ_WIDGET_ANDROID
 }
 
 
 // nsIAlertsDoNotDisturb
 NS_IMETHODIMP nsAlertsService::GetManualDoNotDisturb(bool* aRetVal)
 {
 #ifdef MOZ_WIDGET_ANDROID
   return NS_ERROR_NOT_IMPLEMENTED;
--- a/toolkit/components/alerts/nsXULAlerts.cpp
+++ b/toolkit/components/alerts/nsXULAlerts.cpp
@@ -58,22 +58,27 @@ nsXULAlertObserver::Observe(nsISupports*
 
 // We don't cycle collect nsXULAlerts since gXULAlerts will keep the instance
 // alive till shutdown anyway.
 NS_IMPL_ISUPPORTS(nsXULAlerts, nsIAlertsService, nsIAlertsDoNotDisturb, nsIAlertsIconURI)
 
 /* static */ already_AddRefed<nsXULAlerts>
 nsXULAlerts::GetInstance()
 {
+#ifdef MOZ_WIDGET_ANDROID
+  // Gecko on Android does not fully support XUL windows.
+  return nullptr;
+#else
   if (!gXULAlerts) {
     gXULAlerts = new nsXULAlerts();
     ClearOnShutdown(&gXULAlerts);
   }
   RefPtr<nsXULAlerts> instance = gXULAlerts.get();
   return instance.forget();
+#endif // MOZ_WIDGET_ANDROID
 }
 
 NS_IMETHODIMP
 nsXULAlerts::ShowAlertNotification(const nsAString& aImageUrl, const nsAString& aAlertTitle,
                                    const nsAString& aAlertText, bool aAlertTextClickable,
                                    const nsAString& aAlertCookie, nsIObserver* aAlertListener,
                                    const nsAString& aAlertName, const nsAString& aBidi,
                                    const nsAString& aLang, const nsAString & aData,