From ee0b46b80e4c23bf0b35aaa8462326faba9eacea Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 18 Oct 2016 00:01:16 -0400 Subject: [PATCH] Bug 1310905 - Remove some b2g specific code from DOM notifications; r=baku --- dom/notification/DesktopNotification.cpp | 29 ------ dom/notification/Notification.cpp | 92 +---------------- dom/notification/NotificationStorage.js | 4 - .../test/unit/common_test_notificationdb.js | 2 +- .../test/unit/test_notificationdb.js | 98 ------------------- 5 files changed, 4 insertions(+), 221 deletions(-) diff --git a/dom/notification/DesktopNotification.cpp b/dom/notification/DesktopNotification.cpp index c3e01247d522..ed290074592c 100644 --- a/dom/notification/DesktopNotification.cpp +++ b/dom/notification/DesktopNotification.cpp @@ -14,7 +14,6 @@ #include "nsIDOMDesktopNotification.h" #include "mozilla/Preferences.h" #include "nsGlobalWindow.h" -#include "nsIAppsService.h" #include "nsIScriptSecurityManager.h" #include "nsServiceManagerUtils.h" #include "PermissionMessageUtils.h" @@ -73,34 +72,6 @@ DesktopNotification::PostDesktopNotification() mObserver = new AlertServiceObserver(this); } -#ifdef MOZ_B2G - nsCOMPtr appNotifier = - do_GetService("@mozilla.org/system-alerts-service;1"); - if (appNotifier) { - nsCOMPtr window = GetOwner(); - uint32_t appId = window ? window->GetDoc()->NodePrincipal()->GetAppId() - : nsIScriptSecurityManager::UNKNOWN_APP_ID; - - if (appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) { - nsCOMPtr appsService = do_GetService("@mozilla.org/AppsService;1"); - nsString manifestUrl = EmptyString(); - appsService->GetManifestURLByLocalId(appId, manifestUrl); - mozilla::AutoSafeJSContext cx; - JS::Rooted 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 alerts = do_GetService("@mozilla.org/alerts-service;1"); if (!alerts) { return NS_ERROR_NOT_IMPLEMENTED; diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index d57a03340f9a..80e96e2f9343 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -31,7 +31,6 @@ #include "nsDOMJSUtils.h" #include "nsGlobalWindow.h" #include "nsIAlertsService.h" -#include "nsIAppsService.h" #include "nsIContentPermissionPrompt.h" #include "nsIDocument.h" #include "nsILoadContext.h" @@ -1506,15 +1505,6 @@ MainThreadNotificationObserver::Observe(nsISupports* aSubject, const char* aTopi } } } 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 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")); @@ -1784,52 +1774,6 @@ Notification::ShowInternal() IsInPrivateBrowsing()); -#ifdef MOZ_B2G - nsCOMPtr 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 window = GetOwner(); - if (window) { - appId = window->GetDoc()->NodePrincipal()->GetAppId(); - } - } - - if (appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) { - nsCOMPtr 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 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:"); @@ -2364,23 +2308,8 @@ Notification::GetOrigin(nsIPrincipal* aPrincipal, nsString& aOrigin) 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 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; } @@ -2827,22 +2756,7 @@ Notification::Observe(nsISupports* aSubject, const char* aTopic, obs->RemoveObserver(this, DOM_WINDOW_FROZEN_TOPIC); } - uint16_t appStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED; - uint32_t appId = nsIScriptSecurityManager::UNKNOWN_APP_ID; - - nsCOMPtr doc = window ? window->GetExtantDoc() : nullptr; - nsCOMPtr 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(); } } diff --git a/dom/notification/NotificationStorage.js b/dom/notification/NotificationStorage.js index 636974d68dba..8186d61b88d1 100644 --- a/dom/notification/NotificationStorage.js +++ b/dom/notification/NotificationStorage.js @@ -23,10 +23,6 @@ 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"; diff --git a/dom/notification/test/unit/common_test_notificationdb.js b/dom/notification/test/unit/common_test_notificationdb.js index 83888edf4526..116c7836ad01 100644 --- a/dom/notification/test/unit/common_test_notificationdb.js +++ b/dom/notification/test/unit/common_test_notificationdb.js @@ -11,7 +11,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "cpmm", 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", diff --git a/dom/notification/test/unit/test_notificationdb.js b/dom/notification/test/unit/test_notificationdb.js index 392df8b030e7..d631bd034558 100644 --- a/dom/notification/test/unit/test_notificationdb.js +++ b/dom/notification/test/unit/test_notificationdb.js @@ -308,101 +308,3 @@ add_test(function test_delete_previous() { 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 - }); - }); -});