diff -r 000000000000 -r 6474c204b198 browser/metro/base/content/TopSites.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/browser/metro/base/content/TopSites.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,158 @@ +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +'use strict'; + +/** + * singleton to provide data-level functionality to the views + */ +let TopSites = { + prepareCache: function(aForce){ + // front to the NewTabUtils' links cache + // -ensure NewTabUtils.links links are pre-cached + + // avoid re-fetching links data while a fetch is in flight + if (this._promisedCache && !aForce) { + return this._promisedCache; + } + let deferred = Promise.defer(); + this._promisedCache = deferred.promise; + + NewTabUtils.links.populateCache(function () { + deferred.resolve(); + this._promisedCache = null; + this._sites = null; // reset our sites cache so they are built anew + this._sitesDirty.clear(); + }.bind(this), true); + return this._promisedCache; + }, + + _sites: null, + _sitesDirty: new Set(), + getSites: function() { + if (this._sites) { + return this._sites; + } + + let links = NewTabUtils.links.getLinks(); + let sites = links.map(function(aLink){ + let site = new Site(aLink); + return site; + }); + + // reset state + this._sites = sites; + this._sitesDirty.clear(); + return this._sites; + }, + + /** + * Get list of top site as in need of update/re-render + * @param aSite Optionally add Site arguments to be refreshed/updated + */ + dirty: function() { + // add any arguments for more fine-grained updates rather than invalidating the whole collection + for (let i=0; i -1) { + NewTabUtils.pinnedLinks.pin(site, pinIndex); + } + } + // clear out the cache, we'll fetch and re-render + this._sites = null; + this._sitesDirty.clear(); + this.update(); + }, + + _linkFromNode: function _linkFromNode(aNode) { + return { + url: aNode.getAttribute("value"), + title: aNode.getAttribute("label") + }; + } +}; +