Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
imgLoader.cpp File Reference
#include "imgLoader.h"
#include "nsCOMPtr.h"
#include "nsNetUtil.h"
#include "nsIHttpChannel.h"
#include "nsICachingChannel.h"
#include "nsIProxyObjectManager.h"
#include "nsIServiceManager.h"
#include "nsXPIDLString.h"
#include "nsCRT.h"
#include "netCore.h"
#include "imgCache.h"
#include "imgRequest.h"
#include "imgRequestProxy.h"
#include "ImageErrors.h"
#include "ImageLogging.h"
#include "nsIComponentRegistrar.h"
#include "nsIHttpChannelInternal.h"
#include "nsIRequest.h"
#include "nsIStreamConverterService.h"

Go to the source code of this file.

Defines

#define LOAD_FLAGS_CACHE_MASK
#define LOAD_FLAGS_VALIDATE_MASK

Functions

static PRBool RevalidateEntry (nsICacheEntryDescriptor *aEntry, nsLoadFlags aFlags, PRBool aHasExpired)
static nsresult NewImageChannel (nsIChannel **aResult, nsIURI *aURI, nsIURI *aInitialDocumentURI, nsIURI *aReferringURI, nsILoadGroup *aLoadGroup, nsLoadFlags aLoadFlags)
static NS_METHOD dispose_of_data (nsIInputStream *in, void *closure, const char *fromRawSegment, PRUint32 toOffset, PRUint32 count, PRUint32 *writeCount)
 nsIStreamListener methods

Define Documentation

Value:

Definition at line 123 of file imgLoader.cpp.


Function Documentation

static NS_METHOD dispose_of_data ( nsIInputStream in,
void closure,
const char *  fromRawSegment,
PRUint32  toOffset,
PRUint32  count,
PRUint32 writeCount 
) [static]

nsIStreamListener methods

Definition at line 1020 of file imgLoader.cpp.

{
  *writeCount = count;
  return NS_OK;
}
static nsresult NewImageChannel ( nsIChannel **  aResult,
nsIURI aURI,
nsIURI aInitialDocumentURI,
nsIURI aReferringURI,
nsILoadGroup aLoadGroup,
nsLoadFlags  aLoadFlags 
) [static]

Definition at line 174 of file imgLoader.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIChannel> newChannel;
  nsCOMPtr<nsIHttpChannel> newHttpChannel;
 
  nsCOMPtr<nsIInterfaceRequestor> callbacks;

  if (aLoadGroup) {
    // Get the notification callbacks from the load group for the new channel.
    //
    // XXX: This is not exactly correct, because the network request could be
    //      referenced by multiple windows...  However, the new channel needs
    //      something.  So, using the 'first' notification callbacks is better
    //      than nothing...
    //
    aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
  }

  // Pass in a NULL loadgroup because this is the underlying network request.
  // This request may be referenced by several proxy image requests (psossibly
  // in different documents).
  // If all of the proxy requests are canceled then this request should be
  // canceled too.
  //
  rv = NS_NewChannel(aResult,
                     aURI,        // URI 
                     nsnull,      // Cached IOService
                     nsnull,      // LoadGroup
                     callbacks,   // Notification Callbacks
                     aLoadFlags);
  if (NS_FAILED(rv))
    return rv;

  // Initialize HTTP-specific attributes
  newHttpChannel = do_QueryInterface(*aResult);
  if (newHttpChannel) {
    newHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
                                     NS_LITERAL_CSTRING("image/png,*/*;q=0.5"),
                                     PR_FALSE);

    nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal = do_QueryInterface(newHttpChannel);
    NS_ENSURE_TRUE(httpChannelInternal, NS_ERROR_UNEXPECTED);
    httpChannelInternal->SetDocumentURI(aInitialDocumentURI);
    newHttpChannel->SetReferrer(aReferringURI);
  }

  // Image channels are loaded by default with reduced priority.
  nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(*aResult);
  if (p) {
    PRUint32 priority = nsISupportsPriority::PRIORITY_LOW;

    if (aLoadFlags & nsIRequest::LOAD_BACKGROUND)
      ++priority; // further reduce priority for background loads

    p->AdjustPriority(priority);
  }

  return NS_OK;
}

Here is the call graph for this function:

static PRBool RevalidateEntry ( nsICacheEntryDescriptor aEntry,
nsLoadFlags  aFlags,
PRBool  aHasExpired 
) [static]

Definition at line 128 of file imgLoader.cpp.

{
  PRBool bValidateEntry = PR_FALSE;

  NS_ASSERTION(!(aFlags & nsIRequest::LOAD_BYPASS_CACHE),
               "MUST not revalidate when BYPASS_CACHE is specified.");

  if (aFlags & nsIRequest::VALIDATE_ALWAYS) {
    bValidateEntry = PR_TRUE;
  }
  //
  // The cache entry has expired...  Determine whether the stale cache
  // entry can be used without validation...
  //
  else if (aHasExpired) {
    //
    // VALIDATE_NEVER and VALIDATE_ONCE_PER_SESSION allow stale cache
    // entries to be used unless they have been explicitly marked to
    // indicate that revalidation is necessary.
    //
    if (aFlags & (nsIRequest::VALIDATE_NEVER | 
                  nsIRequest::VALIDATE_ONCE_PER_SESSION)) 
    {
      nsXPIDLCString value;

      aEntry->GetMetaDataElement("MustValidateIfExpired",
                                 getter_Copies(value));
      if (PL_strcmp(value, "true")) {
        bValidateEntry = PR_TRUE;
      }
    }
    //
    // LOAD_FROM_CACHE allows a stale cache entry to be used... Otherwise,
    // the entry must be revalidated.
    //
    else if (!(aFlags & nsIRequest::LOAD_FROM_CACHE)) {
      bValidateEntry = PR_TRUE;
    }
  }

  return bValidateEntry;
}

Here is the call graph for this function: