Bug 947619 Tabs bookmarked in private windows have no titles r=mcsmurf
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Mon, 06 Jan 2014 00:29:23 +0000
changeset 17253 ff2f997e1b3233e398555cef67228ee616ed95af
parent 17252 97e4cad8ce7b36565bf91823b13177076d712b64
child 17254 08b8cae1f27e6e959e0819864fe58d4df853705e
push id1103
push usermbanner@mozilla.com
push dateTue, 18 Mar 2014 07:44:06 +0000
treeherdercomm-beta@50c6279a0af0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcsmurf
bugs947619
Bug 947619 Tabs bookmarked in private windows have no titles r=mcsmurf
suite/common/bookmarks/bm-props.js
suite/common/bookmarks/browser-places.js
suite/common/src/PlacesUIUtils.jsm
suite/common/sync/aboutSyncTabs.js
--- a/suite/common/bookmarks/bm-props.js
+++ b/suite/common/bookmarks/bm-props.js
@@ -10,16 +10,17 @@
  *     - "add" - for adding a new item.
  *       @ type (String). Possible values:
  *         - "bookmark"
  *           @ loadBookmarkInSidebar - optional, the default state for the
  *             "Load this bookmark in the sidebar" field.
  *         - "folder"
  *           @ URIList (Array of nsIURI objects) - optional, list of uris to
  *             be bookmarked under the new folder.
+ *           @ titleList (Array of String) - optional, list of titles.
  *         - "livemark"
  *       @ uri (nsIURI object) - optional, the default uri for the new item.
  *         The property is not used for the "folder with items" type.
  *       @ title (String) - optional, the default title for the new item.
  *       @ description (String) - optional, the default description for the new
  *         item.
  *       @ defaultInsertionPoint (InsertionPoint JS object) - optional, the
  *         default insertion point for the new item.
@@ -79,16 +80,17 @@ var BookmarkPropertiesPanel = {
   _action: null,
   _itemType: null,
   _itemId: -1,
   _uri: null,
   _loadInSidebar: false,
   _title: "",
   _description: "",
   _URIs: [],
+  _titles: [],
   _keyword: "",
   _postData: null,
   _charSet: "",
   _feedURI: null,
   _siteURI: null,
 
   _defaultInsertionPoint: null,
   _hiddenRows: [],
@@ -193,16 +195,18 @@ var BookmarkPropertiesPanel = {
           break;
 
         case "folder":
           this._itemType = BOOKMARK_FOLDER;
           if (!this._title) {
             if ("URIList" in dialogInfo) {
               this._title = this._strings.getString("bookmarkAllTabsDefault");
               this._URIs = dialogInfo.URIList;
+              if ("titleList" in dialogInfo)
+                this._titles = dialogInfo.titleList;
             }
             else
               this._title = this._strings.getString("newFolderDefault");
               this._dummyItem = true;
           }
           break;
 
         case "livemark":
@@ -583,17 +587,17 @@ var BookmarkPropertiesPanel = {
   /**
    * Returns a childItems-transactions array representing the URIList with
    * which the dialog has been opened.
    */
   _getTransactionsForURIList: function BPP__getTransactionsForURIList() {
     var transactions = [];
     for (var i = 0; i < this._URIs.length; ++i) {
       var uri = this._URIs[i];
-      var title = this._getURITitleFromHistory(uri);
+      var title = this._titles[i] || this._getURITitleFromHistory(uri);
       var createTxn = new PlacesCreateBookmarkTransaction(uri, -1,
                                                           PlacesUtils.bookmarks.DEFAULT_INDEX,
                                                           title);
       transactions.push(createTxn);
     }
     return transactions; 
   },
 
--- a/suite/common/bookmarks/browser-places.js
+++ b/suite/common/bookmarks/browser-places.js
@@ -365,42 +365,45 @@ var PlacesCommandHook = {
   /**
    * This function returns a list of nsIURI objects characterizing the
    * tabs currently open in the browser.  The URIs will appear in the
    * list in the order in which their corresponding tabs appeared.  However,
    * only the first instance of each URI will be returned.
    *
    * @returns a list of nsIURI objects representing unique locations open
    */
-  _getUniqueTabInfo: function BATC__getUniqueTabInfo() {
+  _getUniqueTabInfo: function BATC__getUniqueTabInfo(aTitles) {
     var tabList = [];
     var seenURIs = {};
 
     var browsers = gBrowser.browsers;
     for (var i = 0; i < browsers.length; ++i) {
       let uri = browsers[i].currentURI;
 
       // skip redundant entries
       if (uri.spec in seenURIs)
         continue;
 
       // add to the set of seen URIs
       seenURIs[uri.spec] = null;
       tabList.push(uri);
+      if (aTitles)
+        aTitles.push(browsers[i].contentTitle);
     }
     return tabList;
   },
 
   /**
    * Adds a folder with bookmarks to all of the currently open tabs in this
    * window.
    */
   bookmarkCurrentPages: function PCH_bookmarkCurrentPages() {
-    var tabURIs = this._getUniqueTabInfo();
-    PlacesUIUtils.showMinimalAddMultiBookmarkUI(tabURIs);
+    var titles = [];
+    var tabURIs = this._getUniqueTabInfo(titles);
+    PlacesUIUtils.showMinimalAddMultiBookmarkUI(tabURIs, titles);
   },
 
 
   /**
    * Adds a Live Bookmark to a feed associated with the current page.
    * @param     url
    *            The nsIURI of the page the feed was attached to
    * @title     title
--- a/suite/common/src/PlacesUIUtils.jsm
+++ b/suite/common/src/PlacesUIUtils.jsm
@@ -517,27 +517,32 @@ var PlacesUIUtils = {
 
   /**
    * Show an "Add Bookmarks" dialog to allow the adding of a folder full
    * of bookmarks corresponding to the objects in the uriList.  This will
    * be called most often as the result of a "Bookmark All Tabs..." command.
    *
    * @param aURIList  List of nsIURI objects representing the locations
    *                  to be bookmarked.
+   * @param aTitleList  Optional list of strings giving the page titles.
    * @return true if any transaction has been performed.
    */
-  showMinimalAddMultiBookmarkUI: function PUIU_showAddMultiBookmarkUI(aURIList) {
+  showMinimalAddMultiBookmarkUI: function PUIU_showAddMultiBookmarkUI(aURIList, aTitleList) {
     if (aURIList.length == 0)
       throw("showAddMultiBookmarkUI expects a list of nsIURI objects");
     var info = {
       action: "add",
       type: "folder",
       hiddenRows: ["description"],
       URIList: aURIList
     };
+
+    if (aTitleList)
+      info.titleList = aTitleList;
+
     return this._showBookmarkDialog(info);
   },
 
   /**
    * Opens the properties dialog for a given item identifier.
    *
    * @param aItemId
    *        item identifier for which the properties are to be shown
--- a/suite/common/sync/aboutSyncTabs.js
+++ b/suite/common/sync/aboutSyncTabs.js
@@ -95,27 +95,29 @@ let RemoteTabViewer = {
     let uri = Weave.Utils.makeURI(item.getAttribute("url"));
     let title = item.getAttribute("title");
     PlacesUIUtils.showMinimalAddBookmarkUI(uri, title);
   },
 
   bookmarkSelectedTabs: function() {
     let items = this._tabsList.selectedItems;
     let URIs = [];
+    let titles = [];
     for (let i = 0; i < items.length; i++) {
       if (items[i].getAttribute("type") == "tab") {
         let uri = Weave.Utils.makeURI(items[i].getAttribute("url"));
         if (!uri)
           continue;
 
         URIs.push(uri);
+        titles.push(items[i].getAttribute("title"));
       }
     }
     if (URIs.length)
-      PlacesUIUtils.showMinimalAddMultiBookmarkUI(URIs);
+      PlacesUIUtils.showMinimalAddMultiBookmarkUI(URIs, titles);
   },
 
   _generateTabList: function() {
     let engine = Weave.Service.engineManager.get("tabs");
     let list = this._tabsList;
 
     // clear out existing richlistitems
     let count = list.getRowCount();