Bug 505385 - Part 17: Consolidate image request failure handling code into a central location and deal with preexisting errors correctly. r=joe

This commit is contained in:
Josh Matthews 2012-10-12 12:11:23 -04:00
Родитель be8e467dce
Коммит c15377e449
1 изменённых файлов: 22 добавлений и 20 удалений

Просмотреть файл

@ -172,6 +172,20 @@ NS_IMETHODIMP imgStatusTrackerObserver::OnStopFrame(imgIRequest *request,
return NS_OK;
}
static void
FireFailureNotification(imgRequest* aRequest)
{
// Some kind of problem has happened with image decoding.
// Report the URI to net:failed-to-process-uri-conent observers.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
nsCOMPtr<nsIURI> uri;
aRequest->GetURI(getter_AddRefs(uri));
os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
}
}
/* void onStopDecode (in imgIRequest request, in nsresult status, in wstring statusArg); */
NS_IMETHODIMP imgStatusTrackerObserver::OnStopDecode(imgIRequest *aRequest,
nsresult aStatus)
@ -184,6 +198,8 @@ NS_IMETHODIMP imgStatusTrackerObserver::OnStopDecode(imgIRequest *aRequest,
// entry size to take this into account.
mTracker->GetRequest()->UpdateCacheEntrySize();
bool preexistingError = mTracker->GetImageStatus() == imgIRequest::STATUS_ERROR;
mTracker->RecordStopDecode(aStatus);
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
@ -195,16 +211,8 @@ NS_IMETHODIMP imgStatusTrackerObserver::OnStopDecode(imgIRequest *aRequest,
// block onload, but then hit an error before we get to our first frame.
mTracker->MaybeUnblockOnload();
if (NS_FAILED(aStatus)) {
// Some kind of problem has happened with image decoding.
// Report the URI to net:failed-to-process-uri-conent observers.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
nsCOMPtr<nsIURI> uri;
mTracker->GetRequest()->GetURI(getter_AddRefs(uri));
os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
}
if (NS_FAILED(aStatus) && !preexistingError) {
FireFailureNotification(mTracker->GetRequest());
}
return NS_OK;
@ -771,6 +779,8 @@ imgStatusTracker::SendStopRequest(imgRequestProxy* aProxy, bool aLastPart, nsres
void
imgStatusTracker::OnStopRequest(bool aLastPart, nsresult aStatus)
{
bool preexistingError = mImageStatus == imgIRequest::STATUS_ERROR;
RecordStopRequest(aLastPart, aStatus);
/* notify the kids */
nsTObserverArray<imgRequestProxy*>::ForwardIterator srIter(mConsumers);
@ -778,16 +788,8 @@ imgStatusTracker::OnStopRequest(bool aLastPart, nsresult aStatus)
SendStopRequest(srIter.GetNext(), aLastPart, aStatus);
}
if (NS_FAILED(aStatus)) {
// Some kind of problem has happened with image decoding.
// Report the URI to net:failed-to-process-uri-conent observers.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
nsCOMPtr<nsIURI> uri;
GetRequest()->GetURI(getter_AddRefs(uri));
os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
}
if (NS_FAILED(aStatus) && !preexistingError) {
FireFailureNotification(GetRequest());
}
}