code hardening: let's consider an empty file an invalid file

This commit is contained in:
gorhill 2014-09-03 20:29:05 -04:00
parent c0aadc1972
commit 88596cb855
1 changed files with 7 additions and 12 deletions

View File

@ -371,32 +371,27 @@ var readLocalFile = function(path, callback) {
};
var onInstallFileLoaded = function() {
this.onload = this.onerror = null;
//console.log('µBlock> readLocalFile("%s") / onInstallFileLoaded()', path);
reportBack(this.responseText);
this.onload = this.onerror = null;
};
var onInstallFileError = function() {
this.onload = this.onerror = null;
console.error('µBlock> readLocalFile("%s") / onInstallFileError()', path);
reportBack('', 'Error');
this.onload = this.onerror = null;
};
var onCachedContentLoaded = function(details) {
//console.log('µBlock> readLocalFile("%s") / onCachedContentLoaded()', path);
reportBack(details.content);
};
var onCachedContentError = function(details) {
//console.error('µBlock> readLocalFile("%s") / onCachedContentError()', path);
if ( reIsExternalPath.test(path) ) {
reportBack('', 'Error: asset not found');
var onCachedContentReady = function(details) {
//console.log('µBlock> readLocalFile("%s") / onCachedContentReady()', path);
if ( !details.error && details.content !== '' ) {
reportBack(details.content);
return;
}
getTextFileFromURL(chrome.runtime.getURL(details.path), onInstallFileLoaded, onInstallFileError);
};
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
cachedAssetsManager.load(path, onCachedContentReady);
};
// https://www.youtube.com/watch?v=r9KVpuFPtHc