Bug 715129 - File picker can't pick applications on Vista or later r=jimm, a=akeybl
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Mon, 09 Jan 2012 08:05:16 -0600
changeset 84869 c6e163903f18a133595f788952a3cc7605fad19c
parent 84868 f826346fc7a0188edd94e3f1a44a0189908198a4
child 84870 9f80f3664500ac40da99f0ee65e8f1b51c5892cd
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, akeybl
bugs715129
milestone11.0a2
Bug 715129 - File picker can't pick applications on Vista or later r=jimm, a=akeybl
widget/src/windows/nsFilePicker.cpp
widget/src/windows/nsFilePicker.h
--- a/widget/src/windows/nsFilePicker.cpp
+++ b/widget/src/windows/nsFilePicker.cpp
@@ -1335,31 +1335,34 @@ nsFilePicker::IsDefaultPathHtml()
       return true;
   }
   return false;
 }
 
 void
 nsFilePicker::ComDlgFilterSpec::Append(const nsAString& aTitle, const nsAString& aFilter)
 {
-  PRUint32 size = sizeof(COMDLG_FILTERSPEC);
-  PRUint32 hdrLen = size * (mLength + 1);
-  mSpecList = (COMDLG_FILTERSPEC*)realloc(mSpecList, hdrLen);
-  if (!mSpecList) {
+  COMDLG_FILTERSPEC* pSpecForward = mSpecList.AppendElement();
+  if (!pSpecForward) {
     NS_WARNING("mSpecList realloc failed.");
     return;
   }
-  COMDLG_FILTERSPEC* pSpecForward = (COMDLG_FILTERSPEC*)(mSpecList + mLength);
-  memset(pSpecForward, 0, size);
+  memset(pSpecForward, 0, sizeof(*pSpecForward));
   nsString* pStr = mStrings.AppendElement(aTitle);
   if (!pStr) {
     NS_WARNING("mStrings.AppendElement failed.");
     return;
   }
   pSpecForward->pszName = pStr->get();
   pStr = mStrings.AppendElement(aFilter);
   if (!pStr) {
     NS_WARNING("mStrings.AppendElement failed.");
     return;
   }
+  if (aFilter.EqualsLiteral("..apps"))
+    pStr->AssignLiteral("*.exe;*.com");
+  else {
+    pStr->StripWhitespace();
+    if (pStr->EqualsLiteral("*"))
+      pStr->AppendLiteral(".*");
+  }
   pSpecForward->pszSpec = pStr->get();
-  mLength++;
 }
--- a/widget/src/windows/nsFilePicker.h
+++ b/widget/src/windows/nsFilePicker.h
@@ -155,40 +155,35 @@ protected:
   nsString               mUnicodeFile;
   static PRUnichar      *mLastUsedUnicodeDirectory;
   HWND                   mDlgWnd;
 
 #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
   class ComDlgFilterSpec
   {
   public:
-    ComDlgFilterSpec() :
-      mSpecList(nsnull),
-      mLength(0) {}
-    ~ComDlgFilterSpec() {
-      free(mSpecList);
-    }
+    ComDlgFilterSpec() {}
+    ~ComDlgFilterSpec() {}
     
     const PRUint32 Length() {
-      return mLength;
+      return mSpecList.Length();
     }
 
     const bool IsEmpty() {
-      return (mLength == 0);
+      return (mSpecList.Length() == 0);
     }
 
     const COMDLG_FILTERSPEC* get() {
-      return mSpecList;
+      return mSpecList.Elements();
     }
     
     void Append(const nsAString& aTitle, const nsAString& aFilter);
   private:
-    COMDLG_FILTERSPEC* mSpecList;
+    nsAutoTArray<COMDLG_FILTERSPEC, 1> mSpecList;
     nsAutoTArray<nsString, 2> mStrings;
-    PRUint32 mLength;
   };
 
   ComDlgFilterSpec       mComFilterList;
   DWORD                  mFDECookie;
 #endif
 };
 
 #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN