gorhill 10 years ago
parent
commit
f815223f27
  1. 7
      src/js/uritools.js
  2. 45
      src/lib/publicsuffixlist.js

7
src/js/uritools.js

@ -366,11 +366,18 @@ var domainCachePrune = function() {
} }
}; };
var domainCacheReset = function() {
domainCache = {};
domainCacheCount = 0;
};
var domainCache = {}; var domainCache = {};
var domainCacheCount = 0; var domainCacheCount = 0;
var domainCacheCountLowWaterMark = 75; var domainCacheCountLowWaterMark = 75;
var domainCacheCountHighWaterMark = 100; var domainCacheCountHighWaterMark = 100;
psl.onChanged.addListener(domainCacheReset);
/******************************************************************************/ /******************************************************************************/
URI.domainFromURI = function(uri) { URI.domainFromURI = function(uri) {

45
src/lib/publicsuffixlist.js

@ -33,6 +33,8 @@
;(function(root) { ;(function(root) {
'use strict';
/******************************************************************************/ /******************************************************************************/
var exceptions = {}; var exceptions = {};
@ -45,6 +47,8 @@ var selfieMagic = 'iscjsfsaolnm';
var cutoffLength = 256; var cutoffLength = 256;
var mustPunycode = /[^a-z0-9.-]/; var mustPunycode = /[^a-z0-9.-]/;
var onChangedListeners = [];
/******************************************************************************/ /******************************************************************************/
// In the context of this code, a domain is defined as: // In the context of this code, a domain is defined as:
@ -234,6 +238,8 @@ function parse(text, toAscii) {
} }
crystallize(exceptions); crystallize(exceptions);
crystallize(rules); crystallize(rules);
callListeners(onChangedListeners);
} }
/******************************************************************************/ /******************************************************************************/
@ -302,11 +308,47 @@ function fromSelfie(selfie) {
} }
rules = selfie.rules; rules = selfie.rules;
exceptions = selfie.exceptions; exceptions = selfie.exceptions;
callListeners(onChangedListeners);
return true; return true;
} }
/******************************************************************************/ /******************************************************************************/
var addListener = function(listeners, callback) {
if ( typeof callback !== 'function' ) {
return;
}
if ( listeners.indexOf(callback) === -1 ) {
listeners.push(callback);
}
};
var removeListener = function(listeners, callback) {
var pos = listeners.indexOf(callback);
if ( pos !== -1 ) {
listeners.splice(pos, 1);
}
};
var callListeners = function(listeners) {
for ( var i = 0; i < listeners.length; i++ ) {
listeners[i]();
}
};
/******************************************************************************/
var onChanged = {
addListener: function(callback) {
addListener(onChangedListeners, callback);
},
removeListener: function(callback) {
removeListener(onChangedListeners, callback);
}
};
/******************************************************************************/
// Public API // Public API
root = root || window; root = root || window;
@ -317,7 +359,8 @@ root.publicSuffixList = {
'getDomain': getDomain, 'getDomain': getDomain,
'getPublicSuffix': getPublicSuffix, 'getPublicSuffix': getPublicSuffix,
'toSelfie': toSelfie, 'toSelfie': toSelfie,
'fromSelfie': fromSelfie
'fromSelfie': fromSelfie,
'onChanged': onChanged
}; };
/******************************************************************************/ /******************************************************************************/

Loading…
Cancel
Save