Bug 963561 - Notify Home.banner consumers when a message is dismissed. r=wesj a=sledru
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 14 Feb 2014 16:51:43 -0800
changeset 183079 6f1b2e06c66679a84c27ca394143807af12e3843
parent 183078 fcbc2e04b8c8e663e42f42d25e41d8749023bde1
child 183080 478823afeb536f33ca102ca3c989666879f73612
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj, sledru
bugs963561
milestone29.0a2
Bug 963561 - Notify Home.banner consumers when a message is dismissed. r=wesj a=sledru
mobile/android/base/home/HomeBanner.java
mobile/android/modules/Home.jsm
--- a/mobile/android/base/home/HomeBanner.java
+++ b/mobile/android/base/home/HomeBanner.java
@@ -53,16 +53,18 @@ public class HomeBanner extends LinearLa
 
         // The drawable should have 50% opacity.
         closeButton.getDrawable().setAlpha(127);
 
         closeButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
                 HomeBanner.this.setVisibility(View.GONE);
+                // Send the current message id back to JS.
+                GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("HomeBanner:Dismiss", (String) getTag()));
             }
         });
 
         setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 // Send the current message id back to JS.
                 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("HomeBanner:Click", (String) getTag()));
--- a/mobile/android/modules/Home.jsm
+++ b/mobile/android/modules/Home.jsm
@@ -41,16 +41,19 @@ function BannerMessage(options) {
   if ("icon" in options && options.icon != null)
     this.iconURI = resolveGeckoURI(options.icon);
 
   if ("onshown" in options && typeof options.onshown === "function")
     this.onshown = options.onshown;
 
   if ("onclick" in options && typeof options.onclick === "function")
     this.onclick = options.onclick;
+
+  if ("ondismiss" in options && typeof options.ondismiss === "function")
+    this.ondismiss = options.ondismiss;
 }
 
 let HomeBanner = {
   // Holds the messages that will rotate through the banner.
   _messages: {},
 
   // A queue used to keep track of which message to show next.
   _queue: [],
@@ -59,16 +62,20 @@ let HomeBanner = {
     switch(topic) {
       case "HomeBanner:Get":
         this._handleGet();
         break;
 
       case "HomeBanner:Click":
         this._handleClick(data);
         break;
+
+      case "HomeBanner:Dismiss":
+        this._handleDismiss(data);
+        break;
     }
   },
 
   _handleGet: function() {
     // Get the message from the front of the queue, then add it back
     // to the end of the queue to show it again later.
     let id = this._queue.shift();
     this._queue.push(id);
@@ -86,16 +93,22 @@ let HomeBanner = {
   },
 
   _handleClick: function(id) {
     let message = this._messages[id];
     if (message.onclick)
       message.onclick();
   },
 
+  _handleDismiss: function(id) {
+    let message = this._messages[id];
+    if (message.ondismiss)
+      message.ondismiss();
+  },
+
   /**
    * Adds a new banner message to the rotation.
    *
    * @return id Unique identifer for the message.
    */
   add: function(options) {
     let message = new BannerMessage(options);
     this._messages[message.id] = message;
@@ -103,16 +116,17 @@ let HomeBanner = {
     // Add the new message to the end of the queue.
     this._queue.push(message.id);
 
     // If this is the first message we're adding, add
     // observers to listen for requests from the Java UI.
     if (Object.keys(this._messages).length == 1) {
       Services.obs.addObserver(this, "HomeBanner:Get", false);
       Services.obs.addObserver(this, "HomeBanner:Click", false);
+      Services.obs.addObserver(this, "HomeBanner:Dismiss", false);
 
       // Send a message to Java, in case there's an active HomeBanner
       // waiting for a response.
       this._handleGet();
     }
 
     return message.id;
   },
@@ -128,16 +142,17 @@ let HomeBanner = {
     // Remove the message from the queue.
     let index = this._queue.indexOf(id);
     this._queue.splice(index, 1);
 
     // If there are no more messages, remove the observers.
     if (Object.keys(this._messages).length == 0) {
       Services.obs.removeObserver(this, "HomeBanner:Get");
       Services.obs.removeObserver(this, "HomeBanner:Click");
+      Services.obs.removeObserver(this, "HomeBanner:Dismiss");
     }
   }
 };
 
 function Panel(options) {
   if ("id" in options)
     this.id = options.id;