Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Proposal: The createNotification() should have 'message' parameter to pass data to the mozSetMessageHandler

42 views
Skip to first unread message

Evan Tseng

unread,
Apr 29, 2013, 10:49:39 PM4/29/13
to dev-w...@lists.mozilla.org
Hello guys,

When user click a item in Notification bar on FFOS device, the FFOS will open a specific App to handle the item.
For example, the user click a SMS notification, FFOS should open the SMS App and switch to the specific message thread page by phone number.

As developers use the createNotification function in navigator.mozNotification to create a notification,
but there is no sensible way to pass a data to the handler function in navigator.mozSetMessageHandler.

The spec of createNotification function: https://developer.mozilla.org/en-US/docs/DOM/navigator.mozNotification
notification createNotification(
in DOMString title,
in DOMString description,
in DOMString iconURL Optional
);

You could see the following code in SMS app in Gaia project.
https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/js/activity_handler.js#L175

window.navigator.mozSetMessageHandler('notification',
function notificationClick(message) {
if (!message.clicked) {
return;
}

navigator.mozApps.getSelf().onsuccess = function(evt) {
var app = evt.target.result;
app.launch();

// Getting back the number form the icon URL
var notificationType = message.imageURL.split('?')[1];
// Case regular 'sms-received'
if (notificationType == 'sms-received') {
var number = message.imageURL.split('?')[2];
showThreadFromSystemMessage(number);
return;
}
var number = message.title;
// Class 0 message
var messageBody = number + '\n' + message.body;
alert(messageBody);
};
});
}

In the notificationClick function, the message object could have four attributes:
1. clicked
2. title
3. description
4. imageURL

Because there is no attribute for passing data, the SMS app use the imageURL attribute to store data for passing to the mozSetMessageHandler.
We could see the code in GitHub page https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/js/activity_handler.js#L153.

It's a hack way to pass data to the mozSetMessageHandler.
The hack way is also used in 'Bug 855814 - Calendar: Notification: Tapping doesn't always launch app and show event'. http://bugzil.la/855814

So my proposal is that we should add a new parameter 'message' for passing data to the mozSetMessageHandler.
Is that possible, or anyone have other ideas for this?
Thanks. :)

"Yuan Xulei(袁徐磊)"

unread,
Apr 30, 2013, 5:19:46 PM4/30/13
to Evan Tseng, dev-w...@lists.mozilla.org, doug....@gmail.com, wc...@mozilla.com
Hi Evan,

The w3c notification spec(http://www.w3.org/TR/notifications/#api) uses
the `tag` member to pass additional information to the notification
object. I think it is possible to do it the same way.

BTW, navigator.mozNotification is not standard and the w3c notification
API has landed(https://bugzilla.mozilla.org/show_bug.cgi?id=782211). Why
not use the standard API instead? It seems the API could provide what
you want.
> _______________________________________________
> dev-webapi mailing list
> dev-w...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-webapi

Fabrice Desre

unread,
Apr 30, 2013, 8:58:15 PM4/30/13
to "Yuan Xulei(袁徐磊)", Evan Tseng, wc...@mozilla.com, doug....@gmail.com, dev-w...@lists.mozilla.org
On 04/30/2013 02:19 PM, "Yuan Xulei(袁徐磊)" wrote:
> Hi Evan,
>
> The w3c notification spec(http://www.w3.org/TR/notifications/#api) uses
> the `tag` member to pass additional information to the notification
> object. I think it is possible to do it the same way.
>
> BTW, navigator.mozNotification is not standard and the w3c notification
> API has landed(https://bugzilla.mozilla.org/show_bug.cgi?id=782211). Why
> not use the standard API instead? It seems the API could provide what
> you want.

This API has not landed on b2g18 unfortunately. We'll need to update our
current gecko/gaia glue to use the new API as soon as we are done with 1.1

Fabrice
--
Fabrice Desré
b2g team
Mozilla Corporation

Mounir Lamouri

unread,
May 1, 2013, 9:45:32 AM5/1/13
to dev-w...@lists.mozilla.org
On 30/04/13 03:49, Evan Tseng wrote:
> So my proposal is that we should add a new parameter 'message' for passing data to the mozSetMessageHandler.
> Is that possible, or anyone have other ideas for this?

What is the target version for that change? If it is for 1.2+, you
should definitely use the new Notification API and not change
mozNotifications. If it is for 1.1 or 1.0.1 (sic), you should probably
add a tag attribute that should behave like in the new API so we are
sure this code will run well enough when we switch to the new API in Gaia.

--
Mounir
0 new messages