mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 546942 - Move places import-export-service to toolkit. r=sdwilsh
--HG-- rename : browser/components/places/public/nsIPlacesImportExportService.idl => toolkit/components/places/public/nsIPlacesImportExportService.idl rename : browser/components/places/src/nsPlacesImportExportService.cpp => toolkit/components/places/src/nsPlacesImportExportService.cpp rename : browser/components/places/src/nsPlacesImportExportService.h => toolkit/components/places/src/nsPlacesImportExportService.h
This commit is contained in:
parent
5060537f28
commit
1593a62e17
@ -43,7 +43,6 @@ endif
|
||||
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
../feeds/src/$(LIB_PREFIX)browser_feeds_s.$(LIB_SUFFIX) \
|
||||
../places/src/$(LIB_PREFIX)browserplaces_s.$(LIB_SUFFIX) \
|
||||
../privatebrowsing/src/$(LIB_PREFIX)privatebrowsing_s.$(LIB_SUFFIX) \
|
||||
../about/$(LIB_PREFIX)browserabout_s.$(LIB_SUFFIX) \
|
||||
../dirprovider/$(LIB_PREFIX)browserdir_s.$(LIB_SUFFIX) \
|
||||
|
@ -91,13 +91,6 @@
|
||||
#define NS_ABOUTFEEDS_CID \
|
||||
{ 0x12ff56ec, 0x58be, 0x402c, { 0xb0, 0x57, 0x1, 0xf9, 0x61, 0xde, 0x96, 0x9b } }
|
||||
|
||||
// 6fb0c970-e1b1-11db-8314-0800200c9a66
|
||||
#define NS_PLACESIMPORTEXPORTSERVICE_CID \
|
||||
{ 0x6fb0c970, 0xe1b1, 0x11db, { 0x83, 0x14, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 } }
|
||||
|
||||
#define NS_PLACESIMPORTEXPORTSERVICE_CONTRACTID \
|
||||
"@mozilla.org/browser/places/import-export-service;1"
|
||||
|
||||
// 136e2c4d-c5a4-477c-b131-d93d7d704f64
|
||||
#define NS_PRIVATE_BROWSING_SERVICE_WRAPPER_CID \
|
||||
{ 0x136e2c4d, 0xc5a4, 0x477c, { 0xb1, 0x31, 0xd9, 0x3d, 0x7d, 0x70, 0x4f, 0x64 } }
|
||||
|
@ -40,7 +40,6 @@
|
||||
|
||||
#include "nsBrowserCompsCID.h"
|
||||
#include "DirectoryProvider.h"
|
||||
#include "nsPlacesImportExportService.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include "nsWindowsShellService.h"
|
||||
@ -86,7 +85,6 @@ using namespace mozilla::browser;
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(DirectoryProvider)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPlacesImportExportService)
|
||||
#if defined(XP_WIN)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindowsShellService)
|
||||
#elif defined(XP_MACOSX)
|
||||
@ -148,12 +146,6 @@ static const nsModuleComponentInfo components[] =
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
{ "Places Import/Export Service",
|
||||
NS_PLACESIMPORTEXPORTSERVICE_CID,
|
||||
NS_PLACESIMPORTEXPORTSERVICE_CONTRACTID,
|
||||
nsPlacesImportExportServiceConstructor},
|
||||
|
||||
{ "Feed Sniffer",
|
||||
NS_FEEDSNIFFER_CID,
|
||||
NS_FEEDSNIFFER_CONTRACTID,
|
||||
|
@ -210,6 +210,13 @@ BrowserGlue.prototype = {
|
||||
// Customization has finished, we don't need the customizer anymore.
|
||||
delete this._distributionCustomizer;
|
||||
break;
|
||||
case "bookmarks-restore-success":
|
||||
case "bookmarks-restore-failed":
|
||||
this._observerService.removeObserver(this, "bookmarks-restore-success");
|
||||
this._observerService.removeObserver(this, "bookmarks-restore-failed");
|
||||
if (topic == "bookmarks-restore-success" && data == "html-initial")
|
||||
this.ensurePlacesDefaultQueriesInitialized();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
@ -677,13 +684,16 @@ BrowserGlue.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
// If bookmarks are not imported, then initialize smart bookmarks. This
|
||||
// happens during a common startup.
|
||||
// Otherwise, if any kind of import runs, smart bookmarks creation should be
|
||||
// delayed till the import operations has finished. Not doing so would
|
||||
// cause them to be overwritten by the newly imported bookmarks.
|
||||
if (!importBookmarks) {
|
||||
// Call it here for Fx3 profiles created before the Places folder
|
||||
// has been added, otherwise it's called during import.
|
||||
this.ensurePlacesDefaultQueriesInitialized();
|
||||
}
|
||||
else {
|
||||
// ensurePlacesDefaultQueriesInitialized() is called by import.
|
||||
// An import operation is about to run.
|
||||
// Don't try to recreate smart bookmarks if autoExportHTML is true or
|
||||
// smart bookmarks are disabled.
|
||||
var autoExportHTML = false;
|
||||
@ -711,7 +721,12 @@ BrowserGlue.prototype = {
|
||||
bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
|
||||
|
||||
if (bookmarksFile.exists()) {
|
||||
// import the file
|
||||
// Add an import observer. It will ensure that smart bookmarks are
|
||||
// created once the operation is complete.
|
||||
this._observerService.addObserver(this, "bookmarks-restore-success", false);
|
||||
this._observerService.addObserver(this, "bookmarks-restore-failed", false);
|
||||
|
||||
// Import from bookmarks.html file.
|
||||
try {
|
||||
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
|
||||
getService(Ci.nsIPlacesImportExportService);
|
||||
@ -719,6 +734,8 @@ BrowserGlue.prototype = {
|
||||
} catch (err) {
|
||||
// Report the error, but ignore it.
|
||||
Cu.reportError("Bookmarks.html file could be corrupt. " + err);
|
||||
this._observerService.removeObserver(this, "bookmarks-restore-success");
|
||||
this._observerService.removeObserver(this, "bookmarks-restore-failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -46,8 +46,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||
MODULE = browserplaces
|
||||
XPIDL_MODULE = browserplaces
|
||||
|
||||
XPIDLSRCS = nsIPlacesImportExportService.idl \
|
||||
nsIPlacesTransactionsService.idl \
|
||||
XPIDLSRCS = nsIPlacesTransactionsService.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -44,17 +44,6 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = browserplaces
|
||||
LIBRARY_NAME = browserplaces_s
|
||||
FORCE_STATIC_LIB = 1
|
||||
FORCE_USE_PIC = 1
|
||||
ifndef MOZ_MEMORY
|
||||
USE_STATIC_LIBS = 1
|
||||
endif
|
||||
|
||||
|
||||
CPPSRCS = nsPlacesImportExportService.cpp
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
nsPlacesTransactionsService.js \
|
||||
PlacesProtocolHandler.js \
|
||||
|
@ -41,6 +41,32 @@
|
||||
* database is corrupt and one backup is available.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onBeforeItemRemoved: function(id) {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
@ -74,30 +100,15 @@ function run_test() {
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
|
||||
|
||||
// Wait for restore to finish.
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(observer, "bookmarks-restore-success");
|
||||
os.removeObserver(observer, "bookmarks-restore-failed");
|
||||
do_check_eq(aTopic, "bookmarks-restore-success");
|
||||
do_check_eq(aData, "json");
|
||||
continue_test();
|
||||
}
|
||||
}
|
||||
os.addObserver(observer, "bookmarks-restore-success", false);
|
||||
os.addObserver(observer, "bookmarks-restore-failed", false);
|
||||
// The test will continue once restore has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
// Check that JSON backup has been restored.
|
||||
// Notice restore from JSON notification is fired before smart bookmarks creation.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(bs.getItemTitle(itemId), "examplejson");
|
||||
|
||||
remove_bookmarks_html();
|
||||
|
@ -41,6 +41,32 @@
|
||||
* is corrupt but a JSON backup is not available.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onBeforeItemRemoved: function(id) {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
@ -72,30 +98,14 @@ function run_test() {
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
|
||||
|
||||
// Wait for restore to finish.
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(observer, "bookmarks-restore-success");
|
||||
os.removeObserver(observer, "bookmarks-restore-failed");
|
||||
do_check_eq(aTopic, "bookmarks-restore-success");
|
||||
do_check_eq(aData, "html-initial");
|
||||
continue_test();
|
||||
}
|
||||
}
|
||||
os.addObserver(observer, "bookmarks-restore-success", false);
|
||||
os.addObserver(observer, "bookmarks-restore-failed", false);
|
||||
// The test will continue once import has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
// Check that bookmarks html has been restored.
|
||||
// Notice restore from HTML notification is fired after smart bookmarks creation.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_neq(itemId, -1);
|
||||
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||
|
||||
remove_bookmarks_html();
|
||||
|
@ -41,6 +41,32 @@
|
||||
* corrupt, nor a JSON backup nor bookmarks.html are available.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onBeforeItemRemoved: function(id) {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
@ -72,26 +98,12 @@ function run_test() {
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
|
||||
|
||||
// Wait for restore to finish.
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(observer, "bookmarks-restore-success");
|
||||
os.removeObserver(observer, "bookmarks-restore-failed");
|
||||
do_check_eq(aTopic, "bookmarks-restore-success");
|
||||
do_check_eq(aData, "html-initial");
|
||||
continue_test();
|
||||
}
|
||||
}
|
||||
os.addObserver(observer, "bookmarks-restore-success", false);
|
||||
os.addObserver(observer, "bookmarks-restore-failed", false);
|
||||
// The test will continue once import has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
// Check that default bookmarks have been restored.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_true(itemId > 0);
|
||||
|
@ -42,9 +42,37 @@
|
||||
* bookmark on init, we should not try to import.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onBeforeItemRemoved: function(id) {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
// Create our bookmarks.html copying bookmarks.glue.html to the profile
|
||||
// folder. It will be ignored.
|
||||
create_bookmarks_html("bookmarks.glue.html");
|
||||
@ -57,11 +85,6 @@ function run_test() {
|
||||
do_check_false(db.exists());
|
||||
}
|
||||
|
||||
// Disable Smart Bookmarks creation.
|
||||
let ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
|
||||
// Initialize Places through the History Service.
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
@ -71,8 +94,6 @@ function run_test() {
|
||||
|
||||
// A migrator would run before nsBrowserGlue, so we mimic that behavior
|
||||
// adding a bookmark.
|
||||
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://mozilla.org/"),
|
||||
bs.DEFAULT_INDEX, "migrated");
|
||||
|
||||
@ -80,23 +101,19 @@ function run_test() {
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIBrowserGlue);
|
||||
|
||||
// Import could take some time, usually less than 1s, but to be sure we will
|
||||
// check after 3s.
|
||||
do_test_pending();
|
||||
do_timeout(3000, continue_test);
|
||||
// The test will continue once import has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
// Check the created bookmarks still exist.
|
||||
let itemId = bs.getIdForItemAt(bs.bookmarksMenuFolder, 0);
|
||||
let itemId = bs.getIdForItemAt(bs.bookmarksMenuFolder, SMART_BOOKMARKS_ON_MENU);
|
||||
do_check_eq(bs.getItemTitle(itemId), "migrated");
|
||||
|
||||
// Check that we have not imported any new bookmark.
|
||||
do_check_eq(bs.getIdForItemAt(bs.bookmarksMenuFolder, 1), -1);
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||
do_check_eq(bs.getIdForItemAt(bs.bookmarksMenuFolder, SMART_BOOKMARKS_ON_MENU + 1), -1);
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_MENU), -1);
|
||||
|
||||
remove_bookmarks_html();
|
||||
|
||||
|
@ -41,6 +41,32 @@
|
||||
* database has been created and one backup is available.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onBeforeItemRemoved: function(id) {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
@ -70,29 +96,15 @@ function run_test() {
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
|
||||
|
||||
// Wait for restore to finish.
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(observer, "bookmarks-restore-success");
|
||||
os.removeObserver(observer, "bookmarks-restore-failed");
|
||||
do_check_eq(aTopic, "bookmarks-restore-success");
|
||||
do_check_eq(aData, "json");
|
||||
continue_test();
|
||||
}
|
||||
}
|
||||
os.addObserver(observer, "bookmarks-restore-success", false);
|
||||
os.addObserver(observer, "bookmarks-restore-failed", false);
|
||||
// The test will continue once restore has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
// Check that JSON backup has been restored.
|
||||
// Notice restore from JSON notification is fired before smart bookmarks creation.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(bs.getItemTitle(itemId), "examplejson");
|
||||
|
||||
remove_bookmarks_html();
|
||||
|
@ -113,6 +113,9 @@
|
||||
#define NS_FAVICONSERVICE_CONTRACTID \
|
||||
"@mozilla.org/browser/favicon-service;1"
|
||||
|
||||
#define NS_PLACESIMPORTEXPORTSERVICE_CONTRACTID \
|
||||
"@mozilla.org/browser/places/import-export-service;1"
|
||||
|
||||
#define NS_APPSTARTUP_CONTRACTID \
|
||||
"@mozilla.org/toolkit/app-startup;1"
|
||||
|
||||
@ -199,3 +202,7 @@
|
||||
|
||||
#define NS_FAVICONSERVICE_CID \
|
||||
{ 0x984e3259, 0x9266, 0x49cf, { 0xb6, 0x05, 0x60, 0xb0, 0x22, 0xa0, 0x07, 0x56 } }
|
||||
|
||||
// {6fb0c970-e1b1-11db-8314-0800200c9a66}
|
||||
#define NS_PLACESIMPORTEXPORTSERVICE_CID \
|
||||
{ 0x6fb0c970, 0xe1b1, 0x11db, { 0x83, 0x14, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 } }
|
||||
|
@ -63,6 +63,7 @@ XPIDLSRCS += \
|
||||
nsPIPlacesHistoryListenersNotifier.idl \
|
||||
mozIPlacesAutoComplete.idl \
|
||||
nsIMicrosummaryService.idl \
|
||||
nsIPlacesImportExportService.idl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
|
@ -65,6 +65,7 @@ CPPSRCS = \
|
||||
SQLFunctions.cpp \
|
||||
Helpers.cpp \
|
||||
History.cpp \
|
||||
nsPlacesImportExportService.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
|
@ -95,7 +95,6 @@
|
||||
#include "nsPlacesImportExportService.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
@ -104,9 +103,9 @@
|
||||
#include "nsIHTMLContentSink.h"
|
||||
#include "nsIParser.h"
|
||||
#include "prprf.h"
|
||||
#include "nsIBrowserGlue.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsPlacesMacros.h"
|
||||
|
||||
static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
|
||||
|
||||
@ -309,6 +308,7 @@ nsEscapeHTML(const char* string)
|
||||
return escaped;
|
||||
}
|
||||
|
||||
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsPlacesImportExportService, gImportExportService)
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsPlacesImportExportService, nsIPlacesImportExportService,
|
||||
nsINavHistoryBatchCallback)
|
||||
@ -316,25 +316,37 @@ NS_IMPL_ISUPPORTS2(nsPlacesImportExportService, nsIPlacesImportExportService,
|
||||
|
||||
nsPlacesImportExportService::nsPlacesImportExportService()
|
||||
{
|
||||
// Be sure to call EnsureServiceState() before using services.
|
||||
mHistoryService = do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
|
||||
NS_WARN_IF_FALSE(mHistoryService, "could not get history service");
|
||||
mFaviconService = do_GetService(NS_FAVICONSERVICE_CONTRACTID);
|
||||
NS_WARN_IF_FALSE(mFaviconService, "could not get favicon service");
|
||||
mAnnotationService = do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID);
|
||||
NS_WARN_IF_FALSE(mAnnotationService, "could not get annotation service");
|
||||
mBookmarksService = do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID);
|
||||
NS_WARN_IF_FALSE(mBookmarksService, "could not get bookmarks service");
|
||||
mLivemarkService = do_GetService(NS_LIVEMARKSERVICE_CONTRACTID);
|
||||
NS_WARN_IF_FALSE(mLivemarkService, "could not get livemark service");
|
||||
mMicrosummaryService = do_GetService("@mozilla.org/microsummary/service;1");
|
||||
NS_WARN_IF_FALSE(mMicrosummaryService, "could not get microsummary service");
|
||||
NS_ASSERTION(!gImportExportService,
|
||||
"Attempting to create two instances of the service!");
|
||||
gImportExportService = this;
|
||||
}
|
||||
|
||||
nsPlacesImportExportService::~nsPlacesImportExportService()
|
||||
{
|
||||
NS_ASSERTION(gImportExportService == this,
|
||||
"Deleting a non-singleton instance of the service");
|
||||
if (gImportExportService == this)
|
||||
gImportExportService = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPlacesImportExportService::Init()
|
||||
{
|
||||
// Be sure to call EnsureServiceState() before using services.
|
||||
mHistoryService = do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(mHistoryService, NS_ERROR_OUT_OF_MEMORY);
|
||||
mFaviconService = do_GetService(NS_FAVICONSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(mFaviconService, NS_ERROR_OUT_OF_MEMORY);
|
||||
mAnnotationService = do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(mAnnotationService, NS_ERROR_OUT_OF_MEMORY);
|
||||
mBookmarksService = do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(mBookmarksService, NS_ERROR_OUT_OF_MEMORY);
|
||||
mLivemarkService = do_GetService(NS_LIVEMARKSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(mLivemarkService, NS_ERROR_OUT_OF_MEMORY);
|
||||
mMicrosummaryService = do_GetService("@mozilla.org/microsummary/service;1");
|
||||
NS_ENSURE_TRUE(mMicrosummaryService, NS_ERROR_OUT_OF_MEMORY);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* The content sink stuff is based loosely on nsIHTMLContentSink.
|
||||
@ -1330,7 +1342,7 @@ BookmarkContentSink::ConvertImportedDateToInternalDate(const nsACString& aDate)
|
||||
PRTime convertedDate = 0;
|
||||
if (!aDate.IsEmpty()) {
|
||||
nsresult rv;
|
||||
convertedDate = aDate.ToInteger(&rv);
|
||||
convertedDate = PromiseFlatCString(aDate).ToInteger(&rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
convertedDate *= 1000000; // in bookmarks.html this value is in seconds, not microseconds
|
||||
}
|
||||
@ -2301,13 +2313,6 @@ nsPlacesImportExportService::RunBatched(nsISupports* aUserData)
|
||||
|
||||
rv = mBookmarksService->RemoveFolderChildren(unfiledBookmarksFolder);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Add the smart bookmarks.
|
||||
nsCOMPtr<nsIBrowserGlue> glue =
|
||||
do_GetService("@mozilla.org/browser/browserglue;1");
|
||||
NS_ENSURE_TRUE(glue, NS_ERROR_OUT_OF_MEMORY);
|
||||
rv = glue->EnsurePlacesDefaultQueriesInitialized();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// streams
|
@ -23,7 +23,18 @@ class nsPlacesImportExportService : public nsIPlacesImportExportService,
|
||||
NS_DECL_NSINAVHISTORYBATCHCALLBACK
|
||||
nsPlacesImportExportService();
|
||||
|
||||
/**
|
||||
* Obtains the service's object.
|
||||
*/
|
||||
static nsPlacesImportExportService* GetSingleton();
|
||||
|
||||
/**
|
||||
* Initializes the service's object. This should only be called once.
|
||||
*/
|
||||
nsresult Init();
|
||||
|
||||
private:
|
||||
static nsPlacesImportExportService* gImportExportService;
|
||||
virtual ~nsPlacesImportExportService();
|
||||
|
||||
protected:
|
@ -6,6 +6,7 @@
|
||||
#include "nsNavHistory.h"
|
||||
#include "nsNavBookmarks.h"
|
||||
#include "nsFaviconService.h"
|
||||
#include "nsPlacesImportExportService.h"
|
||||
#include "History.h"
|
||||
#include "nsDocShellCID.h"
|
||||
|
||||
@ -29,6 +30,8 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsNavBookmarks,
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsFaviconService,
|
||||
nsFaviconService::GetSingleton)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(History, History::GetSingleton)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsPlacesImportExportService,
|
||||
nsPlacesImportExportService::GetSingleton)
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAnnoProtocolHandler)
|
||||
|
||||
@ -83,6 +86,11 @@ static const nsModuleComponentInfo components[] =
|
||||
NS_IHISTORY_CONTRACTID,
|
||||
HistoryConstructor },
|
||||
|
||||
{ "Places Import/Export Service",
|
||||
NS_PLACESIMPORTEXPORTSERVICE_CID,
|
||||
NS_PLACESIMPORTEXPORTSERVICE_CONTRACTID,
|
||||
nsPlacesImportExportServiceConstructor},
|
||||
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(nsPlacesModule, components)
|
||||
|
Loading…
Reference in New Issue
Block a user