Bug 1197714 - do not open duplicate Saved files tabs. ui-r=Paenglab, r=mkmelin
authoraceman <acelists@atlas.sk>
Wed, 23 Sep 2015 23:39:29 +0200
changeset 18428 579d2e9c7c2105b5c0c0bcb1367f13ce365ccfa9
parent 18427 243713ca559c073c6bc33e8c47a7d88a80807a7c
child 18429 303fcd96901fc5d1383a5392b995014394bd8a7b
push id11284
push userarchaeopteryx@coole-files.de
push dateThu, 24 Sep 2015 12:12:35 +0000
treeherdercomm-central@a54375d27b3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersPaenglab, mkmelin
bugs1197714
Bug 1197714 - do not open duplicate Saved files tabs. ui-r=Paenglab, r=mkmelin
mail/base/content/mailCore.js
mail/base/content/tabmail.xml
--- a/mail/base/content/mailCore.js
+++ b/mail/base/content/mailCore.js
@@ -504,19 +504,24 @@ function openIMAccountWizard()
   }
 #endif
   window.openDialog(kUrl, kName, kFeatures);
 }
 
 function openSavedFilesWnd()
 {
   let tabmail = document.getElementById("tabmail");
-  tabmail.openTab("chromeTab",
-                  { chromePage: "about:downloads",
-                    clickHandler: "specialTabs.aboutClickHandler(event);" });
+  let downloadsBrowser = tabmail.getBrowserForDocumentId("aboutDownloads");
+  if (downloadsBrowser)
+    tabmail.switchToTab(downloadsBrowser);
+  else {
+    gDownloadsTab = tabmail.openTab("chromeTab",
+                      { chromePage: "about:downloads",
+                        clickHandler: "specialTabs.aboutClickHandler(event);" });
+  }
 }
 
 function SetBusyCursor(window, enable)
 {
     // setCursor() is only available for chrome windows.
     // However one of our frames is the start page which
     // is a non-chrome window, so check if this window has a
     // setCursor method
--- a/mail/base/content/tabmail.xml
+++ b/mail/base/content/tabmail.xml
@@ -1075,26 +1075,45 @@
            document that's been loaded -->
       <method name="getBrowserForDocument">
         <parameter name="aDocument"/>
         <body><![CDATA[
           for (let i = 0; i < this.tabInfo.length; ++i) {
             let browserFunc = this.tabInfo[i].mode.getBrowser ||
                               this.tabInfo[i].mode.tabType.getBrowser;
             if (browserFunc) {
-              var possBrowser = browserFunc.call(this.tabInfo[i].mode.tabType,
+              let possBrowser = browserFunc.call(this.tabInfo[i].mode.tabType,
                                                  this.tabInfo[i]);
               if (possBrowser &&
                   possBrowser.contentWindow == aDocument)
                 return this.tabInfo[i];
             }
           }
           return null;
         ]]></body>
       </method>
+      <!-- getBrowserForDocumentId is used to find the browser for a specific
+           document via its id attribute -->
+      <method name="getBrowserForDocumentId">
+        <parameter name="aDocumentId"/>
+        <body><![CDATA[
+          for (let i = 0; i < this.tabInfo.length; ++i) {
+            let browserFunc = this.tabInfo[i].mode.getBrowser ||
+                              this.tabInfo[i].mode.tabType.getBrowser;
+            if (browserFunc) {
+              let possBrowser = browserFunc.call(this.tabInfo[i].mode.tabType,
+                                                 this.tabInfo[i]);
+              if (possBrowser &&
+                  possBrowser.contentDocument.documentElement.id == aDocumentId)
+                return this.tabInfo[i];
+            }
+          }
+          return null;
+        ]]></body>
+      </method>
       <method name="removeCurrentTab">
         <body><![CDATA[
           this.removeTabByNode(
             this.tabContainer.childNodes[this.tabContainer.selectedIndex]);
         ]]></body>
       </method>
       <method name="switchToTab">
         <parameter name="aTabIndexNodeOrInfo"/>