;;(function(exports){'use strict';var _=navigator.mozL10n.get;var MAX_AWESOME_RESULTS=4;var MAX_HISTORY_RESULTS=20;var MAX_TOPSITES_RESULTS=6;var STORE_NAME='places';var topSitesWrapper=document.getElementById('top-sites');var historyWrapper=document.getElementById('history');if(topSitesWrapper&&historyWrapper){topSitesWrapper.addEventListener('click',itemClicked);historyWrapper.addEventListener('click',itemClicked);} var cachedLink=document.createElement('a');function parseUrl(url){cachedLink.href=url;return cachedLink;} var icons={};var iconUrls={};function getIcon(place){if(place.url in icons&&icons[place.url]){return icons[place.url];} IconsHelper.getIcon(place.url,null,place).then(icon=>{saveIcon(place.url,icon);});return false;} function saveIcon(key,url){if(key in icons){return;} icons[key]=null;iconUrls[key]=url;fetchIcon(url,function(err,icon){if(!err){icons[key]=icon;}});} function fetchIcon(uri,callback){var xhr=new XMLHttpRequest({mozSystem:true});xhr.open('GET',uri,true);xhr.responseType='blob';xhr.addEventListener('load',function(){if(!(xhr.status===200||xhr.status===0)){return callback(new Error('error_downloading'));} var blob=xhr.response;if(blob.size>this.MAX_ICON_SIZE){return callback(new Error('image_to_large'));} var img=document.createElement('img');img.src=window.URL.createObjectURL(blob);img.onload=function(){window.URL.revokeObjectURL(img.src);if(img.naturalWidth<=0){return callback(new Error('Cannot load image'));} callback(null,blob);};img.onerror=function(){window.URL.revokeObjectURL(img.src);return callback(new Error('Cannot load image'));};});xhr.onerror=function(err){return callback(new Error('Cannot load uri'));};xhr.send();} function itemClicked(e){if(e.target.dataset.url){Search.navigate(e.target.dataset.url);}} var listTemplate=createList();function createList(){var list=document.createElement('ul');list.setAttribute('role','listbox');return list;} function incrementHistoryThreshold(timestamp,currentThreshold,thresholds){var newThreshold=currentThreshold+=1;if(timestamp{if(icon&&iconDom){iconDom.onload=function(){iconWrapper.classList.remove('empty');iconDom.style.display='block';};iconDom.src=icon;}});} function buildHistory(visits){var thresholds=[Date.now(),DateHelper.todayStarted(),DateHelper.yesterdayStarted(),DateHelper.thisWeekStarted(),DateHelper.thisMonthStarted(),DateHelper.lastSixMonthsStarted(),0];var threshold=0;var month=null;var year=null;var fragment=document.createDocumentFragment();visits.forEach(function(visit){if(visit.date>0&&visit.date{this.syncStore=new SyncDataStore(STORE_NAME,this.persistStore,'url');this.syncStore.filter=function(place){return place.url.startsWith('app://')||place.url==='about:blank';};this.syncStore.onChange=function(){showStartPage();};var rev=this.persistStore.latestRevision||0;return this.syncStore.sync(rev).then(()=>{return new Promise(resolve=>{function done(){showStartPage();resolve();} asyncStorage.getItem('have-preloaded-sites',(havePreloaded)=>{if(!havePreloaded){this.preloadTopSites().then(()=>{asyncStorage.setItem('have-preloaded-sites',true);done();});}else{done();}});});});});},saveSites:function(sites){return Promise.all(sites.map(site=>{site.frecency=-2;return this.persistStore.addPlace(site);}));},preloadTopSites:function(){return LazyLoader.getJSON('/js/inittopsites.json').then(sites=>{return this.saveSites(sites);});},search:function(filter){return new Promise((resolve,reject)=>{var matchedOrigins={};this.persistStore.read('frecency',MAX_AWESOME_RESULTS,(results)=>{resolve(results.map(function(result){return formatPlace(result,filter);}));},function filterFun(result){if(result.frecency<=0){return false;} var url=parseUrl(result.url);var matches=!(url.hostname in matchedOrigins)&&(matchesFilter(result.title,filter)||matchesFilter(result.url,filter));if(matches){matchedOrigins[url.hostname]=true;} return matches;});});}};exports.Places=new Places();Search.provider(exports.Places);}(window));