Bug 337371 (for tomy@ponderer.org) r=darin combine url classifier tables into a single component
This commit is contained in:
Родитель
326d5ee666
Коммит
e49ebe0adf
|
@ -0,0 +1,145 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Url Classifier code
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Tony Chang <tony@ponderer.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Abstract base class for a lookup table.
|
||||
* @construction
|
||||
*/
|
||||
function UrlClassifierTable() {
|
||||
this.debugZone = "urlclassifier-table";
|
||||
this.name = '';
|
||||
this.needsUpdate = false;
|
||||
}
|
||||
|
||||
UrlClassifierTable.prototype.QueryInterface = function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsISupports) ||
|
||||
iid.equals(Components.interfaces.nsIUrlClassifierTable))
|
||||
return this;
|
||||
Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses need to implment this method.
|
||||
*/
|
||||
UrlClassifierTable.prototype.exists = function(url, callback) {
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Url table implementation
|
||||
function UrlClassifierTableUrl() {
|
||||
UrlClassifierTable.call(this);
|
||||
this.dbservice_ = Cc["@mozilla.org/url-classifier/dbservice;1"]
|
||||
.getService(Ci.nsIUrlClassifierDBService);
|
||||
}
|
||||
UrlClassifierTableUrl.inherits(UrlClassifierTable);
|
||||
|
||||
/**
|
||||
* Look up a URL in a URL table
|
||||
*/
|
||||
UrlClassifierTableUrl.prototype.exists = function(url, callback) {
|
||||
var canonicalized = PROT_URLCanonicalizer.canonicalizeURL_(url);
|
||||
G_Debug(this, "Looking up: " + url + " (" + canonicalized + ")");
|
||||
|
||||
function dbCallback(v) {
|
||||
G_Debug("dbCallback", "Looked up " + url + ": " + v + "|");
|
||||
callback.handleEvent(v.length > 0);
|
||||
}
|
||||
this.dbservice_.exists(this.name, url, dbCallback);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Domain table implementation
|
||||
|
||||
function UrlClassifierTableDomain() {
|
||||
UrlClassifierTable.call(this);
|
||||
this.debugZone = "urlclassifier-table-domain";
|
||||
}
|
||||
UrlClassifierTableDomain.inherits(UrlClassifierTable);
|
||||
|
||||
/**
|
||||
* Look up a URL in a domain table
|
||||
*
|
||||
* @returns Boolean true if the url domain is in the table
|
||||
*/
|
||||
UrlClassifierTableDomain.prototype.exists = function(url, callback) {
|
||||
var ioService = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
var urlObj = ioService.newURI(url, null, null);
|
||||
var host = urlObj.host;
|
||||
var components = host.split(".");
|
||||
|
||||
// We don't have a good way map from hosts to domains, so we instead try
|
||||
// each possibility. Could probably optimize to start at the second dot?
|
||||
var possible = [];
|
||||
for (var i = 0; i < components.length - 1; i++) {
|
||||
host = components.slice(i).join(".");
|
||||
possible.push(host);
|
||||
}
|
||||
|
||||
// Run the possible domains against the db.
|
||||
(new ExistsMultiQuerier(possible, this.name, callback)).run();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Enchash table implementation
|
||||
function UrlClassifierTableEnchash() {
|
||||
UrlClassifierTable.call(this);
|
||||
this.debugZone = "urlclassifier-table-enchash";
|
||||
this.enchashDecrypter_ = new PROT_EnchashDecrypter();
|
||||
}
|
||||
UrlClassifierTableEnchash.inherits(UrlClassifierTable);
|
||||
|
||||
/**
|
||||
* Look up a URL in an enchashDB. We try all sub domains (up to MAX_DOTS).
|
||||
*/
|
||||
UrlClassifierTableEnchash.prototype.exists = function(url, callback) {
|
||||
var host = this.enchashDecrypter_.getCanonicalHost(url);
|
||||
|
||||
var possible = [];
|
||||
for (var i = 0; i < PROT_EnchashDecrypter.MAX_DOTS + 1; i++) {
|
||||
possible.push(host);
|
||||
|
||||
var index = host.indexOf(".");
|
||||
if (index == -1)
|
||||
break;
|
||||
host = host.substring(index + 1);
|
||||
}
|
||||
// Run the possible domains against the db.
|
||||
(new EnchashMultiQuerier(possible, this.name, callback, url)).run();
|
||||
}
|
|
@ -3,6 +3,7 @@ toolkit.jar:
|
|||
+ content/global/url-classifier/enchash-decrypter.js (content/enchash-decrypter.js)
|
||||
+ content/global/url-classifier/listmanager.js (content/listmanager.js)
|
||||
+ content/global/url-classifier/multi-querier.js (content/multi-querier.js)
|
||||
+ content/global/url-classifier/trtable.js (content/trtable.js)
|
||||
+ content/global/url-classifier/url-canonicalizer.js (content/url-canonicalizer.js)
|
||||
+ content/global/url-classifier/url-crypto.js (content/url-crypto.js)
|
||||
+ content/global/url-classifier/url-crypto-key-manager.js (content/url-crypto-key-manager.js)
|
||||
|
@ -11,7 +12,6 @@ toolkit.jar:
|
|||
#
|
||||
+ content/global/url-classifier/js/arc4.js (content/js/arc4.js)
|
||||
+ content/global/url-classifier/js/lang.js (content/js/lang.js)
|
||||
+ content/global/url-classifier/js/thread-queue.js (content/js/thread-queue.js)
|
||||
#
|
||||
+ content/global/url-classifier/moz/alarm.js (content/moz/alarm.js)
|
||||
+ content/global/url-classifier/moz/base64.js (content/moz/base64.js)
|
||||
|
|
|
@ -27,9 +27,7 @@ LOCAL_INCLUDES = \
|
|||
|
||||
|
||||
# EXTRA_COMPONENTS installs components written in JS to dist/bin/components
|
||||
EXTRA_COMPONENTS = urlClassifierTableUrl.js \
|
||||
urlClassifierTableDomain.js \
|
||||
urlClassifierTableEnchash.js \
|
||||
EXTRA_COMPONENTS = nsUrlClassifierTable.js \
|
||||
urlListManager.js \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Url Classifier code
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Tony Chang <tony@ponderer.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const G_GDEBUG = false;
|
||||
|
||||
// Use subscript loader to load files. The files in ../content get mapped
|
||||
// to chrome://global/content/url-classifier/. Order matters if one file depends
|
||||
// on another file during initialization.
|
||||
const LIB_FILES = [
|
||||
"chrome://global/content/url-classifier/js/arc4.js",
|
||||
"chrome://global/content/url-classifier/js/lang.js",
|
||||
|
||||
"chrome://global/content/url-classifier/moz/preferences.js",
|
||||
"chrome://global/content/url-classifier/moz/filesystem.js",
|
||||
"chrome://global/content/url-classifier/moz/debug.js", // req js/lang.js moz/prefs.js moz/filesystem.js
|
||||
"chrome://global/content/url-classifier/moz/lang.js",
|
||||
|
||||
"chrome://global/content/url-classifier/moz/base64.js",
|
||||
"chrome://global/content/url-classifier/moz/cryptohasher.js",
|
||||
"chrome://global/content/url-classifier/enchash-decrypter.js",
|
||||
"chrome://global/content/url-classifier/multi-querier.js",
|
||||
"chrome://global/content/url-classifier/url-canonicalizer.js",
|
||||
"chrome://global/content/url-classifier/trtable.js"
|
||||
];
|
||||
|
||||
for (var i = 0, libFile; libFile = LIB_FILES[i]; ++i) {
|
||||
//dump('*** loading subscript ' + libFile + '\n');
|
||||
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Ci.mozIJSSubScriptLoader)
|
||||
.loadSubScript(libFile);
|
||||
}
|
||||
|
||||
function UrlClassifierTableMod() {
|
||||
this.components = {};
|
||||
this.addComponent({
|
||||
cid: "{43399ee0-da0b-46a8-9541-08721265981c}",
|
||||
name: "UrlClassifier Table Url Module",
|
||||
progid: "@mozilla.org/url-classifier/table;1?type=url",
|
||||
factory: new UrlClassifierTableFactory(UrlClassifierTableUrl)
|
||||
});
|
||||
this.addComponent({
|
||||
cid: "{3b5004c6-3fcd-4b12-b311-a4dfbeaf27aa}",
|
||||
name: "UrlClassifier Table Domain Module",
|
||||
progid: "@mozilla.org/url-classifier/table;1?type=domain",
|
||||
factory: new UrlClassifierTableFactory(UrlClassifierTableDomain)
|
||||
});
|
||||
this.addComponent({
|
||||
cid: "{04f15d1d-2db8-4b8e-91d7-82f30308b434}",
|
||||
name: "UrlClassifier Table Enchash Module",
|
||||
progid: "@mozilla.org/url-classifier/table;1?type=enchash",
|
||||
factory: new UrlClassifierTableFactory(UrlClassifierTableEnchash)
|
||||
});
|
||||
}
|
||||
|
||||
UrlClassifierTableMod.prototype.addComponent = function(comp) {
|
||||
this.components[comp.cid] = comp;
|
||||
};
|
||||
|
||||
UrlClassifierTableMod.prototype.registerSelf = function(compMgr, fileSpec, loc, type) {
|
||||
compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
// Register all the components
|
||||
for (var cid in this.components) {
|
||||
var comp = this.components[cid];
|
||||
compMgr.registerFactoryLocation(Components.ID(comp.cid),
|
||||
comp.name,
|
||||
comp.progid,
|
||||
fileSpec,
|
||||
loc,
|
||||
type);
|
||||
}
|
||||
};
|
||||
|
||||
UrlClassifierTableMod.prototype.getClassObject = function(compMgr, cid, iid) {
|
||||
var comp = this.components[cid.toString()];
|
||||
|
||||
if (!comp)
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
if (!iid.equals(Ci.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
return comp.factory;
|
||||
};
|
||||
|
||||
UrlClassifierTableMod.prototype.canUnload = function(compMgr) {
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a factory.
|
||||
* @param ctor Function constructor for the object we're creating.
|
||||
*/
|
||||
function UrlClassifierTableFactory(ctor) {
|
||||
this.ctor = ctor;
|
||||
}
|
||||
|
||||
UrlClassifierTableFactory.prototype.createInstance = function(outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return (new this.ctor()).QueryInterface(iid);
|
||||
};
|
||||
|
||||
var modInst = new UrlClassifierTableMod();
|
||||
|
||||
function NSGetModule(compMgr, fileSpec) {
|
||||
return modInst;
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Url Classifier code
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Tony Chang <tony@ponderer.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// TODO: Rename this file to nsUrlClassifierListManager.js
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const G_GDEBUG = false;
|
||||
|
||||
// Use subscript loader to load files. The files in ../content get mapped
|
||||
// to chrome://global/content/url-classifier/. Order matters if one file depends
|
||||
// on another file during initialization.
|
||||
const LIB_FILES = [
|
||||
"chrome://global/content/url-classifier/js/arc4.js",
|
||||
"chrome://global/content/url-classifier/js/lang.js",
|
||||
"chrome://global/content/url-classifier/js/thread-queue.js",
|
||||
|
||||
"chrome://global/content/url-classifier/moz/preferences.js",
|
||||
"chrome://global/content/url-classifier/moz/filesystem.js",
|
||||
"chrome://global/content/url-classifier/moz/debug.js", // dep js/lang.js moz/prefs.js moz/filesystem.js
|
||||
"chrome://global/content/url-classifier/moz/alarm.js",
|
||||
"chrome://global/content/url-classifier/moz/base64.js",
|
||||
"chrome://global/content/url-classifier/moz/cryptohasher.js",
|
||||
"chrome://global/content/url-classifier/moz/lang.js",
|
||||
"chrome://global/content/url-classifier/moz/observer.js",
|
||||
"chrome://global/content/url-classifier/moz/protocol4.js",
|
||||
|
||||
"chrome://global/content/url-classifier/application.js",
|
||||
"chrome://global/content/url-classifier/listmanager.js",
|
||||
"chrome://global/content/url-classifier/url-crypto.js",
|
||||
"chrome://global/content/url-classifier/url-crypto-key-manager.js", // dep url-crypto.js
|
||||
"chrome://global/content/url-classifier/wireformat.js",
|
||||
"chrome://global/content/url-classifier/xml-fetcher.js",
|
||||
];
|
||||
|
||||
for (var i = 0, libFile; libFile = LIB_FILES[i]; ++i) {
|
||||
//dump('*** loading subscript ' + libFile + '\n');
|
||||
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Ci.mozIJSSubScriptLoader)
|
||||
.loadSubScript(libFile);
|
||||
}
|
||||
|
||||
// Module object
|
||||
function UrlClassifierListManagerMod() {
|
||||
this.firstTime = true;
|
||||
this.cid = Components.ID("{ca168834-cc00-48f9-b83c-fd018e58cae3}");
|
||||
this.progid = "@mozilla.org/url-classifier/listmanager;1";
|
||||
}
|
||||
|
||||
UrlClassifierListManagerMod.prototype.registerSelf = function(compMgr, fileSpec, loc, type) {
|
||||
if (this.firstTime) {
|
||||
this.firstTime = false;
|
||||
throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
|
||||
}
|
||||
compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
compMgr.registerFactoryLocation(this.cid,
|
||||
"UrlClassifier List Manager Module",
|
||||
this.progid,
|
||||
fileSpec,
|
||||
loc,
|
||||
type);
|
||||
};
|
||||
|
||||
UrlClassifierListManagerMod.prototype.getClassObject = function(compMgr, cid, iid) {
|
||||
if (!cid.equals(this.cid))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
if (!iid.equals(Ci.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
return this.factory;
|
||||
}
|
||||
|
||||
UrlClassifierListManagerMod.prototype.canUnload = function(compMgr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
UrlClassifierListManagerMod.prototype.factory = {
|
||||
createInstance: function(outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return (new PROT_ListManager()).QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
var ListManagerModInst = new UrlClassifierListManagerMod();
|
||||
|
||||
function NSGetModule(compMgr, fileSpec) {
|
||||
return ListManagerModInst;
|
||||
}
|
Загрузка…
Ссылка в новой задаче