bug 717759 - negative pipeline feedback on img decode problem r=bz r=jdrew r=honzab

--HG--
extra : rebase_source : cb9795b5442102a777602f59c225ab9572e06cea
This commit is contained in:
Patrick McManus 2012-03-20 13:11:32 -04:00
parent c07a1b4659
commit 25a5bea7c6
7 changed files with 92 additions and 0 deletions

View File

@ -685,6 +685,15 @@ NS_IMETHODIMP imgRequest::OnStopDecode(imgIRequest *aRequest,
aStatusArg);
}
if (NS_FAILED(aStatus)) {
// Some kind of problem has happened with image decoding.
// Report the URI to net:failed-to-decode-uri observers.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os)
os->NotifyObservers(mURI, "net:failed-to-process-uri", nsnull);
}
// RasterImage and everything below it is completely correct and
// bulletproof about its handling of decoder notifications.
// Unfortunately, here and above we have to make some gross and

View File

@ -118,6 +118,9 @@ _CHROME_FILES = imgutils.js \
test_undisplayed_iframe.html \
iframe.html \
ref-iframe.html \
test_net_failedtoprocess.html \
invalid.jpg \
damon.jpg \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1 @@
notajpg

View File

@ -0,0 +1,48 @@
<!DOCTYPE HTML>
<html>
<!--
Test that a image decoding error producs a net:failed-to-process-uri
observer event with the nsIURI of the failed image as the subject
-->
<head>
<title>Test for image net:failed-to-process-uri</title>
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
const Ci = Components.interfaces;
const Cc = Components.classes;
var observer = {
QueryInterface: function (aIID) {
if (aIID.equals(Ci.nsISupports) ||
aIID.equals(Ci.nsIObserver))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
observe: function(subject, topic, data) {
ok(topic == "net:failed-to-process-uri", "wrong topic");
subject = subject.QueryInterface(Ci.nsIURI);
ok(subject.asciiSpec == "chrome://mochitests/content/chrome/image/test/mochitest/invalid.jpg", "wrong subject");
SimpleTest.finish();
}
};
var obs = Cc["@mozilla.org/observer-service;1"].getService();
obs = obs.QueryInterface(Ci.nsIObserverService);
obs.addObserver(observer, "net:failed-to-process-uri", false);
</script>
</pre>
<img src="damon.jpg">
<img src="invalid.jpg">
</body>
</html>

View File

@ -990,6 +990,29 @@ nsHttpConnectionMgr::PipelineFeedbackInfo(nsHttpConnectionInfo *ci,
ent->OnPipelineFeedbackInfo(info, conn, data);
}
void
nsHttpConnectionMgr::ReportFailedToProcess(nsIURI *uri)
{
NS_ABORT_IF_FALSE(uri, "precondition");
nsCAutoString host;
PRInt32 port = -1;
bool usingSSL = false;
nsresult rv = uri->SchemeIs("https", &usingSSL);
if (NS_SUCCEEDED(rv))
rv = uri->GetAsciiHost(host);
if (NS_SUCCEEDED(rv))
rv = uri->GetPort(&port);
if (NS_FAILED(rv) || host.IsEmpty())
return;
nsRefPtr<nsHttpConnectionInfo> ci =
new nsHttpConnectionInfo(host, port, nsnull, usingSSL);
PipelineFeedbackInfo(ci, RedCorruptedContent, nsnull, 0);
}
// we're at the active connection limit if any one of the following conditions is true:
// (1) at max-connections
// (2) keep-alive enabled and at max-persistent-connections-per-server/proxy

View File

@ -205,6 +205,8 @@ public:
nsHttpConnection *,
PRUint32);
void ReportFailedToProcess(nsIURI *uri);
//-------------------------------------------------------------------------
// NOTE: functions below may be called only on the socket thread.
//-------------------------------------------------------------------------

View File

@ -343,6 +343,7 @@ nsHttpHandler::Init()
mObserverService->AddObserver(this, "net:clear-active-logins", true);
mObserverService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, true);
mObserverService->AddObserver(this, "net:prune-dead-connections", true);
mObserverService->AddObserver(this, "net:failed-to-process-uri", true);
}
return NS_OK;
@ -1634,6 +1635,11 @@ nsHttpHandler::Observe(nsISupports *subject,
mConnMgr->PruneDeadConnections();
}
}
else if (strcmp(topic, "net:failed-to-process-uri") == 0) {
nsCOMPtr<nsIURI> uri = do_QueryInterface(subject);
if (uri && mConnMgr)
mConnMgr->ReportFailedToProcess(uri);
}
return NS_OK;
}