зеркало из https://github.com/mozilla/gecko-dev.git
Bug 401753 - Creating the Places folder for an existing profile with lots of bookmarks takes too long, the personal toolbar is blank for several seconds. r=sspitzer.
This commit is contained in:
Родитель
553cfb5be8
Коммит
2f696dc023
|
@ -268,128 +268,6 @@ function initBookmarksToolbar() {
|
|||
PlacesUtils.getQueryStringForFolder(PlacesUtils.bookmarks.toolbarFolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the special "Places" folder (with some special queries) to the personal toolbar folder
|
||||
*/
|
||||
function initPlacesDefaultQueries() {
|
||||
var createdDefaultQueries = false;
|
||||
try {
|
||||
createdDefaultQueries = gPrefService.getBoolPref("browser.places.createdDefaultQueries");
|
||||
} catch(ex) {}
|
||||
|
||||
if (createdDefaultQueries)
|
||||
return;
|
||||
|
||||
var bmsvc = PlacesUtils.bookmarks;
|
||||
var callback = {
|
||||
runBatched: function() {
|
||||
var placesFolderTitle =
|
||||
PlacesUtils.getString("placesFolderTitle");
|
||||
var recentlyCreatedBookmarksTitle =
|
||||
PlacesUtils.getString("recentlyCreatedBookmarksTitle");
|
||||
var recentlyVisitedBookmarksTitle =
|
||||
PlacesUtils.getString("recentlyVisitedBookmarksTitle");
|
||||
var mostVisitedBookmarksTitle =
|
||||
PlacesUtils.getString("mostVisitedBookmarksTitle");
|
||||
var recentlyUsedTagsTitle =
|
||||
PlacesUtils.getString("recentlyUsedTagsTitle");
|
||||
var mostUsedTagsTitle =
|
||||
PlacesUtils.getString("mostUsedTagsTitle");
|
||||
var mostVisitedSitesTitle =
|
||||
PlacesUtils.getString("mostVisitedSitesTitle");
|
||||
|
||||
var bookmarksMenuFolder = PlacesUtils.bookmarksMenuFolderId;
|
||||
var unfiledBookmarksFolder = PlacesUtils.unfiledBookmarksFolderId;
|
||||
var toolbarFolder = PlacesUtils.toolbarFolderId;
|
||||
var tagsFolder = PlacesUtils.tagsFolderId;
|
||||
var defaultIndex = bmsvc.DEFAULT_INDEX;
|
||||
|
||||
// index = 0, make it the first folder
|
||||
var placesFolder = bmsvc.createFolder(toolbarFolder,
|
||||
placesFolderTitle,
|
||||
0);
|
||||
|
||||
// XXX should this be a pref? see bug #399268
|
||||
var maxResults = 10;
|
||||
|
||||
// exclude queries so that user created "saved searches"
|
||||
// and these queries (added automatically) are excluded
|
||||
var recentlyCreatedBookmarksItem = bmsvc.insertBookmark(placesFolder,
|
||||
IO.newURI("place:folder=" + bookmarksMenuFolder +
|
||||
"&folder=" + unfiledBookmarksFolder +
|
||||
"&folder=" + toolbarFolder +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
||||
"&excludeItemIfParentHasAnnotation=livemark%2FfeedURI" +
|
||||
"&maxResults=" + maxResults +
|
||||
"&excludeQueries=1"),
|
||||
defaultIndex, recentlyCreatedBookmarksTitle);
|
||||
|
||||
var recentlyVisitedBookmarksItem = bmsvc.insertBookmark(placesFolder,
|
||||
IO.newURI("place:folder=" + bookmarksMenuFolder +
|
||||
"&folder=" + unfiledBookmarksFolder +
|
||||
"&folder=" + toolbarFolder +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&sort=" + Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING +
|
||||
"&excludeItemIfParentHasAnnotation=livemark%2FfeedURI" +
|
||||
"&minVisits=1&maxResults=" + maxResults),
|
||||
defaultIndex, recentlyVisitedBookmarksTitle);
|
||||
|
||||
var mostVisitedBookmarksItem = bmsvc.insertBookmark(placesFolder,
|
||||
IO.newURI("place:folder=" + bookmarksMenuFolder +
|
||||
"&folder=" + unfiledBookmarksFolder +
|
||||
"&folder=" + toolbarFolder +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
||||
"&excludeItemIfParentHasAnnotation=livemark%2FfeedURI" +
|
||||
"&minVisits=1&maxResults=" + maxResults),
|
||||
defaultIndex, mostVisitedBookmarksTitle);
|
||||
|
||||
var recentlyUsedTagsItem = bmsvc.insertBookmark(placesFolder,
|
||||
IO.newURI("place:folder=" + tagsFolder +
|
||||
"&group=" + Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&applyOptionsToContainers=1" +
|
||||
"&sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
||||
"&maxResults=" + maxResults),
|
||||
defaultIndex, recentlyUsedTagsTitle);
|
||||
|
||||
var mostUsedTagsItem = bmsvc.insertBookmark(placesFolder,
|
||||
IO.newURI("place:folder=" + tagsFolder +
|
||||
"&group=" + Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&applyOptionsToContainers=1" +
|
||||
"&sort=" + Ci.nsINavHistoryQueryOptions.SORT_BY_COUNT_DESCENDING +
|
||||
"&maxResults=" + maxResults),
|
||||
defaultIndex, mostUsedTagsTitle);
|
||||
|
||||
var mostVisitedSitesItem = bmsvc.insertBookmark(placesFolder,
|
||||
IO.newURI("place:queryType=" +
|
||||
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY +
|
||||
"&sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
||||
"&maxResults=" + maxResults),
|
||||
defaultIndex, mostVisitedSitesTitle);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
bmsvc.runInBatchMode(callback, null);
|
||||
}
|
||||
catch(ex) {
|
||||
Components.utils.reportError(ex);
|
||||
}
|
||||
finally {
|
||||
// We need to persist this preference change, since we want to
|
||||
// check it at next app start even if the browser exits abruptly
|
||||
gPrefService.setBoolPref("browser.places.createdDefaultQueries", true);
|
||||
gPrefService.savePrefFile(null);
|
||||
}
|
||||
}
|
||||
|
||||
const gSessionHistoryObserver = {
|
||||
observe: function(subject, topic, data)
|
||||
{
|
||||
|
@ -1032,7 +910,6 @@ function delayedStartup()
|
|||
|
||||
UpdateUrlbarSearchSplitterState();
|
||||
|
||||
initPlacesDefaultQueries();
|
||||
initBookmarksToolbar();
|
||||
PlacesStarButton.init();
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#
|
||||
# Contributor(s):
|
||||
# Giorgio Maone <g.maone@informaction.com>
|
||||
# Seth Spitzer <sspitzer@mozilla.com>
|
||||
# Asaf Romano <mano@mozilla.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -339,8 +341,12 @@ BrowserGlue.prototype = {
|
|||
importBookmarks = prefBranch.getBoolPref("browser.places.importBookmarksHTML");
|
||||
} catch(ex) {}
|
||||
|
||||
if (!importBookmarks)
|
||||
if (!importBookmarks) {
|
||||
// Call it here for Fx3 profiles created before the Places folder
|
||||
// has been added, otherwise it's called during import.
|
||||
this.ensurePlacesDefaultQueriesInitialized();
|
||||
return;
|
||||
}
|
||||
|
||||
var dirService = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
|
@ -389,7 +395,7 @@ BrowserGlue.prototype = {
|
|||
getService(Ci.nsIPlacesImportExportService);
|
||||
importer.backupBookmarksFile();
|
||||
},
|
||||
|
||||
|
||||
// ------------------------------
|
||||
// public nsIBrowserGlue members
|
||||
// ------------------------------
|
||||
|
@ -399,6 +405,142 @@ BrowserGlue.prototype = {
|
|||
this.Sanitizer.sanitize(aParentWindow);
|
||||
},
|
||||
|
||||
ensurePlacesDefaultQueriesInitialized: function() {
|
||||
// bail out if the folder is already created
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
var createdDefaultQueries = false;
|
||||
try {
|
||||
createdDefaultQueries = prefBranch.getBoolPref("browser.places.createdDefaultQueries");
|
||||
} catch(ex) { }
|
||||
|
||||
if (createdDefaultQueries)
|
||||
return;
|
||||
|
||||
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
// XXXmano bug 405497: this should be batched even if we're not called from
|
||||
// the import service. However, calling runInBatchedMode from within a
|
||||
// RunBatched implementation hangs the browser.
|
||||
var callback = {
|
||||
_placesBundle: Cc["@mozilla.org/intl/stringbundle;1"].
|
||||
getService(Ci.nsIStringBundleService).
|
||||
createBundle("chrome://browser/locale/places/places.properties"),
|
||||
|
||||
_uri: function(aSpec) {
|
||||
return Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService).
|
||||
newURI(aSpec, null, null);
|
||||
},
|
||||
|
||||
runBatched: function() {
|
||||
var placesFolderTitle =
|
||||
this._placesBundle.GetStringFromName("placesFolderTitle");
|
||||
var recentlyCreatedBookmarksTitle =
|
||||
this._placesBundle.GetStringFromName("recentlyCreatedBookmarksTitle");
|
||||
var recentlyVisitedBookmarksTitle =
|
||||
this._placesBundle.GetStringFromName("recentlyVisitedBookmarksTitle");
|
||||
var mostVisitedBookmarksTitle =
|
||||
this._placesBundle.GetStringFromName("mostVisitedBookmarksTitle");
|
||||
var recentlyUsedTagsTitle =
|
||||
this._placesBundle.GetStringFromName("recentlyUsedTagsTitle");
|
||||
var mostUsedTagsTitle =
|
||||
this._placesBundle.GetStringFromName("mostUsedTagsTitle");
|
||||
var mostVisitedSitesTitle =
|
||||
this._placesBundle.GetStringFromName("mostVisitedSitesTitle");
|
||||
|
||||
var bookmarksMenuFolder = bmsvc.bookmarksMenuFolder;
|
||||
var unfiledBookmarksFolder = bmsvc.unfiledBookmarksFolder;
|
||||
var toolbarFolder = bmsvc.toolbarFolder;
|
||||
var tagsFolder = bmsvc.tagsFolder;
|
||||
var defaultIndex = bmsvc.DEFAULT_INDEX;
|
||||
|
||||
// index = 0, make it the first folder
|
||||
var placesFolder = bmsvc.createFolder(toolbarFolder, placesFolderTitle,
|
||||
0);
|
||||
|
||||
// XXX should this be a pref? see bug #399268
|
||||
var maxResults = 10;
|
||||
|
||||
// exclude queries so that user created "saved searches"
|
||||
// and these queries (added automatically) are excluded
|
||||
var recentlyCreatedBookmarksItem = bmsvc.insertBookmark(placesFolder,
|
||||
this._uri("place:folder=" + bookmarksMenuFolder +
|
||||
"&folder=" + unfiledBookmarksFolder +
|
||||
"&folder=" + toolbarFolder +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
||||
"&excludeItemIfParentHasAnnotation=livemark%2FfeedURI" +
|
||||
"&maxResults=" + maxResults +
|
||||
"&excludeQueries=1"),
|
||||
defaultIndex, recentlyCreatedBookmarksTitle);
|
||||
|
||||
var recentlyVisitedBookmarksItem = bmsvc.insertBookmark(placesFolder,
|
||||
this._uri("place:folder=" + bookmarksMenuFolder +
|
||||
"&folder=" + unfiledBookmarksFolder +
|
||||
"&folder=" + toolbarFolder +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&sort=" + Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING +
|
||||
"&excludeItemIfParentHasAnnotation=livemark%2FfeedURI" +
|
||||
"&minVisits=1&maxResults=" + maxResults),
|
||||
defaultIndex, recentlyVisitedBookmarksTitle);
|
||||
|
||||
var mostVisitedBookmarksItem = bmsvc.insertBookmark(placesFolder,
|
||||
this._uri("place:folder=" + bookmarksMenuFolder +
|
||||
"&folder=" + unfiledBookmarksFolder +
|
||||
"&folder=" + toolbarFolder +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
||||
"&excludeItemIfParentHasAnnotation=livemark%2FfeedURI" +
|
||||
"&minVisits=1&maxResults=" + maxResults),
|
||||
defaultIndex, mostVisitedBookmarksTitle);
|
||||
|
||||
var recentlyUsedTagsItem = bmsvc.insertBookmark(placesFolder,
|
||||
this._uri("place:folder=" + tagsFolder +
|
||||
"&group=" + Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&applyOptionsToContainers=1" +
|
||||
"&sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_DATEADDED_DESCENDING +
|
||||
"&maxResults=" + maxResults),
|
||||
defaultIndex, recentlyUsedTagsTitle);
|
||||
|
||||
var mostUsedTagsItem = bmsvc.insertBookmark(placesFolder,
|
||||
this._uri("place:folder=" + tagsFolder +
|
||||
"&group=" + Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER +
|
||||
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS +
|
||||
"&applyOptionsToContainers=1" +
|
||||
"&sort=" + Ci.nsINavHistoryQueryOptions.SORT_BY_COUNT_DESCENDING +
|
||||
"&maxResults=" + maxResults),
|
||||
defaultIndex, mostUsedTagsTitle);
|
||||
|
||||
var mostVisitedSitesItem = bmsvc.insertBookmark(placesFolder,
|
||||
this._uri("place:queryType=" +
|
||||
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY +
|
||||
"&sort=" +
|
||||
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
|
||||
"&maxResults=" + maxResults),
|
||||
defaultIndex, mostVisitedSitesTitle);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
callback.runBatched();
|
||||
// See XXX note above
|
||||
// bmsvc.runInBatchMode(callback, null);
|
||||
}
|
||||
catch(ex) {
|
||||
Components.utils.reportError(ex);
|
||||
}
|
||||
finally {
|
||||
prefBranch.setBoolPref("browser.places.createdDefaultQueries", true);
|
||||
prefBranch.savePrefFile(null);
|
||||
}
|
||||
},
|
||||
|
||||
// for XPCOM
|
||||
classDescription: "Firefox Browser Glue Service",
|
||||
classID: Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),
|
||||
|
@ -422,6 +564,3 @@ BrowserGlue.prototype = {
|
|||
function NSGetModule(aCompMgr, aFileSpec) {
|
||||
return XPCOMUtils.generateModule([BrowserGlue]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Giorgio Maone <g.maone@informaction.com>
|
||||
* Asaf Romano <mano@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -56,7 +57,7 @@ interface nsIDOMWindow;
|
|||
*
|
||||
*/
|
||||
|
||||
[scriptable, uuid(6d340848-9bc1-49a3-9073-99932bbc2a11)]
|
||||
[scriptable, uuid(01639c88-c0eb-4d75-9ee1-f325c1e04215)]
|
||||
interface nsIBrowserGlue : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -67,4 +68,9 @@ interface nsIBrowserGlue : nsISupports
|
|||
*
|
||||
*/
|
||||
void sanitize(in nsIDOMWindow aParentWindow);
|
||||
|
||||
/**
|
||||
* Add the special "Places" folder (with some special queries) to the personal toolbar folder.
|
||||
*/
|
||||
void ensurePlacesDefaultQueriesInitialized();
|
||||
};
|
||||
|
|
|
@ -69,3 +69,5 @@ CPPSRCS = nsPlacesImportExportService.cpp
|
|||
EXTRA_COMPONENTS = nsPlacesTransactionsService.js
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
XPIDL_FLAGS += -I$(topsrcdir)/browser/components
|
||||
|
|
|
@ -104,6 +104,7 @@
|
|||
#include "nsIParser.h"
|
||||
#include "prprf.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIBrowserGlue.h"
|
||||
|
||||
static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
|
||||
|
||||
|
@ -2264,6 +2265,13 @@ nsPlacesImportExportService::RunBatched(nsISupports* aUserData)
|
|||
|
||||
rv = mBookmarksService->RemoveFolderChildren(toolbarFolder);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// add the "Places" folder
|
||||
nsCOMPtr<nsIBrowserGlue> glue(do_GetService("@mozilla.org/browser/browserglue;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = glue->EnsurePlacesDefaultQueriesInitialized();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// streams
|
||||
|
|
|
@ -89,6 +89,10 @@ function run_test() {
|
|||
// get places import/export service
|
||||
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].getService(Ci.nsIPlacesImportExportService);
|
||||
|
||||
// avoid creating the places smart folder during tests
|
||||
Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).
|
||||
setBoolPref("browser.places.createdDefaultQueries", true);
|
||||
|
||||
// file pointer to legacy bookmarks file
|
||||
var bookmarksFileOld = do_get_file("browser/components/places/tests/unit/bookmarks.preplaces.html");
|
||||
// file pointer to a new places-exported bookmarks file
|
||||
|
|
Загрузка…
Ссылка в новой задаче