The corresponding PlacesUtils API, which abstracts the complexity of the Places database.
If your code works in the context of a chrome window, you get a free PlacesUtils text variable. Otherwise (download, add SDK, whatever) you need to import PlacesUtils.jsm .
Cu.import("resource://gre/modules/PlacesUtils.jsm");
As for Places , the downloaded files are nothing more than a special kind of visited pages, respectively annotated. It is a matter of only one line of code to get an array of all downloaded files.
var results = PlacesUtils.annotations.getAnnotationsWithName("downloads/destinationFileURI");
Since we requested the destinationFileURI annotation, each resultarray element contains the loading location in the annotationValue property as a file: URI specification string.
With this you can check if the file really exists
function getFileFromURIspec(fileurispec){
getFileFromURIspec will return an nsIFile or null instance if the specification is not valid, which should not happen in this case, but the health check never hurts. With this, you can call the exists() method, and if it returns false , then the corresponding page entry in Places will be suitable for deletion. We can determine which page is its uri, which is also convenient for each results element.
PlacesUtils.bhistory.removePage(result.uri);
Summarizing
var results = PlacesUtils.annotations.getAnnotationsWithName("downloads/destinationFileURI"); results.forEach(function(result){ var file = getFileFromURIspec(result.annotationValue); if(!file){
paa
source share