Bug 384370 ? use JSON as the on disk, lossless format for our bookmark backup - TESTING PERF (r=mconnor)

This commit is contained in:
dietrich@mozilla.com 2008-03-04 11:41:52 -08:00
Родитель 03afe204b5
Коммит f2ff676e82
31 изменённых файлов: 796 добавлений и 1395 удалений

Просмотреть файл

@ -320,9 +320,10 @@ pref("browser.tabs.selectOwnerOnClose", true);
pref("browser.bookmarks.sort.direction", "descending"); pref("browser.bookmarks.sort.direction", "descending");
pref("browser.bookmarks.sort.resource", "rdf:http://home.netscape.com/NC-rdf#Name"); pref("browser.bookmarks.sort.resource", "rdf:http://home.netscape.com/NC-rdf#Name");
// By default, do not overwrite bookmarks.html in the profile directory // By default, do not export HTML at shutdown.
// See bug #381216 for details // If true, at shutdown the bookmarks in your menu and toolbar will
pref("browser.bookmarks.overwrite", false); // be exported as HTML to the bookmarks.html file.
pref("browser.bookmarks.autoExportHTML", false);
// Scripts & Windows prefs // Scripts & Windows prefs
pref("dom.disable_open_during_load", true); pref("dom.disable_open_during_load", true);

Просмотреть файл

@ -329,7 +329,7 @@
</menu> </menu>
<menu id="history-menu" <menu id="history-menu"
oncommand="var url = event.target.getAttribute('statustext'); if (url) { PlacesUtils.markPageAsTyped(url); openUILink(url, event, false, true); }" oncommand="var url = event.target.getAttribute('statustext'); if (url) { PlacesUIUtils.markPageAsTyped(url); openUILink(url, event, false, true); }"
onclick="checkForMiddleClick(this, event);" onclick="checkForMiddleClick(this, event);"
label="&historyMenu.label;" label="&historyMenu.label;"
accesskey="&historyMenu.accesskey;"> accesskey="&historyMenu.accesskey;">

Просмотреть файл

@ -105,7 +105,7 @@ var StarUI = {
this._itemId = -1; this._itemId = -1;
this._uri = null; this._uri = null;
if (this._batching) { if (this._batching) {
PlacesUtils.ptm.endBatch(); PlacesUIUtils.ptm.endBatch();
this._batching = false; this._batching = false;
} }
} }
@ -188,11 +188,11 @@ var StarUI = {
// Otherwise, if no changes were done in the edit-item panel, the last // Otherwise, if no changes were done in the edit-item panel, the last
// transaction on the undo stack may be the initial createItem transaction, // transaction on the undo stack may be the initial createItem transaction,
// or worse, the batched editing of some other item. // or worse, the batched editing of some other item.
PlacesUtils.ptm.doTransaction({ doTransaction: function() { }, PlacesUIUtils.ptm.doTransaction({ doTransaction: function() { },
undoTransaction: function() { }, undoTransaction: function() { },
redoTransaction: function() { }, redoTransaction: function() { },
isTransient: false, isTransient: false,
merge: function() { return false; } }); merge: function() { return false; } });
if (this.panel.state == "closed") { if (this.panel.state == "closed") {
// Consume dismiss clicks, see bug 400924 // Consume dismiss clicks, see bug 400924
@ -271,7 +271,7 @@ var StarUI = {
cancelButtonOnCommand: function SU_cancelButtonOnCommand() { cancelButtonOnCommand: function SU_cancelButtonOnCommand() {
this.endBatch(); this.endBatch();
PlacesUtils.ptm.undoTransaction(); PlacesUIUtils.ptm.undoTransaction();
this.panel.hidePopup(); this.panel.hidePopup();
}, },
@ -282,8 +282,8 @@ var StarUI = {
// a "Bookmark Removed" notification along with an Undo button is // a "Bookmark Removed" notification along with an Undo button is
// shown // shown
if (this._batching) { if (this._batching) {
PlacesUtils.ptm.endBatch(); PlacesUIUtils.ptm.endBatch();
PlacesUtils.ptm.beginBatch(); // allow undo from within the notification PlacesUIUtils.ptm.beginBatch(); // allow undo from within the notification
var bundle = this._element("bundle_browser"); var bundle = this._element("bundle_browser");
// "Bookmark Removed" title (the description field is already empty in // "Bookmark Removed" title (the description field is already empty in
@ -308,8 +308,8 @@ var StarUI = {
// the tags for the url // the tags for the url
var itemIds = PlacesUtils.getBookmarksForURI(this._uri); var itemIds = PlacesUtils.getBookmarksForURI(this._uri);
for (var i=0; i < itemIds.length; i++) { for (var i=0; i < itemIds.length; i++) {
var txn = PlacesUtils.ptm.removeItem(itemIds[i]); var txn = PlacesUIUtils.ptm.removeItem(itemIds[i]);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
#ifdef ADVANCED_STARRING_UI #ifdef ADVANCED_STARRING_UI
@ -324,21 +324,21 @@ var StarUI = {
// restore the bookmark by undoing the last transaction and go back // restore the bookmark by undoing the last transaction and go back
// to the edit state // to the edit state
this.endBatch(); this.endBatch();
PlacesUtils.ptm.undoTransaction(); PlacesUIUtils.ptm.undoTransaction();
this._itemId = PlacesUtils.getMostRecentBookmarkForURI(this._uri); this._itemId = PlacesUtils.getMostRecentBookmarkForURI(this._uri);
this.showEditBookmarkPopup(); this.showEditBookmarkPopup();
}, },
beginBatch: function SU_beginBatch() { beginBatch: function SU_beginBatch() {
if (!this._batching) { if (!this._batching) {
PlacesUtils.ptm.beginBatch(); PlacesUIUtils.ptm.beginBatch();
this._batching = true; this._batching = true;
} }
}, },
endBatch: function SU_endBatch() { endBatch: function SU_endBatch() {
if (this._batching) { if (this._batching) {
PlacesUtils.ptm.endBatch(); PlacesUIUtils.ptm.endBatch();
this._batching = false; this._batching = false;
} }
} }
@ -372,7 +372,7 @@ var PlacesCommandHook = {
var description; var description;
try { try {
title = webNav.document.title || url.spec; title = webNav.document.title || url.spec;
description = PlacesUtils.getDescriptionFromDocument(webNav.document); description = PlacesUIUtils.getDescriptionFromDocument(webNav.document);
} }
catch (e) { } catch (e) { }
@ -386,9 +386,9 @@ var PlacesCommandHook = {
var parent = aParent != undefined ? var parent = aParent != undefined ?
aParent : PlacesUtils.unfiledBookmarksFolderId; aParent : PlacesUtils.unfiledBookmarksFolderId;
var descAnno = { name: DESCRIPTION_ANNO, value: description }; var descAnno = { name: DESCRIPTION_ANNO, value: description };
var txn = PlacesUtils.ptm.createItem(uri, parent, -1, var txn = PlacesUIUtils.ptm.createItem(uri, parent, -1,
title, null, [descAnno]); title, null, [descAnno]);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
itemId = PlacesUtils.getMostRecentBookmarkForURI(uri); itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
} }
@ -432,8 +432,8 @@ var PlacesCommandHook = {
var itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI); var itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI);
if (itemId == -1) { if (itemId == -1) {
StarUI.beginBatch(); StarUI.beginBatch();
var txn = PlacesUtils.ptm.createItem(linkURI, aParent, -1, aTitle); var txn = PlacesUIUtils.ptm.createItem(linkURI, aParent, -1, aTitle);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI); itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI);
} }
@ -474,7 +474,7 @@ var PlacesCommandHook = {
*/ */
bookmarkCurrentPages: function PCH_bookmarkCurrentPages() { bookmarkCurrentPages: function PCH_bookmarkCurrentPages() {
var tabURIs = this._getUniqueTabInfo(); var tabURIs = this._getUniqueTabInfo();
PlacesUtils.showMinimalAddMultiBookmarkUI(tabURIs); PlacesUIUtils.showMinimalAddMultiBookmarkUI(tabURIs);
}, },
@ -500,12 +500,12 @@ var PlacesCommandHook = {
if (arguments.length > 2) if (arguments.length > 2)
description = feedSubtitle; description = feedSubtitle;
else else
description = PlacesUtils.getDescriptionFromDocument(doc); description = PlacesUIUtils.getDescriptionFromDocument(doc);
var toolbarIP = var toolbarIP =
new InsertionPoint(PlacesUtils.bookmarks.toolbarFolder, -1); new InsertionPoint(PlacesUtils.bookmarks.toolbarFolder, -1);
PlacesUtils.showMinimalAddLivemarkUI(feedURI, gBrowser.currentURI, PlacesUIUtils.showMinimalAddLivemarkUI(feedURI, gBrowser.currentURI,
title, description, toolbarIP, true); title, description, toolbarIP, true);
}, },
/** /**
@ -581,7 +581,7 @@ var BookmarksEventHandler = {
return; return;
var target = aEvent.originalTarget; var target = aEvent.originalTarget;
var view = PlacesUtils.getViewForNode(target); var view = PlacesUIUtils.getViewForNode(target);
if (target.node && PlacesUtils.nodeIsFolder(target.node)) { if (target.node && PlacesUtils.nodeIsFolder(target.node)) {
// Don't open the root folder in tabs when the empty area on the toolbar // Don't open the root folder in tabs when the empty area on the toolbar
// is middle-clicked or when a non-bookmark item except for Open in Tabs) // is middle-clicked or when a non-bookmark item except for Open in Tabs)
@ -625,7 +625,7 @@ var BookmarksEventHandler = {
onCommand: function BM_onCommand(aEvent) { onCommand: function BM_onCommand(aEvent) {
var target = aEvent.originalTarget; var target = aEvent.originalTarget;
if (target.node) if (target.node)
PlacesUtils.openNodeWithEvent(target.node, aEvent); PlacesUIUtils.openNodeWithEvent(target.node, aEvent);
}, },
/** /**
@ -685,7 +685,7 @@ var BookmarksEventHandler = {
openHomePage.setAttribute("onclick", openHomePage.setAttribute("onclick",
"checkForMiddleClick(this, event); event.stopPropagation();"); "checkForMiddleClick(this, event); event.stopPropagation();");
openHomePage.setAttribute("label", openHomePage.setAttribute("label",
PlacesUtils.getFormattedString("menuOpenLivemarkOrigin.label", PlacesUIUtils.getFormattedString("menuOpenLivemarkOrigin.label",
[target.parentNode.getAttribute("label")])); [target.parentNode.getAttribute("label")]));
target.appendChild(openHomePage); target.appendChild(openHomePage);
} }
@ -694,7 +694,7 @@ var BookmarksEventHandler = {
var openInTabs = document.createElement("menuitem"); var openInTabs = document.createElement("menuitem");
openInTabs.setAttribute("openInTabs", "true"); openInTabs.setAttribute("openInTabs", "true");
openInTabs.setAttribute("oncommand", openInTabs.setAttribute("oncommand",
"PlacesUtils.openContainerNodeInTabs(this.parentNode._resultNode, event);"); "PlacesUIUtils.openContainerNodeInTabs(this.parentNode._resultNode, event);");
openInTabs.setAttribute("label", openInTabs.setAttribute("label",
gNavigatorBundle.getString("menuOpenAllInTabs.label")); gNavigatorBundle.getString("menuOpenAllInTabs.label"));
target.appendChild(openInTabs); target.appendChild(openInTabs);
@ -755,7 +755,7 @@ var BookmarksMenuDropHandler = {
getSupportedFlavours: function BMDH_getSupportedFlavours() { getSupportedFlavours: function BMDH_getSupportedFlavours() {
var flavorSet = new FlavourSet(); var flavorSet = new FlavourSet();
var view = document.getElementById("bookmarksMenuPopup"); var view = document.getElementById("bookmarksMenuPopup");
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES var types = PlacesUIUtils.GENERIC_VIEW_DROP_TYPES
for (var i = 0; i < types.length; ++i) for (var i = 0; i < types.length; ++i)
flavorSet.appendFlavour(types[i]); flavorSet.appendFlavour(types[i]);
return flavorSet; return flavorSet;

Просмотреть файл

@ -2549,7 +2549,7 @@ var bookmarksButtonObserver = {
var split = aXferData.data.split("\n"); var split = aXferData.data.split("\n");
var url = split[0]; var url = split[0];
if (url != aXferData.data) // do nothing if it's not a valid URL if (url != aXferData.data) // do nothing if it's not a valid URL
PlacesUtils.showMinimalAddBookmarkUI(makeURI(url), split[1]); PlacesUIUtils.showMinimalAddBookmarkUI(makeURI(url), split[1]);
}, },
onDragOver: function (aEvent, aFlavour, aDragSession) onDragOver: function (aEvent, aFlavour, aDragSession)
@ -3019,7 +3019,7 @@ function addToUrlbarHistory(aUrlToAdd)
try { try {
if (aUrlToAdd.indexOf(" ") == -1) { if (aUrlToAdd.indexOf(" ") == -1) {
PlacesUtils.markPageAsTyped(aUrlToAdd); PlacesUIUtils.markPageAsTyped(aUrlToAdd);
} }
} }
catch(ex) { catch(ex) {
@ -4430,9 +4430,9 @@ function asyncOpenWebPanel(event)
// This is the Opera convention for a special link that - when clicked - allows // This is the Opera convention for a special link that - when clicked - allows
// you to add a sidebar panel. We support the Opera convention here. The link's // you to add a sidebar panel. We support the Opera convention here. The link's
// title attribute contains the title that should be used for the sidebar panel. // title attribute contains the title that should be used for the sidebar panel.
PlacesUtils.showMinimalAddBookmarkUI(makeURI(wrapper.href), PlacesUIUtils.showMinimalAddBookmarkUI(makeURI(wrapper.href),
wrapper.getAttribute("title"), wrapper.getAttribute("title"),
null, null, true, true); null, null, true, true);
event.preventDefault(); event.preventDefault();
return false; return false;
} }
@ -5396,9 +5396,9 @@ function AddKeywordForSearchField()
else else
spec += "?" + formData.join("&"); spec += "?" + formData.join("&");
var description = PlacesUtils.getDescriptionFromDocument(node.ownerDocument); var description = PlacesUIUtils.getDescriptionFromDocument(node.ownerDocument);
PlacesUtils.showMinimalAddBookmarkUI(makeURI(spec), "", description, null, PlacesUIUtils.showMinimalAddBookmarkUI(makeURI(spec), "", description, null,
null, null, "", postData); null, null, "", postData);
} }
function SwitchDocumentDirection(aWindow) { function SwitchDocumentDirection(aWindow) {

Просмотреть файл

@ -1191,13 +1191,13 @@ nsContextMenu.prototype = {
var itemId = PlacesUtils.getMostRecentBookmarkForURI(uri); var itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
if (itemId == -1) { if (itemId == -1) {
var title = doc.title; var title = doc.title;
var description = PlacesUtils.getDescriptionFromDocument(doc); var description = PlacesUIUtils.getDescriptionFromDocument(doc);
var descAnno = { name: DESCRIPTION_ANNO, value: description }; var descAnno = { name: DESCRIPTION_ANNO, value: description };
var txn = PlacesUtils.ptm.createItem(uri, var txn = PlacesUIUtils.ptm.createItem(uri,
PlacesUtils.bookmarksMenuFolderId, PlacesUtils.bookmarksMenuFolderId,
-1, title, null, [descAnno]); -1, title, null, [descAnno]);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
itemId = PlacesUtils.getMostRecentBookmarkForURI(uri); itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
StarUI.beginBatch(); StarUI.beginBatch();
} }

Просмотреть файл

@ -45,6 +45,13 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource:///modules/distribution.js"); Cu.import("resource:///modules/distribution.js");
// Check to see if bookmarks need backing up once per
// day on 1 hour idle.
const BOOKMARKS_ARCHIVE_IDLE_TIME = 60 * 60;
// Backup bookmarks once every 24 hours.
const BOOKMARKS_ARCHIVE_INTERVAL = 86400 * 1000;
// Factory object // Factory object
const BrowserGlueServiceFactory = { const BrowserGlueServiceFactory = {
_instance: null, _instance: null,
@ -103,15 +110,23 @@ BrowserGlue.prototype = {
if (this._saveSession) { if (this._saveSession) {
this._setPrefToSaveSession(); this._setPrefToSaveSession();
} }
this._shutdownPlaces();
this.idleService.removeIdleObserver(this, BOOKMARKS_ARCHIVE_IDLE_TIME);
break; break;
case "session-save": case "session-save":
this._setPrefToSaveSession(); this._setPrefToSaveSession();
subject.QueryInterface(Ci.nsISupportsPRBool); subject.QueryInterface(Ci.nsISupportsPRBool);
subject.data = true; subject.data = true;
break; break;
case "idle":
if (this.idleService.idleTime > BOOKMARKS_ARCHIVE_IDLE_TIME * 1000) {
// Back up bookmarks.
this._archiveBookmarks();
}
break;
} }
} },
,
// initialization (called on application startup) // initialization (called on application startup)
_init: function() _init: function()
{ {
@ -324,6 +339,14 @@ BrowserGlue.prototype = {
return Sanitizer; return Sanitizer;
}, },
_idleService: null,
get idleService() {
if (!this._idleService)
this._idleService = Cc["@mozilla.org/widget/idleservice;1"].
getService(Ci.nsIIdleService);
return this._idleService;
},
/** /**
* Initialize Places * Initialize Places
* - imports the bookmarks html file if bookmarks datastore is empty * - imports the bookmarks html file if bookmarks datastore is empty
@ -336,10 +359,11 @@ BrowserGlue.prototype = {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"]. var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService); getService(Ci.nsINavHistoryService);
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
var importBookmarks = false; var importBookmarks = false;
try { try {
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
importBookmarks = prefBranch.getBoolPref("browser.places.importBookmarksHTML"); importBookmarks = prefBranch.getBoolPref("browser.places.importBookmarksHTML");
} catch(ex) {} } catch(ex) {}
@ -355,46 +379,39 @@ BrowserGlue.prototype = {
// Call it here for Fx3 profiles created before the Places folder // Call it here for Fx3 profiles created before the Places folder
// has been added, otherwise it's called during import. // has been added, otherwise it's called during import.
this.ensurePlacesDefaultQueriesInitialized(); this.ensurePlacesDefaultQueriesInitialized();
return;
} }
else {
// ensurePlacesDefaultQueriesInitialized() is called by import.
prefBranch.setBoolPref("browser.places.createdSmartBookmarks", false);
// ensurePlacesDefaultQueriesInitialized() is called by import. // get latest backup
prefBranch.setBoolPref("browser.places.createdSmartBookmarks", false); Cu.import("resource://gre/modules/utils.js");
var bookmarksFile = PlacesUtils.getMostRecentBackup();
var dirService = Cc["@mozilla.org/file/directory_service;1"]. if (bookmarksFile.leafName.match("\.json$")) {
getService(Ci.nsIProperties); // restore a JSON backup
PlacesUtils.restoreBookmarksFromJSONFile(bookmarksFile);
var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
if (bookmarksFile.exists()) {
// import the file
try {
var importer =
Cc["@mozilla.org/browser/places/import-export-service;1"].
getService(Ci.nsIPlacesImportExportService);
importer.importHTMLFromFile(bookmarksFile, true);
} catch(ex) {
} finally {
prefBranch.setBoolPref("browser.places.importBookmarksHTML", false);
} }
else {
// if there's no json backup use bookmarks.html
var dirService = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
// only back up pre-places bookmarks.html if we plan on overwriting it // import the file
if (prefBranch.getBoolPref("browser.bookmarks.overwrite")) { try {
// backup pre-places bookmarks.html var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
// XXXtodo remove this before betas, after import/export is solid getService(Ci.nsIPlacesImportExportService);
var profDir = dirService.get("ProfD", Ci.nsILocalFile); importer.importHTMLFromFile(bookmarksFile, true /* overwrite existing */);
var bookmarksBackup = profDir.clone(); } finally {
bookmarksBackup.append("bookmarks.preplaces.html"); prefBranch.setBoolPref("browser.places.importBookmarksHTML", false);
if (!bookmarksBackup.exists()) {
// save old bookmarks.html file as bookmarks.preplaces.html
try {
bookmarksFile.copyTo(profDir, "bookmarks.preplaces.html");
} catch(ex) {
dump("nsBrowserGlue::_initPlaces(): copy of bookmarks.html to bookmarks.preplaces.html failed: " + ex + "\n");
}
} }
} }
} }
// Initialize bookmark archiving on idle.
// Once a day, either on idle or shutdown, bookmarks are backed up.
this.idleService.addIdleObserver(this, BOOKMARKS_ARCHIVE_IDLE_TIME);
}, },
/** /**

Просмотреть файл

@ -567,8 +567,8 @@ var BookmarkPropertiesPanel = {
var itemToSelect = userEnteredNameField; var itemToSelect = userEnteredNameField;
try { try {
this._microsummaries = this._microsummaries =
PlacesUtils.microsummaries.getMicrosummaries(this._bookmarkURI, PlacesUIUtils.microsummaries.getMicrosummaries(this._bookmarkURI,
this._bookmarkId); this._bookmarkId);
} }
catch(ex) { catch(ex) {
// getMicrosummaries will throw an exception if the page to which the URI // getMicrosummaries will throw an exception if the page to which the URI
@ -590,8 +590,8 @@ var BookmarkPropertiesPanel = {
var menuItem = this._createMicrosummaryMenuItem(microsummary); var menuItem = this._createMicrosummaryMenuItem(microsummary);
if (this._action == ACTION_EDIT && if (this._action == ACTION_EDIT &&
PlacesUtils.microsummaries PlacesUIUtils.microsummaries
.isMicrosummary(this._bookmarkId, microsummary)) .isMicrosummary(this._bookmarkId, microsummary))
itemToSelect = menuItem; itemToSelect = menuItem;
menupopup.appendChild(menuItem); menupopup.appendChild(menuItem);
@ -713,7 +713,7 @@ var BookmarkPropertiesPanel = {
try { try {
var value = this._element(aTextboxID).value; var value = this._element(aTextboxID).value;
if (value) { if (value) {
var uri = PlacesUtils.createFixedURI(value); var uri = PlacesUIUtils.createFixedURI(value);
return true; return true;
} }
} catch (e) { } } catch (e) { }
@ -725,7 +725,7 @@ var BookmarkPropertiesPanel = {
*/ */
_getEditTitleTransaction: _getEditTitleTransaction:
function BPP__getEditTitleTransaction(aItemId, aNewTitle) { function BPP__getEditTitleTransaction(aItemId, aNewTitle) {
return PlacesUtils.ptm.editItemTitle(aItemId, aNewTitle); return PlacesUIUtils.ptm.editItemTitle(aItemId, aNewTitle);
}, },
/** /**
@ -813,21 +813,21 @@ var BookmarkPropertiesPanel = {
// description // description
var description = this._element("descriptionTextfield").value; var description = this._element("descriptionTextfield").value;
if (description != this._itemDescription) { if (description != this._itemDescription) {
transactions.push(PlacesUtils.ptm. transactions.push(PlacesUIUtils.ptm.
editItemDescription(itemId, description, editItemDescription(itemId, description,
this._itemType != BOOKMARK_ITEM)); this._itemType != BOOKMARK_ITEM));
} }
if (this._itemType == BOOKMARK_ITEM) { if (this._itemType == BOOKMARK_ITEM) {
// location // location
var url = PlacesUtils.createFixedURI(this._element("editURLBar").value); var url = PlacesUIUtils.createFixedURI(this._element("editURLBar").value);
if (!this._bookmarkURI.equals(url)) if (!this._bookmarkURI.equals(url))
transactions.push(PlacesUtils.ptm.editBookmarkURI(itemId, url)); transactions.push(PlacesUIUtils.ptm.editBookmarkURI(itemId, url));
// keyword transactions // keyword transactions
var newKeyword = this._element("keywordTextfield").value; var newKeyword = this._element("keywordTextfield").value;
if (newKeyword != this._bookmarkKeyword) { if (newKeyword != this._bookmarkKeyword) {
transactions.push(PlacesUtils.ptm. transactions.push(PlacesUIUtils.ptm.
editBookmarkKeyword(itemId, newKeyword)); editBookmarkKeyword(itemId, newKeyword));
} }
@ -841,39 +841,39 @@ var BookmarkPropertiesPanel = {
// selected a microsummary which is not the one the bookmark previously // selected a microsummary which is not the one the bookmark previously
// had. // had.
if ((newMicrosummary == null && if ((newMicrosummary == null &&
PlacesUtils.microsummaries.hasMicrosummary(itemId)) || PlacesUIUtils.microsummaries.hasMicrosummary(itemId)) ||
(newMicrosummary != null && (newMicrosummary != null &&
!PlacesUtils.microsummaries !PlacesUIUtils.microsummaries
.isMicrosummary(itemId, newMicrosummary))) { .isMicrosummary(itemId, newMicrosummary))) {
transactions.push( transactions.push(
PlacesUtils.ptm.editBookmarkMicrosummary(itemId, newMicrosummary)); PlacesUIUtils.ptm.editBookmarkMicrosummary(itemId, newMicrosummary));
} }
// load in sidebar // load in sidebar
var loadInSidebarChecked = this._element("loadInSidebarCheckbox").checked; var loadInSidebarChecked = this._element("loadInSidebarCheckbox").checked;
if (loadInSidebarChecked != this._loadBookmarkInSidebar) { if (loadInSidebarChecked != this._loadBookmarkInSidebar) {
transactions.push( transactions.push(
PlacesUtils.ptm.setLoadInSidebar(itemId, loadInSidebarChecked)); PlacesUIUtils.ptm.setLoadInSidebar(itemId, loadInSidebarChecked));
} }
} }
else if (this._itemType == LIVEMARK_CONTAINER) { else if (this._itemType == LIVEMARK_CONTAINER) {
var feedURIString = this._element("feedLocationTextfield").value; var feedURIString = this._element("feedLocationTextfield").value;
var feedURI = PlacesUtils.createFixedURI(feedURIString); var feedURI = PlacesUIUtils.createFixedURI(feedURIString);
if (!this._feedURI.equals(feedURI)) { if (!this._feedURI.equals(feedURI)) {
transactions.push( transactions.push(
PlacesUtils.ptm.editLivemarkFeedURI(this._folderId, feedURI)); PlacesUIUtils.ptm.editLivemarkFeedURI(this._folderId, feedURI));
} }
// Site Location is empty, we can set its URI to null // Site Location is empty, we can set its URI to null
var newSiteURIString = this._element("feedSiteLocationTextfield").value; var newSiteURIString = this._element("feedSiteLocationTextfield").value;
var newSiteURI = null; var newSiteURI = null;
if (newSiteURIString) if (newSiteURIString)
newSiteURI = PlacesUtils.createFixedURI(newSiteURIString); newSiteURI = PlacesUIUtils.createFixedURI(newSiteURIString);
if ((!newSiteURI && this._siteURI) || if ((!newSiteURI && this._siteURI) ||
(newSiteURI && (!this._siteURI || !this._siteURI.equals(newSiteURI)))) { (newSiteURI && (!this._siteURI || !this._siteURI.equals(newSiteURI)))) {
transactions.push( transactions.push(
PlacesUtils.ptm.editLivemarkSiteURI(this._folderId, newSiteURI)); PlacesUIUtils.ptm.editLivemarkSiteURI(this._folderId, newSiteURI));
} }
} }
@ -882,8 +882,8 @@ var BookmarkPropertiesPanel = {
if (transactions.length > 0) { if (transactions.length > 0) {
window.arguments[0].performed = true; window.arguments[0].performed = true;
var aggregate = var aggregate =
PlacesUtils.ptm.aggregateTransactions(this._getDialogTitle(), transactions); PlacesUIUtils.ptm.aggregateTransactions(this._getDialogTitle(), transactions);
PlacesUtils.ptm.doTransaction(aggregate); PlacesUIUtils.ptm.doTransaction(aggregate);
} }
}, },
@ -912,7 +912,7 @@ var BookmarkPropertiesPanel = {
*/ */
_getCreateNewBookmarkTransaction: _getCreateNewBookmarkTransaction:
function BPP__getCreateNewBookmarkTransaction(aContainer, aIndex) { function BPP__getCreateNewBookmarkTransaction(aContainer, aIndex) {
var uri = PlacesUtils.createFixedURI(this._element("editURLBar").value); var uri = PlacesUIUtils.createFixedURI(this._element("editURLBar").value);
var title = this._element("userEnteredName").label; var title = this._element("userEnteredName").label;
var keyword = this._element("keywordTextfield").value; var keyword = this._element("keywordTextfield").value;
var annotations = []; var annotations = [];
@ -928,20 +928,20 @@ var BookmarkPropertiesPanel = {
var microsummary = this._element("namePicker").selectedItem.microsummary; var microsummary = this._element("namePicker").selectedItem.microsummary;
if (microsummary) { if (microsummary) {
childTransactions.push( childTransactions.push(
PlacesUtils.ptm.editBookmarkMicrosummary(-1, microsummary)); PlacesUIUtils.ptm.editBookmarkMicrosummary(-1, microsummary));
} }
if (this._postData) { if (this._postData) {
childTransactions.push( childTransactions.push(
PlacesUtils.ptm.editBookmarkPostData(-1, this._postData)); PlacesUIUtils.ptm.editBookmarkPostData(-1, this._postData));
} }
var transactions = [PlacesUtils.ptm.createItem(uri, aContainer, aIndex, var transactions = [PlacesUIUtils.ptm.createItem(uri, aContainer, aIndex,
title, keyword, title, keyword,
annotations, annotations,
childTransactions)]; childTransactions)];
return PlacesUtils.ptm.aggregateTransactions(this._getDialogTitle(), transactions); return PlacesUIUtils.ptm.aggregateTransactions(this._getDialogTitle(), transactions);
}, },
/** /**
@ -953,7 +953,7 @@ var BookmarkPropertiesPanel = {
for (var i = 0; i < this._URIList.length; ++i) { for (var i = 0; i < this._URIList.length; ++i) {
var uri = this._URIList[i]; var uri = this._URIList[i];
var title = this._getURITitleFromHistory(uri); var title = this._getURITitleFromHistory(uri);
transactions.push(PlacesUtils.ptm.createItem(uri, -1, -1, title)); transactions.push(PlacesUIUtils.ptm.createItem(uri, -1, -1, title));
} }
return transactions; return transactions;
}, },
@ -973,8 +973,8 @@ var BookmarkPropertiesPanel = {
if (description) if (description)
annotations.push(this._getDescriptionAnnotation(description)); annotations.push(this._getDescriptionAnnotation(description));
return PlacesUtils.ptm.createFolder(folderName, aContainer, aIndex, return PlacesUIUtils.ptm.createFolder(folderName, aContainer, aIndex,
annotations, childItemsTransactions); annotations, childItemsTransactions);
}, },
/** /**
@ -984,16 +984,16 @@ var BookmarkPropertiesPanel = {
_getCreateNewLivemarkTransaction: _getCreateNewLivemarkTransaction:
function BPP__getCreateNewLivemarkTransaction(aContainer, aIndex) { function BPP__getCreateNewLivemarkTransaction(aContainer, aIndex) {
var feedURIString = this._element("feedLocationTextfield").value; var feedURIString = this._element("feedLocationTextfield").value;
var feedURI = PlacesUtils.createFixedURI(feedURIString); var feedURI = PlacesUIUtils.createFixedURI(feedURIString);
var siteURIString = this._element("feedSiteLocationTextfield").value; var siteURIString = this._element("feedSiteLocationTextfield").value;
var siteURI = null; var siteURI = null;
if (siteURIString) if (siteURIString)
siteURI = PlacesUtils.createFixedURI(siteURIString); siteURI = PlacesUIUtils.createFixedURI(siteURIString);
var name = this._element("namePicker").value; var name = this._element("namePicker").value;
return PlacesUtils.ptm.createLivemark(feedURI, siteURI, name, return PlacesUIUtils.ptm.createLivemark(feedURI, siteURI, name,
aContainer, aIndex); aContainer, aIndex);
}, },
/** /**
@ -1018,7 +1018,7 @@ var BookmarkPropertiesPanel = {
// perfrom our transaction do via the transaction manager passed by the // perfrom our transaction do via the transaction manager passed by the
// opener so it can be undone. // opener so it can be undone.
window.arguments[0].performed = true; window.arguments[0].performed = true;
PlacesUtils.ptm.doTransaction(createTxn); PlacesUIUtils.ptm.doTransaction(createTxn);
}, },
onNamePickerInput: function BPP_onNamePickerInput() { onNamePickerInput: function BPP_onNamePickerInput() {
@ -1049,7 +1049,7 @@ var BookmarkPropertiesPanel = {
if (!this._folderTree.place) { if (!this._folderTree.place) {
const FOLDER_TREE_PLACE_URI = const FOLDER_TREE_PLACE_URI =
"place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" + "place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" +
PlacesUtils.allBookmarksFolderId; PlacesUIUtils.allBookmarksFolderId;
this._folderTree.place = FOLDER_TREE_PLACE_URI; this._folderTree.place = FOLDER_TREE_PLACE_URI;
} }

Просмотреть файл

@ -37,7 +37,7 @@
function init() { function init() {
document.getElementById("bookmarks-view").place = document.getElementById("bookmarks-view").place =
"place:queryType=1&folder=" + window.top.PlacesUtils.allBookmarksFolderId; "place:queryType=1&folder=" + window.top.PlacesUIUtils.allBookmarksFolderId;
document.getElementById("search-box").focus(); document.getElementById("search-box").focus();
} }

Просмотреть файл

@ -103,9 +103,9 @@ PlacesController.prototype = {
isCommandEnabled: function PC_isCommandEnabled(aCommand) { isCommandEnabled: function PC_isCommandEnabled(aCommand) {
switch (aCommand) { switch (aCommand) {
case "cmd_undo": case "cmd_undo":
return PlacesUtils.ptm.numberOfUndoItems > 0; return PlacesUIUtils.ptm.numberOfUndoItems > 0;
case "cmd_redo": case "cmd_redo":
return PlacesUtils.ptm.numberOfRedoItems > 0; return PlacesUIUtils.ptm.numberOfRedoItems > 0;
case "cmd_cut": case "cmd_cut":
case "cmd_delete": case "cmd_delete":
return this._hasRemovableSelection(false); return this._hasRemovableSelection(false);
@ -152,7 +152,7 @@ PlacesController.prototype = {
case "placesCmd_reloadMicrosummary": case "placesCmd_reloadMicrosummary":
var selectedNode = this._view.selectedNode; var selectedNode = this._view.selectedNode;
return selectedNode && PlacesUtils.nodeIsBookmark(selectedNode) && return selectedNode && PlacesUtils.nodeIsBookmark(selectedNode) &&
PlacesUtils.microsummaries.hasMicrosummary(selectedNode.itemId); PlacesUIUtils.microsummaries.hasMicrosummary(selectedNode.itemId);
case "placesCmd_reload": case "placesCmd_reload":
// Livemark containers // Livemark containers
var selectedNode = this._view.selectedNode; var selectedNode = this._view.selectedNode;
@ -192,10 +192,10 @@ PlacesController.prototype = {
doCommand: function PC_doCommand(aCommand) { doCommand: function PC_doCommand(aCommand) {
switch (aCommand) { switch (aCommand) {
case "cmd_undo": case "cmd_undo":
PlacesUtils.ptm.undoTransaction(); PlacesUIUtils.ptm.undoTransaction();
break; break;
case "cmd_redo": case "cmd_redo":
PlacesUtils.ptm.redoTransaction(); PlacesUIUtils.ptm.redoTransaction();
break; break;
case "cmd_cut": case "cmd_cut":
this.cut(); this.cut();
@ -213,13 +213,13 @@ PlacesController.prototype = {
this.selectAll(); this.selectAll();
break; break;
case "placesCmd_open": case "placesCmd_open":
PlacesUtils.openNodeIn(this._view.selectedNode, "current"); PlacesUIUtils.openNodeIn(this._view.selectedNode, "current");
break; break;
case "placesCmd_open:window": case "placesCmd_open:window":
PlacesUtils.openNodeIn(this._view.selectedNode, "window"); PlacesUIUtils.openNodeIn(this._view.selectedNode, "window");
break; break;
case "placesCmd_open:tab": case "placesCmd_open:tab":
PlacesUtils.openNodeIn(this._view.selectedNode, "tab"); PlacesUIUtils.openNodeIn(this._view.selectedNode, "tab");
break; break;
case "placesCmd_new:folder": case "placesCmd_new:folder":
this.newItem("folder"); this.newItem("folder");
@ -337,8 +337,8 @@ PlacesController.prototype = {
// if the clipboard contains TYPE_X_MOZ_PLACE_* data, it is definitely // if the clipboard contains TYPE_X_MOZ_PLACE_* data, it is definitely
// pasteable, with no need to unwrap all the nodes. // pasteable, with no need to unwrap all the nodes.
var flavors = PlacesUtils.placesFlavors; var flavors = PlacesUIUtils.placesFlavors;
var clipboard = PlacesUtils.clipboard; var clipboard = PlacesUIUtils.clipboard;
var hasPlacesData = var hasPlacesData =
clipboard.hasDataMatchingFlavors(flavors, flavors.length, clipboard.hasDataMatchingFlavors(flavors, flavors.length,
Ci.nsIClipboard.kGlobalClipboard); Ci.nsIClipboard.kGlobalClipboard);
@ -442,7 +442,7 @@ PlacesController.prototype = {
uri = PlacesUtils._uri(node.uri); uri = PlacesUtils._uri(node.uri);
if (PlacesUtils.nodeIsBookmark(node)) { if (PlacesUtils.nodeIsBookmark(node)) {
nodeData["bookmark"] = true; nodeData["bookmark"] = true;
var mss = PlacesUtils.microsummaries; var mss = PlacesUIUtils.microsummaries;
if (mss.hasMicrosummary(node.itemId)) if (mss.hasMicrosummary(node.itemId))
nodeData["microsummary"] = true; nodeData["microsummary"] = true;
else if (node.parent && else if (node.parent &&
@ -628,9 +628,9 @@ PlacesController.prototype = {
return; return;
if (PlacesUtils.nodeIsFolder(node)) if (PlacesUtils.nodeIsFolder(node))
PlacesUtils.showFolderProperties(node.itemId); PlacesUIUtils.showFolderProperties(node.itemId);
else if (PlacesUtils.nodeIsBookmark(node)) else if (PlacesUtils.nodeIsBookmark(node))
PlacesUtils.showBookmarkProperties(node.itemId); PlacesUIUtils.showBookmarkProperties(node.itemId);
}, },
/** /**
@ -656,7 +656,7 @@ PlacesController.prototype = {
*/ */
reloadSelectedMicrosummary: function PC_reloadSelectedMicrosummary() { reloadSelectedMicrosummary: function PC_reloadSelectedMicrosummary() {
var selectedNode = this._view.selectedNode; var selectedNode = this._view.selectedNode;
var mss = PlacesUtils.microsummaries; var mss = PlacesUIUtils.microsummaries;
if (mss.hasMicrosummary(selectedNode.itemId)) if (mss.hasMicrosummary(selectedNode.itemId))
mss.refreshMicrosummary(selectedNode.itemId); mss.refreshMicrosummary(selectedNode.itemId);
}, },
@ -688,14 +688,14 @@ PlacesController.prototype = {
GetStringFromName("brandShortName"); GetStringFromName("brandShortName");
var buttonPressed = promptService.confirmEx(window, var buttonPressed = promptService.confirmEx(window,
PlacesUtils.getString("tabs.openWarningTitle"), PlacesUIUtils.getString("tabs.openWarningTitle"),
PlacesUtils.getFormattedString(messageKey, PlacesUIUtils.getFormattedString(messageKey,
[numTabsToOpen, brandShortName]), [numTabsToOpen, brandShortName]),
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0) (promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0)
+ (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1), + (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
PlacesUtils.getString(openKey), PlacesUIUtils.getString(openKey),
null, null, null, null,
PlacesUtils.getFormattedString("tabs.openWarningPromptMeBranded", PlacesUIUtils.getFormattedString("tabs.openWarningPromptMeBranded",
[brandShortName]), [brandShortName]),
warnOnOpen); warnOnOpen);
@ -714,9 +714,9 @@ PlacesController.prototype = {
openSelectionInTabs: function PC_openLinksInTabs(aEvent) { openSelectionInTabs: function PC_openLinksInTabs(aEvent) {
var node = this._view.selectedNode; var node = this._view.selectedNode;
if (node && PlacesUtils.nodeIsContainer(node)) if (node && PlacesUtils.nodeIsContainer(node))
PlacesUtils.openContainerNodeInTabs(this._view.selectedNode, aEvent); PlacesUIUtils.openContainerNodeInTabs(this._view.selectedNode, aEvent);
else else
PlacesUtils.openURINodesInTabs(this._view.getSelectionNodes(), aEvent); PlacesUIUtils.openURINodesInTabs(this._view.getSelectionNodes(), aEvent);
}, },
/** /**
@ -732,11 +732,11 @@ PlacesController.prototype = {
var performed = false; var performed = false;
if (aType == "bookmark") if (aType == "bookmark")
performed = PlacesUtils.showAddBookmarkUI(null, null, null, ip); performed = PlacesUIUtils.showAddBookmarkUI(null, null, null, ip);
else if (aType == "livemark") else if (aType == "livemark")
performed = PlacesUtils.showAddLivemarkUI(null, null, null, null, ip); performed = PlacesUIUtils.showAddLivemarkUI(null, null, null, null, ip);
else // folder else // folder
performed = PlacesUtils.showAddFolderUI(null, ip); performed = PlacesUIUtils.showAddFolderUI(null, ip);
if (performed) { if (performed) {
// select the new item // select the new item
@ -757,7 +757,7 @@ PlacesController.prototype = {
throw Cr.NS_ERROR_NOT_AVAILABLE; throw Cr.NS_ERROR_NOT_AVAILABLE;
var performed = false; var performed = false;
performed = PlacesUtils.showAddFolderUI(null, ip); performed = PlacesUIUtils.showAddFolderUI(null, ip);
if (performed) { if (performed) {
// select the new item // select the new item
var insertedNodeId = PlacesUtils.bookmarks var insertedNodeId = PlacesUtils.bookmarks
@ -773,8 +773,8 @@ PlacesController.prototype = {
var ip = this._view.insertionPoint; var ip = this._view.insertionPoint;
if (!ip) if (!ip)
throw Cr.NS_ERROR_NOT_AVAILABLE; throw Cr.NS_ERROR_NOT_AVAILABLE;
var txn = PlacesUtils.ptm.createSeparator(ip.itemId, ip.index); var txn = PlacesUIUtils.ptm.createSeparator(ip.itemId, ip.index);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
// select the new item // select the new item
var insertedNodeId = PlacesUtils.bookmarks var insertedNodeId = PlacesUtils.bookmarks
.getIdForItemAt(ip.itemId, ip.index); .getIdForItemAt(ip.itemId, ip.index);
@ -795,8 +795,8 @@ PlacesController.prototype = {
*/ */
sortFolderByName: function PC_sortFolderByName() { sortFolderByName: function PC_sortFolderByName() {
var itemId = PlacesUtils.getConcreteItemId(this._view.selectedNode); var itemId = PlacesUtils.getConcreteItemId(this._view.selectedNode);
var txn = PlacesUtils.ptm.sortFolderByName(itemId); var txn = PlacesUIUtils.ptm.sortFolderByName(itemId);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
}, },
/** /**
@ -856,7 +856,7 @@ PlacesController.prototype = {
if (PlacesUtils.nodeIsFolder(node)) if (PlacesUtils.nodeIsFolder(node))
removedFolders.push(node); removedFolders.push(node);
transactions.push(PlacesUtils.ptm.removeItem(node.itemId)); transactions.push(PlacesUIUtils.ptm.removeItem(node.itemId));
} }
}, },
@ -873,8 +873,8 @@ PlacesController.prototype = {
for (var i = ranges.length - 1; i >= 0 ; --i) for (var i = ranges.length - 1; i >= 0 ; --i)
this._removeRange(ranges[i], transactions); this._removeRange(ranges[i], transactions);
if (transactions.length > 0) { if (transactions.length > 0) {
var txn = PlacesUtils.ptm.aggregateTransactions(txnName, transactions); var txn = PlacesUIUtils.ptm.aggregateTransactions(txnName, transactions);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
}, },
@ -997,7 +997,7 @@ PlacesController.prototype = {
var data = new TransferData(); var data = new TransferData();
function addData(type, overrideURI) { function addData(type, overrideURI) {
data.addDataForFlavour(type, PlacesUtils._wrapString( data.addDataForFlavour(type, PlacesUIUtils._wrapString(
PlacesUtils.wrapNode(node, type, overrideURI))); PlacesUtils.wrapNode(node, type, overrideURI)));
} }
@ -1075,7 +1075,7 @@ PlacesController.prototype = {
function addData(type, data) { function addData(type, data) {
xferable.addDataFlavor(type); xferable.addDataFlavor(type);
xferable.setTransferData(type, PlacesUtils._wrapString(data), data.length * 2); xferable.setTransferData(type, PlacesUIUtils._wrapString(data), data.length * 2);
} }
// This order is _important_! It controls how this and other applications // This order is _important_! It controls how this and other applications
// select data to be inserted based on type. // select data to be inserted based on type.
@ -1089,7 +1089,7 @@ PlacesController.prototype = {
addData(PlacesUtils.TYPE_HTML, htmlString); addData(PlacesUtils.TYPE_HTML, htmlString);
if (placeString || unicodeString || htmlString || mozURLString) { if (placeString || unicodeString || htmlString || mozURLString) {
PlacesUtils.clipboard.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard); PlacesUIUtils.clipboard.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard);
} }
} }
finally { finally {
@ -1116,6 +1116,7 @@ PlacesController.prototype = {
// clipboard. We need to get all of that data and build edit transactions // clipboard. We need to get all of that data and build edit transactions
// for them. This means asking the clipboard once for each type and // for them. This means asking the clipboard once for each type and
// aggregating the results. // aggregating the results.
dump("PASTING\n");
/** /**
* Constructs a transferable that can receive data of specific types. * Constructs a transferable that can receive data of specific types.
@ -1133,7 +1134,7 @@ PlacesController.prototype = {
return xferable; return xferable;
} }
var clipboard = PlacesUtils.clipboard; var clipboard = PlacesUIUtils.clipboard;
var ip = this._view.insertionPoint; var ip = this._view.insertionPoint;
if (!ip) if (!ip)
@ -1161,9 +1162,9 @@ PlacesController.prototype = {
// transactions insert differently if index == -1 // transactions insert differently if index == -1
if (ip.index > -1) if (ip.index > -1)
index = ip.index + i; index = ip.index + i;
transactions.push(PlacesUtils.makeTransaction(items[i], type.value, transactions.push(PlacesUIUtils.makeTransaction(items[i], type.value,
ip.itemId, index, ip.itemId, index,
true)); true));
} }
return transactions; return transactions;
} }
@ -1182,8 +1183,8 @@ PlacesController.prototype = {
var transactions = getTransactions([PlacesUtils.TYPE_X_MOZ_PLACE, var transactions = getTransactions([PlacesUtils.TYPE_X_MOZ_PLACE,
PlacesUtils.TYPE_X_MOZ_URL, PlacesUtils.TYPE_X_MOZ_URL,
PlacesUtils.TYPE_UNICODE]); PlacesUtils.TYPE_UNICODE]);
var txn = PlacesUtils.ptm.aggregateTransactions("Paste", transactions); var txn = PlacesUIUtils.ptm.aggregateTransactions("Paste", transactions);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
// select the pasted items, they should be consecutive // select the pasted items, they should be consecutive
var insertedNodeIds = []; var insertedNodeIds = [];
@ -1243,7 +1244,7 @@ var PlacesControllerDragHelper = {
canDrop: function PCDH_canDrop() { canDrop: function PCDH_canDrop() {
var session = this.getSession(); var session = this.getSession();
if (session) { if (session) {
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES; var types = PlacesUIUtils.GENERIC_VIEW_DROP_TYPES;
for (var i = 0; i < types.length; ++i) { for (var i = 0; i < types.length; ++i) {
if (session.isDataFlavorSupported(types[i])) if (session.isDataFlavorSupported(types[i]))
return true; return true;
@ -1263,7 +1264,7 @@ var PlacesControllerDragHelper = {
_initTransferable: function PCDH__initTransferable(session) { _initTransferable: function PCDH__initTransferable(session) {
var xferable = Cc["@mozilla.org/widget/transferable;1"]. var xferable = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable); createInstance(Ci.nsITransferable);
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES; var types = PlacesUIUtils.GENERIC_VIEW_DROP_TYPES;
for (var i = 0; i < types.length; ++i) { for (var i = 0; i < types.length; ++i) {
if (session.isDataFlavorSupported(types[i])) if (session.isDataFlavorSupported(types[i]))
xferable.addDataFlavor(types[i]); xferable.addDataFlavor(types[i]);
@ -1306,13 +1307,13 @@ var PlacesControllerDragHelper = {
movedCount++; movedCount++;
} }
transactions.push(PlacesUtils.makeTransaction(unwrapped, transactions.push(PlacesUIUtils.makeTransaction(unwrapped,
flavor.value, insertionPoint.itemId, flavor.value, insertionPoint.itemId,
index, copy)); index, copy));
} }
var txn = PlacesUtils.ptm.aggregateTransactions("DropItems", transactions); var txn = PlacesUIUtils.ptm.aggregateTransactions("DropItems", transactions);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
}; };

Просмотреть файл

@ -145,7 +145,7 @@ var gEditItemOverlay = {
// description field // description field
this._initTextField("descriptionField", this._initTextField("descriptionField",
PlacesUtils.getItemDescription(this._itemId)); PlacesUIUtils.getItemDescription(this._itemId));
this._showHideRows(); this._showHideRows();
@ -324,8 +324,8 @@ var gEditItemOverlay = {
try { try {
if (this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK && if (this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK &&
!this._readOnly) !this._readOnly)
this._microsummaries = PlacesUtils.microsummaries this._microsummaries = PlacesUIUtils.microsummaries
.getMicrosummaries(this._uri, -1); .getMicrosummaries(this._uri, -1);
} }
catch(ex) { catch(ex) {
// getMicrosummaries will throw an exception in at least two cases: // getMicrosummaries will throw an exception in at least two cases:
@ -346,8 +346,8 @@ var gEditItemOverlay = {
var microsummary = enumerator.getNext() var microsummary = enumerator.getNext()
.QueryInterface(Ci.nsIMicrosummary); .QueryInterface(Ci.nsIMicrosummary);
var menuItem = this._createMicrosummaryMenuItem(microsummary); var menuItem = this._createMicrosummaryMenuItem(microsummary);
if (PlacesUtils.microsummaries if (PlacesUIUtils.microsummaries
.isMicrosummary(this._itemId, microsummary)) .isMicrosummary(this._itemId, microsummary))
itemToSelect = menuItem; itemToSelect = menuItem;
menupopup.appendChild(menuItem); menupopup.appendChild(menuItem);
@ -449,12 +449,12 @@ var gEditItemOverlay = {
} }
if (tagsToAdd.length > 0) { if (tagsToAdd.length > 0) {
var tagTxn = PlacesUtils.ptm.tagURI(this._uri, tagsToAdd); var tagTxn = PlacesUIUtils.ptm.tagURI(this._uri, tagsToAdd);
PlacesUtils.ptm.doTransaction(tagTxn); PlacesUIUtils.ptm.doTransaction(tagTxn);
} }
if (tagsToRemove.length > 0) { if (tagsToRemove.length > 0) {
var untagTxn = PlacesUtils.ptm.untagURI(this._uri, tagsToRemove); var untagTxn = PlacesUIUtils.ptm.untagURI(this._uri, tagsToRemove);
PlacesUtils.ptm.doTransaction(untagTxn); PlacesUIUtils.ptm.doTransaction(untagTxn);
} }
} }
}, },
@ -470,12 +470,12 @@ var gEditItemOverlay = {
var namePicker = this._element("namePicker") var namePicker = this._element("namePicker")
var txns = []; var txns = [];
const ptm = PlacesUtils.ptm; const ptm = PlacesUIUtils.ptm;
// Here we update either the item title or its cached static title // Here we update either the item title or its cached static title
var newTitle = this._element("userEnteredName").label; var newTitle = this._element("userEnteredName").label;
if (this._getItemStaticTitle() != newTitle) { if (this._getItemStaticTitle() != newTitle) {
if (PlacesUtils.microsummaries.hasMicrosummary(this._itemId)) { if (PlacesUIUtils.microsummaries.hasMicrosummary(this._itemId)) {
// Note: this implicitly also takes care of the microsummary->static // Note: this implicitly also takes care of the microsummary->static
// title case, the removeMicorosummary method in the service will set // title case, the removeMicorosummary method in the service will set
// the item-title to the value of this annotation. // the item-title to the value of this annotation.
@ -496,10 +496,10 @@ var gEditItemOverlay = {
// bookmark previously had one, or the user selected a microsummary which // bookmark previously had one, or the user selected a microsummary which
// is not the one the bookmark previously had // is not the one the bookmark previously had
if ((newMicrosummary == null && if ((newMicrosummary == null &&
PlacesUtils.microsummaries.hasMicrosummary(this._itemId)) || PlacesUIUtils.microsummaries.hasMicrosummary(this._itemId)) ||
(newMicrosummary != null && (newMicrosummary != null &&
!PlacesUtils.microsummaries !PlacesUIUtils.microsummaries
.isMicrosummary(this._itemId, newMicrosummary))) { .isMicrosummary(this._itemId, newMicrosummary))) {
txns.push(ptm.editBookmarkMicrosummary(this._itemId, newMicrosummary)); txns.push(ptm.editBookmarkMicrosummary(this._itemId, newMicrosummary));
} }
@ -510,67 +510,67 @@ var gEditItemOverlay = {
onDescriptionFieldBlur: function EIO_onDescriptionFieldInput() { onDescriptionFieldBlur: function EIO_onDescriptionFieldInput() {
var description = this._element("descriptionField").value; var description = this._element("descriptionField").value;
if (description != PlacesUtils.getItemDescription(this._itemId)) { if (description != PlacesUtils.getItemDescription(this._itemId)) {
var txn = PlacesUtils.ptm var txn = PlacesUIUtils.ptm
.editItemDescription(this._itemId, description); .editItemDescription(this._itemId, description);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
}, },
onLocationFieldBlur: function EIO_onLocationFieldBlur() { onLocationFieldBlur: function EIO_onLocationFieldBlur() {
var uri; var uri;
try { try {
uri = PlacesUtils.createFixedURI(this._element("locationField").value); uri = PlacesUIUtils.createFixedURI(this._element("locationField").value);
} }
catch(ex) { return; } catch(ex) { return; }
if (!this._uri.equals(uri)) { if (!this._uri.equals(uri)) {
var txn = PlacesUtils.ptm.editBookmarkURI(this._itemId, uri); var txn = PlacesUIUtils.ptm.editBookmarkURI(this._itemId, uri);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
}, },
onKeywordFieldBlur: function EIO_onKeywordFieldBlur() { onKeywordFieldBlur: function EIO_onKeywordFieldBlur() {
var keyword = this._element("keywordField").value; var keyword = this._element("keywordField").value;
if (keyword != PlacesUtils.bookmarks.getKeywordForBookmark(this._itemId)) { if (keyword != PlacesUtils.bookmarks.getKeywordForBookmark(this._itemId)) {
var txn = PlacesUtils.ptm.editBookmarkKeyword(this._itemId, keyword); var txn = PlacesUIUtils.ptm.editBookmarkKeyword(this._itemId, keyword);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
}, },
onFeedLocationFieldBlur: function EIO_onFeedLocationFieldBlur() { onFeedLocationFieldBlur: function EIO_onFeedLocationFieldBlur() {
var uri; var uri;
try { try {
uri = PlacesUtils.createFixedURI(this._element("feedLocationField").value); uri = PlacesUIUtils.createFixedURI(this._element("feedLocationField").value);
} }
catch(ex) { return; } catch(ex) { return; }
var currentFeedURI = PlacesUtils.livemarks.getFeedURI(this._itemId); var currentFeedURI = PlacesUtils.livemarks.getFeedURI(this._itemId);
if (!currentFeedURI.equals(uri)) { if (!currentFeedURI.equals(uri)) {
var txn = PlacesUtils.ptm.editLivemarkFeedURI(this._itemId, uri); var txn = PlacesUIUtils.ptm.editLivemarkFeedURI(this._itemId, uri);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
}, },
onSiteLocationFieldBlur: function EIO_onSiteLocationFieldBlur() { onSiteLocationFieldBlur: function EIO_onSiteLocationFieldBlur() {
var uri = null; var uri = null;
try { try {
uri = PlacesUtils.createFixedURI(this._element("siteLocationField").value); uri = PlacesUIUtils.createFixedURI(this._element("siteLocationField").value);
} }
catch(ex) { } catch(ex) { }
var currentSiteURI = PlacesUtils.livemarks.getSiteURI(this._itemId); var currentSiteURI = PlacesUtils.livemarks.getSiteURI(this._itemId);
if (!uri || !currentSiteURI.equals(uri)) { if (!uri || !currentSiteURI.equals(uri)) {
var txn = PlacesUtils.ptm.editLivemarkSiteURI(this._itemId, uri); var txn = PlacesUIUtils.ptm.editLivemarkSiteURI(this._itemId, uri);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
}, },
onLoadInSidebarCheckboxCommand: onLoadInSidebarCheckboxCommand:
function EIO_onLoadInSidebarCheckboxCommand() { function EIO_onLoadInSidebarCheckboxCommand() {
var loadInSidebarChecked = this._element("loadInSidebarCheckbox").checked; var loadInSidebarChecked = this._element("loadInSidebarCheckbox").checked;
var txn = PlacesUtils.ptm.setLoadInSidebar(this._itemId, var txn = PlacesUIUtils.ptm.setLoadInSidebar(this._itemId,
loadInSidebarChecked); loadInSidebarChecked);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
}, },
toggleFolderTreeVisibility: function EIO_toggleFolderTreeVisibility() { toggleFolderTreeVisibility: function EIO_toggleFolderTreeVisibility() {
@ -591,7 +591,7 @@ var gEditItemOverlay = {
if (!this._folderTree.place) { if (!this._folderTree.place) {
const FOLDER_TREE_PLACE_URI = const FOLDER_TREE_PLACE_URI =
"place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" + "place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" +
window.top.PlacesUtils.allBookmarksFolderId; window.top.PlacesUIUtils.allBookmarksFolderId;
this._folderTree.place = FOLDER_TREE_PLACE_URI; this._folderTree.place = FOLDER_TREE_PLACE_URI;
} }
@ -651,8 +651,8 @@ var gEditItemOverlay = {
// Move the item // Move the item
var container = this._getFolderIdFromMenuList(); var container = this._getFolderIdFromMenuList();
if (PlacesUtils.bookmarks.getFolderIdForItem(this._itemId) != container) { if (PlacesUtils.bookmarks.getFolderIdForItem(this._itemId) != container) {
var txn = PlacesUtils.ptm.moveItem(this._itemId, container, -1); var txn = PlacesUIUtils.ptm.moveItem(this._itemId, container, -1);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
// Mark the containing folder as recently-used if it isn't in the // Mark the containing folder as recently-used if it isn't in the
// static list // static list

Просмотреть файл

@ -104,7 +104,7 @@ function historyAddBookmarks()
// or if the selected item is not a URI node // or if the selected item is not a URI node
var node = gHistoryTree.selectedNode; var node = gHistoryTree.selectedNode;
if (node && PlacesUtils.nodeIsURI(node)) if (node && PlacesUtils.nodeIsURI(node))
PlacesUtils.showMinimalAddBookmarkUI(PlacesUtils._uri(node.uri), node.title); PlacesUIUtils.showMinimalAddBookmarkUI(PlacesUtils._uri(node.uri), node.title);
} }
function searchHistory(aInput) function searchHistory(aInput)

Просмотреть файл

@ -215,7 +215,7 @@
<method name="getSupportedFlavours"> <method name="getSupportedFlavours">
<body><![CDATA[ <body><![CDATA[
var flavourSet = new FlavourSet(); var flavourSet = new FlavourSet();
var acceptedDropFlavours = PlacesUtils.GENERIC_VIEW_DROP_TYPES; var acceptedDropFlavours = PlacesUIUtils.GENERIC_VIEW_DROP_TYPES;
acceptedDropFlavours.forEach(flavourSet.appendFlavour, flavourSet); acceptedDropFlavours.forEach(flavourSet.appendFlavour, flavourSet);
return flavourSet; return flavourSet;
]]></body> ]]></body>
@ -601,7 +601,7 @@
<parameter name="aBefore"/> <parameter name="aBefore"/>
<body><![CDATA[ <body><![CDATA[
var element = var element =
PlacesUtils.createMenuItemForNode(aChild, this._containerNodesMap); PlacesUIUtils.createMenuItemForNode(aChild, this._containerNodesMap);
if (aBefore) if (aBefore)
aParentPopup.insertBefore(element, aBefore); aParentPopup.insertBefore(element, aBefore);
@ -626,7 +626,7 @@
return; return;
} }
var label = PlacesUtils.getString("bookmarksMenuEmptyFolder"); var label = PlacesUIUtils.getString("bookmarksMenuEmptyFolder");
aPopup._emptyMenuItem = document.createElement("menuitem"); aPopup._emptyMenuItem = document.createElement("menuitem");
aPopup._emptyMenuItem.setAttribute("label", label); aPopup._emptyMenuItem.setAttribute("label", label);
aPopup._emptyMenuItem.setAttribute("disabled", true); aPopup._emptyMenuItem.setAttribute("disabled", true);

Просмотреть файл

@ -52,7 +52,7 @@ var gMoveBookmarksDialog = {
this.foldersTree.place = this.foldersTree.place =
"place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" + "place:excludeItems=1&excludeQueries=1&excludeReadOnlyFolders=1&folder=" +
PlacesUtils.allBookmarksFolderId; PlacesUIUtils.allBookmarksFolderId;
}, },
onOK: function MBD_onOK(aEvent) { onOK: function MBD_onOK(aEvent) {
@ -68,12 +68,12 @@ var gMoveBookmarksDialog = {
continue; continue;
transactions.push(new transactions.push(new
PlacesUtils.ptm.moveItem(this._nodes[i].itemId, selectedFolderID, -1)); PlacesUIUtils.ptm.moveItem(this._nodes[i].itemId, selectedFolderID, -1));
} }
if (transactions.length != 0) { if (transactions.length != 0) {
var txn = PlacesUtils.ptm.aggregateTransactions("Move Items", transactions); var txn = PlacesUIUtils.ptm.aggregateTransactions("Move Items", transactions);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
} }
}, },

Просмотреть файл

@ -43,12 +43,12 @@ var PlacesOrganizer = {
_content: null, _content: null,
_initFolderTree: function() { _initFolderTree: function() {
var leftPaneRoot = PlacesUtils.leftPaneFolderId; var leftPaneRoot = PlacesUIUtils.leftPaneFolderId;
this._places.place = "place:excludeItems=1&expandQueries=0&folder=" + leftPaneRoot; this._places.place = "place:excludeItems=1&expandQueries=0&folder=" + leftPaneRoot;
}, },
selectLeftPaneQuery: function PO_selectLeftPaneQuery(aQueryName) { selectLeftPaneQuery: function PO_selectLeftPaneQuery(aQueryName) {
var itemId = PlacesUtils.leftPaneQueries[aQueryName]; var itemId = PlacesUIUtils.leftPaneQueries[aQueryName];
this._places.selectItems([itemId]); this._places.selectItems([itemId]);
// Forcefully expand all-bookmarks // Forcefully expand all-bookmarks
if (aQueryName == "AllBookmarks") if (aQueryName == "AllBookmarks")
@ -218,7 +218,7 @@ var PlacesOrganizer = {
// the search box in the toolbar if the active collection is the current // the search box in the toolbar if the active collection is the current
// collection. // collection.
var findCommand = document.getElementById("OrganizerCommand_find:current"); var findCommand = document.getElementById("OrganizerCommand_find:current");
var findLabel = PlacesUtils.getFormattedString("findInPrefix", [node.title]); var findLabel = PlacesUIUtils.getFormattedString("findInPrefix", [node.title]);
findCommand.setAttribute("label", findLabel); findCommand.setAttribute("label", findLabel);
if (PlacesSearchBox.filterCollection == "collection") if (PlacesSearchBox.filterCollection == "collection")
PlacesSearchBox.updateCollectionTitle(node.title); PlacesSearchBox.updateCollectionTitle(node.title);
@ -239,7 +239,7 @@ var PlacesOrganizer = {
var selectedNode = currentView.selectedNode; var selectedNode = currentView.selectedNode;
if (selectedNode && aEvent.button == 1) { if (selectedNode && aEvent.button == 1) {
if (PlacesUtils.nodeIsURI(selectedNode)) if (PlacesUtils.nodeIsURI(selectedNode))
PlacesUtils.openNodeWithEvent(selectedNode, aEvent); PlacesUIUtils.openNodeWithEvent(selectedNode, aEvent);
else if (PlacesUtils.nodeIsContainer(selectedNode)) { else if (PlacesUtils.nodeIsContainer(selectedNode)) {
// The command execution function will take care of seeing the // The command execution function will take care of seeing the
// selection is a folder/container and loading its contents in // selection is a folder/container and loading its contents in
@ -257,7 +257,7 @@ var PlacesOrganizer = {
}, },
openSelectedNode: function PU_openSelectedNode(aEvent) { openSelectedNode: function PU_openSelectedNode(aEvent) {
PlacesUtils.openNodeWithEvent(this._content.selectedNode, aEvent); PlacesUIUtils.openNodeWithEvent(this._content.selectedNode, aEvent);
}, },
/** /**
@ -298,7 +298,7 @@ var PlacesOrganizer = {
importFromFile: function PO_importFromFile() { importFromFile: function PO_importFromFile() {
var fp = Cc["@mozilla.org/filepicker;1"]. var fp = Cc["@mozilla.org/filepicker;1"].
createInstance(Ci.nsIFilePicker); createInstance(Ci.nsIFilePicker);
fp.init(window, PlacesUtils.getString("SelectImport"), fp.init(window, PlacesUIUtils.getString("SelectImport"),
Ci.nsIFilePicker.modeOpen); Ci.nsIFilePicker.modeOpen);
fp.appendFilters(Ci.nsIFilePicker.filterHTML | Ci.nsIFilePicker.filterAll); fp.appendFilters(Ci.nsIFilePicker.filterHTML | Ci.nsIFilePicker.filterAll);
if (fp.show() != Ci.nsIFilePicker.returnCancel) { if (fp.show() != Ci.nsIFilePicker.returnCancel) {
@ -317,7 +317,7 @@ var PlacesOrganizer = {
exportBookmarks: function PO_exportBookmarks() { exportBookmarks: function PO_exportBookmarks() {
var fp = Cc["@mozilla.org/filepicker;1"]. var fp = Cc["@mozilla.org/filepicker;1"].
createInstance(Ci.nsIFilePicker); createInstance(Ci.nsIFilePicker);
fp.init(window, PlacesUtils.getString("EnterExport"), fp.init(window, PlacesUIUtils.getString("EnterExport"),
Ci.nsIFilePicker.modeSave); Ci.nsIFilePicker.modeSave);
fp.appendFilters(Ci.nsIFilePicker.filterHTML); fp.appendFilters(Ci.nsIFilePicker.filterHTML);
fp.defaultString = "bookmarks.html"; fp.defaultString = "bookmarks.html";
@ -352,13 +352,13 @@ var PlacesOrganizer = {
var files = bookmarksBackupDir.directoryEntries; var files = bookmarksBackupDir.directoryEntries;
while (files.hasMoreElements()) { while (files.hasMoreElements()) {
var f = files.getNext().QueryInterface(Ci.nsIFile); var f = files.getNext().QueryInterface(Ci.nsIFile);
if (!f.isHidden() && f.leafName.match(/\.html?$/)) if (!f.isHidden() && f.leafName.match(/^bookmarks-.+(html|json)?$/))
fileList.push(f); fileList.push(f);
} }
fileList.sort(function PO_fileList_compare(a, b) { fileList.sort(function PO_fileList_compare(a, b) {
return b.lastModifiedTime - a.lastModifiedTime; return b.lastModifiedTime - a.lastModifiedTime;
}); });
if (fileList.length == 0) if (fileList.length == 0)
return; return;
@ -369,7 +369,7 @@ var PlacesOrganizer = {
(document.createElement("menuitem"), (document.createElement("menuitem"),
document.getElementById("restoreFromFile")); document.getElementById("restoreFromFile"));
var dateStr = fileList[i].leafName.replace("bookmarks-", ""). var dateStr = fileList[i].leafName.replace("bookmarks-", "").
replace(".html", ""); replace(/\.(html|json)$/, "");
if (!dateStr.length) if (!dateStr.length)
dateStr = fileList[i].leafName; dateStr = fileList[i].leafName;
m.setAttribute("label", dateStr); m.setAttribute("label", dateStr);
@ -392,27 +392,58 @@ var PlacesOrganizer = {
bookmarksFile.append(aMenuItem.getAttribute("value")); bookmarksFile.append(aMenuItem.getAttribute("value"));
if (!bookmarksFile.exists()) if (!bookmarksFile.exists())
return; return;
this.restoreBookmarksFromFile(bookmarksFile);
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService);
if (!prompts.confirm(null,
PlacesUtils.getString("bookmarksRestoreAlertTitle"),
PlacesUtils.getString("bookmarksRestoreAlert")))
return;
var ieSvc = Cc["@mozilla.org/browser/places/import-export-service;1"].
getService(Ci.nsIPlacesImportExportService);
ieSvc.importHTMLFromFile(bookmarksFile, true);
}, },
/** /**
* Backup bookmarks to desktop, auto-generate a filename with a date * Called when 'Choose File...' is selected from the restore menu.
* Prompts for a file and restores bookmarks to those in the file.
*/
onRestoreBookmarksFromFile: function PO_onRestoreBookmarksFromFile() {
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
fp.init(window, PlacesUIUtils.getString("bookmarksRestoreTitle"),
Ci.nsIFilePicker.modeOpen);
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var backupsDir = dirSvc.get("Desk", Ci.nsILocalFile);
fp.displayDirectory = backupsDir;
if (fp.show() != Ci.nsIFilePicker.returnCancel)
PlacesUtils.restoreBookmarksFromFile(fp.file);
},
/**
* Restores bookmarks from an HTML or JSON file.
*/
restoreBookmarksFromFile: function PO_restoreBookmarksFromFile(aFile) {
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService);
if (!prompts.confirm(null,
PlacesUIUtils.getString("bookmarksRestoreAlertTitle"),
PlacesUIUtils.getString("bookmarksRestoreAlert")))
return;
if (aFile.leafName.match("\.json$")) {
// restore a JSON backup
PlacesUtils.restoreBookmarksFromJSONFile(aFile);
}
else {
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
getService(Ci.nsIPlacesImportExportService);
importer.importHTMLFromFile(aFile, true /* overwrite existing */);
}
},
/**
* Backup bookmarks to desktop, auto-generate a filename with a date.
* The file is a JSON serialization of bookmarks, tags and any annotations
* of those items.
*/ */
backupBookmarks: function PO_backupBookmarks() { backupBookmarks: function PO_backupBookmarks() {
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
fp.init(window, PlacesUtils.getString("bookmarksBackupTitle"), fp.init(window, PlacesUIUtils.getString("bookmarksBackupTitle"),
Ci.nsIFilePicker.modeSave); Ci.nsIFilePicker.modeSave);
fp.appendFilters(Ci.nsIFilePicker.filterHTML);
var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties); getService(Ci.nsIProperties);
@ -423,41 +454,10 @@ var PlacesOrganizer = {
// and makes the alphabetical order of multiple backup files more useful. // and makes the alphabetical order of multiple backup files more useful.
var date = (new Date).toLocaleFormat("%Y-%m-%d"); var date = (new Date).toLocaleFormat("%Y-%m-%d");
fp.defaultString = PlacesUtils.getFormattedString("bookmarksBackupFilename", fp.defaultString = PlacesUtils.getFormattedString("bookmarksBackupFilename",
[date]); [date]);
if (fp.show() != Ci.nsIFilePicker.returnCancel) { if (fp.show() != Ci.nsIFilePicker.returnCancel)
var ieSvc = Cc["@mozilla.org/browser/places/import-export-service;1"]. PlacesUtils.backupBookmarksToFile(fp.file);
getService(Ci.nsIPlacesImportExportService);
ieSvc.exportHTMLToFile(fp.file);
}
},
/**
* Called when 'Choose File...' is selected from the Revert menupopup
* Prompts for a file and reverts bookmarks to those in the file
*/
restoreFromFile: function PO_restoreFromFile() {
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService);
if (!prompts.confirm(null, PlacesUtils.getString("bookmarksRestoreAlertTitle"),
PlacesUtils.getString("bookmarksRestoreAlert")))
return;
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
fp.init(window, PlacesUtils.getString("bookmarksRestoreTitle"),
Ci.nsIFilePicker.modeOpen);
fp.appendFilters(Ci.nsIFilePicker.filterHTML);
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var backupsDir = dirSvc.get("Desk", Ci.nsILocalFile);
fp.displayDirectory = backupsDir;
if (fp.show() != Ci.nsIFilePicker.returnCancel) {
var ieSvc = Cc["@mozilla.org/browser/places/import-export-service;1"].
getService(Ci.nsIPlacesImportExportService);
ieSvc.importHTMLFromFile(fp.file, true);
}
}, },
_paneDisabled: false, _paneDisabled: false,
@ -548,16 +548,16 @@ var PlacesOrganizer = {
var rowCount = this._content.treeBoxObject.view.rowCount; var rowCount = this._content.treeBoxObject.view.rowCount;
if (rowCount == 0) { if (rowCount == 0) {
selectItemDesc.hidden = true; selectItemDesc.hidden = true;
itemsCountLabel.value = PlacesUtils.getString("detailsPane.noItems"); itemsCountLabel.value = PlacesUIUtils.getString("detailsPane.noItems");
} }
else { else {
selectItemDesc.hidden = false; selectItemDesc.hidden = false;
if (rowCount == 1) if (rowCount == 1)
itemsCountLabel.value = PlacesUtils.getString("detailsPane.oneItem"); itemsCountLabel.value = PlacesUIUtils.getString("detailsPane.oneItem");
else { else {
itemsCountLabel.value = itemsCountLabel.value =
PlacesUtils.getFormattedString("detailsPane.multipleItems", PlacesUIUtils.getFormattedString("detailsPane.multipleItems",
[rowCount]); [rowCount]);
} }
} }
} }
@ -642,9 +642,9 @@ var PlacesOrganizer = {
// Prompt the user for a name for the query. // Prompt the user for a name for the query.
// XXX - using prompt service for now; will need to make // XXX - using prompt service for now; will need to make
// a real dialog and localize when we're sure this is the UI we want. // a real dialog and localize when we're sure this is the UI we want.
var title = PlacesUtils.getString("saveSearch.title"); var title = PlacesUIUtils.getString("saveSearch.title");
var inputLabel = PlacesUtils.getString("saveSearch.inputLabel"); var inputLabel = PlacesUIUtils.getString("saveSearch.inputLabel");
var defaultText = PlacesUtils.getString("saveSearch.defaultText"); var defaultText = PlacesUIUtils.getString("saveSearch.defaultText");
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]. var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService); getService(Ci.nsIPromptService);
@ -657,11 +657,11 @@ var PlacesOrganizer = {
return; return;
// Add the place: uri as a bookmark under the bookmarks root. // Add the place: uri as a bookmark under the bookmarks root.
var txn = PlacesUtils.ptm.createItem(placeURI, var txn = PlacesUIUtils.ptm.createItem(placeURI,
PlacesUtils.bookmarksMenuFolderId, PlacesUtils.bookmarksMenuFolderId,
PlacesUtils.bookmarks.DEFAULT_INDEX, PlacesUtils.bookmarks.DEFAULT_INDEX,
input.value); input.value);
PlacesUtils.ptm.doTransaction(txn); PlacesUIUtils.ptm.doTransaction(txn);
// select and load the new query // select and load the new query
this._places.selectPlaceURI(placeSpec); this._places.selectPlaceURI(placeSpec);
@ -774,8 +774,8 @@ var PlacesSearchBox = {
updateCollectionTitle: function PSB_updateCollectionTitle(title) { updateCollectionTitle: function PSB_updateCollectionTitle(title) {
this.searchFilter.emptyText = this.searchFilter.emptyText =
title ? title ?
PlacesUtils.getFormattedString("searchCurrentDefault", [title]) : PlacesUIUtils.getFormattedString("searchCurrentDefault", [title]) :
PlacesUtils.getString("searchBookmarks"); PlacesUIUtils.getString("searchBookmarks");
}, },
/** /**
@ -1333,7 +1333,7 @@ var PlacesQueryBuilder = {
var selectedFolder = PlacesOrganizer._places.selectedNode.itemId; var selectedFolder = PlacesOrganizer._places.selectedNode.itemId;
// note "all bookmarks" isn't the concrete parent of the top-level // note "all bookmarks" isn't the concrete parent of the top-level
// bookmark folders // bookmark folders
if (selectedFolder != PlacesUtils.allBookmarksFolderId) { if (selectedFolder != PlacesUIUtils.allBookmarksFolderId) {
PlacesSearchBox.filterCollection = "collection"; PlacesSearchBox.filterCollection = "collection";
folders.push(PlacesOrganizer._places.selectedNode.itemId); folders.push(PlacesOrganizer._places.selectedNode.itemId);
break; break;
@ -1445,8 +1445,8 @@ var ViewMenu = {
// see bug #386287 for details // see bug #386287 for details
var columnId = column.getAttribute("anonid"); var columnId = column.getAttribute("anonid");
menuitemPrefix += columnId == "title" ? "name" : columnId; menuitemPrefix += columnId == "title" ? "name" : columnId;
label = PlacesUtils.getString(menuitemPrefix + ".label"); label = PlacesUIUtils.getString(menuitemPrefix + ".label");
var accesskey = PlacesUtils.getString(menuitemPrefix + ".accesskey"); var accesskey = PlacesUIUtils.getString(menuitemPrefix + ".accesskey");
menuitem.setAttribute("accesskey", accesskey); menuitem.setAttribute("accesskey", accesskey);
} }
menuitem.setAttribute("label", label); menuitem.setAttribute("label", label);

Просмотреть файл

@ -107,7 +107,7 @@
<command id="OrganizerCommand_backup" <command id="OrganizerCommand_backup"
oncommand="PlacesOrganizer.backupBookmarks();"/> oncommand="PlacesOrganizer.backupBookmarks();"/>
<command id="OrganizerCommand_restoreFromFile" <command id="OrganizerCommand_restoreFromFile"
oncommand="PlacesOrganizer.restoreFromFile();"/> oncommand="PlacesOrganizer.onRestoreBookmarksFromFile();"/>
<command id="OrganizerCommand_search:save" <command id="OrganizerCommand_search:save"
oncommand="PlacesOrganizer.saveSearch();"/> oncommand="PlacesOrganizer.saveSearch();"/>
<command id="OrganizerCommand_search:moreCriteria" <command id="OrganizerCommand_search:moreCriteria"

Просмотреть файл

@ -94,7 +94,7 @@
</commandset> </commandset>
<popup id="placesContext" <popup id="placesContext"
onpopupshowing="this._view = PlacesUtils.getViewForNode(document.popupNode); onpopupshowing="this._view = PlacesUIUtils.getViewForNode(document.popupNode);
return this._view.buildContextMenu(this);" return this._view.buildContextMenu(this);"
onpopuphiding="this._view.destroyContextMenu();"> onpopuphiding="this._view.destroyContextMenu();">
<menuitem id="placesContext_open" <menuitem id="placesContext_open"
@ -117,7 +117,7 @@
selectiontype="single" selectiontype="single"
selection="link"/> selection="link"/>
<menuitem id="placesContext_openContainer:tabs" <menuitem id="placesContext_openContainer:tabs"
oncommand="var view = PlacesUtils.getViewForNode(document.popupNode); oncommand="var view = PlacesUIUtils.getViewForNode(document.popupNode);
view.controller.openSelectionInTabs(event);" view.controller.openSelectionInTabs(event);"
onclick="checkForMiddleClick(this, event);" onclick="checkForMiddleClick(this, event);"
label="&cmd.open_all_in_tabs.label;" label="&cmd.open_all_in_tabs.label;"
@ -125,7 +125,7 @@
selectiontype="single" selectiontype="single"
selection="folder|host|query"/> selection="folder|host|query"/>
<menuitem id="placesContext_openLinks:tabs" <menuitem id="placesContext_openLinks:tabs"
oncommand="var view = PlacesUtils.getViewForNode(document.popupNode); oncommand="var view = PlacesUIUtils.getViewForNode(document.popupNode);
view.controller.openSelectionInTabs(event);" view.controller.openSelectionInTabs(event);"
onclick="checkForMiddleClick(this, event);" onclick="checkForMiddleClick(this, event);"
label="&cmd.open_all_in_tabs.label;" label="&cmd.open_all_in_tabs.label;"

Просмотреть файл

@ -67,13 +67,13 @@ var SidebarUtils = {
// do this *before* attempting to load the link since openURL uses // do this *before* attempting to load the link since openURL uses
// selection as an indication of which link to load. // selection as an indication of which link to load.
tbo.view.selection.select(row.value); tbo.view.selection.select(row.value);
PlacesUtils.openNodeWithEvent(aTree.selectedNode, aEvent); PlacesUIUtils.openNodeWithEvent(aTree.selectedNode, aEvent);
} }
}, },
handleTreeKeyPress: function SU_handleTreeKeyPress(aEvent) { handleTreeKeyPress: function SU_handleTreeKeyPress(aEvent) {
if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN) if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN)
PlacesUtils.openNodeWithEvent(aEvent.target.selectedNode, aEvent); PlacesUIUtils.openNodeWithEvent(aEvent.target.selectedNode, aEvent);
}, },
/** /**

Просмотреть файл

@ -902,7 +902,7 @@
getSupportedFlavours: function TBV_DO_getSupportedFlavours() { getSupportedFlavours: function TBV_DO_getSupportedFlavours() {
var flavorSet = new FlavourSet(); var flavorSet = new FlavourSet();
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES; var types = PlacesUIUtils.GENERIC_VIEW_DROP_TYPES;
for (var i = 0; i < types.length; ++i) for (var i = 0; i < types.length; ++i)
flavorSet.appendFlavour(types[i]); flavorSet.appendFlavour(types[i]);
return flavorSet; return flavorSet;
@ -961,7 +961,7 @@
return; return;
} }
var label = PlacesUtils.getString("bookmarksMenuEmptyFolder"); var label = PlacesUIUtils.getString("bookmarksMenuEmptyFolder");
aPopup._emptyMenuItem = document.createElement("menuitem"); aPopup._emptyMenuItem = document.createElement("menuitem");
aPopup._emptyMenuItem.setAttribute("label", label); aPopup._emptyMenuItem.setAttribute("label", label);
aPopup._emptyMenuItem.setAttribute("disabled", true); aPopup._emptyMenuItem.setAttribute("disabled", true);
@ -975,7 +975,7 @@
<parameter name="aBefore"/> <parameter name="aBefore"/>
<body><![CDATA[ <body><![CDATA[
var element = var element =
PlacesUtils.createMenuItemForNode(aChild, this._containerNodesMap); PlacesUIUtils.createMenuItemForNode(aChild, this._containerNodesMap);
if (aBefore) if (aBefore)
aParentPopup.insertBefore(element, aBefore); aParentPopup.insertBefore(element, aBefore);
else else

Просмотреть файл

@ -711,7 +711,7 @@
<method name="getSupportedFlavours"> <method name="getSupportedFlavours">
<body><![CDATA[ <body><![CDATA[
var flavorSet = new FlavourSet(); var flavorSet = new FlavourSet();
var types = PlacesUtils.GENERIC_VIEW_DROP_TYPES; var types = PlacesUIUtils.GENERIC_VIEW_DROP_TYPES;
for (var i = 0; i < types.length; ++i) for (var i = 0; i < types.length; ++i)
flavorSet.appendFlavour(types[i]); flavorSet.appendFlavour(types[i]);
return flavorSet; return flavorSet;

Просмотреть файл

@ -192,8 +192,8 @@ PlacesTreeView.prototype = {
if (!aContainer.containerOpen) if (!aContainer.containerOpen)
return; // nothing to do return; // nothing to do
const openLiteral = PlacesUtils.RDF.GetResource("http://home.netscape.com/NC-rdf#open"); const openLiteral = PlacesUIUtils.RDF.GetResource("http://home.netscape.com/NC-rdf#open");
const trueLiteral = PlacesUtils.RDF.GetLiteral("true"); const trueLiteral = PlacesUIUtils.RDF.GetLiteral("true");
var cc = aContainer.childCount; var cc = aContainer.childCount;
for (var i=0; i < cc; i++) { for (var i=0; i < cc; i++) {
@ -219,8 +219,8 @@ PlacesTreeView.prototype = {
var resource = this._getResourceForNode(curChild); var resource = this._getResourceForNode(curChild);
var isopen = resource != null && var isopen = resource != null &&
PlacesUtils.localStore.HasAssertion(resource, openLiteral, PlacesUIUtils.localStore.HasAssertion(resource, openLiteral,
trueLiteral, true); trueLiteral, true);
if (isopen != curChild.containerOpen) if (isopen != curChild.containerOpen)
aToOpen.push(curChild); aToOpen.push(curChild);
else if (curChild.containerOpen && curChild.childCount > 0) else if (curChild.containerOpen && curChild.childCount > 0)
@ -832,7 +832,7 @@ PlacesTreeView.prototype = {
{ {
var uri = aNode.uri; var uri = aNode.uri;
NS_ASSERT(uri, "if there is no uri, we can't persist the open state"); NS_ASSERT(uri, "if there is no uri, we can't persist the open state");
return uri ? PlacesUtils.RDF.GetResource(uri) : null; return uri ? PlacesUIUtils.RDF.GetResource(uri) : null;
}, },
// nsITreeView // nsITreeView
@ -1129,7 +1129,7 @@ PlacesTreeView.prototype = {
// if they go through the "result" API. // if they go through the "result" API.
if (PlacesUtils.nodeIsSeparator(node)) if (PlacesUtils.nodeIsSeparator(node))
return ""; return "";
return node.title || PlacesUtils.getString("noTitle"); return node.title || PlacesUIUtils.getString("noTitle");
case this.COLUMN_TYPE_TAGS: case this.COLUMN_TYPE_TAGS:
return node.tags; return node.tags;
case this.COLUMN_TYPE_URI: case this.COLUMN_TYPE_URI:
@ -1203,13 +1203,13 @@ PlacesTreeView.prototype = {
var resource = this._getResourceForNode(node); var resource = this._getResourceForNode(node);
if (resource) { if (resource) {
const openLiteral = PlacesUtils.RDF.GetResource("http://home.netscape.com/NC-rdf#open"); const openLiteral = PlacesUIUtils.RDF.GetResource("http://home.netscape.com/NC-rdf#open");
const trueLiteral = PlacesUtils.RDF.GetLiteral("true"); const trueLiteral = PlacesUIUtils.RDF.GetLiteral("true");
if (node.containerOpen) if (node.containerOpen)
PlacesUtils.localStore.Unassert(resource, openLiteral, trueLiteral); PlacesUIUtils.localStore.Unassert(resource, openLiteral, trueLiteral);
else else
PlacesUtils.localStore.Assert(resource, openLiteral, trueLiteral, true); PlacesUIUtils.localStore.Assert(resource, openLiteral, trueLiteral, true);
} }
node.containerOpen = !node.containerOpen; node.containerOpen = !node.containerOpen;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -67,6 +67,8 @@ CPPSRCS = nsPlacesImportExportService.cpp
EXTRA_COMPONENTS = nsPlacesTransactionsService.js EXTRA_COMPONENTS = nsPlacesTransactionsService.js
EXTRA_PP_COMPONENTS = nsPlacesTransactionsService.js
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
XPIDL_FLAGS += -I$(topsrcdir)/browser/components XPIDL_FLAGS += -I$(topsrcdir)/browser/components

Просмотреть файл

@ -381,10 +381,10 @@ protected:
// importing bookmarks.html files. // importing bookmarks.html files.
PRBool mAllowRootChanges; PRBool mAllowRootChanges;
// if set, this is an import of initial bookmarks.html content, // If set, this is an import of initial bookmarks.html content,
// so we don't want to kick off HTTP traffic // so we don't want to kick off HTTP traffic
// and we want the imported personal toolbar folder // and we want the imported personal toolbar folder
// to be set as the personal toolbar folder. (if not set // to be set as the personal toolbar folder. (If not set
// we will treat it as a normal folder.) // we will treat it as a normal folder.)
PRBool mIsImportDefaults; PRBool mIsImportDefaults;
@ -2440,9 +2440,7 @@ nsPlacesImportExportService::ExportHTMLToFile(nsILocalFile* aBookmarksFile)
return rv; return rv;
} }
#define BROWSER_BOOKMARKS_OVERWRITE_PREF "browser.bookmarks.overwrite"
#define BROWSER_BOOKMARKS_MAX_BACKUPS_PREF "browser.bookmarks.max_backups" #define BROWSER_BOOKMARKS_MAX_BACKUPS_PREF "browser.bookmarks.max_backups"
#define POSTPLACES_BOOKMARKS_FILE "bookmarks.postplaces.html"
NS_IMETHODIMP NS_IMETHODIMP
nsPlacesImportExportService::BackupBookmarksFile() nsPlacesImportExportService::BackupBookmarksFile()
@ -2458,15 +2456,6 @@ nsPlacesImportExportService::BackupBookmarksFile()
rv = NS_GetSpecialDirectory(NS_APP_BOOKMARKS_50_FILE, rv = NS_GetSpecialDirectory(NS_APP_BOOKMARKS_50_FILE,
getter_AddRefs(bookmarksFileDir)); getter_AddRefs(bookmarksFileDir));
PRBool overwriteBookmarks;
rv = prefs->GetBoolPref(BROWSER_BOOKMARKS_OVERWRITE_PREF, &overwriteBookmarks);
NS_ENSURE_SUCCESS(rv, rv);
if (!overwriteBookmarks) {
rv = bookmarksFileDir->SetLeafName(NS_LITERAL_STRING(POSTPLACES_BOOKMARKS_FILE));
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILocalFile> bookmarksFile(do_QueryInterface(bookmarksFileDir)); nsCOMPtr<nsILocalFile> bookmarksFile(do_QueryInterface(bookmarksFileDir));
@ -2483,17 +2472,6 @@ nsPlacesImportExportService::BackupBookmarksFile()
rv = ExportHTMLToFile(bookmarksFile); rv = ExportHTMLToFile(bookmarksFile);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// archive if needed
PRInt32 numberOfBackups;
rv = prefs->GetIntPref(BROWSER_BOOKMARKS_MAX_BACKUPS_PREF, &numberOfBackups);
if (NS_FAILED(rv))
numberOfBackups = 5;
if (numberOfBackups > 0) {
rv = ArchiveBookmarksFile(numberOfBackups, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK; return NS_OK;
} }
@ -2509,7 +2487,7 @@ nsPlacesImportExportService::BackupBookmarksFile()
*/ */
nsresult nsresult
nsPlacesImportExportService::ArchiveBookmarksFile(PRInt32 numberOfBackups, nsPlacesImportExportService::ArchiveBookmarksFile(PRInt32 numberOfBackups,
PRBool forceArchive) PRBool forceArchive)
{ {
nsCOMPtr<nsIFile> bookmarksBackupDir; nsCOMPtr<nsIFile> bookmarksBackupDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
@ -2530,7 +2508,7 @@ nsPlacesImportExportService::ArchiveBookmarksFile(PRInt32 numberOfBackups,
} }
// construct the new leafname // construct the new leafname
PRTime now64 = PR_Now(); PRTime now64 = PR_Now();
PRExplodedTime nowInfo; PRExplodedTime nowInfo;
PR_ExplodeTime(now64, PR_LocalTimeParameters, &nowInfo); PR_ExplodeTime(now64, PR_LocalTimeParameters, &nowInfo);
PR_NormalizeTime(&nowInfo, PR_LocalTimeParameters); PR_NormalizeTime(&nowInfo, PR_LocalTimeParameters);
@ -2541,8 +2519,6 @@ nsPlacesImportExportService::ArchiveBookmarksFile(PRInt32 numberOfBackups,
// and makes the alphabetical order of multiple backup files more useful. // and makes the alphabetical order of multiple backup files more useful.
PR_FormatTime(timeString, 128, "bookmarks-%Y-%m-%d.html", &nowInfo); PR_FormatTime(timeString, 128, "bookmarks-%Y-%m-%d.html", &nowInfo);
//nsCAutoString backupFilenameCString(timeString);
//nsAutoString backupFilenameString = NS_ConvertUTF8toUTF16(backupFilenameCString);
nsAutoString backupFilenameString = NS_ConvertUTF8toUTF16((timeString)); nsAutoString backupFilenameString = NS_ConvertUTF8toUTF16((timeString));
nsCOMPtr<nsIFile> backupFile; nsCOMPtr<nsIFile> backupFile;
@ -2609,18 +2585,6 @@ nsPlacesImportExportService::ArchiveBookmarksFile(PRInt32 numberOfBackups,
getter_AddRefs(bookmarksFile)); getter_AddRefs(bookmarksFile));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
PRBool overwriteBookmarks;
rv = prefs->GetBoolPref(BROWSER_BOOKMARKS_OVERWRITE_PREF, &overwriteBookmarks);
NS_ENSURE_SUCCESS(rv, rv);
if (!overwriteBookmarks) {
rv = bookmarksFile->SetLeafName(NS_LITERAL_STRING(POSTPLACES_BOOKMARKS_FILE));
NS_ENSURE_SUCCESS(rv, rv);
}
rv = bookmarksFile->CopyTo(bookmarksBackupDir, backupFilenameString); rv = bookmarksFile->CopyTo(bookmarksBackupDir, backupFilenameString);
// at least dump something out in case this fails in a debug build // at least dump something out in case this fails in a debug build
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -37,16 +37,15 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
let Ci = Components.interfaces;
let Cc = Components.classes;
let Cr = Components.results;
const loadInSidebarAnno = "bookmarkProperties/loadInSidebar"; const loadInSidebarAnno = "bookmarkProperties/loadInSidebar";
const descriptionAnno = "bookmarkProperties/description"; const descriptionAnno = "bookmarkProperties/description";
const CLASS_ID = Components.ID("c0844a84-5a12-4808-80a8-809cb002bb4f"); const CLASS_ID = Components.ID("c0844a84-5a12-4808-80a8-809cb002bb4f");
const CONTRACT_ID = "@mozilla.org/browser/placesTransactionsService;1"; const CONTRACT_ID = "@mozilla.org/browser/placesTransactionsService;1";
var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].
getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://global/content/debug.js");
loader.loadSubScript("chrome://browser/content/places/utils.js");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
// The minimum amount of transactions we should tell our observers to begin // The minimum amount of transactions we should tell our observers to begin
@ -56,6 +55,7 @@ const MIN_TRANSACTIONS_FOR_BATCH = 5;
function placesTransactionsService() { function placesTransactionsService() {
this.mTransactionManager = Cc["@mozilla.org/transactionmanager;1"]. this.mTransactionManager = Cc["@mozilla.org/transactionmanager;1"].
createInstance(Ci.nsITransactionManager); createInstance(Ci.nsITransactionManager);
Components.utils.import("resource://gre/modules/utils.js");
} }
placesTransactionsService.prototype = { placesTransactionsService.prototype = {
@ -442,6 +442,7 @@ placesCreateLivemarkTransactions.prototype = {
}; };
function placesMoveItemTransactions(aItemId, aNewContainer, aNewIndex) { function placesMoveItemTransactions(aItemId, aNewContainer, aNewIndex) {
Components.utils.import("resource://gre/modules/debug.js");
NS_ASSERT(aNewIndex >= -1, "invalid insertion index"); NS_ASSERT(aNewIndex >= -1, "invalid insertion index");
this._id = aItemId; this._id = aItemId;
this._oldContainer = PlacesUtils.bookmarks.getFolderIdForItem(this._id); this._oldContainer = PlacesUtils.bookmarks.getFolderIdForItem(this._id);

Просмотреть файл

@ -37,6 +37,8 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
version(170);
const NS_APP_USER_PROFILE_50_DIR = "ProfD"; const NS_APP_USER_PROFILE_50_DIR = "ProfD";
var Ci = Components.interfaces; var Ci = Components.interfaces;
var Cc = Components.classes; var Cc = Components.classes;

Просмотреть файл

@ -36,7 +36,286 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
const DESCRIPTION_ANNO = "bookmarkProperties/description";
const POST_DATA_ANNO = "bookmarkProperties/POSTData";
const LAST_CHARSET_ANNO = "URIProperties/characterSet";
Components.utils.import("resource://gre/modules/utils.js");
do_check_eq(typeof PlacesUtils, "object");
// main
function run_test() { function run_test() {
// XXX test disabled due to backout of bug 384370 /*
return; HTML+FEATURES SUMMARY:
- import legacy bookmarks
- export as json, import, test (tests integrity of html > json)
- export as html, import, test (tests integrity of json > html)
BACKUP/RESTORE SUMMARY:
- create a bookmark in each root
- tag multiple URIs with multiple tags
- export as json, import, 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.createdSmartBookmarks", true);
// file pointer to legacy bookmarks file
//var bookmarksFileOld = do_get_file("browser/components/places/tests/unit/bookmarks.large.html");
var bookmarksFileOld = do_get_file("browser/components/places/tests/unit/bookmarks.preplaces.html");
// file pointer to a new places-exported json file
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
jsonFile.append("bookmarks.exported.json");
// create bookmarks.exported.json
if (jsonFile.exists())
jsonFile.remove(false);
jsonFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600);
if (!jsonFile.exists())
do_throw("couldn't create file: bookmarks.exported.json");
// Test importing a pre-Places canonical bookmarks file.
// 1. import bookmarks.preplaces.html
// 2. run the test-suite
// Note: we do not empty the db before this import to catch bugs like 380999
try {
importer.importHTMLFromFile(bookmarksFileOld, true);
} catch(ex) { do_throw("couldn't import legacy bookmarks file: " + ex); }
populate();
validate();
// Test exporting a Places canonical json file.
// 1. export to bookmarks.exported.json
// 2. empty bookmarks db
// 3. import bookmarks.exported.json
// 4. run the test-suite
try {
PlacesUtils.backupBookmarksToFile(jsonFile);
} catch(ex) { do_throw("couldn't export to file: " + ex); }
LOG("exported json");
try {
PlacesUtils.restoreBookmarksFromFile(jsonFile);
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
LOG("imported json");
validate();
LOG("validated import");
}
var tagData = [
{ uri: uri("http://slint.us"), tags: ["indie", "kentucky", "music"] },
{ uri: uri("http://en.wikipedia.org/wiki/Diplodocus"), tags: ["dinosaur", "dj", "rad word"] }
];
var recentTagsQueryURI = uri("place:folder=" + PlacesUtils.bookmarks.tagsFolder +
"&group=" + Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER +
"&applyOptionsToContainers=1" +
"&queryType=" + Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS);
var bookmarkData = [
//{ uri: uri("http://www.saveur.com/"), title: "Saveur Magazine" },
//{ uri: uri("http://twitter.com/"), title: "Twitter" },
{ uri: uri("http://slint.us"), title: "indie, kentucky, music" },
{ uri: uri("http://en.wikipedia.org/wiki/Diplodocus"), title: "dinosaur, dj, rad word" }
//{ uri: recentTagsQueryURI, title: "Recent Tags" }
];
/*
populate data in each folder
(menu is populated via the html import)
*/
function populate() {
// add tags
for each(let {uri: u, tags: t} in tagData)
PlacesUtils.tagging.tagURI(u, t);
// add unfiled bookmarks
for each(let {uri: u, title: t} in bookmarkData) {
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.unfiledBookmarksFolder,
u, PlacesUtils.bookmarks.DEFAULT_INDEX, t);
}
// add to the toolbar
for each(let {uri: u, title: t} in bookmarkData) {
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.toolbarFolder,
u, PlacesUtils.bookmarks.DEFAULT_INDEX, t);
}
}
function validate() {
testCanonicalBookmarks(PlacesUtils.bookmarks.bookmarksMenuFolder);
testToolbarFolder();
testUnfiledBookmarks();
testTags();
}
// Tests a bookmarks datastore that has a set of bookmarks, etc
// that flex each supported field and feature.
function testCanonicalBookmarks() {
// query to see if the deleted folder and items have been imported
var query = PlacesUtils.history.getNewQuery();
query.setFolders([PlacesUtils.bookmarks.bookmarksMenuFolder], 1);
var result = PlacesUtils.history.executeQuery(query, PlacesUtils.history.getNewQueryOptions());
var rootNode = result.root;
rootNode.containerOpen = true;
// 6-2: the toolbar contents are imported to the places-toolbar folder,
// the separator above it is removed.
do_check_eq(rootNode.childCount, 4);
// get test folder
var testFolder = rootNode.getChild(3);
do_check_eq(testFolder.type, testFolder.RESULT_TYPE_FOLDER);
do_check_eq(testFolder.title, "test");
/*
// add date
do_check_eq(PlacesUtils.bookmarks.getItemDateAdded(testFolder.itemId)/1000000, 1177541020);
// last modified
do_check_eq(PlacesUtils.bookmarks.getItemLastModified(testFolder.itemId)/1000000, 1177541050);
*/
testFolder = testFolder.QueryInterface(Ci.nsINavHistoryQueryResultNode);
do_check_eq(testFolder.hasChildren, true);
// folder description
do_check_true(PlacesUtils.annotations.itemHasAnnotation(testFolder.itemId,
DESCRIPTION_ANNO));
do_check_eq("folder test comment",
PlacesUtils.annotations.getItemAnnotation(testFolder.itemId, DESCRIPTION_ANNO));
// open test folder, and test the children
testFolder.containerOpen = true;
var cc = testFolder.childCount;
// XXX Bug 380468
// do_check_eq(cc, 2);
do_check_eq(cc, 1);
// test bookmark 1
var testBookmark1 = testFolder.getChild(0);
// url
do_check_eq("http://test/post", testBookmark1.uri);
// title
do_check_eq("test post keyword", testBookmark1.title);
// keyword
do_check_eq("test", PlacesUtils.bookmarks.getKeywordForBookmark(testBookmark1.itemId));
// sidebar
do_check_true(PlacesUtils.annotations.itemHasAnnotation(testBookmark1.itemId,
LOAD_IN_SIDEBAR_ANNO));
/*
// add date
do_check_eq(testBookmark1.dateAdded/1000000, 1177375336);
// last modified
do_check_eq(testBookmark1.lastModified/1000000, 1177375423);
*/
// post data
do_check_true(PlacesUtils.annotations.itemHasAnnotation(testBookmark1.itemId, POST_DATA_ANNO));
do_check_eq("hidden1%3Dbar&text1%3D%25s",
PlacesUtils.annotations.getItemAnnotation(testBookmark1.itemId, POST_DATA_ANNO));
// last charset
do_check_true(PlacesUtils.annotations.itemHasAnnotation(testBookmark1.itemId, LAST_CHARSET_ANNO));
do_check_eq("ISO-8859-1", PlacesUtils.annotations.getItemAnnotation(testBookmark1.itemId,
LAST_CHARSET_ANNO));
// description
do_check_true(PlacesUtils.annotations.itemHasAnnotation(testBookmark1.itemId,
DESCRIPTION_ANNO));
do_check_eq("item description",
PlacesUtils.annotations.getItemAnnotation(testBookmark1.itemId,
DESCRIPTION_ANNO));
/*
// XXX Bug 380468
// test bookmark 2
var testBookmark2 = testFolder.getChild(1);
// url
do_check_eq("http://test/micsum", testBookmark2.uri);
// title
do_check_eq("test microsummary", testBookmark2.title);
// check that it's a microsummary
var micsum = mssvc.getMicrosummary(testBookmark2.itemId);
if (!micsum)
do_throw("Could not import microsummary");
// check generator uri
var generator = micsum.generator;
do_check_eq("urn:source:http://dietrich.ganx4.com/mozilla/test-microsummary.xml", generator.uri.spec);
// expiration and generated title can change, so don't test them
*/
// clean up
testFolder.containerOpen = false;
rootNode.containerOpen = false;
}
function testToolbarFolder() {
var query = PlacesUtils.history.getNewQuery();
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
var result = PlacesUtils.history.executeQuery(query, PlacesUtils.history.getNewQueryOptions());
var toolbar = result.root;
toolbar.containerOpen = true;
// child count (add 2 for pre-existing items)
do_check_eq(toolbar.childCount, bookmarkData.length + 2);
// livemark
var livemark = toolbar.getChild(1);
// title
do_check_eq("Latest Headlines", livemark.title);
// livemark check
do_check_true(PlacesUtils.livemarks.isLivemark(livemark.itemId));
// site url
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
PlacesUtils.livemarks.getSiteURI(livemark.itemId).spec);
// feed url
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
PlacesUtils.livemarks.getFeedURI(livemark.itemId).spec);
// test added bookmark data
var child = toolbar.getChild(2);
do_check_eq(child.uri, bookmarkData[0].uri.spec);
do_check_eq(child.title, bookmarkData[0].title);
child = toolbar.getChild(3);
do_check_eq(child.uri, bookmarkData[1].uri.spec);
do_check_eq(child.title, bookmarkData[1].title);
toolbar.containerOpen = false;
}
function testUnfiledBookmarks() {
var query = PlacesUtils.history.getNewQuery();
query.setFolders([PlacesUtils.bookmarks.unfiledBookmarksFolder], 1);
var result = PlacesUtils.history.executeQuery(query, PlacesUtils.history.getNewQueryOptions());
var rootNode = result.root;
rootNode.containerOpen = true;
do_check_eq(rootNode.childCount, bookmarkData.length);
for (var i = 0; i < rootNode.childCount; i++) {
var child = rootNode.getChild(i);
dump(bookmarkData[i].uri.spec + " == " + child.uri + "?\n");
do_check_true(bookmarkData[i].uri.equals(uri(child.uri)));
do_check_eq(child.title, bookmarkData[i].title);
/* WTF
if (child.tags)
do_check_eq(child.tags, bookmarkData[i].title);
*/
}
rootNode.containerOpen = false;
}
function testTags() {
for each(let {uri: u, tags: t} in tagData) {
var i = 0;
dump("test tags for " + u.spec + ": " + t + "\n");
var tt = PlacesUtils.tagging.getTagsForURI(u, {});
dump("true tags for " + u.spec + ": " + tt + "\n");
do_check_true(t.every(function(el) {
i++;
return tt.indexOf(el) > -1;
}));
do_check_eq(i, t.length);
}
} }

Просмотреть файл

@ -36,12 +36,7 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
version(170); Components.utils.import("resource://gre/modules/utils.js");
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://global/content/debug.js");
loader.loadSubScript("chrome://browser/content/places/utils.js");
const bmsvc = PlacesUtils.bookmarks; const bmsvc = PlacesUtils.bookmarks;
const testFolderId = PlacesUtils.bookmarksMenuFolderId; const testFolderId = PlacesUtils.bookmarksMenuFolderId;

Просмотреть файл

@ -78,7 +78,6 @@ try {
do_throw("Could not get io service\n"); do_throw("Could not get io service\n");
} }
const DESCRIPTION_ANNO = "bookmarkProperties/description"; const DESCRIPTION_ANNO = "bookmarkProperties/description";
const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar"; const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
const POST_DATA_ANNO = "bookmarkProperties/POSTData"; const POST_DATA_ANNO = "bookmarkProperties/POSTData";

Просмотреть файл

@ -129,7 +129,7 @@ function (aTitle, aContentURL, aCustomizeURL, aPersist)
} }
catch(ex) { return; } catch(ex) { return; }
win.PlacesUtils.showMinimalAddBookmarkUI(uri, aTitle, null, null, true, true); win.PlacesUIUtils.showMinimalAddBookmarkUI(uri, aTitle, null, null, true, true);
} }
nsSidebar.prototype.validateSearchEngine = nsSidebar.prototype.validateSearchEngine =

Просмотреть файл

@ -105,4 +105,8 @@ EXTRA_PP_COMPONENTS = nsLivemarkService.js \
nsTaggingService.js \ nsTaggingService.js \
$(NULL) $(NULL)
EXTRA_JS_MODULES = utils.js
EXTRA_PP_JS_MODULES = utils.js
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -194,13 +194,14 @@ TaggingService.prototype = {
* the item-id of the tag element under the tags root * the item-id of the tag element under the tags root
*/ */
_removeTagIfEmpty: function TS__removeTagIfEmpty(aTagId) { _removeTagIfEmpty: function TS__removeTagIfEmpty(aTagId) {
var options = this._history.getNewQueryOptions(); var node = this._getTagNode(aTagId).QueryInterface(Ci.nsINavHistoryContainerResultNode);
var query = this._history.getNewQuery(); var wasOpen = node.containerOpen;
query.setFolders([aTagId], 1); if (!wasOpen)
var result = this._history.executeQuery(query, options); node.containerOpen = true;
var rootNode = result.root; var cc = node.childCount;
rootNode.containerOpen = true; if (wasOpen)
if (rootNode.childCount == 0) node.containerOpen = false;
if (cc == 0)
this._bms.removeFolder(aTagId); this._bms.removeFolder(aTagId);
}, },