Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends
imgRequest Class Reference

#include <imgRequest.h>

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

List of all members.

Public Member Functions

 imgRequest ()
virtual ~imgRequest ()
NS_DECL_ISUPPORTS nsresult Init (nsIChannel *aChannel, nsICacheEntryDescriptor *aCacheEntry, void *aCacheId, void *aLoadId)
nsresult AddProxy (imgRequestProxy *proxy, PRBool aNotify)
nsresult RemoveProxy (imgRequestProxy *proxy, nsresult aStatus, PRBool aNotify)
nsresult NotifyProxyListener (imgRequestProxy *proxy)
void SniffMimeType (const char *buf, PRUint32 len)
PRBool IsReusable (void *aCacheId)
void onStartDecode (in imgIRequest aRequest)
 called as soon as the image begins getting decoded
void onStartContainer (in imgIRequest aRequest, in imgIContainer aContainer)
 called once the image has been inited and therefore has a width and height
void onStartFrame (in imgIRequest aRequest, in gfxIImageFrame aFrame)
 called when each frame is created
void onDataAvailable (in imgIRequest aRequest, in gfxIImageFrame aFrame,[const ] in nsIntRect aRect)
 called when some part of the frame has new data in it
void onStopFrame (in imgIRequest aRequest, in gfxIImageFrame aFrame)
 called when a frame is finished decoding
void onStopContainer (in imgIRequest aRequest, in imgIContainer aContainer)
 probably not needed.
void onStopDecode (in imgIRequest aRequest, in nsresult status, in wstring statusArg)
 called when the decoder is dying off
void frameChanged (in imgIContainer aContainer, in gfxIImageFrame aFrame, in nsIntRect aDirtyRect)
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.

Public Attributes

attribute imgIContainer image
 the image container...
readonly attribute PRBool isMultiPartChannel

Private Member Functions

void SetLoadId (void *aLoadId)
PRUint32 GetImageStatus () const
nsresult GetResultFromImageStatus (PRUint32 aStatus) const
void Cancel (nsresult aStatus)
nsresult GetURI (nsIURI **aURI)
void RemoveFromCache ()
const char * GetMimeType () const
nsIPropertiesProperties ()
PRBool HaveProxyWithObserver (imgRequestProxy *aProxyToIgnore) const
PRInt32 Priority () const
void AdjustPriority (imgRequestProxy *aProxy, PRInt32 aDelta)

Private Attributes

nsCOMPtr< nsIChannelmChannel
nsCOMPtr< nsIURImURI
nsCOMPtr< imgIContainermImage
nsCOMPtr< imgIDecodermDecoder
nsCOMPtr< nsIPropertiesmProperties
nsVoidArray mObservers
PRPackedBool mLoading
PRPackedBool mProcessing
PRPackedBool mHadLastPart
PRUint32 mImageStatus
PRUint32 mState
nsCString mContentType
nsCOMPtr< nsICacheEntryDescriptormCacheEntry
voidmCacheId
voidmLoadId
PRTime mLoadTime
imgCacheValidatormValidator
PRBool mIsMultiPartChannel

Friends

class imgRequestProxy
class imgLoader
class imgCacheValidator
class imgCache

Detailed Description

Definition at line 73 of file imgRequest.h.


Constructor & Destructor Documentation

imgRequest::~imgRequest ( ) [virtual]

Definition at line 89 of file imgRequest.cpp.

{
  /* destructor code */
}

Member Function Documentation

Definition at line 126 of file imgRequest.cpp.

{
  LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequest::AddProxy", "proxy", proxy);

  mObservers.AppendElement(NS_STATIC_CAST(void*, proxy));

  if (aNotify)
    NotifyProxyListener(proxy);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void imgRequest::AdjustPriority ( imgRequestProxy aProxy,
PRInt32  aDelta 
) [private]

Definition at line 349 of file imgRequest.cpp.

{
  // only the first proxy is allowed to modify the priority of this image load.
  //
  // XXX(darin): this is probably not the most optimal algorithm as we may want
  // to increase the priority of requests that have a lot of proxies.  the key
  // concern though is that image loads remain lower priority than other pieces
  // of content such as link clicks, CSS, and JS.
  //
  if (mObservers[0] != proxy)
    return;

  nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mChannel);
  if (p)
    p->AdjustPriority(delta);
}

Here is the call graph for this function:

void imgRequest::Cancel ( nsresult  aStatus) [private]

Definition at line 277 of file imgRequest.cpp.

{
  /* The Cancel() method here should only be called by this class. */

  LOG_SCOPE(gImgLog, "imgRequest::Cancel");

  if (mImage) {
    LOG_MSG(gImgLog, "imgRequest::Cancel", "stopping animation");

    mImage->StopAnimation();
  }

  if (!(mImageStatus & imgIRequest::STATUS_LOAD_PARTIAL))
    mImageStatus |= imgIRequest::STATUS_ERROR;

  RemoveFromCache();

  if (mChannel && mLoading)
    mChannel->Cancel(aStatus);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void imgIContainerObserver::frameChanged ( in imgIContainer  aContainer,
in gfxIImageFrame  aFrame,
in nsIntRect  aDirtyRect 
) [inherited]
PRUint32 imgRequest::GetImageStatus ( ) const [inline, private]

Definition at line 114 of file imgRequest.h.

{ return mImageStatus; }
const char* imgRequest::GetMimeType ( void  ) const [inline, private]

Definition at line 119 of file imgRequest.h.

                                         {
    return mContentType.get();
  }

Here is the call graph for this function:

nsresult imgRequest::GetResultFromImageStatus ( PRUint32  aStatus) const [inline, private]

Definition at line 265 of file imgRequest.cpp.

Here is the caller graph for this function:

nsresult imgRequest::GetURI ( nsIURI **  aURI) [private]

Definition at line 298 of file imgRequest.cpp.

{
  LOG_FUNC(gImgLog, "imgRequest::GetURI");

  if (mChannel)
    return mChannel->GetOriginalURI(aURI);

  if (mURI) {
    *aURI = mURI;
    NS_ADDREF(*aURI);
    return NS_OK;
  }

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

PRBool imgRequest::HaveProxyWithObserver ( imgRequestProxy aProxyToIgnore) const [private]

Definition at line 324 of file imgRequest.cpp.

{
  for (PRInt32 i = 0; i < mObservers.Count(); ++i) {
    imgRequestProxy *proxy = NS_STATIC_CAST(imgRequestProxy*, mObservers[i]);
    if (proxy == aProxyToIgnore) {
      continue;
    }
    
    if (proxy->HasObserver()) {
      return PR_TRUE;
    }
  }
  
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult imgRequest::Init ( nsIChannel aChannel,
nsICacheEntryDescriptor aCacheEntry,
void aCacheId,
void aLoadId 
)

Definition at line 94 of file imgRequest.cpp.

{
  LOG_FUNC(gImgLog, "imgRequest::Init");

  NS_ASSERTION(!mImage, "imgRequest::Init -- Multiple calls to init");
  NS_ASSERTION(aChannel, "imgRequest::Init -- No channel");

  mProperties = do_CreateInstance("@mozilla.org/properties;1");
  if (!mProperties)
    return NS_ERROR_OUT_OF_MEMORY;

  mChannel = aChannel;

  /* set our loading flag to true here.
     Setting it here lets checks to see if the load is in progress
     before OnStartRequest gets called, letting 'this' properly get removed
     from the cache in certain cases.
  */
  mLoading = PR_TRUE;

  mCacheEntry = aCacheEntry;

  mCacheId = aCacheId;

  SetLoadId(aLoadId);

  return NS_OK;
}

Here is the call graph for this function:

PRBool imgRequest::IsReusable ( void aCacheId) [inline]

Definition at line 102 of file imgRequest.h.

{ return !mLoading || (aCacheId == mCacheId); }

Definition at line 195 of file imgRequest.cpp.

{
  nsCOMPtr<imgIRequest> kungFuDeathGrip(proxy);

  // OnStartRequest
  if (mState & onStartRequest)
    proxy->OnStartRequest(nsnull, nsnull);

  // OnStartDecode
  if (mState & onStartDecode)
    proxy->OnStartDecode();

  // OnStartContainer
  if (mState & onStartContainer)
    proxy->OnStartContainer(mImage);

  // Send frame messages (OnStartFrame, OnDataAvailable, OnStopFrame)
  PRUint32 nframes = 0;
  if (mImage)
    mImage->GetNumFrames(&nframes);

  if (nframes > 0) {
    nsCOMPtr<gfxIImageFrame> frame;

    // get the current frame or only frame
    mImage->GetCurrentFrame(getter_AddRefs(frame));
    NS_ASSERTION(frame, "GetCurrentFrame gave back a null frame!");

    // OnStartFrame
    proxy->OnStartFrame(frame);

    if (!(mState & onStopContainer)) {
      // OnDataAvailable
      nsIntRect r;
      frame->GetRect(r);  // XXX we should only send the currently decoded rectangle here.
      proxy->OnDataAvailable(frame, &r);
    } else {
      // OnDataAvailable
      nsIntRect r;
      frame->GetRect(r);  // We're done loading this image, send the the whole rect
      proxy->OnDataAvailable(frame, &r);

      // OnStopFrame
      proxy->OnStopFrame(frame);
    }
  }

  // OnStopContainer
  if (mState & onStopContainer)
    proxy->OnStopContainer(mImage);

  // OnStopDecode
  if (mState & onStopDecode)
    proxy->OnStopDecode(GetResultFromImageStatus(mImageStatus), nsnull);

  if (mImage && !HaveProxyWithObserver(proxy) && proxy->HasObserver()) {
    LOG_MSG(gImgLog, "imgRequest::AddProxy", "resetting animation");

    mImage->ResetAnimation();
  }

  if (mState & onStopRequest) {
    proxy->OnStopRequest(nsnull, nsnull,
                         GetResultFromImageStatus(mImageStatus),
                         mHadLastPart);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void imgIDecoderObserver::onDataAvailable ( in imgIRequest  aRequest,
in gfxIImageFrame  aFrame,
[const ] in nsIntRect  aRect 
) [inherited]

called when some part of the frame has new data in it

void imgIDecoderObserver::onStartContainer ( in imgIRequest  aRequest,
in imgIContainer  aContainer 
) [inherited]

called once the image has been inited and therefore has a width and height

Here is the caller graph for this function:

called as soon as the image begins getting decoded

Here is the caller graph for this function:

void imgIDecoderObserver::onStartFrame ( in imgIRequest  aRequest,
in gfxIImageFrame  aFrame 
) [inherited]

called when each frame is created

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void imgIDecoderObserver::onStopContainer ( in imgIRequest  aRequest,
in imgIContainer  aContainer 
) [inherited]

probably not needed.

called right before onStopDecode

Here is the caller graph for this function:

void imgIDecoderObserver::onStopDecode ( in imgIRequest  aRequest,
in nsresult  status,
in wstring  statusArg 
) [inherited]

called when the decoder is dying off

Here is the caller graph for this function:

void imgIDecoderObserver::onStopFrame ( in imgIRequest  aRequest,
in gfxIImageFrame  aFrame 
) [inherited]

called when a frame is finished decoding

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

PRInt32 imgRequest::Priority ( ) const [private]

Definition at line 340 of file imgRequest.cpp.

Here is the call graph for this function:

nsIProperties* imgRequest::Properties ( ) [inline, private]

Definition at line 122 of file imgRequest.h.

                                     {
    return mProperties;
  }

Definition at line 314 of file imgRequest.cpp.

{
  LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache");

  if (mCacheEntry) {
    mCacheEntry->Doom();
    mCacheEntry = nsnull;
  }
}

Here is the caller graph for this function:

nsresult imgRequest::RemoveProxy ( imgRequestProxy proxy,
nsresult  aStatus,
PRBool  aNotify 
)

Definition at line 138 of file imgRequest.cpp.

{
  LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequest::RemoveProxy", "proxy", proxy);

  mObservers.RemoveElement(NS_STATIC_CAST(void*, proxy));

  /* Check mState below before we potentially call Cancel() below. Since
     Cancel() may result in OnStopRequest being called back before Cancel()
     returns, leaving mState in a different state then the one it was in at
     this point.
   */

  if (aNotify) {
    // make sure that observer gets an OnStopDecode message sent to it
    if (!(mState & onStopDecode)) {
      proxy->OnStopDecode(aStatus, nsnull);
    }

  }

  // make sure that observer gets an OnStopRequest message sent to it
  if (!(mState & onStopRequest)) {
    proxy->OnStopRequest(nsnull, nsnull, NS_BINDING_ABORTED, PR_TRUE);
  }

  if (mImage && !HaveProxyWithObserver(nsnull)) {
    LOG_MSG(gImgLog, "imgRequest::RemoveProxy", "stopping animation");

    mImage->StopAnimation();
  }

  if (mObservers.Count() == 0) {
    /* If |aStatus| is a failure code, then cancel the load if it is still in progress.
       Otherwise, let the load continue, keeping 'this' in the cache with no observers.
       This way, if a proxy is destroyed without calling cancel on it, it won't leak
       and won't leave a bad pointer in mObservers.
     */
    if (mChannel && mLoading && NS_FAILED(aStatus)) {
      LOG_MSG(gImgLog, "imgRequest::RemoveProxy", "load in progress.  canceling");

      mImageStatus |= imgIRequest::STATUS_LOAD_PARTIAL;

      this->Cancel(NS_BINDING_ABORTED);
    }

    /* break the cycle from the cache entry. */
    mCacheEntry = nsnull;
  }

  // If a proxy is removed for a reason other than its owner being
  // changed, remove the proxy from the loadgroup.
  if (aStatus != NS_IMAGELIB_CHANGING_OWNER)
    proxy->RemoveFromLoadGroup(PR_TRUE);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void imgRequest::SetLoadId ( void aLoadId) [inline, private]

Definition at line 110 of file imgRequest.h.

                                       {
    mLoadId = aLoadId;
    mLoadTime = PR_Now();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void imgRequest::SniffMimeType ( const char *  buf,
PRUint32  len 
)

Definition at line 930 of file imgRequest.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class imgCache [friend]

Definition at line 108 of file imgRequest.h.

friend class imgCacheValidator [friend]

Definition at line 107 of file imgRequest.h.

friend class imgLoader [friend]

Definition at line 106 of file imgRequest.h.

friend class imgRequestProxy [friend]

Definition at line 105 of file imgRequest.h.


Member Data Documentation

the image container...

Returns:
the image object associated with the request.
Attention:
NEED DOCS

Definition at line 59 of file imgILoad.idl.

Definition at line 60 of file imgILoad.idl.

Definition at line 163 of file imgRequest.h.

Definition at line 165 of file imgRequest.h.

Definition at line 146 of file imgRequest.h.

Definition at line 161 of file imgRequest.h.

Definition at line 149 of file imgRequest.h.

Definition at line 156 of file imgRequest.h.

Definition at line 148 of file imgRequest.h.

Definition at line 158 of file imgRequest.h.

Definition at line 171 of file imgRequest.h.

Definition at line 167 of file imgRequest.h.

Definition at line 154 of file imgRequest.h.

Definition at line 168 of file imgRequest.h.

Definition at line 152 of file imgRequest.h.

Definition at line 155 of file imgRequest.h.

Definition at line 150 of file imgRequest.h.

Definition at line 159 of file imgRequest.h.

Definition at line 147 of file imgRequest.h.

Definition at line 170 of file imgRequest.h.


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