38 #include "nsAppDirectoryServiceDefs.h"
40 #include "nsDirectoryServiceDefs.h"
41 #include "nsDirectoryServiceUtils.h"
42 #include "nsDocShellCID.h"
43 #include "nsINavBookmarksService.h"
45 #include "nsIBrowserProfileMigrator.h"
46 #include "nsIBrowserHistory.h"
47 #include "nsICookieManager2.h"
48 #include "nsIGlobalHistory.h"
49 #include "nsIInputStream.h"
50 #include "nsILineInputStream.h"
51 #include "nsILocalFile.h"
52 #include "nsINIParser.h"
53 #include "nsIObserverService.h"
54 #include "nsIPermissionManager.h"
55 #include "nsIPrefLocalizedString.h"
56 #include "nsIPrefService.h"
57 #include "nsIProfileMigrator.h"
58 #include "nsIProperties.h"
59 #include "nsIRDFContainer.h"
60 #include "nsIRDFService.h"
61 #include "nsIServiceManager.h"
62 #include "nsIStringBundle.h"
63 #include "nsISupportsPrimitives.h"
64 #include "nsNetUtil.h"
66 #include "nsToolkitCompsCID.h"
71 #define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
74 #define OPERA_PREFERENCES_FOLDER_NAME NS_LITERAL_STRING("Opera")
75 #define OPERA_PREFERENCES_FILE_NAME NS_LITERAL_STRING("opera6.ini")
76 #define OPERA_HISTORY_FILE_NAME NS_LITERAL_STRING("global.dat")
77 #define OPERA_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("opera6.adr")
78 #elif defined(XP_MACOSX)
79 #define OPERA_PREFERENCES_FOLDER_NAME NS_LITERAL_STRING("Opera 6 Preferences")
80 #define OPERA_PREFERENCES_FILE_NAME NS_LITERAL_STRING("Opera 6 Preferences")
81 #define OPERA_HISTORY_FILE_NAME NS_LITERAL_STRING("Opera Global History")
82 #define OPERA_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("Bookmarks")
83 #elif defined (XP_UNIX)
84 #define OPERA_PREFERENCES_FOLDER_NAME NS_LITERAL_STRING(".opera")
85 #define OPERA_PREFERENCES_FILE_NAME NS_LITERAL_STRING("opera6.ini")
86 #define OPERA_HISTORY_FILE_NAME NS_LITERAL_STRING("global.dat")
87 #define OPERA_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("opera6.adr")
88 #elif defined (XP_BEOS)
89 #define OPERA_PREFERENCES_FOLDER_NAME NS_LITERAL_STRING("Opera")
90 #define OPERA_PREFERENCES_FILE_NAME NS_LITERAL_STRING("opera.ini")
91 #define OPERA_HISTORY_FILE_NAME NS_LITERAL_STRING("global.dat")
92 #define OPERA_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("opera.adr")
94 #error Need to define location of Opera Profile data.
97 #define OPERA_COOKIES_FILE_NAME NS_LITERAL_STRING("cookies4.dat")
99 #define OPERA_COOKIES_FILE_NAME NS_LITERAL_STRING("cookies.dat")
109 mObserverService = do_GetService(
"@mozilla.org/observer-service;1");
117 nsOperaProfileMigrator::Migrate(PRUint16 aItems, nsIProfileStartup* aStartup,
const PRUnichar* aProfile)
120 PRBool aReplace = aStartup ? PR_TRUE : PR_FALSE;
123 rv = aStartup->DoStartup();
124 NS_ENSURE_SUCCESS(rv, rv);
143 nsOperaProfileMigrator::GetMigrateData(
const PRUnichar* aProfile,
148 if (!mOperaProfile) {
151 return NS_ERROR_FILE_NOT_FOUND;
160 { ToNewUnicode(OPERA_HISTORY_FILE_NAME),
163 { ToNewUnicode(OPERA_BOOKMARKS_FILE_NAME),
169 aReplace, mOperaProfile, aResult);
175 nsOperaProfileMigrator::GetSourceExists(PRBool* aResult)
177 nsCOMPtr<nsISupportsArray> profiles;
178 GetSourceProfiles(getter_AddRefs(profiles));
182 profiles->Count(&count);
183 *aResult = count > 0;
192 nsOperaProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
194 nsCOMPtr<nsISupportsArray> profiles;
195 GetSourceProfiles(getter_AddRefs(profiles));
200 profiles->Count(&count);
201 *aResult = count > 1;
211 nsOperaProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
216 mProfiles = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
217 if (NS_FAILED(rv))
return rv;
219 nsCOMPtr<nsIProperties> fileLocator(do_GetService(
"@mozilla.org/file/directory_service;1"));
220 nsCOMPtr<nsILocalFile>
file;
222 fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
225 file->Append(OPERA_PREFERENCES_FOLDER_NAME);
227 nsCOMPtr<nsISimpleEnumerator> e;
228 rv = file->GetDirectoryEntries(getter_AddRefs(e));
233 e->HasMoreElements(&hasMore);
235 nsCOMPtr<nsILocalFile> curr;
236 e->GetNext(getter_AddRefs(curr));
238 PRBool isDirectory = PR_FALSE;
239 curr->IsDirectory(&isDirectory);
241 nsCOMPtr<nsISupportsString>
string(do_CreateInstance(
"@mozilla.org/supports-string;1"));
242 nsAutoString leafName;
243 curr->GetLeafName(leafName);
244 string->SetData(leafName);
245 mProfiles->AppendElement(
string);
248 e->HasMoreElements(&hasMore);
250 #elif defined (XP_MACOSX)
251 fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
253 file->Append(NS_LITERAL_STRING(
"Preferences"));
254 file->Append(OPERA_PREFERENCES_FOLDER_NAME);
257 file->Exists(&exists);
260 nsCOMPtr<nsISupportsString>
string(do_CreateInstance(
"@mozilla.org/supports-string;1"));
261 string->SetData(OPERA_PREFERENCES_FOLDER_NAME);
262 mProfiles->AppendElement(
string);
264 #elif defined (XP_UNIX)
265 fileLocator->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
267 file->Append(OPERA_PREFERENCES_FOLDER_NAME);
270 file->Exists(&exists);
273 nsCOMPtr<nsISupportsString>
string(do_CreateInstance(
"@mozilla.org/supports-string;1"));
274 string->SetData(OPERA_PREFERENCES_FOLDER_NAME);
275 mProfiles->AppendElement(
string);
280 *aResult = mProfiles;
281 NS_IF_ADDREF(*aResult);
286 nsOperaProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
291 nsCOMPtr<nsIFile> operaPrefs;
292 mOperaProfile->Clone(getter_AddRefs(operaPrefs));
293 operaPrefs->Append(OPERA_PREFERENCES_FILE_NAME);
295 nsCOMPtr<nsILocalFile> lf(do_QueryInterface(operaPrefs));
296 NS_ENSURE_TRUE(lf, NS_ERROR_UNEXPECTED);
299 rv = parser.Init(lf);
300 NS_ENSURE_SUCCESS(rv, rv);
302 rv = parser.GetString(
"User Prefs",
306 if (NS_SUCCEEDED(rv))
313 #define _OPM(type) nsOperaProfileMigrator::type
317 {
"User Prefs",
"Download Directory",
_OPM(
STRING),
"browser.download.dir",
_OPM(SetFile), PR_FALSE, { -1 } },
318 { nsnull,
"Enable Cookies",
_OPM(INT),
"network.cookie.cookieBehavior",
_OPM(SetCookieBehavior), PR_FALSE, { -1 } },
319 { nsnull,
"Accept Cookies Session Only",
_OPM(BOOL),
"network.cookie.lifetimePolicy",
_OPM(SetCookieLifetime), PR_FALSE, { -1 } },
320 { nsnull,
"Allow script to resize window",
_OPM(BOOL),
"dom.disable_window_move_resize",
_OPM(SetBool), PR_FALSE, { -1 } },
321 { nsnull,
"Allow script to move window",
_OPM(BOOL),
"dom.disable_window_move_resize",
_OPM(SetBool), PR_FALSE, { -1 } },
322 { nsnull,
"Allow script to raise window",
_OPM(BOOL),
"dom.disable_window_flip",
_OPM(SetBool), PR_FALSE, { -1 } },
323 { nsnull,
"Allow script to change status",
_OPM(BOOL),
"dom.disable_window_status_change",
_OPM(SetBool), PR_FALSE, { -1 } },
324 { nsnull,
"Ignore Unrequested Popups",
_OPM(BOOL),
"dom.disable_open_during_load",
_OPM(SetBool), PR_FALSE, { -1 } },
325 { nsnull,
"Load Figures",
_OPM(BOOL),
"permissions.default.image",
_OPM(SetImageBehavior), PR_FALSE, { -1 } },
327 {
"Visited link", nsnull,
_OPM(COLOR),
"browser.visited_color",
_OPM(SetString), PR_FALSE, { -1 } },
328 {
"Link", nsnull,
_OPM(COLOR),
"browser.anchor_color",
_OPM(SetString), PR_FALSE, { -1 } },
329 { nsnull,
"Underline",
_OPM(BOOL),
"browser.underline_anchors",
_OPM(SetBool), PR_FALSE, { -1 } },
330 { nsnull,
"Expiry",
_OPM(INT),
"browser.history_expire_days",
_OPM(SetInt), PR_FALSE, { -1 } },
332 {
"Security Prefs",
"Enable SSL v2",
_OPM(BOOL),
"security.enable_ssl2",
_OPM(SetBool), PR_FALSE, { -1 } },
333 { nsnull,
"Enable SSL v3",
_OPM(BOOL),
"security.enable_ssl3",
_OPM(SetBool), PR_FALSE, { -1 } },
334 { nsnull,
"Enable TLS v1.0",
_OPM(BOOL),
"security.enable_tls",
_OPM(SetBool), PR_FALSE, { -1 } },
336 {
"Extensions",
"Scripting",
_OPM(BOOL),
"javascript.enabled",
_OPM(SetBool), PR_FALSE, { -1 } }
343 nsCOMPtr<nsILocalFile> lf(do_CreateInstance(
"@mozilla.org/file/local;1"));
344 lf->InitWithPath(NS_ConvertUTF8toUTF16(xform->
stringValue));
345 return aBranch->SetComplexValue(xform->
targetPrefName, NS_GET_IID(nsILocalFile), lf);
381 nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance(
"@mozilla.org/pref-localizedstring;1"));
383 pls->SetData(data.get());
406 nsCOMPtr<nsIFile> operaPrefs;
407 mOperaProfile->Clone(getter_AddRefs(operaPrefs));
408 operaPrefs->Append(OPERA_PREFERENCES_FILE_NAME);
410 nsCOMPtr<nsILocalFile> lf(do_QueryInterface(operaPrefs));
411 NS_ENSURE_TRUE(lf, NS_ERROR_UNEXPECTED);
414 rv = parser.Init(lf);
415 NS_ENSURE_SUCCESS(rv, rv);
423 const char* lastSectionName = nsnull;
424 for (transform = gTransforms; transform < end; ++transform) {
429 char* colorString = nsnull;
430 nsresult rv =
ParseColor(parser, lastSectionName, &colorString);
431 if (NS_SUCCEEDED(rv)) {
442 rv = parser.GetString(lastSectionName,
445 if (NS_SUCCEEDED(rv)) {
447 switch (transform->
type) {
452 transform->
intValue = val.ToInteger(&strerr);
456 transform->
boolValue = val.ToInteger(&strerr) != 0;
488 PRInt32 networkProxyType = 0;
490 const char* protocols[4] = {
"HTTP",
"HTTPS",
"FTP",
"GOPHER" };
491 const char* protocols_l[4] = {
"http",
"https",
"ftp",
"gopher" };
492 char toggleBuf[15], serverBuf[20], serverPrefBuf[20],
493 serverPortPrefBuf[25];
495 for (PRUint32
i = 0;
i < 4; ++
i) {
496 sprintf(toggleBuf,
"Use %s", protocols[
i]);
497 GetInteger(aParser,
"Proxy", toggleBuf, &enabled);
501 networkProxyType = 1;
504 sprintf(serverBuf,
"%s Server", protocols[i]);
505 nsCAutoString proxyServer;
506 rv = aParser.GetString(
"Proxy", serverBuf, proxyServer);
510 sprintf(serverPrefBuf,
"network.proxy.%s", protocols_l[i]);
511 sprintf(serverPortPrefBuf,
"network.proxy.%s_port", protocols_l[i]);
514 serverPrefBuf, serverPortPrefBuf, aBranch);
517 GetInteger(aParser,
"Proxy",
"Use Automatic Proxy Configuration", &enabled);
519 networkProxyType = 2;
521 nsCAutoString configURL;
522 rv = aParser.GetString(
"Proxy",
"Automatic Proxy Configuration URL",
524 if (NS_SUCCEEDED(rv))
525 aBranch->SetCharPref(
"network.proxy.autoconfig_url", configURL.get());
527 GetInteger(aParser,
"Proxy",
"No Proxy Servers Check", &enabled);
529 nsCAutoString servers;
530 rv = aParser.GetString(
"Proxy",
"No Proxy Servers", servers);
531 if (NS_SUCCEEDED(rv))
536 aBranch->SetIntPref(
"network.proxy.type", networkProxyType);
543 const char* aSectionName,
544 const char* aKeyName,
549 nsresult rv = aParser.GetString(aSectionName, aKeyName, val);
553 *aResult = val.ToInteger(&rv);
561 const char* aSectionName,
char** aResult)
566 rv =
GetInteger(aParser, aSectionName,
"Red", &r);
567 rv |=
GetInteger(aParser, aSectionName,
"Green", &g);
568 rv |=
GetInteger(aParser, aSectionName,
"Blue", &b);
572 *aResult = (
char*)malloc(
sizeof(
char) * 8);
574 return NS_ERROR_OUT_OF_MEMORY;
576 sprintf(*aResult,
"#%02X%02X%02X", r, g, b);
586 nsCAutoString userContentCSS;
587 rv = aParser.GetString(
"User Prefs",
"Local CSS File", userContentCSS);
588 if (NS_FAILED(rv) || userContentCSS.Length() == 0)
592 nsCOMPtr<nsILocalFile> userContentCSSFile;
593 rv = NS_NewNativeLocalFile(userContentCSS, PR_TRUE,
594 getter_AddRefs(userContentCSSFile));
599 rv = userContentCSSFile->Exists(&exists);
600 if (NS_FAILED(rv) || !exists)
603 nsCOMPtr<nsIFile> profileChromeDir;
604 NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR,
605 getter_AddRefs(profileChromeDir));
606 if (!profileChromeDir)
609 userContentCSSFile->CopyToNative(profileChromeDir,
610 NS_LITERAL_CSTRING(
"userContent.css"));
620 nsCOMPtr<nsIFile> temp;
621 mOperaProfile->Clone(getter_AddRefs(temp));
622 nsCOMPtr<nsILocalFile> historyFile(do_QueryInterface(temp));
626 nsCOMPtr<nsIInputStream> fileStream;
627 NS_NewLocalFileInputStream(getter_AddRefs(fileStream), historyFile);
629 return NS_ERROR_OUT_OF_MEMORY;
633 return NS_ERROR_OUT_OF_MEMORY;
646 mAppVersion(0), mFileVersion(0), mTagTypeLength(0), mPayloadTypeLength(0),
647 mCookieOpen(PR_FALSE), mCurrHandlingInfo(0)
649 mStream = do_CreateInstance(
"@mozilla.org/binaryinputstream;1");
651 mStream->SetInputStream(aSourceStream);
653 mCurrCookie.isSecure = PR_FALSE;
654 mCurrCookie.expiryTime = 0;
660 mStream->SetInputStream(nsnull);
668 return NS_ERROR_FAILURE;
676 nsCOMPtr<nsICookieManager2> manager(do_GetService(NS_COOKIEMANAGER_CONTRACTID));
677 nsCOMPtr<nsIPermissionManager> permissionManager(do_GetService(
"@mozilla.org/permissionmanager;1"));
680 PRUint16 length, segmentLength;
684 if (NS_FAILED(mStream->Read8(&tag)))
689 mStream->Read16(&length);
693 mStream->Read16(&length);
695 mStream->ReadBytes(length, &buf);
696 buf = (
char*)nsMemory::Realloc(buf, length+1);
698 mDomainStack.AppendElement(buf);
703 if (mCurrHandlingInfo)
707 PRUint32
count = mDomainStack.Length();
709 char* segment = mDomainStack.ElementAt(count - 1);
711 nsMemory::Free(segment);
712 mDomainStack.RemoveElementAt(count - 1);
718 mStream->Read16(&length);
722 mStream->Read16(&length);
724 mStream->ReadBytes(length, &buf);
725 buf = (
char*)nsMemory::Realloc(buf, length+1);
727 mPathStack.AppendElement(buf);
740 PRUint32
count = mPathStack.Length();
742 char* segment = mPathStack.ElementAt(count - 1);
744 nsMemory::Free(segment);
745 mPathStack.RemoveElementAt(count - 1);
751 mStream->Read16(&length);
752 mStream->Read8(&mCurrHandlingInfo);
757 mStream->Read16(&length);
759 mStream->Read8(&temp);
770 mStream->Read16(&segmentLength);
771 mCookieOpen = PR_TRUE;
776 mStream->Read16(&length);
777 mStream->ReadBytes(length, &buf);
778 buf = (
char*)nsMemory::Realloc(buf, length+1);
780 mCurrCookie.id.Assign(buf);
789 mStream->Read16(&length);
790 mStream->ReadBytes(length, &buf);
791 buf = (
char*)nsMemory::Realloc(buf, length+1);
793 mCurrCookie.data.Assign(buf);
801 mStream->Read16(&length);
802 mStream->Read32(reinterpret_cast<PRUint32*>(&(mCurrCookie.expiryTime)));
805 mCurrCookie.isSecure = PR_TRUE;
812 mStream->Read16(&length);
814 mStream->Read32(reinterpret_cast<PRUint32*>(&temp));
823 mStream->Read16(&length);
824 mStream->ReadBytes(length, &buf);
833 mStream->Read16(&length);
835 mStream->Read8(&temp);
850 char* segment = nsnull;
852 PRUint32
count = mPathStack.Length();
853 for (i = 0; i <
count; ++
i) {
854 segment = mPathStack.ElementAt(i);
856 nsMemory::Free(segment);
860 count = mDomainStack.Length();
861 for (i = 0; i <
count; ++
i) {
862 segment = mDomainStack.ElementAt(i);
864 nsMemory::Free(segment);
879 nsCOMPtr<nsIURI>
uri(do_CreateInstance(
"@mozilla.org/network/standard-url;1"));
881 return NS_ERROR_OUT_OF_MEMORY;
882 uri->SetHost(domain);
884 rv = aManager->Add(uri,
"cookie",
885 (mCurrHandlingInfo == 1 || mCurrHandlingInfo == 3)
886 ? (PRUint32) nsIPermissionManager::ALLOW_ACTION
887 : (PRUint32) nsIPermissionManager::DENY_ACTION);
889 mCurrHandlingInfo = 0;
906 mCookieOpen = PR_FALSE;
908 nsresult rv = aManager->Add(domain,
912 mCurrCookie.isSecure,
915 PRInt64(mCurrCookie.expiryTime));
917 mCurrCookie.isSecure = 0;
918 mCurrCookie.expiryTime = 0;
926 PRUint32
count = mPathStack.Length();
927 nsCAutoString synthesizedPath(
"/");
928 for (PRUint32
i = 0;
i <
count; ++
i) {
929 synthesizedPath.Append(mPathStack.ElementAt(
i));
931 synthesizedPath.Append(
"/");
933 if (synthesizedPath.IsEmpty())
934 synthesizedPath.Assign(
"/");
936 *aResult = ToNewCString(synthesizedPath);
942 PRUint32
count = mDomainStack.Length();
946 nsCAutoString synthesizedDomain;
947 for (PRInt32
i = (PRInt32)count - 1;
i >= 0; --
i) {
948 synthesizedDomain.Append(mDomainStack.ElementAt((PRUint32)
i));
950 synthesizedDomain.Append(
".");
953 *aResult = ToNewCString(synthesizedDomain);
959 mStream->Read32(&mAppVersion);
960 mStream->Read32(&mFileVersion);
962 if (mAppVersion & 0x1000 && mFileVersion & 0x2000) {
963 mStream->Read16(&mTagTypeLength);
964 mStream->Read16(&mPayloadTypeLength);
968 return NS_ERROR_FAILURE;
972 nsOperaProfileMigrator::RunBatched(
nsISupports* aUserData)
975 nsCOMPtr<nsISupportsPRUint8> strWrapper(do_QueryInterface(aUserData));
976 NS_ASSERTION(strWrapper,
"Unable to create nsISupportsPRUint8 wrapper!");
977 nsresult rv = strWrapper->GetData(&batchAction);
978 NS_ENSURE_SUCCESS(rv, rv);
980 switch (batchAction) {
994 NS_ENSURE_SUCCESS(rv, rv);
1003 nsCOMPtr<nsINavHistoryService>
history =
1004 do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID, &rv);
1005 NS_ENSURE_SUCCESS(rv, rv);
1009 nsCOMPtr<nsISupportsPRUint8> supports =
1010 do_CreateInstance(NS_SUPPORTS_PRUINT8_CONTRACTID);
1011 NS_ENSURE_TRUE(supports, NS_ERROR_OUT_OF_MEMORY);
1012 rv = supports->SetData(batchAction);
1013 NS_ENSURE_SUCCESS(rv, rv);
1015 rv = history->RunInBatchMode(
this, supports);
1016 NS_ENSURE_SUCCESS(rv, rv);
1024 nsCOMPtr<nsIBrowserHistory> hist(do_GetService(NS_GLOBALHISTORY2_CONTRACTID));
1026 nsCOMPtr<nsIFile> temp;
1027 mOperaProfile->Clone(getter_AddRefs(temp));
1028 nsCOMPtr<nsILocalFile> historyFile(do_QueryInterface(temp));
1029 historyFile->Append(OPERA_HISTORY_FILE_NAME);
1031 nsCOMPtr<nsIInputStream> fileStream;
1032 NS_NewLocalFileInputStream(getter_AddRefs(fileStream), historyFile);
1033 if (!fileStream)
return NS_ERROR_OUT_OF_MEMORY;
1035 nsCOMPtr<nsILineInputStream> lineStream = do_QueryInterface(fileStream);
1037 nsCAutoString buffer,
url;
1039 PRTime lastVisitDate;
1040 PRBool moreData = PR_FALSE;
1042 enum { TITLE, URL, LASTVISIT } state = TITLE;
1046 nsresult rv = lineStream->ReadLine(buffer, &moreData);
1052 CopyUTF8toUTF16(buffer, title);
1062 lastVisitDate = buffer.ToInteger(&err);
1064 PRInt64 temp, million;
1065 LL_I2L(temp, lastVisitDate);
1066 LL_I2L(million, PR_USEC_PER_SEC);
1067 LL_MUL(lastVisitDate, temp, million);
1069 nsCOMPtr<nsIURI>
uri;
1070 NS_NewURI(getter_AddRefs(uri), url);
1072 hist->AddPageWithDetails(uri, title.get(), lastVisitDate);
1087 nsCOMPtr<nsINavBookmarksService> bookmarks =
1088 do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID, &rv);
1089 NS_ENSURE_SUCCESS(rv, rv);
1093 nsCOMPtr<nsISupportsPRUint8> supports =
1094 do_CreateInstance(NS_SUPPORTS_PRUINT8_CONTRACTID);
1095 NS_ENSURE_TRUE(supports, NS_ERROR_OUT_OF_MEMORY);
1096 rv = supports->SetData(batchAction);
1097 NS_ENSURE_SUCCESS(rv, rv);
1099 rv = bookmarks->RunInBatchMode(
this, supports);
1100 NS_ENSURE_SUCCESS(rv, rv);
1109 nsCOMPtr<nsIFile> operaBookmarks;
1110 mOperaProfile->Clone(getter_AddRefs(operaBookmarks));
1111 operaBookmarks->Append(OPERA_BOOKMARKS_FILE_NAME);
1113 nsCOMPtr<nsIInputStream> fileInputStream;
1114 NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), operaBookmarks);
1115 NS_ENSURE_TRUE(fileInputStream, NS_ERROR_OUT_OF_MEMORY);
1117 nsCOMPtr<nsILineInputStream> lineInputStream(do_QueryInterface(fileInputStream));
1120 nsCOMPtr<nsINavBookmarksService> bms =
1121 do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID, &rv);
1122 NS_ENSURE_SUCCESS(rv, rv);
1123 PRInt64 bookmarksMenuFolderId;
1124 rv = bms->GetBookmarksMenuFolder(&bookmarksMenuFolderId);
1125 NS_ENSURE_SUCCESS(rv, rv);
1126 PRInt64 parentFolder = bookmarksMenuFolderId;
1128 nsCOMPtr<nsIStringBundleService> bundleService =
1129 do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
1130 NS_ENSURE_SUCCESS(rv, rv);
1131 nsCOMPtr<nsIStringBundle>
bundle;
1132 rv = bundleService->CreateBundle(
MIGRATION_BUNDLE, getter_AddRefs(bundle));
1133 NS_ENSURE_SUCCESS(rv, rv);
1136 nsString sourceNameOpera;
1137 rv = bundle->GetStringFromName(NS_LITERAL_STRING(
"sourceNameOpera").
get(),
1138 getter_Copies(sourceNameOpera));
1139 NS_ENSURE_SUCCESS(rv, rv);
1141 const PRUnichar* sourceNameStrings[] = { sourceNameOpera.get() };
1142 nsString importedOperaHotlistTitle;
1143 rv = bundle->FormatStringFromName(NS_LITERAL_STRING(
"importedBookmarksFolder").
get(),
1144 sourceNameStrings, 1,
1145 getter_Copies(importedOperaHotlistTitle));
1146 NS_ENSURE_SUCCESS(rv, rv);
1148 rv = bms->CreateFolder(parentFolder,
1149 NS_ConvertUTF16toUTF8(importedOperaHotlistTitle),
1150 nsINavBookmarksService::DEFAULT_INDEX,
1152 NS_ENSURE_SUCCESS(rv, rv);
1155 nsCOMPtr<nsIFile> profile;
1158 NS_ENSURE_SUCCESS(rv, rv);
1161 #if defined(XP_WIN) || (defined(XP_UNIX) && !defined(XP_MACOSX))
1162 CopySmartKeywords(bms, bundle, parentFolder);
1165 PRInt64 bookmarksToolbarFolderId;
1166 rv = bms->GetToolbarFolder(&bookmarksToolbarFolderId);
1167 NS_ENSURE_SUCCESS(rv, rv);
1170 bookmarksToolbarFolderId, bms);
1171 NS_ENSURE_SUCCESS(rv, rv);
1176 #if defined(XP_WIN) || (defined(XP_UNIX) && !defined(XP_MACOSX))
1178 nsOperaProfileMigrator::CopySmartKeywords(nsINavBookmarksService* aBMS,
1179 nsIStringBundle* aBundle,
1180 PRInt64 aParentFolder)
1184 nsCOMPtr<nsIFile> smartKeywords;
1185 mOperaProfile->Clone(getter_AddRefs(smartKeywords));
1186 smartKeywords->Append(NS_LITERAL_STRING(
"search.ini"));
1188 nsCOMPtr<nsILocalFile> lf(do_QueryInterface(smartKeywords));
1190 if (!lf || NS_FAILED(parser.Init(lf)))
1193 nsString sourceNameOpera;
1194 rv = aBundle->GetStringFromName(NS_LITERAL_STRING(
"sourceNameOpera").
get(),
1195 getter_Copies(sourceNameOpera));
1196 NS_ENSURE_SUCCESS(rv, rv);
1198 const PRUnichar* sourceNameStrings[] = { sourceNameOpera.get() };
1199 nsString importedSearchUrlsTitle;
1200 rv = aBundle->FormatStringFromName(NS_LITERAL_STRING(
"importedSearchURLsFolder").
get(),
1201 sourceNameStrings, 1,
1202 getter_Copies(importedSearchUrlsTitle));
1203 NS_ENSURE_SUCCESS(rv, rv);
1205 PRInt64 keywordsFolder;
1206 rv = aBMS->CreateFolder(aParentFolder,
1207 NS_ConvertUTF16toUTF8(importedSearchUrlsTitle),
1208 nsINavBookmarksService::DEFAULT_INDEX,
1210 NS_ENSURE_SUCCESS(rv, rv);
1212 PRInt32 sectionIndex = 1;
1213 nsCAutoString
name,
url, keyword;
1215 nsCAutoString section(
"Search Engine ");
1216 section.AppendInt(sectionIndex++);
1218 rv = parser.GetString(section.get(),
"Name",
name);
1219 if (NS_FAILED(rv)) {
1226 rv = parser.GetString(section.get(),
"URL",
url);
1227 if (NS_FAILED(rv) || url.IsEmpty())
1230 rv = parser.GetString(section.get(),
"Key", keyword);
1231 if (NS_FAILED(rv) || keyword.IsEmpty())
1235 rv =
GetInteger(parser, section.get(),
"Is post", &post);
1236 if (NS_SUCCEEDED(rv) && post)
1239 PRUint32 length = name.Length();
1242 index = name.FindChar(
'&', index);
1243 if ((PRUint32)index >= length - 2)
1247 if (name.CharAt(index + 1) ==
'&') {
1255 while ((PRUint32)index < length);
1257 nsCOMPtr<nsIURI>
uri;
1258 if (NS_FAILED(NS_NewURI(getter_AddRefs(uri), url.get())) || !
uri)
1261 nsCAutoString hostCStr;
1262 uri->GetHost(hostCStr);
1263 NS_ConvertASCIItoUTF16 host(hostCStr);
1265 const PRUnichar* descStrings[] = { NS_ConvertUTF8toUTF16(keyword).get(),
1267 nsString keywordDesc;
1268 rv = aBundle->FormatStringFromName(NS_LITERAL_STRING(
"importedSearchUrlDesc").
get(),
1270 getter_Copies(keywordDesc));
1271 NS_ENSURE_SUCCESS(rv, rv);
1274 rv = aBMS->InsertBookmark(keywordsFolder, uri,
1275 nsINavBookmarksService::DEFAULT_INDEX,
1277 NS_ENSURE_SUCCESS(rv, rv);
1278 rv = aBMS->SetKeywordForBookmark(newId, NS_ConvertUTF8toUTF16(keyword));
1279 NS_ENSURE_SUCCESS(rv, rv);
1301 if (Substring(aBuffer, 0, 7).Equals(NS_LITERAL_STRING(
"#FOLDER")))
1303 if (Substring(aBuffer, 0, 4).Equals(NS_LITERAL_STRING(
"#URL")))
1305 if (Substring(aBuffer, 0, 1).Equals(NS_LITERAL_STRING(
"-")))
1307 if (Substring(aBuffer, 1, 5).Equals(NS_LITERAL_STRING(
"NAME="))) {
1308 const nsAString& data = Substring(aBuffer, 6, aBuffer.Length() - 6);
1309 *aData = ToNewUnicode(data);
1312 if (Substring(aBuffer, 1, 4).Equals(NS_LITERAL_STRING(
"URL="))) {
1313 const nsAString& data = Substring(aBuffer, 5, aBuffer.Length() - 5);
1314 *aData = ToNewUnicode(data);
1317 if (Substring(aBuffer, 1, 12).Equals(NS_LITERAL_STRING(
"DESCRIPTION="))) {
1318 const nsAString& data = Substring(aBuffer, 13, aBuffer.Length() - 13);
1319 *aData = ToNewUnicode(data);
1322 if (Substring(aBuffer, 1, 11).Equals(NS_LITERAL_STRING(
"SHORT NAME="))) {
1323 const nsAString& data = Substring(aBuffer, 12, aBuffer.Length() - 12);
1324 *aData = ToNewUnicode(data);
1327 if (Substring(aBuffer, 1, 15).Equals(NS_LITERAL_STRING(
"ON PERSONALBAR="))) {
1328 const nsAString& data = Substring(aBuffer, 16, aBuffer.Length() - 16);
1329 *aData = ToNewUnicode(data);
1332 if (aBuffer.IsEmpty())
1343 nsINavBookmarksService* aBMS)
1346 PRBool moreData = PR_FALSE;
1347 nsAutoString buffer;
1349 nsAutoString keyword, description;
1351 PRBool onToolbar = PR_FALSE;
1353 nsCAutoString cBuffer;
1354 rv = aStream->ReadLine(cBuffer, &moreData);
1355 if (NS_FAILED(rv))
return rv;
1357 CopyUTF8toUTF16(cBuffer, buffer);
1374 name.Assign(NS_ConvertUTF16toUTF8(data));
1377 url.Assign(NS_ConvertUTF16toUTF8(data));
1386 if (NS_LITERAL_STRING(
"YES").Equals(data))
1387 onToolbar = PR_TRUE;
1396 if (!name.IsEmpty() && !url.IsEmpty()) {
1397 nsCOMPtr<nsIURI>
uri;
1398 rv = NS_NewURI(getter_AddRefs(uri), url);
1402 rv = aBMS->InsertBookmark(onToolbar ? aToolbar : aParent,
1403 uri, nsINavBookmarksService::DEFAULT_INDEX,
1410 description.Truncate();
1411 onToolbar = PR_FALSE;
1415 if (!name.IsEmpty()) {
1417 rv = aBMS->CreateFolder(onToolbar ? aToolbar : aParent,
1418 name, nsINavBookmarksService::DEFAULT_INDEX, &newFolder);
1440 nsCOMPtr<nsIProperties> fileLocator(do_GetService(
"@mozilla.org/file/directory_service;1"));
1441 nsCOMPtr<nsILocalFile>
file;
1443 fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
1446 file->Append(OPERA_PREFERENCES_FOLDER_NAME);
1447 file->Append(nsDependentString(aProfile));
1448 file->Append(NS_LITERAL_STRING(
"profile"));
1449 #elif defined (XP_MACOSX)
1450 fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
1452 file->Append(NS_LITERAL_STRING(
"Preferences"));
1453 file->Append(OPERA_PREFERENCES_FOLDER_NAME);
1454 #elif defined (XP_UNIX)
1455 fileLocator->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(file));
1457 file->Append(OPERA_PREFERENCES_FOLDER_NAME);
nsresult InitializeBookmarks(nsIFile *aTargetProfile)
static nsresult SetCookieLifetime(void *aTransform, nsIPrefBranch *aBranch)
static nsOperaProfileMigrator::PrefTransform gTransforms[]
nsresult CopyCookies(PRBool aReplace)
static nsresult SetWString(void *aTransform, nsIPrefBranch *aBranch)
const unsigned short HISTORY
void ParseOverrideServers(const nsAString &aServers, nsIPrefBranch *aBranch)
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
nsresult CopyUserContentSheet(nsINIParser &aParser)
#define BATCH_ACTION_BOOKMARKS
const NS_PREFSERVICE_CONTRACTID
const nsIPrefLocalizedString
nsresult CopyPreferences(PRBool aReplace)
void SynthesizePath(char **aResult)
const unsigned short SETTINGS
static nsresult SetCookieBehavior(void *aTransform, nsIPrefBranch *aBranch)
nsresult CopyBookmarks(PRBool aReplace)
nsresult CopyHistory(PRBool aReplace)
#define BATCH_ACTION_HISTORY_REPLACE
static nsresult SetInt(void *aTransform, nsIPrefBranch *aBranch)
#define NOTIFY_OBSERVERS(message, item)
nsresult ParseBookmarksFolder(nsILineInputStream *aStream, PRInt64 aFolder, PRInt64 aToolbar, nsINavBookmarksService *aBMS)
static LineType GetLineType(nsAString &aBuffer, PRUnichar **aData)
nsresult AddCookie(nsICookieManager2 *aManager)
static nsresult SetString(void *aTransform, nsIPrefBranch *aBranch)
#define MIGRATION_STARTED
void GetOperaProfile(const PRUnichar *aProfile, nsILocalFile **aFile)
#define COPY_DATA(func, replace, itemIndex)
this _dialogInput val(dateText)
virtual ~nsOperaProfileMigrator()
nsresult ParseColor(nsINIParser &aParser, const char *aSectionName, char **aResult)
const unsigned short COOKIES
void SynthesizeDomain(char **aResult)
const nsIPermissionManager
static nsresult SetFile(void *aTransform, nsIPrefBranch *aBranch)
StringArrayEnumerator prototype hasMore
static nsresult SetImageBehavior(void *aTransform, nsIPrefBranch *aBranch)
#define OPERA_COOKIES_FILE_NAME
const unsigned short BOOKMARKS
virtual ~nsOperaCookieMigrator()
nsresult AddCookieOverride(nsIPermissionManager *aManager)
void GetProfilePath(nsIProfileStartup *aStartup, nsCOMPtr< nsIFile > &aProfileDir)
#define BATCH_ACTION_HISTORY
nsresult GetInteger(nsINIParser &aParser, const char *aSectionName, const char *aKeyName, PRInt32 *aResult)
void SetProxyPref(const nsAString &aHostPort, const char *aPref, const char *aPortPref, nsIPrefBranch *aPrefs)
dataSBGenres SBProperties tag
#define BATCH_ACTION_BOOKMARKS_REPLACE
nsresult CopyHistoryBatched(PRBool aReplace)
nsresult CopyProxySettings(nsINIParser &aParser, nsIPrefBranch *aBranch)
static nsresult SetBool(void *aTransform, nsIPrefBranch *aBranch)
nsresult CopyBookmarksBatched(PRBool aReplace)
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
void GetMigrateDataFromArray(MigrationData *aDataArray, PRInt32 aDataArrayLength, PRBool aReplace, nsIFile *aSourceProfile, PRUint16 *aResult)