зеркало из https://github.com/mozilla/gecko-dev.git
(215094) - Make Migrator only show options in import data source list that can be imported after the profile has been loaded.
This commit is contained in:
Родитель
856a899981
Коммит
602b725ee8
|
@ -72,7 +72,18 @@ var MigrationWizard = {
|
|||
this._source = newSource;
|
||||
|
||||
// check for more than one source profile
|
||||
this._wiz.currentPage.next = this._migrator.sourceHasMultipleProfiles ? "selectProfile" : "importItems";
|
||||
if (this._migrator.sourceHasMultipleProfiles)
|
||||
this._wiz.currentPage.next = "selectProfile";
|
||||
else {
|
||||
this._wiz.currentPage.next = "importItems";
|
||||
var sourceProfiles = this._migrator.sourceProfiles;
|
||||
if (sourceProfiles && sourceProfiles.Count() == 1) {
|
||||
var profileName = sourceProfiles.QueryElementAt(0, Components.interfaces.nsISupportsString);
|
||||
this._selectedProfile = profileName.data;
|
||||
}
|
||||
else
|
||||
this._selectedProfile = "";
|
||||
}
|
||||
},
|
||||
|
||||
// 2 - [Profile Selection]
|
||||
|
@ -123,7 +134,7 @@ var MigrationWizard = {
|
|||
|
||||
var bundle = document.getElementById("bundle");
|
||||
|
||||
var items = this._migrator.getMigrateData(this._selectedProfile);
|
||||
var items = this._migrator.getMigrateData(this._selectedProfile, this._autoMigrate);
|
||||
for (var i = 0; i < 32; ++i) {
|
||||
var itemID = (items >> i) & 0x1 ? Math.pow(2, i) : 0;
|
||||
if (itemID > 0) {
|
||||
|
|
|
@ -66,9 +66,11 @@ interface nsIBrowserProfileMigrator : nsISupports
|
|||
* offers for import.
|
||||
* @param aProfile the profile that we are looking for available data
|
||||
* to import
|
||||
* @param aReplace whether or not the profile is being run replace-current
|
||||
* data mode (automigration, before profile has started)
|
||||
* @returns bit field containing profile items (see above)
|
||||
*/
|
||||
unsigned long getMigrateData(in wstring aProfile);
|
||||
unsigned long getMigrateData(in wstring aProfile, in boolean aReplace);
|
||||
|
||||
/**
|
||||
* Whether or not there is any data that can be imported from this
|
||||
|
|
|
@ -64,4 +64,10 @@ void ParseOverrideServers(char* aServers, nsIPrefBranch* aBranch);
|
|||
void SetProxyPref(const nsACString& aHostPort, const char* aPref,
|
||||
const char* aPortPref, nsIPrefBranch* aPrefs);
|
||||
|
||||
typedef struct {
|
||||
PRUnichar* fileName;
|
||||
PRUint32 sourceFlag;
|
||||
PRBool replaceOnly;
|
||||
} MIGRATIONDATA;
|
||||
|
||||
#endif
|
|
@ -77,7 +77,9 @@ nsCaminoProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnich
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCaminoProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsCaminoProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
*aResult = 0; // XXXben implement me
|
||||
return NS_OK;
|
||||
|
|
|
@ -140,26 +140,40 @@ nsDogbertProfileMigrator::GetSourceProfile(const PRUnichar* aProfile)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDogbertProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsDogbertProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
if (!mSourceProfile)
|
||||
GetSourceProfile(aProfile);
|
||||
|
||||
PRBool exists;
|
||||
const PRUnichar* fileNames[] = { PREF_FILE_NAME_IN_4x.get(),
|
||||
COOKIES_FILE_NAME_IN_4x.get(),
|
||||
BOOKMARKS_FILE_NAME_IN_4x.get() };
|
||||
const PRUint32 sourceFlags[] = { nsIBrowserProfileMigrator::SETTINGS,
|
||||
const MIGRATIONDATA data[] = { { ToNewUnicode(PREF_FILE_NAME_IN_4x),
|
||||
nsIBrowserProfileMigrator::SETTINGS,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(COOKIES_FILE_NAME_IN_4x),
|
||||
nsIBrowserProfileMigrator::COOKIES,
|
||||
nsIBrowserProfileMigrator::BOOKMARKS };
|
||||
PR_FALSE },
|
||||
{ ToNewUnicode(BOOKMARKS_FILE_NAME_IN_4x),
|
||||
nsIBrowserProfileMigrator::BOOKMARKS,
|
||||
PR_FALSE } };
|
||||
|
||||
nsCOMPtr<nsIFile> sourceFile;
|
||||
for (PRInt32 i = 0; i < 3; ++i) {
|
||||
// Don't list items that can only be imported in replace-mode when
|
||||
// we aren't being run in replace-mode.
|
||||
if (!aReplace && data[i].replaceOnly)
|
||||
continue;
|
||||
|
||||
mSourceProfile->Clone(getter_AddRefs(sourceFile));
|
||||
sourceFile->Append(nsDependentString(fileNames[i]));
|
||||
sourceFile->Append(nsDependentString(data[i].fileName));
|
||||
sourceFile->Exists(&exists);
|
||||
if (exists)
|
||||
*aResult |= sourceFlags[i];
|
||||
*aResult |= data[i].sourceFlag;
|
||||
|
||||
nsCRT::free(data[i].fileName);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -365,7 +379,7 @@ nsDogbertProfileMigrator::CopyCookies(PRBool aReplace)
|
|||
mSourceProfile->Clone(getter_AddRefs(dogbertCookiesFile));
|
||||
dogbertCookiesFile->Append(COOKIES_FILE_NAME_IN_4x);
|
||||
|
||||
rv = cookieManager->ReadCookies(dogbertCookiesFile);
|
||||
rv = ImportNetscapeCookies(dogbertCookiesFile);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -464,7 +478,7 @@ nsDogbertProfileMigrator::CopyBookmarks(PRBool aReplace)
|
|||
return MigrateDogbertBookmarks();
|
||||
|
||||
return ImportNetscapeBookmarks(BOOKMARKS_FILE_NAME_IN_4x,
|
||||
NS_LITERAL_STRING("sourceNameSeamonkey").get());
|
||||
NS_LITERAL_STRING("sourceNameDogbert").get());
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -77,7 +77,9 @@ nsICabProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsICabProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsICabProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
*aResult = 0; // XXXben implement me
|
||||
return NS_OK;
|
||||
|
|
|
@ -448,7 +448,9 @@ nsIEProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnichar*
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIEProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsIEProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
// There's no harm in assuming everything is available.
|
||||
*aResult = nsIBrowserProfileMigrator::SETTINGS | nsIBrowserProfileMigrator::COOKIES |
|
||||
|
|
|
@ -77,7 +77,9 @@ nsMacIEProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnicha
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacIEProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsMacIEProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
*aResult = 0; // XXXben implement me
|
||||
return NS_OK;
|
||||
|
|
|
@ -38,7 +38,11 @@
|
|||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIBookmarksService.h"
|
||||
#include "nsICookieManager2.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsILineInputStream.h"
|
||||
#include "nsInt64.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefLocalizedString.h"
|
||||
#include "nsIPrefService.h"
|
||||
|
@ -49,9 +53,12 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetscapeProfileMigratorBase.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "prtime.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
|
@ -63,6 +70,8 @@ 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()
|
||||
|
@ -390,3 +399,153 @@ nsNetscapeProfileMigratorBase::ImportNetscapeBookmarks(const nsAString& aBookmar
|
|||
return ds->DoCommand(sources, importCmd, params);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsNetscapeProfileMigratorBase::ImportNetscapeCookies(nsIFile* aCookiesFile)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStream> cookiesStream;
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(cookiesStream), aCookiesFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsILineInputStream> lineInputStream(do_QueryInterface(cookiesStream));
|
||||
|
||||
// This code is copied from mozilla/netwerk/cookie/src/nsCookieManager.cpp
|
||||
static NS_NAMED_LITERAL_CSTRING(kTrue, "TRUE");
|
||||
|
||||
nsAutoString bufferUnicode;
|
||||
nsCAutoString buffer;
|
||||
PRBool isMore = PR_TRUE;
|
||||
PRInt32 hostIndex = 0, isDomainIndex, pathIndex, secureIndex, expiresIndex, nameIndex, cookieIndex;
|
||||
nsASingleFragmentCString::char_iterator iter;
|
||||
PRInt32 numInts;
|
||||
PRInt64 expires;
|
||||
PRBool isDomain;
|
||||
nsInt64 currentTime = nsInt64(PR_Now()) / nsInt64(1000000);
|
||||
|
||||
nsCOMPtr<nsICookieManager2> cookieManager(do_GetService(NS_COOKIEMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
/* file format is:
|
||||
*
|
||||
* host \t isDomain \t path \t secure \t expires \t name \t cookie
|
||||
*
|
||||
* if this format isn't respected we move onto the next line in the file.
|
||||
* isDomain is "TRUE" or "FALSE" (default to "FALSE")
|
||||
* isSecure is "TRUE" or "FALSE" (default to "TRUE")
|
||||
* expires is a PRInt64 integer
|
||||
* note 1: cookie can contain tabs.
|
||||
* note 2: cookies are written in order of lastAccessed time:
|
||||
* most-recently used come first; least-recently-used come last.
|
||||
*/
|
||||
|
||||
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(bufferUnicode, &isMore))) {
|
||||
// downconvert to ASCII. eventually, we want to fix nsILineInputStream
|
||||
// to operate on a CString buffer...
|
||||
CopyUCS2toASCII(bufferUnicode, buffer);
|
||||
|
||||
if (buffer.IsEmpty() || buffer.First() == '#')
|
||||
continue;
|
||||
|
||||
// this is a cheap, cheesy way of parsing a tab-delimited line into
|
||||
// string indexes, which can be lopped off into substrings. just for
|
||||
// purposes of obfuscation, it also checks that each token was found.
|
||||
// todo: use iterators?
|
||||
if ((isDomainIndex = buffer.FindChar('\t', hostIndex) + 1) == 0 ||
|
||||
(pathIndex = buffer.FindChar('\t', isDomainIndex) + 1) == 0 ||
|
||||
(secureIndex = buffer.FindChar('\t', pathIndex) + 1) == 0 ||
|
||||
(expiresIndex = buffer.FindChar('\t', secureIndex) + 1) == 0 ||
|
||||
(nameIndex = buffer.FindChar('\t', expiresIndex) + 1) == 0 ||
|
||||
(cookieIndex = buffer.FindChar('\t', nameIndex) + 1) == 0)
|
||||
continue;
|
||||
|
||||
// check the expirytime first - if it's expired, ignore
|
||||
// nullstomp the trailing tab, to avoid copying the string
|
||||
buffer.BeginWriting(iter);
|
||||
*(iter += nameIndex - 1) = char(0);
|
||||
numInts = PR_sscanf(buffer.get() + expiresIndex, "%lld", &expires);
|
||||
if (numInts != 1 || nsInt64(expires) < currentTime)
|
||||
continue;
|
||||
|
||||
isDomain = Substring(buffer, isDomainIndex, pathIndex - isDomainIndex - 1).Equals(kTrue);
|
||||
const nsASingleFragmentCString &host = Substring(buffer, hostIndex, isDomainIndex - hostIndex - 1);
|
||||
// check for bad legacy cookies (domain not starting with a dot, or containing a port),
|
||||
// and discard
|
||||
if (isDomain && !host.IsEmpty() && host.First() != '.' ||
|
||||
host.FindChar(':') != kNotFound)
|
||||
continue;
|
||||
|
||||
// create a new nsCookie and assign the data.
|
||||
rv = cookieManager->Add(host,
|
||||
Substring(buffer, pathIndex, secureIndex - pathIndex - 1),
|
||||
Substring(buffer, nameIndex, cookieIndex - nameIndex - 1),
|
||||
Substring(buffer, cookieIndex, buffer.Length() - cookieIndex),
|
||||
Substring(buffer, secureIndex, expiresIndex - secureIndex - 1).Equals(kTrue),
|
||||
PR_FALSE,
|
||||
expires);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsNetscapeProfileMigratorBase::GetSignonFileName(PRBool aReplace, char** aFileName)
|
||||
{
|
||||
nsresult rv;
|
||||
if (aReplace) {
|
||||
// Find out what the signons file was called, this is stored in a pref
|
||||
// in Seamonkey.
|
||||
nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
psvc->ResetPrefs();
|
||||
|
||||
nsCOMPtr<nsIFile> sourcePrefsName;
|
||||
mSourceProfile->Clone(getter_AddRefs(sourcePrefsName));
|
||||
sourcePrefsName->Append(FILE_NAME_PREFS_5X);
|
||||
psvc->ReadUserPrefs(sourcePrefsName);
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
|
||||
rv = branch->GetCharPref("signon.SignonFileName", aFileName);
|
||||
}
|
||||
else
|
||||
rv = LocateSignonsFile(aFileName);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsNetscapeProfileMigratorBase::LocateSignonsFile(char** aResult)
|
||||
{
|
||||
nsCOMPtr<nsISimpleEnumerator> entries;
|
||||
nsresult rv = mSourceProfile->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString fileName;
|
||||
do {
|
||||
PRBool hasMore = PR_FALSE;
|
||||
rv = entries->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv) || !hasMore) break;
|
||||
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
rv = entries->GetNext(getter_AddRefs(supp));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
nsCOMPtr<nsIFile> currFile(do_QueryInterface(supp));
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewFileURI(getter_AddRefs(uri), currFile);
|
||||
if (NS_FAILED(rv)) break;
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
||||
|
||||
nsCAutoString extn;
|
||||
url->GetFileExtension(extn);
|
||||
|
||||
if (extn.EqualsIgnoreCase("s")) {
|
||||
url->GetFileName(fileName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1);
|
||||
|
||||
*aResult = ToNewCString(fileName);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,11 @@ protected:
|
|||
nsresult ImportNetscapeBookmarks(const nsAString& aBookmarksFileName,
|
||||
const PRUnichar* aImportSourceNameKey);
|
||||
|
||||
nsresult ImportNetscapeCookies(nsIFile* aCookiesFile);
|
||||
|
||||
nsresult GetSignonFileName(PRBool aReplace, char** aFileName);
|
||||
nsresult LocateSignonsFile(char** aResult);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsILocalFile> mSourceProfile;
|
||||
nsCOMPtr<nsILocalFile> mTargetProfile;
|
||||
|
|
|
@ -77,7 +77,9 @@ nsOmniWebProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnic
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOmniWebProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsOmniWebProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
*aResult = 0; // XXXben implement me
|
||||
return NS_OK;
|
||||
|
|
|
@ -62,11 +62,13 @@
|
|||
#include "nsOperaProfileMigrator.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsToolkitCompsCID.h"
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
static NS_DEFINE_CID(kGlobalHistoryCID, NS_GLOBALHISTORY_CID);
|
||||
#define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
|
||||
|
||||
#ifdef XP_WIN
|
||||
|
@ -120,28 +122,43 @@ nsOperaProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnicha
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOperaProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsOperaProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
if (!mOperaProfile)
|
||||
GetOperaProfile(aProfile, getter_AddRefs(mOperaProfile));
|
||||
|
||||
PRBool exists;
|
||||
const PRUnichar* fileNames[] = { OPERA_PREFERENCES_FILE_NAME.get(),
|
||||
OPERA_COOKIES_FILE_NAME.get(),
|
||||
OPERA_HISTORY_FILE_NAME.get(),
|
||||
OPERA_BOOKMARKS_FILE_NAME.get() };
|
||||
const PRUint32 sourceFlags[] = { nsIBrowserProfileMigrator::SETTINGS,
|
||||
const MIGRATIONDATA data[] = { { ToNewUnicode(OPERA_PREFERENCES_FILE_NAME),
|
||||
nsIBrowserProfileMigrator::SETTINGS,
|
||||
PR_FALSE },
|
||||
{ ToNewUnicode(OPERA_COOKIES_FILE_NAME),
|
||||
nsIBrowserProfileMigrator::COOKIES,
|
||||
PR_FALSE },
|
||||
{ ToNewUnicode(OPERA_HISTORY_FILE_NAME),
|
||||
nsIBrowserProfileMigrator::HISTORY,
|
||||
nsIBrowserProfileMigrator::BOOKMARKS };
|
||||
PR_FALSE },
|
||||
{ ToNewUnicode(OPERA_BOOKMARKS_FILE_NAME),
|
||||
nsIBrowserProfileMigrator::BOOKMARKS,
|
||||
PR_FALSE } };
|
||||
|
||||
nsCOMPtr<nsIFile> sourceFile;
|
||||
PRBool exists;
|
||||
for (PRInt32 i = 0; i < 4; ++i) {
|
||||
// Don't list items that can only be imported in replace-mode when
|
||||
// we aren't being run in replace-mode.
|
||||
if (!aReplace && data[i].replaceOnly)
|
||||
continue;
|
||||
|
||||
mOperaProfile->Clone(getter_AddRefs(sourceFile));
|
||||
sourceFile->Append(nsDependentString(fileNames[i]));
|
||||
sourceFile->Append(nsDependentString(data[i].fileName));
|
||||
sourceFile->Exists(&exists);
|
||||
if (exists)
|
||||
*aResult |= sourceFlags[i];
|
||||
*aResult |= data[i].sourceFlag;
|
||||
|
||||
nsCRT::free(data[i].fileName);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -828,7 +845,7 @@ nsOperaCookieMigrator::ReadHeader()
|
|||
nsresult
|
||||
nsOperaProfileMigrator::CopyHistory(PRBool aReplace)
|
||||
{
|
||||
nsCOMPtr<nsIBrowserHistory> hist(do_GetService(NS_GLOBALHISTORY_CONTRACTID));
|
||||
nsCOMPtr<nsIBrowserHistory> hist(do_GetService(kGlobalHistoryCID));
|
||||
|
||||
nsCOMPtr<nsIFile> temp;
|
||||
mOperaProfile->Clone(getter_AddRefs(temp));
|
||||
|
|
|
@ -115,35 +115,68 @@ nsPhoenixProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnic
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPhoenixProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsPhoenixProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
if (!mSourceProfile)
|
||||
GetSourceProfile(aProfile);
|
||||
|
||||
PRBool exists;
|
||||
const PRUnichar* fileNames[] = { FILE_NAME_PREFS.get(),
|
||||
FILE_NAME_COOKIES.get(),
|
||||
FILE_NAME_HISTORY.get(),
|
||||
FILE_NAME_BOOKMARKS.get(),
|
||||
FILE_NAME_DOWNLOADS.get(),
|
||||
FILE_NAME_MIMETYPES.get(),
|
||||
FILE_NAME_USERCHROME.get(),
|
||||
FILE_NAME_USERCONTENT.get() };
|
||||
const PRUint32 sourceFlags[] = { nsIBrowserProfileMigrator::SETTINGS,
|
||||
nsIBrowserProfileMigrator::COOKIES,
|
||||
nsIBrowserProfileMigrator::HISTORY,
|
||||
nsIBrowserProfileMigrator::BOOKMARKS,
|
||||
nsIBrowserProfileMigrator::OTHERDATA,
|
||||
nsIBrowserProfileMigrator::OTHERDATA,
|
||||
const MIGRATIONDATA data[] = { { ToNewUnicode(FILE_NAME_PREFS),
|
||||
nsIBrowserProfileMigrator::SETTINGS,
|
||||
nsIBrowserProfileMigrator::SETTINGS };
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_COOKIES),
|
||||
nsIBrowserProfileMigrator::COOKIES,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_HISTORY),
|
||||
nsIBrowserProfileMigrator::HISTORY,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_BOOKMARKS),
|
||||
nsIBrowserProfileMigrator::BOOKMARKS,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_DOWNLOADS),
|
||||
nsIBrowserProfileMigrator::OTHERDATA,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_MIMETYPES),
|
||||
nsIBrowserProfileMigrator::OTHERDATA,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_USERCHROME),
|
||||
nsIBrowserProfileMigrator::OTHERDATA,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_USERCONTENT),
|
||||
nsIBrowserProfileMigrator::OTHERDATA,
|
||||
PR_TRUE } };
|
||||
|
||||
nsCOMPtr<nsIFile> sourceFile;
|
||||
PRBool exists;
|
||||
for (PRInt32 i = 0; i < 8; ++i) {
|
||||
// Don't list items that can only be imported in replace-mode when
|
||||
// we aren't being run in replace-mode.
|
||||
if (!aReplace && data[i].replaceOnly)
|
||||
continue;
|
||||
|
||||
mSourceProfile->Clone(getter_AddRefs(sourceFile));
|
||||
sourceFile->Append(nsDependentString(fileNames[i]));
|
||||
sourceFile->Append(nsDependentString(data[i].fileName));
|
||||
sourceFile->Exists(&exists);
|
||||
if (exists)
|
||||
*aResult |= sourceFlags[i];
|
||||
*aResult |= data[i].sourceFlag;
|
||||
|
||||
nsCRT::free(data[i].fileName);
|
||||
}
|
||||
|
||||
// Now locate passwords
|
||||
nsXPIDLCString signonsFileName;
|
||||
GetSignonFileName(aReplace, getter_Copies(signonsFileName));
|
||||
|
||||
if (!signonsFileName.IsEmpty()) {
|
||||
nsAutoString fileName; fileName.AssignWithConversion(signonsFileName);
|
||||
nsCOMPtr<nsIFile> sourcePasswordsFile;
|
||||
mSourceProfile->Clone(getter_AddRefs(sourcePasswordsFile));
|
||||
sourcePasswordsFile->Append(fileName);
|
||||
|
||||
sourcePasswordsFile->Exists(&exists);
|
||||
if (exists)
|
||||
*aResult |= nsIBrowserProfileMigrator::PASSWORDS;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -101,7 +101,9 @@ nsSafariProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUnich
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSafariProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsSafariProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
*aResult = 0; // XXXben implement me
|
||||
return NS_OK;
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsSeamonkeyProfileMigrator.h"
|
||||
|
@ -110,31 +109,62 @@ nsSeamonkeyProfileMigrator::Migrate(PRUint32 aItems, PRBool aReplace, const PRUn
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSeamonkeyProfileMigrator::GetMigrateData(const PRUnichar* aProfile, PRUint32* aResult)
|
||||
nsSeamonkeyProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
|
||||
PRBool aReplace,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
if (!mSourceProfile)
|
||||
GetSourceProfile(aProfile);
|
||||
|
||||
PRBool exists;
|
||||
const PRUnichar* fileNames[] = { FILE_NAME_PREFS.get(),
|
||||
FILE_NAME_COOKIES.get(),
|
||||
FILE_NAME_HISTORY.get(),
|
||||
FILE_NAME_BOOKMARKS.get(),
|
||||
FILE_NAME_DOWNLOADS.get(),
|
||||
FILE_NAME_MIMETYPES.get() };
|
||||
const PRUint32 sourceFlags[] = { nsIBrowserProfileMigrator::SETTINGS,
|
||||
const MIGRATIONDATA data[] = { { ToNewUnicode(FILE_NAME_PREFS),
|
||||
nsIBrowserProfileMigrator::SETTINGS,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_COOKIES),
|
||||
nsIBrowserProfileMigrator::COOKIES,
|
||||
PR_FALSE },
|
||||
{ ToNewUnicode(FILE_NAME_HISTORY),
|
||||
nsIBrowserProfileMigrator::HISTORY,
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_BOOKMARKS),
|
||||
nsIBrowserProfileMigrator::BOOKMARKS,
|
||||
PR_FALSE },
|
||||
{ ToNewUnicode(FILE_NAME_DOWNLOADS),
|
||||
nsIBrowserProfileMigrator::OTHERDATA,
|
||||
nsIBrowserProfileMigrator::OTHERDATA };
|
||||
PR_TRUE },
|
||||
{ ToNewUnicode(FILE_NAME_MIMETYPES),
|
||||
nsIBrowserProfileMigrator::OTHERDATA,
|
||||
PR_TRUE } };
|
||||
|
||||
nsCOMPtr<nsIFile> sourceFile;
|
||||
PRBool exists;
|
||||
for (PRInt32 i = 0; i < 6; ++i) {
|
||||
// Don't list items that can only be imported in replace-mode when
|
||||
// we aren't being run in replace-mode.
|
||||
if (!aReplace && data[i].replaceOnly)
|
||||
continue;
|
||||
|
||||
mSourceProfile->Clone(getter_AddRefs(sourceFile));
|
||||
sourceFile->Append(nsDependentString(fileNames[i]));
|
||||
sourceFile->Append(nsDependentString(data[i].fileName));
|
||||
sourceFile->Exists(&exists);
|
||||
if (exists)
|
||||
*aResult |= sourceFlags[i];
|
||||
*aResult |= data[i].sourceFlag;
|
||||
|
||||
nsCRT::free(data[i].fileName);
|
||||
}
|
||||
|
||||
// Now locate passwords
|
||||
nsXPIDLCString signonsFileName;
|
||||
GetSignonFileName(aReplace, getter_Copies(signonsFileName));
|
||||
|
||||
if (!signonsFileName.IsEmpty()) {
|
||||
nsAutoString fileName; fileName.AssignWithConversion(signonsFileName);
|
||||
nsCOMPtr<nsIFile> sourcePasswordsFile;
|
||||
mSourceProfile->Clone(getter_AddRefs(sourcePasswordsFile));
|
||||
sourcePasswordsFile->Append(fileName);
|
||||
|
||||
sourcePasswordsFile->Exists(&exists);
|
||||
if (exists)
|
||||
*aResult |= nsIBrowserProfileMigrator::PASSWORDS;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -556,15 +586,11 @@ nsSeamonkeyProfileMigrator::CopyCookies(PRBool aReplace)
|
|||
if (aReplace)
|
||||
rv = CopyFile(FILE_NAME_COOKIES, FILE_NAME_COOKIES);
|
||||
else {
|
||||
nsCOMPtr<nsICookieManager2> cookieManager(do_GetService(NS_COOKIEMANAGER_CONTRACTID));
|
||||
if (!cookieManager)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsIFile> seamonkeyCookiesFile;
|
||||
mSourceProfile->Clone(getter_AddRefs(seamonkeyCookiesFile));
|
||||
seamonkeyCookiesFile->Append(FILE_NAME_COOKIES);
|
||||
|
||||
rv = cookieManager->ReadCookies(seamonkeyCookiesFile);
|
||||
rv = ImportNetscapeCookies(seamonkeyCookiesFile);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -581,22 +607,7 @@ nsSeamonkeyProfileMigrator::CopyPasswords(PRBool aReplace)
|
|||
nsresult rv;
|
||||
|
||||
nsXPIDLCString signonsFileName;
|
||||
if (aReplace) {
|
||||
// Find out what the signons file was called, this is stored in a pref
|
||||
// in Seamonkey.
|
||||
nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
psvc->ResetPrefs();
|
||||
|
||||
nsCOMPtr<nsIFile> seamonkeyPrefsFile;
|
||||
mSourceProfile->Clone(getter_AddRefs(seamonkeyPrefsFile));
|
||||
seamonkeyPrefsFile->Append(FILE_NAME_PREFS);
|
||||
psvc->ReadUserPrefs(seamonkeyPrefsFile);
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
|
||||
rv = branch->GetCharPref("signon.SignonFileName", getter_Copies(signonsFileName));
|
||||
}
|
||||
else
|
||||
LocateSignonsFile(getter_Copies(signonsFileName));
|
||||
GetSignonFileName(aReplace, getter_Copies(signonsFileName));
|
||||
|
||||
if (signonsFileName.IsEmpty())
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
@ -615,45 +626,6 @@ nsSeamonkeyProfileMigrator::CopyPasswords(PRBool aReplace)
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSeamonkeyProfileMigrator::LocateSignonsFile(char** aResult)
|
||||
{
|
||||
nsCOMPtr<nsISimpleEnumerator> entries;
|
||||
nsresult rv = mSourceProfile->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString fileName;
|
||||
do {
|
||||
PRBool hasMore = PR_FALSE;
|
||||
rv = entries->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv) || !hasMore) break;
|
||||
|
||||
nsCOMPtr<nsISupports> supp;
|
||||
rv = entries->GetNext(getter_AddRefs(supp));
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
nsCOMPtr<nsIFile> currFile(do_QueryInterface(supp));
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewFileURI(getter_AddRefs(uri), currFile);
|
||||
if (NS_FAILED(rv)) break;
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
||||
|
||||
nsCAutoString extn;
|
||||
url->GetFileExtension(extn);
|
||||
|
||||
if (extn.EqualsIgnoreCase("s")) {
|
||||
url->GetFileName(fileName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1);
|
||||
|
||||
*aResult = ToNewCString(fileName);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSeamonkeyProfileMigrator::CopyBookmarks(PRBool aReplace)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче