Skip to content
40 changes: 30 additions & 10 deletions lib/imgcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,20 @@ LOG_LEVEL_ERROR = 3;
};

// Fix for #42 (Cordova versions < 4.0)
Helpers.EntryToURL = function (entry) {
Helpers.EntryToURL = function (entry, native) {
if (Helpers.isCordovaAndroidOlderThan4() && typeof entry.toNativeURL === 'function') {
return entry.toNativeURL();
} else if (window.WkWebView && typeof window.WkWebView.convertFilePath === 'function') {
return window.WkWebView.convertFilePath(entry.toURL());
} else if (
!Helpers.isIonicNormalizerFunctionExist() && // Fix for #223 #237 #246
}
else if (typeof entry.toInternalURL === 'function' && window.WkWebView && document.location.protocol !== 'file') {
var nativeUrl = entry.toURL(); // will be "file://...."
// Use nativeUrl to get scheme friendly url
var schemeUrl = window.WkWebView.convertFilePath(nativeUrl); // Will be "app://.. OR other custom scheme
return schemeUrl;
}
else if(native && Helpers.isCordovaAndroid()) {
return entry.nativeURL;
}
else if (!Helpers.isIonicNormalizerFunctionExist() && // Fix for #223 #237 #246
(typeof entry.toInternalURL === 'function')) {
// Fix for #97
return entry.toInternalURL();
Expand All @@ -203,7 +210,7 @@ LOG_LEVEL_ERROR = 3;
// Returns a URL that can be used to locate a file
Helpers.EntryGetURL = function (entry) {
// toURL for html5, toURI for cordova 1.x
var url = (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.toURI());
var url = (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry, false) : entry.toURI());
// Fix for #223 #237 #246
return Helpers.isIonicNormalizerFunctionExist() ? Helpers.ionicNormalizer(url) : url;
};
Expand All @@ -220,7 +227,7 @@ LOG_LEVEL_ERROR = 3;
}
}
// From Cordova 3.3 onward toURL() seems to be required instead of fullPath (#38)
return (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.fullPath);
return (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry, true) : entry.fullPath);
} else {
return entry.fullPath;
}
Expand Down Expand Up @@ -712,9 +719,22 @@ LOG_LEVEL_ERROR = 3;
}
},
function (error) {
if (error.source) { ImgCache.overridables.log('Download error source: ' + error.source, LOG_LEVEL_ERROR); }
if (error.target) { ImgCache.overridables.log('Download error target: ' + error.target, LOG_LEVEL_ERROR); }
ImgCache.overridables.log('Download error code: ' + error.code, LOG_LEVEL_ERROR);
var FILE_TRANSFER_ERRORS = {
1: 'FILE_NOT_FOUND_ERR',
2: 'INVALID_URL_ERR',
3: 'CONNECTION_ERR',
4: 'ABORT_ERR',
5: 'NOT_MODIFIED_ERR'
};
var codeLabel = FILE_TRANSFER_ERRORS[error.code] || ('UNKNOWN(' + error.code + ')');
ImgCache.overridables.log(
'Download failed [' + codeLabel + ']' +
(error.source ? ' | source: ' + error.source : '') +
(error.target ? ' | target: ' + error.target : '') +
(error.http_status ? ' | http_status: ' + error.http_status : '') +
(error.exception ? ' | exception: ' + error.exception : ''),
LOG_LEVEL_ERROR
);
if (error_callback) { error_callback(error); }
},
on_progress
Expand Down
Loading