Bug 824240 - Make the Downloads View Seamonkey-friendly. r=mak
authorAsaf Romano <mano@mozilla.com>
Thu, 27 Dec 2012 16:50:56 +0200
changeset 126205 f3e277d2e0c167546b8a68edcfd39f5d239c9f55
parent 126204 6d66c25f3e41da00ffafc0b10b63ece8adddf21b
child 126206 58d263c1c3dcb864c47ecbb2bc94f32aa5e0571a
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs824240
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 824240 - Make the Downloads View Seamonkey-friendly. r=mak
browser/components/places/content/downloadsViewOverlay.xul
browser/components/places/content/places.js
browser/components/places/content/places.xul
browser/components/places/jar.mn
new file mode 100644
--- /dev/null
+++ b/browser/components/places/content/downloadsViewOverlay.xul
@@ -0,0 +1,36 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<?xul-overlay href="chrome://browser/content/downloads/allDownloadsViewOverlay.xul"?>
+
+<overlay id="downloadsViewOverlay"
+         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+  <script type="application/javascript"><![CDATA[
+    let useNewView = false;
+    try {
+      useNewView = Services.prefs.getBoolPref("browser.library.useNewDownloadsView");
+    }
+    catch(ex) { }
+
+    if (useNewView) {
+      const DOWNLOADS_QUERY = "place:transition=" +
+        Components.interfaces.nsINavHistoryService.TRANSITION_DOWNLOAD +
+        "&sort=" +
+        Components.interfaces.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
+
+      ContentArea.setContentViewForQueryString(DOWNLOADS_QUERY,
+        function() new DownloadsPlacesView(document.getElementById("downloadsRichListBox")));
+    }
+  ]]></script>
+
+  <window id="places">
+    <commandset id="downloadCommands"/>
+    <menupopup id="downloadsContextMenu"/>
+  </window>
+
+  <deck id="placesViewsDeck">
+    <richlistbox id="downloadsRichListBox"/>
+  </deck>
+</overlay>
--- a/browser/components/places/content/places.js
+++ b/browser/components/places/content/places.js
@@ -1,20 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource:///modules/MigrationUtils.jsm");
 
-const DOWNLOADS_QUERY = "place:transition=" +
-  Components.interfaces.nsINavHistoryService.TRANSITION_DOWNLOAD +
-  "&sort=" +
-  Components.interfaces.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
-
 var PlacesOrganizer = {
   _places: null,
 
   // IDs of fields from editBookmarkOverlay that should be hidden when infoBox
   // is minimal. IDs should be kept in sync with the IDs of the elements
   // observing additionalInfoBroadcaster.
   _additionalInfoFields: [
     "editBMPanel_descriptionRow",
@@ -1241,44 +1236,65 @@ let gPrivateBrowsingListener = {
       this._cmd_import.setAttribute("disabled", "true");
     else
       this._cmd_import.removeAttribute("disabled");
   }
 };
 #endif
 
 let ContentArea = {
+  _specialViews: new Map(),
+
   init: function CA_init() {
     this._deck = document.getElementById("placesViewsDeck");
-    this._specialViews = new Map();
     ContentTree.init();
   },
 
-  _shouldUseNewDownloadsView: function CA_shouldUseNewDownloadsView() {
-    try {
-      return Services.prefs.getBoolPref("browser.library.useNewDownloadsView");
-    }
-    catch(ex) { }
-    return false;
-  },
-
+  /**
+   * Gets the content view to be used for loading the given query.
+   * If a custom view was set by setContentViewForQueryString, that
+   * view would be returned, else the default tree view is returned
+   *
+   * @param aQueryString
+   *        a query string
+   * @return the view to be used for loading aQueryString.
+   */
   getContentViewForQueryString:
   function CA_getContentViewForQueryString(aQueryString) {
-    if (this._specialViews.has(aQueryString))
-      return this._specialViews.get(aQueryString);
-    if (aQueryString == DOWNLOADS_QUERY && this._shouldUseNewDownloadsView()) {
-      let view = new DownloadsPlacesView(document.getElementById("downloadsRichListBox"));
-      this.setContentViewForQueryString(aQueryString, view);
-      return view;
+    try {
+      if (this._specialViews.has(aQueryString)) {
+        let view = this._specialViews.get(aQueryString);
+        if (typeof view == "function") {
+          view = view();
+          this._specialViews.set(aQueryString, view);
+        }
+        return view;
+      }
+    }
+    catch(ex) {
+      Cu.reportError(ex);
     }
     return ContentTree.view;
   },
 
+  /**
+   * Sets a custom view to be used rather than the default places tree
+   * whenever the given query is selected in the left pane.
+   * @param aQueryString
+   *        a query string
+   * @param aView
+   *        Either the custom view or a function that will return the view
+   *        the first (and only) time it's called.
+   */
   setContentViewForQueryString:
   function CA_setContentViewForQueryString(aQueryString, aView) {
+    if (!aQueryString ||
+        typeof aView != "object" && typeof aView != "function")
+      throw new Error("Invalid arguments");
+
     this._specialViews.set(aQueryString, aView);
   },
 
   get currentView() PlacesUIUtils.getViewForNode(this._deck.selectedPanel),
   set currentView(aView) {
     if (this.currentView != aView)
       this._deck.selectedPanel = aView.associatedElement;
     return aView;
--- a/browser/components/places/content/places.xul
+++ b/browser/components/places/content/places.xul
@@ -7,17 +7,16 @@
 <?xml-stylesheet href="chrome://browser/content/places/places.css"?>
 <?xml-stylesheet href="chrome://browser/content/places/organizer.css"?>
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/places/places.css"?>
 <?xml-stylesheet href="chrome://browser/skin/places/organizer.css"?>
 
 <?xul-overlay href="chrome://browser/content/places/editBookmarkOverlay.xul"?>
-<?xul-overlay href="chrome://browser/content/downloads/allDownloadsViewOverlay.xul"?>
 
 #ifdef XP_MACOSX
 <?xul-overlay href="chrome://browser/content/macBrowserOverlay.xul"?>
 #else
 <?xul-overlay href="chrome://browser/content/baseMenuOverlay.xul"?>
 <?xul-overlay href="chrome://global/content/editMenuOverlay.xul"?>
 <?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?>
 #endif
@@ -400,17 +399,16 @@
             <treecol label="&col.dateadded.label;" id="placesContentDateAdded" anonid="dateAdded" flex="1" hidden="true"
                       persist="width hidden ordinal sortActive sortDirection"/>
             <splitter class="tree-splitter"/>
             <treecol label="&col.lastmodified.label;" id="placesContentLastModified" anonid="lastModified" flex="1" hidden="true"
                       persist="width hidden ordinal sortActive sortDirection"/>
           </treecols>
           <treechildren flex="1"/>
         </tree>
-        <richlistbox id="downloadsRichListBox"/>
       </deck>
       <deck id="detailsDeck" style="height: 11em;">
         <vbox id="itemsCountBox" align="center">
           <spacer flex="3"/>
           <label id="itemsCountText"/>
           <spacer flex="1"/>
           <description id="selectItemDescription">
               &detailsPane.selectAnItemText.description;
@@ -435,12 +433,9 @@
                     accesskey="&detailsPane.more.accesskey;"
                     control="infoBoxExpander"/>
 
           </hbox>
         </vbox>
       </deck>
     </vbox>
   </hbox>
-
-  <commandset id="downloadCommands"/>
-  <menupopup id="downloadsContextMenu"/>
 </window>
--- a/browser/components/places/jar.mn
+++ b/browser/components/places/jar.mn
@@ -1,13 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 browser.jar:
+% overlay chrome://browser/content/places/places.xul chrome://browser/content/places/downloadsViewOverlay.xul
 # Provide another URI for the bookmarkProperties dialog so we can persist the
 # attributes separately
     content/browser/places/bookmarkProperties2.xul       (content/bookmarkProperties.xul)
 *   content/browser/places/places.xul                    (content/places.xul) 
 *   content/browser/places/places.js                     (content/places.js)
     content/browser/places/places.css                    (content/places.css)
     content/browser/places/organizer.css                 (content/organizer.css)
     content/browser/places/bookmarkProperties.xul        (content/bookmarkProperties.xul)
@@ -25,8 +26,9 @@ browser.jar:
 # ditto for the bookmarks sidebar
     content/browser/bookmarks/bookmarksPanel.xul         (content/bookmarksPanel.xul)
     content/browser/bookmarks/bookmarksPanel.js          (content/bookmarksPanel.js)
 *   content/browser/bookmarks/sidebarUtils.js            (content/sidebarUtils.js)
     content/browser/places/moveBookmarks.xul             (content/moveBookmarks.xul)
     content/browser/places/moveBookmarks.js              (content/moveBookmarks.js)
     content/browser/places/editBookmarkOverlay.xul       (content/editBookmarkOverlay.xul)
     content/browser/places/editBookmarkOverlay.js        (content/editBookmarkOverlay.js)
+    content/browser/places/downloadsViewOverlay.xul      (content/downloadsViewOverlay.xul)