Back to index

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

#include <nsURIChecker.h>

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

List of all members.

Public Member Functions

 nsURIChecker ()
virtual ~nsURIChecker ()
void init (in nsIURI aURI)
 Initializes the URI checker.
void asyncCheck (in nsIRequestObserver aObserver, in nsISupports aContext)
 Begin asynchronous checking URI for validity.
boolean isPending ()
 Indicates whether the request is pending.
void cancel (in nsresult aStatus)
 Cancels the current request.
void suspend ()
 Suspends the current request.
void resume ()
 Resumes the current request.
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.
void onChannelRedirect (in nsIChannel oldChannel, in nsIChannel newChannel, in unsigned long flags)
 Called when a redirect occurs.
void getInterface (in nsIIDRef uuid,[iid_is(uuid), retval] out nsQIResult result)
 Retrieves the specified interface pointer.

Public Attributes

readonly attribute nsIChannel baseChannel
 Returns the base channel that will be used to verify the URI.
readonly attribute AUTF8String name
 The name of the request.
readonly attribute nsresult status
 The error status associated with the request.
attribute nsILoadGroup loadGroup
 The load group of this request.
attribute nsLoadFlags loadFlags
 The load flags of this request.
const unsigned long LOAD_NORMAL = 0
 No special load flags:
const unsigned long LOAD_BACKGROUND = 1 << 0
 Don't deliver status notifications to the nsIProgressEventSink, or keep this load from completing the nsILoadGroup it may belong to.
const unsigned long INHIBIT_CACHING = 1 << 7
 This flag prevents caching of any kind.
const unsigned long INHIBIT_PERSISTENT_CACHING = 1 << 8
 This flag prevents caching on disk (or other persistent media), which may be needed to preserve privacy.
const unsigned long LOAD_BYPASS_CACHE = 1 << 9
 Force an end-to-end download of content data from the origin server.
const unsigned long LOAD_FROM_CACHE = 1 << 10
 Load from the cache, bypassing protocol specific validation logic.
const unsigned long VALIDATE_ALWAYS = 1 << 11
 The following flags control the frequency of cached content validation when neither LOAD_BYPASS_CACHE or LOAD_FROM_CACHE are set.
const unsigned long VALIDATE_NEVER = 1 << 12
const unsigned long VALIDATE_ONCE_PER_SESSION = 1 << 13
const unsigned long REDIRECT_TEMPORARY = 1 << 0
 This is a temporary redirect.
const unsigned long REDIRECT_PERMANENT = 1 << 1
 This is a permanent redirect.
const unsigned long REDIRECT_INTERNAL = 1 << 2
 This is an internal redirect, i.e.

Protected Member Functions

void SetStatusAndCallBack (nsresult aStatus)
nsresult CheckStatus ()

Protected Attributes

nsCOMPtr< nsIChannelmChannel
nsCOMPtr< nsIRequestObservermObserver
nsCOMPtr< nsISupports > mObserverContext
nsresult mStatus
PRPackedBool mIsPending
PRPackedBool mAllowHead

Detailed Description

Definition at line 53 of file nsURIChecker.h.


Constructor & Destructor Documentation

virtual nsURIChecker::~nsURIChecker ( ) [inline, virtual]

Definition at line 60 of file nsURIChecker.h.

{}

Member Function Documentation

void nsIURIChecker::asyncCheck ( in nsIRequestObserver  aObserver,
in nsISupports  aContext 
) [inherited]

Begin asynchronous checking URI for validity.

Notification will be asynchronous through the nsIRequestObserver callback interface. When OnStartRequest is fired, the baseChannel attribute will have been updated to reflect the final channel used (corresponding to any redirects that may have been followed).

Our interpretations of the nsIRequestObserver status codes: NS_BINDING_SUCCEEDED: link is valid NS_BINDING_FAILED: link is invalid (gave an error) NS_BINDING_ABORTED: timed out, or cancelled

Parameters:
aObserverThe object to notify when the link is verified. We will call aObserver.OnStartRequest followed immediately by aObserver.OnStopRequest. It is recommended that the caller use OnStopRequest to act on the link's status. The underlying request will not be cancelled until after OnStopRequest has been called.
aContextA closure that will be passed back to the nsIRequestObserver methods.
void nsIRequest::cancel ( in nsresult  aStatus) [inherited]

Cancels the current request.

This will close any open input or output streams and terminate any async requests. Users should normally pass NS_BINDING_ABORTED, although other errors may also be passed. The error passed in will become the value of the status attribute.

Parameters:
aStatusthe reason for canceling this request.

NOTE: most nsIRequest implementations expect aStatus to be a failure code; however, some implementations may allow aStatus to be a success code such as NS_OK. In general, aStatus should be a failure code.

Definition at line 92 of file nsURIChecker.cpp.

{
    NS_ASSERTION(mChannel, "no channel");

    nsresult status;
    nsresult rv = mChannel->GetStatus(&status);
    // DNS errors and other obvious problems will return failure status
    if (NS_FAILED(rv) || NS_FAILED(status))
        return NS_BINDING_FAILED;

    // If status is zero, it might still be an error if it's http:
    // http has data even when there's an error like a 404.
    nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mChannel);
    if (!httpChannel)
        return NS_BINDING_SUCCEEDED;

    PRUint32 responseStatus;
    rv = httpChannel->GetResponseStatus(&responseStatus);
    if (NS_FAILED(rv))
        return NS_BINDING_FAILED;

    // If it's between 200-299, it's valid:
    if (responseStatus / 100 == 2)
        return NS_BINDING_SUCCEEDED;

    // If we got a 404 (not found), we need some extra checking:
    // toplevel urls from Netscape Enterprise Server 3.6, like the old AOL-
    // hosted http://www.mozilla.org, generate a 404 and will have to be
    // retried without the head.
    if (responseStatus == 404) {
        if (mAllowHead && ServerIsNES3x(httpChannel)) {
            mAllowHead = PR_FALSE;

            // save the current value of mChannel in case we can't issue
            // the new request for some reason.
            nsCOMPtr<nsIChannel> lastChannel = mChannel;

            nsCOMPtr<nsIURI> uri;
            PRUint32 loadFlags;

            rv  = lastChannel->GetOriginalURI(getter_AddRefs(uri));
            rv |= lastChannel->GetLoadFlags(&loadFlags);

            // XXX we are carrying over the load flags, but what about other
            // parameters that may have been set on lastChannel??

            if (NS_SUCCEEDED(rv)) {
                rv = Init(uri);
                if (NS_SUCCEEDED(rv)) {
                    rv = mChannel->SetLoadFlags(loadFlags);
                    if (NS_SUCCEEDED(rv)) {
                        rv = AsyncCheck(mObserver, mObserverContext);
                        // if we succeeded in loading the new channel, then we
                        // want to return without notifying our observer.
                        if (NS_SUCCEEDED(rv))
                            return NS_BASE_STREAM_WOULD_BLOCK;
                    }
                }
            }
            // it is important to update this so our observer will be able
            // to access our baseChannel attribute if they want.
            mChannel = lastChannel;
        }
    }

    // If we get here, assume the resource does not exist.
    return NS_BINDING_FAILED;
}

Here is the call graph for this function:

void nsIInterfaceRequestor::getInterface ( in nsIIDRef  uuid,
[iid_is(uuid), retval] out nsQIResult  result 
) [inherited]

Retrieves the specified interface pointer.

Parameters:
uuidThe IID of the interface being requested.
result[out] The interface pointer to be filled in if the interface is accessible.
Returns:
NS_OK - interface was successfully returned. NS_NOINTERFACE - interface not accessible. NS_ERROR* - method failure.
void nsIURIChecker::init ( in nsIURI  aURI) [inherited]

Initializes the URI checker.

After this method is called, it is valid to further configure the URI checker by calling its nsIRequest methods. This method creates the channel that will be used to verify the URI. In the case of the HTTP protocol, only a HEAD request will be issued.

Parameters:
aURIThe URI to be checked.
boolean nsIRequest::isPending ( ) [inherited]

Indicates whether the request is pending.

nsIRequest::isPending is true when there is an outstanding asynchronous event that will make the request no longer be pending. Requests do not necessarily start out pending; in some cases, requests have to be explicitly initiated (e.g. nsIChannel implementations are only pending once asyncOpen returns successfully).

Requests can become pending multiple times during their lifetime.

Returns:
TRUE if the request has yet to reach completion.
FALSE if the request has reached completion (e.g., after OnStopRequest has fired).
Note:
Suspended requests are still considered pending.
void nsIChannelEventSink::onChannelRedirect ( in nsIChannel  oldChannel,
in nsIChannel  newChannel,
in unsigned long  flags 
) [inherited]

Called when a redirect occurs.

This may happen due to an HTTP 3xx status code.

Parameters:
oldChannelThe channel that's being redirected.
newChannelThe new channel. This channel is not opened yet.
flagsFlags indicating the type of redirect. A bitmask consisting of flags from above. One of REDIRECT_TEMPORARY and REDIRECT_PERMANENT will always be set.
Exceptions:
<any>Throwing an exception will cancel the load. No network request for the new channel will be made.
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 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 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:

void nsIRequest::resume ( ) [inherited]

Resumes the current request.

This may have the effect of re-opening any underlying transport and will resume the delivery of data to any open streams.

Definition at line 78 of file nsURIChecker.cpp.

{
    mStatus = aStatus;
    mIsPending = PR_FALSE;

    if (mObserver) {
        mObserver->OnStartRequest(this, mObserverContext);
        mObserver->OnStopRequest(this, mObserverContext, mStatus);
        mObserver = nsnull;
        mObserverContext = nsnull;
    }
}
void nsIRequest::suspend ( ) [inherited]

Suspends the current request.

This may have the effect of closing any underlying transport (in order to free up resources), although any open streams remain logically opened and will continue delivering data when the transport is resumed.

NOTE: some implementations are unable to immediately suspend, and may continue to deliver events already posted to an event queue. In general, callers should be capable of handling events even after suspending a request.


Member Data Documentation

Returns the base channel that will be used to verify the URI.

Definition at line 71 of file nsIURIChecker.idl.

const unsigned long nsIRequest::INHIBIT_CACHING = 1 << 7 [inherited]

This flag prevents caching of any kind.

It does not, however, prevent cached content from being used to satisfy this request.

Definition at line 153 of file nsIRequest.idl.

const unsigned long nsIRequest::INHIBIT_PERSISTENT_CACHING = 1 << 8 [inherited]

This flag prevents caching on disk (or other persistent media), which may be needed to preserve privacy.

For HTTPS, this flag is set auto- matically.

Definition at line 160 of file nsIRequest.idl.

const unsigned long nsIRequest::LOAD_BACKGROUND = 1 << 0 [inherited]

Don't deliver status notifications to the nsIProgressEventSink, or keep this load from completing the nsILoadGroup it may belong to.

Definition at line 143 of file nsIRequest.idl.

const unsigned long nsIRequest::LOAD_BYPASS_CACHE = 1 << 9 [inherited]

Force an end-to-end download of content data from the origin server.

This flag is used for a shift-reload.

Definition at line 172 of file nsIRequest.idl.

const unsigned long nsIRequest::LOAD_FROM_CACHE = 1 << 10 [inherited]

Load from the cache, bypassing protocol specific validation logic.

This flag is used when browsing via history. It is not recommended for normal browsing as it may likely violate reasonable assumptions made by the server and confuse users.

Definition at line 180 of file nsIRequest.idl.

const unsigned long nsIRequest::LOAD_NORMAL = 0 [inherited]

No special load flags:

Definition at line 137 of file nsIRequest.idl.

The load flags of this request.

Bits 0-15 are reserved.

When added to a load group, this request's load flags are merged with the load flags of the load group.

Definition at line 128 of file nsIRequest.idl.

The load group of this request.

While pending, the request is a member of the load group. It is the responsibility of the request to implement this policy.

Definition at line 120 of file nsIRequest.idl.

Definition at line 76 of file nsURIChecker.h.

Definition at line 71 of file nsURIChecker.h.

Definition at line 75 of file nsURIChecker.h.

Definition at line 72 of file nsURIChecker.h.

nsCOMPtr<nsISupports> nsURIChecker::mObserverContext [protected]

Definition at line 73 of file nsURIChecker.h.

Definition at line 74 of file nsURIChecker.h.

readonly attribute AUTF8String nsIRequest::name [inherited]

The name of the request.

Often this is the URI of the request.

Definition at line 55 of file nsIRequest.idl.

const unsigned long nsIChannelEventSink::REDIRECT_INTERNAL = 1 << 2 [inherited]

This is an internal redirect, i.e.

it was not initiated by the remote server, but is specific to the channel implementation.

The new URI may be identical to the old one.

Definition at line 81 of file nsIChannelEventSink.idl.

const unsigned long nsIChannelEventSink::REDIRECT_PERMANENT = 1 << 1 [inherited]

This is a permanent redirect.

New requests for this resource should use the URI of the new channel (This might be an HTTP 301 reponse). If this flag is not set, this is a temporary redirect.

The new URI may be identical to the old one.

Definition at line 73 of file nsIChannelEventSink.idl.

const unsigned long nsIChannelEventSink::REDIRECT_TEMPORARY = 1 << 0 [inherited]

This is a temporary redirect.

New requests for this resource should continue to use the URI of the old channel.

The new URI may be identical to the old one.

Definition at line 64 of file nsIChannelEventSink.idl.

readonly attribute nsresult nsIRequest::status [inherited]

The error status associated with the request.

Definition at line 77 of file nsIRequest.idl.

const unsigned long nsIRequest::VALIDATE_ALWAYS = 1 << 11 [inherited]

The following flags control the frequency of cached content validation when neither LOAD_BYPASS_CACHE or LOAD_FROM_CACHE are set.

By default, cached content is automatically validated if necessary before reuse.

VALIDATE_ALWAYS forces validation of any cached content independent of its expiration time.

VALIDATE_NEVER disables validation of expired content.

VALIDATE_ONCE_PER_SESSION disables validation of expired content, provided it has already been validated (at least once) since the start of this session.

NOTE TO IMPLEMENTORS: These flags are intended for normal browsing, and they should therefore not apply to content that must be validated before each use. Consider, for example, a HTTP response with a "Cache-control: no-cache" header. According to RFC2616, this response must be validated before it can be taken from a cache. Breaking this requirement could result in incorrect and potentially undesirable side-effects.

Definition at line 204 of file nsIRequest.idl.

const unsigned long nsIRequest::VALIDATE_NEVER = 1 << 12 [inherited]

Definition at line 205 of file nsIRequest.idl.

const unsigned long nsIRequest::VALIDATE_ONCE_PER_SESSION = 1 << 13 [inherited]

Definition at line 206 of file nsIRequest.idl.


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