tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit eb15eb3da6f39a90e774e07cfc83152b38c05cd0
parent dcdbc805276cd5bf131cac2dbf53dda1538a32d5
Author: Nina Pypchenko <npypchenko@mozilla.com>
Date:   Fri,  3 Oct 2025 04:18:58 +0000

Bug 1942835 - Remove unused parts of NewTabUtils r=home-newtab-reviewers,thecount

Differential Revision: https://phabricator.services.mozilla.com/D267202

Diffstat:
Mtoolkit/modules/NewTabUtils.sys.mjs | 150++-----------------------------------------------------------------------------
1 file changed, 3 insertions(+), 147 deletions(-)

diff --git a/toolkit/modules/NewTabUtils.sys.mjs b/toolkit/modules/NewTabUtils.sys.mjs @@ -38,9 +38,6 @@ XPCOMUtils.defineLazyServiceGetter( "nsIIDNService" ); -// Boolean preferences that control newtab content -const PREF_NEWTAB_ENABLED = "browser.newtabpage.enabled"; - // The maximum number of results PlacesProvider retrieves from history. const HISTORY_RESULTS_LIMIT = 100; @@ -208,113 +205,6 @@ LinksStorage.prototype = { }; /** - * Singleton that serves as a registry for all open 'New Tab Page's. - */ -var AllPages = { - /** - * The array containing all active pages. - */ - _pages: [], - - /** - * Cached value that tells whether the New Tab Page feature is enabled. - */ - _enabled: null, - - /** - * Adds a page to the internal list of pages. - * @param aPage The page to register. - */ - register: function AllPages_register(aPage) { - this._pages.push(aPage); - this._addObserver(); - }, - - /** - * Removes a page from the internal list of pages. - * @param aPage The page to unregister. - */ - unregister: function AllPages_unregister(aPage) { - let index = this._pages.indexOf(aPage); - if (index > -1) { - this._pages.splice(index, 1); - } - }, - - /** - * Returns whether the 'New Tab Page' is enabled. - */ - get enabled() { - if (this._enabled === null) { - this._enabled = Services.prefs.getBoolPref(PREF_NEWTAB_ENABLED, false); - } - - return this._enabled; - }, - - /** - * Enables or disables the 'New Tab Page' feature. - */ - set enabled(aEnabled) { - if (this.enabled != aEnabled) { - Services.prefs.setBoolPref(PREF_NEWTAB_ENABLED, !!aEnabled); - } - }, - - /** - * Returns the number of registered New Tab Pages (i.e. the number of open - * about:newtab instances). - */ - get length() { - return this._pages.length; - }, - - /** - * Updates all currently active pages but the given one. - * @param aExceptPage The page to exclude from updating. - * @param aReason The reason for updating all pages. - */ - update(aExceptPage, aReason = "") { - for (let page of this._pages.slice()) { - if (aExceptPage != page) { - page.update(aReason); - } - } - }, - - /** - * Implements the nsIObserver interface to get notified when the preference - * value changes or when a new copy of a page thumbnail is available. - */ - observe: function AllPages_observe(aSubject, aTopic, aData) { - if (aTopic == "nsPref:changed") { - // Clear the cached value. - switch (aData) { - case PREF_NEWTAB_ENABLED: - this._enabled = null; - break; - } - } - // and all notifications get forwarded to each page. - this._pages.forEach(function (aPage) { - aPage.observe(aSubject, aTopic, aData); - }, this); - }, - - /** - * Adds a preference and new thumbnail observer and turns itself into a - * no-op after the first invokation. - */ - _addObserver: function AllPages_addObserver() { - Services.prefs.addObserver(PREF_NEWTAB_ENABLED, this); - Services.obs.addObserver(this, "page-thumbnail:create"); - this._addObserver = function () {}; - }, - - QueryInterface: ChromeUtils.generateQI(["nsIObserver"]), -}; - -/** * Singleton that keeps track of all pinned links and their positions in the * grid. */ @@ -1824,7 +1714,6 @@ var Links = { let { sortedLinks, siteMap, linkMap } = links; let existingLink = linkMap.get(aLink.url); let insertionLink = null; - let updatePages = false; if (existingLink) { // Update our copy's position in O(lg n) by first removing it from its @@ -1843,7 +1732,6 @@ var Links = { sortedLinks.splice(idx, 1); if (aDeleted) { - updatePages = true; linkMap.delete(existingLink.url); this._decrementSiteMap(siteMap, existingLink); } else { @@ -1857,7 +1745,6 @@ var Links = { // Update our copy's title in O(1). if ("title" in aLink && aLink.title != existingLink.title) { existingLink.title = aLink.title; - updatePages = true; } } else if (this._sortProperties.every(prop => prop in aLink)) { // Before doing the O(lg n) insertion below, do an O(1) check for the @@ -1886,11 +1773,6 @@ var Links = { linkMap.delete(lastLink.url); this._decrementSiteMap(siteMap, lastLink); } - updatePages = true; - } - - if (updatePages) { - AllPages.update(null, "links-changed"); } }, @@ -1898,13 +1780,7 @@ var Links = { * Called by a provider to notify us when many links change. */ onManyLinksChanged: function Links_onManyLinksChanged(aProvider) { - this._populateProviderCache( - aProvider, - () => { - AllPages.update(null, "links-changed"); - }, - true - ); + this._populateProviderCache(aProvider, () => {}, true); }, _indexOf: function Links__indexOf(aArray, aLink) { @@ -1924,15 +1800,7 @@ var Links = { * sanitization. */ observe: function Links_observe() { - // Make sure to update open about:newtab instances. If there are no opened - // pages we can just wait for the next new tab to populate the cache again. - if (AllPages.length && AllPages.enabled) { - this.populateCache(function () { - AllPages.update(); - }, true); - } else { - this.resetCache(); - } + this.resetCache(); }, _callObservers(methodName, ...args) { @@ -2046,11 +1914,6 @@ var ExpirationFilter = { filterForThumbnailExpiration: function ExpirationFilter_filterForThumbnailExpiration(aCallback) { - if (!AllPages.enabled) { - aCallback([]); - return; - } - Links.populateCache(function () { let urls = []; @@ -2134,10 +1997,6 @@ export var NewTabUtils = { return false; }, - isTopPlacesSite(aSite) { - return this.isTopSiteGivenProvider(aSite, PlacesProvider); - }, - /** * Restores all sites that have been removed from the grid. */ @@ -2147,9 +2006,7 @@ export var NewTabUtils = { PinnedLinks.resetCache(); BlockedLinks.resetCache(); - Links.populateCache(function () { - AllPages.update(); - }, true); + Links.populateCache(() => {}, true); }, /** @@ -2287,7 +2144,6 @@ export var NewTabUtils = { }, links: Links, - allPages: AllPages, pinnedLinks: PinnedLinks, blockedLinks: BlockedLinks, activityStreamLinks: ActivityStreamLinks,