User:Brahmana/Downloads Complete Alert Control Flow
Here I assume the state of the download changed to "Download Completed" and hence the nsDownload::OnStateChange() is called. This will call nsDownload::SetState() to carry out necessary action for the new state of the download. It is here that we decide to show the sliding alert based on the value of the corresponding preference: browser.download.manager.showAlertOnComplete. This alert is shown using the nsIAlertService. Here is the code which does that: 
Based on the definition of nsIAlertService here:  and the final function call "alerts->ShowAlertNotification()" tells us that we send the DownloadManager as the listener for any callbacks from the alert service.
Again from the alert service interface definition its clear that for any callbacks it will call the Observe() function of the listener that was passed to it. Further when it needs to do a callback for a click by the user it sends "clickalertcallback" as the topic which brings us back to DownloadManager here:  As seen this code just shows DMUI.
As a side note the complete implementation of nsIDownloadManagerUI is in JS in 
There is nothing interesting happening here. It just uses nsIWindowWatcher to show the downloads window by giving the chrome url of downloads.xul and the windowType attribute value. Now all the action happens when the window loads and by that I mean in the onLoad handler of the DM window which is Startup() present in downloads.js and in particular here: . And the function definition itself is here: 
All of it self-explanative, but one thing to note here is the variable: gUserInteracted. Based on my mxr search this is not used anywhere other than this downloads.js file. And in this file, there is only one assignment which is during initialization where it is set to false. So this variable is probably doomed to be false through out. (I am thinking of making its life better, if I succeed this document must also change).