bug #23055 (r=warren). Added LOAD_DOCUMENT_URI load attribute for the DocLoader to distinguish doc URIs

This commit is contained in:
rpotts%netscape.com 2000-01-15 06:12:54 +00:00
parent 75168769b3
commit be79b9fb76
15 changed files with 172 additions and 63 deletions

View File

@ -217,7 +217,7 @@ nsCachedChromeChannel::GetLoadAttributes(nsLoadFlags *aLoadAttributes)
NS_IMETHODIMP
nsCachedChromeChannel::SetLoadAttributes(nsLoadFlags aLoadAttributes)
{
NS_NOTREACHED("don't do that");
// XXX: NS_NOTREACHED("don't do that");
return NS_OK;
}
@ -439,6 +439,8 @@ nsChromeProtocolHandler::NewChannel(const char* aVerb, nsIURI* aURI,
// load the thing.
rv = nsCachedChromeChannel::Create(aURI, getter_AddRefs(result));
if (NS_FAILED(rv)) return rv;
result->SetLoadGroup(aLoadGroup);
}
else {
// Miss. Resolve the chrome URL using the registry and do a

View File

@ -1828,8 +1828,27 @@ nsresult nsWebShell::CreateViewer(nsIChannel* aChannel,
rv = aChannel->GetLoadGroup(getter_AddRefs(currentLoadGroup));
if (NS_SUCCEEDED(rv))
{
if (currentLoadGroup.get() != loadGroup.get())
if (currentLoadGroup.get() != loadGroup.get()) {
nsLoadFlags loadAttribs = 0;
//Cancel any URIs that are currently loading...
/// XXX: Need to do this eventually Stop();
//
// Retarget the document to this loadgroup...
//
if (currentLoadGroup) {
(void) currentLoadGroup->RemoveChannel(aChannel, nsnull, nsnull, nsnull);
}
aChannel->SetLoadGroup(loadGroup);
// Mark the channel as being a document URI...
aChannel->GetLoadAttributes(&loadAttribs);
loadAttribs |= nsIChannel::LOAD_DOCUMENT_URI;
aChannel->SetLoadAttributes(loadAttribs);
loadGroup->AddChannel(aChannel, nsnull);
}
}
/*

View File

@ -119,6 +119,7 @@ interface nsIChannel : nsIRequest
* nsIProgressEventSink, or keep this load from
* completing the nsILoadGroup it may belong to */
const unsigned long LOAD_DOCUMENT_URI = 1 << 1;
//
// The following flags control caching behavior. Not all protocols pay
// attention to all these flags, but they are applicable to more than one

View File

@ -418,6 +418,9 @@ nsLoadGroup::AddChannel(nsIChannel *channel, nsISupports* ctxt)
#endif /* PR_LOGGING */
nsLoadFlags flags;
MergeLoadAttributes(channel);
rv = channel->GetLoadAttributes(&flags);
if (NS_FAILED(rv)) return rv;
@ -613,3 +616,55 @@ nsLoadGroup::GetActiveCount(PRUint32* aResult)
}
////////////////////////////////////////////////////////////////////////////////
nsresult nsLoadGroup::MergeLoadAttributes(nsIChannel *aChannel)
{
nsresult rv;
nsLoadFlags flags, oldFlags;
rv = aChannel->GetLoadAttributes(&flags);
if (NS_FAILED(rv)) return rv;
oldFlags = flags;
//
// Inherit the group cache validation policy (bits 12-15)
//
if ( !((nsIChannel::VALIDATE_NEVER |
nsIChannel::VALIDATE_ALWAYS |
nsIChannel::VALIDATE_ONCE_PER_SESSION |
nsIChannel::VALIDATE_HEURISTICALLY) & flags)) {
flags |= (nsIChannel::VALIDATE_NEVER |
nsIChannel::VALIDATE_ALWAYS |
nsIChannel::VALIDATE_ONCE_PER_SESSION |
nsIChannel::VALIDATE_HEURISTICALLY) & mDefaultLoadAttributes;
}
//
// Inherit the group reload policy (bits 9-10)
//
if (!(nsIChannel::FORCE_VALIDATION & flags)) {
flags |= (nsIChannel::FORCE_VALIDATION & mDefaultLoadAttributes);
}
if (!(nsIChannel::FORCE_RELOAD & flags)) {
flags |= (nsIChannel::FORCE_RELOAD & mDefaultLoadAttributes);
}
//
// Inherit the group persistent cache policy (bit 8)
//
if (!(nsIChannel::INHIBIT_PERSISTENT_CACHING & flags)) {
flags |= (nsIChannel::INHIBIT_PERSISTENT_CACHING & mDefaultLoadAttributes);
}
//
// Inherit the group loading policy (bit 0)
//
if (!(nsIChannel::LOAD_BACKGROUND & flags)) {
flags |= (nsIChannel::LOAD_BACKGROUND & mDefaultLoadAttributes);
}
if (flags != oldFlags) {
rv = aChannel->SetLoadAttributes(flags);
}
return rv;
}

View File

@ -59,6 +59,7 @@ protected:
virtual ~nsLoadGroup();
nsresult Init();
nsresult MergeLoadAttributes(nsIChannel *aChannel);
protected:
PRUint32 mDefaultLoadAttributes;

View File

@ -436,22 +436,9 @@ nsFileChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
NS_IMETHODIMP
nsFileChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
{
nsresult rv = NS_OK;
nsCOMPtr<nsILoadGroup> oldLoadGroup = mLoadGroup;
mLoadGroup = aLoadGroup;
if (oldLoadGroup) {
// then remove ourselves from the group...and add ourselves to the new group...
(void)mLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull);
mLoadGroup->AddChannel(this, nsnull);
}
if (mLoadGroup) {
rv = mLoadGroup->GetDefaultLoadAttributes(&mLoadAttributes);
if (NS_FAILED(rv)) return rv;
}
return rv;
return NS_OK;
}
NS_IMETHODIMP

View File

@ -410,14 +410,7 @@ nsFTPChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
NS_IMETHODIMP
nsFTPChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
{
if (mLoadGroup) // if we already had a load group remove ourselves...
(void)mLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull);
mLoadGroup = aLoadGroup;
if (mLoadGroup) {
nsresult rv = mLoadGroup->AddChannel(this, nsnull);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}

View File

@ -370,39 +370,9 @@ nsHTTPChannel::GetLoadGroup(nsILoadGroup * *aLoadGroup)
NS_IMETHODIMP
nsHTTPChannel::SetLoadGroup(nsILoadGroup *aGroup)
{
//TODO think if we need to make a copy of the URL and keep it here
//since it might get deleted off the creators thread. And the
//stream listener could be elsewhere...
nsresult rv = NS_OK;
nsCOMPtr<nsILoadGroup> oldLoadGroup = mLoadGroup;
mLoadGroup = aGroup;
if (mLoadGroup) {
mLoadGroup->GetDefaultLoadAttributes(&mLoadAttributes);
}
// if we had an old group....
if (oldLoadGroup) {
// then remove ourselves from the group...and add ourselves to the new group...
(void)oldLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull);
mLoadGroup->AddChannel(this, nsnull);
}
else {
// this is the first load group we've been given...so do any extra
// start up work...
/*
Set up a request object - later set to a clone of a default
request from the handler. TODO
*/
mRequest = new nsHTTPRequest(mURI);
if (mRequest == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mRequest);
rv = mRequest->SetConnection(this);
}
return rv;
return NS_OK;
}
NS_IMETHODIMP
@ -654,6 +624,27 @@ nsHTTPChannel::OnProgress(nsIChannel* aChannel, nsISupports* aContext,
////////////////////////////////////////////////////////////////////////////////
// nsHTTPChannel methods:
nsresult nsHTTPChannel::Init(nsILoadGroup *aLoadGroup)
{
nsresult rv;
/*
Set up a request object - later set to a clone of a default
request from the handler. TODO
*/
mRequest = new nsHTTPRequest(mURI);
if (!mRequest) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mRequest);
(void) mRequest->SetConnection(this);
rv = SetLoadGroup(aLoadGroup);
return rv;
}
// Create a cache entry for the channel's URL or retrieve an existing one. If
// there's an existing cache entry for the current URL, confirm that it doesn't
// contain partially downloaded content. Finally, check to see if the cache

View File

@ -229,9 +229,9 @@ nsHTTPHandler::NewChannel(const char* verb, nsIURI* i_URL,
bufferMaxSize);
if (pChannel) {
NS_ADDREF(pChannel);
rv = pChannel->SetLoadAttributes(loadAttributes);
rv = pChannel->Init(aLoadGroup);
if (NS_FAILED(rv)) goto done;
rv = pChannel->SetLoadGroup(aLoadGroup);
rv = pChannel->SetLoadAttributes(loadAttributes);
if (NS_FAILED(rv)) goto done;
rv = pChannel->SetNotificationCallbacks(notificationCallbacks);
if (NS_FAILED(rv)) goto done;

View File

@ -529,10 +529,6 @@ nsResChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
nsAutoLock lock(mLock);
mLoadGroup = aLoadGroup;
if (mLoadGroup) {
nsresult rv = mLoadGroup->GetDefaultLoadAttributes(&mLoadAttributes);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}

View File

@ -145,6 +145,15 @@ nsMultiMixedConv::OnDataAvailable(nsIChannel *channel, nsISupports *context,
// part and move on.
rv = mFinalListener->OnStopRequest(mPartChannel, context, NS_OK, nsnull);
if (NS_FAILED(rv)) break;
// Remove the channel from its load group (if any)
nsCOMPtr<nsILoadGroup> loadGroup;
(void) mPartChannel->GetLoadGroup(getter_AddRefs(loadGroup));
if (loadGroup) {
loadGroup->RemoveChannel(mPartChannel, context, NS_OK, nsnull);
}
mPartChannel = 0;
}
// the boundary occurs at the beginning of the data.
@ -235,6 +244,8 @@ nsMultiMixedConv::OnDataAvailable(nsIChannel *channel, nsISupports *context,
if ( (newLine[mLineFeedIncrement] == '\n')
|| (newLine[mLineFeedIncrement] == '\r')
|| (newLine == cursor) ) {
nsCOMPtr<nsILoadGroup> loadGroup;
// that's it we've processed all the headers and
// this is no longer a mNewPart
mNewPart = PR_FALSE;
@ -249,12 +260,13 @@ nsMultiMixedConv::OnDataAvailable(nsIChannel *channel, nsISupports *context,
nsAllocator::Free(buffer);
return rv;
}
(void) channel->GetLoadGroup(getter_AddRefs(loadGroup));
if (mContentType.Length() < 1)
mContentType = "text/html"; // default to text/html, that's all we'll ever see anyway
rv = NS_NewInputStreamChannel(partURI, mContentType.GetBuffer(), mContentLength,
nsnull, // inStr
nsnull, // loadGroup
loadGroup, // loadGroup
nsnull, // notificationCallbacks
nsIChannel::LOAD_NORMAL,
nsnull, // originalURI
@ -265,6 +277,11 @@ nsMultiMixedConv::OnDataAvailable(nsIChannel *channel, nsISupports *context,
return rv;
}
// Add the new channel to the load group (if any)
if (loadGroup) {
loadGroup->AddChannel(mPartChannel, nsnull);
}
// Let's start off the load. NOTE: we don't forward on the channel passed
// into our OnDataAvailable() as it's the root channel for the raw stream.
rv = mFinalListener->OnStartRequest(mPartChannel, context);
@ -328,6 +345,14 @@ nsMultiMixedConv::OnDataAvailable(nsIChannel *channel, nsISupports *context,
rv = mFinalListener->OnStopRequest(mPartChannel, context, NS_OK, nsnull);
if (NS_FAILED(rv)) break;
// Remove the channel from its load group (if any)
nsCOMPtr<nsILoadGroup> loadGroup;
(void) mPartChannel->GetLoadGroup(getter_AddRefs(loadGroup));
if (loadGroup) {
loadGroup->RemoveChannel(mPartChannel, context, NS_OK, nsnull);
}
mPartChannel = 0; // kill this channel. it's done
if (done || (*(boundary+mBoundaryStrLen+1) == '-') ) {
// it's completely over

View File

@ -217,7 +217,7 @@ nsCachedChromeChannel::GetLoadAttributes(nsLoadFlags *aLoadAttributes)
NS_IMETHODIMP
nsCachedChromeChannel::SetLoadAttributes(nsLoadFlags aLoadAttributes)
{
NS_NOTREACHED("don't do that");
// XXX: NS_NOTREACHED("don't do that");
return NS_OK;
}
@ -439,6 +439,8 @@ nsChromeProtocolHandler::NewChannel(const char* aVerb, nsIURI* aURI,
// load the thing.
rv = nsCachedChromeChannel::Create(aURI, getter_AddRefs(result));
if (NS_FAILED(rv)) return rv;
result->SetLoadGroup(aLoadGroup);
}
else {
// Miss. Resolve the chrome URL using the registry and do a

View File

@ -593,6 +593,15 @@ nsDocLoaderImpl::OnStartRequest(nsIChannel *aChannel, nsISupports *aCtxt)
// called each time a channel is added to the group.
nsresult rv;
if (!mIsLoadingDocument) {
PRUint32 loadAttribs = 0;
aChannel->GetLoadAttributes(&loadAttribs);
if (loadAttribs & nsIChannel::LOAD_DOCUMENT_URI) {
mIsLoadingDocument = PR_TRUE;
}
}
//
// Only fire an OnStartDocumentLoad(...) if the document loader
// has initiated a load... Otherwise, this notification has

View File

@ -593,6 +593,15 @@ nsDocLoaderImpl::OnStartRequest(nsIChannel *aChannel, nsISupports *aCtxt)
// called each time a channel is added to the group.
nsresult rv;
if (!mIsLoadingDocument) {
PRUint32 loadAttribs = 0;
aChannel->GetLoadAttributes(&loadAttribs);
if (loadAttribs & nsIChannel::LOAD_DOCUMENT_URI) {
mIsLoadingDocument = PR_TRUE;
}
}
//
// Only fire an OnStartDocumentLoad(...) if the document loader
// has initiated a load... Otherwise, this notification has

View File

@ -1828,8 +1828,27 @@ nsresult nsWebShell::CreateViewer(nsIChannel* aChannel,
rv = aChannel->GetLoadGroup(getter_AddRefs(currentLoadGroup));
if (NS_SUCCEEDED(rv))
{
if (currentLoadGroup.get() != loadGroup.get())
if (currentLoadGroup.get() != loadGroup.get()) {
nsLoadFlags loadAttribs = 0;
//Cancel any URIs that are currently loading...
/// XXX: Need to do this eventually Stop();
//
// Retarget the document to this loadgroup...
//
if (currentLoadGroup) {
(void) currentLoadGroup->RemoveChannel(aChannel, nsnull, nsnull, nsnull);
}
aChannel->SetLoadGroup(loadGroup);
// Mark the channel as being a document URI...
aChannel->GetLoadAttributes(&loadAttribs);
loadAttribs |= nsIChannel::LOAD_DOCUMENT_URI;
aChannel->SetLoadAttributes(loadAttribs);
loadGroup->AddChannel(aChannel, nsnull);
}
}
/*