Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions
imgLoader Class Reference

#include <imgLoader.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_IMGILOADER
NS_DECL_NSICONTENTSNIFFER 
imgLoader ()
virtual ~imgLoader ()
imgIRequest loadImage (in nsIURI aURI, in nsIURI aInitialDocumentURL, in nsIURI aReferrerURI, in nsILoadGroup aLoadGroup, in imgIDecoderObserver aObserver, in nsISupports aCX, in nsLoadFlags aLoadFlags, in nsISupports cacheKey, in imgIRequest aRequest)
 Start the load and decode of an image.
imgIRequest loadImageWithChannel (in nsIChannel aChannel, in imgIDecoderObserver aObserver, in nsISupports cx, out nsIStreamListener aListener)
 Start the load and decode of an image.
boolean supportImageWithMimeType (in string mimeType)
 Checks if a decoder for the an image with the given mime type is available.
ACString getMIMETypeFromContent ([const, array, size_is(aLength)] in octet aData, in unsigned long aLength)
 Given a chunk of data, determines a MIME type.

Static Public Member Functions

static nsresult GetMimeTypeFromContent (const char *aContents, PRUint32 aLength, nsACString &aContentType)

Private Member Functions

nsresult CreateNewProxyForRequest (imgRequest *aRequest, nsILoadGroup *aLoadGroup, imgIDecoderObserver *aObserver, nsLoadFlags aLoadFlags, imgIRequest *aRequestProxy, imgIRequest **_retval)

Detailed Description

Definition at line 61 of file imgLoader.h.


Constructor & Destructor Documentation

Definition at line 107 of file imgLoader.cpp.

{
  /* member initializers and constructor code */
#ifdef DEBUG_pavlov
  PrintImageDecoders();
#endif
}
imgLoader::~imgLoader ( ) [virtual]

Definition at line 115 of file imgLoader.cpp.

{
  /* destructor code */
}

Member Function Documentation

nsresult imgLoader::CreateNewProxyForRequest ( imgRequest aRequest,
nsILoadGroup aLoadGroup,
imgIDecoderObserver aObserver,
nsLoadFlags  aLoadFlags,
imgIRequest aRequestProxy,
imgIRequest **  _retval 
) [private]

Definition at line 684 of file imgLoader.cpp.

{
  LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::CreateNewProxyForRequest", "imgRequest", aRequest);

  /* XXX If we move decoding onto separate threads, we should save off the
     calling thread here and pass it off to |proxyRequest| so that it call
     proxy calls to |aObserver|.
   */

  imgRequestProxy *proxyRequest;
  if (aProxyRequest) {
    proxyRequest = NS_STATIC_CAST(imgRequestProxy *, aProxyRequest);
  } else {
    NS_NEWXPCOM(proxyRequest, imgRequestProxy);
    if (!proxyRequest) return NS_ERROR_OUT_OF_MEMORY;
  }
  NS_ADDREF(proxyRequest);

  /* It is important to call |SetLoadFlags()| before calling |Init()| because
     |Init()| adds the request to the loadgroup.
   */
  proxyRequest->SetLoadFlags(aLoadFlags);

  // init adds itself to imgRequest's list of observers
  nsresult rv = proxyRequest->Init(aRequest, aLoadGroup, aObserver);
  if (NS_FAILED(rv)) {
    NS_RELEASE(proxyRequest);
    return rv;
  }

  if (*_retval) {
    (*_retval)->Cancel(NS_IMAGELIB_ERROR_LOAD_ABORTED);
    NS_RELEASE(*_retval);
  }
  // transfer reference to caller
  *_retval = NS_STATIC_CAST(imgIRequest*, proxyRequest);

  return NS_OK;
}

Here is the call graph for this function:

ACString nsIContentSniffer::getMIMETypeFromContent ( [const, array, size_is(aLength)] in octet  aData,
in unsigned long  aLength 
) [inherited]

Given a chunk of data, determines a MIME type.

Parameters:
aDataData to check
aLengthLength of the data
Exceptions:
NS_ERROR_NOT_AVAILABLEif no MIME type could be determined.
nsresult imgLoader::GetMimeTypeFromContent ( const char *  aContents,
PRUint32  aLength,
nsACString &  aContentType 
) [static]

Definition at line 746 of file imgLoader.cpp.

{
  /* Is it a GIF? */
  if (aLength >= 4 && !nsCRT::strncmp(aContents, "GIF8", 4))  {
    aContentType.AssignLiteral("image/gif");
  }

  /* or a PNG? */
  else if (aLength >= 4 && ((unsigned char)aContents[0]==0x89 &&
                   (unsigned char)aContents[1]==0x50 &&
                   (unsigned char)aContents[2]==0x4E &&
                   (unsigned char)aContents[3]==0x47))
  { 
    aContentType.AssignLiteral("image/png");
  }

  /* maybe a JPEG (JFIF)? */
  /* JFIF files start with SOI APP0 but older files can start with SOI DQT
   * so we test for SOI followed by any marker, i.e. FF D8 FF
   * this will also work for SPIFF JPEG files if they appear in the future.
   *
   * (JFIF is 0XFF 0XD8 0XFF 0XE0 <skip 2> 0X4A 0X46 0X49 0X46 0X00)
   */
  else if (aLength >= 3 &&
     ((unsigned char)aContents[0])==0xFF &&
     ((unsigned char)aContents[1])==0xD8 &&
     ((unsigned char)aContents[2])==0xFF)
  {
    aContentType.AssignLiteral("image/jpeg");
  }

  /* or how about ART? */
  /* ART begins with JG (4A 47). Major version offset 2.
   * Minor version offset 3. Offset 4 must be NULL.
   */
  else if (aLength >= 5 &&
   ((unsigned char) aContents[0])==0x4a &&
   ((unsigned char) aContents[1])==0x47 &&
   ((unsigned char) aContents[4])==0x00 )
  {
    aContentType.AssignLiteral("image/x-jg");
  }

  else if (aLength >= 2 && !nsCRT::strncmp(aContents, "BM", 2)) {
    aContentType.AssignLiteral("image/bmp");
  }

  // ICOs always begin with a 2-byte 0 followed by a 2-byte 1.
  // CURs begin with 2-byte 0 followed by 2-byte 2.
  else if (aLength >= 4 && (!memcmp(aContents, "\000\000\001\000", 4) ||
                            !memcmp(aContents, "\000\000\002\000", 4))) {
    aContentType.AssignLiteral("image/x-icon");
  }

  else if (aLength >= 8 && !nsCRT::strncmp(aContents, "#define ", 8)) {
    aContentType.AssignLiteral("image/x-xbitmap");
  }
  else {
    /* none of the above?  I give up */
    return NS_ERROR_NOT_AVAILABLE;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

imgIRequest imgILoader::loadImage ( in nsIURI  aURI,
in nsIURI  aInitialDocumentURL,
in nsIURI  aReferrerURI,
in nsILoadGroup  aLoadGroup,
in imgIDecoderObserver  aObserver,
in nsISupports  aCX,
in nsLoadFlags  aLoadFlags,
in nsISupports  cacheKey,
in imgIRequest  aRequest 
) [inherited]

Start the load and decode of an image.

Parameters:
aURIthe URI to load
aInitialDocumentURIthe URI that 'initiated' the load -- used for 3rd party cookie blocking
aReferrerURIthe 'referring' URI
aLoadGroupLoadgroup to put the image load into
aObserverthe observer
aCXsome random data
aLoadFlagsLoad flags for the request
aCacheKeycache key to use for a load if the original image came from a request that had post data
aRequestA newly created, unused imgIRequest object or NULL for one to be created for you.

libpr0n does NOT keep a strong ref to the observer; this prevents reference cycles. This means that callers of loadImage should make sure to Cancel() the resulting request before the observer goes away.

imgIRequest imgILoader::loadImageWithChannel ( in nsIChannel  aChannel,
in imgIDecoderObserver  aObserver,
in nsISupports  cx,
out nsIStreamListener  aListener 
) [inherited]

Start the load and decode of an image.

Parameters:
urithe URI to load
aObserverthe observer
cxsome random data

libpr0n does NOT keep a strong ref to the observer; this prevents reference cycles. This means that callers of loadImageWithChannel should make sure to Cancel() the resulting request before the observer goes away.

Checks if a decoder for the an image with the given mime type is available.

Parameters:
mimeTypeThe type to find a decoder for
Returns:
true if a decoder is available, false otherwise

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