Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions
nsMimeTypeArray Class Reference

#include <nsMimeTypeArray.h>

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

List of all members.

Public Member Functions

 nsMimeTypeArray (nsIDOMNavigator *navigator)
virtual ~nsMimeTypeArray ()
NS_DECL_ISUPPORTS NS_IMETHOD GetLength (PRUint32 *aLength)
NS_IMETHOD Item (PRUint32 aIndex, nsIDOMMimeType **aReturn)
NS_IMETHOD NamedItem (const nsAString &aName, nsIDOMMimeType **aReturn)
nsresult Refresh ()
nsIDOMMimeType item (in unsigned long index)
nsIDOMMimeType namedItem (in DOMString name)

Public Attributes

readonly attribute unsigned long length

Protected Attributes

nsIDOMNavigatormNavigator
PRUint32 mMimeTypeCount
nsIDOMMimeType ** mMimeTypeArray

Private Member Functions

nsresult GetMimeTypes ()
void Clear ()

Detailed Description

Definition at line 48 of file nsMimeTypeArray.h.


Constructor & Destructor Documentation

Definition at line 51 of file nsMimeTypeArray.cpp.

Definition at line 58 of file nsMimeTypeArray.cpp.

{
  Clear();
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 178 of file nsMimeTypeArray.cpp.

Here is the caller graph for this function:

Definition at line 77 of file nsMimeTypeArray.cpp.

{
  if (mMimeTypeArray == nsnull) {
    nsresult rv = GetMimeTypes();
    if (rv != NS_OK)
      return rv;
  }
  *aLength = mMimeTypeCount;
  return NS_OK;
}

Definition at line 196 of file nsMimeTypeArray.cpp.

{
  NS_PRECONDITION(!mMimeTypeArray && mMimeTypeCount==0,
                      "already initialized");

  nsIDOMPluginArray* pluginArray = nsnull;
  nsresult rv = mNavigator->GetPlugins(&pluginArray);
  if (rv == NS_OK) {
    // count up all possible MimeTypes, and collect them here. Later,
    // we'll remove duplicates.
    mMimeTypeCount = 0;
    PRUint32 pluginCount = 0;
    rv = pluginArray->GetLength(&pluginCount);
    if (rv == NS_OK) {
      PRUint32 i;
      for (i = 0; i < pluginCount; i++) {
        nsIDOMPlugin* plugin = nsnull;
        if (NS_SUCCEEDED(pluginArray->Item(i, &plugin)) &&
            plugin) {
          PRUint32 mimeTypeCount = 0;
          if (plugin->GetLength(&mimeTypeCount) == NS_OK)
            mMimeTypeCount += mimeTypeCount;
          NS_RELEASE(plugin);
        }
      }
      // now we know how many there are, start gathering them.
      mMimeTypeArray = new nsIDOMMimeType*[mMimeTypeCount];
      if (mMimeTypeArray == nsnull)
        return NS_ERROR_OUT_OF_MEMORY;
      PRUint32 mimeTypeIndex = 0;
      PRUint32 k;
      for (k = 0; k < pluginCount; k++) {
        nsIDOMPlugin* plugin = nsnull;
        if (pluginArray->Item(k, &plugin) == NS_OK) {
          PRUint32 mimeTypeCount = 0;
          if (plugin->GetLength(&mimeTypeCount) == NS_OK) {
            for (PRUint32 j = 0; j < mimeTypeCount; j++)
              plugin->Item(j, &mMimeTypeArray[mimeTypeIndex++]);
          }
          NS_RELEASE(plugin);
        }
      }
    }
    NS_RELEASE(pluginArray);
  }
  return rv;
}

Here is the caller graph for this function:

nsIDOMMimeType nsIDOMMimeTypeArray::item ( in unsigned long  index) [inherited]

Definition at line 89 of file nsMimeTypeArray.cpp.

{
  if (mMimeTypeArray == nsnull) {
    nsresult rv = GetMimeTypes();
    if (rv != NS_OK)
      return rv;
  }
  if (aIndex < mMimeTypeCount) {
    *aReturn = mMimeTypeArray[aIndex];
    NS_IF_ADDREF(*aReturn);
    return NS_OK;
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

nsIDOMMimeType nsIDOMMimeTypeArray::namedItem ( in DOMString  name) [inherited]
NS_IMETHODIMP nsMimeTypeArray::NamedItem ( const nsAString &  aName,
nsIDOMMimeType **  aReturn 
)

Definition at line 105 of file nsMimeTypeArray.cpp.

{
  NS_ENSURE_ARG_POINTER(aReturn);
  *aReturn = nsnull;

  if (mMimeTypeArray == nsnull) {
    nsresult rv = GetMimeTypes();
    if (rv != NS_OK)
      return rv;
  }

  nsAutoString type;

  for (PRUint32 i = 0; i < mMimeTypeCount; i++) {
    nsIDOMMimeType *mtype = mMimeTypeArray[i];

    mtype->GetType(type);

    if (type.Equals(aName)) {
      *aReturn = mtype;

      NS_ADDREF(*aReturn);

      return NS_OK;
    }
  }

  // Now let's check with the MIME service.
  nsCOMPtr<nsIMIMEService> mimeSrv = do_GetService("@mozilla.org/mime;1");
  if (mimeSrv) {
    nsCOMPtr<nsIMIMEInfo> mimeInfo;
    mimeSrv->GetFromTypeAndExtension(NS_ConvertUCS2toUTF8(aName), EmptyCString(),
                                     getter_AddRefs(mimeInfo));
    if (mimeInfo) {
      // Now we check whether we can really claim to support this type
      nsMIMEInfoHandleAction action = nsIMIMEInfo::saveToDisk;
      mimeInfo->GetPreferredAction(&action);
      if (action != nsIMIMEInfo::handleInternally) {
        PRBool hasHelper = PR_FALSE;
        mimeInfo->GetHasDefaultHandler(&hasHelper);
        if (!hasHelper) {
          nsCOMPtr<nsIFile> helper;
          mimeInfo->GetPreferredApplicationHandler(getter_AddRefs(helper));
          if (!helper) {
            // mime info from the OS may not have a PreferredApplicationHandler
            // so just check for an empty default description
            nsAutoString defaultDescription;
            mimeInfo->GetDefaultDescription(defaultDescription);
            if (defaultDescription.IsEmpty()) {
              // no support; just leave
              return NS_OK;
            }
          }
        }
      }

      // If we got here, we support this type!  Say so.
      nsCOMPtr<nsIDOMMimeType> helper = new nsHelperMimeType(aName);
      if (!helper) {
        return NS_ERROR_OUT_OF_MEMORY;
      }
      nsCOMPtr<nsIDOMMimeType> entry = new nsMimeType(nsnull, helper);
      if (!entry) {
        return NS_ERROR_OUT_OF_MEMORY;
      }

      entry.swap(*aReturn);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 190 of file nsMimeTypeArray.cpp.

{
  Clear();
  return GetMimeTypes();
}

Here is the call graph for this function:


Member Data Documentation

readonly attribute unsigned long nsIDOMMimeTypeArray::length [inherited]

Definition at line 45 of file nsIDOMMimeTypeArray.idl.

Definition at line 68 of file nsMimeTypeArray.h.

Definition at line 67 of file nsMimeTypeArray.h.

Definition at line 66 of file nsMimeTypeArray.h.


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