39 #include "nsAppDirectoryServiceDefs.h"
41 #include "nsDirectoryServiceDefs.h"
42 #include "nsDirectoryServiceUtils.h"
43 #include "nsDocShellCID.h"
44 #include "nsINavBookmarksService.h"
46 #include "nsIBrowserHistory.h"
47 #include "nsICookieManager2.h"
48 #include "nsIFileProtocolHandler.h"
49 #include "nsIFormHistory.h"
50 #include "nsIIOService.h"
51 #include "nsILocalFileMac.h"
52 #include "nsIObserverService.h"
53 #include "nsIPrefService.h"
54 #include "nsIProfileMigrator.h"
55 #include "nsIProtocolHandler.h"
56 #include "nsIRDFContainer.h"
57 #include "nsIRDFDataSource.h"
58 #include "nsIRDFRemoteDataSource.h"
59 #include "nsIRDFService.h"
60 #include "nsIServiceManager.h"
61 #include "nsIStringBundle.h"
62 #include "nsISupportsArray.h"
63 #include "nsISupportsPrimitives.h"
65 #include "nsToolkitCompsCID.h"
66 #include "nsNetUtil.h"
69 #include <Carbon/Carbon.h>
71 #define SAFARI_PREFERENCES_FILE_NAME NS_LITERAL_STRING("com.apple.Safari.plist")
72 #define SAFARI_BOOKMARKS_FILE_NAME NS_LITERAL_STRING("Bookmarks.plist")
73 #define SAFARI_HISTORY_FILE_NAME NS_LITERAL_STRING("History.plist")
74 #define SAFARI_COOKIES_FILE_NAME NS_LITERAL_STRING("Cookies.plist")
75 #define SAFARI_COOKIE_BEHAVIOR_FILE_NAME NS_LITERAL_STRING("com.apple.WebFoundation.plist")
76 #define SAFARI_DATE_OFFSET 978307200
77 #define SAFARI_HOME_PAGE_PREF "HomePage"
78 #define MIGRATION_BUNDLE "chrome://browser/locale/migration/migration.properties"
87 mObserverService = do_GetService(
"@mozilla.org/observer-service;1");
98 nsSafariProfileMigrator::Migrate(PRUint16 aItems, nsIProfileStartup* aStartup,
99 const PRUnichar* aProfile)
103 PRBool replace = PR_FALSE;
107 rv = aStartup->DoStartup();
108 NS_ENSURE_SUCCESS(rv, rv);
126 nsSafariProfileMigrator::GetMigrateData(
const PRUnichar* aProfile,
131 nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
132 nsCOMPtr<nsILocalFile> safariSettingsDir, safariCookiesDir;
133 fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile),
134 getter_AddRefs(safariSettingsDir));
135 safariSettingsDir->Append(NS_LITERAL_STRING(
"Safari"));
136 fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile),
137 getter_AddRefs(safariCookiesDir));
138 safariCookiesDir->Append(NS_LITERAL_STRING(
"Cookies"));
149 aReplace, safariSettingsDir, aResult);
156 aReplace, safariCookiesDir, aResult);
159 nsCOMPtr<nsILocalFile> systemPrefsDir;
160 fileLocator->Get(NS_OSX_USER_PREFERENCES_DIR, NS_GET_IID(nsILocalFile),
161 getter_AddRefs(systemPrefsDir));
166 aReplace, systemPrefsDir, aResult);
170 PRBool hasContentStylesheet = PR_FALSE;
172 !hasContentStylesheet) {
173 nsCOMPtr<nsILocalFile> safariUserStylesheetFile;
179 if (HasFormDataToImport())
186 nsSafariProfileMigrator::GetSourceExists(PRBool* aResult)
189 GetMigrateData(nsnull, PR_FALSE, &data);
191 *aResult = data != 0;
197 nsSafariProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
205 nsSafariProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
217 aPListFile->Exists(&exists);
221 nsCAutoString filePath;
222 aPListFile->GetNativePath(filePath);
224 nsCOMPtr<nsILocalFileMac> macFile(do_QueryInterface(aPListFile));
226 macFile->GetCFURL(&urlRef);
231 CFDataRef resourceData = NULL;
232 Boolean dataSuccess = ::CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
239 CFPropertyListRef propertyList = NULL;
242 propertyList = ::CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
244 kCFPropertyListImmutable,
247 ::CFRelease(resourceData);
257 nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
258 nsCOMPtr<nsILocalFile> safariPrefsFile;
259 fileLocator->Get(NS_OSX_USER_PREFERENCES_DIR,
260 NS_GET_IID(nsILocalFile),
261 getter_AddRefs(safariPrefsFile));
271 CFIndex bufferSize = ::CFStringGetLength(aStringRef) + 1;
272 char* buffer = (
char*)malloc(
sizeof(
char) * bufferSize);
275 if (::CFStringGetCString(aStringRef, buffer, bufferSize,
276 kCFStringEncodingASCII))
277 buffer[bufferSize-1] =
'\0';
292 CFStringRef
value = (CFStringRef)::CFDictionaryGetValue(aDictionary, aKey);
294 nsAutoTArray<UniChar, 1024> buffer;
295 CFIndex valueLength = ::CFStringGetLength(value);
296 buffer.SetLength(valueLength);
298 ::CFStringGetCharacters(value, CFRangeMake(0, valueLength), buffer.Elements());
299 aResult.Assign(buffer.Elements(), valueLength);
307 nsACString& aResult, CFStringEncoding aEncoding)
309 CFStringRef
value = (CFStringRef)::CFDictionaryGetValue(aDictionary, aKey);
311 nsAutoTArray<char, 1024> buffer;
312 CFIndex valueLength = ::CFStringGetLength(value);
313 buffer.SetLength(valueLength + 1);
315 if (::CFStringGetCString(value, buffer.Elements(), valueLength + 1, aEncoding)) {
316 aResult = buffer.Elements();
326 CFStringRef
value = (CFStringRef)::CFArrayGetValueAtIndex(aArray, aIndex);
328 nsAutoTArray<UniChar, 1024> buffer;
329 CFIndex valueLength = ::CFStringGetLength(value);
330 buffer.SetLength(valueLength);
332 ::CFStringGetCharacters(value, CFRangeMake(0, valueLength), buffer.Elements());
333 aResult.Assign(buffer.Elements(), valueLength);
339 #define _SPM(type) nsSafariProfileMigrator::type
343 { CFSTR(
"AlwaysShowTabBar"),
_SPM(BOOL),
"browser.tabs.autoHide",
_SPM(SetBoolInverted), PR_FALSE, -1 },
344 { CFSTR(
"AutoFillPasswords"),
_SPM(BOOL),
"signon.rememberSignons",
_SPM(SetBool), PR_FALSE, -1 },
345 { CFSTR(
"OpenNewTabsInFront"),
_SPM(BOOL),
"browser.tabs.loadInBackground",
_SPM(SetBoolInverted), PR_FALSE, -1 },
346 { CFSTR(
"NSDefaultOpenDir"),
_SPM(
STRING),
"browser.download.dir",
_SPM(SetDownloadFolder), PR_FALSE, -1 },
347 { CFSTR(
"AutoOpenSafeDownloads"),
_SPM(BOOL), nsnull,
_SPM(SetDownloadHandlers), PR_FALSE, -1 },
348 { CFSTR(
"DownloadsClearingPolicy"),
_SPM(INT),
"browser.download.manager.retention",
_SPM(SetDownloadRetention), PR_FALSE, -1 },
349 { CFSTR(
"WebKitDefaultTextEncodingName"),
_SPM(
STRING),
"intl.charset.default",
_SPM(SetDefaultEncoding), PR_FALSE, -1 },
350 { CFSTR(
"WebKitStandardFont"),
_SPM(
STRING),
"font.name.serif.",
_SPM(SetFontName), PR_FALSE, -1 },
351 { CFSTR(
"WebKitDefaultFontSize"),
_SPM(INT),
"font.size.serif.",
_SPM(SetFontSize), PR_FALSE, -1 },
352 { CFSTR(
"WebKitFixedFont"),
_SPM(
STRING),
"font.name.fixed.",
_SPM(SetFontName), PR_FALSE, -1 },
353 { CFSTR(
"WebKitDefaultFixedFontSize"),
_SPM(INT),
"font.size.fixed.",
_SPM(SetFontSize), PR_FALSE, -1 },
354 { CFSTR(
"WebKitMinimumFontSize"),
_SPM(INT),
"font.minimum-size.",
_SPM(SetFontSize), PR_FALSE, -1 },
355 { CFSTR(
"WebKitDisplayImagesKey"),
_SPM(BOOL),
"permissions.default.image",
_SPM(SetDisplayImages), PR_FALSE, -1 },
356 { CFSTR(
"WebKitJavaScriptEnabled"),
_SPM(BOOL),
"javascript.enabled",
_SPM(SetBool), PR_FALSE, -1 },
357 { CFSTR(
"WebKitJavaScriptCanOpenWindowsAutomatically"),
358 _SPM(BOOL),
"dom.disable_open_during_load",
_SPM(SetBoolInverted), PR_FALSE, -1 }
397 #define CHARSET_ENTRY(charsetLabel, associatedLangGroup) \
398 {#charsetLabel, sizeof(#charsetLabel) - 1, #charsetLabel, #associatedLangGroup}
399 #define CHARSET_ENTRY2(webkitLabel, mozLabel, associatedLangGroup) \
400 {#webkitLabel, sizeof(#webkitLabel) - 1, #mozLabel, #associatedLangGroup}
441 #undef CHARSET_ENTRY2
449 nsCAutoString associatedLangGroup;
451 PRUint32 encodingLength = encoding.Length();
452 const char* encodingStr = encoding.get();
454 PRInt16 charsetIndex = -1;
455 for (PRUint16
i = 0; (charsetIndex == -1) &&
456 i < (
sizeof(gCharsets) /
sizeof(gCharsets[0])); ++
i) {
457 if (gCharsets[
i].webkitLabelLength == encodingLength &&
458 !strcmp(gCharsets[
i].webkitLabel, encodingStr))
459 charsetIndex = (PRInt16)
i;
461 if (charsetIndex == -1)
469 aBranch->SetCharPref(
"font.language.group",
470 gCharsets[charsetIndex].associatedLangGroup);
471 aBranch->SetCharPref(
"migration.associatedLangGroup",
472 gCharsets[charsetIndex].associatedLangGroup);
482 nsCOMPtr<nsILocalFile> downloadFolder;
483 nsresult rv = NS_NewNativeLocalFile(nsDependentCString(xform->
stringValue),
484 PR_TRUE, getter_AddRefs(downloadFolder));
485 NS_ENSURE_SUCCESS(rv, rv);
490 nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
491 nsCOMPtr<nsILocalFile> desktopFolder;
492 fileLocator->Get(NS_OSX_USER_DESKTOP_DIR, NS_GET_IID(nsILocalFile),
493 getter_AddRefs(desktopFolder));
496 downloadFolder->Equals(desktopFolder, &equals);
497 aBranch->SetIntPref(
"browser.download.folderList", equals ? 0 : 2);
498 aBranch->SetComplexValue(
"browser.download.dir",
499 NS_GET_IID(nsILocalFile), downloadFolder);
512 nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
513 nsCOMPtr<nsILocalFile> mimeRegistryFile;
514 fileLocator->Get(NS_APP_USER_MIMETYPES_50_FILE, NS_GET_IID(nsILocalFile),
515 getter_AddRefs(mimeRegistryFile));
517 nsCOMPtr<nsIIOService>
ioService(do_GetService(
"@mozilla.org/network/io-service;1"));
518 nsCOMPtr<nsIProtocolHandler> ph;
519 ioService->GetProtocolHandler(
"file", getter_AddRefs(ph));
520 nsCOMPtr<nsIFileProtocolHandler> fph(do_QueryInterface(ph));
522 nsCOMPtr<nsIRDFService> rdfService(do_GetService(
"@mozilla.org/rdf/rdf-service;1"));
523 nsCOMPtr<nsIRDFDataSource> mimeTypes;
526 fph->GetURLSpecFromFile(mimeRegistryFile, dsURL);
527 rdfService->GetDataSourceBlocking(dsURL.get(), getter_AddRefs(mimeTypes));
529 nsCOMPtr<nsIRDFResource> overridesListResource;
530 rdfService->GetResource(NS_LITERAL_CSTRING(
"urn:mimetypes:root"),
531 getter_AddRefs(overridesListResource));
533 nsCOMPtr<nsIRDFContainer> overridesList(do_CreateInstance(
"@mozilla.org/rdf/container;1"));
534 overridesList->Init(mimeTypes, overridesListResource);
536 nsCOMPtr<nsIRDFResource> handlerPropArc, externalApplicationArc;
537 rdfService->GetResource(
NC_URI(handlerProp), getter_AddRefs(handlerPropArc));
538 rdfService->GetResource(
NC_URI(externalApplication),
539 getter_AddRefs(externalApplicationArc));
542 overridesList->GetCount(&count);
543 for (PRInt32
i = count;
i >= 1; --
i) {
544 nsCOMPtr<nsIRDFNode> currOverrideNode;
545 overridesList->RemoveElementAt(
i, PR_FALSE, getter_AddRefs(currOverrideNode));
546 nsCOMPtr<nsIRDFResource> currOverride(do_QueryInterface(currOverrideNode));
548 nsCOMPtr<nsIRDFNode> handlerPropNode;
549 mimeTypes->GetTarget(currOverride, handlerPropArc, PR_TRUE,
550 getter_AddRefs(handlerPropNode));
551 nsCOMPtr<nsIRDFResource> handlerPropResource(do_QueryInterface(handlerPropNode));
553 if (handlerPropResource) {
554 nsCOMPtr<nsIRDFNode> externalApplicationNode;
555 mimeTypes->GetTarget(handlerPropResource, externalApplicationArc,
556 PR_TRUE, getter_AddRefs(externalApplicationNode));
557 nsCOMPtr<nsIRDFResource> externalApplicationResource(do_QueryInterface(externalApplicationNode));
560 if (externalApplicationResource)
568 nsCOMPtr<nsIRDFRemoteDataSource> rds(do_QueryInterface(mimeTypes));
577 nsIRDFResource* aResource)
579 nsCOMPtr<nsISimpleEnumerator> arcLabels;
580 aDataSource->ArcLabelsOut(aResource, getter_AddRefs(arcLabels));
586 arcLabels->HasMoreElements(&hasMore);
591 nsCOMPtr<nsIRDFResource> currArc;
592 arcLabels->GetNext(getter_AddRefs(currArc));
595 nsCOMPtr<nsIRDFNode> currTarget;
596 aDataSource->GetTarget(aResource, currArc, PR_TRUE,
597 getter_AddRefs(currTarget));
599 aDataSource->Unassert(aResource, currArc, currTarget);
636 nsCString associatedLangGroup;
637 nsresult rv = aBranch->GetCharPref(
"migration.associatedLangGroup",
638 getter_Copies(associatedLangGroup));
644 prefName.Append(associatedLangGroup);
646 return aBranch->SetCharPref(prefName.get(), xform->
stringValue);
652 nsCString associatedLangGroup;
653 nsresult rv = aBranch->GetCharPref(
"migration.associatedLangGroup",
654 getter_Copies(associatedLangGroup));
660 prefName.Append(associatedLangGroup);
662 return aBranch->SetIntPref(prefName.get(), xform->
intValue);
672 return NS_ERROR_FAILURE;
679 for (transform = gTransforms; transform < end; ++transform) {
680 Boolean hasValue = ::CFDictionaryContainsKey(safariPrefs, transform->
keyName);
685 switch (transform->
type) {
687 CFStringRef stringValue = (CFStringRef)
688 ::CFDictionaryGetValue(safariPrefs,
698 CFNumberRef intValue = (CFNumberRef)
699 ::CFDictionaryGetValue(safariPrefs,
702 if (::CFNumberGetValue(intValue, kCFNumberSInt32Type, &value)) {
709 CFBooleanRef boolValue = (CFBooleanRef)
710 ::CFDictionaryGetValue(safariPrefs,
712 transform->
boolValue = boolValue == kCFBooleanTrue;
727 ::CFRelease(safariPrefs);
731 nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
732 nsCOMPtr<nsILocalFile> safariWebFoundationPrefsFile;
733 fileLocator->Get(NS_OSX_USER_PREFERENCES_DIR, NS_GET_IID(nsILocalFile),
734 getter_AddRefs(safariWebFoundationPrefsFile));
737 CFDictionaryRef safariWebFoundationPrefs =
739 if (safariWebFoundationPrefs) {
746 nsAutoString acceptCookies;
748 CFSTR(
"NSHTTPAcceptCookies"), acceptCookies)) {
749 PRInt32 cookieValue = 0;
750 if (acceptCookies.EqualsLiteral(
"never"))
752 else if (acceptCookies.EqualsLiteral(
"current page"))
755 branch->SetIntPref(
"network.cookie.cookieBehavior", cookieValue);
758 ::CFRelease(safariWebFoundationPrefs);
767 nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
768 nsCOMPtr<nsILocalFile> safariCookiesFile;
769 fileLocator->Get(NS_MAC_USER_LIB_DIR,
770 NS_GET_IID(nsILocalFile),
771 getter_AddRefs(safariCookiesFile));
772 safariCookiesFile->Append(NS_LITERAL_STRING(
"Cookies"));
779 nsCOMPtr<nsICookieManager2>
cookieManager(do_GetService(NS_COOKIEMANAGER_CONTRACTID));
780 CFIndex
count = ::CFArrayGetCount(safariCookies);
781 for (PRInt32
i = 0;
i <
count; ++
i) {
782 CFDictionaryRef
entry = (CFDictionaryRef)::CFArrayGetValueAtIndex(safariCookies,
i);
784 CFDateRef
date = (CFDateRef)::CFDictionaryGetValue(entry, CFSTR(
"Expires"));
789 kCFStringEncodingUTF8) &&
791 kCFStringEncodingUTF8) &&
793 kCFStringEncodingASCII) &&
795 kCFStringEncodingASCII)) {
797 LL_D2L(expiryTime, (
double)::CFDateGetAbsoluteTime(date));
800 cookieManager->Add(domain, path, name, value,
807 ::CFRelease(safariCookies);
813 nsSafariProfileMigrator::RunBatched(
nsISupports* aUserData)
816 nsCOMPtr<nsISupportsPRUint8> strWrapper(do_QueryInterface(aUserData));
817 NS_ASSERTION(strWrapper,
"Unable to create nsISupportsPRUint8 wrapper!");
818 nsresult rv = strWrapper->GetData(&batchAction);
819 NS_ENSURE_SUCCESS(rv, rv);
821 switch (batchAction) {
835 NS_ENSURE_SUCCESS(rv, rv);
844 nsCOMPtr<nsINavHistoryService>
history =
845 do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID, &rv);
846 NS_ENSURE_SUCCESS(rv, rv);
850 nsCOMPtr<nsISupportsPRUint8> supports =
851 do_CreateInstance(NS_SUPPORTS_PRUINT8_CONTRACTID);
852 NS_ENSURE_TRUE(supports, NS_ERROR_OUT_OF_MEMORY);
853 rv = supports->SetData(batchAction);
854 NS_ENSURE_SUCCESS(rv, rv);
856 rv = history->RunInBatchMode(
this, supports);
857 NS_ENSURE_SUCCESS(rv, rv);
865 nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
866 nsCOMPtr<nsILocalFile> safariHistoryFile;
867 fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile),
868 getter_AddRefs(safariHistoryFile));
869 safariHistoryFile->Append(NS_LITERAL_STRING(
"Safari"));
872 CFDictionaryRef safariHistory =
877 if (!::CFDictionaryContainsKey(safariHistory, CFSTR(
"WebHistoryDates"))) {
878 ::CFRelease(safariHistory);
882 nsCOMPtr<nsIBrowserHistory>
history(do_GetService(NS_GLOBALHISTORY2_CONTRACTID));
884 CFArrayRef children = (CFArrayRef)
885 ::CFDictionaryGetValue(safariHistory, CFSTR(
"WebHistoryDates"));
887 CFIndex
count = ::CFArrayGetCount(children);
888 for (PRInt32
i = 0;
i <
count; ++
i) {
889 CFDictionaryRef
entry = (CFDictionaryRef)::CFArrayGetValueAtIndex(children,
i);
891 CFStringRef lastVisitedDate = (CFStringRef)
892 ::CFDictionaryGetValue(entry, CFSTR(
"lastVisitedDate"));
893 nsAutoString
url, title;
899 PRTime lastVisitTime;
900 PRInt64 temp, million;
902 LL_I2L(million, PR_USEC_PER_SEC);
903 LL_MUL(lastVisitTime, temp, million);
905 nsCOMPtr<nsIURI>
uri;
906 NS_NewURI(getter_AddRefs(uri), url);
908 history->AddPageWithDetails(uri, title.get(), lastVisitTime);
913 ::CFRelease(safariHistory);
922 nsCOMPtr<nsINavBookmarksService> bookmarks =
923 do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID, &rv);
924 NS_ENSURE_SUCCESS(rv, rv);
928 nsCOMPtr<nsISupportsPRUint8> supports =
929 do_CreateInstance(NS_SUPPORTS_PRUINT8_CONTRACTID);
930 NS_ENSURE_TRUE(supports, NS_ERROR_OUT_OF_MEMORY);
931 rv = supports->SetData(batchAction);
932 NS_ENSURE_SUCCESS(rv, rv);
934 rv = bookmarks->RunInBatchMode(
this, supports);
935 NS_ENSURE_SUCCESS(rv, rv);
947 nsCOMPtr<nsINavBookmarksService> bms =
948 do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID, &rv);
949 NS_ENSURE_SUCCESS(rv, rv);
950 PRInt64 bookmarksMenuFolderId;
951 rv = bms->GetBookmarksMenuFolder(&bookmarksMenuFolderId);
952 NS_ENSURE_SUCCESS(rv, rv);
956 nsCOMPtr<nsIStringBundleService> bundleService =
957 do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
958 NS_ENSURE_SUCCESS(rv, rv);
959 nsCOMPtr<nsIStringBundle>
bundle;
961 NS_ENSURE_SUCCESS(rv, rv);
963 nsString sourceNameSafari;
964 rv = bundle->GetStringFromName(NS_LITERAL_STRING(
"sourceNameSafari").
get(),
965 getter_Copies(sourceNameSafari));
966 NS_ENSURE_SUCCESS(rv, rv);
968 const PRUnichar* sourceNameStrings[] = { sourceNameSafari.get() };
969 nsString importedSafariBookmarksTitle;
970 rv = bundle->FormatStringFromName(NS_LITERAL_STRING(
"importedBookmarksFolder").
get(),
971 sourceNameStrings, 1,
972 getter_Copies(importedSafariBookmarksTitle));
973 NS_ENSURE_SUCCESS(rv, rv);
975 rv = bms->CreateFolder(bookmarksMenuFolderId,
976 NS_ConvertUTF16toUTF8(importedSafariBookmarksTitle),
977 nsINavBookmarksService::DEFAULT_INDEX, &folder);
978 NS_ENSURE_SUCCESS(rv, rv);
981 nsCOMPtr<nsIFile> profile;
984 NS_ENSURE_SUCCESS(rv, rv);
986 folder = bookmarksMenuFolderId;
989 nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
990 nsCOMPtr<nsILocalFile> safariBookmarksFile;
991 fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile),
992 getter_AddRefs(safariBookmarksFile));
993 safariBookmarksFile->Append(NS_LITERAL_STRING(
"Safari"));
996 CFDictionaryRef safariBookmarks =
998 if (!safariBookmarks)
1009 if (::CFDictionaryContainsKey(safariBookmarks, CFSTR(
"Children")) &&
1010 ::CFDictionaryContainsKey(safariBookmarks, CFSTR(
"WebBookmarkFileVersion")) ) {
1011 CFNumberRef intValue =
1012 (CFNumberRef)::CFDictionaryGetValue(safariBookmarks,
1013 CFSTR(
"WebBookmarkFileVersion"));
1015 if (::CFNumberGetValue(intValue, kCFNumberSInt32Type, &value) && value ==1) {
1016 CFArrayRef children =
1017 (CFArrayRef)::CFDictionaryGetValue(safariBookmarks, CFSTR(
"Children"));
1023 ::CFRelease(safariBookmarks);
1029 PRInt64 aParentFolder,
1030 nsINavBookmarksService * aBookmarksService,
1031 PRBool aIsAtRootLevel)
1033 nsresult rv =
NS_OK;
1035 CFIndex
count = ::CFArrayGetCount(aChildren);
1036 for (PRInt32
i = 0;
i <
count; ++
i) {
1037 CFDictionaryRef
entry = (CFDictionaryRef)::CFArrayGetValueAtIndex(aChildren,
i);
1043 if (!type.EqualsLiteral(
"WebBookmarkTypeList") &&
1044 !type.EqualsLiteral(
"WebBookmarkTypeLeaf"))
1047 if (::CFDictionaryContainsKey(entry, CFSTR(
"Children")) &&
1048 type.EqualsLiteral(
"WebBookmarkTypeList")) {
1053 CFArrayRef children = (CFArrayRef)::CFDictionaryGetValue(entry,
1058 if (title.EqualsLiteral(
"BookmarksBar") && aIsAtRootLevel) {
1059 PRInt64 toolbarFolder;
1060 aBookmarksService->GetToolbarFolder(&toolbarFolder);
1068 else if (title.EqualsLiteral(
"BookmarksMenu") && aIsAtRootLevel) {
1078 rv |= aBookmarksService->CreateFolder(aParentFolder, NS_ConvertUTF16toUTF8(title),
1079 nsINavBookmarksService::DEFAULT_INDEX,
1087 else if (type.EqualsLiteral(
"WebBookmarkTypeLeaf")) {
1089 CFDictionaryRef URIDictionary = (CFDictionaryRef)
1090 ::CFDictionaryGetValue(entry, CFSTR(
"URIDictionary"));
1095 nsCOMPtr<nsIURI>
uri;
1096 rv = NS_NewURI(getter_AddRefs(uri), url);
1097 if (NS_SUCCEEDED(rv)) {
1099 rv = aBookmarksService->InsertBookmark(aParentFolder, uri,
1100 nsINavBookmarksService::DEFAULT_INDEX,
1101 NS_ConvertUTF16toUTF8(title), &
id);
1114 nsSafariProfileMigrator::HasFormDataToImport()
1116 PRBool hasFormData = PR_FALSE;
1122 if (::CFDictionaryContainsKey(safariPrefs, CFSTR(
"RecentSearchStrings")))
1123 hasFormData = PR_TRUE;
1124 ::CFRelease(safariPrefs);
1136 nsresult rv = NS_ERROR_FAILURE;
1142 Boolean hasSearchStrings = ::CFDictionaryContainsKey(safariPrefs,
1143 CFSTR(
"RecentSearchStrings"));
1144 if (hasSearchStrings) {
1145 nsCOMPtr<nsIFormHistory2> formHistory(do_GetService(
"@mozilla.org/satchel/form-history;1"));
1147 CFArrayRef
strings = (CFArrayRef)::CFDictionaryGetValue(safariPrefs,
1148 CFSTR(
"RecentSearchStrings"));
1150 CFIndex
count = ::CFArrayGetCount(strings);
1151 for (PRInt32
i = 0;
i <
count; ++
i) {
1154 formHistory->AddEntry(NS_LITERAL_STRING(
"searchbar-history"), value);
1163 ::CFRelease(safariPrefs);
1174 NS_ENSURE_ARG(outExists);
1177 nsCOMPtr<nsIFile> userChromeDir;
1178 nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR,
1179 getter_AddRefs(userChromeDir));
1180 nsCAutoString userChromeDirPath;
1181 rv = userChromeDir->GetNativePath(userChromeDirPath);
1182 NS_ENSURE_SUCCESS(rv, rv);
1184 nsCAutoString
path(userChromeDirPath);
1185 path.Append(
"/userContent.css");
1187 nsCOMPtr<nsILocalFile>
file;
1188 rv = NS_NewNativeLocalFile(path, PR_FALSE,
1189 getter_AddRefs(file));
1190 NS_ENSURE_SUCCESS(rv, rv);
1192 file->Exists(outExists);
1203 return NS_ERROR_FAILURE;
1205 nsresult rv = NS_ERROR_FAILURE;
1207 if (::CFDictionaryContainsKey
1208 (safariPrefs, CFSTR(
"WebKitUserStyleSheetEnabledPreferenceKey")) &&
1209 ::CFDictionaryContainsKey
1210 (safariPrefs, CFSTR(
"WebKitUserStyleSheetLocationPreferenceKey"))) {
1211 CFBooleanRef hasSheet = (CFBooleanRef)::CFDictionaryGetValue(safariPrefs,
1212 CFSTR(
"WebKitUserStyleSheetEnabledPreferenceKey"));
1213 if (hasSheet == kCFBooleanTrue) {
1217 CFSTR(
"WebKitUserStyleSheetLocation" \
1218 "PreferenceKey"), path)) {
1219 nsCOMPtr<nsILocalFile>
file;
1220 rv = NS_NewLocalFile(path, PR_FALSE, getter_AddRefs(file));
1221 if (NS_SUCCEEDED(rv)) {
1222 PRBool exists = PR_FALSE;
1223 file->Exists(&exists);
1225 NS_ADDREF(*aResult = file);
1229 rv = NS_ERROR_FILE_NOT_FOUND;
1234 ::CFRelease(safariPrefs);
1244 nsCOMPtr<nsILocalFile> stylesheetFile;
1246 nsCOMPtr<nsIFile> userChromeDir;
1247 NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR,
1248 getter_AddRefs(userChromeDir));
1250 stylesheetFile->CopyTo(userChromeDir, NS_LITERAL_STRING(
"userContent.css"));
1257 nsSafariProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
1266 aResult, kCFStringEncodingUTF8);
1267 ::CFRelease(safariPrefs);
1274 ICInstance internetConfig;
1275 OSStatus error = ::ICStart(&internetConfig,
'FRFX');
1277 return NS_ERROR_FAILURE;
1280 Str255 homePagePValue;
1281 long prefSize =
sizeof(homePagePValue);
1282 error = ::ICGetPref(internetConfig, kICWWWHomePage, &dummy,
1283 homePagePValue, &prefSize);
1285 return NS_ERROR_FAILURE;
1287 char homePageValue[256] =
"";
1288 CopyPascalStringToC((ConstStr255Param)homePagePValue, homePageValue);
1289 aResult.Assign(homePageValue);
1290 ::ICStop(internetConfig);
PRBool GetDictionaryStringValue(CFDictionaryRef aDictionary, CFStringRef aKey, nsAString &aResult)
const unsigned short FORMDATA
nsresult InitializeBookmarks(nsIFile *aTargetProfile)
static void CleanResource(nsIRDFDataSource *aDataSource, nsIRDFResource *aResource)
PRBool GetDictionaryCStringValue(CFDictionaryRef aDictionary, CFStringRef aKey, nsACString &aResult, CFStringEncoding aEncoding)
static const charsetEntry gCharsets[]
static nsresult SetDownloadFolder(void *aTransform, nsIPrefBranch *aBranch)
nsresult CopyBookmarksBatched(PRBool aReplace)
void FreeNullTerminatedString(char *aString)
#define SAFARI_HISTORY_FILE_NAME
const char * associatedLangGroup
const unsigned short HISTORY
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
static nsresult SetInt(void *aTransform, nsIPrefBranch *aBranch)
virtual ~nsSafariProfileMigrator()
#define BATCH_ACTION_BOOKMARKS
const NS_PREFSERVICE_CONTRACTID
static nsSafariProfileMigrator::PrefTransform gTransforms[]
static nsresult SetString(void *aTransform, nsIPrefBranch *aBranch)
#define SAFARI_PREFERENCES_FILE_NAME
static nsresult SetDownloadRetention(void *aTransform, nsIPrefBranch *aBranch)
char * GetNullTerminatedString(CFStringRef aStringRef)
PRBool GetArrayStringValue(CFArrayRef aArray, PRInt32 aIndex, nsAString &aResult)
static nsresult SetDisplayImages(void *aTransform, nsIPrefBranch *aBranch)
#define CHARSET_ENTRY2(webkitLabel, mozLabel, associatedLangGroup)
const unsigned short SETTINGS
#define BATCH_ACTION_HISTORY_REPLACE
nsresult CopyBookmarks(PRBool aReplace)
#define NOTIFY_OBSERVERS(message, item)
#define SAFARI_DATE_OFFSET
#define SAFARI_HOME_PAGE_PREF
nsresult CopyFormData(PRBool aReplace)
#define SAFARI_COOKIE_BEHAVIOR_FILE_NAME
nsresult CopyPreferences(PRBool aReplace)
static nsresult SetFontName(void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetDefaultEncoding(void *aTransform, nsIPrefBranch *aBranch)
#define MIGRATION_STARTED
nsresult CopyHistoryBatched(PRBool aReplace)
#define COPY_DATA(func, replace, itemIndex)
CFDictionaryRef CopySafariPrefs()
#define SAFARI_COOKIES_FILE_NAME
static nsresult SetFontSize(void *aTransform, nsIPrefBranch *aBranch)
#define CHARSET_ENTRY(charsetLabel, associatedLangGroup)
CFPropertyListRef CopyPListFromFile(nsILocalFile *aPListFile)
static nsresult SetDownloadHandlers(void *aTransform, nsIPrefBranch *aBranch)
nsresult CopyCookies(PRBool aReplace)
const unsigned short COOKIES
nsresult GetSafariUserStyleSheet(nsILocalFile **aResult)
StringArrayEnumerator prototype hasMore
const unsigned short BOOKMARKS
nsresult ProfileHasContentStyleSheet(PRBool *outExists)
#define SAFARI_BOOKMARKS_FILE_NAME
void GetProfilePath(nsIProfileStartup *aStartup, nsCOMPtr< nsIFile > &aProfileDir)
#define BATCH_ACTION_HISTORY
static nsresult SetBoolInverted(void *aTransform, nsIPrefBranch *aBranch)
#define BATCH_ACTION_BOOKMARKS_REPLACE
nsresult CopyHistory(PRBool aReplace)
static nsresult SetBool(void *aTransform, nsIPrefBranch *aBranch)
nsresult ParseBookmarksFolder(CFArrayRef aChildren, PRInt64 aParentFolder, nsINavBookmarksService *aBookmarksService, PRBool aIsAtRootLevel)
const unsigned short OTHERDATA
_getSelectedPageStyle s i
nsresult CopyOtherData(PRBool aReplace)
void GetMigrateDataFromArray(MigrationData *aDataArray, PRInt32 aDataArrayLength, PRBool aReplace, nsIFile *aSourceProfile, PRUint16 *aResult)