Bug 1210211 - Part 2: Notify Push service of visible notifications. r=baku

--HG--
extra : commitid : JIe7odI4Fgo
extra : rebase_source : f71dc1cf94def6ad72db773c1ba77473149f8359
This commit is contained in:
William Chen 2015-11-16 21:33:17 -08:00
parent 8588891ca7
commit cfff602824
3 changed files with 74 additions and 1 deletions

View File

@ -57,3 +57,21 @@ interface nsIPushNotificationService : nsISupports
*/
jsval clearForDomain(in string domain);
};
[scriptable, uuid(a2555e70-46f8-4b52-bf02-d978b979d143)]
interface nsIPushQuotaManager : nsISupports
{
/**
* Informs the quota manager that a notification
* for the given origin has been shown. Used to
* determine if push quota should be relaxed.
*/
void notificationForOriginShown(in string origin);
/**
* Informs the quota manager that a notification
* for the given origin has been closed. Used to
* determine if push quota should be relaxed.
*/
void notificationForOriginClosed(in string origin);
};

View File

@ -51,6 +51,10 @@
#include "nsIDOMDesktopNotification.h"
#endif
#ifndef MOZ_SIMPLEPUSH
#include "nsIPushNotificationService.h"
#endif
namespace mozilla {
namespace dom {
@ -678,6 +682,8 @@ protected:
{
AssertIsOnMainThread();
}
nsresult AdjustPushQuota(const char* aTopic);
};
NS_IMPL_ISUPPORTS(NotificationObserver, nsIObserver)
@ -1173,11 +1179,39 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
ContentChild::GetSingleton()->SendOpenNotificationSettings(
IPC::Principal(mPrincipal));
return NS_OK;
} else if (!strcmp("alertshow", aTopic) ||
!strcmp("alertfinished", aTopic)) {
Unused << NS_WARN_IF(NS_FAILED(AdjustPushQuota(aTopic)));
}
return mObserver->Observe(aSubject, aTopic, aData);
}
nsresult
NotificationObserver::AdjustPushQuota(const char* aTopic)
{
#ifdef MOZ_SIMPLEPUSH
return NS_ERROR_NOT_IMPLEMENTED;
#else
nsCOMPtr<nsIPushQuotaManager> pushQuotaManager =
do_GetService("@mozilla.org/push/NotificationService;1");
if (!pushQuotaManager) {
return NS_ERROR_FAILURE;
}
nsAutoCString origin;
nsresult rv = mPrincipal->GetOrigin(origin);
if (NS_FAILED(rv)) {
return rv;
}
if (!strcmp("alertshow", aTopic)) {
return pushQuotaManager->NotificationForOriginShown(origin.get());
}
return pushQuotaManager->NotificationForOriginClosed(origin.get());
#endif
}
NS_IMETHODIMP
MainThreadNotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)

View File

@ -36,7 +36,8 @@ PushNotificationService.prototype = {
_xpcom_factory: XPCOMUtils.generateSingletonFactory(PushNotificationService),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference,
Ci.nsIPushNotificationService]),
Ci.nsIPushNotificationService,
Ci.nsIPushQuotaManager,]),
register: function register(scope, originAttributes) {
return PushService.register({
@ -74,6 +75,26 @@ PushNotificationService.prototype = {
}
break;
}
},
// nsIPushQuotaManager methods
notificationForOriginShown: function(origin) {
if (!isParent) {
Services.cpmm.sendAsyncMessage("Push:NotificationForOriginShown", origin);
return;
}
PushService._notificationForOriginShown(origin);
},
notificationForOriginClosed: function(origin) {
if (!isParent) {
Services.cpmm.sendAsyncMessage("Push:NotificationForOriginClosed", origin);
return;
}
PushService._notificationForOriginClosed(origin);
}
};