@@ -276,7 +276,7 @@ function initMatrixStats() {
276276 // collect all hostnames and ancestors from net traffic
277277 var background = getBackgroundPage ( ) ;
278278 var pageUrl = pageStats . pageUrl ;
279- var url , hostname , reqType , root , parent , reqKey ;
279+ var url , hostname , reqType , nodes , node , reqKey ;
280280 var reqKeys = Object . keys ( pageStats . requests ) ;
281281 var iReqKeys = reqKeys . length ;
282282
@@ -285,25 +285,31 @@ function initMatrixStats() {
285285 while ( iReqKeys -- ) {
286286 reqKey = reqKeys [ iReqKeys ] ;
287287 url = background . urlFromReqKey ( reqKey ) ;
288- hostname = background . getHostnameFromURL ( url ) ;
288+ hostname = background . uriTools . hostnameFromURI ( url ) ;
289+
289290 // rhill 2013-10-23: hostname can be empty if the request is a data url
290291 // https://github.com/gorhill/httpswitchboard/issues/26
291292 if ( hostname === '' ) {
292- hostname = background . getHostnameFromURL ( pageUrl ) ;
293+ hostname = background . uriTools . hostnameFromURI ( pageUrl ) ;
293294 }
294295 reqType = background . typeFromReqKey ( reqKey ) ;
296+
295297 // we want a row for self and ancestors
296- parent = hostname ;
297- while ( parent ) {
298- root = parent ;
299- if ( ! matrixStats [ parent ] ) {
300- matrixStats [ parent ] = HostnameStats . prototype . factory ( parent ) ;
298+ nodes = background . uriTools . allHostnamesFromHostname ( hostname ) ;
299+
300+ while ( true ) {
301+ node = nodes . shift ( ) ;
302+ if ( ! node ) {
303+ break ;
304+ }
305+ if ( ! matrixStats [ node ] ) {
306+ matrixStats [ node ] = HostnameStats . prototype . factory ( node ) ;
301307 }
302- parent = background . getParentHostnameFromHostname ( parent ) ;
303308 }
304309 matrixStats [ hostname ] . types [ reqType ] . count += 1 ;
305310 // https://github.com/gorhill/httpswitchboard/issues/12
306311 // Count requests for whole row.
312+
307313 matrixStats [ hostname ] . types [ '*' ] . count += 1 ;
308314 // meta row for domain, only:
309315 // - there are subdomains
@@ -358,8 +364,8 @@ function getGroupStats() {
358364 // First, group according to whether at least one node in the domain
359365 // hierarchy is white or blacklisted
360366 var background = getBackgroundPage ( ) ;
361- var pageDomain = background . getDomainFromURL ( HTTPSBPopup . pageURL ) ;
362- var hostname , domain , parent ;
367+ var pageDomain = background . uriTools . domainFromURI ( HTTPSBPopup . pageURL ) ;
368+ var hostname , domain , nodes , node ;
363369 var temporaryColor ;
364370 var dark , group ;
365371 var hostnames = Object . keys ( matrixStats ) ;
@@ -377,17 +383,22 @@ function getGroupStats() {
377383 }
378384 // Walk upward the chain of hostname and find at least one which
379385 // is expressly whitelisted or blacklisted.
380- parent = hostname ;
381- while ( parent ) {
382- temporaryColor = matrixStats [ parent ] . types [ '*' ] . temporaryColor ;
386+ nodes = background . uriTools . allHostnamesFromHostname ( hostname ) ;
387+ domain = nodes [ nodes . length - 1 ] ;
388+
389+ while ( true ) {
390+ node = nodes . shift ( ) ;
391+ if ( ! node ) {
392+ break ;
393+ }
394+ temporaryColor = matrixStats [ node ] . types [ '*' ] . temporaryColor ;
383395 dark = temporaryColor . charAt ( 1 ) === 'd' ;
384396 if ( dark ) {
385397 break ;
386398 }
387- parent = background . getParentHostnameFromHostname ( parent ) ;
388399 }
389400 // Domain of the page comes first
390- if ( background . getDomainFromHostname ( hostname ) === pageDomain ) {
401+ if ( domain === pageDomain ) {
391402 group = 0 ;
392403 }
393404 // Whitelisted hostnames are second, blacklisted are fourth
@@ -397,7 +408,6 @@ function getGroupStats() {
397408 } else {
398409 group = 2 ;
399410 }
400- domain = background . getDomainFromHostname ( hostname ) ;
401411 if ( ! groups [ group ] [ domain ] ) {
402412 groups [ group ] [ domain ] = { all : { } , withRules : { } } ;
403413 }
@@ -410,6 +420,7 @@ function getGroupStats() {
410420 // which are not explicitly part of the web page.
411421 var iGroup = groups . length ;
412422 var domains , iDomain ;
423+ var nodes ;
413424 while ( iGroup -- ) {
414425 group = groups [ iGroup ] ;
415426 domains = Object . keys ( group ) ;
@@ -419,10 +430,13 @@ function getGroupStats() {
419430 hostnames = Object . keys ( group [ domain ] . withRules ) ;
420431 iHostname = hostnames . length ;
421432 while ( iHostname -- ) {
422- hostname = hostnames [ iHostname ] ;
423- while ( hostname ) {
424- group [ domain ] . all [ hostname ] = group [ domain ] . withRules [ hostname ] ;
425- hostname = background . getParentHostnameFromHostname ( hostname ) ;
433+ nodes = background . uriTools . allHostnamesFromHostname ( hostnames [ iHostname ] ) ;
434+ while ( true ) {
435+ node = nodes . shift ( ) ;
436+ if ( ! node ) {
437+ break ;
438+ }
439+ group [ domain ] . all [ node ] = group [ domain ] . withRules [ node ] ;
426440 }
427441 }
428442 }
@@ -717,22 +731,22 @@ function renderMatrixCellDomain(cell, domain) {
717731 $ ( cell ) . prop ( { reqType : '*' , hostname : domain } )
718732 . addClass ( getCellClass ( domain , '*' ) )
719733 . children ( 'b' )
720- . text ( domain ) ;
734+ . text ( punycode . toUnicode ( domain ) ) ;
721735}
722736
723737function renderMatrixCellSubdomain ( cell , domain , subomain ) {
724738 $ ( cell ) . prop ( { reqType : '*' , hostname : subomain } )
725739 . addClass ( getCellClass ( subomain , '*' ) )
726740 . children ( 'b' )
727- . text ( subomain . slice ( 0 , subomain . lastIndexOf ( domain ) - 1 ) + '.' )
728- . after ( domain ) ;
741+ . text ( punycode . toUnicode ( subomain . slice ( 0 , subomain . lastIndexOf ( domain ) - 1 ) ) + '.' )
742+ . after ( punycode . toUnicode ( domain ) ) ;
729743}
730744
731745function renderMatrixMetaCellDomain ( cell , domain ) {
732746 $ ( cell ) . prop ( { reqType : '*' , hostname : domain } )
733747 . addClass ( getCellClass ( domain , '*' ) )
734748 . children ( 'b' )
735- . text ( domain )
749+ . text ( punycode . toUnicode ( domain ) )
736750 . before ( '\u2217.' ) ;
737751}
738752
0 commit comments