this completes fix to #207

This commit is contained in:
gorhill 2014-09-15 11:09:06 -04:00
parent 1e464ccb4a
commit 6e77cc3853
5 changed files with 54 additions and 26 deletions

View File

@ -259,6 +259,10 @@
"message":"Mitwirkende",
"description":"English: Contributors"
},
"errorCantConnectTo":{
"message":"Unable to connect to {{url}}",
"description":"English: Network error: unable to connect to {{url}}"
},
"dummy":{
"message":"Dieser Eintrag muss der letzte sein",
"description":"so we dont need to deal with comma for last entry"

View File

@ -259,6 +259,10 @@
"message":"Contributors",
"description":"English: Contributors"
},
"errorCantConnectTo":{
"message":"Unable to connect to {{url}}",
"description":"English: Network error: unable to connect to {{url}}"
},
"dummy":{
"message":"This entry must be the last one",
"description":"so we dont need to deal with comma for last entry"

View File

@ -259,6 +259,10 @@
"message":"Contributeurs",
"description":"English: Contributors"
},
"errorCantConnectTo":{
"message":"Erreur de connexion: {{url}}",
"description":"English: Network error: unable to connect to {{url}}"
},
"dummy":{
"message":"This entry must be the last one",
"description":"so we dont need to deal with comma for last entry"

View File

@ -57,6 +57,9 @@ var reIsUserPath = /^assets\/user\//;
var lastRepoMetaTimestamp = 0;
var refreshRepoMetaPeriod = 5 * oneHour;
// TODO: move chrome.i18n.getMessage to XAL
var errorCantConnectTo = chrome.i18n.getMessage('errorCantConnectTo');
var exports = {
autoUpdate: true,
autoUpdateDelay: 4 * oneDay
@ -439,6 +442,8 @@ var readRepoFile = function(path, callback) {
callback(details);
};
var repositoryURL = repositoryRoot + path;
var onRepoFileLoaded = function() {
this.onload = this.onerror = null;
//console.log('µBlock> readRepoFile("%s") / onRepoFileLoaded()', path);
@ -452,13 +457,13 @@ var readRepoFile = function(path, callback) {
var onRepoFileError = function() {
this.onload = this.onerror = null;
//console.error('µBlock> readRepoFile("%s") / onRepoFileError()', path);
console.error(errorCantConnectTo.replace('{{url}}', repositoryURL));
reportBack('', 'Error');
};
// 'ublock=...' is to skip browser cache
getTextFileFromURL(
repositoryRoot + path + '?ublock=' + Date.now(),
repositoryURL + '?ublock=' + Date.now(),
onRepoFileLoaded,
onRepoFileError
);
@ -516,7 +521,8 @@ var readRepoCopyAsset = function(path, callback) {
getTextFileFromURL(chrome.runtime.getURL(details.path), onInstallFileLoaded, onInstallFileError);
};
var repositoryURL = repositoryRoot + path + '?ublock=' + Date.now();
var repositoryURL = repositoryRoot + path;
var repositoryURLSkipCache = repositoryURL + '?ublock=' + Date.now();
var onRepoFileLoaded = function() {
this.onload = this.onerror = null;
@ -532,7 +538,7 @@ var readRepoCopyAsset = function(path, callback) {
var onRepoFileError = function() {
this.onload = this.onerror = null;
console.error('µBlock> readRepoCopyAsset("%s") / onRepoFileError("%s"):', path, repositoryURL, this.statusText);
console.error(errorCantConnectTo.replace('{{url}}', repositoryURL));
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
};
@ -542,7 +548,7 @@ var readRepoCopyAsset = function(path, callback) {
console.error('µBlock> readRepoCopyAsset("%s") / onHomeFileLoaded("%s"): no response', path, assetEntry.homeURL);
// Fetch from repo only if obsolescence was due to repo checksum
if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) {
getTextFileFromURL(repositoryURL, onRepoFileLoaded, onRepoFileError);
getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
} else {
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
}
@ -555,10 +561,10 @@ var readRepoCopyAsset = function(path, callback) {
var onHomeFileError = function() {
this.onload = this.onerror = null;
console.error('µBlock> readRepoCopyAsset("%s") / onHomeFileError("%s"):', path, assetEntry.homeURL, this.statusText);
console.error(errorCantConnectTo.replace('{{url}}', assetEntry.homeURL));
// Fetch from repo only if obsolescence was due to repo checksum
if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) {
getTextFileFromURL(repositoryURL, onRepoFileLoaded, onRepoFileError);
getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
} else {
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
}
@ -604,7 +610,7 @@ var readRepoCopyAsset = function(path, callback) {
if ( typeof homeURL === 'string' && homeURL !== '' ) {
getTextFileFromURL(homeURL, onHomeFileLoaded, onHomeFileError);
} else {
getTextFileFromURL(repositoryURL, onRepoFileLoaded, onRepoFileError);
getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
}
return;
}
@ -686,7 +692,7 @@ var readRepoOnlyAsset = function(path, callback) {
var onRepoFileError = function() {
this.onload = this.onerror = null;
console.error('µBlock> readRepoOnlyAsset("%s") / onRepoFileError("%s"):', path, repositoryURL, this.statusText);
console.error(errorCantConnectTo.replace('{{url}}', repositoryURL));
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
};
@ -763,7 +769,7 @@ var readExternalAsset = function(path, callback) {
var onExternalFileError = function() {
this.onload = this.onerror = null;
console.error('µBlock> readExternalAsset("%s") / onExternalFileError()', path);
console.error(errorCantConnectTo.replace('{{url}}', path));
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
};

View File

@ -584,24 +584,34 @@
var µb = this;
var fromSelfie = false;
// Final initialization steps after all needed assets are in memory
// Final initialization steps after all needed assets are in memory.
// - Initialize internal state with maybe already existing tabs.
// - Schedule next update operation.
var onAllDone = function() {
// Initialize internal state with maybe already existing tabs
var bindToTabs = function(tabs) {
var scriptStart = function(tabId) {
var scriptEnd = function() {
// http://code.google.com/p/chromium/issues/detail?id=410868#c11
// Need to be sure to access `chrome.runtime.lastError` to prevent
// spurious warnings in the console.
var scriptDone = function(tabId) {
chrome.runtime.lastError;
};
var scriptEnd = function(tabId) {
if ( chrome.runtime.lastError ) {
return;
}
chrome.tabs.executeScript(tabId, {
file: 'js/contentscript-end.js',
allFrames: true,
runAt: 'document_idle'
});
}, scriptDone);
};
var scriptStart = function(tabId) {
chrome.tabs.executeScript(tabId, {
file: 'js/contentscript-start.js',
allFrames: true,
runAt: 'document_idle'
}, scriptEnd);
}, function(){ scriptEnd(tabId); });
};
var bindToTabs = function(tabs) {
var i = tabs.length, tab;
while ( i-- ) {
tab = tabs[i];