Bug 540421 Remove unused Windows 9x compatibility code r+sr=bienvenu
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Wed, 20 Jan 2010 12:34:55 +0000
changeset 4725 7c79d282d28dca6320fdbd2e4775c8c974dcdf72
parent 4724 c93c2e58a3feaa0f9528d89db83aeeef4273ecf7
child 4726 fe691eaa03b40be8c5649e47c9faafa6fe16bf33
push id3695
push userneil@parkwaycc.co.uk
push dateWed, 20 Jan 2010 12:35:01 +0000
treeherdercomm-central@7c79d282d28d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs540421
Bug 540421 Remove unused Windows 9x compatibility code r+sr=bienvenu
mailnews/base/src/nsMessengerWinIntegration.cpp
mailnews/base/src/nsMessengerWinIntegration.h
--- a/mailnews/base/src/nsMessengerWinIntegration.cpp
+++ b/mailnews/base/src/nsMessengerWinIntegration.cpp
@@ -78,17 +78,16 @@
 #include "nsNativeCharsetUtils.h"
 
 #include "nsToolkitCompsCID.h"
 #include <stdlib.h>
 #define PROFILE_COMMANDLINE_ARG " -profile "
 
 #define XP_SHSetUnreadMailCounts "SHSetUnreadMailCountW"
 #define XP_SHEnumerateUnreadMailAccounts "SHEnumerateUnreadMailAccountsW"
-#define ShellNotifyWideVersion "Shell_NotifyIconW"
 #define NOTIFICATIONCLASSNAME "MailBiffNotificationMessageWindow"
 #define UNREADMAILNODEKEY "Software\\Microsoft\\Windows\\CurrentVersion\\UnreadMail\\"
 #define SHELL32_DLL NS_LITERAL_CSTRING("shell32.dll")
 #define DOUBLE_QUOTE "\""
 #define MAIL_COMMANDLINE_ARG " -mail"
 #define IDI_MAILBIFF 101
 #define UNREAD_UPDATE_INTERVAL	(20 * 1000)	// 20 seconds
 #define ALERT_CHROME_URL "chrome://messenger/content/newmailalert.xul"
@@ -255,17 +254,16 @@ nsMessengerWinIntegration::nsMessengerWi
   mUnreadTimerActive = PR_FALSE;
   mStoreUnreadCounts = PR_FALSE;
 
   mBiffStateAtom = do_GetAtom("BiffState");
   mBiffIconVisible = PR_FALSE;
   mSuppressBiffIcon = PR_FALSE;
   mAlertInProgress = PR_FALSE;
   mBiffIconInitialized = PR_FALSE;
-  mUseWideCharBiffIcon = PR_FALSE;
   NS_NewISupportsArray(getter_AddRefs(mFoldersWithNewMail));
 }
 
 nsMessengerWinIntegration::~nsMessengerWinIntegration()
 {
   if (mUnreadCountUpdateTimer) {
     mUnreadCountUpdateTimer->Cancel();
     mUnreadCountUpdateTimer = nsnull;
@@ -296,59 +294,44 @@ nsMessengerWinIntegration::ResetCurrent(
 
   mCurrentUnreadCount = -1;
   mLastUnreadCountWrittenToRegistry = -1;
 
   mDefaultAccountMightHaveAnInbox = PR_TRUE;
   return NS_OK;
 }
 
-NOTIFYICONDATA nsMessengerWinIntegration::sNativeBiffIconData = { sizeof(NOTIFYICONDATA),
-                                                    0,
-                                                    2,
-                                                    NIF_ICON | NIF_MESSAGE | NIF_TIP,
-                                                    WM_USER,
-                                                    0,
-                                                    0 };
-
-NOTIFYICONDATAW nsMessengerWinIntegration::sWideBiffIconData = { sizeof(NOTIFYICONDATAW),
-                                                    0,
-                                                    2,
-                                                    NIF_ICON | NIF_MESSAGE | NIF_TIP,
-                                                    WM_USER,
-                                                    0,
-                                                    0 };
+NOTIFYICONDATAW sBiffIconData = { sizeof(NOTIFYICONDATAW),
+                                  0,
+                                  2,
+                                  NIF_ICON | NIF_MESSAGE | NIF_TIP,
+                                  WM_USER,
+                                  0,
+                                  0 };
+// allow for the null terminator
+static const PRUint32 kMaxTooltipSize = sizeof(sBiffIconData.szTip) /
+                                        sizeof(sBiffIconData.szTip[0]) - 1;
 
 #ifdef MOZ_STATIC_BUILD
 #define MAIL_DLL_NAME NULL
 #else
 #ifdef MOZ_STATIC_MAIL_BUILD
 #define MAIL_DLL_NAME "mail.dll"
 #else
 #define MAIL_DLL_NAME "msgbase.dll"
 #endif
 #endif
 
 void nsMessengerWinIntegration::InitializeBiffStatusIcon()
 {
   // initialize our biff status bar icon
   Create();
 
-  if (mUseWideCharBiffIcon)
-  {
-    sWideBiffIconData.hWnd = (HWND) msgWindow;
-    sWideBiffIconData.hIcon =  ::LoadIcon( ::GetModuleHandle( MAIL_DLL_NAME ), MAKEINTRESOURCE(IDI_MAILBIFF) );
-    sWideBiffIconData.szTip[0] = 0;
-  }
-  else
-  {
-    sNativeBiffIconData.hWnd = (HWND) msgWindow;
-    sNativeBiffIconData.hIcon =  ::LoadIcon( ::GetModuleHandle( MAIL_DLL_NAME ), MAKEINTRESOURCE(IDI_MAILBIFF) );
-    sNativeBiffIconData.szTip[0] = 0;
-  }
+  sBiffIconData.hWnd = (HWND) msgWindow;
+  sBiffIconData.hIcon = ::LoadIcon( ::GetModuleHandle( MAIL_DLL_NAME ), MAKEINTRESOURCE(IDI_MAILBIFF) );
 
   mBiffIconInitialized = PR_TRUE;
 }
 
 nsresult
 nsMessengerWinIntegration::Init()
 {
   nsresult rv;
@@ -376,19 +359,16 @@ nsMessengerWinIntegration::Init()
   HMODULE hModule = ::LoadLibrary(mShellDllPath.get());
   if (!hModule)
     return NS_OK;
 
   // get process addresses for the unread mail count functions
   if (hModule) {
     mSHSetUnreadMailCount = (fnSHSetUnreadMailCount)GetProcAddress(hModule, XP_SHSetUnreadMailCounts);
     mSHEnumerateUnreadMailAccounts = (fnSHEnumerateUnreadMailAccounts)GetProcAddress(hModule, XP_SHEnumerateUnreadMailAccounts);
-    mShellNotifyWideChar = (fnShellNotifyW)GetProcAddress(hModule, ShellNotifyWideVersion);
-    if (mShellNotifyWideChar)
-       mUseWideCharBiffIcon = PR_TRUE; // this version of the shell supports I18N friendly ShellNotify routines.
   }
 
   // if failed to get either of the process addresses, this is not XP platform
   // so we aren't storing unread counts
   if (mSHSetUnreadMailCount && mSHEnumerateUnreadMailAccounts)
     mStoreUnreadCounts = PR_TRUE;
 
   nsCOMPtr <nsIMsgAccountManager> accountManager =
@@ -414,21 +394,19 @@ nsMessengerWinIntegration::Init()
                                NS_GET_IID(nsIFile),
                                getter_AddRefs(profilePath));
     NS_ENSURE_SUCCESS(rv,rv);
 
     rv = profilePath->GetPath(mProfilePath);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // get application path
-    char appPath[_MAX_PATH] = {0};
-    GetModuleFileName(nsnull, appPath, sizeof(appPath));
-    WCHAR wideFormatAppPath[_MAX_PATH*2] = {0};
-    MultiByteToWideChar(CP_ACP, 0, appPath, strlen(appPath), wideFormatAppPath, _MAX_PATH*2);
-    mAppName.Assign((PRUnichar *)wideFormatAppPath);
+    WCHAR appPath[_MAX_PATH] = {0};
+    ::GetModuleFileNameW(nsnull, appPath, sizeof(appPath));
+    mAppName.Assign((PRUnichar *)appPath);
 
     rv = ResetCurrent();
     NS_ENSURE_SUCCESS(rv,rv);
   }
 
   return NS_OK;
 }
 
@@ -645,17 +623,16 @@ void nsMessengerWinIntegration::FillTool
   nsAutoString toolTipText;
   nsAutoString animatedAlertText;
   nsCOMPtr<nsIMsgFolder> folder;
   nsCOMPtr<nsIWeakReference> weakReference;
   PRInt32 numNewMessages = 0;
 
   PRUint32 count = 0;
   mFoldersWithNewMail->Count(&count);
-  PRUint32 maxTooltipSize = GetToolTipSize();
 
   for (PRUint32 index = 0; index < count; index++)
   {
     weakReference = do_QueryElementAt(mFoldersWithNewMail, index);
     folder = do_QueryReferent(weakReference);
     if (folder)
     {
       folder->GetPrettiestName(accountName);
@@ -681,29 +658,29 @@ void nsMessengerWinIntegration::FillTool
           bundle->FormatStringFromName(NS_LITERAL_STRING("biffNotification_messages").get(), formatStrings, 1, getter_Copies(finalText));
 
         // the alert message is special...we actually only want to show the first account with
         // new mail in the alert.
         if (animatedAlertText.IsEmpty()) // if we haven't filled in the animated alert text yet
           animatedAlertText = finalText;
 
         // only add this new string if it will fit without truncation....
-        if (maxTooltipSize >= toolTipText.Length() + accountName.Length() + finalText.Length() + 2)
+        if (kMaxTooltipSize >= toolTipText.Length() + accountName.Length() + finalText.Length() + 2)
         {
           if (index > 0)
             toolTipText.Append(PRUnichar('\n'));
           toolTipText.Append(accountName);
           toolTipText.Append(' ');
           toolTipText.Append(finalText);
         }
       } // if we got a bundle
     } // if we got a folder
   } // for each folder
 
-  SetToolTipStringOnIconData(toolTipText.get());
+  ::wcsncpy( sBiffIconData.szTip, toolTipText.get(), kMaxTooltipSize);
 
   if (!mBiffIconVisible)
   {
 #ifndef MOZ_THUNDERBIRD
     ShowAlertMessage(accountName, animatedAlertText, EmptyCString());
 #else
     ShowNewAlertNotification(PR_FALSE);
 #endif
@@ -773,78 +750,19 @@ nsresult nsMessengerWinIntegration::GetF
 }
 
 void nsMessengerWinIntegration::DestroyBiffIcon()
 {
   GenericShellNotify(NIM_DELETE);
   // Don't call DestroyIcon().  see http://bugzilla.mozilla.org/show_bug.cgi?id=134745
 }
 
-PRUint32 nsMessengerWinIntegration::GetToolTipSize()
-{
-  if (mUseWideCharBiffIcon)
-    return (sizeof(sWideBiffIconData.szTip)/sizeof(sWideBiffIconData.szTip[0]));
-  else
-    return (sizeof(sNativeBiffIconData.szTip));
-}
-
-void nsMessengerWinIntegration::SetToolTipStringOnIconData(const PRUnichar * aToolTipString)
-{
-  if (!aToolTipString) return;
-
-  PRUint32 toolTipBufSize = GetToolTipSize();
-
-  if (mUseWideCharBiffIcon)
-  {
-    ::wcsncpy( sWideBiffIconData.szTip, aToolTipString, toolTipBufSize);
-    if (wcslen(aToolTipString) >= toolTipBufSize)
-      sWideBiffIconData.szTip[toolTipBufSize - 1] = 0;
-  }
-  else
-  {
-    nsCAutoString nativeToolTipString;
-    NS_CopyUnicodeToNative(nsDependentString(aToolTipString),
-                           nativeToolTipString);
-    ::strncpy(sNativeBiffIconData.szTip,
-              nativeToolTipString.get(), GetToolTipSize());
-    if (nativeToolTipString.Length() >= toolTipBufSize)
-      sNativeBiffIconData.szTip[toolTipBufSize - 1] = 0;
-  }
-}
-
 void nsMessengerWinIntegration::GenericShellNotify(DWORD aMessage)
 {
-  if (mUseWideCharBiffIcon)
-  {
-    BOOL res = mShellNotifyWideChar( aMessage, &sWideBiffIconData );
-    if (!res)
-      RevertToNonUnicodeShellAPI(); // oops we don't really implement the unicode shell apis...fall back.
-    else
-      return;
-  }
-
-  ::Shell_NotifyIcon( aMessage, &sNativeBiffIconData );
-}
-
-// some flavors of windows define ShellNotifyW but when you actually try to use it,
-// they return an error. In this case, we'll have a routine which converts us over to the
-// default ASCII version.
-void nsMessengerWinIntegration::RevertToNonUnicodeShellAPI()
-{
-  mUseWideCharBiffIcon = PR_FALSE;
-
-  // now initialize the ascii shell notify struct
-  InitializeBiffStatusIcon();
-
-  // now we need to copy over any left over tool tip strings
-  if (sWideBiffIconData.szTip)
-  {
-    const PRUnichar * oldTooltipString = sWideBiffIconData.szTip;
-    SetToolTipStringOnIconData(oldTooltipString);
-  }
+  ::Shell_NotifyIconW( aMessage, &sBiffIconData );
 }
 
 NS_IMETHODIMP
 nsMessengerWinIntegration::OnItemPropertyFlagChanged(nsIMsgDBHdr *item, nsIAtom *property, PRUint32 oldFlag, PRUint32 newFlag)
 {
   return NS_OK;
 }
 
--- a/mailnews/base/src/nsMessengerWinIntegration.h
+++ b/mailnews/base/src/nsMessengerWinIntegration.h
@@ -56,17 +56,16 @@
 #include "nsISupportsArray.h"
 #include "nsIObserver.h"
 
 // this function is exported by shell32.dll version 5.60 or later (Windows XP or greater)
 extern "C"
 {
 typedef HRESULT (__stdcall *fnSHSetUnreadMailCount)(LPCWSTR pszMailAddress, DWORD dwCount, LPCWSTR pszShellExecuteCommand);
 typedef HRESULT (__stdcall *fnSHEnumerateUnreadMailAccounts)(HKEY hKeyUser, DWORD dwIndex, LPCWSTR pszMailAddress, int cchMailAddress);
-typedef BOOL (_stdcall *fnShellNotifyW)(DWORD dwMessage, PNOTIFYICONDATAW lpdata);
 }
 
 #define NS_MESSENGERWININTEGRATION_CID \
   {0xf62f3d3a, 0x1dd1, 0x11b2, \
     {0xa5, 0x16, 0xef, 0xad, 0xb1, 0x31, 0x61, 0x5c}}
 
 class nsIStringBundle; 
 
@@ -87,39 +86,31 @@ public:
 #ifdef MOZ_THUNDERBIRD
   nsresult ShowNewAlertNotification(PRBool aUserInitiated);
 #endif
 
 private:
   nsresult AlertFinished();
   nsresult AlertClicked();
 
-  static NOTIFYICONDATAW sWideBiffIconData; 
-  static NOTIFYICONDATA  sNativeBiffIconData;
-
   void InitializeBiffStatusIcon(); 
   void FillToolTipInfo();
   void GenericShellNotify(DWORD aMessage);
-  void SetToolTipStringOnIconData(const PRUnichar * aToolTipString);
   void DestroyBiffIcon();
-  void RevertToNonUnicodeShellAPI();
 
-  PRUint32 GetToolTipSize(); // available space for the tooltip string
 #ifndef MOZ_THUNDERBIRD
   nsresult ShowAlertMessage(const nsAString& aAlertTitle, const nsAString& aAlertText, const nsACString& aFolderURI);
 #endif
   nsresult GetFirstFolderWithNewMail(nsACString& aFolderURI);
 
   nsresult GetStringBundle(nsIStringBundle **aBundle);
   nsCOMPtr<nsISupportsArray> mFoldersWithNewMail;  // keep track of all the root folders with pending new mail
-  fnShellNotifyW mShellNotifyWideChar;
   nsCOMPtr<nsIAtom> mBiffStateAtom;
   PRUint32 mCurrentBiffState;
 
-  PRPackedBool mUseWideCharBiffIcon; 
   PRPackedBool mStoreUnreadCounts;   // for windows XP, we do a lot of work to store the last unread count for the inbox
                                      // this flag is set to true when we are doing that
   PRPackedBool mBiffIconVisible;
   PRPackedBool mBiffIconInitialized;
   PRPackedBool mSuppressBiffIcon;
   PRPackedBool mAlertInProgress;
   
   // "might" because we don't know until we check