aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/assets.js
diff options
context:
space:
mode:
authorgorhill <rhill@raymondhill.net>2015-02-15 07:16:31 -0500
committergorhill <rhill@raymondhill.net>2015-02-15 07:16:31 -0500
commit388ac771666de7168a4f59e2185236d555a2a637 (patch)
tree223d839e22447181159b375eb83b9491affd0a20 /src/js/assets.js
parenta9acf9de26ae1e5a1a76ae5fc5356f9b2cb63297 (diff)
downloaduBlock-388ac771666de7168a4f59e2185236d555a2a637.zip
uBlock-388ac771666de7168a4f59e2185236d555a2a637.tar.gz
uBlock-388ac771666de7168a4f59e2185236d555a2a637.tar.bz2
preparing for 1st release candidate
Diffstat (limited to 'src/js/assets.js')
-rw-r--r--src/js/assets.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/js/assets.js b/src/js/assets.js
index b3bee48..ed2f812 100644
--- a/src/js/assets.js
+++ b/src/js/assets.js
@@ -265,11 +265,21 @@ var cachedAssetsManager = (function() {
var getTextFileFromURL = function(url, onLoad, onError) {
// https://github.com/gorhill/uMatrix/issues/15
var onResponseReceived = function() {
+ if ( this.status < 200 || this.status >= 300 ) {
+ return onError.call(this);
+ }
// xhr for local files gives status 0, but actually succeeds
- if ( (this.status >= 200 && this.status < 300) || (this.status === 0 && this.responseText) ) {
- return onLoad.call(this);
+ if ( this.status === 0 && stringIsNotEmpty(this.responseText) === false ) {
+ return onError.call(this);
+ }
+ // we never download anything else than plain text: discard if response
+ // appears to be a HTML document: could happen when server returns
+ // some kind of error page I suppose
+ var text = this.responseText.trim();
+ if ( text.charAt(0) === '<' && text.slice(-1) === '>' ) {
+ return onError.call(this);
}
- return onError.call(this);
+ return onLoad.call(this);
};
// console.log('µBlock> getTextFileFromURL("%s"):', url);
var xhr = new XMLHttpRequest();
@@ -1078,10 +1088,10 @@ var exports = {};
var onAssetUpdated = function(details) {
var path = details.path;
if ( details.error ) {
- console.debug('assets.js > µBlock.assetUpdater/onAssetUpdated: "%s" failed', path);
+ //console.debug('assets.js > µBlock.assetUpdater/onAssetUpdated: "%s" failed', path);
return;
}
- console.debug('assets.js > µBlock.assetUpdater/onAssetUpdated: "%s"', path);
+ //console.debug('assets.js > µBlock.assetUpdater/onAssetUpdated: "%s"', path);
updated[path] = true;
updatedCount += 1;
@@ -1109,7 +1119,7 @@ var updateOne = function() {
if ( !metaEntry.cacheObsolete && !metaEntry.repoObsolete ) {
continue;
}
- console.debug('assets.js > µBlock.assetUpdater/updateOne: assets.get("%s")', path);
+ //console.debug('assets.js > µBlock.assetUpdater/updateOne: assets.get("%s")', path);
µb.assets.get(path, onAssetUpdated);
break;
}
@@ -1136,7 +1146,7 @@ var updateDaemon = function() {
// Start an update cycle?
if ( updateCycleTime !== 0 ) {
if ( Date.now() >= updateCycleTime ) {
- console.debug('assets.js > µBlock.assetUpdater/updateDaemon: update cycle started');
+ //console.debug('assets.js > µBlock.assetUpdater/updateDaemon: update cycle started');
reset();
if ( onStart !== null ) {
onStart();
@@ -1159,7 +1169,7 @@ var updateDaemon = function() {
// If anything was updated, notify listener
if ( updatedCount !== 0 ) {
if ( onCompleted !== null ) {
- console.debug('assets.js > µBlock.assetUpdater/updateDaemon: update cycle completed');
+ //console.debug('assets.js > µBlock.assetUpdater/updateDaemon: update cycle completed');
onCompleted({
updated: JSON.parse(JSON.stringify(updated)), // give callee its own safe copy
updatedCount: updatedCount
@@ -1170,7 +1180,7 @@ var updateDaemon = function() {
// Schedule next update cycle
if ( updateCycleTime === 0 ) {
reset();
- console.debug('assets.js > µBlock.assetUpdater/updateDaemon: update cycle re-scheduled');
+ //console.debug('assets.js > µBlock.assetUpdater/updateDaemon: update cycle re-scheduled');
updateCycleTime = Date.now() + updateCycleNextPeriod;
}
};
@@ -1214,7 +1224,7 @@ exports.add = function(path) {
return;
}
- console.debug('assets.js > µBlock.assetUpdater.add("%s")', path);
+ //console.debug('assets.js > µBlock.assetUpdater.add("%s")', path);
toUpdate[path] = true;
toUpdateCount += 1;