From 49284ece28eb4c668bdcae1149b9f28af0f6396e Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Tue, 6 Sep 2011 12:37:42 +0200 Subject: configData.matches array is now used as include for PageMod. --- lib/libbugzilla.js | 63 +++++++++++++++++++++++++++++++++++++++++------------- lib/main.js | 21 +++++++----------- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js index 4e9cdd9..c2c0828 100644 --- a/lib/libbugzilla.js +++ b/lib/libbugzilla.js @@ -292,6 +292,12 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subjectStr, comme function loginToAllBugzillas(callback) { var loginCallsCounter = 0, bugzilla = ""; + + // This is not a good place to run this, but I do not have currently + // better place where all execution paths in this module meets in the + // end. TODO Fix this. + processPageModeREs(); + if ("enabledPackages" in config.gJSONData.configData) { // For all bugzillas we are interested in ... for (bugzillaHost in config.gJSONData.configData.enabledPackages) { @@ -315,7 +321,7 @@ function loginToAllBugzillas(callback) { // When we complete all logins, execute the callback if (loginCallsCounter <= 0) { debug("All logins done!"); - callback(); + callback(config); } }); // Increment call counter @@ -359,6 +365,15 @@ var makeJSONRPCCall = exports.makeJSONRPCCall = function makeJSONRPCCall(url, me }).post(); }; +function processPageModeREs() { + var confD = config.configData; + ['bugPageMatch', 'skipMatch'].forEach(function (key) { + confD[key] = confD[key+"Str"].map(function (REStr) { + return new RegExp(REStr); + }); + }); +} + /** * Preprocess JSON into config data structure. * @@ -366,6 +381,7 @@ var makeJSONRPCCall = exports.makeJSONRPCCall = function makeJSONRPCCall(url, me */ function processConfigJSON(rawJSON) { config.gJSONData = rawJSON; + var origConstData = config.gJSONData.configData; // Get additional tables if ("downloadJSON" in config.gJSONData.configData) { @@ -397,11 +413,33 @@ function processConfigJSON(rawJSON) { preferences.set(prefDebugName, debugOption); config.configData.debuggingVerbose = debugOption; - // FIXME What are these variables actually good for? Document them. - if ("matches" in config.configData) { - config.configData.skipMatches = config.configData.matches.map(function(x) { - return x.replace("show_bug.cgi.*","((process|post)_bug|attachment)\.cgi$"); - }); + // Include properties for the main PageMod and for the skip-process-page one. + const skippingURLParts = [ + "process_bug.cgi", + "post_bug.cgi", + "attachment.cgi" + ]; + config.configData.pageModIncludeRE = origConstData.pageModIncludeRE; + if ("matches" in origConstData) { + if (config.configData.pageModIncludeRE) { + config.configData.bugPageMatchStr = origConstData.matches; + config.configData.skipMatchStr = origConstData.matches. + map(function(x) { + return x.replace("show_bug.cgi\\?id=.*", + "\\/(process_bug|post_bug|attachment).cgi$"); + }); + } + else { + config.configData.bugPageMatch = origConstData.matches; + config.configData.skipMatch = []; + origConstData.matches. + forEach(function(x) { + skippingURLParts.forEach(function (part) { + config.configData.skipMatch.push(x. + replace("show_bug.cgi.*", part + ".cgi")); + }); + }); + } } config.constantData = {}; @@ -424,8 +462,8 @@ function processConfigJSON(rawJSON) { } copiedAttributes.forEach(function (attrib) { - if (attrib in config.gJSONData.configData) { - config.configData[attrib] = config.gJSONData.configData[attrib]; + if (attrib in origConstData) { + config.configData[attrib] = origConstData[attrib]; } }); } @@ -480,25 +518,20 @@ exports.initialize = function initialize(callback) { if(req.status == 200) { var _curETag = req.getResponseHeader("ETag"); var _curLastModified = new Date(req.getResponseHeader("Last-Modified")); - console.log("_curLastModified = " + _curLastModified); - console.log("cache.lastModified = " + - myStorage.storage.configJSON.meta.lastModified); if ((_curETag == myStorage.storage.configJSON.meta.eTag) || (_curLastModified <= myStorage.storage.configJSON.meta.lastModified)) { - console.log("Loading from cache!"); + debug("Loading from cache!"); // use cached values config = myStorage.storage.configJSON.parsedJSON; if ("submitsLogging" in config.gJSONData.configData && config.gJSONData.configData.submitsLogging) { logger.initialize(); } - console.log("config.gJSONData = " + config.gJSONData); - console.log("config.config = " + config.configData); loginToAllBugzillas(callback); } else { // cache is not up-to-date - console.log("Too old cache!"); + debug("Too old cache!"); fetchConfigurationJSON(urlStr, callback); } } diff --git a/lib/main.js b/lib/main.js index b7875c3..6561cba 100644 --- a/lib/main.js +++ b/lib/main.js @@ -114,12 +114,9 @@ var contentScriptLibraries = [ self.data.url("lib/bzpage.js") ]; -var mainPMRE = new RegExp("http[s]?:\\/\\/bug(zilla|s)\\.[^\\/]*?" + - "\\/show_bug.cgi\\?id=.*"); - -libbz.initialize(function() { +libbz.initialize(function(config) { pageMod.PageMod({ - include : [ mainPMRE ], + include : config.configData.bugPageMatch, contentScriptWhen : 'ready', contentScriptFile : contentScriptLibraries, onAttach : function onAttach(worker, msg) { @@ -135,18 +132,16 @@ libbz.initialize(function() { }); } }); -}); -var skipPGRE = new RegExp("http[s]?:\\/\\/bug(zilla|s)\\.[^\\/]*?" + - "\\/(process_bug|post_bug|attachment).cgi"); - -pageMod.PageMod({ - include : [ skipPGRE ], - contentScriptWhen : 'ready', - contentScriptFile : self.data.url("lib/skip-bug.js") + pageMod.PageMod({ + include : config.configData.skipMatch, + contentScriptWhen : 'ready', + contentScriptFile : self.data.url("lib/skip-bug.js") + }); }); + //Allow toggling of CC event displays using a context menu entry contextMenu.Item({ label : "Toggle CC History", -- cgit