Bug 1310905 - Remove some b2g specific code from DOM notifications; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 18 Oct 2016 00:01:16 -0400
changeset 361293 6e6f78b3cc413ffccc9d9f0cc4341e1130074573
parent 361292 9235e72b424f8d1ce441e9c309399c04c77d9de2
child 361294 b1e0caca8bc1fc2f0dd964a1d2259258c3978fdb
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1310905
milestone52.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 1310905 - Remove some b2g specific code from DOM notifications; r=baku
dom/notification/DesktopNotification.cpp
dom/notification/Notification.cpp
dom/notification/NotificationStorage.js
dom/notification/test/unit/common_test_notificationdb.js
dom/notification/test/unit/test_notificationdb.js
--- a/dom/notification/DesktopNotification.cpp
+++ b/dom/notification/DesktopNotification.cpp
@@ -9,17 +9,16 @@
 #include "mozilla/dom/ToJSValue.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentPermissionHelper.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/dom/PBrowserChild.h"
 #include "nsIDOMDesktopNotification.h"
 #include "mozilla/Preferences.h"
 #include "nsGlobalWindow.h"
-#include "nsIAppsService.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsServiceManagerUtils.h"
 #include "PermissionMessageUtils.h"
 #include "nsILoadContext.h"
 
 namespace mozilla {
 namespace dom {
 
@@ -68,44 +67,16 @@ uint32_t DesktopNotification::sCount = 0
 
 nsresult
 DesktopNotification::PostDesktopNotification()
 {
   if (!mObserver) {
     mObserver = new AlertServiceObserver(this);
   }
 
-#ifdef MOZ_B2G
-  nsCOMPtr<nsIAppNotificationService> appNotifier =
-    do_GetService("@mozilla.org/system-alerts-service;1");
-  if (appNotifier) {
-    nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
-    uint32_t appId = window ? window->GetDoc()->NodePrincipal()->GetAppId()
-                            : nsIScriptSecurityManager::UNKNOWN_APP_ID;
-
-    if (appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
-      nsCOMPtr<nsIAppsService> appsService = do_GetService("@mozilla.org/AppsService;1");
-      nsString manifestUrl = EmptyString();
-      appsService->GetManifestURLByLocalId(appId, manifestUrl);
-      mozilla::AutoSafeJSContext cx;
-      JS::Rooted<JS::Value> val(cx);
-      AppNotificationServiceOptions ops;
-      ops.mTextClickable = true;
-      ops.mManifestURL = manifestUrl;
-
-      if (!ToJSValue(cx, ops, &val)) {
-        return NS_ERROR_FAILURE;
-      }
-
-      return appNotifier->ShowAppNotification(mIconURL, mTitle, mDescription,
-                                              mObserver, val);
-    }
-  }
-#endif
-
   nsCOMPtr<nsIAlertsService> alerts = do_GetService("@mozilla.org/alerts-service;1");
   if (!alerts) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   // Generate a unique name (which will also be used as a cookie) because
   // the nsIAlertsService will coalesce notifications with the same name.
   // In the case of IPC, the parent process will use the cookie to map
--- a/dom/notification/Notification.cpp
+++ b/dom/notification/Notification.cpp
@@ -26,17 +26,16 @@
 #include "nsAlertsUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentPermissionHelper.h"
 #include "nsContentUtils.h"
 #include "nsCRTGlue.h"
 #include "nsDOMJSUtils.h"
 #include "nsGlobalWindow.h"
 #include "nsIAlertsService.h"
-#include "nsIAppsService.h"
 #include "nsIContentPermissionPrompt.h"
 #include "nsIDocument.h"
 #include "nsILoadContext.h"
 #include "nsINotificationStorage.h"
 #include "nsIPermissionManager.h"
 #include "nsIPermission.h"
 #include "nsIPushService.h"
 #include "nsIScriptSecurityManager.h"
@@ -1501,25 +1500,16 @@ MainThreadNotificationObserver::Observe(
         // Browser UI may use DOMWebNotificationClicked to focus the tab
         // from which the event was dispatched.
         nsContentUtils::DispatchChromeEvent(doc, window->GetOuterWindow(),
                                             NS_LITERAL_STRING("DOMWebNotificationClicked"),
                                             true, true);
       }
     }
   } else if (!strcmp("alertfinished", aTopic)) {
-    // In b2g-desktop, if the app is closed, closing a notification still
-    // triggers the observer which might be alive even though the owner window
-    // was closed. Keeping this until we remove the close event (Bug 1139363)
-    // from implementation.
-    nsCOMPtr<nsPIDOMWindowInner> window = notification->GetOwner();
-    if (NS_WARN_IF(!window || !window->IsCurrentInnerWindow())) {
-      return NS_ERROR_FAILURE;
-    }
-
     notification->UnpersistNotification();
     notification->mIsClosed = true;
     notification->DispatchTrustedEvent(NS_LITERAL_STRING("close"));
   } else if (!strcmp("alertshow", aTopic)) {
     notification->DispatchTrustedEvent(NS_LITERAL_STRING("show"));
   }
   return NS_OK;
 }
@@ -1779,62 +1769,16 @@ Notification::ShowInternal()
                                                      behavior);
   }
   MOZ_ASSERT(observer);
   nsCOMPtr<nsIObserver> alertObserver = new NotificationObserver(observer,
                                                                  GetPrincipal(),
                                                                  IsInPrivateBrowsing());
 
 
-#ifdef MOZ_B2G
-  nsCOMPtr<nsIAppNotificationService> appNotifier =
-    do_GetService("@mozilla.org/system-alerts-service;1");
-  if (appNotifier) {
-    uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
-    if (mWorkerPrivate) {
-      appId = mWorkerPrivate->GetPrincipal()->GetAppId();
-    } else {
-      nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
-      if (window) {
-        appId = window->GetDoc()->NodePrincipal()->GetAppId();
-      }
-    }
-
-    if (appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
-      nsCOMPtr<nsIAppsService> appsService = do_GetService("@mozilla.org/AppsService;1");
-      nsString manifestUrl = EmptyString();
-      nsresult rv = appsService->GetManifestURLByLocalId(appId, manifestUrl);
-      if (NS_SUCCEEDED(rv)) {
-        mozilla::AutoSafeJSContext cx;
-        JS::Rooted<JS::Value> val(cx);
-        AppNotificationServiceOptions ops;
-        ops.mTextClickable = true;
-        ops.mManifestURL = manifestUrl;
-        GetAlertName(ops.mId);
-        ops.mDbId = mID;
-        ops.mDir = DirectionToString(mDir);
-        ops.mLang = mLang;
-        ops.mTag = mTag;
-        ops.mData = mDataAsBase64;
-        ops.mMozbehavior = mBehavior;
-        ops.mMozbehavior.mSoundFile = soundUrl;
-
-        if (!ToJSValue(cx, ops, &val)) {
-          NS_WARNING("Converting dict to object failed!");
-          return;
-        }
-
-        appNotifier->ShowAppNotification(iconUrl, mTitle, mBody,
-                                         alertObserver, val);
-        return;
-      }
-    }
-  }
-#endif
-
   // In the case of IPC, the parent process uses the cookie to map to
   // nsIObserver. Thus the cookie must be unique to differentiate observers.
   nsString uniqueCookie = NS_LITERAL_STRING("notification:");
   uniqueCookie.AppendInt(sCount++);
   bool inPrivateBrowsing = IsInPrivateBrowsing();
 
   bool requireInteraction = mRequireInteraction;
   if (!Preferences::GetBool("dom.webnotifications.requireinteraction.enabled", false)) {
@@ -2359,33 +2303,18 @@ Notification::CloseInternal()
 
 nsresult
 Notification::GetOrigin(nsIPrincipal* aPrincipal, nsString& aOrigin)
 {
   if (!aPrincipal) {
     return NS_ERROR_FAILURE;
   }
 
-  uint16_t appStatus = aPrincipal->GetAppStatus();
-  uint32_t appId = aPrincipal->GetAppId();
-
-  nsresult rv;
-  if (appStatus == nsIPrincipal::APP_STATUS_NOT_INSTALLED ||
-      appId == nsIScriptSecurityManager::NO_APP_ID ||
-      appId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
-    rv = nsContentUtils::GetUTFOrigin(aPrincipal, aOrigin);
-    NS_ENSURE_SUCCESS(rv, rv);
-  } else {
-    // If we are in "app code", use manifest URL as unique origin since
-    // multiple apps can share the same origin but not same notifications.
-    nsCOMPtr<nsIAppsService> appsService =
-      do_GetService("@mozilla.org/AppsService;1", &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-    appsService->GetManifestURLByLocalId(appId, aOrigin);
-  }
+  nsresult rv = nsContentUtils::GetUTFOrigin(aPrincipal, aOrigin);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 bool
 Notification::RequireInteraction() const
 {
   return mRequireInteraction;
@@ -2822,32 +2751,17 @@ Notification::Observe(nsISupports* aSubj
     if (SameCOMIdentity(aSubject, window)) {
       nsCOMPtr<nsIObserverService> obs =
         mozilla::services::GetObserverService();
       if (obs) {
         obs->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC);
         obs->RemoveObserver(this, DOM_WINDOW_FROZEN_TOPIC);
       }
 
-      uint16_t appStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
-      uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
-
-      nsCOMPtr<nsIDocument> doc = window ? window->GetExtantDoc() : nullptr;
-      nsCOMPtr<nsIPrincipal> nodePrincipal = doc ? doc->NodePrincipal() :
-                                             nullptr;
-      if (nodePrincipal) {
-        appStatus = nodePrincipal->GetAppStatus();
-        appId = nodePrincipal->GetAppId();
-      }
-
-      if (appStatus == nsIPrincipal::APP_STATUS_NOT_INSTALLED ||
-          appId == nsIScriptSecurityManager::NO_APP_ID ||
-          appId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
-        CloseInternal();
-      }
+      CloseInternal();
     }
   }
 
   return NS_OK;
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/notification/NotificationStorage.js
+++ b/dom/notification/NotificationStorage.js
@@ -18,20 +18,16 @@ const NOTIFICATIONSTORAGE_CONTRACTID = "
 
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
-XPCOMUtils.defineLazyServiceGetter(this, "appsService",
-                                   "@mozilla.org/AppsService;1",
-                                   "nsIAppsService");
-
 const kMessageNotificationGetAllOk = "Notification:GetAll:Return:OK";
 const kMessageNotificationGetAllKo = "Notification:GetAll:Return:KO";
 const kMessageNotificationSaveKo   = "Notification:Save:Return:KO";
 const kMessageNotificationDeleteKo = "Notification:Delete:Return:KO";
 
 const kMessages = [
   kMessageNotificationGetAllOk,
   kMessageNotificationGetAllKo,
--- a/dom/notification/test/unit/common_test_notificationdb.js
+++ b/dom/notification/test/unit/common_test_notificationdb.js
@@ -6,17 +6,17 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
 function getNotificationObject(app, id, tag) {
   return {
-    origin: "app://" + app + ".gaiamobile.org/manifest.webapp",
+    origin: "https://" + app + ".gaiamobile.org/",
     id: id,
     title: app + "Notification:" + Date.now(),
     dir: "auto",
     lang: "",
     body: app + " notification body",
     tag: tag || "",
     icon: "icon.png"
   };
--- a/dom/notification/test/unit/test_notificationdb.js
+++ b/dom/notification/test/unit/test_notificationdb.js
@@ -303,106 +303,8 @@ add_test(function test_delete_previous()
   };
 
   addAndSend("Notification:Delete", msgReply, msgHandler, {
     origin: systemNotification.origin,
     id: "{2bc883bf-2809-4432-b0f4-f54e10372764}",
     requestID: requestID
   });
 });
-
-// Store two notifications, one without alertName and one with
-add_test(function test_send_two_alertName() {
-  let requestID = 30;
-  let notifications = [
-    {
-      origin: "app://system.gaiamobile.org/manifest.webapp",
-      id: "{27ead857-4f43-457f-a770-93b82fbfc223}",
-      title: "Notification title",
-      dir: "auto",
-      lang: "",
-      body: "Notification body",
-      tag: "",
-      icon: "icon.png",
-      timestamp: new Date().getTime()
-    }, {
-      origin: "app://system.gaiamobile.org/manifest.webapp",
-      id: "{40275e04-58d0-47be-8cc7-540578f793a4}",
-      title: "Notification title",
-      dir: "auto",
-      lang: "",
-      body: "Notification body",
-      tag: "",
-      icon: "icon.png",
-      alertName: "alertName",
-      timestamp: new Date().getTime()
-    }
-  ];
-  let origin = notifications[0].origin;
-
-  let msgGetCrossOriginReply = "Notification:GetAllCrossOrigin:Return:OK";
-  let msgGetCrossOriginHandler = {
-    receiveMessage: function(message) {
-      if (message.name === msgGetCrossOriginReply) {
-        cpmm.removeMessageListener(
-          msgGetCrossOriginReply, msgGetCrossOriginHandler);
-
-        let gotNotifications = message.data.notifications;
-
-        // we expect to have one notification
-        do_check_eq(1, gotNotifications.length);
-
-        // compare the only notification we should have got back
-        compareNotification(gotNotifications[0], notifications[1]);
-
-        run_next_test();
-      }
-    }
-  };
-  cpmm.addMessageListener(msgGetCrossOriginReply, msgGetCrossOriginHandler);
-
-  let msgGetReply = "Notification:GetAll:Return:OK";
-  let msgGetHandler = {
-    receiveMessage: function(message) {
-      if (message.name === msgGetReply) {
-        cpmm.removeMessageListener(msgGetReply, msgGetHandler);
-
-        let gotNotifications = message.data.notifications;
-
-        // we expect to have two notifications
-        do_check_eq(2, gotNotifications.length);
-
-        // compare each notification
-        for (let i = 0; i < gotNotifications.length; i++) {
-          compareNotification(gotNotifications[i], notifications[i]);
-        }
-
-        run_next_test();
-      }
-    }
-  };
-  cpmm.addMessageListener(msgGetReply, msgGetHandler);
-
-  let msgSaveReply = "Notification:Save:Return:OK";
-  let msgSaveCalls = 0;
-  let msgSaveHandler = {
-    receiveMessage: function(message) {
-      if (message.name === msgSaveReply) {
-        msgSaveCalls++;
-        if (msgSaveCalls === 2) {
-          cpmm.removeMessageListener(msgSaveReply, msgSaveHandler);
-          // Trigger getall
-          cpmm.sendAsyncMessage("Notification:GetAll", {
-            origin: origin
-          });
-        }
-      }
-    }
-  };
-  cpmm.addMessageListener(msgSaveReply, msgSaveHandler);
-
-  notifications.forEach(function(n) {
-    cpmm.sendAsyncMessage("Notification:Save", {
-      origin: origin,
-      notification: n
-    });
-  });
-});