From 6e77cc385393767afdd5fd3871bd2bb81b6108dd Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 15 Sep 2014 11:09:06 -0400 Subject: [PATCH] this completes fix to #207 --- _locales/de/messages.json | 4 ++++ _locales/en/messages.json | 4 ++++ _locales/fr/messages.json | 4 ++++ js/assets.js | 26 ++++++++++++++---------- js/storage.js | 42 ++++++++++++++++++++++++--------------- 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/_locales/de/messages.json b/_locales/de/messages.json index db59d5be4..90adea5ee 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -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" diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6c75c2817..0fb4c7dab 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -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" diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index 19e030c80..7655857d4 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -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" diff --git a/js/assets.js b/js/assets.js index 653a14bd7..b7d730928 100644 --- a/js/assets.js +++ b/js/assets.js @@ -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); }; diff --git a/js/storage.js b/js/storage.js index 11838c963..1faaf8f4e 100644 --- a/js/storage.js +++ b/js/storage.js @@ -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 + // 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 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; while ( i-- ) { tab = tabs[i];