Bug 236304 - MacIE profile migrator (only imports bookmarks). r=josh/mconnor, a=bsmedberg.

This commit is contained in:
mozilla.mano%sent.com 2005-07-25 21:33:21 +00:00
Родитель a531441ddb
Коммит 11e854a746
12 изменённых файлов: 293 добавлений и 326 удалений

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

@ -48,7 +48,7 @@ interface nsIArray;
interface nsIRDFResource;
interface nsITransactionManager;
[scriptable, uuid(2c31ecce-4157-4820-8631-ec65b2e0ca93)]
[scriptable, uuid(ccc48346-429d-4931-94dc-beb1afcea292)]
interface nsIBookmarksService : nsISupports
{
const unsigned long BOOKMARK_DEFAULT_TYPE = 0;
@ -105,8 +105,6 @@ interface nsIBookmarksService : nsISupports
void updateLastVisitedDate(in string aURL, in wstring docCharset);
string resolveKeyword(in wstring aName, out wstring aPostData);
void importSystemBookmarks(in nsIRDFResource aParentFolder);
readonly attribute nsITransactionManager transactionManager;

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

@ -204,7 +204,6 @@ nsIRDFService *gRDF;
nsIRDFContainerUtils *gRDFC;
nsICharsetAlias *gCharsetAlias;
PRBool gLoadedBookmarks = PR_FALSE;
PRBool gImportedSystemBookmarks = PR_FALSE;
static nsresult
bm_AddRefGlobals()
@ -1618,10 +1617,6 @@ nsBookmarksService::nsBookmarksService() :
mBookmarksAvailable(PR_FALSE),
mDirty(PR_FALSE),
mNeedBackupUpdate(PR_FALSE)
#if defined(XP_MACOSX)
,mIEFavoritesAvailable(PR_FALSE)
#endif
{ }
nsBookmarksService::~nsBookmarksService()
@ -3455,55 +3450,6 @@ nsBookmarksService::ResolveKeyword(const PRUnichar *aUserInput, PRUnichar** aPos
return NS_RDF_NO_VALUE;
}
NS_IMETHODIMP
nsBookmarksService::ImportSystemBookmarks(nsIRDFResource* aParentFolder)
{
gImportedSystemBookmarks = PR_TRUE;
#if defined(XP_MACOSX)
nsCOMPtr<nsIFile> ieFavoritesFile;
nsresult rv = NS_GetSpecialDirectory(NS_MAC_PREFS_DIR, getter_AddRefs(ieFavoritesFile));
NS_ENSURE_SUCCESS(rv, rv);
ieFavoritesFile->Append(NS_LITERAL_STRING("Explorer"));
ieFavoritesFile->Append(NS_LITERAL_STRING("Favorites.html"));
BookmarkParser parser;
parser.Init(ieFavoritesFile, mInner);
BeginUpdateBatch();
parser.Parse(aParentFolder, kNC_Bookmark);
EndUpdateBatch();
#endif
return NS_OK;
}
#if defined(XP_MACOSX)
void
nsBookmarksService::HandleSystemBookmarks(nsIRDFNode* aNode)
{
if (!gImportedSystemBookmarks && aNode == kNC_SystemBookmarksStaticRoot)
{
PRBool isSeq = PR_TRUE;
gRDFC->IsSeq(mInner, kNC_SystemBookmarksStaticRoot, &isSeq);
if (!isSeq)
{
nsCOMPtr<nsIRDFContainer> ctr;
gRDFC->MakeSeq(mInner, kNC_SystemBookmarksStaticRoot, getter_AddRefs(ctr));
ImportSystemBookmarks(kNC_SystemBookmarksStaticRoot);
}
}
#if defined(XP_MACOSX)
// on the Mac, IE favorites are stored in an HTML file.
// Defer importing the contents of this file until necessary.
else if ((aNode == kNC_IEFavoritesRoot) && (mIEFavoritesAvailable == PR_FALSE))
ReadFavorites();
#endif
}
#endif
NS_IMETHODIMP
nsBookmarksService::GetTransactionManager(nsITransactionManager** aTransactionManager)
{
@ -3939,10 +3885,6 @@ nsBookmarksService::HasAssertion(nsIRDFResource* source,
PRBool tv,
PRBool* hasAssertion)
{
#if defined(XP_MACOSX)
HandleSystemBookmarks(source);
#endif
PRBool isLivemark = PR_FALSE;
if (property != kNC_LivemarkLock &&
(property == kRDF_nextVal || property == kNC_child) &&
@ -3984,20 +3926,12 @@ nsBookmarksService::RemoveObserver(nsIRDFObserver* aObserver)
NS_IMETHODIMP
nsBookmarksService::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *_retval)
{
#if defined(XP_MACOSX)
HandleSystemBookmarks(aNode);
#endif
return mInner->HasArcIn(aNode, aArc, _retval);
}
NS_IMETHODIMP
nsBookmarksService::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *_retval)
{
#if defined(XP_MACOSX)
HandleSystemBookmarks(aSource);
#endif
PRBool isLivemark = PR_FALSE;
if (NS_SUCCEEDED(mInner->HasAssertion(aSource, kRDF_type, kNC_Livemark, PR_TRUE, &isLivemark)) &&
isLivemark)
@ -4012,20 +3946,12 @@ NS_IMETHODIMP
nsBookmarksService::ArcLabelsOut(nsIRDFResource* source,
nsISimpleEnumerator** labels)
{
#if defined(XP_MACOSX)
HandleSystemBookmarks(source);
#endif
return mInner->ArcLabelsOut(source, labels);
}
NS_IMETHODIMP
nsBookmarksService::GetAllResources(nsISimpleEnumerator** aResult)
{
#if defined(XP_MACOSX)
HandleSystemBookmarks(kNC_SystemBookmarksStaticRoot);
#endif
{
return mInner->GetAllResources(aResult);
}
@ -4472,59 +4398,6 @@ nsBookmarksService::GetBookmarksFile(nsIFile* *aResult)
return NS_OK;
}
#if defined(XP_MACOSX)
nsresult
nsBookmarksService::ReadFavorites()
{
mIEFavoritesAvailable = PR_TRUE;
nsresult rv;
#ifdef DEBUG_varga
PRTime now = PR_Now();
printf("Start reading in IE Favorites.html\n");
#endif
// look for and import any IE Favorites
nsAutoString ieTitle;
getLocaleString("ImportedIEFavorites", ieTitle);
nsCOMPtr<nsIFile> ieFavoritesFile;
rv = NS_GetSpecialDirectory(NS_MAC_PREFS_DIR, getter_AddRefs(ieFavoritesFile));
NS_ENSURE_SUCCESS(rv, rv);
ieFavoritesFile->Append(NS_LITERAL_STRING("Explorer"));
ieFavoritesFile->Append(NS_LITERAL_STRING("Favorites.html"));
if (NS_SUCCEEDED(rv = gRDFC->MakeSeq(mInner, kNC_IEFavoritesRoot, nsnull)))
{
BookmarkParser parser;
parser.Init(ieFavoritesFile, mInner);
BeginUpdateBatch();
parser.Parse(kNC_IEFavoritesRoot, kNC_IEFavorite);
EndUpdateBatch();
nsCOMPtr<nsIRDFLiteral> ieTitleLiteral;
rv = gRDF->GetLiteral(ieTitle.get(), getter_AddRefs(ieTitleLiteral));
if (NS_SUCCEEDED(rv) && ieTitleLiteral)
{
rv = mInner->Assert(kNC_IEFavoritesRoot, kNC_Name, ieTitleLiteral, PR_TRUE);
}
}
#ifdef DEBUG_varga
PRTime now2 = PR_Now();
PRUint64 loadTime64;
LL_SUB(loadTime64, now2, now);
PRUint32 loadTime32;
LL_L2UI(loadTime32, loadTime64);
printf("Finished reading in IE Favorites.html (%u microseconds)\n", loadTime32);
#endif
return rv;
}
#endif
NS_IMETHODIMP
nsBookmarksService::ReadBookmarks(PRBool *didLoadBookmarks)
{
@ -4695,9 +4568,7 @@ nsBookmarksService::LoadBookmarks()
parser.Init(bookmarksFile, mInner);
if (useDynamicSystemBookmarks)
{
#if defined(XP_MACOSX)
parser.SetIEFavoritesRoot(nsCString(kURINC_IEFavoritesRoot));
#elif defined(XP_BEOS)
#if defined(XP_BEOS)
parser.SetIEFavoritesRoot(bookmarksURICString);
#endif
parser.ParserFoundIEFavoritesRoot(&foundIERoot);
@ -4744,90 +4615,11 @@ nsBookmarksService::LoadBookmarks()
} // <-- scope the stream to get the open/close automatically.
// Now append the one-time-per-profile empty "Full" System Bookmarks Root.
// When the user opens this folder for the first time, system bookmarks are
// imported into this folder. A pref is used to keep track of whether or
// not to perform this operation.
#if defined(XP_MACOSX)
PRBool addedStaticRoot = PR_FALSE;
if (mBookmarksPrefs)
mBookmarksPrefs->GetBoolPref("added_static_root",
&addedStaticRoot);
// Add the root that System bookmarks are imported into as real bookmarks. This is
// only done once.
if (!addedStaticRoot)
{
nsCOMPtr<nsIRDFContainer> rootContainer(do_CreateInstance(kRDFContainerCID, &rv));
if (NS_FAILED(rv)) return rv;
rv = rootContainer->Init(this, kNC_BookmarksRoot);
if (NS_FAILED(rv)) return rv;
rv = mInner->Assert(kNC_SystemBookmarksStaticRoot, kRDF_type, kNC_Folder, PR_TRUE);
if (NS_FAILED(rv)) return rv;
nsAutoString importedStaticTitle;
getLocaleString("ImportedIEStaticFavorites", importedStaticTitle);
nsCOMPtr<nsIRDFLiteral> staticTitleLiteral;
rv = gRDF->GetLiteral(importedStaticTitle.get(), getter_AddRefs(staticTitleLiteral));
if (NS_FAILED(rv)) return rv;
rv = mInner->Assert(kNC_SystemBookmarksStaticRoot, kNC_Name, staticTitleLiteral, PR_TRUE);
if (NS_FAILED(rv)) return rv;
rv = rootContainer->AppendElement(kNC_SystemBookmarksStaticRoot);
if (NS_FAILED(rv)) return rv;
// If the user has not specifically asked for the Dynamic bookmarks root
// via the pref, remove it from an existing bookmarks file as it serves
// only to add confusion.
if (!useDynamicSystemBookmarks)
{
nsCOMPtr<nsIRDFContainer> container(do_CreateInstance(kRDFContainerCID, &rv));
if (NS_FAILED(rv)) return rv;
rv = container->Init(this, kNC_BookmarksRoot);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFResource> systemFolderResource;
#if defined(XP_MACOSX)
rv = gRDF->GetResource(NS_LITERAL_CSTRING(kURINC_IEFavoritesRoot),
getter_AddRefs(systemFolderResource));
#endif
rv = container->RemoveElement(systemFolderResource, PR_TRUE);
if (NS_FAILED(rv)) return rv;
}
if (mBookmarksPrefs)
mBookmarksPrefs->SetBoolPref("added_static_root", PR_TRUE);
}
#endif
// Add the dynamic system bookmarks root if the user has asked for it
// by setting the pref.
if (useDynamicSystemBookmarks)
{
#if defined(XP_MACOSX)
// if the IE Favorites root isn't somewhere in bookmarks.html, add it
if (!foundIERoot)
{
nsCOMPtr<nsIRDFContainer> bookmarksRoot(do_CreateInstance(kRDFContainerCID, &rv));
if (NS_FAILED(rv)) return rv;
rv = bookmarksRoot->Init(this, kNC_BookmarksRoot);
if (NS_FAILED(rv)) return rv;
rv = bookmarksRoot->AppendElement(kNC_IEFavoritesRoot);
if (NS_FAILED(rv)) return rv;
// make sure IE Favorites root folder has the proper type
rv = mInner->Assert(kNC_IEFavoritesRoot, kRDF_type, kNC_IEFavoriteFolder, PR_TRUE);
if (NS_FAILED(rv)) return rv;
}
#elif defined(XP_BEOS)
#if defined(XP_BEOS)
nsCOMPtr<nsIRDFResource> systemFolderResource;
rv = gRDF->GetResource(bookmarksURICString,
getter_AddRefs(systemFolderResource));

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

@ -106,17 +106,6 @@ public:
static nsresult UpdateBookmarkForwardProxy(nsIRDFDataSource* aDS, nsIRDFResource* aBookmarkResource);
protected:
// System Bookmark parsing
#if defined(XP_MAC) || defined(XP_MACOSX)
PRBool mIEFavoritesAvailable;
nsresult ReadFavorites();
#endif
#if defined(XP_MAC) || defined(XP_MACOSX)
void HandleSystemBookmarks(nsIRDFNode* aNode);
#endif
static void FireTimer(nsITimer* aTimer, void* aClosure);
nsresult ExamineBookmarkSchedule(nsIRDFResource *theBookmark, PRBool & examineFlag);

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

@ -66,8 +66,8 @@
#ifdef XP_UNIX
#ifdef XP_MACOSX
<radio id="safari" label="&importFromSafari.label;" accesskey="&importFromSafari.accesskey;"/>
<!-- XXXben - uncomment these as we write migrators for them
<radio id="macie" label="&importFromIE.label;" accesskey="&importFromIE.accesskey;"/>
<!-- XXXben - uncomment these as we write migrators for them
<radio id="camino" label="&importFromCamino.label;" accesskey="&importFromCamino.accesskey;"/>
<radio id="omniweb" label="&importFromOmniWeb.label;" accesskey="&importFromOmniWeb.accesskey;"/>
<radio id="icab" label="&importFromICab.label;" accesskey="&importFromICab.accesskey;"/>

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

@ -20,6 +20,7 @@
*
* Contributor(s):
* Ben Goodger <ben@bengoodger.com>
* Asaf Romano <mozilla.mano@sent.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -36,7 +37,10 @@
* ***** END LICENSE BLOCK ***** */
#include "nsBrowserProfileMigratorUtils.h"
#include "nsIBookmarksService.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsILineInputStream.h"
#include "nsIProperties.h"
#include "nsIProfileMigrator.h"
@ -44,9 +48,16 @@
#include "nsNetUtil.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIRDFService.h"
#include "nsIStringBundle.h"
#include "nsISupportsArray.h"
#include "nsXPCOMCID.h"
#include "nsCRT.h"
#define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
void SetProxyPref(const nsACString& aHostPort, const char* aPref,
const char* aPortPref, nsIPrefBranch* aPrefs)
{
@ -141,3 +152,133 @@ GetProfilePath(nsIProfileStartup* aStartup, nsCOMPtr<nsIFile>& aProfileDir)
}
}
}
nsresult
AnnotatePersonalToolbarFolder(nsIFile* aSourceBookmarksFile,
nsIFile* aTargetBookmarksFile,
const char* aToolbarFolderName)
{
nsCOMPtr<nsIInputStream> fileInputStream;
nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream),
aSourceBookmarksFile);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIOutputStream> outputStream;
rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream),
aTargetBookmarksFile);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILineInputStream> lineInputStream =
do_QueryInterface(fileInputStream, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString sourceBuffer;
nsCAutoString targetBuffer;
PRBool moreData = PR_FALSE;
PRUint32 bytesWritten = 0;
do {
lineInputStream->ReadLine(sourceBuffer, &moreData);
if (!moreData)
break;
PRInt32 nameOffset = sourceBuffer.Find(aToolbarFolderName);
if (nameOffset >= 0) {
// Found the personal toolbar name on a line, check to make sure it's
// actually a folder.
NS_NAMED_LITERAL_CSTRING(folderPrefix, "<DT><H3 ");
PRInt32 folderPrefixOffset = sourceBuffer.Find(folderPrefix);
if (folderPrefixOffset >= 0)
sourceBuffer.Insert(NS_LITERAL_CSTRING("PERSONAL_TOOLBAR_FOLDER=\"true\" "),
folderPrefixOffset + folderPrefix.Length());
}
targetBuffer.Assign(sourceBuffer);
targetBuffer.Append("\r\n");
outputStream->Write(targetBuffer.get(), targetBuffer.Length(),
&bytesWritten);
}
while (1);
outputStream->Close();
return NS_OK;
}
nsresult
ImportBookmarksHTML(nsIFile* aBookmarksFile,
const PRUnichar* aImportSourceNameKey)
{
nsresult rv;
nsCOMPtr<nsIBookmarksService> bms =
do_GetService("@mozilla.org/browser/bookmarks-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupportsArray> params;
rv = NS_NewISupportsArray(getter_AddRefs(params));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRDFService> rdfs =
do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRDFResource> prop;
rv = rdfs->GetResource(NC_URI(URL), getter_AddRefs(prop));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRDFLiteral> url;
nsAutoString path;
aBookmarksFile->GetPath(path);
rdfs->GetLiteral(path.get(), getter_AddRefs(url));
params->AppendElement(prop);
params->AppendElement(url);
nsCOMPtr<nsIRDFResource> importCmd;
rv = rdfs->GetResource(NC_URI(command?cmd=import), getter_AddRefs(importCmd));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRDFResource> root;
rv = rdfs->GetResource(NS_LITERAL_CSTRING("NC:BookmarksRoot"),
getter_AddRefs(root));
NS_ENSURE_SUCCESS(rv, rv);
// Look for the localized name of the bookmarks toolbar
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(kStringBundleServiceCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(MIGRATION_BUNDLE, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString sourceName;
bundle->GetStringFromName(aImportSourceNameKey, getter_Copies(sourceName));
const PRUnichar* sourceNameStrings[] = { sourceName.get() };
nsXPIDLString importedBookmarksTitle;
bundle->FormatStringFromName(NS_LITERAL_STRING("importedBookmarksFolder").get(),
sourceNameStrings, 1,
getter_Copies(importedBookmarksTitle));
nsCOMPtr<nsIRDFResource> folder;
bms->CreateFolderInContainer(importedBookmarksTitle.get(), root, -1,
getter_AddRefs(folder));
nsCOMPtr<nsIRDFResource> folderProp;
rv = rdfs->GetResource(NC_URI(Folder), getter_AddRefs(folderProp));
NS_ENSURE_SUCCESS(rv, rv);
params->AppendElement(folderProp);
params->AppendElement(folder);
nsCOMPtr<nsISupportsArray> sources;
rv = NS_NewISupportsArray(getter_AddRefs(sources));
NS_ENSURE_SUCCESS(rv, rv);
sources->AppendElement(folder);
nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(bms, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return ds->DoCommand(sources, importCmd, params);
}

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

@ -86,5 +86,20 @@ void GetMigrateDataFromArray(MigrationData* aDataArray,
// this is already cloned, modify it to your heart's content
void GetProfilePath(nsIProfileStartup* aStartup, nsCOMPtr<nsIFile>& aProfileDir);
// The Netscape Bookmarks Format (bookmarks.html) is fairly standard but
// each browser vendor seems to have their own way of identifying the
// Personal Toolbar Folder. This function scans for the vendor-specific
// name in the source Bookmarks file and then writes out a normalized
// variant into the target folder.
nsresult AnnotatePersonalToolbarFolder(nsIFile* aSourceBookmarksFile,
nsIFile* aTargetBookmarksFile,
const char* aToolbarFolderName);
// In-place import from aBookmarksFile into a folder in the user's bookmarks
// with the name "From (STR:aImportSourceNameKey)" (aImportSourceNameKey
// is a key into migration.properties with the pretty name of the application.
nsresult ImportBookmarksHTML(nsIFile* aBookmarksFile,
const PRUnichar* aImportSourceNameKey);
#endif

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

@ -652,45 +652,10 @@ nsDogbertProfileMigrator::MigrateDogbertBookmarks()
mSourceProfile->Clone(getter_AddRefs(sourceBookmarksFile));
sourceBookmarksFile->Append(BOOKMARKS_FILE_NAME_IN_4x);
nsCOMPtr<nsIInputStream> fileInputStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), sourceBookmarksFile);
if (!fileInputStream) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIFile> targetBookmarksFile;
mTargetProfile->Clone(getter_AddRefs(targetBookmarksFile));
targetBookmarksFile->Append(BOOKMARKS_FILE_NAME_IN_5x);
nsCOMPtr<nsIOutputStream> outputStream;
NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), targetBookmarksFile);
if (!outputStream) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsILineInputStream> lineInputStream(do_QueryInterface(fileInputStream));
nsCAutoString sourceBuffer;
nsCAutoString targetBuffer;
PRBool moreData = PR_FALSE;
PRUint32 bytesWritten = 0;
do {
nsresult rv = lineInputStream->ReadLine(sourceBuffer, &moreData);
if (NS_FAILED(rv)) return rv;
if (!moreData)
break;
PRInt32 nameOffset = sourceBuffer.Find(toolbarName);
if (nameOffset >= 0) {
// Found the personal toolbar name on a line, check to make sure it's actually a folder.
NS_NAMED_LITERAL_CSTRING(folderPrefix, "<DT><H3 ");
PRInt32 folderPrefixOffset = sourceBuffer.Find(folderPrefix);
if (folderPrefixOffset >= 0)
sourceBuffer.Insert(NS_LITERAL_CSTRING("PERSONAL_TOOLBAR_FOLDER=\"true\" "),
folderPrefixOffset + folderPrefix.Length());
}
targetBuffer.Assign(sourceBuffer);
targetBuffer.Append("\r\n");
outputStream->Write(targetBuffer.get(), targetBuffer.Length(), &bytesWritten);
}
while (1);
return NS_OK;
return AnnotatePersonalToolbarFolder(sourceBookmarksFile,
targetBookmarksFile, toolbarName);
}

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

@ -35,14 +35,25 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsDirectoryServiceDefs.h"
#include "nsBrowserProfileMigratorUtils.h"
#include "nsMacIEProfileMigrator.h"
#include "nsILocalFile.h"
#include "nsIObserverService.h"
#include "nsIProfileMigrator.h"
#include "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#define MACIE_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("Favorites.html")
#define MACIE_PREFERENCES_FOLDER_NAME NS_LITERAL_STRING("Explorer")
#define FIREFOX_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("bookmarks.html")
#define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
///////////////////////////////////////////////////////////////////////////////
// nsMacIEProfileMigrator
@ -65,8 +76,28 @@ nsMacIEProfileMigrator::Migrate(PRUint16 aItems, nsIProfileStartup* aStartup, co
{
nsresult rv = NS_OK;
PRBool replace = aStartup ? PR_TRUE : PR_FALSE;
if (!mTargetProfile) {
GetProfilePath(aStartup, mTargetProfile);
if (!mTargetProfile) return NS_ERROR_FAILURE;
}
if (!mSourceProfile) {
nsCOMPtr<nsIProperties> fileLocator =
do_GetService("@mozilla.org/file/directory_service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
fileLocator->Get(NS_OSX_USER_PREFERENCES_DIR,
NS_GET_IID(nsILocalFile),
getter_AddRefs(mSourceProfile));
mSourceProfile->Append(MACIE_PREFERENCES_FOLDER_NAME);
}
NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
COPY_DATA(CopyBookmarks, replace, nsIBrowserProfileMigrator::BOOKMARKS);
NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
return rv;
@ -77,15 +108,39 @@ nsMacIEProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
PRBool aReplace,
PRUint16* aResult)
{
*aResult = 0; // XXXben implement me
*aResult = 0;
if (!mSourceProfile) {
nsresult rv;
nsCOMPtr<nsIProperties> fileLocator =
do_GetService("@mozilla.org/file/directory_service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
fileLocator->Get(NS_OSX_USER_PREFERENCES_DIR,
NS_GET_IID(nsILocalFile),
getter_AddRefs(mSourceProfile));
mSourceProfile->Append(MACIE_PREFERENCES_FOLDER_NAME);
}
MigrationData data[] = { { ToNewUnicode(MACIE_BOOKMARKS_FILE_NAME),
nsIBrowserProfileMigrator::BOOKMARKS,
PR_FALSE } };
// Frees file name strings allocated above.
GetMigrateDataFromArray(data, sizeof(data)/sizeof(MigrationData),
aReplace, mSourceProfile, aResult);
return NS_OK;
}
NS_IMETHODIMP
nsMacIEProfileMigrator::GetSourceExists(PRBool* aResult)
{
*aResult = PR_FALSE; // XXXben implement me
PRUint16 data;
GetMigrateData(nsnull, PR_FALSE, &data);
*aResult = data != 0;
return NS_OK;
}
@ -106,3 +161,58 @@ nsMacIEProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
///////////////////////////////////////////////////////////////////////////////
// nsMacIEProfileMigrator
nsresult
nsMacIEProfileMigrator::CopyBookmarks(PRBool aReplace)
{
nsCOMPtr<nsIFile> sourceFile;
mSourceProfile->Clone(getter_AddRefs(sourceFile));
sourceFile->Append(MACIE_BOOKMARKS_FILE_NAME);
PRBool exists = PR_FALSE;
sourceFile->Exists(&exists);
if (!exists)
return NS_OK;
nsCOMPtr<nsIFile> targetFile;
mTargetProfile->Clone(getter_AddRefs(targetFile));
targetFile->Append(FIREFOX_BOOKMARKS_FILE_NAME);
// If we're blowing away existing content, annotate the Personal Toolbar and
// then just copy the file.
if (aReplace) {
nsresult rv;
// Look for the localized name of the IE Favorites Bar
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(kStringBundleServiceCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(MIGRATION_BUNDLE, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString toolbarFolderNameMacIE;
bundle->GetStringFromName(NS_LITERAL_STRING("toolbarFolderNameMacIE").get(),
getter_Copies(toolbarFolderNameMacIE));
nsCAutoString ctoolbarFolderNameMacIE;
CopyUTF16toUTF8(toolbarFolderNameMacIE, ctoolbarFolderNameMacIE);
// If we can't find it for some reason, just copy the file.
if (NS_FAILED(rv)) {
targetFile->Exists(&exists);
if (exists)
targetFile->Remove(PR_FALSE);
return sourceFile->CopyTo(mTargetProfile, FIREFOX_BOOKMARKS_FILE_NAME);
}
// Now read the 4.x bookmarks file, correcting the Personal Toolbar Folder
// line and writing to the new location.
return AnnotatePersonalToolbarFolder(sourceFile,
targetFile,
ctoolbarFolderNameMacIE.get());
}
return ImportBookmarksHTML(sourceFile,
NS_LITERAL_STRING("sourceNameIE").get());
}

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

@ -53,9 +53,14 @@ public:
virtual ~nsMacIEProfileMigrator();
protected:
nsresult CopyBookmarks(PRBool aReplace);
protected:
nsCOMPtr<nsILocalFile> mSourceProfile;
nsCOMPtr<nsIFile> mTargetProfile;
private:
nsCOMPtr<nsIObserverService> mObserverService;
};
#endif
#endif

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

@ -36,20 +36,18 @@
* ***** END LICENSE BLOCK ***** */
#include "nsAppDirectoryServiceDefs.h"
#include "nsBrowserProfileMigratorUtils.h"
#include "nsCRT.h"
#include "nsIBookmarksService.h"
#include "nsICookieManager2.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsILineInputStream.h"
#include "nsInt64.h"
#include "nsIOutputStream.h"
#include "nsIPrefBranch.h"
#include "nsIPrefLocalizedString.h"
#include "nsIPrefService.h"
#include "nsIRDFService.h"
#include "nsIRegistry.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsISupportsPrimitives.h"
#include "nsIURL.h"
#include "nsNetscapeProfileMigratorBase.h"
@ -64,18 +62,12 @@
#define SECONDS_BETWEEN_1900_AND_1970 2208988800UL
#endif /* XP_MAC */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
#define FILE_NAME_PREFS_5X NS_LITERAL_STRING("prefs.js")
///////////////////////////////////////////////////////////////////////////////
// nsNetscapeProfileMigratorBase
nsNetscapeProfileMigratorBase::nsNetscapeProfileMigratorBase()
{
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(kStringBundleServiceCID));
bundleService->CreateBundle(MIGRATION_BUNDLE, getter_AddRefs(mBundle));
}
nsresult
@ -280,54 +272,8 @@ nsNetscapeProfileMigratorBase::ImportNetscapeBookmarks(const nsAString& aBookmar
nsCOMPtr<nsIFile> bookmarksFile;
mSourceProfile->Clone(getter_AddRefs(bookmarksFile));
bookmarksFile->Append(aBookmarksFileName);
nsCOMPtr<nsIBookmarksService> bms(do_GetService("@mozilla.org/browser/bookmarks-service;1"));
nsCOMPtr<nsISupportsArray> params;
NS_NewISupportsArray(getter_AddRefs(params));
nsCOMPtr<nsIRDFService> rdfs(do_GetService("@mozilla.org/rdf/rdf-service;1"));
nsCOMPtr<nsIRDFResource> prop;
rdfs->GetResource(NS_LITERAL_CSTRING("http://home.netscape.com/NC-rdf#URL"),
getter_AddRefs(prop));
nsCOMPtr<nsIRDFLiteral> url;
nsAutoString path;
bookmarksFile->GetPath(path);
rdfs->GetLiteral(path.get(), getter_AddRefs(url));
params->AppendElement(prop);
params->AppendElement(url);
nsCOMPtr<nsIRDFResource> importCmd;
rdfs->GetResource(NS_LITERAL_CSTRING("http://home.netscape.com/NC-rdf#command?cmd=import"),
getter_AddRefs(importCmd));
nsCOMPtr<nsIRDFResource> root;
rdfs->GetResource(NS_LITERAL_CSTRING("NC:BookmarksRoot"), getter_AddRefs(root));
nsXPIDLString sourceName;
mBundle->GetStringFromName(aImportSourceNameKey, getter_Copies(sourceName));
const PRUnichar* sourceNameStrings[] = { sourceName.get() };
nsXPIDLString importedBookmarksTitle;
mBundle->FormatStringFromName(NS_LITERAL_STRING("importedBookmarksFolder").get(),
sourceNameStrings, 1,
getter_Copies(importedBookmarksTitle));
nsCOMPtr<nsIRDFResource> folder;
bms->CreateFolderInContainer(importedBookmarksTitle.get(), root, -1, getter_AddRefs(folder));
nsCOMPtr<nsIRDFResource> folderProp;
rdfs->GetResource(NS_LITERAL_CSTRING("http://home.netscape.com/NC-rdf#Folder"),
getter_AddRefs(folderProp));
params->AppendElement(folderProp);
params->AppendElement(folder);
nsCOMPtr<nsISupportsArray> sources;
NS_NewISupportsArray(getter_AddRefs(sources));
sources->AppendElement(folder);
nsCOMPtr<nsIRDFDataSource> ds(do_QueryInterface(bms));
return ds->DoCommand(sources, importCmd, params);
return ImportBookmarksHTML(bookmarksFile, aImportSourceNameKey);
}
nsresult

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

@ -40,6 +40,7 @@
#include "nsILocalFile.h"
#include "nsIStringBundle.h"
#include "nsISupportsArray.h"
#include "nsString.h"
class nsIFile;
@ -95,8 +96,6 @@ protected:
protected:
nsCOMPtr<nsILocalFile> mSourceProfile;
nsCOMPtr<nsIFile> mTargetProfile;
nsCOMPtr<nsIStringBundle> mBundle;
};
#endif

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

@ -33,6 +33,7 @@ importedOperaSearchUrls=Keyword Searches (From Opera)
1_seamonkey=Preferences
1_phoenix=Preferences
1_safari=Preferences
1_macie=Preferences
2_ie=Cookies
2_opera=Cookies
@ -40,6 +41,7 @@ importedOperaSearchUrls=Keyword Searches (From Opera)
2_seamonkey=Cookies
2_phoenix=Cookies
2_safari=Cookies
2_macie=Cookies
4_ie=Browsing History
4_opera=Browsing History
@ -47,6 +49,7 @@ importedOperaSearchUrls=Keyword Searches (From Opera)
4_seamonkey=Browsing History
4_phoenix=Browsing History
4_safari=Browsing History
4_macie=Browsing History
8_ie=Saved Form History
8_opera=Saved Form History
@ -54,6 +57,7 @@ importedOperaSearchUrls=Keyword Searches (From Opera)
8_seamonkey=Saved Form History
8_phoenix=Saved Form History
8_safari=Saved Form History
8_macie=Saved Form History
16_ie=Saved Passwords
16_opera=Saved Passwords
@ -61,6 +65,7 @@ importedOperaSearchUrls=Keyword Searches (From Opera)
16_seamonkey=Saved Passwords
16_phoenix=Saved Passwords
16_safari=Saved Passwords
16_macie=Saved Passwords
32_ie=Favorites
32_opera=Bookmarks
@ -68,6 +73,7 @@ importedOperaSearchUrls=Keyword Searches (From Opera)
32_seamonkey=Bookmarks
32_phoenix=Bookmarks
32_safari=Bookmarks
32_macie=Favorites
64_ie=Other Data
64_opera=Other Data
@ -75,4 +81,5 @@ importedOperaSearchUrls=Keyword Searches (From Opera)
64_seamonkey=Other Data
64_phoenix=Other Data
64_safari=Other Data
64_macie=Other Data