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

This commit is contained in:
Patrick McManus 2012-03-22 19:39:32 -04:00
Родитель 6d514a6643
Коммит 007716fc61
7 изменённых файлов: 92 добавлений и 0 удалений

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

@ -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

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

@ -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)

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

@ -0,0 +1 @@
notajpg

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

@ -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>

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

@ -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

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

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

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

@ -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;
}