mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1310905 - Remove some b2g specific code from DOM notifications; r=baku
This commit is contained in:
parent
f13c011369
commit
ee0b46b80e
@ -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<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;
|
||||
|
@ -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<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"));
|
||||
@ -1784,52 +1774,6 @@ Notification::ShowInternal()
|
||||
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:");
|
||||
@ -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<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;
|
||||
}
|
||||
@ -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<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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user