Bug 1007020 - Also send progress information when connection is LOAD_BACKGROUND. r=bz

This commit is contained in:
Dragana Damjanovic
2014-08-01 02:10:00 -04:00
parent 49d9411f36
commit 324a43aad5
9 changed files with 48 additions and 39 deletions

View File

@@ -26,6 +26,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=800386
var forwardFailed = false;
var xhr = new XMLHttpRequest;
var xhr2 = new XMLHttpRequest;
var eventSink = xhr.getInterface(Components.interfaces.nsIProgressEventSink);
isnot(eventSink, null, "Should get event sink directly!");
@@ -36,7 +38,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=800386
if (aIID.equals(Components.interfaces.nsIProgressEventSink)) {
triedForwarding = true;
try {
return xhr.getInterface(aIID);
return xhr2.getInterface(aIID);
} catch (e) {
forwardFailed = true;
}

View File

@@ -470,10 +470,6 @@ nsJARChannel::FireOnProgress(uint64_t aProgress)
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mProgressSink);
if (mLoadFlags & LOAD_BACKGROUND) {
return;
}
mProgressSink->OnProgress(this, nullptr, aProgress,
uint64_t(mContentLength));
}

View File

@@ -117,11 +117,12 @@ interface nsIRequest : nsISupports
*/
const unsigned long LOAD_NORMAL = 0;
/**
* Don't deliver status notifications to the nsIProgressEventSink, or keep
* this load from completing the nsILoadGroup it may belong to.
/**
* Do not deliver status notifications to the nsIProgressEventSink and
* do not block the loadgroup from completing (should this load belong to one).
* Note: Progress notifications will still be delivered.
*/
const unsigned long LOAD_BACKGROUND = 1 << 0;
const unsigned long LOAD_BACKGROUND = 1 << 0;
/**************************************************************************
* The following flags control the flow of data into the cache.

View File

@@ -641,27 +641,34 @@ nsBaseChannel::OnTransportStatus(nsITransport *transport, nsresult status,
{
// In some cases, we may wish to suppress transport-layer status events.
if (!mPump || NS_FAILED(mStatus) || HasLoadFlag(LOAD_BACKGROUND))
if (!mPump || NS_FAILED(mStatus)) {
return NS_OK;
}
SUSPEND_PUMP_FOR_SCOPE();
// Lazily fetch mProgressSink
if (!mProgressSink) {
if (mQueriedProgressSink)
if (mQueriedProgressSink) {
return NS_OK;
}
GetCallback(mProgressSink);
mQueriedProgressSink = true;
if (!mProgressSink)
if (!mProgressSink) {
return NS_OK;
}
}
nsAutoString statusArg;
if (GetStatusArg(status, statusArg))
mProgressSink->OnStatus(this, mListenerContext, status, statusArg.get());
if (!HasLoadFlag(LOAD_BACKGROUND)) {
nsAutoString statusArg;
if (GetStatusArg(status, statusArg)) {
mProgressSink->OnStatus(this, mListenerContext, status, statusArg.get());
}
}
if (progress)
if (progress) {
mProgressSink->OnProgress(this, mListenerContext, progress, progressMax);
}
return NS_OK;
}

View File

@@ -435,15 +435,18 @@ HttpChannelChild::OnTransportAndData(const nsresult& channelStatus,
return;
// cache the progress sink so we don't have to query for it each time.
if (!mProgressSink)
if (!mProgressSink) {
GetCallback(mProgressSink);
}
// Hold queue lock throughout all three calls, else we might process a later
// necko msg in between them.
AutoEventEnqueuer ensureSerialDispatch(mEventQ);
// block status/progress after Cancel or OnStopRequest has been called,
// Block status/progress after Cancel or OnStopRequest has been called,
// or if channel has LOAD_BACKGROUND set.
// Note: Progress events will be received directly in RecvOnProgress if
// LOAD_BACKGROUND is set.
// - JDUELL: may not need mStatus/mIsPending checks, given this is always called
// during OnDataAvailable, and we've already checked mCanceled. Code
// dupe'd from nsHttpChannel
@@ -604,15 +607,14 @@ HttpChannelChild::OnProgress(const uint64_t& progress,
return;
// cache the progress sink so we don't have to query for it each time.
if (!mProgressSink)
if (!mProgressSink) {
GetCallback(mProgressSink);
}
AutoEventEnqueuer ensureSerialDispatch(mEventQ);
// block socket status event after Cancel or OnStopRequest has been called,
// or if channel has LOAD_BACKGROUND set
if (mProgressSink && NS_SUCCEEDED(mStatus) && mIsPending &&
!(mLoadFlags & LOAD_BACKGROUND))
// Block socket status event after Cancel or OnStopRequest has been called.
if (mProgressSink && NS_SUCCEEDED(mStatus) && mIsPending)
{
if (progress > 0) {
MOZ_ASSERT(progress <= progressMax, "unexpected progress values");

View File

@@ -705,9 +705,9 @@ HttpChannelParent::OnProgress(nsIRequest *aRequest,
mStoredProgress = aProgress;
mStoredProgressMax = aProgressMax;
} else {
// Send to child now. The only case I've observed that this handles (i.e.
// non-ODA status with progress > 0) is data upload progress notification
// (status == NS_NET_STATUS_SENDING_TO)
// Send OnProgress events to the child for data upload progress notifications
// (i.e. status == NS_NET_STATUS_SENDING_TO) or if the channel has
// LOAD_BACKGROUND set.
if (mIPCClosed || !SendOnProgress(aProgress, aProgressMax))
return NS_ERROR_UNEXPECTED;
}

View File

@@ -5427,14 +5427,18 @@ nsHttpChannel::OnTransportStatus(nsITransport *trans, nsresult status,
}
// block socket status event after Cancel or OnStopRequest has been called.
if (mProgressSink && NS_SUCCEEDED(mStatus) && mIsPending && !(mLoadFlags & LOAD_BACKGROUND)) {
LOG(("sending status notification [this=%p status=%x progress=%llu/%llu]\n",
if (mProgressSink && NS_SUCCEEDED(mStatus) && mIsPending) {
LOG(("sending progress%s notification [this=%p status=%x"
" progress=%llu/%llu]\n",
(mLoadFlags & LOAD_BACKGROUND)? "" : " and status",
this, status, progress, progressMax));
nsAutoCString host;
mURI->GetHost(host);
mProgressSink->OnStatus(this, nullptr, status,
NS_ConvertUTF8toUTF16(host).get());
if (!(mLoadFlags & LOAD_BACKGROUND)) {
nsAutoCString host;
mURI->GetHost(host);
mProgressSink->OnStatus(this, nullptr, status,
NS_ConvertUTF8toUTF16(host).get());
}
if (progress > 0) {
MOZ_ASSERT(progress <= progressMax, "unexpected progress values");
@@ -5447,11 +5451,6 @@ nsHttpChannel::OnTransportStatus(nsITransport *trans, nsresult status,
}
}
}
#ifdef DEBUG
else
LOG(("skipping status notification [this=%p sink=%p pending=%u background=%x]\n",
this, mProgressSink.get(), mIsPending, (mLoadFlags & LOAD_BACKGROUND)));
#endif
return NS_OK;
}

View File

@@ -213,9 +213,10 @@ WyciwygChannelChild::OnDataAvailable(const nsCString& data,
if (NS_FAILED(rv))
Cancel(rv);
if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
if (mProgressSink && NS_SUCCEEDED(rv)) {
mProgressSink->OnProgress(this, nullptr, offset + data.Length(),
uint64_t(mContentLength));
}
}
class WyciwygStopRequestEvent : public ChannelEvent

View File

@@ -699,9 +699,10 @@ nsWyciwygChannel::OnDataAvailable(nsIRequest *request, nsISupports *ctx,
rv = mListener->OnDataAvailable(this, mListenerContext, input, offset, count);
// XXX handle 64-bit stuff for real
if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
if (mProgressSink && NS_SUCCEEDED(rv)) {
mProgressSink->OnProgress(this, nullptr, offset + count,
uint64_t(mContentLength));
}
return rv; // let the pump cancel on failure
}