Skip to content

Commit

Permalink
Bug 1210211 - Part 2: Notify Push service of visible notifications. r…
Browse files Browse the repository at this point in the history
…=baku

--HG--
extra : commitid : 7lTQ80hfQU6
extra : rebase_source : f31c7dd4c3dc9f9d4bb492791fd59c413268d22d
  • Loading branch information
William Chen committed Nov 16, 2015
1 parent e791f70 commit 1677aae
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
18 changes: 18 additions & 0 deletions dom/interfaces/push/nsIPushNotificationService.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
22 changes: 22 additions & 0 deletions dom/notification/Notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "nsILoadContext.h"
#include "nsINotificationStorage.h"
#include "nsIPermissionManager.h"
#include "nsIPushNotificationService.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceWorkerManager.h"
#include "nsIUUIDGenerator.h"
Expand Down Expand Up @@ -1173,6 +1174,27 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic,
ContentChild::GetSingleton()->SendOpenNotificationSettings(
IPC::Principal(mPrincipal));
return NS_OK;
} else if (!strcmp("alertshow", aTopic) ||
!strcmp("alertfinished", aTopic)) {
nsCOMPtr<nsIPushQuotaManager> pushQuotaManager =
do_GetService("@mozilla.org/push/NotificationService;1");
if (pushQuotaManager) {
nsAutoCString origin;
nsresult rv = mPrincipal->GetOrigin(origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

if (!strcmp("alertshow", aTopic)) {
rv = pushQuotaManager->NotificationForOriginShown(origin.get());
} else {
rv = pushQuotaManager->NotificationForOriginClosed(origin.get());
}

if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
}

return mObserver->Observe(aSubject, aTopic, aData);
Expand Down
23 changes: 22 additions & 1 deletion dom/push/PushNotificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
}
};

Expand Down

0 comments on commit 1677aae

Please sign in to comment.