Bug 961587: Only create Windows 8 Touch smart bookmark once a user has intialized their Metro bookmark list. r=mbrubeck, r=mak77

This commit is contained in:
Marina Samuel 2014-03-10 12:53:19 -04:00
parent ed4e523f62
commit d4dcf5b089
5 changed files with 70 additions and 26 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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

View File

@ -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() {

View File

@ -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