Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
nsOSHelperAppService Class Reference

#include <nsOSHelperAppService.h>

Inheritance diagram for nsOSHelperAppService:
Inheritance graph
[legend]
Collaboration diagram for nsOSHelperAppService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsOSHelperAppService ()
virtual ~nsOSHelperAppService ()
already_AddRefed< nsIMIMEInfoGetMIMEInfoFromOS (const nsACString &aMIMEType, const nsACString &aFileExt, PRBool *aFound)
 Given a mimetype and an extension, looks up a mime info from the OS.
NS_IMETHOD ExternalProtocolHandlerExists (const char *aProtocolScheme, PRBool *aHandlerExists)
nsresult LoadUriInternal (nsIURI *aURL)
 nsOSHelperAppService ()
virtual ~nsOSHelperAppService ()
NS_IMETHOD ExternalProtocolHandlerExists (const char *aProtocolScheme, PRBool *aHandlerExists)
NS_IMETHOD GetApplicationDescription (const nsACString &aScheme, nsAString &_retval)
nsresult LoadUriInternal (nsIURI *aURL)
NS_IMETHOD GetFromTypeAndExtension (const nsACString &aType, const nsACString &aFileExt, nsIMIMEInfo **aMIMEInfo)
already_AddRefed< nsIMIMEInfoGetMIMEInfoFromOS (const nsACString &aMIMEType, const nsACString &aFileExt, PRBool *aFound)
 Given a mimetype and an extension, looks up a mime info from the OS.
virtual nsresult GetFileTokenForPath (const PRUnichar *platformAppPath, nsIFile **aFile)
 Given a string identifying an application, create an nsIFile representing it.
 nsOSHelperAppService ()
virtual ~nsOSHelperAppService ()
already_AddRefed< nsIMIMEInfoGetMIMEInfoFromOS (const nsACString &aMimeType, const nsACString &aFileExt, PRBool *aFound)
 Given a mimetype and an extension, looks up a mime info from the OS.
NS_IMETHOD ExternalProtocolHandlerExists (const char *aProtocolScheme, PRBool *aHandlerExists)
nsresult LoadUriInternal (nsIURI *aURL)
NS_IMETHODIMP GetApplicationDescription (const nsACString &aScheme, nsAString &_retval)
 nsOSHelperAppService ()
virtual ~nsOSHelperAppService ()
already_AddRefed< nsIMIMEInfoGetMIMEInfoFromOS (const nsACString &aMimeType, const nsACString &aFileExt, PRBool *aFound)
 Given a mimetype and an extension, looks up a mime info from the OS.
NS_IMETHOD ExternalProtocolHandlerExists (const char *aProtocolScheme, PRBool *aHandlerExists)
nsresult LoadUriInternal (nsIURI *aURL)
NS_IMETHOD GetApplicationDescription (const nsACString &aScheme, nsAString &_retval)
virtual nsresult GetFileTokenForPath (const PRUnichar *platformAppPath, nsIFile **aFile)
 Given a string identifying an application, create an nsIFile representing it.
 nsOSHelperAppService ()
virtual ~nsOSHelperAppService ()
NS_IMETHOD ExternalProtocolHandlerExists (const char *aProtocolScheme, PRBool *aHandlerExists)
nsresult LoadUriInternal (nsIURI *aURL)
NS_IMETHOD GetApplicationDescription (const nsACString &aScheme, nsAString &_retval)
already_AddRefed< nsIMIMEInfoGetMIMEInfoFromOS (const nsACString &aMIMEType, const nsACString &aFileExt, PRBool *aFound)
 Given a mimetype and an extension, looks up a mime info from the OS.
 NS_HIDDEN_ (nsresult) InitDataSource()
 Initializes the RDF datasource from the profile.
 NS_HIDDEN_ (nsresult) Init()
 Initializes internal state.
 NS_HIDDEN_ (nsresult) GetMIMEInfoForMimeTypeFromDS(const nsACString &aContentType
 Given a content type, look up the user override information to see if we have a mime info object representing this content type.
 NS_HIDDEN_ (nsresult) GetMIMEInfoForExtensionFromDS(const nsACString &aFileExtension
 Given an extension, look up the user override information to see if we have a mime info object representing this extension.
 NS_HIDDEN_ (PRBool) GetTypeFromDS(const nsACString &aFileExtension
 Looks up the MIME Type for a given extension in the RDF Datasource.
 NS_HIDDEN_ (PRBool) MIMETypeIsInDataSource(const char *aContentType)
 Helper routine used to test whether a given mime type is in our mimeTypes.rdf data source.
nsIStreamListener doContent (in ACString aMimeContentType, in nsIRequest aRequest, in nsIInterfaceRequestor aWindowContext)
 Binds an external helper application to a stream listener.
boolean applyDecodingForExtension (in AUTF8String aExtension, in ACString aEncodingType)
 Returns true if data from a URL with this extension combination is to be decoded from aEncodingType prior to saving or passing off to helper apps, false otherwise.
void deleteTemporaryFileOnExit (in nsIFile aTemporaryFile)
 mscott --> eventually I should move this into a new service so other consumers can add temporary files they want deleted on exit.
boolean externalProtocolHandlerExists (in string aProtocolScheme)
 Check whether a handler for a specific protocol exists.
boolean isExposedProtocol (in string aProtocolScheme)
 Check whether a handler for a specific protocol is "exposed" as a visible feature of the current application.
void loadUrl (in nsIURI aURL)
 Used to load a url via an external protocol handler (if one exists)
void loadURI (in nsIURI aURI, in nsIPrompt aPrompt)
 Used to load a URI via an external application.
AString getApplicationDescription (in AUTF8String aScheme)
 Gets a human-readable description for the application responsible for handling a specific protocol.
nsIMIMEInfo getFromTypeAndExtension (in ACString aMIMEType, in AUTF8String aFileExt)
 Retrieves an nsIMIMEInfo using both the extension and the type of a file.
ACString getTypeFromExtension (in AUTF8String aFileExt)
 Retrieves a ACString representation of the MIME type associated with this file extension.
ACString getTypeFromURI (in nsIURI aURI)
 Retrieves a ACString representation of the MIME type associated with this URI.
ACString getTypeFromFile (in nsIFile aFile)
AUTF8String getPrimaryExtension (in ACString aMIMEType, in AUTF8String aFileExt)
 Given a Type/Extension combination, returns the default extension for this type.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Static Public Member Functions

static PRBool GetValueString (HKEY hKey, const PRUnichar *pValueName, nsAString &result)
 Get the string value of a registry value and store it in result.

Public Attributes

nsIMIMEInfoaMIMEInfo
nsACString & aType

Protected Member Functions

nsresult SetMIMEInfoForType (const char *aMIMEType, nsMIMEInfoBeOS **_retval)
nsresult GetMimeInfoFromExtension (const char *aFileExt, nsMIMEInfoBeOS **_retval)
nsresult GetMimeInfoFromMIMEType (const char *aMIMEType, nsMIMEInfoBeOS **_retval)
void UpdateCreatorInfo (nsIMIMEInfo *aMIMEInfo)
already_AddRefed< nsMIMEInfoOS2GetFromType (const nsCString &aMimeType)
already_AddRefed< nsMIMEInfoOS2GetFromExtension (const nsCString &aFileExt)
already_AddRefed< nsMIMEInfoBaseGetFromType (const nsCString &aMimeType)
already_AddRefed< nsMIMEInfoBaseGetFromExtension (const nsCString &aFileExt)
virtual void FixFilePermissions (nsILocalFile *aFile)
 Fixes the file permissions to be correct.
nsresult GetDefaultAppInfo (const nsAString &aTypeName, nsAString &aDefaultDescription, nsIFile **aDefaultApplication)
already_AddRefed< nsMIMEInfoWinGetByExtension (const nsAFlatString &aFileExt, const char *aTypeHint=nsnull)
nsresult FindOSMimeInfoForType (const char *aMimeContentType, nsIURI *aURI, char **aFileExtension, nsIMIMEInfo **aMIMEInfo)
 NS_HIDDEN_ (nsresult) FillTopLevelProperties(nsIRDFResource *aContentTypeNodeResource
 Helper routines for digesting the data source and filling in a mime info object for a given content type inside that data source.
 NS_HIDDEN_ (nsresult) FillContentHandlerProperties(const char *aContentType
 NS_HIDDEN_ (nsresult) FillLiteralValueFromTarget(nsIRDFResource *aSource
 A small helper function which gets the target for a given source and property.
 NS_HIDDEN_ (nsresult) GetMIMEInfoForMimeTypeFromExtras(const nsACString &aContentType
 Searches the "extra" array of MIMEInfo objects for an object with a specific type.
 NS_HIDDEN_ (nsresult) GetMIMEInfoForExtensionFromExtras(const nsACString &aExtension
 Searches the "extra" array of MIMEInfo objects for an object with a specific extension.
 NS_HIDDEN_ (PRBool) GetTypeFromExtras(const nsACString &aExtension
 Searches the "extra" array for a MIME type, and gets its extension.
 NS_HIDDEN_ (nsresult) ExpungeTemporaryFiles()
 Functions related to the tempory file cleanup service provided by nsExternalHelperAppService.
virtual NS_HIDDEN_ (nsresult) LoadUriInternal(nsIURI *aURL)=0
 OS-specific loading of external URLs.
 NS_HIDDEN_ (PRBool) isExternalLoadOK(nsIURI *aURI
 NS_HIDDEN_ (PRBool) promptForScheme(nsIURI *aURI

Static Protected Member Functions

static nsresult GetMIMEInfoFromRegistry (const nsAFlatString &fileType, nsIMIMEInfo *pInfo)
static PRBool typeFromExtEquals (const PRUnichar *aExt, const char *aType)
 Looks up the type for the extension aExt and compares it to aType.
static void *PR_CALLBACK handleExternalLoadEvent (PLEvent *event)

Protected Attributes

nsIRDFService nsIMIMEInfoaMIMEInfo
nsIRDFResource nsIRDFService
nsIMIMEInfo
aMIMEInfo
nsCOMPtr< nsIRDFDataSourcemOverRideDataSource
 Pointer to the datasource that contains the user override information.
nsCOMPtr< nsIRDFResourcekNC_Description
nsCOMPtr< nsIRDFResourcekNC_Value
nsCOMPtr< nsIRDFResourcekNC_FileExtensions
nsCOMPtr< nsIRDFResourcekNC_Path
nsCOMPtr< nsIRDFResourcekNC_UseSystemDefault
nsCOMPtr< nsIRDFResourcekNC_SaveToDisk
nsCOMPtr< nsIRDFResourcekNC_AlwaysAsk
nsCOMPtr< nsIRDFResourcekNC_HandleInternal
nsCOMPtr< nsIRDFResourcekNC_PrettyName
PRBool mDataSourceInitialized
 Whether mOverRideDataSource is initialized.
nsIRDFServiceaRDFService
nsIRDFResource nsIRDFServiceaRDFService
nsIRDFResourceaContentTypeNodeResource
nsIRDFResourceaProperty
nsIRDFResource const PRUnichar ** aLiteralValue
nsACString & aMIMEType
nsCOMArray< nsILocalFilemTemporaryFilesList
 Array for the files that should be deleted.
nsIPromptaPrompt
nsIPrompt PRBoolaRemember

Static Protected Attributes

static PRBool sIsNT = PR_FALSE
 Whether we're running on an OS that supports the *W registry functions.

Private Member Functions

nsresult GetApplicationAndParametersFromINI (const nsACString &aProtocol, char *app, ULONG appLength, char *param, ULONG paramLength)
nsresult GetHandlerAppFromPrefs (const char *aScheme, nsIFile **aApp)

Static Private Member Functions

static nsresult UnescapeCommand (const nsAString &aEscapedCommand, const nsAString &aMajorType, const nsAString &aMinorType, nsHashtable &aTypeOptions, nsACString &aUnEscapedCommand)
static nsresult GetFileLocation (const char *aPrefName, const char *aEnvVarName, PRUnichar **aFileLocation)
static nsresult LookUpTypeAndDescription (const nsAString &aFileExtension, nsAString &aMajorType, nsAString &aMinorType, nsAString &aDescription)
static nsresult CreateInputStream (const nsAString &aFilename, nsIFileInputStream **aFileInputStream, nsILineInputStream **aLineInputStream, nsACString &aBuffer, PRBool *aNetscapeFormat, PRBool *aMore)
static nsresult GetTypeAndDescriptionFromMimetypesFile (const nsAString &aFilename, const nsAString &aFileExtension, nsAString &aMajorType, nsAString &aMinorType, nsAString &aDescription)
static nsresult LookUpExtensionsAndDescription (const nsAString &aMajorType, const nsAString &aMinorType, nsAString &aFileExtensions, nsAString &aDescription)
static nsresult GetExtensionsAndDescriptionFromMimetypesFile (const nsAString &aFilename, const nsAString &aMajorType, const nsAString &aMinorType, nsAString &aFileExtensions, nsAString &aDescription)
static nsresult ParseNetscapeMIMETypesEntry (const nsAString &aEntry, nsAString::const_iterator &aMajorTypeStart, nsAString::const_iterator &aMajorTypeEnd, nsAString::const_iterator &aMinorTypeStart, nsAString::const_iterator &aMinorTypeEnd, nsAString &aExtensions, nsAString::const_iterator &aDescriptionStart, nsAString::const_iterator &aDescriptionEnd)
static nsresult ParseNormalMIMETypesEntry (const nsAString &aEntry, nsAString::const_iterator &aMajorTypeStart, nsAString::const_iterator &aMajorTypeEnd, nsAString::const_iterator &aMinorTypeStart, nsAString::const_iterator &aMinorTypeEnd, nsAString &aExtensions, nsAString::const_iterator &aDescriptionStart, nsAString::const_iterator &aDescriptionEnd)
static nsresult LookUpHandlerAndDescription (const nsAString &aMajorType, const nsAString &aMinorType, nsHashtable &aTypeOptions, nsAString &aHandler, nsAString &aDescription, nsAString &aMozillaFlags)
static nsresult GetHandlerAndDescriptionFromMailcapFile (const nsAString &aFilename, const nsAString &aMajorType, const nsAString &aMinorType, nsHashtable &aTypeOptions, nsAString &aHandler, nsAString &aDescription, nsAString &aMozillaFlags)
static nsresult UnescapeCommand (const nsAString &aEscapedCommand, const nsAString &aMajorType, const nsAString &aMinorType, nsHashtable &aTypeOptions, nsACString &aUnEscapedCommand)
static nsresult GetFileLocation (const char *aPrefName, const char *aEnvVarName, PRUnichar **aFileLocation)
static nsresult LookUpTypeAndDescription (const nsAString &aFileExtension, nsAString &aMajorType, nsAString &aMinorType, nsAString &aDescription, PRBool aUserData)
static nsresult CreateInputStream (const nsAString &aFilename, nsIFileInputStream **aFileInputStream, nsILineInputStream **aLineInputStream, nsACString &aBuffer, PRBool *aNetscapeFormat, PRBool *aMore)
static nsresult GetTypeAndDescriptionFromMimetypesFile (const nsAString &aFilename, const nsAString &aFileExtension, nsAString &aMajorType, nsAString &aMinorType, nsAString &aDescription)
static nsresult LookUpExtensionsAndDescription (const nsAString &aMajorType, const nsAString &aMinorType, nsAString &aFileExtensions, nsAString &aDescription)
static nsresult GetExtensionsAndDescriptionFromMimetypesFile (const nsAString &aFilename, const nsAString &aMajorType, const nsAString &aMinorType, nsAString &aFileExtensions, nsAString &aDescription)
static nsresult ParseNetscapeMIMETypesEntry (const nsAString &aEntry, nsAString::const_iterator &aMajorTypeStart, nsAString::const_iterator &aMajorTypeEnd, nsAString::const_iterator &aMinorTypeStart, nsAString::const_iterator &aMinorTypeEnd, nsAString &aExtensions, nsAString::const_iterator &aDescriptionStart, nsAString::const_iterator &aDescriptionEnd)
static nsresult ParseNormalMIMETypesEntry (const nsAString &aEntry, nsAString::const_iterator &aMajorTypeStart, nsAString::const_iterator &aMajorTypeEnd, nsAString::const_iterator &aMinorTypeStart, nsAString::const_iterator &aMinorTypeEnd, nsAString &aExtensions, nsAString::const_iterator &aDescriptionStart, nsAString::const_iterator &aDescriptionEnd)
static nsresult LookUpHandlerAndDescription (const nsAString &aMajorType, const nsAString &aMinorType, nsHashtable &aTypeOptions, nsAString &aHandler, nsAString &aDescription, nsAString &aMozillaFlags)
static nsresult DoLookUpHandlerAndDescription (const nsAString &aMajorType, const nsAString &aMinorType, nsHashtable &aTypeOptions, nsAString &aHandler, nsAString &aDescription, nsAString &aMozillaFlags, PRBool aUserData)
static nsresult GetHandlerAndDescriptionFromMailcapFile (const nsAString &aFilename, const nsAString &aMajorType, const nsAString &aMinorType, nsHashtable &aTypeOptions, nsAString &aHandler, nsAString &aDescription, nsAString &aMozillaFlags)

Private Attributes

PRUint32 mPermissions

Friends

class nsExternalAppHandler

Detailed Description

Definition at line 50 of file nsOSHelperAppService.h.


Constructor & Destructor Documentation

Definition at line 58 of file nsOSHelperAppService.cpp.

Definition at line 62 of file nsOSHelperAppService.cpp.

{}

Member Function Documentation

boolean nsIExternalHelperAppService::applyDecodingForExtension ( in AUTF8String  aExtension,
in ACString  aEncodingType 
) [inherited]

Returns true if data from a URL with this extension combination is to be decoded from aEncodingType prior to saving or passing off to helper apps, false otherwise.

nsresult nsOSHelperAppService::CreateInputStream ( const nsAString &  aFilename,
nsIFileInputStream **  aFileInputStream,
nsILineInputStream **  aLineInputStream,
nsACString &  aBuffer,
PRBool aNetscapeFormat,
PRBool aMore 
) [static, private]

Definition at line 328 of file nsOSHelperAppService.cpp.

                                                        {
  LOG(("-- CreateInputStream"));
  nsresult rv = NS_OK;

  nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
  if (NS_FAILED(rv))
    return rv;
  rv = file->InitWithPath(aFilename);
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIFileInputStream> fileStream(do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv));
  if (NS_FAILED(rv))
    return rv;
  rv = fileStream->Init(file, -1, -1, PR_FALSE);
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsILineInputStream> lineStream(do_QueryInterface(fileStream, &rv));

  if (NS_FAILED(rv)) {
    LOG(("Interface trouble in stream land!"));
    return rv;
  }

  rv = lineStream->ReadLine(aBuffer, aMore);
  if (NS_FAILED(rv)) {
    fileStream->Close();
    return rv;
  }

  *aNetscapeFormat = IsNetscapeFormat(aBuffer);

  *aFileInputStream = fileStream;
  NS_ADDREF(*aFileInputStream);
  *aLineInputStream = lineStream;
  NS_ADDREF(*aLineInputStream);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::CreateInputStream ( const nsAString &  aFilename,
nsIFileInputStream **  aFileInputStream,
nsILineInputStream **  aLineInputStream,
nsACString &  aBuffer,
PRBool aNetscapeFormat,
PRBool aMore 
) [static, private]

mscott --> eventually I should move this into a new service so other consumers can add temporary files they want deleted on exit.

Parameters:
aTemporaryFileA temporary file we should delete on exit.
nsIStreamListener nsIExternalHelperAppService::doContent ( in ACString  aMimeContentType,
in nsIRequest  aRequest,
in nsIInterfaceRequestor  aWindowContext 
) [inherited]

Binds an external helper application to a stream listener.

The caller should pump data into the returned stream listener. When the OnStopRequest is issued, the stream listener implementation will launch the helper app with this data.

Parameters:
aMimeContentTypeThe content type of the incoming data
aRequestThe request corresponding to the incoming data
aWindowContextUse GetInterface to retrieve properties like the dom window or parent window... The service might need this in order to bring up dialogs.
Returns:
A nsIStreamListener which the caller should pump the data into.
nsresult nsOSHelperAppService::DoLookUpHandlerAndDescription ( const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsHashtable &  aTypeOptions,
nsAString &  aHandler,
nsAString &  aDescription,
nsAString &  aMozillaFlags,
PRBool  aUserData 
) [static, private]

Definition at line 955 of file nsOSHelperAppService.cpp.

                                                                      {
  LOG(("-- LookUpHandlerAndDescription for type '%s/%s'\n",
       NS_LossyConvertUCS2toASCII(aMajorType).get(),
       NS_LossyConvertUCS2toASCII(aMinorType).get()));
  nsresult rv = NS_OK;
  nsXPIDLString mailcapFileName;

  const char * filenamePref = aUserData ?
    "helpers.private_mailcap_file" : "helpers.global_mailcap_file";
  const char * filenameEnvVar = aUserData ?
    "PERSONAL_MAILCAP" : "MAILCAP";
  
  rv = GetFileLocation(filenamePref,
                       filenameEnvVar,
                       getter_Copies(mailcapFileName));
  if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
    rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
                                                 aMajorType,
                                                 aMinorType,
                                                 aTypeOptions,
                                                 aHandler,
                                                 aDescription,
                                                 aMozillaFlags);
  } else {
    rv = NS_ERROR_NOT_AVAILABLE;
  }

  return rv;
}

Here is the call graph for this function:

NS_IMETHODIMP nsOSHelperAppService::ExternalProtocolHandlerExists ( const char *  aProtocolScheme,
PRBool aHandlerExists 
)

Definition at line 65 of file nsOSHelperAppService.cpp.

{
       LOG(("-- nsOSHelperAppService::ExternalProtocolHandlerExists for '%s'\n",
            aProtocolScheme));
       // look up the protocol scheme in the MIME database
       *aHandlerExists = PR_FALSE;
       if (aProtocolScheme && *aProtocolScheme)
       {
              BString protoStr(aProtocolScheme);
              protoStr.Prepend("application/x-vnd.Be.URL.");
              BMimeType protocol;
              if (protocol.SetTo(protoStr.String()) == B_OK)
              {
                     if (protocol.IsInstalled())
                            *aHandlerExists = PR_TRUE;
              }
              if ((!*aHandlerExists) && (!strcmp("mailto", aProtocolScheme)))
              {
                     // mailto link, no x-vnd.Be.URL.mailto entry
                     if (protocol.SetTo("text/x-email") == B_OK)
                     {
                            if (protocol.IsInstalled())
                                   *aHandlerExists = PR_TRUE;
                     }
              }
       }

       return NS_OK;
}
NS_IMETHOD nsOSHelperAppService::ExternalProtocolHandlerExists ( const char *  aProtocolScheme,
PRBool aHandlerExists 
)
NS_IMETHOD nsOSHelperAppService::ExternalProtocolHandlerExists ( const char *  aProtocolScheme,
PRBool aHandlerExists 
)

Check whether a handler for a specific protocol exists.

Parameters:
aProtocolSchemeThe scheme from a url: http, ftp, mailto, etc.
Returns:
true if we have a handler and false otherwise.
NS_IMETHOD nsOSHelperAppService::ExternalProtocolHandlerExists ( const char *  aProtocolScheme,
PRBool aHandlerExists 
)
NS_IMETHOD nsOSHelperAppService::ExternalProtocolHandlerExists ( const char *  aProtocolScheme,
PRBool aHandlerExists 
)
nsresult nsOSHelperAppService::FindOSMimeInfoForType ( const char *  aMimeContentType,
nsIURI aURI,
char **  aFileExtension,
nsIMIMEInfo **  aMIMEInfo 
) [protected]
void nsOSHelperAppService::FixFilePermissions ( nsILocalFile aFile) [protected, virtual]

Fixes the file permissions to be correct.

Base class has a no-op implementation, subclasses can use this to correctly inherit ACLs from the parent directory, to make the permissions obey the umask, etc.

Reimplemented from nsExternalHelperAppService.

Definition at line 1677 of file nsOSHelperAppService.cpp.

{
  aFile->SetPermissions(mPermissions); 
}
nsresult nsOSHelperAppService::GetApplicationAndParametersFromINI ( const nsACString &  aProtocol,
char *  app,
ULONG  appLength,
char *  param,
ULONG  paramLength 
) [private]

Definition at line 1147 of file nsOSHelperAppService.cpp.

{
  /* initialize app to '\0' for later check */
  *app = '\0';

  /* http or https */
  if ((aProtocol == NS_LITERAL_CSTRING("http")) ||
      (aProtocol == NS_LITERAL_CSTRING("https"))) {
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultBrowserExe",
                          "",
                          app,
                          appLength);
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultParameters",
                          "",
                          param,
                          paramLength);
  }
  /* mailto: */
  else if (aProtocol == NS_LITERAL_CSTRING("mailto")) {
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultMailExe",
                          "",
                          app,
                          appLength);
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultMailParameters",
                          "",
                          param,
                          paramLength);
  }
  /* ftp */
  else if (aProtocol == NS_LITERAL_CSTRING("ftp")) {
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultFTPExe",
                          "",
                          app,
                          appLength);
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultFTPParameters",
                          "",
                          param,
                          paramLength);
  }
  /* news: or snews: */
  else if ((aProtocol == NS_LITERAL_CSTRING("news")) ||
           (aProtocol == NS_LITERAL_CSTRING("snews"))) {
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultNewsExe",
                          "",
                          app,
                          appLength);
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultNewsParameters",
                          "",
                          param,
                          paramLength);
  }
  /* irc: */
  else if (aProtocol == NS_LITERAL_CSTRING("irc")) {
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultIRCExe",
                          "",
                          app,
                          appLength);
    PrfQueryProfileString(HINI_USER,
                          "WPURLDEFAULTSETTINGS",
                          "DefaultIRCParameters",
                          "",
                          param,
                          paramLength);
  }
  else {
    NS_WARNING("GetApplicationAndParametersFromINI(): unsupported protocol scheme");
    return NS_ERROR_FAILURE;
  }

  /* application string in INI was empty */
  if (app[0] == '\0')
    return NS_ERROR_FAILURE;

  return NS_OK;
}
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription ( const nsACString &  aScheme,
nsAString &  _retval 
)

Definition at line 127 of file nsOSHelperAppService.cpp.

{
  nsresult rv = NS_ERROR_NOT_AVAILABLE;

  CFStringRef schemeCFString = 
    ::CFStringCreateWithBytes(kCFAllocatorDefault,
                              (const UInt8 *)PromiseFlatCString(aScheme).get(),
                              aScheme.Length(),
                              kCFStringEncodingUTF8,
                              false);
  if (schemeCFString) {
    // Since the public API (LSGetApplicationForURL) fails every now and then,
    // we're using undocumented _LSCopyDefaultSchemeHandlerURL
    CFURLRef handlerBundleURL;
    OSStatus err = ::_LSCopyDefaultSchemeHandlerURL(schemeCFString,
                                                    &handlerBundleURL);
    if (err == noErr) {
      CFBundleRef handlerBundle = ::CFBundleCreate(NULL, handlerBundleURL);
      if (handlerBundle) {
        // Get the human-readable name of the default handler bundle
        CFStringRef bundleName =
          (CFStringRef)::CFBundleGetValueForInfoDictionaryKey(handlerBundle,
                                                              kCFBundleNameKey);
        if (bundleName) {
          nsAutoBuffer<UniChar, 255> buffer;
          CFIndex bundleNameLength = ::CFStringGetLength(bundleName);
          buffer.EnsureElemCapacity(bundleNameLength);
          ::CFStringGetCharacters(bundleName, CFRangeMake(0, bundleNameLength),
                                  buffer.get());
          _retval.Assign(buffer.get(), bundleNameLength);
          rv = NS_OK;
        }

        ::CFRelease(handlerBundle);
      }

      ::CFRelease(handlerBundleURL);
    }

    ::CFRelease(schemeCFString);
  }

  return rv;
}

Here is the call graph for this function:

NS_IMETHOD nsOSHelperAppService::GetApplicationDescription ( const nsACString &  aScheme,
nsAString &  _retval 
)
NS_IMETHOD nsOSHelperAppService::GetApplicationDescription ( const nsACString &  aScheme,
nsAString &  _retval 
)
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription ( const nsACString &  aScheme,
nsAString &  _retval 
)
AString nsIExternalProtocolService::getApplicationDescription ( in AUTF8String  aScheme) [inherited]

Gets a human-readable description for the application responsible for handling a specific protocol.

Parameters:
aSchemeThe scheme to look up. For example, "mms".
Exceptions:
NS_ERROR_NOT_IMPLEMENTEDIf getting descriptions for protocol helpers is not supported
NS_ERROR_NOT_AVAILABLEIf no protocol helper exists for this scheme, or if it is not possible to get a description for it.
already_AddRefed< nsMIMEInfoWin > nsOSHelperAppService::GetByExtension ( const nsAFlatString aFileExt,
const char *  aTypeHint = nsnull 
) [protected]

Definition at line 513 of file nsOSHelperAppService.cpp.

{
  if (aFileExt.IsEmpty())
    return nsnull;

  // windows registry assumes your file extension is going to include the '.'.
  // so make sure it's there...
  nsAutoString fileExtToUse;
  if (aFileExt.First() != PRUnichar('.'))
    fileExtToUse = PRUnichar('.');

  fileExtToUse.Append(aFileExt);

  // o.t. try to get an entry from the windows registry.
  nsCOMPtr<nsIWindowsRegKey> regKey = 
    do_CreateInstance("@mozilla.org/windows-registry-key;1");
  if (!regKey) 
    return nsnull; 

  nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
                             fileExtToUse,
                             nsIWindowsRegKey::ACCESS_QUERY_VALUE);
  if (NS_FAILED(rv))
    return nsnull; 

  nsCAutoString typeToUse;
  if (aTypeHint && *aTypeHint) {
    typeToUse.Assign(aTypeHint);
  }
  else {
    nsAutoString temp;
    if (NS_FAILED(regKey->ReadStringValue(NS_LITERAL_STRING("Content Type"), 
                  temp))) {
      return nsnull; 
    }
    // Content-Type is always in ASCII
    LossyAppendUTF16toASCII(temp, typeToUse);
  }

  nsMIMEInfoWin* mimeInfo = new nsMIMEInfoWin(typeToUse);
  if (!mimeInfo)
    return nsnull; // out of memory

  NS_ADDREF(mimeInfo);
  // don't append the '.'
  mimeInfo->AppendExtension(NS_ConvertUTF16toUTF8(Substring(fileExtToUse, 1)));

  mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);

  nsAutoString description;
  PRBool found = NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(), 
                                                      description));

  nsAutoString defaultDescription;
  nsCOMPtr<nsIFile> defaultApplication;
  GetDefaultAppInfo(description, defaultDescription,
                    getter_AddRefs(defaultApplication));

  mimeInfo->SetDefaultDescription(defaultDescription);
  mimeInfo->SetDefaultApplicationHandler(defaultApplication);

  // Get other nsIMIMEInfo fields from registry, if possible.
  if (found)
  {
      GetMIMEInfoFromRegistry(description, mimeInfo);
  }
  else {
    NS_IF_RELEASE(mimeInfo); // we failed to really find an entry in the registry
  }

  return mimeInfo;
}

Here is the call graph for this function:

nsresult nsOSHelperAppService::GetDefaultAppInfo ( const nsAString &  aTypeName,
nsAString &  aDefaultDescription,
nsIFile **  aDefaultApplication 
) [protected]

Definition at line 396 of file nsOSHelperAppService.cpp.

{
  // If all else fails, use the file type key name, which will be 
  // something like "pngfile" for .pngs, "WMVFile" for .wmvs, etc. 
  aDefaultDescription = aTypeName;
  *aDefaultApplication = nsnull;

  nsAutoString handlerKeyName(aTypeName);
  handlerKeyName.AppendLiteral("\\shell\\open\\command");
  nsCOMPtr<nsIWindowsRegKey> regKey = 
    do_CreateInstance("@mozilla.org/windows-registry-key;1");
  if (!regKey) 
    return NS_OK;

  nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
                             handlerKeyName, 
                             nsIWindowsRegKey::ACCESS_QUERY_VALUE);
  if (NS_FAILED(rv))
    return NS_OK;
   
  // OK, the default value here is the description of the type.
  nsAutoString handlerCommand;
  rv = regKey->ReadStringValue(EmptyString(), handlerCommand);
  if (NS_FAILED(rv))
    return NS_OK;

  nsAutoString handlerFilePath;
  // First look to see if we're invoking a Windows shell service, such as 
  // the Picture & Fax Viewer, which are invoked through rundll32.exe, and
  // so we need to extract the DLL path because that's where the version
  // info is held - not in rundll32.exe
  //
  // The format of rundll32.exe calls is:
  //
  // rundll32.exe c:\path\to.dll,Function %args
  //
  // What we want is the DLL - since that's where the real application name
  // is stored, e.g. zipfldr.dll, shimgvw.dll, etc. 
  // 
  // Working from the end of the registry value, the path begins at the last
  // comma in the string (stripping off Function and args) to the position
  // just after the first space (the space after rundll32.exe).
  // 
  NS_NAMED_LITERAL_STRING(rundllSegment, "rundll32.exe ");
  if (StringBeginsWith(handlerCommand, rundllSegment)) {
    PRInt32 lastCommaPos = handlerCommand.RFindChar(',');
    PRUint32 rundllSegmentLength = rundllSegment.Length();
    PRUint32 len;
    if (lastCommaPos != kNotFound)
      len = lastCommaPos - rundllSegmentLength;
    else
      len = handlerCommand.Length() - rundllSegmentLength;
    handlerFilePath = Substring(handlerCommand, rundllSegmentLength, len);
  }
  else
    handlerFilePath = handlerCommand;

  // Trim any command parameters so that we have a native path we can 
  // initialize a local file with...
  RemoveParameters(handlerFilePath);

  // Similarly replace embedded environment variables... (this must be done
  // AFTER |RemoveParameters| since it may introduce spaces into the path
  // string)

  if (sIsNT) {
    DWORD required = ::ExpandEnvironmentStringsW(handlerFilePath.get(),
                                                 L"", 0);
    if (!required) 
      return NS_ERROR_FAILURE;

    nsAutoArrayPtr<WCHAR> destination(new WCHAR[required]); 
    if (!destination)
      return NS_ERROR_OUT_OF_MEMORY;
    if (!::ExpandEnvironmentStringsW(handlerFilePath.get(), destination,
                                     required))
      return NS_ERROR_FAILURE;

    handlerFilePath = destination;
  }
  else {
    nsCAutoString nativeHandlerFilePath; 
    NS_CopyUnicodeToNative(handlerFilePath, nativeHandlerFilePath);
    DWORD required = ::ExpandEnvironmentStringsA(nativeHandlerFilePath.get(),
                                                 "", 0);
    if (!required) 
      return NS_ERROR_FAILURE;

    nsAutoArrayPtr<char> destination(new char[required]); 
    if (!destination)
      return NS_ERROR_OUT_OF_MEMORY;
    if (!::ExpandEnvironmentStringsA(nativeHandlerFilePath.get(), 
                                     destination, required))
      return NS_ERROR_FAILURE;

    NS_CopyNativeToUnicode(nsDependentCString(destination), handlerFilePath);
  }

  nsCOMPtr<nsILocalFile> lf;
  NS_NewLocalFile(handlerFilePath, PR_TRUE, getter_AddRefs(lf));
  if (!lf)
    return NS_ERROR_OUT_OF_MEMORY;

  nsILocalFileWin* lfw = nsnull;
  CallQueryInterface(lf, &lfw);
  if (lfw) {
    // The "FileDescription" field contains the actual name of the application.
    lfw->GetVersionInfoField("FileDescription", aDefaultDescription);
    // QI addref'ed for us.
    *aDefaultApplication = lfw;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsOSHelperAppService::GetExtensionsAndDescriptionFromMimetypesFile ( const nsAString &  aFilename,
const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsAString &  aFileExtensions,
nsAString &  aDescription 
) [static, private]

Definition at line 548 of file nsOSHelperAppService.cpp.

                                                                                            {
  LOG(("-- GetExtensionsAndDescriptionFromMimetypesFile\n"));
  LOG(("Getting extensions and description from types file '%s'\n",
       NS_LossyConvertUCS2toASCII(aFilename).get()));
  LOG(("Using type '%s/%s'\n",
       NS_LossyConvertUCS2toASCII(aMajorType).get(),
       NS_LossyConvertUCS2toASCII(aMinorType).get()));

  nsresult rv = NS_OK;
  nsCOMPtr<nsIFileInputStream> mimeFile;
  nsCOMPtr<nsILineInputStream> mimeTypes;
  PRBool netscapeFormat;
  nsAutoString buf;
  nsCAutoString cBuf;
  PRBool more = PR_FALSE;
  rv = CreateInputStream(aFilename, getter_AddRefs(mimeFile), getter_AddRefs(mimeTypes),
                         cBuf, &netscapeFormat, &more);

  if (NS_FAILED(rv)) {
    return rv;
  }
  
  nsAutoString extensions;
  nsString entry;
  entry.SetCapacity(100);
  nsAString::const_iterator majorTypeStart, majorTypeEnd,
                            minorTypeStart, minorTypeEnd,
                            descriptionStart, descriptionEnd;
  
  do {
    CopyASCIItoUTF16(cBuf, buf);
    // read through, building up an entry.  If we finish an entry, check for
    // a match and return out of the loop if we match

    // skip comments and empty lines
    if (!buf.IsEmpty() && buf.First() != '#') {
      entry.Append(buf);
      if (entry.Last() == '\\') {
        entry.Truncate(entry.Length() - 1);
        entry.Append(PRUnichar(' '));  // in case there is no trailing whitespace on this line
      } else {  // we have a full entry
        LOG(("Current entry: '%s'\n",
             NS_LossyConvertUCS2toASCII(entry).get()));
        if (netscapeFormat) {
          rv = ParseNetscapeMIMETypesEntry(entry,
                                           majorTypeStart, majorTypeEnd,
                                           minorTypeStart, minorTypeEnd,
                                           extensions,
                                           descriptionStart, descriptionEnd);
          
          if (NS_FAILED(rv)) {
            // We sometimes get things like RealPlayer appending
            // "normal" entries to "Netscape" .mime.types files.  Try
            // to handle that.  Bug 106381.
            LOG(("Bogus entry; trying 'normal' mode\n"));
            rv = ParseNormalMIMETypesEntry(entry,
                                           majorTypeStart, majorTypeEnd,
                                           minorTypeStart, minorTypeEnd,
                                           extensions,
                                           descriptionStart, descriptionEnd);
          }
        } else {
          rv = ParseNormalMIMETypesEntry(entry,
                                         majorTypeStart, majorTypeEnd,
                                         minorTypeStart,
                                         minorTypeEnd, extensions,
                                         descriptionStart, descriptionEnd);
          
          if (NS_FAILED(rv)) {
            // We sometimes get things like StarOffice prepending
            // "normal" entries to "Netscape" .mime.types files.  Try
            // to handle that.  Bug 136670.
            LOG(("Bogus entry; trying 'Netscape' mode\n"));
            rv = ParseNetscapeMIMETypesEntry(entry,
                                             majorTypeStart, majorTypeEnd,
                                             minorTypeStart, minorTypeEnd,
                                             extensions,
                                             descriptionStart, descriptionEnd);
          }
        }
        
        if (NS_SUCCEEDED(rv) &&
            Substring(majorTypeStart,
                      majorTypeEnd).Equals(aMajorType,
                                           nsCaseInsensitiveStringComparator())&&
            Substring(minorTypeStart,
                      minorTypeEnd).Equals(aMinorType,
                                           nsCaseInsensitiveStringComparator())) {
          // it's a match
          aFileExtensions.Assign(extensions);
          aDescription.Assign(Substring(descriptionStart, descriptionEnd));
          mimeFile->Close();
          return NS_OK;
        } else if (NS_FAILED(rv)) {
          LOG(("Failed to parse entry: %s\n", NS_LossyConvertUCS2toASCII(entry).get()));
        }
        
        entry.Truncate();
      }
    }
    if (!more) {
      rv = NS_ERROR_NOT_AVAILABLE;
      break;
    }
    // read the next line
    rv = mimeTypes->ReadLine(cBuf, &more);
  } while (NS_SUCCEEDED(rv));

  mimeFile->Close();
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::GetExtensionsAndDescriptionFromMimetypesFile ( const nsAString &  aFilename,
const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsAString &  aFileExtensions,
nsAString &  aDescription 
) [static, private]
nsresult nsOSHelperAppService::GetFileLocation ( const char *  aPrefName,
const char *  aEnvVarName,
PRUnichar **  aFileLocation 
) [static, private]

Definition at line 201 of file nsOSHelperAppService.cpp.

                                                                 {
  LOG(("-- GetFileLocation.  Pref: '%s'  EnvVar: '%s'\n",
       aPrefName,
       aEnvVarName));
  NS_PRECONDITION(aPrefName, "Null pref name passed; don't do that!");
  
  nsresult rv;
  *aFileLocation = nsnull;
  /* The lookup order is:
     1) user pref
     2) env var
     3) pref
  */
  nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIPrefBranch> prefBranch;
  rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
  NS_ENSURE_SUCCESS(rv, rv);

  /*
    If we have an env var we should check whether the pref is a user
    pref.  If we do not, we don't care.
  */
  nsCOMPtr<nsISupportsString> prefFileName;
  PRBool isUserPref = PR_FALSE;
  prefBranch->PrefHasUserValue(aPrefName, &isUserPref);
  if (isUserPref) {
    rv = prefBranch->GetComplexValue(aPrefName,
                                     NS_GET_IID(nsISupportsString),
                                     getter_AddRefs(prefFileName));
    if (NS_SUCCEEDED(rv)) {
      return prefFileName->ToString(aFileLocation);
    }
  }

  if (aEnvVarName && *aEnvVarName) {
    char* prefValue = PR_GetEnv(aEnvVarName);
    if (prefValue && *prefValue) {
      // the pref is in the system charset and it's a filepath... The
      // natural way to do the charset conversion is by just initing
      // an nsIFile with the native path and asking it for the Unicode
      // version.
      nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
      NS_ENSURE_SUCCESS(rv, rv);

      rv = file->InitWithNativePath(nsDependentCString(prefValue));
      NS_ENSURE_SUCCESS(rv, rv);

      nsAutoString unicodePath;
      rv = file->GetPath(unicodePath);
      NS_ENSURE_SUCCESS(rv, rv);
      
      *aFileLocation = ToNewUnicode(unicodePath);
      if (!*aFileLocation)
        return NS_ERROR_OUT_OF_MEMORY;
      return NS_OK;
    }
  }
  
  rv = prefBranch->GetComplexValue(aPrefName,
                                   NS_GET_IID(nsISupportsString),
                                   getter_AddRefs(prefFileName));
  if (NS_SUCCEEDED(rv)) {
    return prefFileName->ToString(aFileLocation);
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::GetFileLocation ( const char *  aPrefName,
const char *  aEnvVarName,
PRUnichar **  aFileLocation 
) [static, private]
nsresult nsOSHelperAppService::GetFileTokenForPath ( const PRUnichar platformAppPath,
nsIFile **  aFile 
) [virtual]

Given a string identifying an application, create an nsIFile representing it.

This function should look in $PATH for the application. The base class implementation will first try to interpret platformAppPath as an absolute path, and if that fails it will look for a file next to the mozilla executable. Subclasses can override this method if they want a different behaviour.

Parameters:
platformAppPathA platform specific path to an application that we got out of the rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform
aFile[out] An nsIFile representation of that platform application path.

Reimplemented from nsExternalHelperAppService.

Definition at line 190 of file nsOSHelperAppService.cpp.

{
  nsresult rv;
  nsCOMPtr<nsILocalFileMac> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv,rv);

  CFURLRef pathAsCFURL;
  CFStringRef pathAsCFString = ::CFStringCreateWithCharacters(NULL,
                                                              aPlatformAppPath,
                                                              nsCRT::strlen(aPlatformAppPath));
  if (!pathAsCFString)
    return NS_ERROR_OUT_OF_MEMORY;

  if (::CFStringGetCharacterAtIndex(pathAsCFString, 0) == '/') {
    // we have a Posix path
    pathAsCFURL = ::CFURLCreateWithFileSystemPath(nsnull, pathAsCFString,
                                                  kCFURLPOSIXPathStyle, PR_FALSE);
    if (!pathAsCFURL) {
      ::CFRelease(pathAsCFString);
      return NS_ERROR_OUT_OF_MEMORY;
    }
  }
  else {
    // if it doesn't start with a / it's not an absolute Posix path
    // let's check if it's a HFS path left over from old preferences

    // If it starts with a ':' char, it's not an absolute HFS path
    // so bail for that, and also if it's empty
    if (::CFStringGetLength(pathAsCFString) == 0 ||
        ::CFStringGetCharacterAtIndex(pathAsCFString, 0) == ':')
    {
      ::CFRelease(pathAsCFString);
      return NS_ERROR_FILE_UNRECOGNIZED_PATH;
    }

    pathAsCFURL = ::CFURLCreateWithFileSystemPath(nsnull, pathAsCFString,
                                                  kCFURLHFSPathStyle, PR_FALSE);
    if (!pathAsCFURL) {
      ::CFRelease(pathAsCFString);
      return NS_ERROR_OUT_OF_MEMORY;
    }
  }

  rv = localFile->InitWithCFURL(pathAsCFURL);
  ::CFRelease(pathAsCFString);
  ::CFRelease(pathAsCFURL);
  if (NS_FAILED(rv))
    return rv;
  *aFile = localFile;
  NS_IF_ADDREF(*aFile);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual nsresult nsOSHelperAppService::GetFileTokenForPath ( const PRUnichar platformAppPath,
nsIFile **  aFile 
) [virtual]

Given a string identifying an application, create an nsIFile representing it.

This function should look in $PATH for the application. The base class implementation will first try to interpret platformAppPath as an absolute path, and if that fails it will look for a file next to the mozilla executable. Subclasses can override this method if they want a different behaviour.

Parameters:
platformAppPathA platform specific path to an application that we got out of the rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform
aFile[out] An nsIFile representation of that platform application path.

Reimplemented from nsExternalHelperAppService.

Definition at line 1531 of file nsOSHelperAppService.cpp.

                                                                {
  // if the extension is empty, return immediately
  if (aFileExt.IsEmpty())
    return nsnull;
  
  LOG(("Here we do an extension lookup for '%s'\n", aFileExt.get()));

  nsresult rv;

  nsAutoString majorType, minorType,
               mime_types_description, mailcap_description,
               handler, mozillaFlags;
  
  rv = LookUpTypeAndDescription(NS_ConvertUTF8toUCS2(aFileExt),
                                majorType,
                                minorType,
                                mime_types_description);
  if (NS_FAILED(rv))
    return nsnull;

  NS_LossyConvertUTF16toASCII asciiMajorType(majorType);
  NS_LossyConvertUTF16toASCII asciiMinorType(minorType);

  LOG(("Type/Description results:  majorType='%s', minorType='%s', description='%s'\n",
          asciiMajorType.get(),
          asciiMinorType.get(),
          NS_LossyConvertUCS2toASCII(mime_types_description).get()));

  if (majorType.IsEmpty() && minorType.IsEmpty()) {
    // we didn't get a type mapping, so we can't do anything useful
    return nsnull;
  }

  nsCAutoString mimeType(asciiMajorType + NS_LITERAL_CSTRING("/") + asciiMinorType);
  nsMIMEInfoOS2* mimeInfo = new nsMIMEInfoOS2(mimeType);
  if (!mimeInfo)
    return nsnull;
  NS_ADDREF(mimeInfo);
  
  mimeInfo->AppendExtension(aFileExt);
  nsHashtable typeOptions; // empty hash table
  // The mailcap lookup is two-pass to handle the case of mailcap files
  // that have something like:
  //
  // text/*; emacs %s
  // text/rtf; soffice %s
  //
  // in that order.  We want to pick up "soffice" for text/rtf in such cases
  rv = LookUpHandlerAndDescription(majorType, minorType, typeOptions,
                                   handler, mailcap_description,
                                   mozillaFlags);
  if (NS_FAILED(rv)) {
    // maybe we have an entry for "majorType/*"?
    rv = LookUpHandlerAndDescription(majorType, NS_LITERAL_STRING("*"),
                                     typeOptions, handler, mailcap_description,
                                     mozillaFlags);
  }
  LOG(("Handler/Description results:  handler='%s', description='%s', mozillaFlags='%s'\n",
          NS_LossyConvertUCS2toASCII(handler).get(),
          NS_LossyConvertUCS2toASCII(mailcap_description).get(),
          NS_LossyConvertUCS2toASCII(mozillaFlags).get()));
  mailcap_description.Trim(" \t\"");
  mozillaFlags.Trim(" \t");
  if (!mime_types_description.IsEmpty()) {
    mimeInfo->SetDescription(mime_types_description);
  } else {
    mimeInfo->SetDescription(mailcap_description);
  }
  if (NS_SUCCEEDED(rv) && !handler.IsEmpty()) {
    nsCOMPtr<nsIFile> handlerFile;
    rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
    
    if (NS_SUCCEEDED(rv)) {
      mimeInfo->SetDefaultApplication(handlerFile);
      mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
      mimeInfo->SetDefaultDescription(handler);
    }
  } else {
    mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
  }

  return mimeInfo;
}

Here is the call graph for this function:

Definition at line 1616 of file nsOSHelperAppService.cpp.

                                                            {
  // if the extension is empty, return immediately
  if (aMIMEType.IsEmpty())
    return nsnull;
  
  LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType.get()));
  nsresult rv;
  nsAutoString extensions,
    mime_types_description, mailcap_description,
    handler, mozillaFlags;

  nsHashtable typeOptions;
  
  // extract the major and minor types
  NS_ConvertASCIItoUTF16 mimeType(aMIMEType);
  nsAString::const_iterator start_iter, end_iter,
                            majorTypeStart, majorTypeEnd,
                            minorTypeStart, minorTypeEnd;

  mimeType.BeginReading(start_iter);
  mimeType.EndReading(end_iter);

  // XXX FIXME: add typeOptions parsing in here
  rv = ParseMIMEType(start_iter, majorTypeStart, majorTypeEnd,
                     minorTypeStart, minorTypeEnd, end_iter);

  if (NS_FAILED(rv)) {
    return nsnull;
  }

  nsDependentSubstring majorType(majorTypeStart, majorTypeEnd);
  nsDependentSubstring minorType(minorTypeStart, minorTypeEnd);
  // The mailcap lookup is two-pass to handle the case of mailcap files
  // that have something like:
  //
  // text/*; emacs %s
  // text/rtf; soffice %s
  //
  // in that order.  We want to pick up "soffice" for text/rtf in such cases
  rv = LookUpHandlerAndDescription(majorType,
                                   minorType,
                                   typeOptions,
                                   handler,
                                   mailcap_description,
                                   mozillaFlags);
  if (NS_FAILED(rv)) {
    // maybe we have an entry for "majorType/*"?
    rv = LookUpHandlerAndDescription(majorType,
                                     NS_LITERAL_STRING("*"),
                                     typeOptions,
                                     handler,
                                     mailcap_description,
                                     mozillaFlags);
  }
  LOG(("Handler/Description results:  handler='%s', description='%s', mozillaFlags='%s'\n",
          NS_LossyConvertUCS2toASCII(handler).get(),
          NS_LossyConvertUCS2toASCII(mailcap_description).get(),
          NS_LossyConvertUCS2toASCII(mozillaFlags).get()));
  
  if (handler.IsEmpty()) {
    // we have no useful info....
    return nsnull;
  }
  
  mailcap_description.Trim(" \t\"");
  mozillaFlags.Trim(" \t");
  LookUpExtensionsAndDescription(majorType,
                                 minorType,
                                 extensions,
                                 mime_types_description);

  nsMIMEInfoOS2* mimeInfo = new nsMIMEInfoOS2(aMIMEType);
  if (!mimeInfo)
    return nsnull;
  NS_ADDREF(mimeInfo);

  mimeInfo->SetFileExtensions(NS_ConvertUCS2toUTF8(extensions));
  if (! mime_types_description.IsEmpty()) {
    mimeInfo->SetDescription(mime_types_description);
  } else {
    mimeInfo->SetDescription(mailcap_description);
  }

  nsCOMPtr<nsIFile> handlerFile;
  rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
  
  if (NS_SUCCEEDED(rv)) {
    mimeInfo->SetDefaultApplication(handlerFile);
    mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
    mimeInfo->SetDefaultDescription(handler);
  } else {
    mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
  }

  return mimeInfo;
}

Here is the call graph for this function:

NS_IMETHODIMP nsOSHelperAppService::GetFromTypeAndExtension ( const nsACString &  aType,
const nsACString &  aFileExt,
nsIMIMEInfo **  aMIMEInfo 
)

Definition at line 247 of file nsOSHelperAppService.cpp.

{
  // first, ask our base class....
  nsresult rv = nsExternalHelperAppService::GetFromTypeAndExtension(aType, aFileExt, aMIMEInfo);
  if (NS_SUCCEEDED(rv) && *aMIMEInfo) 
  {
    UpdateCreatorInfo(*aMIMEInfo);
  }
  return rv;
}

Here is the call graph for this function:

nsIMIMEInfo nsIMIMEService::getFromTypeAndExtension ( in ACString  aMIMEType,
in AUTF8String  aFileExt 
) [inherited]

Retrieves an nsIMIMEInfo using both the extension and the type of a file.

The type is given preference during the lookup. One of aMIMEType and aFileExt can be an empty string. At least one of aMIMEType and aFileExt must be nonempty.

nsresult nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile ( const nsAString &  aFilename,
const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsHashtable &  aTypeOptions,
nsAString &  aHandler,
nsAString &  aDescription,
nsAString &  aMozillaFlags 
) [static, private]

Definition at line 953 of file nsOSHelperAppService.cpp.

                                                                                        {

  LOG(("-- GetHandlerAndDescriptionFromMailcapFile\n"));
  LOG(("Getting handler and description from mailcap file '%s'\n",
       NS_LossyConvertUCS2toASCII(aFilename).get()));
  LOG(("Using type '%s/%s'\n",
       NS_LossyConvertUCS2toASCII(aMajorType).get(),
       NS_LossyConvertUCS2toASCII(aMinorType).get()));

  nsresult rv = NS_OK;
  PRBool more = PR_FALSE;
  
  nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
  if (NS_FAILED(rv))
    return rv;
  rv = file->InitWithPath(aFilename);
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIFileInputStream> mailcapFile(do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv));
  if (NS_FAILED(rv))
    return rv;
  rv = mailcapFile->Init(file, -1, -1, PR_FALSE);
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsILineInputStream> mailcap (do_QueryInterface(mailcapFile, &rv));

  if (NS_FAILED(rv)) {
    LOG(("Interface trouble in stream land!"));
    return rv;
  }

  nsString entry, buffer;
  nsCAutoString cBuffer;
  entry.SetCapacity(128);
  cBuffer.SetCapacity(80);
  rv = mailcap->ReadLine(cBuffer, &more);
  if (NS_FAILED(rv)) {
    mailcapFile->Close();
    return rv;
  }

  do {  // return on end-of-file in the loop

    CopyASCIItoUTF16(cBuffer, buffer);
    if (!buffer.IsEmpty() && buffer.First() != '#') {
      entry.Append(buffer);
      if (entry.Last() == '\\') {  // entry continues on next line
        entry.Truncate(entry.Length()-1);
        entry.Append(PRUnichar(' ')); // in case there is no trailing whitespace on this line
      } else {  // we have a full entry in entry.  Check it for the type
        LOG(("Current entry: '%s'\n",
             NS_LossyConvertUCS2toASCII(entry).get()));

        nsAString::const_iterator semicolon_iter,
                                  start_iter, end_iter,
                                  majorTypeStart, majorTypeEnd,
                                  minorTypeStart, minorTypeEnd;
        entry.BeginReading(start_iter);
        entry.EndReading(end_iter);
        semicolon_iter = start_iter;
        FindSemicolon(semicolon_iter, end_iter);
        if (semicolon_iter != end_iter) { // we have something resembling a valid entry
          rv = ParseMIMEType(start_iter, majorTypeStart, majorTypeEnd,
                             minorTypeStart, minorTypeEnd, semicolon_iter);
          if (NS_SUCCEEDED(rv) &&
              Substring(majorTypeStart,
                        majorTypeEnd).Equals(aMajorType,
                                             nsCaseInsensitiveStringComparator()) &&
              Substring(minorTypeStart,
                        minorTypeEnd).Equals(aMinorType,
                                             nsCaseInsensitiveStringComparator())) { // we have a match
            PRBool match = PR_TRUE;
            ++semicolon_iter;             // point at the first char past the semicolon
            start_iter = semicolon_iter;  // handler string starts here
            FindSemicolon(semicolon_iter, end_iter);
            while (start_iter != semicolon_iter &&
                   nsCRT::IsAsciiSpace(*start_iter)) {
              ++start_iter;
            }

            LOG(("The real handler is: '%s'\n",
                 NS_LossyConvertUCS2toASCII(Substring(start_iter,
                                                      semicolon_iter)).get()));
              
            // XXX ugly hack.  Just grab the executable name
            nsAString::const_iterator end_handler_iter = semicolon_iter;
            nsAString::const_iterator end_executable_iter = start_iter;
            while (end_executable_iter != end_handler_iter &&
                   !nsCRT::IsAsciiSpace(*end_executable_iter)) {
              ++end_executable_iter;
            }
            // XXX End ugly hack
            
            aHandler = Substring(start_iter, end_executable_iter);
            
            nsAString::const_iterator start_option_iter, end_optionname_iter, equal_sign_iter;
            PRBool equalSignFound;
            while (match &&
                   semicolon_iter != end_iter &&
                   ++semicolon_iter != end_iter) { // there are options left and we still match
              start_option_iter = semicolon_iter;
              // skip over leading whitespace
              while (start_option_iter != end_iter &&
                     nsCRT::IsAsciiSpace(*start_option_iter)) {
                ++start_option_iter;
              }
              if (start_option_iter == end_iter) { // nothing actually here
                break;
              }
              semicolon_iter = start_option_iter;
              FindSemicolon(semicolon_iter, end_iter);
              equal_sign_iter = start_option_iter;
              equalSignFound = PR_FALSE;
              while (equal_sign_iter != semicolon_iter && !equalSignFound) {
                switch(*equal_sign_iter) {
                case '\\':
                  equal_sign_iter.advance(2);
                  break;
                case '=':
                  equalSignFound = PR_TRUE;
                  break;
                default:
                  ++equal_sign_iter;
                  break;
                }
              }
              end_optionname_iter = start_option_iter;
              // find end of option name
              while (end_optionname_iter != equal_sign_iter &&
                     !nsCRT::IsAsciiSpace(*end_optionname_iter)) {
                ++end_optionname_iter;
              }                     
              nsDependentSubstring optionName(start_option_iter, end_optionname_iter);
              if (equalSignFound) {
                // This is an option that has a name and value
                if (optionName.EqualsLiteral("description")) {
                  aDescription = Substring(++equal_sign_iter, semicolon_iter);
                } else if (optionName.EqualsLiteral("x-mozilla-flags")) {
                  aMozillaFlags = Substring(++equal_sign_iter, semicolon_iter);
                } else if (optionName.EqualsLiteral("test")) {
                  nsCAutoString testCommand;
                  rv = UnescapeCommand(Substring(++equal_sign_iter, semicolon_iter),
                                       aMajorType,
                                       aMinorType,
                                       aTypeOptions,
                                       testCommand);
                  LOG(("Running Test: %s\n", testCommand.get()));
                  // XXX this should not use system(), since that can block the UI thread!
                  if (NS_SUCCEEDED(rv) && system(testCommand.get()) != 0) {
                    match = PR_FALSE;
                  }
                }
              } else {
                // This is an option that just has a name but no value (eg "copiousoutput")
              }
            }
            

            if (match) { // we did not fail any test clauses; all is good
              // get out of here
              mailcapFile->Close();
              return NS_OK;
            } else { // pretend that this match never happened
              aDescription.Truncate();
              aMozillaFlags.Truncate();
              aHandler.Truncate();
            }
          }
        }
        // zero out the entry for the next cycle
        entry.Truncate();
      }    
    }
    if (!more) {
      rv = NS_ERROR_NOT_AVAILABLE;
      break;
    }
    rv = mailcap->ReadLine(cBuffer, &more);
  } while (NS_SUCCEEDED(rv));
  mailcapFile->Close();
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile ( const nsAString &  aFilename,
const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsHashtable &  aTypeOptions,
nsAString &  aHandler,
nsAString &  aDescription,
nsAString &  aMozillaFlags 
) [static, private]
nsresult nsOSHelperAppService::GetHandlerAppFromPrefs ( const char *  aScheme,
nsIFile **  aApp 
) [private]

Definition at line 1189 of file nsOSHelperAppService.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIPrefService> srv(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  if (NS_FAILED(rv)) // we have no pref service... that's bad
    return rv;

  nsCOMPtr<nsIPrefBranch> branch;
  srv->GetBranch("network.protocol-handler.app.", getter_AddRefs(branch));
  if (!branch) // No protocol handlers set up -> can't load url
    return NS_ERROR_NOT_AVAILABLE;

  nsXPIDLCString appPath;
  rv = branch->GetCharPref(aScheme, getter_Copies(appPath));
  if (NS_FAILED(rv))
    return rv;

  LOG(("   found app %s\n", appPath.get()));

  // First, try to treat |appPath| as absolute path, if it starts with '/'
  NS_ConvertUTF8toUTF16 utf16AppPath(appPath);
  if (appPath.First() == '/') {
    nsILocalFile* file;
    rv = NS_NewLocalFile(utf16AppPath, PR_TRUE, &file);
    *aApp = file;
    // If this worked, we are finished
    if (NS_SUCCEEDED(rv))
      return NS_OK;
  }

  // Second, check for a file in the mozilla app directory
  rv = NS_GetSpecialDirectory(NS_OS_CURRENT_PROCESS_DIR, aApp);
  if (NS_SUCCEEDED(rv)) {
    rv = (*aApp)->Append(utf16AppPath);
    if (NS_SUCCEEDED(rv)) {
      PRBool exists = PR_FALSE;
      rv = (*aApp)->Exists(&exists);
      if (NS_SUCCEEDED(rv) && exists)
        return NS_OK;
    }
    NS_RELEASE(*aApp);
  }

  // Thirdly, search the path
  return GetFileTokenForPath(utf16AppPath.get(), aApp);
}

Here is the call graph for this function:

nsresult nsOSHelperAppService::GetMimeInfoFromExtension ( const char *  aFileExt,
nsMIMEInfoBeOS **  _retval 
) [protected]

Definition at line 208 of file nsOSHelperAppService.cpp.

                                   {
       // if the extension is null, return immediately
       if (!aFileExt || !*aFileExt)
              return NS_ERROR_INVALID_ARG;

       LOG(("Here we do an extension lookup for '%s'\n", aFileExt));

       BMimeType mimeType, tmpType;

       if( B_OK == mimeType.GuessMimeType(aFileExt, &tmpType))
              return SetMIMEInfoForType(tmpType.Type(), _retval);
       
       // Extension not found
       return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsOSHelperAppService::GetMimeInfoFromMIMEType ( const char *  aMIMEType,
nsMIMEInfoBeOS **  _retval 
) [protected]

Definition at line 225 of file nsOSHelperAppService.cpp.

                                   {
       // if the mime type is null, return immediately
       if (!aMIMEType || !*aMIMEType)
              return NS_ERROR_INVALID_ARG;

       LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType));
       
       BMimeType mimeType(aMIMEType);
       if (mimeType.IsInstalled())
              return SetMIMEInfoForType(aMIMEType, _retval);
       
       return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

already_AddRefed< nsIMIMEInfo > nsOSHelperAppService::GetMIMEInfoFromOS ( const nsACString &  aMIMEType,
const nsACString &  aFileExt,
PRBool aFound 
) [virtual]

Given a mimetype and an extension, looks up a mime info from the OS.

The mime type is given preference. This function follows the same rules as nsIMIMEService::GetFromTypeAndExtension. This is supposed to be overridden by the platform-specific nsOSHelperAppService!

Parameters:
aFileExtThe file extension; may be empty. UTF-8 encoded.
[out]aFoundShould be set to PR_TRUE if the os has a mapping, to PR_FALSE otherwise. Must not be null.
Returns:
A MIMEInfo. This function must return a MIMEInfo object if it can allocate one. The only justifiable reason for not returning one is an out-of-memory error. If null, the value of aFound is unspecified.

Implements nsExternalHelperAppService.

Definition at line 241 of file nsOSHelperAppService.cpp.

{
  *aFound = PR_TRUE;
  nsMIMEInfoBeOS* mi = nsnull;
  const nsCString& flatType = PromiseFlatCString(aMIMEType);
  const nsCString& flatExt = PromiseFlatCString(aFileExt);
  GetMimeInfoFromMIMEType(flatType.get(), &mi);
  if (mi)
    return mi;

  GetMimeInfoFromExtension(flatExt.get(), &mi);
  if (mi && !aMIMEType.IsEmpty())
    mi->SetMIMEType(aMIMEType);
  if (mi)
    return mi;

  *aFound = PR_FALSE;
  mi = new nsMIMEInfoBeOS(flatType);
  if (!mi)
    return nsnull;
  NS_ADDREF(mi);
  if (!aFileExt.IsEmpty())
    mi->AppendExtension(aFileExt);

  return mi;
}

Here is the call graph for this function:

already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS ( const nsACString &  aMIMEType,
const nsACString &  aFileExt,
PRBool aFound 
) [virtual]

Given a mimetype and an extension, looks up a mime info from the OS.

The mime type is given preference. This function follows the same rules as nsIMIMEService::GetFromTypeAndExtension. This is supposed to be overridden by the platform-specific nsOSHelperAppService!

Parameters:
aFileExtThe file extension; may be empty. UTF-8 encoded.
[out]aFoundShould be set to PR_TRUE if the os has a mapping, to PR_FALSE otherwise. Must not be null.
Returns:
A MIMEInfo. This function must return a MIMEInfo object if it can allocate one. The only justifiable reason for not returning one is an out-of-memory error. If null, the value of aFound is unspecified.

Implements nsExternalHelperAppService.

already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS ( const nsACString &  aMIMEType,
const nsACString &  aFileExt,
PRBool aFound 
) [virtual]

Given a mimetype and an extension, looks up a mime info from the OS.

The mime type is given preference. This function follows the same rules as nsIMIMEService::GetFromTypeAndExtension. This is supposed to be overridden by the platform-specific nsOSHelperAppService!

Parameters:
aFileExtThe file extension; may be empty. UTF-8 encoded.
[out]aFoundShould be set to PR_TRUE if the os has a mapping, to PR_FALSE otherwise. Must not be null.
Returns:
A MIMEInfo. This function must return a MIMEInfo object if it can allocate one. The only justifiable reason for not returning one is an out-of-memory error. If null, the value of aFound is unspecified.

Implements nsExternalHelperAppService.

already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS ( const nsACString &  aMIMEType,
const nsACString &  aFileExt,
PRBool aFound 
) [virtual]

Given a mimetype and an extension, looks up a mime info from the OS.

The mime type is given preference. This function follows the same rules as nsIMIMEService::GetFromTypeAndExtension. This is supposed to be overridden by the platform-specific nsOSHelperAppService!

Parameters:
aFileExtThe file extension; may be empty. UTF-8 encoded.
[out]aFoundShould be set to PR_TRUE if the os has a mapping, to PR_FALSE otherwise. Must not be null.
Returns:
A MIMEInfo. This function must return a MIMEInfo object if it can allocate one. The only justifiable reason for not returning one is an out-of-memory error. If null, the value of aFound is unspecified.

Implements nsExternalHelperAppService.

already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS ( const nsACString &  aMIMEType,
const nsACString &  aFileExt,
PRBool aFound 
) [virtual]

Given a mimetype and an extension, looks up a mime info from the OS.

The mime type is given preference. This function follows the same rules as nsIMIMEService::GetFromTypeAndExtension. This is supposed to be overridden by the platform-specific nsOSHelperAppService!

Parameters:
aFileExtThe file extension; may be empty. UTF-8 encoded.
[out]aFoundShould be set to PR_TRUE if the os has a mapping, to PR_FALSE otherwise. Must not be null.
Returns:
A MIMEInfo. This function must return a MIMEInfo object if it can allocate one. The only justifiable reason for not returning one is an out-of-memory error. If null, the value of aFound is unspecified.

Implements nsExternalHelperAppService.

nsresult nsOSHelperAppService::GetMIMEInfoFromRegistry ( const nsAFlatString fileType,
nsIMIMEInfo pInfo 
) [static, protected]

Definition at line 290 of file nsOSHelperAppService.cpp.

{
  nsresult rv = NS_OK;

  NS_ENSURE_ARG(pInfo);
  nsCOMPtr<nsIWindowsRegKey> regKey = 
    do_CreateInstance("@mozilla.org/windows-registry-key;1");
  if (!regKey) 
    return NS_ERROR_NOT_AVAILABLE;

  rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
                    fileType, nsIWindowsRegKey::ACCESS_QUERY_VALUE);
  if (NS_FAILED(rv))
    return NS_ERROR_FAILURE;
 
  // OK, the default value here is the description of the type.
  nsAutoString description;
  rv = regKey->ReadStringValue(EmptyString(), description);
  if (NS_SUCCEEDED(rv))
    pInfo->SetDescription(description);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

AUTF8String nsIMIMEService::getPrimaryExtension ( in ACString  aMIMEType,
in AUTF8String  aFileExt 
) [inherited]

Given a Type/Extension combination, returns the default extension for this type.

This may be identical to the passed-in extension.

Parameters:
aMIMETypeThe Type to get information on. Must not be empty.
aFileExtFile Extension. Can be empty.
nsresult nsOSHelperAppService::GetTypeAndDescriptionFromMimetypesFile ( const nsAString &  aFilename,
const nsAString &  aFileExtension,
nsAString &  aMajorType,
nsAString &  aMinorType,
nsAString &  aDescription 
) [static, private]

Definition at line 378 of file nsOSHelperAppService.cpp.

                                                                                      {
  LOG(("-- GetTypeAndDescriptionFromMimetypesFile\n"));
  LOG(("Getting type and description from types file '%s'\n",
       NS_LossyConvertUCS2toASCII(aFilename).get()));
  LOG(("Using extension '%s'\n",
       NS_LossyConvertUCS2toASCII(aFileExtension).get()));
  nsresult rv = NS_OK;
  nsCOMPtr<nsIFileInputStream> mimeFile;
  nsCOMPtr<nsILineInputStream> mimeTypes;
  PRBool netscapeFormat;
  nsAutoString buf;
  nsCAutoString cBuf;
  PRBool more = PR_FALSE;
  rv = CreateInputStream(aFilename, getter_AddRefs(mimeFile), getter_AddRefs(mimeTypes),
                         cBuf, &netscapeFormat, &more);

  if (NS_FAILED(rv)) {
    return rv;
  }
  

  nsAutoString extensions;
  nsString entry;
  entry.SetCapacity(100);
  nsAString::const_iterator majorTypeStart, majorTypeEnd,
                            minorTypeStart, minorTypeEnd,
                            descriptionStart, descriptionEnd;

  do {
    CopyASCIItoUTF16(cBuf, buf);
    // read through, building up an entry.  If we finish an entry, check for
    // a match and return out of the loop if we match

    // skip comments and empty lines
    if (!buf.IsEmpty() && buf.First() != '#') {
      entry.Append(buf);
      if (entry.Last() == '\\') {
        entry.Truncate(entry.Length() - 1);
        entry.Append(PRUnichar(' '));  // in case there is no trailing whitespace on this line
      } else {  // we have a full entry
        LOG(("Current entry: '%s'\n",
             NS_LossyConvertUCS2toASCII(entry).get()));
        if (netscapeFormat) {
          rv = ParseNetscapeMIMETypesEntry(entry,
                                           majorTypeStart, majorTypeEnd,
                                           minorTypeStart, minorTypeEnd,
                                           extensions,
                                           descriptionStart, descriptionEnd);
          if (NS_FAILED(rv)) {
            // We sometimes get things like RealPlayer appending
            // "normal" entries to "Netscape" .mime.types files.  Try
            // to handle that.  Bug 106381.
            LOG(("Bogus entry; trying 'normal' mode\n"));
            rv = ParseNormalMIMETypesEntry(entry,
                                           majorTypeStart, majorTypeEnd,
                                           minorTypeStart, minorTypeEnd,
                                           extensions,
                                           descriptionStart, descriptionEnd);
          }
        } else {
          rv = ParseNormalMIMETypesEntry(entry,
                                         majorTypeStart, majorTypeEnd,
                                         minorTypeStart, minorTypeEnd,
                                         extensions,
                                         descriptionStart, descriptionEnd);
          if (NS_FAILED(rv)) {
            // We sometimes get things like StarOffice prepending
            // "normal" entries to "Netscape" .mime.types files.  Try
            // to handle that.  Bug 136670.
            LOG(("Bogus entry; trying 'Netscape' mode\n"));
            rv = ParseNetscapeMIMETypesEntry(entry,
                                             majorTypeStart, majorTypeEnd,
                                             minorTypeStart, minorTypeEnd,
                                             extensions,
                                             descriptionStart, descriptionEnd);
          }
        }

        if (NS_SUCCEEDED(rv)) { // entry parses
          nsAString::const_iterator start, end;
          extensions.BeginReading(start);
          extensions.EndReading(end);
          nsAString::const_iterator iter(start);

          while (start != end) {
            FindCharInReadable(',', iter, end);
            if (Substring(start, iter).Equals(aFileExtension,
                                              nsCaseInsensitiveStringComparator())) {
              // it's a match.  Assign the type and description and run
              aMajorType.Assign(Substring(majorTypeStart, majorTypeEnd));
              aMinorType.Assign(Substring(minorTypeStart, minorTypeEnd));
              aDescription.Assign(Substring(descriptionStart, descriptionEnd));
              mimeFile->Close();
              return NS_OK;
            }
            if (iter != end) {
              ++iter;
            }
            start = iter;
          }
        } else {
          LOG(("Failed to parse entry: %s\n", NS_LossyConvertUCS2toASCII(entry).get()));
        }
        // truncate the entry for the next iteration
        entry.Truncate();
      }
    }
    if (!more) {
      rv = NS_ERROR_NOT_AVAILABLE;
      break;
    }
    // read the next line
    rv = mimeTypes->ReadLine(cBuf, &more);
  } while (NS_SUCCEEDED(rv));

  mimeFile->Close();
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::GetTypeAndDescriptionFromMimetypesFile ( const nsAString &  aFilename,
const nsAString &  aFileExtension,
nsAString &  aMajorType,
nsAString &  aMinorType,
nsAString &  aDescription 
) [static, private]
ACString nsIMIMEService::getTypeFromExtension ( in AUTF8String  aFileExt) [inherited]

Retrieves a ACString representation of the MIME type associated with this file extension.

Parameters:
Afile extension (excluding the dot ('.')).
Returns:
The MIME type, if any.
ACString nsIMIMEService::getTypeFromFile ( in nsIFile  aFile) [inherited]
ACString nsIMIMEService::getTypeFromURI ( in nsIURI  aURI) [inherited]

Retrieves a ACString representation of the MIME type associated with this URI.

The association is purely file extension to MIME type based. No attempt to determine the type via server headers or byte scanning is made.

Parameters:
TheURI the user wants MIME info on.
Returns:
The MIME type, if any.
static PRBool nsOSHelperAppService::GetValueString ( HKEY  hKey,
const PRUnichar pValueName,
nsAString &  result 
) [static]

Get the string value of a registry value and store it in result.

Returns:
PR_TRUE on success, PR_FALSE on failure
void *PR_CALLBACK nsExternalHelperAppService::handleExternalLoadEvent ( PLEvent event) [static, protected, inherited]

Definition at line 1095 of file nsExternalHelperAppService.cpp.

{
  extLoadRequest* req = NS_STATIC_CAST(extLoadRequest*, event);
  if (req && sSrv && sSrv->isExternalLoadOK(req->uri, req->prompt))
    sSrv->LoadUriInternal(req->uri);

  return nsnull;
}

Check whether a handler for a specific protocol is "exposed" as a visible feature of the current application.

An exposed protocol handler is one that can be used in all contexts. A non-exposed protocol handler is one that can only be used internally by the application. For example, a non-exposed protocol would not be loaded by the application in response to a link click or a X-remote openURL command. Instead, it would be deferred to the system's external protocol handler.

void nsIExternalProtocolService::loadURI ( in nsIURI  aURI,
in nsIPrompt  aPrompt 
) [inherited]

Used to load a URI via an external application.

Might prompt the user for permission to load the external application. Replaces loadUrl()

Parameters:
aURIThe URI to load
aPromptIf null we grab one from windowwatcher if we need it

Definition at line 95 of file nsOSHelperAppService.cpp.

{
       LOG(("-- nsOSHelperAppService::LoadUrl\n"));
       nsresult rv = NS_OK;

       if (aURL) {
              // Get the Protocol
              nsCAutoString scheme;
              aURL->GetScheme(scheme);
              BString protoStr(scheme.get());
              protoStr.Prepend("application/x-vnd.Be.URL.");
              // Get the Spec
              nsCAutoString spec;
              aURL->GetSpec(spec);
              const char* args[] = { spec.get() };
              
              //Launch the app            
              BMimeType protocol;
              bool isInstalled = false;
              if (protocol.SetTo(protoStr.String()) == B_OK)
              {
                     if(protocol.IsInstalled())
                     {
                            isInstalled = true;  
                            be_roster->Launch(protoStr.String(), NS_ARRAY_LENGTH(args), (char **)args);
                     }
              }
              if ((!isInstalled) && (!strcmp("mailto", scheme.get())))
                     be_roster->Launch("text/x-email", NS_ARRAY_LENGTH(args), (char **)args);
       }
       return rv;
}

Here is the call graph for this function:

Used to load a url via an external protocol handler (if one exists)

Parameters:
aURLThe url to load
nsresult nsOSHelperAppService::LookUpExtensionsAndDescription ( const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsAString &  aFileExtensions,
nsAString &  aDescription 
) [static, private]

Definition at line 505 of file nsOSHelperAppService.cpp.

                                                                              {
  LOG(("-- LookUpExtensionsAndDescription for type '%s/%s'\n",
       NS_LossyConvertUCS2toASCII(aMajorType).get(),
       NS_LossyConvertUCS2toASCII(aMinorType).get()));
  nsresult rv = NS_OK;
  nsXPIDLString mimeFileName;

  rv = GetFileLocation("helpers.private_mime_types_file",
                       nsnull,
                       getter_Copies(mimeFileName));
  if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
    rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
                                                      aMajorType,
                                                      aMinorType,
                                                      aFileExtensions,
                                                      aDescription);
  } else {
    rv = NS_ERROR_NOT_AVAILABLE;
  }
  if (NS_FAILED(rv) || aFileExtensions.IsEmpty()) {
    rv = GetFileLocation("helpers.global_mime_types_file",
                         nsnull,
                         getter_Copies(mimeFileName));
    if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
      rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
                                                        aMajorType,
                                                        aMinorType,
                                                        aFileExtensions,
                                                        aDescription);
    } else {
      rv = NS_ERROR_NOT_AVAILABLE;
    }
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::LookUpExtensionsAndDescription ( const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsAString &  aFileExtensions,
nsAString &  aDescription 
) [static, private]
nsresult nsOSHelperAppService::LookUpHandlerAndDescription ( const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsHashtable &  aTypeOptions,
nsAString &  aHandler,
nsAString &  aDescription,
nsAString &  aMozillaFlags 
) [static, private]

Definition at line 906 of file nsOSHelperAppService.cpp.

                                                                            {
  LOG(("-- LookUpHandlerAndDescription for type '%s/%s'\n",
       NS_LossyConvertUCS2toASCII(aMajorType).get(),
       NS_LossyConvertUCS2toASCII(aMinorType).get()));
  nsresult rv = NS_OK;
  nsXPIDLString mailcapFileName;

  rv = GetFileLocation("helpers.private_mailcap_file",
                       "PERSONAL_MAILCAP",
                       getter_Copies(mailcapFileName));
  if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
    rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
                                                 aMajorType,
                                                 aMinorType,
                                                 aTypeOptions,
                                                 aHandler,
                                                 aDescription,
                                                 aMozillaFlags);
  } else {
    rv = NS_ERROR_NOT_AVAILABLE;
  }
  if (NS_FAILED(rv) || aHandler.IsEmpty()) {
    rv = GetFileLocation("helpers.global_mailcap_file",
                         "MAILCAP",
                         getter_Copies(mailcapFileName));
    if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
      rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
                                                   aMajorType,
                                                   aMinorType,
                                                   aTypeOptions,
                                                   aHandler,
                                                   aDescription,
                                                   aMozillaFlags);
    } else {
      rv = NS_ERROR_NOT_AVAILABLE;
    }
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::LookUpHandlerAndDescription ( const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsHashtable &  aTypeOptions,
nsAString &  aHandler,
nsAString &  aDescription,
nsAString &  aMozillaFlags 
) [static, private]
nsresult nsOSHelperAppService::LookUpTypeAndDescription ( const nsAString &  aFileExtension,
nsAString &  aMajorType,
nsAString &  aMinorType,
nsAString &  aDescription 
) [static, private]

Definition at line 277 of file nsOSHelperAppService.cpp.

                                                                        {
  LOG(("-- LookUpTypeAndDescription for extension '%s'\n",
       NS_LossyConvertUCS2toASCII(aFileExtension).get()));
  nsresult rv = NS_OK;
  nsXPIDLString mimeFileName;

  rv = GetFileLocation("helpers.private_mime_types_file",
                       nsnull,
                       getter_Copies(mimeFileName));
  if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
    rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
                                                aFileExtension,
                                                aMajorType,
                                                aMinorType,
                                                aDescription);
  } else {
    rv = NS_ERROR_NOT_AVAILABLE;
  }
  if (NS_FAILED(rv) || aMajorType.IsEmpty()) {
    rv = GetFileLocation("helpers.global_mime_types_file",
                         nsnull,
                         getter_Copies(mimeFileName));
    if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
      rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
                                                  aFileExtension,
                                                  aMajorType,
                                                  aMinorType,
                                                  aDescription);
    } else {
      rv = NS_ERROR_NOT_AVAILABLE;
    }
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsOSHelperAppService::LookUpTypeAndDescription ( const nsAString &  aFileExtension,
nsAString &  aMajorType,
nsAString &  aMinorType,
nsAString &  aDescription,
PRBool  aUserData 
) [static, private]

Definition at line 279 of file nsOSHelperAppService.cpp.

                                                                 {
  LOG(("-- LookUpTypeAndDescription for extension '%s'\n",
       NS_LossyConvertUCS2toASCII(aFileExtension).get()));
  nsresult rv = NS_OK;
  nsXPIDLString mimeFileName;

  const char* filenamePref = aUserData ?
    "helpers.private_mime_types_file" : "helpers.global_mime_types_file";
  
  rv = GetFileLocation(filenamePref,
                       nsnull,
                       getter_Copies(mimeFileName));
  if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
    rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
                                                aFileExtension,
                                                aMajorType,
                                                aMinorType,
                                                aDescription);
  } else {
    rv = NS_ERROR_NOT_AVAILABLE;
  }

  return rv;
}

Here is the call graph for this function:

Initializes the RDF datasource from the profile.

Return values:
NS_OKLoading was successful
errorcodeLoading failed
See also:
mOverRideDataSource

Initializes internal state.

Will be called automatically when this service is first instantiated.

Given a content type, look up the user override information to see if we have a mime info object representing this content type.

The user over ride information is contained in a in memory data source.

Parameters:
aMIMEInfoThe mime info to fill with the information

Given an extension, look up the user override information to see if we have a mime info object representing this extension.

The user over ride information is contained in an in-memory data source.

Does not change the MIME Type of the MIME Info.

Parameters:
aMIMEInfoThe mime info to fill with the information

Looks up the MIME Type for a given extension in the RDF Datasource.

Parameters:
aExtensionThe extension to look for
aType[out] The type, if found
Returns:
PR_TRUE if found, PR_FALSE otherwise

Helper routine used to test whether a given mime type is in our mimeTypes.rdf data source.

nsExternalHelperAppService::NS_HIDDEN_ ( nsresult  ) [protected, inherited]

Helper routines for digesting the data source and filling in a mime info object for a given content type inside that data source.

The content type of the MIME Info will not be changed.

nsExternalHelperAppService::NS_HIDDEN_ ( nsresult  ) const [protected, inherited]
See also:
FillTopLevelProperties
nsExternalHelperAppService::NS_HIDDEN_ ( nsresult  ) [protected, inherited]

A small helper function which gets the target for a given source and property.

QIs to a literal and returns a CONST ptr to the string value of that target

nsExternalHelperAppService::NS_HIDDEN_ ( nsresult  ) const [protected, inherited]

Searches the "extra" array of MIMEInfo objects for an object with a specific type.

If found, it will modify the passed-in MIMEInfo. Otherwise, it will return an error and the MIMEInfo will be untouched.

Parameters:
aContentTypeThe type to search for.
aMIMEInfo[inout] The mime info, if found
nsExternalHelperAppService::NS_HIDDEN_ ( nsresult  ) const [protected, inherited]

Searches the "extra" array of MIMEInfo objects for an object with a specific extension.

Does not change the MIME Type of the MIME Info.

See also:
GetMIMEInfoForMimeTypeFromExtras
nsExternalHelperAppService::NS_HIDDEN_ ( PRBool  ) const [protected, inherited]

Searches the "extra" array for a MIME type, and gets its extension.

Parameters:
aExtensionThe extension to search for
aMIMEType[out] The found MIME type.
Returns:
PR_TRUE if the extension was found, PR_FALSE otherwise.
nsExternalHelperAppService::NS_HIDDEN_ ( nsresult  ) [protected, inherited]

Functions related to the tempory file cleanup service provided by nsExternalHelperAppService.

virtual nsExternalHelperAppService::NS_HIDDEN_ ( nsresult  ) [protected, pure virtual, inherited]

OS-specific loading of external URLs.

nsExternalHelperAppService::NS_HIDDEN_ ( PRBool  ) [protected, inherited]
nsExternalHelperAppService::NS_HIDDEN_ ( PRBool  ) [protected, inherited]
void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.
nsresult nsOSHelperAppService::ParseNetscapeMIMETypesEntry ( const nsAString &  aEntry,
nsAString::const_iterator &  aMajorTypeStart,
nsAString::const_iterator &  aMajorTypeEnd,
nsAString::const_iterator &  aMinorTypeStart,
nsAString::const_iterator &  aMinorTypeEnd,
nsAString &  aExtensions,
nsAString::const_iterator &  aDescriptionStart,
nsAString::const_iterator &  aDescriptionEnd 
) [static, private]

Definition at line 676 of file nsOSHelperAppService.cpp.

                                                                                            {
  LOG(("-- ParseNetscapeMIMETypesEntry\n"));
  NS_ASSERTION(!aEntry.IsEmpty(), "Empty Netscape MIME types entry being parsed.");
  
  nsAString::const_iterator start_iter, end_iter, match_start, match_end;

  aEntry.BeginReading(start_iter);
  aEntry.EndReading(end_iter);
  
  // skip trailing whitespace
  do {
    --end_iter;
  } while (end_iter != start_iter &&
           nsCRT::IsAsciiSpace(*end_iter));
  // if we're pointing to a quote, don't advance -- we don't want to
  // include the quote....
  if (*end_iter != '"')
    ++end_iter;
  match_start = start_iter;
  match_end = end_iter;
  
  // Get the major and minor types
  // First the major type
  if (! FindInReadable(NS_LITERAL_STRING("type="), match_start, match_end)) {
    return NS_ERROR_FAILURE;
  }
  
  match_start = match_end;
  
  while (match_end != end_iter &&
         *match_end != '/') {
    ++match_end;
  }
  if (match_end == end_iter) {
    return NS_ERROR_FAILURE;
  }
  
  aMajorTypeStart = match_start;
  aMajorTypeEnd = match_end;

  // now the minor type
  if (++match_end == end_iter) {
    return NS_ERROR_FAILURE;
  }
  
  match_start = match_end;
  
  while (match_end != end_iter &&
         !nsCRT::IsAsciiSpace(*match_end) &&
         *match_end != ';') {
    ++match_end;
  }
  if (match_end == end_iter) {
    return NS_ERROR_FAILURE;
  }
  
  aMinorTypeStart = match_start;
  aMinorTypeEnd = match_end;
  
  // ignore everything up to the end of the mime type from here on
  start_iter = match_end;
  
  // get the extensions
  match_start = match_end;
  match_end = end_iter;
  if (FindInReadable(NS_LITERAL_STRING("exts="), match_start, match_end)) {
    nsAString::const_iterator extStart, extEnd;

    if (match_end == end_iter ||
        (*match_end == '"' && ++match_end == end_iter)) {
      return NS_ERROR_FAILURE;
    }
  
    extStart = match_end;
    match_start = extStart;
    match_end = end_iter;
    if (FindInReadable(NS_LITERAL_STRING("desc=\""), match_start, match_end)) {
      // exts= before desc=, so we have to find the actual end of the extensions
      extEnd = match_start;
      if (extEnd == extStart) {
        return NS_ERROR_FAILURE;
      }
    
      do {
        --extEnd;
      } while (extEnd != extStart &&
               nsCRT::IsAsciiSpace(*extEnd));
      
      if (extEnd != extStart && *extEnd == '"') {
        --extEnd;
      }
    } else {
      // desc= before exts=, so we can use end_iter as the end of the extensions
      extEnd = end_iter;
    }
    aExtensions = Substring(extStart, extEnd);
  } else {
    // no extensions
    aExtensions.Truncate();
  }

  // get the description
  match_start = start_iter;
  match_end = end_iter;
  if (FindInReadable(NS_LITERAL_STRING("desc=\""), match_start, match_end)) {
    aDescriptionStart = match_end;
    match_start = aDescriptionStart;
    match_end = end_iter;
    if (FindInReadable(NS_LITERAL_STRING("exts="), match_start, match_end)) {
      // exts= after desc=, so have to find actual end of description
      aDescriptionEnd = match_start;
      if (aDescriptionEnd == aDescriptionStart) {
        return NS_ERROR_FAILURE;
      }
      
      do {
        --aDescriptionEnd;
      } while (aDescriptionEnd != aDescriptionStart &&
               nsCRT::IsAsciiSpace(*aDescriptionEnd));
      
      if (aDescriptionStart != aDescriptionStart && *aDescriptionEnd == '"') {
        --aDescriptionEnd;
      }
    } else {
      // desc= after exts=, so use end_iter for the description end
      aDescriptionEnd = end_iter;
    }
  } else {
    // no description
    aDescriptionStart = start_iter;
    aDescriptionEnd = start_iter;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::ParseNetscapeMIMETypesEntry ( const nsAString &  aEntry,
nsAString::const_iterator &  aMajorTypeStart,
nsAString::const_iterator &  aMajorTypeEnd,
nsAString::const_iterator &  aMinorTypeStart,
nsAString::const_iterator &  aMinorTypeEnd,
nsAString &  aExtensions,
nsAString::const_iterator &  aDescriptionStart,
nsAString::const_iterator &  aDescriptionEnd 
) [static, private]
nsresult nsOSHelperAppService::ParseNormalMIMETypesEntry ( const nsAString &  aEntry,
nsAString::const_iterator &  aMajorTypeStart,
nsAString::const_iterator &  aMajorTypeEnd,
nsAString::const_iterator &  aMinorTypeStart,
nsAString::const_iterator &  aMinorTypeEnd,
nsAString &  aExtensions,
nsAString::const_iterator &  aDescriptionStart,
nsAString::const_iterator &  aDescriptionEnd 
) [static, private]

Definition at line 826 of file nsOSHelperAppService.cpp.

                                                                                          {
  LOG(("-- ParseNormalMIMETypesEntry\n"));
  NS_ASSERTION(!aEntry.IsEmpty(), "Empty Normal MIME types entry being parsed.");

  nsAString::const_iterator start_iter, end_iter, iter;
  
  aEntry.BeginReading(start_iter);
  aEntry.EndReading(end_iter);

  // no description
  aDescriptionStart = start_iter;
  aDescriptionEnd = start_iter;

  // skip leading whitespace
  while (start_iter != end_iter && nsCRT::IsAsciiSpace(*start_iter)) {
    ++start_iter;
  }
  if (start_iter == end_iter) {
    return NS_ERROR_FAILURE;
  }
  // skip trailing whitespace
  do {
    --end_iter;
  } while (end_iter != start_iter && nsCRT::IsAsciiSpace(*end_iter));
           
  ++end_iter; // point to first whitespace char (or to end of string)
  iter = start_iter;

  // get the major type
  if (! FindCharInReadable('/', iter, end_iter))
    return NS_ERROR_FAILURE;

  nsAString::const_iterator equals_sign_iter(start_iter);
  if (FindCharInReadable('=', equals_sign_iter, iter))
    return NS_ERROR_FAILURE; // see bug 136670
  
  aMajorTypeStart = start_iter;
  aMajorTypeEnd = iter;
  
  // get the minor type
  if (++iter == end_iter) {
    return NS_ERROR_FAILURE;
  }
  start_iter = iter;

  while (iter != end_iter && !nsCRT::IsAsciiSpace(*iter)) { 
    ++iter;
  }
  aMinorTypeStart = start_iter;
  aMinorTypeEnd = iter;

  // get the extensions
  aExtensions.Truncate();
  while (iter != end_iter) {
    while (iter != end_iter && nsCRT::IsAsciiSpace(*iter)) {
      ++iter;
    }

    start_iter = iter;
    while (iter != end_iter && !nsCRT::IsAsciiSpace(*iter)) {
      ++iter;
    }
    aExtensions.Append(Substring(start_iter, iter));
    if (iter != end_iter) { // not the last extension
      aExtensions.Append(PRUnichar(','));
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::ParseNormalMIMETypesEntry ( const nsAString &  aEntry,
nsAString::const_iterator &  aMajorTypeStart,
nsAString::const_iterator &  aMajorTypeEnd,
nsAString::const_iterator &  aMinorTypeStart,
nsAString::const_iterator &  aMinorTypeEnd,
nsAString &  aExtensions,
nsAString::const_iterator &  aDescriptionStart,
nsAString::const_iterator &  aDescriptionEnd 
) [static, private]
nsresult nsOSHelperAppService::SetMIMEInfoForType ( const char *  aMIMEType,
nsMIMEInfoBeOS **  _retval 
) [protected]

Definition at line 129 of file nsOSHelperAppService.cpp.

                                                                                                {

       LOG(("-- nsOSHelperAppService::SetMIMEInfoForType: %s\n",aMIMEType));

       nsresult rv = NS_ERROR_FAILURE;

       nsMIMEInfoBeOS* mimeInfo = new nsMIMEInfoBeOS(aMIMEType);
       if (mimeInfo) {
              NS_ADDREF(mimeInfo);
              BMimeType mimeType(aMIMEType);
              BMessage data;
              int32 index = 0;
              BString strData;
              LOG(("   Adding extensions:\n"));
              if (mimeType.GetFileExtensions(&data) == B_OK) {
                     while (data.FindString("extensions",index,&strData) == B_OK) {
                            // if the file extension includes the '.' then we don't want to include that when we append
                            // it to the mime info object.
                            if (strData.ByteAt(0) == '.')
                                   strData.RemoveFirst(".");
                            mimeInfo->AppendExtension(nsDependentCString(strData.String()));
                            LOG(("      %s\n",strData.String()));
                            index++;
                     }
              }

              char desc[B_MIME_TYPE_LENGTH + 1];
              if (mimeType.GetShortDescription(desc) == B_OK) {
                     mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc));
              } else {
                     if (mimeType.GetLongDescription(desc) == B_OK) {
                            mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc));
                     } else {
                            mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(aMIMEType));
                     }
              }
              
              LOG(("    Description: %s\n",desc));

              //set preferred app and app description
              char appSig[B_MIME_TYPE_LENGTH + 1];
              bool doSave = true;
              if (mimeType.GetPreferredApp(appSig) == B_OK) {
                     LOG(("    Got preferred ap\n"));
                     BMimeType app(appSig);
                     entry_ref ref;
                     BEntry entry;
                     BPath path;
                     if ((app.GetAppHint(&ref) == B_OK) &&
                             (entry.SetTo(&ref, false) == B_OK) &&
                             (entry.GetPath(&path) == B_OK)) {

                            LOG(("    Got our path!\n"));
                            nsCOMPtr<nsIFile> handlerFile;
                            rv = GetFileTokenForPath(NS_ConvertUTF8toUCS2(path.Path()).get(), getter_AddRefs(handlerFile));

                            if (NS_SUCCEEDED(rv)) {
                                   mimeInfo->SetDefaultApplication(handlerFile);
                                   mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
                                   mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(path.Leaf()));
                                   LOG(("    Preferred App: %s\n",path.Leaf()));
                                   doSave = false;
                            }
                     }
              }
              if (doSave) {
                     mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
                     LOG(("    No Preferred App\n"));
              }

              *_retval = mimeInfo;
              rv = NS_OK;
       }
       else
              rv = NS_ERROR_FAILURE;

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsOSHelperAppService::typeFromExtEquals ( const PRUnichar aExt,
const char *  aType 
) [static, protected]

Looks up the type for the extension aExt and compares it to aType.

Definition at line 321 of file nsOSHelperAppService.cpp.

{
  if (!aType)
    return PR_FALSE;
  nsAutoString fileExtToUse;
  if (aExt[0] != PRUnichar('.'))
    fileExtToUse = PRUnichar('.');

  fileExtToUse.Append(aExt);

  PRBool eq = PR_FALSE;
  nsCOMPtr<nsIWindowsRegKey> regKey = 
    do_CreateInstance("@mozilla.org/windows-registry-key;1");
  if (!regKey) 
    return eq;

  nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
                             fileExtToUse,
                             nsIWindowsRegKey::ACCESS_QUERY_VALUE);
  if (NS_FAILED(rv))
      return eq;
   
  nsAutoString type;
  rv = regKey->ReadStringValue(NS_LITERAL_STRING("Content Type"), type);
  if (NS_SUCCEEDED(rv))
     eq = type.EqualsASCII(aType);

  return eq;
}

Here is the call graph for this function:

nsresult nsOSHelperAppService::UnescapeCommand ( const nsAString &  aEscapedCommand,
const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsHashtable &  aTypeOptions,
nsACString &  aUnEscapedCommand 
) [static, private]

Definition at line 107 of file nsOSHelperAppService.cpp.

                                                                     {
  LOG(("-- UnescapeCommand"));
  LOG(("Command to escape: '%s'\n",
       NS_LossyConvertUCS2toASCII(aEscapedCommand).get()));
  //  XXX This function will need to get the mime type and various stuff like that being passed in to work properly
  
  LOG(("UnescapeCommand really needs some work -- it should actually do some unescaping\n"));

  CopyUTF16toUTF8(aEscapedCommand, aUnEscapedCommand);
  LOG(("Escaped command: '%s'\n",
       PromiseFlatCString(aUnEscapedCommand).get()));
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsOSHelperAppService::UnescapeCommand ( const nsAString &  aEscapedCommand,
const nsAString &  aMajorType,
const nsAString &  aMinorType,
nsHashtable &  aTypeOptions,
nsACString &  aUnEscapedCommand 
) [static, private]

Definition at line 338 of file nsOSHelperAppService.cpp.

{
  PRUint32 macCreatorType;
  PRUint32 macFileType;
  aMIMEInfo->GetMacType(&macFileType);
  aMIMEInfo->GetMacCreator(&macCreatorType);
  
  if (macFileType == 0 || macCreatorType == 0)
  {
    // okay these values haven't been initialized yet so fetch a mime object from internet config.
    nsCAutoString mimeType;
    aMIMEInfo->GetMIMEType(mimeType);
    nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
    if (icService)
    {
      nsCOMPtr<nsIMIMEInfo> osMimeObject;
      icService->FillInMIMEInfo(mimeType.get(), nsnull, getter_AddRefs(osMimeObject));
      if (osMimeObject)
      {
        osMimeObject->GetMacType(&macFileType);
        osMimeObject->GetMacCreator(&macCreatorType);
        aMIMEInfo->SetMacCreator(macCreatorType);
        aMIMEInfo->SetMacType(macFileType);
      } // if we got an os object
    } // if we got the ic service
  } // if the creator or file type hasn't been initialized yet
} 

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsExternalAppHandler [friend, inherited]

Definition at line 287 of file nsExternalHelperAppService.h.


Member Data Documentation

Definition at line 227 of file nsExternalHelperAppService.h.

Definition at line 237 of file nsExternalHelperAppService.h.

Definition at line 128 of file nsExternalHelperAppService.h.

Definition at line 221 of file nsExternalHelperAppService.h.

Definition at line 227 of file nsExternalHelperAppService.h.

nsACString& nsExternalHelperAppService::aMIMEType [protected, inherited]

Definition at line 268 of file nsExternalHelperAppService.h.

Definition at line 303 of file nsExternalHelperAppService.h.

Definition at line 237 of file nsExternalHelperAppService.h.

Definition at line 221 of file nsExternalHelperAppService.h.

Definition at line 227 of file nsExternalHelperAppService.h.

Definition at line 304 of file nsExternalHelperAppService.h.

nsACString& nsExternalHelperAppService::aType [inherited]

Definition at line 149 of file nsExternalHelperAppService.h.

Definition at line 206 of file nsExternalHelperAppService.h.

Definition at line 200 of file nsExternalHelperAppService.h.

Definition at line 202 of file nsExternalHelperAppService.h.

Definition at line 207 of file nsExternalHelperAppService.h.

Definition at line 203 of file nsExternalHelperAppService.h.

Definition at line 208 of file nsExternalHelperAppService.h.

Definition at line 205 of file nsExternalHelperAppService.h.

Definition at line 204 of file nsExternalHelperAppService.h.

Definition at line 201 of file nsExternalHelperAppService.h.

Whether mOverRideDataSource is initialized.

Definition at line 213 of file nsExternalHelperAppService.h.

Pointer to the datasource that contains the user override information.

See also:
InitDataSource

Definition at line 198 of file nsExternalHelperAppService.h.

Definition at line 82 of file nsOSHelperAppService.h.

Array for the files that should be deleted.

Definition at line 297 of file nsExternalHelperAppService.h.

Whether we're running on an OS that supports the *W registry functions.

Definition at line 79 of file nsOSHelperAppService.h.


The documentation for this class was generated from the following files: