Closed Bug 696282 Opened 13 years ago Closed 13 years ago

Implement native toast alert support


(Firefox for Android Graveyard :: General, defect, P3)



(firefox11 fixed, fennec11+)

Tracking Status
firefox11 --- fixed
fennec 11+ ---


(Reporter: fabrice, Assigned: ju.vermet)



(Whiteboard: [QA+])


(1 file, 1 obsolete file)

We used to have two alert types:

- actionable ones, that map to Status Bar Notifications (
- simple toasters, that map to Toast Notifications (
We already support Status Bar notifications. We also have a "toaster" alertsservice, but it's XUL. Lets switch it over to use native toast by passing a JSON message from the JS component to the Java UI.
Summary: Implement nsIAlertsService → Implement native toaster nsIAlertsService
Assignee: nobody → wjohnston
Priority: -- → P3
Blocks: 697078
Assignee: wjohnston → ju.vermet
Attached patch Patch v1 (obsolete) — Splinter Review
This is a first implementation with two parameters :
- A JSONObject called "message" just contain a string called "content"
- A boolean to set the duration. If true, long, if false, short
Awesome. Thanks Julien.

I think you're digging at this a bit already, but what we'll probably want is a method like this, except maybe taking a String and a Bool.

Then we'll register a message listener, similar to the ones in embedding/android/ (look for "registerGeckoEventListener", and note we'll also want to unregister the listener at close) that watches for "Toast" messages coming from Javascript. I think we should try to contain all the JSON conversions to that method.

So in the listener, we'll look at the JSON we get, pull out the message text and the "length" boolean (I think for the sake readability, we might be better making this a string with values "long" or "short"?), and then fire them over to the real "showToast" method.

Thanks again. Ask away if any of that doesn't make sense.
Thanks for the patch Julien - let's build on top of this.

We want to call this from JS. It used to be an XPCOM component but let's start by just adding this to the NativeWindow object in browser.js around :, aLong)

Message type will be Toaster:Show, and this message must then be handled in


handling :

Attached patch Patch v2Splinter Review
As suggested by wesj, I used a string to set the toast duration and the JSON conversion is now done in "handleMessage". If the duration is "long", a long toast is shown. If anything else is defined, a short toast is shown.

A toast can be shown by calling the JS function ""myToast", "long");"
Attachment #569539 - Attachment is obsolete: true
Comment on attachment 569581 [details] [diff] [review]
Patch v2

Very nice Julien!

This looks exactly like what we want. I'm going to do a few things to the patch before I land it:
1. Switch to  4-space indents, no Tabs
2. Use | } else if (...) { | format
3. Change the "length" param to "duration" - since that is what Android calls it

Thanks a lot for the patch
Attachment #569581 - Flags: review+

I also tweak:
* "Toaster" -> "Toast" since Android calls it that too.
* Some other spacing issues _not_ in the patch itself (just OCD)
Closed: 13 years ago
Resolution: --- → FIXED
Summary: Implement native toaster nsIAlertsService → Implement native toast alert support
Saving a page as PDF two alerts appeared: Status Bar Notification and Toast Notification. Marking this as verified fixed. 

Build: Mozilla /5.0 (Android;Linux armv7l;rv:11.0a1) Gecko/20111128 Firefox/11.0a1 Fennec/11.0a1
Device: LG Optimus 2X (Android 2.2)
tracking-fennec: --- → 11+
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.