1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

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", "message":"Mitwirkende",
"description":"English: Contributors" "description":"English: Contributors"
}, },
"errorCantConnectTo":{
"message":"Unable to connect to {{url}}",
"description":"English: Network error: unable to connect to {{url}}"
},
"dummy":{ "dummy":{
"message":"Dieser Eintrag muss der letzte sein", "message":"Dieser Eintrag muss der letzte sein",
"description":"so we dont need to deal with comma for last entry" "description":"so we dont need to deal with comma for last entry"

View File

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

View File

@ -259,6 +259,10 @@
"message":"Contributeurs", "message":"Contributeurs",
"description":"English: Contributors" "description":"English: Contributors"
}, },
"errorCantConnectTo":{
"message":"Erreur de connexion: {{url}}",
"description":"English: Network error: unable to connect to {{url}}"
},
"dummy":{ "dummy":{
"message":"This entry must be the last one", "message":"This entry must be the last one",
"description":"so we dont need to deal with comma for last entry" "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 lastRepoMetaTimestamp = 0;
var refreshRepoMetaPeriod = 5 * oneHour; var refreshRepoMetaPeriod = 5 * oneHour;
// TODO: move chrome.i18n.getMessage to XAL
var errorCantConnectTo = chrome.i18n.getMessage('errorCantConnectTo');
var exports = { var exports = {
autoUpdate: true, autoUpdate: true,
autoUpdateDelay: 4 * oneDay autoUpdateDelay: 4 * oneDay
@ -439,6 +442,8 @@ var readRepoFile = function(path, callback) {
callback(details); callback(details);
}; };
var repositoryURL = repositoryRoot + path;
var onRepoFileLoaded = function() { var onRepoFileLoaded = function() {
this.onload = this.onerror = null; this.onload = this.onerror = null;
//console.log('µBlock> readRepoFile("%s") / onRepoFileLoaded()', path); //console.log('µBlock> readRepoFile("%s") / onRepoFileLoaded()', path);
@ -452,13 +457,13 @@ var readRepoFile = function(path, callback) {
var onRepoFileError = function() { var onRepoFileError = function() {
this.onload = this.onerror = null; this.onload = this.onerror = null;
//console.error('µBlock> readRepoFile("%s") / onRepoFileError()', path); console.error(errorCantConnectTo.replace('{{url}}', repositoryURL));
reportBack('', 'Error'); reportBack('', 'Error');
}; };
// 'ublock=...' is to skip browser cache // 'ublock=...' is to skip browser cache
getTextFileFromURL( getTextFileFromURL(
repositoryRoot + path + '?ublock=' + Date.now(), repositoryURL + '?ublock=' + Date.now(),
onRepoFileLoaded, onRepoFileLoaded,
onRepoFileError onRepoFileError
); );
@ -516,7 +521,8 @@ var readRepoCopyAsset = function(path, callback) {
getTextFileFromURL(chrome.runtime.getURL(details.path), onInstallFileLoaded, onInstallFileError); 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() { var onRepoFileLoaded = function() {
this.onload = this.onerror = null; this.onload = this.onerror = null;
@ -532,7 +538,7 @@ var readRepoCopyAsset = function(path, callback) {
var onRepoFileError = function() { var onRepoFileError = function() {
this.onload = this.onerror = null; 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); 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); console.error('µBlock> readRepoCopyAsset("%s") / onHomeFileLoaded("%s"): no response', path, assetEntry.homeURL);
// Fetch from repo only if obsolescence was due to repo checksum // Fetch from repo only if obsolescence was due to repo checksum
if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) { if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) {
getTextFileFromURL(repositoryURL, onRepoFileLoaded, onRepoFileError); getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
} else { } else {
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError); cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
} }
@ -555,10 +561,10 @@ var readRepoCopyAsset = function(path, callback) {
var onHomeFileError = function() { var onHomeFileError = function() {
this.onload = this.onerror = null; 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 // Fetch from repo only if obsolescence was due to repo checksum
if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) { if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) {
getTextFileFromURL(repositoryURL, onRepoFileLoaded, onRepoFileError); getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
} else { } else {
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError); cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
} }
@ -604,7 +610,7 @@ var readRepoCopyAsset = function(path, callback) {
if ( typeof homeURL === 'string' && homeURL !== '' ) { if ( typeof homeURL === 'string' && homeURL !== '' ) {
getTextFileFromURL(homeURL, onHomeFileLoaded, onHomeFileError); getTextFileFromURL(homeURL, onHomeFileLoaded, onHomeFileError);
} else { } else {
getTextFileFromURL(repositoryURL, onRepoFileLoaded, onRepoFileError); getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
} }
return; return;
} }
@ -686,7 +692,7 @@ var readRepoOnlyAsset = function(path, callback) {
var onRepoFileError = function() { var onRepoFileError = function() {
this.onload = this.onerror = null; 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); cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
}; };
@ -763,7 +769,7 @@ var readExternalAsset = function(path, callback) {
var onExternalFileError = function() { var onExternalFileError = function() {
this.onload = this.onerror = null; this.onload = this.onerror = null;
console.error('µBlock> readExternalAsset("%s") / onExternalFileError()', path); console.error(errorCantConnectTo.replace('{{url}}', path));
cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError); cachedAssetsManager.load(path, onCachedContentLoaded, onCachedContentError);
}; };

View File

@ -584,24 +584,34 @@
var µb = this; var µb = this;
var fromSelfie = false; 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() { var onAllDone = function() {
// Initialize internal state with maybe already existing tabs // 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'
}, function(){ scriptEnd(tabId); });
};
var bindToTabs = function(tabs) { var bindToTabs = function(tabs) {
var scriptStart = function(tabId) {
var scriptEnd = function() {
chrome.tabs.executeScript(tabId, {
file: 'js/contentscript-end.js',
allFrames: true,
runAt: 'document_idle'
});
};
chrome.tabs.executeScript(tabId, {
file: 'js/contentscript-start.js',
allFrames: true,
runAt: 'document_idle'
}, scriptEnd);
};
var i = tabs.length, tab; var i = tabs.length, tab;
while ( i-- ) { while ( i-- ) {
tab = tabs[i]; tab = tabs[i];