Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes
nsWindowsShellService Class Reference

#include <nsMailWinIntegration.h>

Inheritance diagram for nsWindowsShellService:
Inheritance graph
[legend]
Collaboration diagram for nsWindowsShellService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsWindowsShellService ()
virtual ~nsWindowsShellService ()
 NS_HIDDEN_ (nsresult) Init()
boolean isDefaultClient (in boolean aStartupCheck, in unsigned short aApps)
 Determines whether or not Thunderbird is the "Default Client" for the passed in app type.
void setDefaultClient (in boolean aForAllUsers, in unsigned short aApps)
 Registers Thunderbird as the "Default Mail Client" for the passed in app type.

Public Attributes

const unsigned short MAIL = 0x0001
 app types we can be registered to handle
const unsigned short NEWS = 0x0002
const unsigned short RSS = 0x0004
attribute boolean shouldCheckDefaultClient
 Used to determine whether or not to show a "Set Default Client" query dialog.

Protected Member Functions

void SetRegKey (const char *aKeyName, const char *aValueName, const char *aValue, PRBool aHKLMOnly)
DWORD DeleteRegKey (HKEY baseKey, const char *keyName)
DWORD DeleteRegKeyDefaultValue (HKEY baseKey, const char *keyName)
PRBool TestForDefault (SETTING aSettings[], PRInt32 aSize)
void setKeysForSettings (SETTING aSettings[], PRInt32 aSize, const char *aAppname)
nsresult setDefaultMail ()
nsresult setDefaultNews ()
PRBool IsDefaultClientVista (PRBool aStartupCheck, PRUint16 aApps, PRBool *aIsDefaultClient)
PRBool SetDefaultClientVista (PRUint16 aApps)

Private Attributes

PRBool mCheckedThisSession
nsCString mAppLongPath
nsCString mAppShortPath
nsCString mMapiDLLPath
nsCString mUninstallPath
nsXPIDLString mBrandFullName
nsXPIDLString mBrandShortName

Detailed Description

Definition at line 60 of file nsMailWinIntegration.h.


Constructor & Destructor Documentation

Definition at line 303 of file nsMailWinIntegration.cpp.

virtual nsWindowsShellService::~nsWindowsShellService ( ) [inline, virtual]

Definition at line 64 of file nsMailWinIntegration.h.

{};

Member Function Documentation

DWORD nsWindowsShellService::DeleteRegKey ( HKEY  baseKey,
const char *  keyName 
) [protected]

Definition at line 487 of file nsMailWinIntegration.cpp.

{
 // Make sure input subkey isn't null. 
 if (!keyName || !::strlen(keyName))
   return ERROR_BADKEY;

 DWORD rc;
 // Open subkey.
 HKEY key;
 rc = ::RegOpenKeyEx(baseKey, keyName, 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &key);
 
 // Continue till we get an error or are done.
 while (rc == ERROR_SUCCESS) 
 {
   char subkeyName[_MAX_PATH];
   DWORD len = sizeof subkeyName;
   // Get first subkey name.  Note that we always get the
   // first one, then delete it.  So we need to get
   // the first one next time, also.
   rc = ::RegEnumKeyEx(key, 0, subkeyName, &len, 0, 0, 0, 0);
   if (rc == ERROR_NO_MORE_ITEMS) 
   {
     // No more subkeys.  Delete the main one.
     rc = ::RegDeleteKey(baseKey, keyName);
     break;
   } 
   if (rc == ERROR_SUCCESS) 
   {
     // Another subkey, delete it, recursively.
     rc = DeleteRegKey(key, subkeyName);
   }
 }
 
 // Close the key we opened.
 ::RegCloseKey(key);
 return rc;
}
DWORD nsWindowsShellService::DeleteRegKeyDefaultValue ( HKEY  baseKey,
const char *  keyName 
) [protected]

Definition at line 334 of file nsMailWinIntegration.cpp.

{
  HKEY key;
  DWORD rc = ::RegOpenKeyEx(baseKey, keyName, 0, KEY_WRITE, &key);
  if (rc == ERROR_SUCCESS) {
    rc = ::RegDeleteValue(key, "");
    ::RegCloseKey(key);
  }
  return rc;
}
boolean nsIShellService::isDefaultClient ( in boolean  aStartupCheck,
in unsigned short  aApps 
) [inherited]

Determines whether or not Thunderbird is the "Default Client" for the passed in app type.

This is simply whether or not Thunderbid is registered to handle the url scheme associatd with the app.

Parameters:
aStartupChecktrue if this is the check being performed by the first mail window at startup, false otherwise.
aAppsthe application types being tested (Mail, News, RSS, etc.)
PRBool nsWindowsShellService::IsDefaultClientVista ( PRBool  aStartupCheck,
PRUint16  aApps,
PRBool aIsDefaultClient 
) [protected]

Definition at line 693 of file nsMailWinIntegration.cpp.

{
  IApplicationAssociationRegistration* pAAR;

  HRESULT hr = CoCreateInstance (CLSID_ApplicationAssociationReg,
                                 NULL,
                                 CLSCTX_INPROC,
                                 IID_IApplicationAssociationReg,
                                 (void**)&pAAR);
  
  if (SUCCEEDED(hr))
  {
    PRBool isDefaultMail = PR_TRUE;
    PRBool isDefaultNews = PR_TRUE;
    if (aApps & nsIShellService::MAIL)
      pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME_MAIL, &isDefaultMail);
    if (aApps & nsIShellService::NEWS)
      pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME_NEWS, &isDefaultNews);

    *aIsDefaultClient = isDefaultNews && isDefaultMail;    
    
    // If this is the first mail window, maintain internal state that we've
    // checked this session (so that subsequent window opens don't show the 
    // default browser dialog).
    if (aStartupCheck)
      mCheckedThisSession = PR_TRUE;
    
    pAAR->Release();
    return PR_TRUE;
  }
  
  return PR_FALSE;
}
void nsIShellService::setDefaultClient ( in boolean  aForAllUsers,
in unsigned short  aApps 
) [inherited]

Registers Thunderbird as the "Default Mail Client" for the passed in app type.

Parameters:
aForAllUsersWhether or not Thunderbird should attempt to become the default client for all users on a multi-user system.
aAppsthe application types being tested (Mail, News, RSS, etc.)

Definition at line 728 of file nsMailWinIntegration.cpp.

{
  IApplicationAssociationRegistration* pAAR;

  HRESULT hr = CoCreateInstance (CLSID_ApplicationAssociationReg,
                                 NULL,
                                 CLSCTX_INPROC,
                                 IID_IApplicationAssociationReg,
                                 (void**)&pAAR);
  
  if (SUCCEEDED(hr))
  {
    if (aApps & nsIShellService::MAIL)
      hr = pAAR->SetAppAsDefaultAll(APP_REG_NAME_MAIL);
    if (aApps & nsIShellService::NEWS)
      hr = pAAR->SetAppAsDefaultAll(APP_REG_NAME_NEWS);   
    
    pAAR->Release();
    return PR_TRUE;
  }
  
  return PR_FALSE;
}

Definition at line 415 of file nsMailWinIntegration.cpp.

{
  nsresult rv;
  NS_ConvertUTF16toUTF8 appName(mBrandFullName);
  setKeysForSettings(gMailSettings, sizeof(gMailSettings)/sizeof(SETTING), appName.get());

  // at least for now, this key needs to be written to HKLM instead of HKCU 
  // which is where the windows operating system looks (at least on Win XP and earlier)
  SetRegKey(NS_LITERAL_CSTRING(MOZ_CLIENT_MAIL_KEY).get(), "", appName.get(), PR_TRUE);

  nsCAutoString nativeFullName;
  // For now, we use 'A' APIs (see bug 240272, 239279)
  NS_CopyUnicodeToNative(mBrandFullName, nativeFullName);

  nsCAutoString key1(NS_LITERAL_CSTRING(MAILCLIENTS));
  key1.Append(appName);
  key1.Append("\\");
  SetRegKey(key1.get(), "", nativeFullName.get(), PR_TRUE);

  // Set the Options and Safe Mode start menu context menu item labels
  nsCOMPtr<nsIStringBundle> bundle;
  nsCOMPtr<nsIStringBundleService> bundleService(do_GetService("@mozilla.org/intl/stringbundle;1", &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = bundleService->CreateBundle("chrome://messenger/locale/shellservice.properties", getter_AddRefs(bundle));
  NS_ENSURE_SUCCESS(rv, rv);
  nsCAutoString optionsKey(NS_LITERAL_CSTRING(MAILCLIENTS "%APPNAME%\\shell\\properties"));
  optionsKey.ReplaceSubstring("%APPNAME%", appName.get());

  const PRUnichar* brandNameStrings[] = { mBrandShortName.get() };

  // Set the Options menu item
  nsXPIDLString optionsTitle;
  bundle->FormatStringFromName(NS_LITERAL_STRING("optionsLabel").get(),
                               brandNameStrings, 1, getter_Copies(optionsTitle));
  // Set the registry keys
  nsCAutoString nativeTitle;
  // For the now, we use 'A' APIs (see bug 240272,  239279)
  NS_CopyUnicodeToNative(optionsTitle, nativeTitle);
  SetRegKey(optionsKey.get(), "", nativeTitle.get(), PR_TRUE);
#ifndef __MINGW32__
  // Tell the MAPI Service to register the mapi proxy dll now that we are the default mail application
  nsCOMPtr<nsIMapiSupport> mapiService (do_GetService(NS_IMAPISUPPORT_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);
  return mapiService->RegisterServer();
#else
  return NS_OK;
#endif
}

Here is the call graph for this function:

Definition at line 466 of file nsMailWinIntegration.cpp.

{
  NS_ConvertUTF16toUTF8 appName(mBrandFullName);
  setKeysForSettings(gNewsSettings, sizeof(gNewsSettings)/sizeof(SETTING), appName.get());

  // at least for now, this key needs to be written to HKLM instead of HKCU 
  // which is where the windows operating system looks (at least on Win XP and earlier)
  SetRegKey(NS_LITERAL_CSTRING(MOZ_CLIENT_NEWS_KEY).get(), "", appName.get(), PR_TRUE);

  nsCAutoString nativeFullName;
  // For now, we use 'A' APIs (see bug 240272, 239279)
  NS_CopyUnicodeToNative(mBrandFullName, nativeFullName);
  nsCAutoString key1(NS_LITERAL_CSTRING(NEWSCLIENTS));
  key1.Append(appName);
  key1.Append("\\");
  SetRegKey(key1.get(), "", nativeFullName.get(), PR_TRUE);
  return NS_OK;
}

Here is the call graph for this function:

void nsWindowsShellService::setKeysForSettings ( SETTING  aSettings[],
PRInt32  aSize,
const char *  aAppname 
) [protected]

Definition at line 612 of file nsMailWinIntegration.cpp.

{
  SETTING* settings;
  SETTING* end = aSettings + aSize;
  PRInt32 offset;

  for (settings = aSettings; settings < end; ++settings) 
  {
    nsCAutoString data(settings->valueData);
    nsCAutoString key(settings->keyName);
    if (settings->flags & APP_PATH_SUBSTITUTION) 
    {
      offset = data.Find("%APPPATH%");
      data.Replace(offset, 9, mAppLongPath);
    }
    if (settings->flags & MAPIDLL_PATH_SUBSTITUTION) 
    {
      offset = data.Find("%MAPIDLLPATH%");
      data.Replace(offset, 13, mMapiDLLPath);
    }
    if (settings->flags & APPNAME_SUBSTITUTION) 
    {
      offset = key.Find("%APPNAME%");
      key.Replace(offset, 9, aAppName);
    }
    if (settings->flags & UNINST_PATH_SUBSTITUTION) 
    {
      offset = data.Find("%UNINSTPATH%"); 
      data.Replace(offset, 12, mUninstallPath);
    }

    SetRegKey(key.get(), settings->valueName, data.get(), settings->flags & HKLM_ONLY);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsWindowsShellService::SetRegKey ( const char *  aKeyName,
const char *  aValueName,
const char *  aValue,
PRBool  aHKLMOnly 
) [protected]

Definition at line 526 of file nsMailWinIntegration.cpp.

{
  char buf[MAX_BUF];
  DWORD len = sizeof buf;

  HKEY theKey;
  nsresult rv = OpenKeyForWriting(HKEY_LOCAL_MACHINE, aKeyName, &theKey, aHKLMOnly);
  if (NS_FAILED(rv))
    return;

  // Get the old value
  DWORD result = ::RegQueryValueEx(theKey, aValueName, NULL, NULL, (LPBYTE)buf, &len);

  // Set the new value
  if (REG_FAILED(result) || strcmp(buf, aValue) != 0)
    ::RegSetValueEx(theKey, aValueName, 0, REG_SZ, 
                    (LPBYTE)aValue, nsDependentCString(aValue).Length());
  
  // Close the key we opened.
  ::RegCloseKey(theKey);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsWindowsShellService::TestForDefault ( SETTING  aSettings[],
PRInt32  aSize 
) [protected]

Definition at line 554 of file nsMailWinIntegration.cpp.

{
  PRBool isDefault = PR_TRUE;
  NS_ConvertUTF16toUTF8 appName(mBrandFullName);
  char currValue[MAX_BUF];
  SETTING* end = aSettings + aSize;
  for (SETTING * settings = aSettings; settings < end; ++settings) 
  {
    if (settings->flags & USE_FOR_DEFAULT_TEST)
    {
      nsCAutoString dataLongPath(settings->valueData);
      nsCAutoString dataShortPath(settings->valueData);
      if (settings->flags & APP_PATH_SUBSTITUTION) {
        PRInt32 offset = dataLongPath.Find("%APPPATH%");
        dataLongPath.Replace(offset, 9, mAppLongPath);
        // Remove the quotes around %APPPATH% in VAL_OPEN for short paths
        PRInt32 offsetQuoted = dataShortPath.Find("\"%APPPATH%\"");
        if (offsetQuoted != -1)
          dataShortPath.Replace(offsetQuoted, 11, mAppShortPath);
        else
          dataShortPath.Replace(offset, 9, mAppShortPath);
      }
      
      nsCAutoString key(settings->keyName);
      if (settings->flags & APPNAME_SUBSTITUTION) 
      {
        PRInt32 offset = key.Find("%APPNAME%");
        key.Replace(offset, 9, appName);
      }

      ::ZeroMemory(currValue, sizeof(currValue));
      HKEY theKey;
      nsresult rv = OpenUserKeyForReading(HKEY_CURRENT_USER, key.get(), &theKey);
      if (NS_SUCCEEDED(rv)) 
      {
        DWORD len = sizeof currValue;
        DWORD result = ::RegQueryValueEx(theKey, settings->valueName, NULL, NULL, (LPBYTE)currValue, &len);
        // Close the key we opened.
        ::RegCloseKey(theKey);
        if (REG_FAILED(result) || !dataLongPath.EqualsIgnoreCase(currValue) && !dataShortPath.EqualsIgnoreCase(currValue))
        {
          // Key wasn't set, or was set to something else (something else became the default client)
          isDefault = PR_FALSE;
          break;
        }
      }
    }
  }  // for each registry key we want to look at

  return isDefault;
}

Here is the call graph for this function:


Member Data Documentation

const unsigned short nsIShellService::MAIL = 0x0001 [inherited]

app types we can be registered to handle

Definition at line 47 of file nsIShellService.idl.

Definition at line 87 of file nsMailWinIntegration.h.

Definition at line 88 of file nsMailWinIntegration.h.

Definition at line 91 of file nsMailWinIntegration.h.

Definition at line 92 of file nsMailWinIntegration.h.

Definition at line 86 of file nsMailWinIntegration.h.

Definition at line 89 of file nsMailWinIntegration.h.

Definition at line 90 of file nsMailWinIntegration.h.

const unsigned short nsIShellService::NEWS = 0x0002 [inherited]

Definition at line 48 of file nsIShellService.idl.

const unsigned short nsIShellService::RSS = 0x0004 [inherited]

Definition at line 49 of file nsIShellService.idl.

Used to determine whether or not to show a "Set Default Client" query dialog.

This attribute is true if the application is starting up and "mail.shell.checkDefaultClient" is true, otherwise it is false.

Definition at line 82 of file nsIShellService.idl.


The documentation for this class was generated from the following files: