Bug 595218 - Badges on the same domain doesnt always reflect the right update [r=vingtetun]
authorMark Finkle <mfinkle@mozilla.com>
Wed, 13 Oct 2010 10:57:12 -0400
changeset 66827 9c6dc4306dff530cc35a04caac6efdf8f9b07e30
parent 66826 5723ff8c20534d3c008d8a6e4b5419cd328810fe
child 66828 b753dc02b81cf38520357acb50b733adaead39f1
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs595218
Bug 595218 - Badges on the same domain doesnt always reflect the right update [r=vingtetun]
mobile/chrome/content/bindings.xml
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/bindings.xml
+++ b/mobile/chrome/content/bindings.xml
@@ -159,17 +159,16 @@
 
       <field name="_scrollBoxObject">
         this.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
       </field>
 
       <!-- Used by the badges implementation -->
       <field name="_badges">[]</field>
       <field name="_badgesTimeout">-1</field>
-      <field name="_eTLDService">Cc["@mozilla.org/network/effective-tld-service;1"].getService(Ci.nsIEffectiveTLDService);</field>
 
       <!-- nsIAutocompleteInput -->
       <property name="overrideValue"
                 readonly="true"
                 onget="return null;"/>
 
       <field name="_input"/>
       <property name="input"
@@ -367,96 +366,80 @@
             newIndex = 0;
           else if (newIndex < 0)
             newIndex = lastIndex;
 
           this.selectedIndex = newIndex;
         ]]></body>
       </method>
 
-      <method name="_getEffectiveHost">
-        <parameter name="aURI"/>
-        <body><![CDATA[
-          let host = null;
-          try {
-            host = aURI.host;
-            return this._eTLDService.getBaseDomainFromHost(host);
-          } catch (e) {}
-
-          return host ? host : aURI.spec;
-        ]]></body>
-      </method>
-
       <method name="registerBadgeHandler">
         <parameter name="aURL"/>
         <parameter name="aHandler"/>
         <body><![CDATA[
           if (!aHandler)
             return false;
 
-          let effectiveHost = this._getEffectiveHost(Services.io.newURI(aURL, null, null));
-          this._badges[effectiveHost] = aHandler;
+          this._badges[aURL] = aHandler;
           return true;
         ]]></body>
       </method>
 
       <method name="unregisterBagdeHandler">
         <parameter name="aURL"/>
         <body><![CDATA[
-          let effectiveHost = this._getEffectiveHost(Services.io.newURI(aURL, null, null));
-          if (this._badges[effectiveHost])
-            delete this._badges[effectiveHost];
+          if (this._badges[aURL])
+            delete this._badges[aURL];
         ]]></body>
       </method>
 
       <method name="_invalidateBadges">
         <body><![CDATA[
           window.clearTimeout(this._badgesTimeout);
 
           this._badgesTimeout = window.setTimeout(function(self) {
 #ifdef MOZ_SERVICES_SYNC
             let remoteItems = RemoteTabsList.panel._getRemoteTabs();
 #endif
             for (let i = 0; i < self._items.childNodes.length; i++) {
               let item = self._items.childNodes[i];
               if (!item.hasAttribute("url"))
                 continue;
 
-              let currentURL = item.getAttribute("url");
-              let itemHost = self._getEffectiveHost(Services.io.newURI(currentURL, null, null));
+              let itemURL = item.getAttribute("url");
+              let itemURI = Services.io.newURI(itemURL, null, null);
 
 #ifdef MOZ_SERVICES_SYNC
               // check if the tab is in the remote list
               for (let i = 0; i < remoteItems.length; i++) {
-                let remoteURI = remoteItems[i].uri;
-                if (remoteURI) {
-                  let itemHost = Services.io.newURI(currentURL, null, null);
-                  let remoteHost = Services.io.newURI(remoteURI, null, null);
-                  if (itemHost.equals(remoteHost))
+                let remoteURL = remoteItems[i].uri;
+                if (remoteURL) {
+                  let remoteURI = Services.io.newURI(remoteURL, null, null);
+                  if (itemURI.equals(remoteURI))
                     item.setAttribute("remote", "true");
                 }
               }
 #endif
 
-              for (let badgeHost in self._badges) {
-                if (itemHost == badgeHost) {
+              for (let badgeURL in self._badges) {
+                if (itemURL.indexOf(badgeURL) == 0) {
                   // wrap the item to prevent setting a badge on a wrong item
                   let wrapper = {
                     set: function(aBadge) {
-                      if (item.getAttribute("url") != currentURL)
+                      if (item.getAttribute("url") != itemURL)
                         return;
 
                       if (!aBadge || aBadge == "")
                         item.removeAttribute("badge");
                       else
                         item.setAttribute("badge", aBadge);
                     }
                   };
 
-                  let handler = self._badges[badgeHost];
+                  let handler = self._badges[badgeURL];
                   handler.updateBadge ? handler.updateBadge(wrapper) : handler(wrapper);
                   break;
                 }
               }
             }
           }, 300, this);
         ]]></body>
       </method>
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -2635,17 +2635,17 @@ var SharingUI = {
 };
 
 
 var BadgeHandlers = {
   _handlers: [
     {
       _lastUpdate: 0,
       _lastCount: 0,
-      url: "http://mail.google.com",
+      url: "https://mail.google.com/mail",
       updateBadge: function(aBadge) {
         // Use the cache if possible
         let now = Date.now();
         if (this._lastCount && this._lastUpdate > now - 1000) {
           aBadge.set(this._lastCount);
           return;
         }