From 0efc432bd5072b79c1a32bb136712855399d92cc Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Mon, 13 Aug 2007 04:41:22 +0000 Subject: [PATCH] Bug #328749 --> phishing detector API changes to stay in sync with firefox. sr=bienvenu --- mail/base/content/phishingDetector.js | 6 +- mail/components/phishing/list-warden.js | 97 +++++++++---------------- 2 files changed, 35 insertions(+), 68 deletions(-) diff --git a/mail/base/content/phishingDetector.js b/mail/base/content/phishingDetector.js index 9c9189646fc..c4143d77d8f 100644 --- a/mail/base/content/phishingDetector.js +++ b/mail/base/content/phishingDetector.js @@ -73,10 +73,8 @@ var gPhishingDetector = { // Register tables // XXX: move table names to a pref that we originally will download // from the provider (need to workout protocol details) - this.mPhishingWarden.registerWhiteTable("goog-white-domain"); - this.mPhishingWarden.registerWhiteTable("goog-white-url"); - this.mPhishingWarden.registerBlackTable("goog-black-url"); - this.mPhishingWarden.registerBlackTable("goog-black-enchash"); + phishWarden.registerWhiteTable("goog-white-exp"); + phishWarden.registerBlackTable("goog-phish-sha128"); // Download/update lists if we're in non-enhanced mode this.mPhishingWarden.maybeToggleUpdateChecking(); diff --git a/mail/components/phishing/list-warden.js b/mail/components/phishing/list-warden.js index 82e6115ccff..13a12b02181 100644 --- a/mail/components/phishing/list-warden.js +++ b/mail/components/phishing/list-warden.js @@ -196,82 +196,51 @@ function MultiTableQuerier(url, whiteTables, blackTables, callback) { this.debugZone = "multitablequerier"; this.url_ = url; - this.whiteTables_ = whiteTables; - this.blackTables_ = blackTables; - this.whiteIdx_ = 0; - this.blackIdx_ = 0; + this.whiteTables_ = {}; + for (var i = 0; i < whiteTables.length; i++) { + this.whiteTables_[whiteTables[i]] = true; + } + + this.blackTables_ = {}; + for (var i = 0; i < blackTables.length; i++) { + this.blackTables_[blackTables[i]] = true; + } this.callback_ = callback; this.listManager_ = Cc["@mozilla.org/url-classifier/listmanager;1"] .getService(Ci.nsIUrlListManager); } -/** - * We first query the white tables in succession. If any contain - * the url, we stop. If none contain the url, we query the black tables - * in succession. If any contain the url, we call callback and - * stop. If none of the black tables contain the url, then we just stop - * (i.e., it's not black url). - */ MultiTableQuerier.prototype.run = function() { - var whiteTable = this.whiteTables_[this.whiteIdx_]; - var blackTable = this.blackTables_[this.blackIdx_]; - if (whiteTable) { - //G_Debug(this, "Looking in whitetable: " + whiteTable); - ++this.whiteIdx_; - this.listManager_.safeExists(whiteTable, this.url_, - BindToObject(this.whiteTableCallback_, - this)); - } else if (blackTable) { - //G_Debug(this, "Looking in blacktable: " + blackTable); - ++this.blackIdx_; - this.listManager_.safeExists(blackTable, this.url_, - BindToObject(this.blackTableCallback_, - this)); - } else { - // No tables left to check, so we quit. - G_Debug(this, "Not found in any tables: " + this.url_); + /* ask the dbservice for all the tables to which this URL belongs */ + this.listManager_.safeLookup(this.url_, + BindToObject(this.lookupCallback_, this)); +} + +MultiTableQuerier.prototype.lookupCallback_ = function(result) { + if (result == "") { this.callback_(PROT_ListWarden.NOT_FOUND); - - // Break circular ref to callback. - this.callback_ = null; - this.listManager_ = null; + return; } -} -/** - * After checking a white table, we return here. If the url is found, - * we can stop. Otherwise, we call run again. - */ -MultiTableQuerier.prototype.whiteTableCallback_ = function(isFound) { - //G_Debug(this, "whiteTableCallback_: " + isFound); - if (!isFound) - this.run(); - else { - G_Debug(this, "Found in whitelist: " + this.url_) - this.callback_(PROT_ListWarden.IN_WHITELIST); + var tableNames = result.split(","); - // Break circular ref to callback. - this.callback_ = null; - this.listManager_ = null; + /* Check the whitelists */ + for (var i = 0; i < tableNames.length; i++) { + if (tableNames[i] && this.whiteTables_[tableNames[i]]) { + this.callback_(PROT_ListWarden.IN_WHITELIST); + return; + } } -} -/** - * After checking a black table, we return here. If the url is found, - * we can call the callback and stop. Otherwise, we call run again. - */ -MultiTableQuerier.prototype.blackTableCallback_ = function(isFound) { - //G_Debug(this, "blackTableCallback_: " + isFound); - if (!isFound) { - this.run(); - } else { - // In the blacklist, must be an evil url. - G_Debug(this, "Found in blacklist: " + this.url_) - this.callback_(PROT_ListWarden.IN_BLACKLIST); - - // Break circular ref to callback. - this.callback_ = null; - this.listManager_ = null; + /* Check the blacklists */ + for (var i = 0; i < tableNames.length; i++) { + if (tableNames[i] && this.blackTables_[tableNames[i]]) { + this.callback_(PROT_ListWarden.IN_BLACKLIST); + return; + } } + + /* Not in any lists we know about */ + this.callback_(PROT_ListWarden.NOT_FOUND); }