diff --git a/mozilla/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/chrome/src/nsChromeProtocolHandler.cpp index 3fe384c17f1..1706e05bd9e 100644 --- a/mozilla/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/chrome/src/nsChromeProtocolHandler.cpp @@ -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 diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index a0be6a592df..7795f9b18c9 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -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); + } } /* diff --git a/mozilla/netwerk/base/public/nsIChannel.idl b/mozilla/netwerk/base/public/nsIChannel.idl index c2c4baca109..95c930b5c89 100644 --- a/mozilla/netwerk/base/public/nsIChannel.idl +++ b/mozilla/netwerk/base/public/nsIChannel.idl @@ -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 diff --git a/mozilla/netwerk/base/src/nsLoadGroup.cpp b/mozilla/netwerk/base/src/nsLoadGroup.cpp index 1563eafe228..40fd61b7de5 100644 --- a/mozilla/netwerk/base/src/nsLoadGroup.cpp +++ b/mozilla/netwerk/base/src/nsLoadGroup.cpp @@ -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; +} + diff --git a/mozilla/netwerk/base/src/nsLoadGroup.h b/mozilla/netwerk/base/src/nsLoadGroup.h index ddf8d37993f..ced466555c7 100644 --- a/mozilla/netwerk/base/src/nsLoadGroup.h +++ b/mozilla/netwerk/base/src/nsLoadGroup.h @@ -59,6 +59,7 @@ protected: virtual ~nsLoadGroup(); nsresult Init(); + nsresult MergeLoadAttributes(nsIChannel *aChannel); protected: PRUint32 mDefaultLoadAttributes; diff --git a/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp b/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp index 0db5a2a902c..9d03c485326 100644 --- a/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp +++ b/mozilla/netwerk/protocol/file/src/nsFileChannel.cpp @@ -436,22 +436,9 @@ nsFileChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup) NS_IMETHODIMP nsFileChannel::SetLoadGroup(nsILoadGroup* aLoadGroup) { - nsresult rv = NS_OK; - nsCOMPtr 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 diff --git a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp index a8104713d13..73da5b25c1a 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp @@ -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; } diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPChannel.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPChannel.cpp index fa9f4057c9f..4c6e0514d85 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPChannel.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPChannel.cpp @@ -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 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 diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp index 365aaf2cb20..8c896a0e48d 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp @@ -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; diff --git a/mozilla/netwerk/protocol/res/src/nsResChannel.cpp b/mozilla/netwerk/protocol/res/src/nsResChannel.cpp index ac0fa42318f..524fe81089e 100644 --- a/mozilla/netwerk/protocol/res/src/nsResChannel.cpp +++ b/mozilla/netwerk/protocol/res/src/nsResChannel.cpp @@ -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; } diff --git a/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp b/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp index 567ac186529..e46ffcf83a5 100644 --- a/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp +++ b/mozilla/netwerk/streamconv/converters/nsMultiMixedConv.cpp @@ -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 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 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 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 diff --git a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp index 3fe384c17f1..1706e05bd9e 100644 --- a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp @@ -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 diff --git a/mozilla/uriloader/base/nsDocLoader.cpp b/mozilla/uriloader/base/nsDocLoader.cpp index 09581e323b9..1d5b62be451 100644 --- a/mozilla/uriloader/base/nsDocLoader.cpp +++ b/mozilla/uriloader/base/nsDocLoader.cpp @@ -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 diff --git a/mozilla/webshell/src/nsDocLoader.cpp b/mozilla/webshell/src/nsDocLoader.cpp index 09581e323b9..1d5b62be451 100644 --- a/mozilla/webshell/src/nsDocLoader.cpp +++ b/mozilla/webshell/src/nsDocLoader.cpp @@ -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 diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index a0be6a592df..7795f9b18c9 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -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); + } } /*