Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. diff --git a/browser/base/content/browser-thumbnails.js b/browser/base/content/browser-thumbnails.js
  2. --- a/browser/base/content/browser-thumbnails.js
  3. +++ b/browser/base/content/browser-thumbnails.js
  4. @@ -104,21 +104,16 @@ var gBrowserThumbnails = {
  5. this._activityStreamEnabled =
  6. Services.prefs.getBoolPref(this.PREF_ACTIVITY_STREAM_ENABLED);
  7. // Get the new top sites
  8. XPCOMUtils.defineLazyGetter(this, "_topSiteURLs", getTopSiteURLs);
  9. break;
  10. }
  11. },
  12.  
  13. - /**
  14. - * clearTopSiteURLCache is only ever called if we've created an nsITimer,
  15. - * which only happens if we've loaded the tiles top sites. Therefore we only
  16. - * need to clear the tiles top sites (and not activity stream's top sites)
  17. - */
  18. clearTopSiteURLCache: function Thumbnails_clearTopSiteURLCache() {
  19. if (this._topSiteURLsRefreshTimer) {
  20. this._topSiteURLsRefreshTimer.cancel();
  21. this._topSiteURLsRefreshTimer = null;
  22. }
  23. // Delete the defined property
  24. delete this._topSiteURLs;
  25. XPCOMUtils.defineLazyGetter(this, "_topSiteURLs", getTopSiteURLs);
  26. @@ -142,19 +137,29 @@ var gBrowserThumbnails = {
  27. if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
  28. aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK)
  29. this._delayedCapture(aBrowser);
  30. },
  31.  
  32. async _capture(aBrowser) {
  33. // Only capture about:newtab top sites.
  34. const topSites = await this._topSiteURLs;
  35. - if (!aBrowser.currentURI ||
  36. - topSites.indexOf(aBrowser.currentURI.spec) == -1)
  37. + const index = topSites.map(l => l.url).indexOf(aBrowser.currentURI.spec);
  38. +
  39. + // if this is not a top site, do not collect a screenshot
  40. + if (!aBrowser.currentURI || index == -1)
  41. return;
  42. +
  43. + // at this point we know it's a top site, but now we check if it has a rich
  44. + // icon already, and if so we don't bother getting a screenshot
  45. + if (topSites[index].hasRichIcon)
  46. + return;
  47. +
  48. + // at this point we know it's a top site and we don't have a rich icon to show
  49. + // so it's ok to get a screenshot for this site
  50. this._shouldCapture(aBrowser, function(aResult) {
  51. if (aResult) {
  52. PageThumbs.captureAndStoreIfStale(aBrowser);
  53. }
  54. });
  55. },
  56.  
  57. _delayedCapture: function Thumbnails_delayedCapture(aBrowser) {
  58. @@ -207,29 +212,29 @@ var gBrowserThumbnails = {
  59. } else {
  60. // idle callback dispatched
  61. window.cancelIdleCallback(timeoutData.id);
  62. }
  63. }
  64. };
  65.  
  66. async function getTopSiteURLs() {
  67. + // The _topSiteURLs getter can be expensive to run, but its return value can
  68. + // change frequently on new profiles, so as a compromise we cache its return
  69. + // value as a lazy getter for 1 minute every time it's called.
  70. + gBrowserThumbnails._topSiteURLsRefreshTimer =
  71. + Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
  72. + gBrowserThumbnails._topSiteURLsRefreshTimer.initWithCallback(gBrowserThumbnails,
  73. + 60 * 1000,
  74. + Ci.nsITimer.TYPE_ONE_SHOT);
  75. let sites = [];
  76. if (gBrowserThumbnails._activityStreamEnabled) {
  77. sites = await NewTabUtils.activityStreamLinks.getTopSites();
  78. } else {
  79. - // The _topSiteURLs getter can be expensive to run, but its return value can
  80. - // change frequently on new profiles, so as a compromise we cache its return
  81. - // value as a lazy getter for 1 minute every time it's called.
  82. - gBrowserThumbnails._topSiteURLsRefreshTimer =
  83. - Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
  84. - gBrowserThumbnails._topSiteURLsRefreshTimer.initWithCallback(gBrowserThumbnails,
  85. - 60 * 1000,
  86. - Ci.nsITimer.TYPE_ONE_SHOT);
  87. sites = NewTabUtils.links.getLinks();
  88. }
  89. return sites.reduce((urls, link) => {
  90. - if (link) urls.push(link.url);
  91. + if (link) urls.push({url: link.url, hasRichIcon: link.faviconSize >= 96});
  92. return urls;
  93. }, []);
  94. }
  95.  
  96. XPCOMUtils.defineLazyGetter(gBrowserThumbnails, "_topSiteURLs", getTopSiteURLs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement