Bug 402520 - Notify Mac OS X when a download finishes so it can make the downloads stack bounce when appropriate. r=sdwilsh, r=josh
authorMarkus Stange <mstange@themasta.com>
Wed, 27 Jan 2010 17:48:18 +0100
changeset 37546 19b64e822f0472145266b4f9d68b2749bc56f0e6
parent 37545 36d5350db6c8dc954e47af60d8f37fd29c373344
child 37547 869030a735da35b28a9597cfe81bab3373e3e145
push id11370
push usermstange@themasta.com
push dateWed, 27 Jan 2010 16:49:13 +0000
treeherdermozilla-central@19b64e822f04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh, josh
bugs402520
milestone1.9.3a1pre
Bug 402520 - Notify Mac OS X when a download finishes so it can make the downloads stack bounce when appropriate. r=sdwilsh, r=josh
toolkit/components/downloads/src/nsDownloadManager.cpp
--- a/toolkit/components/downloads/src/nsDownloadManager.cpp
+++ b/toolkit/components/downloads/src/nsDownloadManager.cpp
@@ -71,16 +71,20 @@
 
 #if defined(XP_WIN) && !defined(WINCE)
 #include <shlobj.h>
 #ifdef DOWNLOAD_SCANNER
 #include "nsDownloadScanner.h"
 #endif
 #endif
 
+#ifdef XP_MACOSX
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
 #define DOWNLOAD_MANAGER_BUNDLE "chrome://mozapps/locale/downloads/downloads.properties"
 #define DOWNLOAD_MANAGER_ALERT_ICON "chrome://mozapps/skin/downloads/downloadIcon.png"
 #define PREF_BDM_SHOWALERTONCOMPLETE "browser.download.manager.showAlertOnComplete"
 #define PREF_BDM_SHOWALERTINTERVAL "browser.download.manager.showAlertInterval"
 #define PREF_BDM_RETENTION "browser.download.manager.retention"
 #define PREF_BDM_QUITBEHAVIOR "browser.download.manager.quitBehavior"
 #define PREF_BDM_ADDTORECENTDOCS "browser.download.manager.addToRecentDocs"
 #define PREF_BDM_SCANWHENDONE "browser.download.manager.scanWhenDone"
@@ -2188,39 +2192,52 @@ nsDownload::SetState(DownloadState aStat
               // the items they downloaded will have been removed.
               alerts->ShowAlertNotification(
                   NS_LITERAL_STRING(DOWNLOAD_MANAGER_ALERT_ICON), title,
                   message, !removeWhenDone, EmptyString(), mDownloadManager,
                   EmptyString());
             }
         }
       }
-#if defined(XP_WIN) && !defined(WINCE)
+#if (defined(XP_WIN) && !defined(WINCE)) || defined(XP_MACOSX)
       nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mTarget);
       nsCOMPtr<nsIFile> file;
       nsAutoString path;
 
       if (fileURL &&
           NS_SUCCEEDED(fileURL->GetFile(getter_AddRefs(file))) &&
           file &&
           NS_SUCCEEDED(file->GetPath(path))) {
 
+#ifdef XP_WIN
         // On windows, add the download to the system's "recent documents"
         // list, with a pref to disable.
         {
           PRBool addToRecentDocs = PR_TRUE;
           if (pref)
             pref->GetBoolPref(PREF_BDM_ADDTORECENTDOCS, &addToRecentDocs);
 
           if (addToRecentDocs &&
               !nsDownloadManager::gDownloadManagerService->mInPrivateBrowsing)
             ::SHAddToRecentDocs(SHARD_PATHW, path.get());
         }
+#endif
+#ifdef XP_MACOSX
+        // On OS X, make the downloads stack bounce.
+        CFStringRef observedObject = ::CFStringCreateWithCString(kCFAllocatorDefault,
+                                             NS_ConvertUTF16toUTF8(path).get(),
+                                             kCFStringEncodingUTF8);
+        CFNotificationCenterRef center = ::CFNotificationCenterGetDistributedCenter();
+        ::CFNotificationCenterPostNotification(center, CFSTR("com.apple.DownloadFileFinished"),
+                                               observedObject, NULL, TRUE);
+        ::CFRelease(observedObject);
+#endif
       }
 
+#ifdef XP_WIN
       // Adjust file attributes so that by default, new files are indexed
       // by desktop search services. Skip off those that land in the temp
       // folder.
       nsCOMPtr<nsIFile> tempDir, fileDir;
       rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tempDir));
       NS_ENSURE_SUCCESS(rv, rv);
       (void)file->GetParent(getter_AddRefs(fileDir));
 
@@ -2228,16 +2245,17 @@ nsDownload::SetState(DownloadState aStat
       if (fileDir)
         (void)fileDir->Equals(tempDir, &isTemp);
 
       nsCOMPtr<nsILocalFileWin> localFileWin(do_QueryInterface(file));
       if (!isTemp && localFileWin)
         (void)localFileWin->SetFileAttributesWin(nsILocalFileWin::WFA_SEARCH_INDEXED);
 
 #endif
+#endif
       // Now remove the download if the user's retention policy is "Remove when Done"
       if (mDownloadManager->GetRetentionBehavior() == 0)
         mDownloadManager->RemoveDownload(mID);
     }
     break;
   default:
     break;
   }