зеркало из https://github.com/mozilla/gecko-dev.git
Bug 977177 - Invalidate the page-icon image cache when necessary. r=adw
Remove page-icon entries when the icon changes, so that we start showing the new content. Also adds an SVG page-icon test. MozReview-Commit-ID: 10MIOvwbQ20 --HG-- extra : rebase_source : 27775ada780c0c949555d5bed979e57227549bc1
This commit is contained in:
Родитель
4a1b0e63d5
Коммит
abe092f4db
|
@ -32,6 +32,7 @@
|
|||
#include "nsIContentPolicy.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "NullPrincipal.h"
|
||||
#include "imgICache.h"
|
||||
|
||||
#define MAX_FAILED_FAVICONS 256
|
||||
#define FAVICON_CACHE_REDUCE_COUNT 64
|
||||
|
@ -260,6 +261,26 @@ nsFaviconService::SendFaviconNotifications(nsIURI* aPageURI,
|
|||
nsAutoCString faviconSpec;
|
||||
nsNavHistory* history = nsNavHistory::GetHistoryService();
|
||||
if (history && NS_SUCCEEDED(aFaviconURI->GetSpec(faviconSpec))) {
|
||||
// Invalide page-icon image cache, since the icon is about to change.
|
||||
nsCString spec;
|
||||
nsresult rv = aPageURI->GetSpec(spec);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCString pageIconSpec("page-icon:");
|
||||
pageIconSpec.Append(spec);
|
||||
nsCOMPtr<nsIURI> pageIconURI;
|
||||
rv = NS_NewURI(getter_AddRefs(pageIconURI), pageIconSpec);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<imgICache> imgCache;
|
||||
rv = GetImgTools()->GetImgCacheForDocument(nullptr, getter_AddRefs(imgCache));
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
Unused << imgCache->RemoveEntry(pageIconURI, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
history->SendPageChangedNotification(aPageURI,
|
||||
nsINavHistoryObserver::ATTRIBUTE_FAVICON,
|
||||
NS_ConvertUTF8toUTF16(faviconSpec),
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
const ICON_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==";
|
||||
const ICON_DATAURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==";
|
||||
const TEST_URI = NetUtil.newURI("http://mozilla.org/");
|
||||
const ICON_URI = NetUtil.newURI("http://mozilla.org/favicon.ico");
|
||||
|
||||
function fetchIconForSpec(spec) {
|
||||
return new Promise((resolve, reject) => {
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI("page-icon:" + TEST_URI.spec),
|
||||
uri: NetUtil.newURI(spec),
|
||||
loadUsingSystemPrincipal: true,
|
||||
contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE_FAVICON
|
||||
}, (input, status, request) => {
|
||||
|
@ -30,10 +30,10 @@ var gDefaultFavicon;
|
|||
var gFavicon;
|
||||
|
||||
add_task(function* setup() {
|
||||
yield PlacesTestUtils.addVisits({ uri: TEST_URI });
|
||||
yield PlacesTestUtils.addVisits(TEST_URI);
|
||||
|
||||
PlacesUtils.favicons.replaceFaviconDataFromDataURL(
|
||||
ICON_URI, ICON_DATA, (Date.now() + 8640000) * 1000,
|
||||
ICON_URI, ICON_DATAURL, (Date.now() + 8640000) * 1000,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
|
||||
yield new Promise(resolve => {
|
||||
|
@ -43,30 +43,42 @@ add_task(function* setup() {
|
|||
resolve, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
});
|
||||
|
||||
gDefaultFavicon = yield fetchIconForSpec(PlacesUtils.favicons.defaultFavicon);
|
||||
gFavicon = yield fetchIconForSpec(ICON_DATA);
|
||||
gDefaultFavicon = yield fetchIconForSpec(PlacesUtils.favicons.defaultFavicon.spec);
|
||||
gFavicon = yield fetchIconForSpec(ICON_DATAURL);
|
||||
});
|
||||
|
||||
add_task(function* known_url() {
|
||||
let {data, contentType} = yield fetchIconForSpec(TEST_URI.spec);
|
||||
let {data, contentType} = yield fetchIconForSpec("page-icon:" + TEST_URI.spec);
|
||||
Assert.equal(contentType, gFavicon.contentType);
|
||||
Assert.deepEqual(data, gFavicon.data, "Got the favicon data");
|
||||
});
|
||||
|
||||
add_task(function* unknown_url() {
|
||||
let {data, contentType} = yield fetchIconForSpec("http://www.moz.org/");
|
||||
let {data, contentType} = yield fetchIconForSpec("page-icon:http://www.moz.org/");
|
||||
Assert.equal(contentType, gDefaultFavicon.contentType);
|
||||
Assert.deepEqual(data, gDefaultFavicon.data, "Got the default favicon data");
|
||||
});
|
||||
|
||||
add_task(function* invalid_url() {
|
||||
let {data, contentType} = yield fetchIconForSpec("test");
|
||||
let {data, contentType} = yield fetchIconForSpec("page-icon:test");
|
||||
Assert.equal(contentType, gDefaultFavicon.contentType);
|
||||
Assert.ok(data == gDefaultFavicon.data, "Got the default favicon data");
|
||||
});
|
||||
|
||||
add_task(function* subpage_url_fallback() {
|
||||
let {data, contentType} = yield fetchIconForSpec("http://mozilla.org/missing");
|
||||
let {data, contentType} = yield fetchIconForSpec("page-icon:http://mozilla.org/missing");
|
||||
Assert.equal(contentType, gFavicon.contentType);
|
||||
Assert.deepEqual(data, gFavicon.data, "Got the root favicon data");
|
||||
});
|
||||
|
||||
add_task(function* svg_icon() {
|
||||
let faviconURI = NetUtil.newURI("http://places.test/favicon.svg");
|
||||
PlacesUtils.favicons.replaceFaviconDataFromDataURL(
|
||||
faviconURI, SMALLSVG_DATA_URI.spec, 0, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
yield setFaviconForPage(TEST_URI, faviconURI);
|
||||
let svgIcon = yield fetchIconForSpec(SMALLSVG_DATA_URI.spec);
|
||||
do_print(svgIcon.contentType)
|
||||
let pageIcon = yield fetchIconForSpec("page-icon:" + TEST_URI.spec);
|
||||
Assert.equal(svgIcon.contentType, pageIcon.contentType);
|
||||
Assert.deepEqual(svgIcon.data, pageIcon.data, "Got the root favicon data");
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче