nsSeamonkeyProfileMigrator.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is The Browser Profile Migrator.
16  *
17  * The Initial Developer of the Original Code is Ben Goodger.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Ben Goodger <ben@bengoodger.com>
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
39 #include "nsDirectoryServiceDefs.h"
40 #include "nsIObserverService.h"
41 #include "nsILoginInfo.h"
42 #include "nsILoginManager.h"
43 #include "nsILoginManagerStorage.h"
44 #include "nsIPrefLocalizedString.h"
45 #include "nsIPrefService.h"
46 #include "nsIServiceManager.h"
47 #include "nsISupportsArray.h"
48 #include "nsISupportsPrimitives.h"
49 #include "nsNetCID.h"
50 #include "nsNetUtil.h"
52 #include "nsIProfileMigrator.h"
53 
55 // nsSeamonkeyProfileMigrator
56 
57 #define FILE_NAME_BOOKMARKS NS_LITERAL_STRING("bookmarks.html")
58 #define FILE_NAME_COOKIES NS_LITERAL_STRING("cookies.txt")
59 #define FILE_NAME_SITEPERM_OLD NS_LITERAL_STRING("cookperm.txt")
60 #define FILE_NAME_SITEPERM_NEW NS_LITERAL_STRING("hostperm.1")
61 #define FILE_NAME_CERT8DB NS_LITERAL_STRING("cert8.db")
62 #define FILE_NAME_KEY3DB NS_LITERAL_STRING("key3.db")
63 #define FILE_NAME_SECMODDB NS_LITERAL_STRING("secmod.db")
64 #define FILE_NAME_HISTORY NS_LITERAL_STRING("history.dat")
65 #define FILE_NAME_MIMETYPES NS_LITERAL_STRING("mimeTypes.rdf")
66 #define FILE_NAME_DOWNLOADS NS_LITERAL_STRING("downloads.rdf")
67 #define FILE_NAME_PREFS NS_LITERAL_STRING("prefs.js")
68 #define FILE_NAME_USER_PREFS NS_LITERAL_STRING("user.js")
69 #define FILE_NAME_USERCONTENT NS_LITERAL_STRING("userContent.css")
70 #define DIR_NAME_CHROME NS_LITERAL_STRING("chrome")
71 
73 
75 {
76  mObserverService = do_GetService("@mozilla.org/observer-service;1");
77 }
78 
80 {
81 }
82 
84 // nsIBrowserProfileMigrator
85 
86 NS_IMETHODIMP
87 nsSeamonkeyProfileMigrator::Migrate(PRUint16 aItems, nsIProfileStartup* aStartup, const PRUnichar* aProfile)
88 {
89  nsresult rv = NS_OK;
90  PRBool aReplace = aStartup ? PR_TRUE : PR_FALSE;
91 
92  if (!mTargetProfile) {
93  GetProfilePath(aStartup, mTargetProfile);
94  if (!mTargetProfile) return NS_ERROR_FAILURE;
95  }
96  if (!mSourceProfile)
97  GetSourceProfile(aProfile);
98 
100 
106 
107  // Need to do startup before trying to copy bookmarks, since bookmarks
108  // import requires a profile. Can't do it earlier because services might
109  // end up creating the files we try to copy above.
110  if (aStartup) {
111  rv = aStartup->DoStartup();
112  NS_ENSURE_SUCCESS(rv, rv);
113  }
114 
116 
117  if (aReplace &&
121  !aItems)) {
122  // Permissions (Images, Cookies, Popups)
125  }
126 
128 
129  return rv;
130 }
131 
132 NS_IMETHODIMP
133 nsSeamonkeyProfileMigrator::GetMigrateData(const PRUnichar* aProfile,
134  PRBool aReplace,
135  PRUint16* aResult)
136 {
137  *aResult = 0;
138 
139  if (!mSourceProfile) {
140  GetSourceProfile(aProfile);
141  if (!mSourceProfile)
142  return NS_ERROR_FILE_NOT_FOUND;
143  }
144 
145  MigrationData data[] = { { ToNewUnicode(FILE_NAME_PREFS),
147  PR_TRUE },
148  { ToNewUnicode(FILE_NAME_USER_PREFS),
150  PR_TRUE },
151  { ToNewUnicode(FILE_NAME_COOKIES),
153  PR_FALSE },
154  { ToNewUnicode(FILE_NAME_HISTORY),
156  PR_TRUE },
157  { ToNewUnicode(FILE_NAME_BOOKMARKS),
159  PR_FALSE },
160  { ToNewUnicode(FILE_NAME_DOWNLOADS),
162  PR_TRUE },
163  { ToNewUnicode(FILE_NAME_MIMETYPES),
165  PR_TRUE } };
166 
167  // Frees file name strings allocated above.
168  GetMigrateDataFromArray(data, sizeof(data)/sizeof(MigrationData),
169  aReplace, mSourceProfile, aResult);
170 
171  // Now locate passwords
172  nsCString signonsFileName;
173  GetSignonFileName(aReplace, getter_Copies(signonsFileName));
174 
175  if (!signonsFileName.IsEmpty()) {
176  NS_ConvertASCIItoUTF16 fileName(signonsFileName);
177  nsCOMPtr<nsIFile> sourcePasswordsFile;
178  mSourceProfile->Clone(getter_AddRefs(sourcePasswordsFile));
179  sourcePasswordsFile->Append(fileName);
180 
181  PRBool exists;
182  sourcePasswordsFile->Exists(&exists);
183  if (exists)
185  }
186 
187  return NS_OK;
188 }
189 
190 NS_IMETHODIMP
191 nsSeamonkeyProfileMigrator::GetSourceExists(PRBool* aResult)
192 {
193  nsCOMPtr<nsISupportsArray> profiles;
194  GetSourceProfiles(getter_AddRefs(profiles));
195 
196  if (profiles) {
197  PRUint32 count;
198  profiles->Count(&count);
199  *aResult = count > 0;
200  }
201  else
202  *aResult = PR_FALSE;
203 
204  return NS_OK;
205 }
206 
207 NS_IMETHODIMP
208 nsSeamonkeyProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
209 {
210  nsCOMPtr<nsISupportsArray> profiles;
211  GetSourceProfiles(getter_AddRefs(profiles));
212 
213  if (profiles) {
214  PRUint32 count;
215  profiles->Count(&count);
216  *aResult = count > 1;
217  }
218  else
219  *aResult = PR_FALSE;
220 
221  return NS_OK;
222 }
223 
224 NS_IMETHODIMP
225 nsSeamonkeyProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
226 {
227  if (!mProfileNames && !mProfileLocations) {
228  mProfileNames = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);
229  mProfileLocations = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);
230  NS_ENSURE_TRUE(mProfileNames && mProfileLocations, NS_ERROR_UNEXPECTED);
231 
232  // Fills mProfileNames and mProfileLocations
234  }
235 
236  NS_IF_ADDREF(*aResult = mProfileNames);
237  return NS_OK;
238 }
239 
240 NS_IMETHODIMP
241 nsSeamonkeyProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
242 {
243  // Load the source pref file
244  nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
245  psvc->ResetPrefs();
246 
247  nsCOMPtr<nsIFile> sourcePrefsFile;
248 
249  mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile));
250  sourcePrefsFile->Append(FILE_NAME_PREFS);
251 
252  psvc->ReadUserPrefs(sourcePrefsFile);
253 
254  nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
255 
256  PRBool hasUserValue;
257  nsCOMPtr<nsIPrefLocalizedString> prefValue;
258  nsresult rv = branch->PrefHasUserValue("browser.startup.homepage", &hasUserValue);
259  if (NS_SUCCEEDED(rv) && hasUserValue) {
260  rv = branch->GetComplexValue("browser.startup.homepage",
261  NS_GET_IID(nsIPrefLocalizedString),
262  getter_AddRefs(prefValue));
263  if (NS_SUCCEEDED(rv) && prefValue) {
264  nsString data;
265  prefValue->ToString(getter_Copies(data));
266 
267  nsCAutoString val;
268  val = ToNewCString(NS_ConvertUTF16toUTF8(data));
269 
270  aResult.Assign(val);
271  }
272  }
273 
274  psvc->ResetPrefs();
275  psvc->ReadUserPrefs(nsnull);
276 
277  return NS_OK;
278 }
279 
281 // nsSeamonkeyProfileMigrator
282 
283 nsresult
285 {
286  PRUint32 count;
287  mProfileNames->Count(&count);
288  for (PRUint32 i = 0; i < count; ++i) {
289  nsCOMPtr<nsISupportsString> str;
290  mProfileNames->QueryElementAt(i, NS_GET_IID(nsISupportsString),
291  getter_AddRefs(str));
292  nsString profileName;
293  str->GetData(profileName);
294  if (profileName.Equals(aProfile)) {
295  mProfileLocations->QueryElementAt(i, NS_GET_IID(nsILocalFile),
296  getter_AddRefs(mSourceProfile));
297  break;
298  }
299  }
300 
301  return NS_OK;
302 }
303 
304 nsresult
306 {
307  // Find the Seamonkey Registry
308  nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1"));
309  nsCOMPtr<nsILocalFile> seamonkeyRegistry;
310 #ifdef XP_WIN
311  fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
312 
313  seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
314  seamonkeyRegistry->Append(NS_LITERAL_STRING("registry.dat"));
315 #elif defined(XP_MACOSX)
316  fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
317 
318  seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
319  seamonkeyRegistry->Append(NS_LITERAL_STRING("Application Registry"));
320 #elif defined(XP_UNIX)
321  fileLocator->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
322 
323  seamonkeyRegistry->Append(NS_LITERAL_STRING(".mozilla"));
324  seamonkeyRegistry->Append(NS_LITERAL_STRING("appreg"));
325 #elif defined(XP_BEOS)
326  fileLocator->Get(NS_BEOS_SETTINGS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
327 
328  seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
329  seamonkeyRegistry->Append(NS_LITERAL_STRING("appreg"));
330 #elif defined(XP_OS2)
331  fileLocator->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
332 
333  seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
334  seamonkeyRegistry->Append(NS_LITERAL_STRING("registry.dat"));
335 #endif
336 
337  return GetProfileDataFromRegistry(seamonkeyRegistry, mProfileNames, mProfileLocations);
338 }
339 
340 #define F(a) nsSeamonkeyProfileMigrator::a
341 
342 #define MAKEPREFTRANSFORM(pref, newpref, getmethod, setmethod) \
343  { pref, newpref, F(Get##getmethod), F(Set##setmethod), PR_FALSE, { -1 } }
344 
345 #define MAKESAMETYPEPREFTRANSFORM(pref, method) \
346  { pref, 0, F(Get##method), F(Set##method), PR_FALSE, { -1 } }
347 
348 
349 static
351  MAKESAMETYPEPREFTRANSFORM("signon.SignonFileName", String),
352  MAKESAMETYPEPREFTRANSFORM("browser.history_expire_days", Int),
353  MAKESAMETYPEPREFTRANSFORM("browser.tabs.autoHide", Bool),
354  MAKESAMETYPEPREFTRANSFORM("browser.tabs.loadInBackground", Bool),
355  MAKESAMETYPEPREFTRANSFORM("browser.enable_automatic_image_resizing", Bool),
356  MAKESAMETYPEPREFTRANSFORM("network.cookie.warnAboutCookies", Bool),
357  MAKESAMETYPEPREFTRANSFORM("network.cookie.lifetime.enabled", Bool),
358  MAKESAMETYPEPREFTRANSFORM("network.cookie.lifetime.behavior", Int),
359  MAKESAMETYPEPREFTRANSFORM("dom.disable_open_during_load", Bool),
360  MAKESAMETYPEPREFTRANSFORM("signon.rememberSignons", Bool),
361  MAKESAMETYPEPREFTRANSFORM("security.enable_ssl2", Bool),
362  MAKESAMETYPEPREFTRANSFORM("security.enable_ssl3", Bool),
363  MAKESAMETYPEPREFTRANSFORM("security.enable_tls", Bool),
364  MAKESAMETYPEPREFTRANSFORM("security.warn_entering_secure", Bool),
365  MAKESAMETYPEPREFTRANSFORM("security.warn_entering_weak", Bool),
366  MAKESAMETYPEPREFTRANSFORM("security.warn_leaving_secure", Bool),
367  MAKESAMETYPEPREFTRANSFORM("security.warn_submit_insecure", Bool),
368  MAKESAMETYPEPREFTRANSFORM("security.warn_viewing_mixed", Bool),
369  MAKESAMETYPEPREFTRANSFORM("security.default_personal_cert", String),
370  MAKESAMETYPEPREFTRANSFORM("security.OSCP.enabled", Int),
371  MAKESAMETYPEPREFTRANSFORM("security.OSCP.signingCA", String),
372  MAKESAMETYPEPREFTRANSFORM("security.OSCP.URL", String),
373  MAKESAMETYPEPREFTRANSFORM("javascript.enabled", Bool),
374  MAKESAMETYPEPREFTRANSFORM("dom.disable_window_move_resize", Bool),
375  MAKESAMETYPEPREFTRANSFORM("dom.disable_window_flip", Bool),
376  MAKESAMETYPEPREFTRANSFORM("dom.disable_window_open_feature.status", Bool),
377  MAKESAMETYPEPREFTRANSFORM("dom.disable_window_status_change", Bool),
378  MAKESAMETYPEPREFTRANSFORM("dom.disable_image_src_set", Bool),
379  MAKESAMETYPEPREFTRANSFORM("accessibility.typeaheadfind.autostart", Bool),
380  MAKESAMETYPEPREFTRANSFORM("accessibility.typeaheadfind.linksonly", Bool),
381  MAKESAMETYPEPREFTRANSFORM("network.proxy.type", Int),
382  MAKESAMETYPEPREFTRANSFORM("network.proxy.http", String),
383  MAKESAMETYPEPREFTRANSFORM("network.proxy.http_port", Int),
384  MAKESAMETYPEPREFTRANSFORM("network.proxy.ftp", String),
385  MAKESAMETYPEPREFTRANSFORM("network.proxy.ftp_port", Int),
386  MAKESAMETYPEPREFTRANSFORM("network.proxy.ssl", String),
387  MAKESAMETYPEPREFTRANSFORM("network.proxy.ssl_port", Int),
388  MAKESAMETYPEPREFTRANSFORM("network.proxy.socks", String),
389  MAKESAMETYPEPREFTRANSFORM("network.proxy.socks_port", Int),
390  MAKESAMETYPEPREFTRANSFORM("network.proxy.gopher", String),
391  MAKESAMETYPEPREFTRANSFORM("network.proxy.gopher_port", Int),
392  MAKESAMETYPEPREFTRANSFORM("network.proxy.no_proxies_on", String),
393  MAKESAMETYPEPREFTRANSFORM("network.proxy.autoconfig_url", String),
394  MAKESAMETYPEPREFTRANSFORM("browser.display.foreground_color", String),
395  MAKESAMETYPEPREFTRANSFORM("browser.display.background_color", String),
396  MAKESAMETYPEPREFTRANSFORM("browser.anchor_color", String),
397  MAKESAMETYPEPREFTRANSFORM("browser.visited_color", String),
398  MAKESAMETYPEPREFTRANSFORM("browser.underline_anchors", Bool),
399  MAKESAMETYPEPREFTRANSFORM("browser.display.use_system_colors", Bool),
400  MAKESAMETYPEPREFTRANSFORM("browser.display.use_document_colors", Bool),
401  MAKESAMETYPEPREFTRANSFORM("browser.display.use_document_fonts", Bool),
402  MAKESAMETYPEPREFTRANSFORM("intl.charset.default", String),
403  MAKESAMETYPEPREFTRANSFORM("intl.accept_languages", String),
404  MAKESAMETYPEPREFTRANSFORM("intl.accept_charsets", String),
405 
406  MAKEPREFTRANSFORM("network.image.imageBehavior", 0, Int, Image),
407  MAKEPREFTRANSFORM("network.cookie.cookieBehavior", 0, Int, Cookie),
408  MAKEPREFTRANSFORM("browser.downloadmanager.behavior", 0, Int, DownloadManager),
409 
410  MAKEPREFTRANSFORM("wallet.captureForms", "formfill.enabled", Bool, Bool)
411 };
412 
413 nsresult
415 {
416  PrefTransform* xform = (PrefTransform*)aTransform;
417  nsresult rv = NS_OK;
418 
419  if (xform->prefHasValue)
420  rv = aBranch->SetIntPref("network.image.imageBehavior", xform->intValue == 1 ? 0 : xform->intValue);
421 
422  return rv;
423 }
424 
425 nsresult
427 {
428  PrefTransform* xform = (PrefTransform*)aTransform;
429  nsresult rv = NS_OK;
430 
431  if (xform->prefHasValue)
432  rv = aBranch->SetIntPref("network.cookie.cookieBehavior", xform->intValue == 3 ? 0 : xform->intValue);
433 
434  return rv;
435 }
436 
437 nsresult
439 {
440  PrefTransform* xform = (PrefTransform*)aTransform;
441  nsresult rv = NS_OK;
442 
443  if (xform->prefHasValue) {
444  // Seamonkey's download manager uses a single pref to control behavior:
445  // 0 - show download manager window
446  // 1 - show individual progress dialogs
447  // 2 - show nothing
448  //
449  // Firefox has only a download manager window, but it can behave like a progress dialog, thus:
450  // 0 || 1 -> show downloads window when a download starts
451  // 2 -> don't show anything when a download starts
452  // 1 -> close the downloads window as if it were a progress window when downloads complete.
453  //
454  rv |= aBranch->SetBoolPref("browser.download.manager.showWhenStarting", xform->intValue != 2);
455  rv |= aBranch->SetBoolPref("browser.download.manager.closeWhenDone", xform->intValue == 1);
456  }
457  return NS_OK;
458 }
459 
460 nsresult
461 nsSeamonkeyProfileMigrator::TransformPreferences(const nsAString& aSourcePrefFileName,
462  const nsAString& aTargetPrefFileName)
463 {
464  PrefTransform* transform;
465  PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform);
466 
467  // Load the source pref file
468  nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
469  psvc->ResetPrefs();
470 
471  nsCOMPtr<nsIFile> sourcePrefsFile;
472  mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile));
473  sourcePrefsFile->Append(aSourcePrefFileName);
474  psvc->ReadUserPrefs(sourcePrefsFile);
475 
476  nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
477  for (transform = gTransforms; transform < end; ++transform)
478  transform->prefGetterFunc(transform, branch);
479 
480  nsTArray<FontPref> fontPrefs;
481  ReadFontsBranch(psvc, &fontPrefs);
482 
483  // Now that we have all the pref data in memory, load the target pref file,
484  // and write it back out
485  psvc->ResetPrefs();
486  for (transform = gTransforms; transform < end; ++transform)
487  transform->prefSetterFunc(transform, branch);
488 
489  WriteFontsBranch(psvc, &fontPrefs);
490 
491  nsCOMPtr<nsIFile> targetPrefsFile;
492  mTargetProfile->Clone(getter_AddRefs(targetPrefsFile));
493  targetPrefsFile->Append(aTargetPrefFileName);
494  psvc->SavePrefFile(targetPrefsFile);
495 
496  psvc->ResetPrefs();
497  psvc->ReadUserPrefs(nsnull);
498 
499  return NS_OK;
500 }
501 
502 void
503 nsSeamonkeyProfileMigrator::ReadFontsBranch(nsIPrefService* aPrefService,
504  nsTArray<FontPref>* aPrefs)
505 {
506  // Enumerate the branch
507  nsCOMPtr<nsIPrefBranch> branch;
508  aPrefService->GetBranch("font.", getter_AddRefs(branch));
509 
510  PRUint32 count;
511  char** prefs = nsnull;
512  nsresult rv = branch->GetChildList("", &count, &prefs);
513  if (NS_FAILED(rv)) return;
514 
515  for (PRUint32 i = 0; i < count; ++i) {
516  // Save each pref's value into an array
517  char* currPref = prefs[i];
518  PRInt32 type;
519  branch->GetPrefType(currPref, &type);
520  FontPref* pref = aPrefs->AppendElement();
521  pref->prefName = currPref;
522  pref->type = type;
523  switch (type) {
524  case nsIPrefBranch::PREF_STRING:
525  rv = branch->GetCharPref(currPref, &pref->stringValue);
526  break;
527  case nsIPrefBranch::PREF_BOOL:
528  rv = branch->GetBoolPref(currPref, &pref->boolValue);
529  break;
530  case nsIPrefBranch::PREF_INT:
531  rv = branch->GetIntPref(currPref, &pref->intValue);
532  break;
533  case nsIPrefBranch::PREF_INVALID:
534  {
535  nsCOMPtr<nsIPrefLocalizedString> str;
536  rv = branch->GetComplexValue(currPref,
537  NS_GET_IID(nsIPrefLocalizedString),
538  getter_AddRefs(str));
539  if (NS_SUCCEEDED(rv) && str)
540  str->ToString(&pref->wstringValue);
541  }
542  break;
543  }
544 
545  if (NS_FAILED(rv))
546  aPrefs->RemoveElementAt(aPrefs->Length()-1);
547  }
548 }
549 
550 void
551 nsSeamonkeyProfileMigrator::WriteFontsBranch(nsIPrefService* aPrefService,
552  nsTArray<FontPref>* aPrefs)
553 {
554  nsresult rv;
555 
556  // Enumerate the branch
557  nsCOMPtr<nsIPrefBranch> branch;
558  aPrefService->GetBranch("font.", getter_AddRefs(branch));
559 
560  PRUint32 count = aPrefs->Length();
561  for (PRUint32 i = 0; i < count; ++i) {
562  FontPref &pref = aPrefs->ElementAt(i);
563  switch (pref.type) {
564  case nsIPrefBranch::PREF_STRING:
565  rv = branch->SetCharPref(pref.prefName, pref.stringValue);
566  NS_Free(pref.stringValue);
567  pref.stringValue = nsnull;
568  break;
569  case nsIPrefBranch::PREF_BOOL:
570  rv = branch->SetBoolPref(pref.prefName, pref.boolValue);
571  break;
572  case nsIPrefBranch::PREF_INT:
573  rv = branch->SetIntPref(pref.prefName, pref.intValue);
574  break;
575  case nsIPrefBranch::PREF_INVALID:
576  nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
577  pls->SetData(pref.wstringValue);
578  rv = branch->SetComplexValue(pref.prefName,
579  NS_GET_IID(nsIPrefLocalizedString),
580  pls);
581  NS_Free(pref.wstringValue);
582  pref.wstringValue = nsnull;
583  break;
584  }
585  NS_Free(pref.prefName);
586  }
587  aPrefs->Clear();
588 }
589 
590 nsresult
592 {
593  nsresult rv = NS_OK;
594  if (!aReplace)
595  return rv;
596 
599 
600  // Security Stuff
604 
605  // User MIME Type overrides
607 
608  rv |= CopyUserContentSheet();
609  return rv;
610 }
611 
612 nsresult
614 {
615  nsCOMPtr<nsIFile> sourceUserContent;
616  mSourceProfile->Clone(getter_AddRefs(sourceUserContent));
617  sourceUserContent->Append(DIR_NAME_CHROME);
618  sourceUserContent->Append(FILE_NAME_USERCONTENT);
619 
620  PRBool exists = PR_FALSE;
621  sourceUserContent->Exists(&exists);
622  if (!exists)
623  return NS_OK;
624 
625  nsCOMPtr<nsIFile> targetUserContent;
626  mTargetProfile->Clone(getter_AddRefs(targetUserContent));
627  targetUserContent->Append(DIR_NAME_CHROME);
628  nsCOMPtr<nsIFile> targetChromeDir;
629  targetUserContent->Clone(getter_AddRefs(targetChromeDir));
630  targetUserContent->Append(FILE_NAME_USERCONTENT);
631 
632  targetUserContent->Exists(&exists);
633  if (exists)
634  targetUserContent->Remove(PR_FALSE);
635 
636  return sourceUserContent->CopyTo(targetChromeDir, FILE_NAME_USERCONTENT);
637 }
638 
639 nsresult
641 {
642  nsresult rv;
643  if (aReplace)
645  else {
646  nsCOMPtr<nsIFile> seamonkeyCookiesFile;
647  mSourceProfile->Clone(getter_AddRefs(seamonkeyCookiesFile));
648  seamonkeyCookiesFile->Append(FILE_NAME_COOKIES);
649 
650  rv = ImportNetscapeCookies(seamonkeyCookiesFile);
651  }
652  return rv;
653 }
654 
655 nsresult
657 {
658  return aReplace ? CopyFile(FILE_NAME_HISTORY, FILE_NAME_HISTORY) : NS_OK;
659 }
660 
661 nsresult
663 {
664  nsresult rv;
665 
666  nsCString signonsFileName;
667  GetSignonFileName(aReplace, getter_Copies(signonsFileName));
668 
669  if (signonsFileName.IsEmpty())
670  return NS_ERROR_FILE_NOT_FOUND;
671 
672  NS_ConvertASCIItoUTF16 fileName(signonsFileName);
673  if (aReplace)
674  rv = CopyFile(fileName, fileName);
675  else {
676  // Get the password manager, which is the destination for the passwords
677  // being migrated. Also create a new instance of the legacy password
678  // storage component, which we'll use to slurp in the signons from
679  // Seamonkey's signons.txt.
680  nsCOMPtr<nsILoginManager> pwmgr(
681  do_GetService("@mozilla.org/login-manager;1"));
682  nsCOMPtr<nsILoginManagerStorage> importer(
683  do_CreateInstance("@mozilla.org/login-manager/storage/legacy;1"));
684 
685  nsCOMPtr<nsIFile> signonsFile;
686  mSourceProfile->Clone(getter_AddRefs(signonsFile));
687  signonsFile->Append(fileName);
688 
689  importer->InitWithFile(signonsFile, nsnull);
690 
691  PRUint32 count;
692  nsILoginInfo **logins;
693 
694  rv = importer->GetAllLogins(&count, &logins);
695  NS_ENSURE_SUCCESS(rv, rv);
696  for (PRUint32 i = 0; i < count; i++) {
697  pwmgr->AddLogin(logins[i]);
698  }
699  NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
700 
701  PRUnichar **hostnames;
702  rv = importer->GetAllDisabledHosts(&count, &hostnames);
703  NS_ENSURE_SUCCESS(rv, rv);
704  for (PRUint32 i = 0; i < count; i++) {
705  pwmgr->SetLoginSavingEnabled(nsDependentString(hostnames[i]),
706  PR_FALSE);
707  }
708  NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, hostnames);
709  }
710  return rv;
711 }
712 
713 nsresult
715 {
716  nsresult rv;
717  if (aReplace) {
718  // Initialize the default bookmarks
720  NS_ENSURE_SUCCESS(rv, rv);
721 
722  // Merge in the bookmarks from the source profile
723  nsCOMPtr<nsIFile> sourceFile;
724  mSourceProfile->Clone(getter_AddRefs(sourceFile));
725  sourceFile->Append(FILE_NAME_BOOKMARKS);
726  rv = ImportBookmarksHTML(sourceFile, PR_TRUE, PR_FALSE, EmptyString().get());
727  NS_ENSURE_SUCCESS(rv, rv);
728  }
729  else {
731  NS_LITERAL_STRING("sourceNameSeamonkey").get());
732  NS_ENSURE_SUCCESS(rv, rv);
733  }
734  return NS_OK;
735 }
736 
737 nsresult
739 {
741 }
742 
nsresult CopyFile(const nsAString &aSourceFileName, const nsAString &aTargetFileName)
nsresult ImportNetscapeBookmarks(const nsAString &aBookmarksFileName, const PRUnichar *aImportSourceNameKey)
void ReadFontsBranch(nsIPrefService *aPrefService, nsTArray< FontPref > *aPrefs)
nsresult InitializeBookmarks(nsIFile *aTargetProfile)
void WriteFontsBranch(nsIPrefService *aPrefService, nsTArray< FontPref > *aPrefs)
nsresult CopyOtherData(PRBool aReplace)
return NS_OK
#define FILE_NAME_SITEPERM_NEW
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
var pref
Definition: openLocation.js:44
const NS_PREFSERVICE_CONTRACTID
const nsIPrefLocalizedString
#define FILE_NAME_KEY3DB
#define FILE_NAME_SECMODDB
nsresult ImportBookmarksHTML(nsIFile *aBookmarksFile, PRBool aImportIntoRoot, PRBool aOverwriteDefaults, const PRUnichar *aImportSourceNameKey)
nsresult CopyPasswords(PRBool aReplace)
nsresult CopyPreferences(PRBool aReplace)
const nsIPrefBranch
#define FILE_NAME_HISTORY
#define FILE_NAME_USER_PREFS
static nsresult SetImage(void *aTransform, nsIPrefBranch *aBranch)
#define NOTIFY_OBSERVERS(message, item)
#define FILE_NAME_PREFS
#define FILE_NAME_BOOKMARKS
nsresult CopyHistory(PRBool aReplace)
var count
Definition: test_bug7406.js:32
nsresult CopyBookmarks(PRBool aReplace)
#define MIGRATION_STARTED
nsresult GetProfileDataFromRegistry(nsILocalFile *aRegistryFile, nsISupportsArray *aProfileNames, nsISupportsArray *aProfileLocations)
#define FILE_NAME_DOWNLOADS
#define COPY_DATA(func, replace, itemIndex)
nsresult CopyCookies(PRBool aReplace)
#define MIGRATION_ENDED
this _dialogInput val(dateText)
#define FILE_NAME_USERCONTENT
static nsSeamonkeyProfileMigrator::PrefTransform gTransforms[]
#define FILE_NAME_SITEPERM_OLD
nsresult GetSourceProfile(const PRUnichar *aProfile)
PRUnichar * wstringValue
#define MAKESAMETYPEPREFTRANSFORM(pref, method)
var prefs
Definition: FeedWriter.js:1169
#define FILE_NAME_CERT8DB
static nsresult SetCookie(void *aTransform, nsIPrefBranch *aBranch)
#define DIR_NAME_CHROME
void GetProfilePath(nsIProfileStartup *aStartup, nsCOMPtr< nsIFile > &aProfileDir)
nsresult TransformPreferences(const nsAString &aSourcePrefFileName, const nsAString &aTargetPrefFileName)
#define MAKEPREFTRANSFORM(pref, newpref, getmethod, setmethod)
const nsISupportsString
static nsresult SetDownloadManager(void *aTransform, nsIPrefBranch *aBranch)
observe data
Definition: FeedWriter.js:1329
_getSelectedPageStyle s i
#define FILE_NAME_COOKIES
nsresult ImportNetscapeCookies(nsIFile *aCookiesFile)
void GetMigrateDataFromArray(MigrationData *aDataArray, PRInt32 aDataArrayLength, PRBool aReplace, nsIFile *aSourceProfile, PRUint16 *aResult)
#define FILE_NAME_MIMETYPES
nsresult GetSignonFileName(PRBool aReplace, char **aFileName)