Mozilla One -- Hacking File/Save

At the highest level, that is, at the level when you first click "Save as" from the browser's File drop down menu, a function called savePage is called. This function can be found in the file mozilla/xpfe/browser/resources/content/navigator.js. The javascript functions contained within this file are where all the initial event handling routines are computed when the user does some action in the browser. The function has the following prototype:

function savePage( url ); 

Quite simply, it will save the given URL to a location on the local disk. The actual transferring of information from the remote site to the local fixed disk as well as the prompting of the user for a location on the fixed drive are all handled by lower level functions in the C++ portion of the browser's code. So, this savePage function calls these lower level functions to actually do the save.

The C++ function that is called from the javascript savePage function above is called SelectFileAndTransferLocationSpec. This function can be found in the file mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp. The function is a member of the nsStreamTransfer class, and has the following prototype:
NS_IMETHODIMP
nsStreamTransfer::SelectFileAndTransferLocationSpec(char const *aURL,
                                               nsIDOMWindow *parent)

This function initializes an outFile and then calls SelectFileAndTranserLocation, which is another member of the nsStreamTransfer class and has the following prototype:

NS_IMETHODIMP nsStreamTransfer::SelectFileAndTransferLocation(
nsIChannel *aChannel, nsIDOMWindow *parent, nsIFileSpec *outFile)

This function is the one that does most of the work. First, it calls SelectFile, a function in this class that will pop up the Save As dialog box and return the path that the user selected. SelectFile has the following prototype:

NS_IMETHODIMP
nsStreamTransfer::SelectFile( nsIFileSpec **aResult, const nsCString 
                              &suggested )

After this is called from SelectFileAndTransferLocation, it will use the stream transferring functions to do the transferring of information from the remote location to the local location. This transferring is begun when it calls the OpenDialog function which goes into deeper levels of code and pops up a progress meter while it transfers the data.

Note that the header (.h) files for these functions are generated at compile time by the file nsIStreamTranser.idl which can be found in mozilla/xpfe/components/xfer/public/.
Mozilla One
Last modified: Thu Apr 6 21:05:02 EDT 2000