Blame uriloader/exthandler/nsExternalHelperAppService.h

Packit f0b94e
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
Packit f0b94e
 * This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
#ifndef nsExternalHelperAppService_h__
Packit f0b94e
#define nsExternalHelperAppService_h__
Packit f0b94e
Packit f0b94e
#include "mozilla/Logging.h"
Packit f0b94e
#include "prtime.h"
Packit f0b94e
Packit f0b94e
#include "nsIExternalHelperAppService.h"
Packit f0b94e
#include "nsIExternalProtocolService.h"
Packit f0b94e
#include "nsIWebProgressListener2.h"
Packit f0b94e
#include "nsIHelperAppLauncherDialog.h"
Packit f0b94e
Packit f0b94e
#include "nsIMIMEInfo.h"
Packit f0b94e
#include "nsIMIMEService.h"
Packit f0b94e
#include "nsINamed.h"
Packit f0b94e
#include "nsIStreamListener.h"
Packit f0b94e
#include "nsIFile.h"
Packit f0b94e
#include "nsIFileStreams.h"
Packit f0b94e
#include "nsIOutputStream.h"
Packit f0b94e
#include "nsString.h"
Packit f0b94e
#include "nsIInterfaceRequestor.h"
Packit f0b94e
#include "nsIInterfaceRequestorUtils.h"
Packit f0b94e
#include "nsIChannel.h"
Packit f0b94e
#include "nsIBackgroundFileSaver.h"
Packit f0b94e
Packit f0b94e
#include "nsIHandlerService.h"
Packit f0b94e
#include "nsCOMPtr.h"
Packit f0b94e
#include "nsIObserver.h"
Packit f0b94e
#include "nsCOMArray.h"
Packit f0b94e
#include "nsWeakReference.h"
Packit f0b94e
#include "nsIPrompt.h"
Packit f0b94e
#include "nsAutoPtr.h"
Packit f0b94e
#include "mozilla/Attributes.h"
Packit f0b94e
Packit f0b94e
class nsExternalAppHandler;
Packit f0b94e
class nsIMIMEInfo;
Packit f0b94e
class nsITransfer;
Packit f0b94e
class MaybeCloseWindowHelper;
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * The helper app service. Responsible for handling content that Mozilla
Packit f0b94e
 * itself can not handle
Packit f0b94e
 */
Packit f0b94e
class nsExternalHelperAppService : public nsIExternalHelperAppService,
Packit f0b94e
                                   public nsPIExternalAppLauncher,
Packit f0b94e
                                   public nsIExternalProtocolService,
Packit f0b94e
                                   public nsIMIMEService,
Packit f0b94e
                                   public nsIObserver,
Packit f0b94e
                                   public nsSupportsWeakReference {
Packit f0b94e
 public:
Packit f0b94e
  NS_DECL_ISUPPORTS
Packit f0b94e
  NS_DECL_NSIEXTERNALHELPERAPPSERVICE
Packit f0b94e
  NS_DECL_NSPIEXTERNALAPPLAUNCHER
Packit f0b94e
  NS_DECL_NSIEXTERNALPROTOCOLSERVICE
Packit f0b94e
  NS_DECL_NSIMIMESERVICE
Packit f0b94e
  NS_DECL_NSIOBSERVER
Packit f0b94e
Packit f0b94e
  nsExternalHelperAppService();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Initializes internal state. Will be called automatically when
Packit f0b94e
   * this service is first instantiated.
Packit f0b94e
   */
Packit f0b94e
  MOZ_MUST_USE nsresult Init();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Given a mimetype and an extension, looks up a mime info from the OS.
Packit f0b94e
   * The mime type is given preference. This function follows the same rules
Packit f0b94e
   * as nsIMIMEService::GetFromTypeAndExtension.
Packit f0b94e
   * This is supposed to be overridden by the platform-specific
Packit f0b94e
   * nsOSHelperAppService!
Packit f0b94e
   * @param aFileExt The file extension; may be empty. UTF-8 encoded.
Packit f0b94e
   * @param [out] aFound
Packit f0b94e
   *        Should be set to true if the os has a mapping, to
Packit f0b94e
   *        false otherwise. Must not be null.
Packit f0b94e
   * @return A MIMEInfo. This function must return a MIMEInfo object if it
Packit f0b94e
   *         can allocate one.  The only justifiable reason for not
Packit f0b94e
   *         returning one is an out-of-memory error.
Packit f0b94e
   *         If null, the value of aFound is unspecified.
Packit f0b94e
   */
Packit f0b94e
  virtual already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(
Packit f0b94e
      const nsACString& aMIMEType, const nsACString& aFileExt,
Packit f0b94e
      bool* aFound) = 0;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Given a string identifying an application, create an nsIFile representing
Packit f0b94e
   * it. This function should look in $PATH for the application.
Packit f0b94e
   * The base class implementation will first try to interpret platformAppPath
Packit f0b94e
   * as an absolute path, and if that fails it will look for a file next to the
Packit f0b94e
   * mozilla executable. Subclasses can override this method if they want a
Packit f0b94e
   * different behaviour.
Packit f0b94e
   * @param platformAppPath A platform specific path to an application that we
Packit f0b94e
   *                        got out of the rdf data source. This can be a mac
Packit f0b94e
   *                        file spec, a unix path or a windows path depending
Packit f0b94e
   *                        on the platform
Packit f0b94e
   * @param aFile           [out] An nsIFile representation of that platform
Packit f0b94e
   *                        application path.
Packit f0b94e
   */
Packit f0b94e
  virtual nsresult GetFileTokenForPath(const char16_t* platformAppPath,
Packit f0b94e
                                       nsIFile** aFile);
Packit f0b94e
Packit f0b94e
  virtual nsresult OSProtocolHandlerExists(const char* aScheme,
Packit f0b94e
                                           bool* aExists) = 0;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Given an extension, get a MIME type string. If not overridden by
Packit f0b94e
   * the OS-specific nsOSHelperAppService, will call into GetMIMEInfoFromOS
Packit f0b94e
   * with an empty mimetype.
Packit f0b94e
   * @return true if we successfully found a mimetype.
Packit f0b94e
   */
Packit f0b94e
  virtual bool GetMIMETypeFromOSForExtension(const nsACString& aExtension,
Packit f0b94e
                                             nsACString& aMIMEType);
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  virtual ~nsExternalHelperAppService();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Searches the "extra" array of MIMEInfo objects for an object
Packit f0b94e
   * with a specific type. If found, it will modify the passed-in
Packit f0b94e
   * MIMEInfo. Otherwise, it will return an error and the MIMEInfo
Packit f0b94e
   * will be untouched.
Packit f0b94e
   * @param aContentType The type to search for.
Packit f0b94e
   * @param aMIMEInfo    [inout] The mime info, if found
Packit f0b94e
   */
Packit f0b94e
  nsresult FillMIMEInfoForMimeTypeFromExtras(const nsACString& aContentType,
Packit f0b94e
                                             nsIMIMEInfo* aMIMEInfo);
Packit f0b94e
  /**
Packit f0b94e
   * Searches the "extra" array of MIMEInfo objects for an object
Packit f0b94e
   * with a specific extension.
Packit f0b94e
   *
Packit f0b94e
   * Does not change the MIME Type of the MIME Info.
Packit f0b94e
   *
Packit f0b94e
   * @see FillMIMEInfoForMimeTypeFromExtras
Packit f0b94e
   */
Packit f0b94e
  nsresult FillMIMEInfoForExtensionFromExtras(const nsACString& aExtension,
Packit f0b94e
                                              nsIMIMEInfo* aMIMEInfo);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Searches the "extra" array for a MIME type, and gets its extension.
Packit f0b94e
   * @param aExtension The extension to search for
Packit f0b94e
   * @param aMIMEType [out] The found MIME type.
Packit f0b94e
   * @return true if the extension was found, false otherwise.
Packit f0b94e
   */
Packit f0b94e
  bool GetTypeFromExtras(const nsACString& aExtension, nsACString& aMIMEType);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Logging Module. Usage: set MOZ_LOG=HelperAppService:level, where level
Packit f0b94e
   * should be 2 for errors, 3 for debug messages from the cross- platform
Packit f0b94e
   * nsExternalHelperAppService, and 4 for os-specific debug messages.
Packit f0b94e
   */
Packit f0b94e
  static mozilla::LazyLogModule mLog;
Packit f0b94e
Packit f0b94e
  // friend, so that it can access the nspr log module.
Packit f0b94e
  friend class nsExternalAppHandler;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Helper function for ExpungeTemporaryFiles and ExpungeTemporaryPrivateFiles
Packit f0b94e
   */
Packit f0b94e
  static void ExpungeTemporaryFilesHelper(nsCOMArray<nsIFile>& fileList);
Packit f0b94e
  /**
Packit f0b94e
   * Helper function for DeleteTemporaryFileOnExit and
Packit f0b94e
   * DeleteTemporaryPrivateFileWhenPossible
Packit f0b94e
   */
Packit f0b94e
  static nsresult DeleteTemporaryFileHelper(nsIFile* aTemporaryFile,
Packit f0b94e
                                            nsCOMArray<nsIFile>& aFileList);
Packit f0b94e
  /**
Packit f0b94e
   * Functions related to the tempory file cleanup service provided by
Packit f0b94e
   * nsExternalHelperAppService
Packit f0b94e
   */
Packit f0b94e
  void ExpungeTemporaryFiles();
Packit f0b94e
  /**
Packit f0b94e
   * Functions related to the tempory file cleanup service provided by
Packit f0b94e
   * nsExternalHelperAppService (for the temporary files added during
Packit f0b94e
   * the private browsing mode)
Packit f0b94e
   */
Packit f0b94e
  void ExpungeTemporaryPrivateFiles();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Array for the files that should be deleted
Packit f0b94e
   */
Packit f0b94e
  nsCOMArray<nsIFile> mTemporaryFilesList;
Packit f0b94e
  /**
Packit f0b94e
   * Array for the files that should be deleted (for the temporary files
Packit f0b94e
   * added during the private browsing mode)
Packit f0b94e
   */
Packit f0b94e
  nsCOMArray<nsIFile> mTemporaryPrivateFilesList;
Packit f0b94e
Packit f0b94e
 private:
Packit f0b94e
  nsresult DoContentContentProcessHelper(const nsACString& aMimeContentType,
Packit f0b94e
                                         nsIRequest* aRequest,
Packit f0b94e
                                         nsIInterfaceRequestor* aContentContext,
Packit f0b94e
                                         bool aForceSave,
Packit f0b94e
                                         nsIInterfaceRequestor* aWindowContext,
Packit f0b94e
                                         nsIStreamListener** aStreamListener);
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * An external app handler is just a small little class that presents itself as
Packit f0b94e
 * a nsIStreamListener. It saves the incoming data into a temp file. The handler
Packit f0b94e
 * is bound to an application when it is created. When it receives an
Packit f0b94e
 * OnStopRequest it launches the application using the temp file it has
Packit f0b94e
 * stored the data into.  We create a handler every time we have to process
Packit f0b94e
 * data using a helper app.
Packit f0b94e
 */
Packit f0b94e
class nsExternalAppHandler final : public nsIStreamListener,
Packit f0b94e
                                   public nsIHelperAppLauncher,
Packit f0b94e
                                   public nsIBackgroundFileSaverObserver,
Packit f0b94e
                                   public nsINamed {
Packit f0b94e
 public:
Packit f0b94e
  NS_DECL_THREADSAFE_ISUPPORTS
Packit f0b94e
  NS_DECL_NSISTREAMLISTENER
Packit f0b94e
  NS_DECL_NSIREQUESTOBSERVER
Packit f0b94e
  NS_DECL_NSIHELPERAPPLAUNCHER
Packit f0b94e
  NS_DECL_NSICANCELABLE
Packit f0b94e
  NS_DECL_NSIBACKGROUNDFILESAVEROBSERVER
Packit f0b94e
  NS_DECL_NSINAMED
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * @param aMIMEInfo       MIMEInfo object, representing the type of the
Packit f0b94e
   *                        content that should be handled
Packit f0b94e
   * @param aFileExtension  The extension we need to append to our temp file,
Packit f0b94e
   *                        INCLUDING the ".". e.g. .mp3
Packit f0b94e
   * @param aContentContext dom Window context, as passed to DoContent.
Packit f0b94e
   * @param aWindowContext  Top level window context used in dialog parenting,
Packit f0b94e
   *                        as passed to DoContent. This parameter may be null,
Packit f0b94e
   *                        in which case dialogs will be parented to
Packit f0b94e
   *                        aContentContext.
Packit f0b94e
   * @param mExtProtSvc     nsExternalHelperAppService on creation
Packit f0b94e
   * @param aFileName       The filename to use
Packit f0b94e
   * @param aReason         A constant from nsIHelperAppLauncherDialog
Packit f0b94e
   * indicating why the request is handled by a helper app.
Packit f0b94e
   */
Packit f0b94e
  nsExternalAppHandler(nsIMIMEInfo* aMIMEInfo, const nsACString& aFileExtension,
Packit f0b94e
                       nsIInterfaceRequestor* aContentContext,
Packit f0b94e
                       nsIInterfaceRequestor* aWindowContext,
Packit f0b94e
                       nsExternalHelperAppService* aExtProtSvc,
Packit f0b94e
                       const nsAString& aFilename, uint32_t aReason,
Packit f0b94e
                       bool aForceSave);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Clean up after the request was diverted to the parent process.
Packit f0b94e
   */
Packit f0b94e
  void DidDivertRequest(nsIRequest* request);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Apply content conversions if needed.
Packit f0b94e
   */
Packit f0b94e
  void MaybeApplyDecodingForExtension(nsIRequest* request);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the dialog parent. Public for ExternalHelperAppChild::OnStartRequest.
Packit f0b94e
   */
Packit f0b94e
  nsIInterfaceRequestor* GetDialogParent() {
Packit f0b94e
    return mWindowContext ? mWindowContext : mContentContext;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  void SetContentContext(nsIInterfaceRequestor* context) {
Packit f0b94e
    MOZ_ASSERT(!mWindowContext);
Packit f0b94e
    mContentContext = context;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
 protected:
Packit f0b94e
  ~nsExternalAppHandler();
Packit f0b94e
Packit f0b94e
  nsCOMPtr<nsIFile> mTempFile;
Packit f0b94e
  nsCOMPtr<nsIURI> mSourceUrl;
Packit f0b94e
  nsString mTempFileExtension;
Packit f0b94e
  nsString mTempLeafName;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * The MIME Info for this load. Will never be null.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIMIMEInfo> mMimeInfo;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * The dom window associated with this request to handle content.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIInterfaceRequestor> mContentContext;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * If set, the parent window helper app dialogs and file pickers
Packit f0b94e
   * should use in parenting. If null, we use mContentContext.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIInterfaceRequestor> mWindowContext;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Used to close the window on a timer, to avoid any exceptions that are
Packit f0b94e
   * thrown if we try to close the window before it's fully loaded.
Packit f0b94e
   */
Packit f0b94e
  RefPtr<MaybeCloseWindowHelper> mMaybeCloseWindowHelper;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * The following field is set if we were processing an http channel that had
Packit f0b94e
   * a content disposition header which specified the SUGGESTED file name we
Packit f0b94e
   * should present to the user in the save to disk dialog.
Packit f0b94e
   */
Packit f0b94e
  nsString mSuggestedFileName;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * If set, this handler should forcibly save the file to disk regardless of
Packit f0b94e
   * MIME info settings or anything else, without ever popping up the
Packit f0b94e
   * unknown content type handling dialog.
Packit f0b94e
   */
Packit f0b94e
  bool mForceSave;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * The canceled flag is set if the user canceled the launching of this
Packit f0b94e
   * application before we finished saving the data to a temp file.
Packit f0b94e
   */
Packit f0b94e
  bool mCanceled;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * True if a stop request has been issued.
Packit f0b94e
   */
Packit f0b94e
  bool mStopRequestIssued;
Packit f0b94e
Packit f0b94e
  bool mIsFileChannel;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * One of the REASON_ constants from nsIHelperAppLauncherDialog. Indicates the
Packit f0b94e
   * reason the dialog was shown (unknown content type, server requested it,
Packit f0b94e
   * etc).
Packit f0b94e
   */
Packit f0b94e
  uint32_t mReason;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Track the executable-ness of the temporary file.
Packit f0b94e
   */
Packit f0b94e
  bool mTempFileIsExecutable;
Packit f0b94e
Packit f0b94e
  PRTime mTimeDownloadStarted;
Packit f0b94e
  int64_t mContentLength;
Packit f0b94e
  int64_t mProgress; /**< Number of bytes received (for sending progress
Packit f0b94e
                        notifications). */
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * When we are told to save the temp file to disk (in a more permament
Packit f0b94e
   * location) before we are done writing the content to a temp file, then
Packit f0b94e
   * we need to remember the final destination until we are ready to use it.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIFile> mFinalFileDestination;
Packit f0b94e
Packit f0b94e
  uint32_t mBufferSize;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * This object handles saving the data received from the network to a
Packit f0b94e
   * temporary location first, and then move the file to its final location,
Packit f0b94e
   * doing all the input/output on a background thread.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIBackgroundFileSaver> mSaver;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Stores the SHA-256 hash associated with the file that we downloaded.
Packit f0b94e
   */
Packit f0b94e
  nsAutoCString mHash;
Packit f0b94e
  /**
Packit f0b94e
   * Stores the signature information of the downloaded file in an nsIArray of
Packit f0b94e
   * nsIX509CertList of nsIX509Cert. If the file is unsigned this will be
Packit f0b94e
   * empty.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIArray> mSignatureInfo;
Packit f0b94e
  /**
Packit f0b94e
   * Stores the redirect information associated with the channel.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIArray> mRedirects;
Packit f0b94e
  /**
Packit f0b94e
   * Creates the temporary file for the download and an output stream for it.
Packit f0b94e
   * Upon successful return, both mTempFile and mSaver will be valid.
Packit f0b94e
   */
Packit f0b94e
  nsresult SetUpTempFile(nsIChannel* aChannel);
Packit f0b94e
  /**
Packit f0b94e
   * When we download a helper app, we are going to retarget all load
Packit f0b94e
   * notifications into our own docloader and load group instead of
Packit f0b94e
   * using the window which initiated the load....RetargetLoadNotifications
Packit f0b94e
   * contains that information...
Packit f0b94e
   */
Packit f0b94e
  void RetargetLoadNotifications(nsIRequest* request);
Packit f0b94e
  /**
Packit f0b94e
   * Once the user tells us how they want to dispose of the content
Packit f0b94e
   * create an nsITransfer so they know what's going on. If this fails, the
Packit f0b94e
   * caller MUST call Cancel.
Packit f0b94e
   */
Packit f0b94e
  nsresult CreateTransfer();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * If we fail to create the necessary temporary file to initiate a transfer
Packit f0b94e
   * we will report the failure by creating a failed nsITransfer.
Packit f0b94e
   */
Packit f0b94e
  nsresult CreateFailedTransfer(bool aIsPrivateBrowsing);
Packit f0b94e
Packit f0b94e
  /*
Packit f0b94e
   * The following two functions are part of the split of SaveToDisk
Packit f0b94e
   * to make it async, and works as following:
Packit f0b94e
   *
Packit f0b94e
   *    SaveToDisk    ------->   RequestSaveDestination
Packit f0b94e
   *                                     .
Packit f0b94e
   *                                     .
Packit f0b94e
   *                                     v
Packit f0b94e
   *    ContinueSave  <-------   SaveDestinationAvailable
Packit f0b94e
   */
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * This is called by SaveToDisk to decide what's the final
Packit f0b94e
   * file destination chosen by the user or by auto-download settings.
Packit f0b94e
   */
Packit f0b94e
  void RequestSaveDestination(const nsString& aDefaultFile,
Packit f0b94e
                              const nsString& aDefaultFileExt);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * When SaveToDisk is called, it possibly delegates to RequestSaveDestination
Packit f0b94e
   * to decide the file destination. ContinueSave must then be called when
Packit f0b94e
   * the final destination is finally known.
Packit f0b94e
   * @param  aFile  The file that was chosen as the final destination.
Packit f0b94e
   *                Must not be null.
Packit f0b94e
   */
Packit f0b94e
  nsresult ContinueSave(nsIFile* aFile);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * After we're done prompting the user for any information, if the original
Packit f0b94e
   * channel had a refresh url associated with it (which might point to a
Packit f0b94e
   * "thank you for downloading" kind of page, then process that....It is safe
Packit f0b94e
   * to invoke this method multiple times. We'll clear mOriginalChannel after
Packit f0b94e
   * it's called and this ensures we won't call it again....
Packit f0b94e
   */
Packit f0b94e
  void ProcessAnyRefreshTags();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Notify our nsITransfer object that we are done with the download.  This is
Packit f0b94e
   * always called after the target file has been closed.
Packit f0b94e
   *
Packit f0b94e
   * @param aStatus
Packit f0b94e
   *        NS_OK for success, or a failure code if the download failed.
Packit f0b94e
   *        A partially downloaded file may still be available in this case.
Packit f0b94e
   */
Packit f0b94e
  void NotifyTransfer(nsresult aStatus);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Helper routine that searches a pref string for a given mime type
Packit f0b94e
   */
Packit f0b94e
  bool GetNeverAskFlagFromPref(const char* prefName, const char* aContentType);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Helper routine to ensure mSuggestedFileName is "correct";
Packit f0b94e
   * this ensures that mTempFileExtension only contains an extension when it
Packit f0b94e
   * is different from mSuggestedFileName's extension.
Packit f0b94e
   */
Packit f0b94e
  void EnsureSuggestedFileName();
Packit f0b94e
Packit f0b94e
  typedef enum { kReadError, kWriteError, kLaunchError } ErrorType;
Packit f0b94e
  /**
Packit f0b94e
   * Utility function to send proper error notification to web progress listener
Packit f0b94e
   */
Packit f0b94e
  void SendStatusChange(ErrorType type, nsresult aStatus, nsIRequest* aRequest,
Packit f0b94e
                        const nsString& path);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Set in nsHelperDlgApp.js. This is always null after the user has chosen an
Packit f0b94e
   * action.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIWebProgressListener2> mDialogProgressListener;
Packit f0b94e
  /**
Packit f0b94e
   * Set once the user has chosen an action. This is null after the download
Packit f0b94e
   * has been canceled or completes.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsITransfer> mTransfer;
Packit f0b94e
Packit f0b94e
  nsCOMPtr<nsIChannel> mOriginalChannel; /**< in the case of a redirect, this
Packit f0b94e
                                            will be the pre-redirect channel. */
Packit f0b94e
  nsCOMPtr<nsIHelperAppLauncherDialog> mDialog;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Keep request alive in case when helper non-modal dialog shown.
Packit f0b94e
   * Thus in OnStopRequest the mRequest will not be set to null (it will be set
Packit f0b94e
   * to null further).
Packit f0b94e
   */
Packit f0b94e
  bool mKeepRequestAlive;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * The request that's being loaded. Initialized in OnStartRequest.
Packit f0b94e
   * Nulled out in OnStopRequest or once we know what we're doing
Packit f0b94e
   * with the data, whichever happens later.
Packit f0b94e
   */
Packit f0b94e
  nsCOMPtr<nsIRequest> mRequest;
Packit f0b94e
Packit f0b94e
  RefPtr<nsExternalHelperAppService> mExtProtSvc;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
#endif  // nsExternalHelperAppService_h__