Bug 715129 File picker can't pick applications on Vista or later r=jimm
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Wed, 04 Jan 2012 20:30:57 +0000
changeset 84966 3ec9d653933557e4fb1635deca2c39fcbc999b61
parent 84965 0735adef851b76e86719f3751167f20e068cb468
child 84988 bc1196840c427c6212743e79f71c066fbed69f47
push idunknown
push userunknown
push dateunknown
reviewersjimm
bugs715129
milestone12.0a1
Bug 715129 File picker can't pick applications on Vista or later r=jimm
widget/windows/nsFilePicker.cpp
widget/windows/nsFilePicker.h
--- a/widget/windows/nsFilePicker.cpp
+++ b/widget/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/windows/nsFilePicker.h
+++ b/widget/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