diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 90a3b68e3826..49d65c18f222 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -1633,7 +1633,7 @@ BrowserGlue.prototype = { // be set to the version it has been added in, we will compare its value // to users' smartBookmarksVersion and add new smart bookmarks without // recreating old deleted ones. - const SMART_BOOKMARKS_VERSION = 6; + const SMART_BOOKMARKS_VERSION = 7; const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion"; @@ -1665,7 +1665,7 @@ BrowserGlue.prototype = { Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING + "&maxResults=" + MAX_RESULTS), parent: PlacesUtils.toolbarFolderId, - position: toolbarIndex++, + get position() { return toolbarIndex++; }, newInVersion: 1 }, RecentlyBookmarked: { @@ -1680,7 +1680,7 @@ BrowserGlue.prototype = { "&maxResults=" + MAX_RESULTS + "&excludeQueries=1"), parent: PlacesUtils.bookmarksMenuFolderId, - position: menuIndex++, + get position() { return menuIndex++; }, newInVersion: 1 }, RecentTags: { @@ -1692,25 +1692,31 @@ BrowserGlue.prototype = { Ci.nsINavHistoryQueryOptions.SORT_BY_LASTMODIFIED_DESCENDING + "&maxResults=" + MAX_RESULTS), parent: PlacesUtils.bookmarksMenuFolderId, - position: menuIndex++, + get position() { return menuIndex++; }, newInVersion: 1 }, }; if (Services.metro && Services.metro.supported) { smartBookmarks.Windows8Touch = { - title: bundle.GetStringFromName("windows8TouchTitle"), - uri: NetUtil.newURI("place:folder=" + - PlacesUtils.annotations.getItemsWithAnnotation('metro/bookmarksRoot', {})[0] + - "&queryType=" + - Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS + - "&sort=" + - Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING + - "&maxResults=" + MAX_RESULTS + - "&excludeQueries=1"), + title: PlacesUtils.getString("windows8TouchTitle"), + get uri() { + let metroBookmarksRoot = PlacesUtils.annotations.getItemsWithAnnotation('metro/bookmarksRoot', {}); + if (metroBookmarksRoot.length > 0) { + return NetUtil.newURI("place:folder=" + + metroBookmarksRoot[0] + + "&queryType=" + + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS + + "&sort=" + + Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING + + "&maxResults=" + MAX_RESULTS + + "&excludeQueries=1") + } + return null; + }, parent: PlacesUtils.bookmarksMenuFolderId, - position: menuIndex++, - newInVersion: 6 + get position() { return menuIndex++; }, + newInVersion: 7 }; } @@ -1722,9 +1728,13 @@ BrowserGlue.prototype = { let queryId = PlacesUtils.annotations.getItemAnnotation(itemId, SMART_BOOKMARKS_ANNO); if (queryId in smartBookmarks) { let smartBookmark = smartBookmarks[queryId]; + if (!smartBookmark.uri) { + PlacesUtils.bookmarks.removeItem(itemId); + return; + } smartBookmark.itemId = itemId; smartBookmark.parent = PlacesUtils.bookmarks.getFolderIdForItem(itemId); - smartBookmark.position = PlacesUtils.bookmarks.getItemIndex(itemId); + smartBookmark.updatedPosition = PlacesUtils.bookmarks.getItemIndex(itemId); } else { // We don't remove old Smart Bookmarks because user could still @@ -1742,7 +1752,7 @@ BrowserGlue.prototype = { // bookmark if it has been removed. if (smartBookmarksCurrentVersion > 0 && smartBookmark.newInVersion <= smartBookmarksCurrentVersion && - !smartBookmark.itemId) + !smartBookmark.itemId || !smartBookmark.uri) continue; // Remove old version of the smart bookmark if it exists, since it @@ -1755,7 +1765,7 @@ BrowserGlue.prototype = { smartBookmark.itemId = PlacesUtils.bookmarks.insertBookmark(smartBookmark.parent, smartBookmark.uri, - smartBookmark.position, + smartBookmark.updatedPosition || smartBookmark.position, smartBookmark.title); PlacesUtils.annotations.setItemAnnotation(smartBookmark.itemId, SMART_BOOKMARKS_ANNO, diff --git a/browser/components/places/tests/unit/head_bookmarks.js b/browser/components/places/tests/unit/head_bookmarks.js index 71a8c608dff8..65e7ff47bdb9 100644 --- a/browser/components/places/tests/unit/head_bookmarks.js +++ b/browser/components/places/tests/unit/head_bookmarks.js @@ -63,10 +63,9 @@ let (XULAppInfo = { } // Smart bookmarks constants. -let isMetroSupported = Services.metro && Services.metro.supported; -const SMART_BOOKMARKS_VERSION = 6 +const SMART_BOOKMARKS_VERSION = 7; const SMART_BOOKMARKS_ON_TOOLBAR = 1; -const SMART_BOOKMARKS_ON_MENU = isMetroSupported ? 4 : 3; // Takes in count the additional separator. +const SMART_BOOKMARKS_ON_MENU = 3; // Takes into account the additional separator. // Default bookmarks constants. const DEFAULT_BOOKMARKS_ON_TOOLBAR = 1; diff --git a/browser/locales/en-US/chrome/browser/places/places.properties b/browser/locales/en-US/chrome/browser/places/places.properties index d5caf3c68bb9..c4dca0abde6a 100644 --- a/browser/locales/en-US/chrome/browser/places/places.properties +++ b/browser/locales/en-US/chrome/browser/places/places.properties @@ -70,10 +70,6 @@ detailsPane.itemsCountLabel=One item;#1 items mostVisitedTitle=Most Visited recentlyBookmarkedTitle=Recently Bookmarked recentTagsTitle=Recent Tags -# LOCALIZATION NOTE (windows8TouchTitle): this is the name of the folder used -# to store bookmarks created in Metro mode and share bookmarks between Metro -# and Desktop. -windows8TouchTitle=Windows 8 Touch OrganizerQueryHistory=History OrganizerQueryDownloads=Downloads diff --git a/browser/metro/components/BrowserStartup.js b/browser/metro/components/BrowserStartup.js index 53de281c986b..1086ae65fdea 100644 --- a/browser/metro/components/BrowserStartup.js +++ b/browser/metro/components/BrowserStartup.js @@ -8,6 +8,13 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", + "resource://gre/modules/PlacesUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "NetUtil", + "resource://gre/modules/NetUtil.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "Task", + "resource://gre/modules/Task.jsm"); + // Custom factory object to ensure that we're a singleton const BrowserStartupServiceFactory = { _instance: null, @@ -62,7 +69,35 @@ BrowserStartup.prototype = { Cu.import("resource://gre/modules/BookmarkJSONUtils.jsm"); - BookmarkJSONUtils.importFromURL("chrome://browser/locale/bookmarks.json", false); + Task.spawn(function() { + yield BookmarkJSONUtils.importFromURL("chrome://browser/locale/bookmarks.json", false); + + // Create the new smart bookmark. + const MAX_RESULTS = 10; + const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; + + // Place the Metro folder at the end of the smart bookmarks list. + let maxIndex = Math.max.apply(null, + PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO).map(id => { + return PlacesUtils.bookmarks.getItemIndex(id); + })); + let smartBookmarkId = + PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId, + NetUtil.newURI("place:folder=" + + PlacesUtils.annotations.getItemsWithAnnotation('metro/bookmarksRoot', {})[0] + + "&queryType=" + + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS + + "&sort=" + + Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING + + "&maxResults=" + MAX_RESULTS + + "&excludeQueries=1"), + maxIndex + 1, + PlacesUtils.getString("windows8TouchTitle")); + PlacesUtils.annotations.setItemAnnotation(smartBookmarkId, + SMART_BOOKMARKS_ANNO, + "Windows8Touch", 0, + PlacesUtils.annotations.EXPIRE_NEVER); + }); }, _startupActions: function() { diff --git a/toolkit/locales/en-US/chrome/places/places.properties b/toolkit/locales/en-US/chrome/places/places.properties index 6b209af65eb7..8b543b8e4cc6 100644 --- a/toolkit/locales/en-US/chrome/places/places.properties +++ b/toolkit/locales/en-US/chrome/places/places.properties @@ -30,3 +30,7 @@ localhost=(local files) # %2$S is the file size unit backupFileSizeText=%1$S %2$S +# LOCALIZATION NOTE (windows8TouchTitle): this is the name of the folder used +# to store bookmarks created in Metro mode and share bookmarks between Metro +# and Desktop. +windows8TouchTitle=Windows 8 Touch \ No newline at end of file