22
33// rhill 2013-11-09: Weird... This code is executed from HTTP Switchboard
44// context first time extension is launched. Avoid this.
5- if ( window . location . href . match ( / ^ h t t p s ? : \/ \/ / ) ) {
5+ if ( / ^ h t t p s ? : \/ \/ . / . test ( window . location . href ) ) {
66
77/******************************************************************************/
88
9+ function localStorageHandler ( mustRemove ) {
10+ if ( mustRemove ) {
11+ window . localStorage . clear ( ) ;
12+ // console.debug('HTTP Switchboard > found and removed non-empty localStorage');
13+ }
14+ }
15+
16+ /*----------------------------------------------------------------------------*/
17+
918// This is to take care of
1019// https://code.google.com/p/chromium/issues/detail?id=232410
1120// We look up noscript tags and force the DOM parser to parse
1221// them.
13- ( function ( ) {
22+ function fixNoscriptTags ( ) {
1423 var a = document . querySelectorAll ( 'noscript' ) ;
1524 var i = a . length ;
1625 var html ;
@@ -20,17 +29,13 @@ if ( window.location.href.match(/^https?:\/\//) ) {
2029 html = html . replace ( / & g t ; / g, '>' ) ;
2130 a [ i ] . innerHTML = html ;
2231 }
23- } ) ( ) ;
32+ }
2433
25- // Can extension remove localStorage of pages (like when cookies for
26- // page are blacklisted)? Need to investigate. (Well at least when
27- // scripts are blocked, localStorage won't happen..)
34+ /*----------------------------------------------------------------------------*/
2835
29- // This must be last, so that result is returned to extension.
30- // This is used so that inline script tags and preemptively blocked scripts
31- // (which won't generate web requests) are logged in the stats.
32- ( function ( ) {
36+ function collectExternalResources ( ) {
3337 var r = {
38+ refCounter : 0 ,
3439 pageUrl : window . location . href ,
3540 scriptSources : { } , // to avoid duplicates
3641 pluginSources : { } , // to avoid duplicates
@@ -50,6 +55,7 @@ if ( window.location.href.match(/^https?:\/\//) ) {
5055 r . scriptSources [ elem . src . trim ( ) ] = true ;
5156 }
5257 }
58+
5359 // https://github.com/gorhill/httpswitchboard/issues/25
5460 elems = document . querySelectorAll ( 'object' ) ;
5561 i = elems . length ;
@@ -59,6 +65,7 @@ if ( window.location.href.match(/^https?:\/\//) ) {
5965 r . pluginSources [ elem . data . trim ( ) ] = true ;
6066 }
6167 }
68+
6269 // https://github.com/gorhill/httpswitchboard/issues/25
6370 elems = document . querySelectorAll ( 'embed' ) ;
6471 i = elems . length ;
@@ -68,25 +75,23 @@ if ( window.location.href.match(/^https?:\/\//) ) {
6875 r . pluginSources [ elem . src . trim ( ) ] = true ;
6976 }
7077 }
78+
7179 // Check for non-empty localStorage
7280 if ( window . localStorage && window . localStorage . length ) {
7381 r . localStorage = true ;
7482 chrome . runtime . sendMessage ( {
75- what : 'contentHasLocalStorage ' ,
83+ what : 'contentScriptHasLocalStorage ' ,
7684 url : r . pageUrl
77- } , function ( mustRemove ) {
78- if ( mustRemove ) {
79- window . localStorage . clear ( ) ;
80- // console.debug('HTTP Switchboard > found and removed non-empty localStorage');
81- }
82- } ) ;
85+ } , localStorageHandler ) ;
8386 }
87+
8488 // TODO: indexedDB
8589 if ( window . indexedDB && ! ! window . indexedDB . webkitGetDatabaseNames ) {
8690 // var db = window.indexedDB.webkitGetDatabaseNames().onsuccess = function(sender) {
8791 // console.debug('webkitGetDatabaseNames(): result=%o', sender.target.result);
8892 // };
8993 }
94+
9095 // TODO: Web SQL
9196 if ( window . openDatabase ) {
9297 // Sad:
@@ -95,8 +100,20 @@ if ( window.location.href.match(/^https?:\/\//) ) {
95100 }
96101
97102 // Important!!
98- return r ;
99- } ) ( ) ;
103+ chrome . runtime . sendMessage ( {
104+ what : 'contentScriptSummary' ,
105+ details : r
106+ } ) ;
107+ }
108+
109+ /*----------------------------------------------------------------------------*/
110+
111+ function loadHandler ( ) {
112+ fixNoscriptTags ( ) ;
113+ collectExternalResources ( ) ;
114+ }
115+
116+ window . addEventListener ( 'load' , loadHandler ) ;
100117
101118/******************************************************************************/
102119
0 commit comments