home *** CD-ROM | disk | FTP | other *** search
/ Chip 2008 June / CHIP-2008-06.iso / bonus / +10SecurityTips / files / xB-Browser_2.0.0.12b.exe / App / Browser / firefox / components / nsUrlClassifierTable.js < prev    next >
Encoding:
JavaScript  |  2008-02-02  |  37.8 KB  |  1,207 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Url Classifier code
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Google Inc.
  18.  * Portions created by the Initial Developer are Copyright (C) 2006
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Tony Chang <tony@ponderer.org>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const Cc = Components.classes;
  39. const Ci = Components.interfaces;
  40.  
  41. // js/lang.js is needed for Function.prototype.inherts
  42. /* ***** BEGIN LICENSE BLOCK *****
  43.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  44.  *
  45.  * The contents of this file are subject to the Mozilla Public License Version
  46.  * 1.1 (the "License"); you may not use this file except in compliance with
  47.  * the License. You may obtain a copy of the License at
  48.  * http://www.mozilla.org/MPL/
  49.  *
  50.  * Software distributed under the License is distributed on an "AS IS" basis,
  51.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  52.  * for the specific language governing rights and limitations under the
  53.  * License.
  54.  *
  55.  * The Original Code is Google Safe Browsing.
  56.  *
  57.  * The Initial Developer of the Original Code is Google Inc.
  58.  * Portions created by the Initial Developer are Copyright (C) 2006
  59.  * the Initial Developer. All Rights Reserved.
  60.  *
  61.  * Contributor(s):
  62.  *   Aaron Boodman <aa@google.com> (original author)
  63.  *
  64.  * Alternatively, the contents of this file may be used under the terms of
  65.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  66.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  67.  * in which case the provisions of the GPL or the LGPL are applicable instead
  68.  * of those above. If you wish to allow use of your version of this file only
  69.  * under the terms of either the GPL or the LGPL, and not to allow others to
  70.  * use your version of this file under the terms of the MPL, indicate your
  71.  * decision by deleting the provisions above and replace them with the notice
  72.  * and other provisions required by the GPL or the LGPL. If you do not delete
  73.  * the provisions above, a recipient may use your version of this file under
  74.  * the terms of any one of the MPL, the GPL or the LGPL.
  75.  *
  76.  * ***** END LICENSE BLOCK ***** */
  77.  
  78. // This file has pure js helper functions. Hence you'll find metion
  79. // of browser-specific features in here.
  80.  
  81.  
  82. /**
  83.  * lang.js - The missing JavaScript language features
  84.  *
  85.  * WARNING: This class adds members to the prototypes of String, Array, and
  86.  * Function for convenience.
  87.  *
  88.  * The tradeoff is that the for/in statement will not work properly for those
  89.  * objects when this library is used.
  90.  *
  91.  * To work around this for Arrays, you may want to use the forEach() method,
  92.  * which is more fun and easier to read.
  93.  */
  94.  
  95. /**
  96.  * Returns true if the specified value is |null|
  97.  */
  98. function isNull(val) {
  99.   return val === null;
  100. }
  101.  
  102. /**
  103.  * Returns true if the specified value is an array
  104.  */
  105. function isArray(val) {
  106.   return isObject(val) && val.constructor == Array;
  107. }
  108.  
  109. /**
  110.  * Returns true if the specified value is a string
  111.  */
  112. function isString(val) {
  113.   return typeof val == "string";
  114. }
  115.  
  116. /**
  117.  * Returns true if the specified value is a boolean
  118.  */
  119. function isBoolean(val) {
  120.   return typeof val == "boolean";
  121. }
  122.  
  123. /**
  124.  * Returns true if the specified value is a number
  125.  */
  126. function isNumber(val) {
  127.   return typeof val == "number";
  128. }
  129.  
  130. /**
  131.  * Returns true if the specified value is a function
  132.  */
  133. function isFunction(val) {
  134.   return typeof val == "function";
  135. }
  136.  
  137. /**
  138.  * Returns true if the specified value is an object
  139.  */
  140. function isObject(val) {
  141.   return val && typeof val == "object";
  142. }
  143.  
  144. /**
  145.  * Returns an array of all the properties defined on an object
  146.  */
  147. function getObjectProps(obj) {
  148.   var ret = [];
  149.  
  150.   for (var p in obj) {
  151.     ret.push(p);
  152.   }
  153.  
  154.   return ret;
  155. }
  156.  
  157. /**
  158.  * Returns true if the specified value is an object which has no properties
  159.  * defined.
  160.  */
  161. function isEmptyObject(val) {
  162.   if (!isObject(val)) {
  163.     return false;
  164.   }
  165.  
  166.   for (var p in val) {
  167.     return false;
  168.   }
  169.  
  170.   return true;
  171. }
  172.  
  173. var getHashCode;
  174. var removeHashCode;
  175.  
  176. (function () {
  177.   var hashCodeProperty = "lang_hashCode_";
  178.  
  179.   /**
  180.    * Adds a lang_hashCode_ field to an object. The hash code is unique for the
  181.    * given object.
  182.    * @param obj {Object} The object to get the hash code for
  183.    * @returns {Number} The hash code for the object
  184.    */
  185.   getHashCode = function(obj) {
  186.     // In IE, DOM nodes do not extend Object so they do not have this method.
  187.     // we need to check hasOwnProperty because the proto might have this set.
  188.     if (obj.hasOwnProperty && obj.hasOwnProperty(hashCodeProperty)) {
  189.       return obj[hashCodeProperty];
  190.     }
  191.     if (!obj[hashCodeProperty]) {
  192.       obj[hashCodeProperty] = ++getHashCode.hashCodeCounter_;
  193.     }
  194.     return obj[hashCodeProperty];
  195.   };
  196.  
  197.   /**
  198.    * Removes the lang_hashCode_ field from an object.
  199.    * @param obj {Object} The object to remove the field from. 
  200.    */
  201.   removeHashCode = function(obj) {
  202.     obj.removeAttribute(hashCodeProperty);
  203.   };
  204.  
  205.   getHashCode.hashCodeCounter_ = 0;
  206. })();
  207.  
  208. /**
  209.  * Fast prefix-checker.
  210.  */
  211. String.prototype.startsWith = function(prefix) {
  212.   if (this.length < prefix.length) {
  213.     return false;
  214.   }
  215.  
  216.   if (this.substring(0, prefix.length) == prefix) {
  217.     return true;
  218.   }
  219.  
  220.   return false;
  221. }
  222.  
  223. /**
  224.  * Removes whitespace from the beginning and end of the string
  225.  */
  226. String.prototype.trim = function() {
  227.   return this.replace(/^\s+|\s+$/g, "");
  228. }
  229.  
  230. /**
  231.  * Does simple python-style string substitution.
  232.  * "foo%s hot%s".subs("bar", "dog") becomes "foobar hotdot".
  233.  * For more fully-featured templating, see template.js.
  234.  */
  235. String.prototype.subs = function() {
  236.   var ret = this;
  237.  
  238.   // this appears to be slow, but testing shows it compares more or less equiv.
  239.   // to the regex.exec method.
  240.   for (var i = 0; i < arguments.length; i++) {
  241.     ret = ret.replace(/\%s/, String(arguments[i]));
  242.   }
  243.  
  244.   return ret;
  245. }
  246.  
  247. /**
  248.  * Returns the last element on an array without removing it.
  249.  */
  250. Array.prototype.peek = function() {
  251.   return this[this.length - 1];
  252. }
  253.  
  254. // TODO(anyone): add splice the first time someone needs it and then implement
  255. // push, pop, shift, unshift in terms of it where possible.
  256.  
  257. // TODO(anyone): add the other neat-o functional methods like map(), etc.
  258.  
  259. /**
  260.  * Partially applies this function to a particular "this object" and zero or
  261.  * more arguments. The result is a new function with some arguments of the first
  262.  * function pre-filled and the value of |this| "pre-specified".
  263.  *
  264.  * Remaining arguments specified at call-time are appended to the pre-
  265.  * specified ones.
  266.  *
  267.  * Also see: partial().
  268.  *
  269.  * Note that bind and partial are optimized such that repeated calls to it do 
  270.  * not create more than one function object, so there is no additional cost for
  271.  * something like:
  272.  *
  273.  * var g = bind(f, obj);
  274.  * var h = partial(g, 1, 2, 3);
  275.  * var k = partial(h, a, b, c);
  276.  *
  277.  * Usage:
  278.  * var barMethBound = bind(myFunction, myObj, "arg1", "arg2");
  279.  * barMethBound("arg3", "arg4");
  280.  *
  281.  * @param thisObj {object} Specifies the object which |this| should point to
  282.  * when the function is run. If the value is null or undefined, it will default
  283.  * to the global object.
  284.  *
  285.  * @returns {function} A partially-applied form of the function bind() was
  286.  * invoked as a method of.
  287.  */
  288. function bind(fn, self, opt_args) {
  289.   var boundargs = (typeof fn.boundArgs_ != "undefined") ? fn.boundArgs_ : [];
  290.   boundargs = boundargs.concat(Array.prototype.slice.call(arguments, 2));
  291.  
  292.   if (typeof fn.boundSelf_ != "undefined") {
  293.     self = fn.boundSelf_;
  294.   }
  295.  
  296.   if (typeof fn.boundFn_ != "undefined") {
  297.     fn = fn.boundFn_;
  298.   }
  299.  
  300.   var newfn = function() {
  301.     // Combine the static args and the new args into one big array
  302.     var args = boundargs.concat(Array.prototype.slice.call(arguments));
  303.     return fn.apply(self, args);
  304.   }
  305.  
  306.   newfn.boundArgs_ = boundargs;
  307.   newfn.boundSelf_ = self;
  308.   newfn.boundFn_ = fn;
  309.  
  310.   return newfn;
  311. }
  312.  
  313. /**
  314.  * An alias to the bind() global function.
  315.  *
  316.  * Usage:
  317.  * var g = f.bind(obj, arg1, arg2);
  318.  * g(arg3, arg4);
  319.  */
  320. Function.prototype.bind = function(self, opt_args) {
  321.   return bind.apply(
  322.     null, [this, self].concat(Array.prototype.slice.call(arguments, 1)));
  323. }
  324.  
  325. /**
  326.  * Like bind(), except that a "this object" is not required. Useful when the
  327.  * target function is already bound.
  328.  * 
  329.  * Usage:
  330.  * var g = partial(f, arg1, arg2);
  331.  * g(arg3, arg4);
  332.  */
  333. function partial(fn, opt_args) {
  334.   return bind.apply(
  335.     null, [fn, null].concat(Array.prototype.slice.call(arguments, 1)));
  336. }
  337.  
  338. /**
  339.  * An alias to the partial() global function.
  340.  *
  341.  * Usage:
  342.  * var g = f.partial(arg1, arg2);
  343.  * g(arg3, arg4);
  344.  */
  345. Function.prototype.partial = function(opt_args) {
  346.   return bind.apply(
  347.     null, [this, null].concat(Array.prototype.slice.call(arguments)));
  348. }
  349.  
  350. /**
  351.  * Convenience. Binds all the methods of obj to itself. Calling this in the
  352.  * constructor before referencing any methods makes things a little more like
  353.  * Java or Python where methods are intrinsically bound to their instance.
  354.  */
  355. function bindMethods(obj) {
  356.   for (var p in obj) {
  357.     if (isFunction(obj[p])) {
  358.       obj[p] = obj[p].bind(obj);
  359.     }
  360.   }
  361. }
  362.  
  363. /**
  364.  * Inherit the prototype methods from one constructor into another.
  365.  *
  366.  * Usage:
  367.  * <pre>
  368.  * function ParentClass(a, b) { }
  369.  * ParentClass.prototype.foo = function(a) { }
  370.  *
  371.  * function ChildClass(a, b, c) {
  372.  *   ParentClass.call(this, a, b);
  373.  * }
  374.  *
  375.  * ChildClass.inherits(ParentClass);
  376.  *
  377.  * var child = new ChildClass("a", "b", "see");
  378.  * child.foo(); // works
  379.  * </pre>
  380.  *
  381.  * In addition, a superclass' implementation of a method can be invoked
  382.  * as follows:
  383.  *
  384.  * <pre>
  385.  * ChildClass.prototype.foo = function(a) {
  386.  *   ChildClass.superClass_.foo.call(this, a);
  387.  *   // other code
  388.  * };
  389.  * </pre>
  390.  */
  391. Function.prototype.inherits = function(parentCtor) {
  392.   var tempCtor = function(){};
  393.   tempCtor.prototype = parentCtor.prototype;
  394.   this.superClass_ = parentCtor.prototype;
  395.   this.prototype = new tempCtor();
  396. }
  397. /* ***** BEGIN LICENSE BLOCK *****
  398.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  399.  *
  400.  * The contents of this file are subject to the Mozilla Public License Version
  401.  * 1.1 (the "License"); you may not use this file except in compliance with
  402.  * the License. You may obtain a copy of the License at
  403.  * http://www.mozilla.org/MPL/
  404.  *
  405.  * Software distributed under the License is distributed on an "AS IS" basis,
  406.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  407.  * for the specific language governing rights and limitations under the
  408.  * License.
  409.  *
  410.  * The Original Code is Google Safe Browsing.
  411.  *
  412.  * The Initial Developer of the Original Code is Google Inc.
  413.  * Portions created by the Initial Developer are Copyright (C) 2006
  414.  * the Initial Developer. All Rights Reserved.
  415.  *
  416.  * Contributor(s):
  417.  *   Fritz Schneider <fritz@google.com> (original author)
  418.  *
  419.  * Alternatively, the contents of this file may be used under the terms of
  420.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  421.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  422.  * in which case the provisions of the GPL or the LGPL are applicable instead
  423.  * of those above. If you wish to allow use of your version of this file only
  424.  * under the terms of either the GPL or the LGPL, and not to allow others to
  425.  * use your version of this file under the terms of the MPL, indicate your
  426.  * decision by deleting the provisions above and replace them with the notice
  427.  * and other provisions required by the GPL or the LGPL. If you do not delete
  428.  * the provisions above, a recipient may use your version of this file under
  429.  * the terms of any one of the MPL, the GPL or the LGPL.
  430.  *
  431.  * ***** END LICENSE BLOCK ***** */
  432.  
  433.  
  434. // This is the code used to interact with data encoded in the
  435. // goog-black-enchash format. The format is basically a map from
  436. // hashed hostnames to encrypted sequences of regular expressions
  437. // where the encryption key is derived from the hashed
  438. // hostname. Encoding lists like this raises the bar slightly on
  439. // deriving complete table data from the db. This data format is NOT
  440. // our idea; we would've raise the bar higher :)
  441. //
  442. // Anyway, this code is a port of the original C++ implementation by
  443. // Garret. To ease verification, I mirrored that code as closely as
  444. // possible.  As a result, you'll see some C++-style variable naming
  445. // and roundabout (C++) ways of doing things. Additionally, I've
  446. // omitted the comments.
  447. //
  448. // This code should not change, except to fix bugs.
  449. //
  450. // TODO: verify that using encodeURI() in getCanonicalHost is OK
  451. // TODO: accommodate other kinds of perl-but-not-javascript qualifiers
  452.  
  453.  
  454. /**
  455.  * This thing knows how to generate lookup keys and decrypt values found in
  456.  * a table of type enchash.
  457.  */
  458. function PROT_EnchashDecrypter() {
  459.   this.debugZone = "enchashdecrypter";
  460.   this.REs_ = PROT_EnchashDecrypter.REs;
  461.   this.hasher_ = new G_CryptoHasher();
  462.   this.base64_ = new G_Base64();
  463.   this.streamCipher_ = Cc["@mozilla.org/security/streamcipher;1"]
  464.                        .createInstance(Ci.nsIStreamCipher);
  465. }
  466.  
  467. PROT_EnchashDecrypter.DATABASE_SALT = "oU3q.72p";
  468. PROT_EnchashDecrypter.SALT_LENGTH = PROT_EnchashDecrypter.DATABASE_SALT.length;
  469.  
  470. PROT_EnchashDecrypter.MAX_DOTS = 5;
  471.  
  472. PROT_EnchashDecrypter.REs = {};
  473. PROT_EnchashDecrypter.REs.FIND_DODGY_CHARS = 
  474.   new RegExp("[\x01-\x1f\x7f-\xff]+");
  475. PROT_EnchashDecrypter.REs.FIND_DODGY_CHARS_GLOBAL = 
  476.   new RegExp("[\x01-\x1f\x7f-\xff]+", "g");
  477. PROT_EnchashDecrypter.REs.FIND_END_DOTS = new RegExp("^\\.+|\\.+$");
  478. PROT_EnchashDecrypter.REs.FIND_END_DOTS_GLOBAL = 
  479.   new RegExp("^\\.+|\\.+$", "g");
  480. PROT_EnchashDecrypter.REs.FIND_MULTIPLE_DOTS = new RegExp("\\.{2,}");
  481. PROT_EnchashDecrypter.REs.FIND_MULTIPLE_DOTS_GLOBAL = 
  482.   new RegExp("\\.{2,}", "g");
  483. PROT_EnchashDecrypter.REs.FIND_TRAILING_SPACE =
  484.   new RegExp("^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}) ");
  485. PROT_EnchashDecrypter.REs.FIND_TRAILING_DOTS = new RegExp("\\.+$");
  486. PROT_EnchashDecrypter.REs.POSSIBLE_IP = 
  487.   new RegExp("^((?:0x[0-9a-f]+|[0-9\\.])+)$", "i");
  488. PROT_EnchashDecrypter.REs.FIND_BAD_OCTAL = new RegExp("(^|\\.)0\\d*[89]");
  489. PROT_EnchashDecrypter.REs.IS_OCTAL = new RegExp("^0[0-7]*$");
  490. PROT_EnchashDecrypter.REs.IS_DECIMAL = new RegExp("^[0-9]+$");
  491. PROT_EnchashDecrypter.REs.IS_HEX = new RegExp("^0[xX]([0-9a-fA-F]+)$");
  492.  
  493. // Regexps are given in perl regexp format. Unfortunately, JavaScript's
  494. // library isn't completely compatible. For example, you can't specify
  495. // case-insensitive matching by using (?i) in the expression text :(
  496. // So we manually set this bit with the help of this regular expression.
  497. PROT_EnchashDecrypter.REs.CASE_INSENSITIVE = /\(\?i\)/g;
  498.  
  499. /**
  500.  * Helper function 
  501.  *
  502.  * @param str String to get chars from
  503.  * 
  504.  * @param n Number of characters to get
  505.  *
  506.  * @returns String made up of the last n characters of str
  507.  */ 
  508. PROT_EnchashDecrypter.prototype.lastNChars_ = function(str, n) {
  509.   n = -n;
  510.   return str.substr(n);
  511. }
  512.  
  513. /**
  514.  * We have to have our own hex-decoder because decodeURIComponent
  515.  * expects UTF-8 (so it will barf on invalid UTF-8 sequences).
  516.  *
  517.  * @param str String to decode
  518.  * 
  519.  * @returns The decoded string
  520.  */
  521. PROT_EnchashDecrypter.prototype.hexDecode_ = function(str) {
  522.   var output = [];
  523.  
  524.   var i = 0;
  525.   while (i < str.length) {
  526.     var c = str.charAt(i);
  527.   
  528.     if (c == "%" && i + 2 < str.length) {
  529.  
  530.       var asciiVal = Number("0x" + str.charAt(i + 1) + str.charAt(i + 2));
  531.       
  532.       if (!isNaN(asciiVal)) {
  533.         i += 2;
  534.         c = String.fromCharCode(asciiVal);
  535.       }
  536.     }
  537.     
  538.     output[output.length] = c;
  539.     ++i;
  540.   }
  541.   
  542.   return output.join("");
  543. }
  544.  
  545. /**
  546.  * Translate a plaintext enchash value into regular expressions
  547.  *
  548.  * @param data String containing a decrypted enchash db entry
  549.  *
  550.  * @returns An array of RegExps
  551.  */
  552. PROT_EnchashDecrypter.prototype.parseRegExps = function(data) {
  553.   var res = data.split("\t");
  554.   
  555.   G_Debug(this, "Got " + res.length + " regular rexpressions");
  556.   
  557.   for (var i = 0; i < res.length; i++) {
  558.     // Could have leading (?i); if so, set the flag and strip it
  559.     var flags = (this.REs_.CASE_INSENSITIVE.test(res[i])) ? "i" : "";
  560.     res[i] = res[i].replace(this.REs_.CASE_INSENSITIVE, "");
  561.     res[i] = new RegExp(res[i], flags);
  562.   }
  563.  
  564.   return res;
  565. }
  566.  
  567. /**
  568.  * Get the canonical version of the given URL for lookup in a table of 
  569.  * type -url.
  570.  *
  571.  * @param url String to canonicalize
  572.  * @param opt_collapseSlashes Boolean true if we want to collapse slashes in
  573.  *        the path
  574.  *
  575.  * @returns String containing the canonicalized url (maximally url-decoded
  576.  *          with hostname normalized, then specially url-encoded)
  577.  */
  578. PROT_EnchashDecrypter.prototype.getCanonicalUrl = function(url,
  579.                                                         opt_collapseSlashes) {
  580.   var urlUtils = Cc["@mozilla.org/url-classifier/utils;1"]
  581.                  .getService(Ci.nsIUrlClassifierUtils);
  582.   var escapedUrl = urlUtils.canonicalizeURL(url);
  583.   // Normalize the host
  584.   var host = this.getCanonicalHost(escapedUrl);
  585.   if (!host) {
  586.     // Probably an invalid url, return what we have so far.
  587.     return escapedUrl;
  588.   }
  589.  
  590.   // Combine our normalized host with our escaped url.
  591.   var ioService = Cc["@mozilla.org/network/io-service;1"]
  592.                   .getService(Ci.nsIIOService);
  593.   var urlObj = ioService.newURI(escapedUrl, null, null);
  594.   urlObj.host = host;
  595.   if (opt_collapseSlashes) {
  596.     // Collapse multiple slashes in the path into a single slash.
  597.     // We end up collapsing slashes in the query string, but it's unlikely
  598.     // that this would lead to a false positive and it's much simpler to do
  599.     // this.
  600.     urlObj.path = urlObj.path.replace(/\/+/g, "/");
  601.   }
  602.   return urlObj.asciiSpec;
  603. }
  604.  
  605. /**
  606.  * @param opt_maxDots Number maximum number of dots to include.
  607.  */
  608. PROT_EnchashDecrypter.prototype.getCanonicalHost = function(str, opt_maxDots) {
  609.   var ioService = Cc["@mozilla.org/network/io-service;1"]
  610.                   .getService(Ci.nsIIOService);
  611.   try {
  612.     var urlObj = ioService.newURI(str, null, null);
  613.     var asciiHost = urlObj.asciiHost;
  614.   } catch (e) {
  615.     G_Debug(this, "Unable to get hostname: " + str);
  616.     return "";
  617.   }
  618.  
  619.   var unescaped = this.hexDecode_(asciiHost);
  620.  
  621.   unescaped = unescaped.replace(this.REs_.FIND_DODGY_CHARS_GLOBAL, "")
  622.               .replace(this.REs_.FIND_END_DOTS_GLOBAL, "")
  623.               .replace(this.REs_.FIND_MULTIPLE_DOTS_GLOBAL, ".");
  624.  
  625.   var temp = this.parseIPAddress_(unescaped);
  626.   if (temp)
  627.     unescaped = temp;
  628.  
  629.   // TODO: what, exactly is it supposed to escape? This doesn't esecape 
  630.   // ":", "/", ";", and "?"
  631.   var escaped = encodeURI(unescaped);
  632.  
  633.   if (opt_maxDots) {
  634.     // Limit the number of dots
  635.     var k;
  636.     var index = escaped.length;
  637.     for (k = 0; k < opt_maxDots + 1; k++) {
  638.       temp = escaped.lastIndexOf(".", index - 1);
  639.       if (temp == -1) {
  640.         break;
  641.       } else {
  642.         index = temp;
  643.       }
  644.     }
  645.     
  646.     if (k == opt_maxDots + 1 && index != -1) {
  647.       escaped = escaped.substring(index + 1);
  648.     }
  649.   }
  650.  
  651.   escaped = escaped.toLowerCase();
  652.   return escaped;
  653. }
  654.  
  655. PROT_EnchashDecrypter.prototype.parseIPAddress_ = function(host) {
  656.  
  657.   host = host.replace(this.REs_.FIND_TRAILING_DOTS_GLOBAL, "");
  658.  
  659.   if (host.length <= 15) {
  660.     // The Windows resolver allows a 4-part dotted decimal IP address to
  661.     // have a space followed by any old rubbish, so long as the total length
  662.     // of the string doesn't get above 15 characters. So, "10.192.95.89 xy"
  663.     // is resolved to 10.192.95.89.
  664.     // If the string length is greater than 15 characters, e.g.
  665.     // "10.192.95.89 xy.wildcard.example.com", it will be resolved through
  666.     // DNS.
  667.     var match = this.REs_.FIND_TRAILING_SPACE.exec(host);
  668.     if (match) {
  669.       host = match[1];
  670.     }
  671.   }
  672.  
  673.   if (!this.REs_.POSSIBLE_IP.test(host))
  674.     return "";
  675.  
  676.   var parts = host.split(".");
  677.   if (parts.length > 4)
  678.     return "";
  679.  
  680.   var allowOctal = !this.REs_.FIND_BAD_OCTAL.test(host);
  681.  
  682.   for (var k = 0; k < parts.length; k++) {
  683.     var canon;
  684.     if (k == parts.length - 1) {
  685.       canon = this.canonicalNum_(parts[k], 5 - parts.length, allowOctal);
  686.     } else {
  687.       canon = this.canonicalNum_(parts[k], 1, allowOctal);
  688.     }
  689.     if (canon != "") 
  690.       parts[k] = canon;
  691.     else
  692.       return "";
  693.   }
  694.  
  695.   return parts.join(".");
  696. }
  697.  
  698. PROT_EnchashDecrypter.prototype.canonicalNum_ = function(num, bytes, octal) {
  699.   if (bytes < 0) 
  700.     return "";
  701.   var temp_num;
  702.  
  703.   if (octal && this.REs_.IS_OCTAL.test(num)) {
  704.  
  705.     num = this.lastNChars_(num, 11);
  706.  
  707.     temp_num = parseInt(num, 8);
  708.     if (isNaN(temp_num))
  709.       temp_num = -1;
  710.  
  711.   } else if (this.REs_.IS_DECIMAL.test(num)) {
  712.  
  713.     num = this.lastNChars_(num, 32);
  714.  
  715.     temp_num = parseInt(num, 10);
  716.     if (isNaN(temp_num))
  717.       temp_num = -1;
  718.  
  719.   } else if (this.REs_.IS_HEX.test(num)) {
  720.     var matches = this.REs_.IS_HEX.exec(num);
  721.     if (matches) {
  722.       num = matches[1];
  723.     }
  724.  
  725.     temp_num = parseInt(num, 16);
  726.     if (isNaN(temp_num))
  727.       temp_num = -1;
  728.  
  729.   } else {
  730.     return "";
  731.   }
  732.  
  733.   if (temp_num == -1) 
  734.     return "";
  735.  
  736.   // Since we mod the number, we're removing the least significant bits.  We
  737.   // Want to push them into the front of the array to preserve the order.
  738.   var parts = [];
  739.   while (bytes--) {
  740.     parts.unshift("" + (temp_num % 256));
  741.     temp_num -= temp_num % 256;
  742.     temp_num /= 256;
  743.   }
  744.  
  745.   return parts.join(".");
  746. }
  747.  
  748. PROT_EnchashDecrypter.prototype.getLookupKey = function(host) {
  749.   var dataKey = PROT_EnchashDecrypter.DATABASE_SALT + host;
  750.   dataKey = this.base64_.arrayifyString(dataKey);
  751.  
  752.   this.hasher_.init(G_CryptoHasher.algorithms.MD5);
  753.   var lookupDigest = this.hasher_.updateFromArray(dataKey);
  754.   var lookupKey = this.hasher_.digestHex();
  755.  
  756.   return lookupKey.toUpperCase();
  757. }
  758.  
  759. PROT_EnchashDecrypter.prototype.decryptData = function(data, host) {
  760.   // XXX: base 64 decoding should be done in C++
  761.   var asciiArray = this.base64_.decodeString(data);
  762.   var ascii = this.base64_.stringifyArray(asciiArray);
  763.  
  764.   var random_salt = ascii.slice(0, PROT_EnchashDecrypter.SALT_LENGTH);
  765.   var encrypted_data = ascii.slice(PROT_EnchashDecrypter.SALT_LENGTH);
  766.   var temp_decryption_key = PROT_EnchashDecrypter.DATABASE_SALT
  767.       + random_salt + host;
  768.   this.hasher_.init(G_CryptoHasher.algorithms.MD5);
  769.   this.hasher_.updateFromString(temp_decryption_key);
  770.  
  771.   var keyFactory = Cc["@mozilla.org/security/keyobjectfactory;1"]
  772.                    .getService(Ci.nsIKeyObjectFactory);
  773.   var key = keyFactory.keyFromString(Ci.nsIKeyObject.RC4,
  774.                                      this.hasher_.digestRaw());
  775.  
  776.   this.streamCipher_.init(key);
  777.   this.streamCipher_.updateFromString(encrypted_data);
  778.  
  779.   return this.streamCipher_.finish(false /* no base64 */);
  780. }
  781.  
  782. /* ***** BEGIN LICENSE BLOCK *****
  783.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  784.  *
  785.  * The contents of this file are subject to the Mozilla Public License Version
  786.  * 1.1 (the "License"); you may not use this file except in compliance with
  787.  * the License. You may obtain a copy of the License at
  788.  * http://www.mozilla.org/MPL/
  789.  *
  790.  * Software distributed under the License is distributed on an "AS IS" basis,
  791.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  792.  * for the specific language governing rights and limitations under the
  793.  * License.
  794.  *
  795.  * The Original Code is Google Safe Browsing.
  796.  *
  797.  * The Initial Developer of the Original Code is Google Inc.
  798.  * Portions created by the Initial Developer are Copyright (C) 2006
  799.  * the Initial Developer. All Rights Reserved.
  800.  *
  801.  * Contributor(s):
  802.  *   Tony Chang <tony@google.com> (original author)
  803.  *
  804.  * Alternatively, the contents of this file may be used under the terms of
  805.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  806.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  807.  * in which case the provisions of the GPL or the LGPL are applicable instead
  808.  * of those above. If you wish to allow use of your version of this file only
  809.  * under the terms of either the GPL or the LGPL, and not to allow others to
  810.  * use your version of this file under the terms of the MPL, indicate your
  811.  * decision by deleting the provisions above and replace them with the notice
  812.  * and other provisions required by the GPL or the LGPL. If you do not delete
  813.  * the provisions above, a recipient may use your version of this file under
  814.  * the terms of any one of the MPL, the GPL or the LGPL.
  815.  *
  816.  * ***** END LICENSE BLOCK ***** */
  817.  
  818. /**
  819.  * This class helps us batch a series of async calls to the db.
  820.  * If any of the tokens is in the database, we fire callback with
  821.  * true as a param.  If all the tokens are not in the  database,
  822.  * we fire callback with false as a param.
  823.  * This is an "Abstract" base class.  Subclasses need to supply
  824.  * the condition_ method.
  825.  *
  826.  * @param tokens Array of strings to lookup in the db
  827.  * @param tableName String name of the table
  828.  * @param callback Function callback function that takes true if the condition
  829.  *        passes.
  830.  */
  831. function MultiQuerier(tokens, tableName, callback) {
  832.   this.tokens_ = tokens;
  833.   this.tableName_ = tableName;
  834.   this.callback_ = callback;
  835.   this.dbservice_ = Cc["@mozilla.org/url-classifier/dbservice;1"]
  836.                     .getService(Ci.nsIUrlClassifierDBService);
  837.   // We put the current token in this variable.
  838.   this.key_ = null;
  839. }
  840.  
  841. /**
  842.  * Run the remaining tokens against the db.
  843.  */
  844. MultiQuerier.prototype.run = function() {
  845.   if (this.tokens_.length == 0) {
  846.     this.callback_.handleEvent(false);
  847.     this.dbservice_ = null;
  848.     this.callback_ = null;
  849.     return;
  850.   }
  851.   
  852.   this.key_ = this.tokens_.pop();
  853.   G_Debug(this, "Looking up " + this.key_ + " in " + this.tableName_);
  854.   this.dbservice_.exists(this.tableName_, this.key_,
  855.                          BindToObject(this.result_, this));
  856. }
  857.  
  858. /**
  859.  * Callback from the db.  If the returned value passes the this.condition_
  860.  * test, go ahead and call the main callback.
  861.  */
  862. MultiQuerier.prototype.result_ = function(value) {
  863.   if (this.condition_(value)) {
  864.     this.callback_.handleEvent(true)
  865.     this.dbservice_ = null;
  866.     this.callback_ = null;
  867.   } else {
  868.     this.run();
  869.   }
  870. }
  871.  
  872. // Subclasses must override this.
  873. MultiQuerier.prototype.condition_ = function(value) {
  874.   throw "MultiQuerier is an abstract base class";
  875. }
  876.  
  877.  
  878. /**
  879.  * Concrete MultiQuerier that stops if the key exists in the db.
  880.  */
  881. function ExistsMultiQuerier(tokens, tableName, callback) {
  882.   MultiQuerier.call(this, tokens, tableName, callback);
  883.   this.debugZone = "existsMultiQuerier";
  884. }
  885. ExistsMultiQuerier.inherits(MultiQuerier);
  886.  
  887. ExistsMultiQuerier.prototype.condition_ = function(value) {
  888.   return value.length > 0;
  889. }
  890.  
  891.  
  892. /**
  893.  * Concrete MultiQuerier that looks up a key, decrypts it, then
  894.  * checks the the resulting regular expressions for a match.
  895.  * @param tokens Array of hosts
  896.  */
  897. function EnchashMultiQuerier(tokens, tableName, callback, url) {
  898.   MultiQuerier.call(this, tokens, tableName, callback);
  899.   this.url_ = url;
  900.   this.enchashDecrypter_ = new PROT_EnchashDecrypter();
  901.   this.debugZone = "enchashMultiQuerier";
  902. }
  903. EnchashMultiQuerier.inherits(MultiQuerier);
  904.  
  905. EnchashMultiQuerier.prototype.run = function() {
  906.   if (this.tokens_.length == 0) {
  907.     this.callback_.handleEvent(false);
  908.     this.dbservice_ = null;
  909.     this.callback_ = null;
  910.     return;
  911.   }
  912.   var host = this.tokens_.pop();
  913.   this.key_ = host;
  914.   var lookupKey = this.enchashDecrypter_.getLookupKey(host);
  915.   this.dbservice_.exists(this.tableName_, lookupKey,
  916.                          BindToObject(this.result_, this));
  917. }
  918.  
  919. EnchashMultiQuerier.prototype.condition_ = function(encryptedValue) {
  920.   if (encryptedValue.length > 0) {
  921.     // We have encrypted regular expressions for this host. Let's 
  922.     // decrypt them and see if we have a match.
  923.     var decrypted = this.enchashDecrypter_.decryptData(encryptedValue,
  924.                                                        this.key_);
  925.     var res = this.enchashDecrypter_.parseRegExps(decrypted);
  926.     for (var j = 0; j < res.length; j++) {
  927.       if (res[j].test(this.url_)) {
  928.         return true;
  929.       }
  930.     }
  931.   }
  932.   return false;
  933. }
  934. /* ***** BEGIN LICENSE BLOCK *****
  935.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  936.  *
  937.  * The contents of this file are subject to the Mozilla Public License Version
  938.  * 1.1 (the "License"); you may not use this file except in compliance with
  939.  * the License. You may obtain a copy of the License at
  940.  * http://www.mozilla.org/MPL/
  941.  *
  942.  * Software distributed under the License is distributed on an "AS IS" basis,
  943.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  944.  * for the specific language governing rights and limitations under the
  945.  * License.
  946.  *
  947.  * The Original Code is Url Classifier code
  948.  *
  949.  * The Initial Developer of the Original Code is
  950.  * Google Inc.
  951.  * Portions created by the Initial Developer are Copyright (C) 2006
  952.  * the Initial Developer. All Rights Reserved.
  953.  *
  954.  * Contributor(s):
  955.  *   Tony Chang <tony@ponderer.org>
  956.  *
  957.  * Alternatively, the contents of this file may be used under the terms of
  958.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  959.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  960.  * in which case the provisions of the GPL or the LGPL are applicable instead
  961.  * of those above. If you wish to allow use of your version of this file only
  962.  * under the terms of either the GPL or the LGPL, and not to allow others to
  963.  * use your version of this file under the terms of the MPL, indicate your
  964.  * decision by deleting the provisions above and replace them with the notice
  965.  * and other provisions required by the GPL or the LGPL. If you do not delete
  966.  * the provisions above, a recipient may use your version of this file under
  967.  * the terms of any one of the MPL, the GPL or the LGPL.
  968.  *
  969.  * ***** END LICENSE BLOCK ***** */
  970.  
  971. // XXX: This should all be moved into the dbservice class so it happens
  972. // in the background thread.
  973.  
  974. /**
  975.  * Abstract base class for a lookup table.
  976.  * @construction
  977.  */
  978. function UrlClassifierTable() {
  979.   this.debugZone = "urlclassifier-table";
  980.   this.name = '';
  981.   this.needsUpdate = false;
  982.   this.enchashDecrypter_ = new PROT_EnchashDecrypter();
  983. }
  984.  
  985. UrlClassifierTable.prototype.QueryInterface = function(iid) {
  986.   if (iid.equals(Components.interfaces.nsISupports) ||
  987.       iid.equals(Components.interfaces.nsIUrlClassifierTable))
  988.     return this;                                              
  989.   Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
  990.   return null;
  991. }
  992.  
  993. /**
  994.  * Subclasses need to implment this method.
  995.  */
  996. UrlClassifierTable.prototype.exists = function(url, callback) {
  997.   throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  998. }
  999.  
  1000. /////////////////////////////////////////////////////////////////////
  1001. // Url table implementation
  1002. function UrlClassifierTableUrl() {
  1003.   UrlClassifierTable.call(this);
  1004. }
  1005. UrlClassifierTableUrl.inherits(UrlClassifierTable);
  1006.  
  1007. /**
  1008.  * Look up a URL in a URL table
  1009.  */
  1010. UrlClassifierTableUrl.prototype.exists = function(url, callback) {
  1011.   var urlUtils = Cc["@mozilla.org/url-classifier/utils;1"]
  1012.                  .getService(Ci.nsIUrlClassifierUtils);
  1013.   // We plan on having the server collapse multiple slashes in the path.
  1014.   // Until this happens, we check both the raw url and the url with multiple
  1015.   // slashes removed.
  1016.   var urls = [
  1017.     this.enchashDecrypter_.getCanonicalUrl(url),
  1018.     this.enchashDecrypter_.getCanonicalUrl(url, true) /* collapse slashes */
  1019.   ];
  1020.  
  1021.   G_Debug(this, "Looking up: " + url + " (" + urls + ")");
  1022.   (new ExistsMultiQuerier(urls,
  1023.                           this.name,
  1024.                           callback)).run();
  1025. }
  1026.  
  1027. /////////////////////////////////////////////////////////////////////
  1028. // Domain table implementation
  1029.  
  1030. function UrlClassifierTableDomain() {
  1031.   UrlClassifierTable.call(this);
  1032.   this.debugZone = "urlclassifier-table-domain";
  1033.   this.ioService_ = Cc["@mozilla.org/network/io-service;1"]
  1034.                     .getService(Ci.nsIIOService);
  1035. }
  1036. UrlClassifierTableDomain.inherits(UrlClassifierTable);
  1037.  
  1038. /**
  1039.  * Look up a URL in a domain table
  1040.  * We also try to lookup domain + first path component (e.g.,
  1041.  * www.mozilla.org/products).
  1042.  *
  1043.  * @returns Boolean true if the url domain is in the table
  1044.  */
  1045. UrlClassifierTableDomain.prototype.exists = function(url, callback) {
  1046.   var canonicalized = this.enchashDecrypter_.getCanonicalUrl(url);
  1047.   var urlObj = this.ioService_.newURI(canonicalized, null, null);
  1048.   var host = '';
  1049.   try {
  1050.     host = urlObj.host;
  1051.   } catch (e) { }
  1052.   var hostComponents = host.split(".");
  1053.  
  1054.   // Try to get the path of the URL.  Pseudo urls (like wyciwyg:) throw
  1055.   // errors when trying to convert to an nsIURL so we wrap in a try/catch
  1056.   // block.
  1057.   var path = ""
  1058.   try {
  1059.     urlObj.QueryInterface(Ci.nsIURL);
  1060.     path = urlObj.filePath;
  1061.   } catch (e) { }
  1062.  
  1063.   var pathComponents = path.split("/");
  1064.  
  1065.   // We don't have a good way map from hosts to domains, so we instead try
  1066.   // each possibility. Could probably optimize to start at the second dot?
  1067.   var possible = [];
  1068.   for (var i = 0; i < hostComponents.length - 1; i++) {
  1069.     host = hostComponents.slice(i).join(".");
  1070.     possible.push(host);
  1071.  
  1072.     // The path starts with a "/", so we are interested in the second path
  1073.     // component if it is available
  1074.     if (pathComponents.length >= 2 && pathComponents[1].length > 0) {
  1075.       host = host + "/" + pathComponents[1];
  1076.       possible.push(host);
  1077.     }
  1078.   }
  1079.  
  1080.   // Run the possible domains against the db.
  1081.   (new ExistsMultiQuerier(possible, this.name, callback)).run();
  1082. }
  1083.  
  1084. /////////////////////////////////////////////////////////////////////
  1085. // Enchash table implementation
  1086.  
  1087. function UrlClassifierTableEnchash() {
  1088.   UrlClassifierTable.call(this);
  1089.   this.debugZone = "urlclassifier-table-enchash";
  1090. }
  1091. UrlClassifierTableEnchash.inherits(UrlClassifierTable);
  1092.  
  1093. /**
  1094.  * Look up a URL in an enchashDB.  We try all sub domains (up to MAX_DOTS).
  1095.  */
  1096. UrlClassifierTableEnchash.prototype.exists = function(url, callback) {
  1097.   url = this.enchashDecrypter_.getCanonicalUrl(url);
  1098.   var host = this.enchashDecrypter_.getCanonicalHost(url,
  1099.                                                PROT_EnchashDecrypter.MAX_DOTS);
  1100.  
  1101.   var possible = [];
  1102.   for (var i = 0; i < PROT_EnchashDecrypter.MAX_DOTS + 1; i++) {
  1103.     possible.push(host);
  1104.  
  1105.     var index = host.indexOf(".");
  1106.     if (index == -1)
  1107.       break;
  1108.     host = host.substring(index + 1);
  1109.   }
  1110.   // Run the possible domains against the db.
  1111.   (new EnchashMultiQuerier(possible, this.name, callback, url)).run();
  1112. }
  1113. //@line 46 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-Release/WINNT_5.2_Depend/mozilla/toolkit/components/url-classifier/src/nsUrlClassifierTable.js"
  1114.  
  1115. var modScope = this;
  1116. function Init() {
  1117.   // Pull the library in.
  1118.   var jslib = Cc["@mozilla.org/url-classifier/jslib;1"]
  1119.               .getService().wrappedJSObject;
  1120.   modScope.G_Preferences = jslib.G_Preferences;
  1121.   modScope.G_PreferenceObserver = jslib.G_PreferenceObserver;
  1122.   modScope.G_Debug = jslib.G_Debug;
  1123.   modScope.G_CryptoHasher = jslib.G_CryptoHasher;
  1124.   modScope.G_Base64 = jslib.G_Base64;
  1125.   modScope.BindToObject = jslib.BindToObject;
  1126.  
  1127.   // We only need to call Init once.
  1128.   modScope.Init = function() {};
  1129. }
  1130.  
  1131.  
  1132. function UrlClassifierTableMod() {
  1133.   this.components = {};
  1134.   this.addComponent({
  1135.       cid: "{43399ee0-da0b-46a8-9541-08721265981c}",
  1136.       name: "UrlClassifier Table Url Module",
  1137.       progid: "@mozilla.org/url-classifier/table;1?type=url",
  1138.       factory: new UrlClassifierTableFactory(UrlClassifierTableUrl)
  1139.     });
  1140.   this.addComponent({
  1141.       cid: "{3b5004c6-3fcd-4b12-b311-a4dfbeaf27aa}",
  1142.       name: "UrlClassifier Table Domain Module",
  1143.       progid: "@mozilla.org/url-classifier/table;1?type=domain",
  1144.       factory: new UrlClassifierTableFactory(UrlClassifierTableDomain)
  1145.     });
  1146.   this.addComponent({
  1147.       cid: "{04f15d1d-2db8-4b8e-91d7-82f30308b434}",
  1148.       name: "UrlClassifier Table Enchash Module",
  1149.       progid: "@mozilla.org/url-classifier/table;1?type=enchash",
  1150.       factory: new UrlClassifierTableFactory(UrlClassifierTableEnchash)
  1151.     });
  1152. }
  1153.  
  1154. UrlClassifierTableMod.prototype.addComponent = function(comp) {
  1155.   this.components[comp.cid] = comp;
  1156. };
  1157.  
  1158. UrlClassifierTableMod.prototype.registerSelf = function(compMgr, fileSpec, loc, type) {
  1159.   compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
  1160.   // Register all the components
  1161.   for (var cid in this.components) {
  1162.     var comp = this.components[cid];
  1163.     compMgr.registerFactoryLocation(Components.ID(comp.cid),
  1164.                                     comp.name,
  1165.                                     comp.progid,
  1166.                                     fileSpec,
  1167.                                     loc,
  1168.                                     type);
  1169.   }
  1170. };
  1171.  
  1172. UrlClassifierTableMod.prototype.getClassObject = function(compMgr, cid, iid) {
  1173.   var comp = this.components[cid.toString()];
  1174.  
  1175.   if (!comp)
  1176.     throw Components.results.NS_ERROR_NO_INTERFACE;
  1177.   if (!iid.equals(Ci.nsIFactory))
  1178.     throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  1179.  
  1180.   return comp.factory;
  1181. };
  1182.  
  1183. UrlClassifierTableMod.prototype.canUnload = function(compMgr) {
  1184.   return true;
  1185. };
  1186.  
  1187. /**
  1188.  * Create a factory.
  1189.  * @param ctor Function constructor for the object we're creating.
  1190.  */
  1191. function UrlClassifierTableFactory(ctor) {
  1192.   this.ctor = ctor;
  1193. }
  1194.  
  1195. UrlClassifierTableFactory.prototype.createInstance = function(outer, iid) {
  1196.   if (outer != null)
  1197.     throw Components.results.NS_ERROR_NO_AGGREGATION;
  1198.   Init();
  1199.   return (new this.ctor()).QueryInterface(iid);
  1200. };
  1201.  
  1202. var modInst = new UrlClassifierTableMod();
  1203.  
  1204. function NSGetModule(compMgr, fileSpec) {
  1205.   return modInst;
  1206. }
  1207.