зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1413650 - Capture loaded page instead of relying on background screenshot r=Mardak
MozReview-Commit-ID: FWToOSH8uL8 --HG-- extra : rebase_source : d0b84e1cb108234710d1e04b2df57a891c512897
This commit is contained in:
Родитель
48c7492ef8
Коммит
b4927e95b5
|
@ -44,7 +44,6 @@ var gBrowserThumbnails = {
|
|||
_tabEvents: ["TabClose", "TabSelect"],
|
||||
|
||||
init: function Thumbnails_init() {
|
||||
PageThumbs.addExpirationFilter(this);
|
||||
gBrowser.addTabsProgressListener(this);
|
||||
Services.prefs.addObserver(this.PREF_DISK_CACHE_SSL, this);
|
||||
Services.prefs.addObserver(this.PREF_ACTIVITY_STREAM_ENABLED, this);
|
||||
|
@ -62,7 +61,6 @@ var gBrowserThumbnails = {
|
|||
},
|
||||
|
||||
uninit: function Thumbnails_uninit() {
|
||||
PageThumbs.removeExpirationFilter(this);
|
||||
gBrowser.removeTabsProgressListener(this);
|
||||
Services.prefs.removeObserver(this.PREF_DISK_CACHE_SSL, this);
|
||||
Services.prefs.removeObserver(this.PREF_ACTIVITY_STREAM_ENABLED, this);
|
||||
|
@ -104,16 +102,11 @@ var gBrowserThumbnails = {
|
|||
this._activityStreamEnabled =
|
||||
Services.prefs.getBoolPref(this.PREF_ACTIVITY_STREAM_ENABLED);
|
||||
// Get the new top sites
|
||||
XPCOMUtils.defineLazyGetter(this, "_topSiteURLs", getTopSiteURLs);
|
||||
this.clearTopSiteURLCache();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* clearTopSiteURLCache is only ever called if we've created an nsITimer,
|
||||
* which only happens if we've loaded the tiles top sites. Therefore we only
|
||||
* need to clear the tiles top sites (and not activity stream's top sites)
|
||||
*/
|
||||
clearTopSiteURLCache: function Thumbnails_clearTopSiteURLCache() {
|
||||
if (this._topSiteURLsRefreshTimer) {
|
||||
this._topSiteURLsRefreshTimer.cancel();
|
||||
|
@ -129,11 +122,6 @@ var gBrowserThumbnails = {
|
|||
gBrowserThumbnails.clearTopSiteURLCache();
|
||||
},
|
||||
|
||||
async filterForThumbnailExpiration(aCallback) {
|
||||
const topSites = await this._topSiteURLs;
|
||||
aCallback(topSites);
|
||||
},
|
||||
|
||||
/**
|
||||
* State change progress listener for all tabs.
|
||||
*/
|
||||
|
@ -212,18 +200,23 @@ var gBrowserThumbnails = {
|
|||
};
|
||||
|
||||
async function getTopSiteURLs() {
|
||||
// The _topSiteURLs getter can be expensive to run, but its return value can
|
||||
// change frequently on new profiles, so as a compromise we cache its return
|
||||
// value as a lazy getter for 1 minute every time it's called.
|
||||
gBrowserThumbnails._topSiteURLsRefreshTimer =
|
||||
Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
gBrowserThumbnails._topSiteURLsRefreshTimer.initWithCallback(gBrowserThumbnails,
|
||||
60 * 1000,
|
||||
Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
let sites = [];
|
||||
if (gBrowserThumbnails._activityStreamEnabled) {
|
||||
sites = await NewTabUtils.activityStreamLinks.getTopSites();
|
||||
// Get both the top sites returned by the query, and also any pinned sites
|
||||
// that the user might have added manually that also need a screenshot.
|
||||
// Also include top sites that don't have rich icons
|
||||
let topSites = await NewTabUtils.activityStreamLinks.getTopSites();
|
||||
sites.push(...topSites.filter(link => !(link.faviconSize >= 96)));
|
||||
sites.push(...NewTabUtils.pinnedLinks.links);
|
||||
} else {
|
||||
// The _topSiteURLs getter can be expensive to run, but its return value can
|
||||
// change frequently on new profiles, so as a compromise we cache its return
|
||||
// value as a lazy getter for 1 minute every time it's called.
|
||||
gBrowserThumbnails._topSiteURLsRefreshTimer =
|
||||
Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
gBrowserThumbnails._topSiteURLsRefreshTimer.initWithCallback(gBrowserThumbnails,
|
||||
60 * 1000,
|
||||
Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
sites = NewTabUtils.links.getLinks();
|
||||
}
|
||||
return sites.reduce((urls, link) => {
|
||||
|
|
|
@ -29,6 +29,7 @@ skip-if = !crashreporter
|
|||
[browser_thumbnails_bg_no_duplicates.js]
|
||||
[browser_thumbnails_bg_captureIfMissing.js]
|
||||
[browser_thumbnails_bg_image_capture.js]
|
||||
[browser_thumbnails_bg_topsites.js]
|
||||
[browser_thumbnails_bug726727.js]
|
||||
[browser_thumbnails_bug727765.js]
|
||||
[browser_thumbnails_bug818225.js]
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const image1x1 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==";
|
||||
const image96x96 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAAJCAYAAADNYymqAAAAKklEQVR42u3RMQEAAAjDMFCO9CGDg1RC00lN6awGAACADQAACAAAAXjXApPGFm+IdJG9AAAAAElFTkSuQmCC";
|
||||
const baseURL = "http://mozilla${i}.com/";
|
||||
|
||||
function* runTests() {
|
||||
// Add 3 top sites - 2 visits each so it can pass frecency threshold of the top sites query
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
yield PlacesTestUtils.addVisits(baseURL.replace("${i}", i));
|
||||
yield PlacesTestUtils.addVisits(baseURL.replace("${i}", i));
|
||||
}
|
||||
|
||||
// Add favicon data for 2 of the top sites
|
||||
let faviconData = new Map();
|
||||
faviconData.set("http://mozilla1.com/", image1x1);
|
||||
faviconData.set("http://mozilla2.com/", image96x96);
|
||||
yield PlacesTestUtils.addFavicons(faviconData);
|
||||
|
||||
// Sanity check that we've successfully added all 3 urls to top sites
|
||||
let links = yield NewTabUtils.activityStreamLinks.getTopSites();
|
||||
is(links[0].url, baseURL.replace("${i}", 3), "Top site has been successfully added");
|
||||
is(links[1].url, baseURL.replace("${i}", 2), "Top site has been successfully added");
|
||||
is(links[2].url, baseURL.replace("${i}", 1), "Top site has been successfully added");
|
||||
|
||||
// Now, add a pinned site so we can also fetch a screenshot for that
|
||||
const pinnedSite = {url: baseURL.replace("${i}", 4)};
|
||||
NewTabUtils.pinnedLinks.pin(pinnedSite, 0);
|
||||
|
||||
// Check that the correct sites will capture screenshots
|
||||
gBrowserThumbnails.clearTopSiteURLCache();
|
||||
let topSites = yield gBrowserThumbnails._topSiteURLs;
|
||||
ok(topSites.includes("http://mozilla1.com/"), "Top site did not have a rich icon - get a screenshot");
|
||||
ok(topSites.includes("http://mozilla3.com/"), "Top site did not have an icon - get a screenshot");
|
||||
ok(topSites.includes("http://mozilla4.com/"), "Site is pinned - get a screenshot");
|
||||
ok(!topSites.includes("http://mozilla2.com/"), "Top site had a rich icon - do not get a screenshot");
|
||||
|
||||
// Clean up
|
||||
NewTabUtils.pinnedLinks.unpin(pinnedSite);
|
||||
yield PlacesTestUtils.clearHistory();
|
||||
}
|
Загрузка…
Ссылка в новой задаче