Warning: The content of this article may be out of date. It was last updated in 2002.
Bird's Eye View
Flow of control
-
URILoader
tries to find a content listener for the MIME type in question. - When this fails,
URILoader
asks annsIExternalHelperAppService
to handle the load. - The
nsExternalHelperAppService
looks up thensIMIMEInfo
for the load and creates annsIHelperAppLauncher
to manage the load. - The
nsExternalAppHandler
(which implementsnsIHelperAppLauncher
) uses thensIMIMEInfo
and annsIHelperAppLauncherDialog
to decide what to do with the data. - The
nsExternalAppHandler
does whatever it decided to do.
nsIMIMEInfo
lookup
- Look in built-in list which the user cannot override (types we handle internally).
- Look in user preferences.
- Ask the OS:
- Registry on Windows.
- Internet Config on the Mac.
-
mailcap
/mime.types
on Linux.
- Look in second built-in list, which the user can override.
nsExternalAppHandler
details
- Implements
nsIStreamListener
. - Gets notifications from Necko as the data comes in.
- Four primary tasks:
- Sets up temporary file and instantiate the
nsIHelperAppLauncherDialog
inOnStartRequest
. - Puts the data in the file as
OnDataAvailable
notifications come in. - Knows how to launch a helper application on the data based on the
nsIMIMEInfo
. - Knows how to save the data to disk at a given location if the user decides to do so.
- Sets up temporary file and instantiate the
nsExternalAppHandler::OnStartRequest
- Creates a temporary file with a salted name to hold the data.
- Decides on a suggested filename for the data in case it will be saved.
- Decides whether the data should be content-decoded (based on some not-so-great heuristics).
- Decides whether the user should be prompted (based on a preference).
- Calls
Show()
on thensIHelperAppLauncherDialog
, which asynchronously puts up the helper app dialog.
nsExternalAppHandler::OnDataAvailable
- Here we just copy the newly arrived data over into our temporary file.
- If any read or write errors occur, abort the whole process:
- Cancel the channel.
- Pull down the helper app dialog (if any).
- Remove the temp file.
nsExternalAppHandler::OnStopRequest
Set a flag that we're done, then do whatever the user wants if the user has decided (save to disk and open in helper are the current options the user has).
Helper App dialog
This is our implementation of nsIHelperAppLauncherDialog
It calls back to the nsExternalAppHandler
to let it know what the user picked
Saving to disk
If a user decides to "save to disk", we just move/copy the temporary file over to the chosen location once the download completes. If an error occurs while we do this we delete the temp file and put up an error dialog.
Launching a helper application
This is delegated to the nsPIExternalAppLauncher
(also implemented by the nsExternalHelperAppHandler
):
- Windows: launch either directly via
nsIProcess
or via the::ShellExecute()
method depending on where the MIMEInfo came from. Last-ditch check for executable files here. - Mac: use the
LaunchWithDoc()
method onnsILocalFileMac
. - Unix: launch directly via
nsIProcess
.
Security considerations
Multiple checks for whether a file is executable (on Windows) to keep from launching such files via ::ShellExecute()
. Checks happen in OnStartRequest
, in the helper app dialog, and as a last ditch in the launching code.
Limitations of nsIMIMEInfo
- No way to say "do whatever the OS default is."
- No support for command-line arguments.
- No support for multiple commands connected by pipes (mostly useful on Unix).
Ongoing work
- Support synchronous dialogs, not just asynchronous ones (fixes many issues related to pre-downloading, content-decoding, etc).
- Reworking the
nsIMIMEService
API to improve the quality of the MIMEInfo we get. - Reworking the helper app dialog to save user choices better.
- GNOME integration for Unix.
Future work
- Fix the deficiencies in
nsIMIMEInfo
. - Better support for
mailcap
syntax. - Possible KDE integration.
- Possibly reflecting the OS settings in our helper app preferences (readonly? writable?).
- Have a way for users to override things in the "not overridable" built-in list.
Original Document Information
- Author(s): Boris Zbarsky
- Last Updated Date: September 12, 2002
- Copyright Information: Portions of this content are © 1998–2007 by individual mozilla.org contributors; content available under a Creative Commons license | Details.