Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsPrefMigration.cpp File Reference
#include "pratom.h"
#include "nsIComponentManager.h"
#include "nsIPromptService.h"
#include "nsIServiceManager.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDependentString.h"
#include "nsFileStream.h"
#include "nsIFileSpec.h"
#include "nsCOMPtr.h"
#include "prio.h"
#include "prerror.h"
#include "prmem.h"
#include "nsIPref.h"
#include "plstr.h"
#include "prprf.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIStringBundle.h"
#include "nsProxiedService.h"
#include "nsNetUtil.h"
#include "nsCRT.h"
#include "nsVoidArray.h"
#include "nsIBaseWindow.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWindowWatcher.h"
#include "nsEmbedCID.h"
#include "nsICharsetConverterManager.h"
#include "nsIPlatformCharset.h"
#include "nsPrefMigration.h"
#include "nsPrefMigrationFactory.h"

Go to the source code of this file.

Classes

struct  MigrateProfileItem
struct  PrefEnumerationClosure

Defines

#define CHROME_STYLE   nsIWebBrowserChrome::CHROME_ALL | nsIWebBrowserChrome::CHROME_CENTER_SCREEN
#define MIGRATION_PROPERTIES_URL   "chrome://communicator/locale/profile/migration.properties"
#define PREF_FILE_HEADER_STRING   "# Mozilla User Preferences "
#define MAX_PREF_LEN   1024
#define IMAP_MAIL_FILTER_FILE_NAME_IN_4x   "rules.dat"
#define POP_MAIL_FILTER_FILE_NAME_IN_4x   "rules.dat"
#define MAIL_SUMMARY_SUFFIX_IN_4x   ".snm"
#define NEWS_SUMMARY_SUFFIX_IN_4x   ".snm"
#define COOKIES_FILE_NAME_IN_4x   "cookies.txt"
#define BOOKMARKS_FILE_NAME_IN_4x   "bookmark.htm"
#define PSM_CERT7_DB   "cert7.db"
#define PSM_KEY3_DB   "key3.db"
#define PSM_SECMODULE_DB   "secmod.db"
#define SUMMARY_SUFFIX_IN_5x   ".msf"
#define COOKIES_FILE_NAME_IN_5x   "cookies.txt"
#define IMAP_MAIL_FILTER_FILE_NAME_IN_5x   "rules.dat"
#define POP_MAIL_FILTER_FILE_NAME_IN_5x   "rules.dat"
#define POPSTATE_FILE_IN_5x   "popstate.dat"
#define BOOKMARKS_FILE_NAME_IN_5x   "bookmarks.html"
#define HISTORY_FILE_NAME_IN_5x   "history.dat"
#define PREMIGRATION_PREFIX   "premigration."
#define ADDRBOOK_FILE_EXTENSION_IN_4X   ".na2"
#define PREF_MIGRATION_MODE_FOR_MAIL   "mail.migration.copyMailFiles"
#define PREF_MAIL_DIRECTORY   "mail.directory"
#define PREF_NEWS_DIRECTORY   "news.directory"
#define PREF_MAIL_IMAP_ROOT_DIR   "mail.imap.root_dir"
#define PREF_NETWORK_HOSTS_POP_SERVER   "network.hosts.pop_server"
#define PREF_4X_NETWORK_HOSTS_IMAP_SERVER   "network.hosts.imap_servers"
#define PREF_MAIL_SERVER_TYPE   "mail.server_type"
#define PREF_BROWSER_CACHE_DIRECTORY   "browser.cache.directory"
#define POP_4X_MAIL_TYPE   0
#define IMAP_4X_MAIL_TYPE   1
#define OLD_MAIL_DIR_NAME   "Mail"
#define OLD_NEWS_DIR_NAME   "News"
#define OLD_IMAPMAIL_DIR_NAME   "ImapMail"
#define NEW_DIR_SUFFIX   "5"
#define PREF_FILE_NAME_IN_5x   "prefs.js"
#define PREF_MIGRATION_PROGRESS_URL   "chrome://communicator/content/profile/profileMigrationProgress.xul"

Functions

static NS_DEFINE_IID (kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID)
static NS_DEFINE_CID (kPrefServiceCID, NS_PREF_CID)
static NS_DEFINE_CID (kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID)
static NS_DEFINE_CID (kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID)
PRBool ProfilesToMigrateCleanup (void *aElement, void *aData)
void ProfileMigrationController (void *data)
static PRBool nsCStringEndsWith (nsCString &name, const char *ending)
static nsresult ConvertStringToUTF8 (const char *aCharset, const char *inString, char **outString)
nsresult ConvertPrefToUTF8 (const char *prefname, nsIPref *prefs, const char *charSet)
static PRBool charEndsWith (const char *str, const char *endStr)
static void fontPrefEnumerationFunction (const char *name, void *data)
static void ldapPrefEnumerationFunction (const char *name, void *data)
static void vCardPrefEnumerationFunction (const char *name, void *data)
PRBool convertPref (nsCString &aElement, void *aData)

Variables

static PRThreadgMigrationThread = nsnull
static const char * prefsToConvert []

Class Documentation

struct MigrateProfileItem

Definition at line 217 of file nsPrefMigration.cpp.

Class Members
const char * newFile
const char * oldFile
struct PrefEnumerationClosure

Definition at line 2296 of file nsDogbertProfileMigrator.cpp.

Collaboration diagram for PrefEnumerationClosure:
Class Members
const char * charSet
nsIPref * prefs

Define Documentation

Definition at line 158 of file nsPrefMigration.cpp.

#define BOOKMARKS_FILE_NAME_IN_4x   "bookmark.htm"

Definition at line 135 of file nsPrefMigration.cpp.

#define BOOKMARKS_FILE_NAME_IN_5x   "bookmarks.html"

Definition at line 149 of file nsPrefMigration.cpp.

Definition at line 91 of file nsPrefMigration.cpp.

#define COOKIES_FILE_NAME_IN_4x   "cookies.txt"

Definition at line 134 of file nsPrefMigration.cpp.

#define COOKIES_FILE_NAME_IN_5x   "cookies.txt"

Definition at line 145 of file nsPrefMigration.cpp.

#define HISTORY_FILE_NAME_IN_5x   "history.dat"

Definition at line 150 of file nsPrefMigration.cpp.

Definition at line 188 of file nsPrefMigration.cpp.

Definition at line 130 of file nsPrefMigration.cpp.

Definition at line 146 of file nsPrefMigration.cpp.

Definition at line 132 of file nsPrefMigration.cpp.

#define MAX_PREF_LEN   1024

Definition at line 101 of file nsPrefMigration.cpp.

#define MIGRATION_PROPERTIES_URL   "chrome://communicator/locale/profile/migration.properties"

Definition at line 92 of file nsPrefMigration.cpp.

Definition at line 211 of file nsPrefMigration.cpp.

Definition at line 133 of file nsPrefMigration.cpp.

#define OLD_IMAPMAIL_DIR_NAME   "ImapMail"

Definition at line 208 of file nsPrefMigration.cpp.

#define OLD_MAIL_DIR_NAME   "Mail"

Definition at line 206 of file nsPrefMigration.cpp.

#define OLD_NEWS_DIR_NAME   "News"

Definition at line 207 of file nsPrefMigration.cpp.

Definition at line 187 of file nsPrefMigration.cpp.

Definition at line 131 of file nsPrefMigration.cpp.

Definition at line 147 of file nsPrefMigration.cpp.

#define POPSTATE_FILE_IN_5x   "popstate.dat"

Definition at line 148 of file nsPrefMigration.cpp.

#define PREF_4X_NETWORK_HOSTS_IMAP_SERVER   "network.hosts.imap_servers"

Definition at line 184 of file nsPrefMigration.cpp.

#define PREF_BROWSER_CACHE_DIRECTORY   "browser.cache.directory"

Definition at line 186 of file nsPrefMigration.cpp.

#define PREF_FILE_HEADER_STRING   "# Mozilla User Preferences "

Definition at line 99 of file nsPrefMigration.cpp.

#define PREF_FILE_NAME_IN_5x   "prefs.js"

Definition at line 213 of file nsPrefMigration.cpp.

#define PREF_MAIL_DIRECTORY   "mail.directory"

Definition at line 180 of file nsPrefMigration.cpp.

#define PREF_MAIL_IMAP_ROOT_DIR   "mail.imap.root_dir"

Definition at line 182 of file nsPrefMigration.cpp.

#define PREF_MAIL_SERVER_TYPE   "mail.server_type"

Definition at line 185 of file nsPrefMigration.cpp.

#define PREF_MIGRATION_MODE_FOR_MAIL   "mail.migration.copyMailFiles"

Definition at line 178 of file nsPrefMigration.cpp.

Definition at line 215 of file nsPrefMigration.cpp.

#define PREF_NETWORK_HOSTS_POP_SERVER   "network.hosts.pop_server"

Definition at line 183 of file nsPrefMigration.cpp.

#define PREF_NEWS_DIRECTORY   "news.directory"

Definition at line 181 of file nsPrefMigration.cpp.

#define PREMIGRATION_PREFIX   "premigration."

Definition at line 157 of file nsPrefMigration.cpp.

#define PSM_CERT7_DB   "cert7.db"

Definition at line 139 of file nsPrefMigration.cpp.

#define PSM_KEY3_DB   "key3.db"

Definition at line 140 of file nsPrefMigration.cpp.

#define PSM_SECMODULE_DB   "secmod.db"

Definition at line 141 of file nsPrefMigration.cpp.

Definition at line 144 of file nsPrefMigration.cpp.


Function Documentation

static PRBool charEndsWith ( const char *  str,
const char *  endStr 
) [static]

Definition at line 2404 of file nsPrefMigration.cpp.

{
    PRUint32 endStrLen = PL_strlen(endStr);
    PRUint32 strLen = PL_strlen(str);
    
    if (strLen < endStrLen) return PR_FALSE;

    PRUint32 pos = strLen - endStrLen;
    if (PL_strncmp(str + pos, endStr, endStrLen) == 0) {
        return PR_TRUE;
    }
    else {
        return PR_FALSE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool convertPref ( nsCString aElement,
void aData 
)

Definition at line 2472 of file nsPrefMigration.cpp.

{
  PrefEnumerationClosure *closure;
  closure = (PrefEnumerationClosure *)aData;

  ConvertPrefToUTF8(aElement.get(), closure->prefs, closure->charSet);
  return PR_TRUE;
}

Here is the call graph for this function:

nsresult ConvertPrefToUTF8 ( const char *  prefname,
nsIPref prefs,
const char *  charSet 
)

Definition at line 2371 of file nsPrefMigration.cpp.

{
    nsresult rv;

    if (!prefname || !prefs) return NS_ERROR_FAILURE;
#ifdef DEBUG_UTF8_CONVERSION 
    printf("converting %s to UTF8\n", prefname);
#endif /* DEBUG_UTF8_CONVERSION */
    
    nsXPIDLCString prefval;

    rv = prefs->CopyCharPref(prefname, getter_Copies(prefval));
    if (NS_FAILED(rv)) return rv;

    if (prefval.IsEmpty()) {
        // no need to convert ""
        return NS_OK;
    }

    nsXPIDLCString outval;
    rv = ConvertStringToUTF8(charSet, (const char *)prefval, getter_Copies(outval));
    // only set the pref if the conversion worked, and it convert to something non null
    if (NS_SUCCEEDED(rv) && (const char *)outval && PL_strlen((const char *)outval)) {
#ifdef DEBUG_UTF8_CONVERSION
        printf("converting %s to %s\n",(const char *)prefval, (const char *)outval);
#endif /* DEBUG_UTF8_CONVERSION */
        rv = prefs->SetCharPref(prefname, (const char *)outval);
    }

    return NS_OK;
}

Here is the call graph for this function:

static nsresult ConvertStringToUTF8 ( const char *  aCharset,
const char *  inString,
char **  outString 
) [static]

Definition at line 2328 of file nsPrefMigration.cpp.

{
  if (nsnull == outString)
    return NS_ERROR_NULL_POINTER;

  nsresult rv;
  // convert result to unicode
  nsCOMPtr<nsICharsetConverterManager> ccm = 
           do_GetService(kCharsetConverterManagerCID, &rv);

  if(NS_SUCCEEDED(rv)) {
    nsCOMPtr <nsIUnicodeDecoder> decoder; // this may be cached

    rv = ccm->GetUnicodeDecoderRaw(aCharset, getter_AddRefs(decoder));
    if(NS_SUCCEEDED(rv) && decoder) {
      PRInt32 uniLength = 0;
      PRInt32 srcLength = strlen(inString);
      rv = decoder->GetMaxLength(inString, srcLength, &uniLength);
      if (NS_SUCCEEDED(rv)) {
        PRUnichar *unichars = new PRUnichar [uniLength];

        if (nsnull != unichars) {
          // convert to unicode
          rv = decoder->Convert(inString, &srcLength, unichars, &uniLength);
          if (NS_SUCCEEDED(rv)) {
            nsAutoString aString;
            aString.Assign(unichars, uniLength);
            // convert to UTF-8
            *outString = ToNewUTF8String(aString);
          }
          delete [] unichars;
        }
        else {
          rv = NS_ERROR_OUT_OF_MEMORY;
        }
      }
    }    
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void fontPrefEnumerationFunction ( const char *  name,
void data 
) [static]

Definition at line 2421 of file nsPrefMigration.cpp.

{
  nsCStringArray *arr;
  arr = (nsCStringArray *)data;
#ifdef DEBUG_UTF8_CONVERSION
  printf("fontPrefEnumerationFunction: %s\n", name);
#endif 

  if (charEndsWith(name,".fixed_font") || charEndsWith(name,".prop_font")) {
    nsCString str(name);
    arr->AppendCString(str);
  }
}

Here is the call graph for this function:

static void ldapPrefEnumerationFunction ( const char *  name,
void data 
) [static]

Definition at line 2436 of file nsPrefMigration.cpp.

{
  nsCStringArray *arr;
  arr = (nsCStringArray *)data;
#ifdef DEBUG_UTF8_CONVERSION
  printf("ldapPrefEnumerationFunction: %s\n", name);
#endif 

  // we only want to convert "ldap_2.servers.*.description"
  if (charEndsWith(name,".description")) {
    nsCString str(name);
    arr->AppendCString(str);
  }
}

Here is the call graph for this function:

static NS_DEFINE_CID ( kPrefServiceCID  ,
NS_PREF_CID   
) [static]
static NS_DEFINE_CID ( kCharsetConverterManagerCID  ,
NS_ICHARSETCONVERTERMANAGER_CID   
) [static]
static NS_DEFINE_CID ( kStringBundleServiceCID  ,
NS_STRINGBUNDLESERVICE_CID   
) [static]
static NS_DEFINE_IID ( kProxyObjectManagerCID  ,
NS_PROXYEVENT_MANAGER_CID   
) [static]
static PRBool nsCStringEndsWith ( nsCString name,
const char *  ending 
) [static]

Definition at line 1435 of file nsPrefMigration.cpp.

{
  if (!ending) return PR_FALSE;

  PRInt32 len = name.Length();
  if (len == 0) return PR_FALSE;

  PRInt32 endingLen = PL_strlen(ending);
  if (len > endingLen && name.RFind(ending, PR_TRUE) == len - endingLen) {
        return PR_TRUE;
  }
  else {
        return PR_FALSE;
  }
}

Here is the caller graph for this function:

Definition at line 354 of file nsPrefMigration.cpp.

{
  if (!data) return;

  nsPrefMigration* migrator = (nsPrefMigration*)data;
  nsIPrefMigration* interfaceM = (nsIPrefMigration*)data;
  PRInt32 index = 0;
  PRInt32 choice = 0;
  nsresult rv = NS_OK;

  nsCOMPtr<nsIPrefMigration> prefProxy;

  do {
    
    choice = 0;
    migrator->mErrorCode = 0;
    MigrateProfileItem* item = nsnull;

    if (migrator->mProfilesToMigrate.Count() != 0)
      item = (MigrateProfileItem*)migrator->mProfilesToMigrate.ElementAt(index);
    if (item)
    {
        rv = migrator->ProcessPrefsCallback(item->oldFile, item->newFile);
        if (NS_FAILED(rv))
        {
          migrator->mErrorCode = rv;
#ifdef DEBUG
          printf("failed to migrate properly.  err=%d\n",rv);
#endif
        }
    }
    else
    {
      migrator->mErrorCode = NS_ERROR_FAILURE;
      return;
    }

    nsCOMPtr<nsIProxyObjectManager> pIProxyObjectManager = 
             do_GetService(kProxyObjectManagerCID, &rv);
    if(NS_FAILED(rv))
    {
      migrator->mErrorCode = rv;
      return;
    }
  
    nsCOMPtr<nsIPrefMigration> migratorInterface = do_QueryInterface(interfaceM, &rv);
    if (NS_FAILED(rv))
    {
      migrator->mErrorCode = rv;
      return;
    }

    if (!prefProxy)
    {
        rv = pIProxyObjectManager->GetProxyForObject(NS_UI_THREAD_EVENTQ, 
                                                   NS_GET_IID(nsIPrefMigration), 
                                                   migratorInterface, 
                                                   PROXY_SYNC,
                                                   getter_AddRefs(prefProxy));
        if (NS_FAILED(rv))
        {
          migrator->mErrorCode = rv;
          return;
        }
    }


    if (migrator->mErrorCode != 0)
    {
      if (migrator->mErrorCode == MIGRATION_RETRY)
      {
        rv = prefProxy->ShowSpaceDialog(&choice);
        if (NS_FAILED(rv))
        {
          migrator->mErrorCode = rv;
          return;
        }
        choice++;// Increment choice to match the RETRY=1, CANCEL=2 and CREATE_NEW=3 format
      }
    }

  } while (choice == MIGRATION_RETRY);

  prefProxy->WindowCloseCallback();
  migrator->mErrorCode = choice;

}

Here is the call graph for this function:

PRBool ProfilesToMigrateCleanup ( void aElement,
void aData 
)

Definition at line 273 of file nsPrefMigration.cpp.

{
  if (aElement)
    delete (MigrateProfileItem*)aElement;

  return PR_TRUE;
}

Here is the caller graph for this function:

static void vCardPrefEnumerationFunction ( const char *  name,
void data 
) [static]

Definition at line 2452 of file nsPrefMigration.cpp.

{
  nsCStringArray *arr;
  arr = (nsCStringArray *)data;
#ifdef DEBUG_UTF8_CONVERSION
  printf("vCardPrefEnumerationFunction: %s\n", name);
#endif 

  // the 4.x vCard prefs might need converting
  nsCString str(name);
  arr->AppendCString(str);
}

Variable Documentation

Definition at line 351 of file nsPrefMigration.cpp.

const char* prefsToConvert[] [static]
Initial value:
 {
      "custtoolbar.personal_toolbar_folder",
      "editor.author",
      "li.server.ldap.userbase",
      "mail.identity.organization",
      "mail.identity.username",
      nsnull
}

Definition at line 2305 of file nsPrefMigration.cpp.