@@ -134,18 +134,10 @@ function beforeRequestHandler(details) {
134134 return ;
135135 }
136136
137- // Don't block stylesheet requests, these are considered has being parts
138- // of the root frame. If root frame is blocked, stylesheets will never
139- // be requested.
140- var type = details . type ;
141- // if ( type === 'stylesheet' ) {
142- // console.log("HTTPSB > %s @ url=%s", details.type, details.url);
143- // return;
144- // }
145-
146137 // quickProfiler.start();
147138
148139 // If it's a top frame, bind to a new page stats store
140+ var type = details . type ;
149141 var isMainFrame = type === 'main_frame' ;
150142 var isRootFrame = isMainFrame && details . parentFrameId < 0 ;
151143 if ( isRootFrame ) {
@@ -156,11 +148,29 @@ function beforeRequestHandler(details) {
156148 hostname = uriTools . hostnameFromURI ( url ) ;
157149 pageURL = pageUrlFromPageStats ( pageStats ) || '*' ;
158150
151+ // rhill 2013-12-08:
152+ // Better handling of stylesheet requests: if domain of `stylesheet` object
153+ // is same as domain of `main_frame`, the `stylesheet` is evaluated as if
154+ // it is `main_frame` (permissive), else it is evaluated as `other`,
155+ // i.e. an external resources (restrictive).
156+ // This is for privacy reasons: a whole lot of web sites pull their fonts
157+ // from, say, `fonts.googleapis.com`, thus giving Google log data that one
158+ // specific IP address has been visiting one specific website.
159+ // We don't want that.
160+ var typeToEval = type ;
161+ if ( type === 'stylesheet' ) {
162+ if ( uriTools . domainFromHostname ( hostname ) === pageStats . pageDomain ) {
163+ typeToEval = 'main_frame' ;
164+ } else {
165+ typeToEval = 'other' ;
166+ }
167+ }
168+
159169 // Block request?
160170 // https://github.com/gorhill/httpswitchboard/issues/27
161171 var block = false ; // By default, don't block behind-the-scene requests
162172 if ( tabId !== httpsb . behindTheSceneTabId || httpsb . userSettings . processBehindTheSceneRequests ) {
163- block = httpsb . blacklisted ( pageURL , type , hostname ) ;
173+ block = httpsb . blacklisted ( pageURL , typeToEval , hostname ) ;
164174 }
165175
166176 if ( pageStats ) {
@@ -301,18 +311,18 @@ function headersReceivedHandler(details) {
301311 return ;
302312 }
303313
304- // Ignore traffic outside tabs
314+ // rhill 2013-12-08: ALWAYS evaluate for javascript, do not rely too much
315+ // on the top page to be bound to a tab.
316+ // https://github.com/gorhill/httpswitchboard/issues/75
305317 var tabId = details . tabId ;
306- if ( tabId < 0 ) {
307- return ;
308- }
309318
310319 // rhill 2013-12-07:
311320 // Apparently in Opera, onBeforeRequest() is triggered while the
312321 // URL is not yet bound to a tab (-1), which caused the code here
313322 // to not be able to lookup the pageStats. So let the code here bind
314323 // the page to a tab if not done yet.
315- if ( isMainFrame && details . parentFrameId < 0 ) {
324+ // https://github.com/gorhill/httpswitchboard/issues/75
325+ if ( tabId >= 0 && isMainFrame && details . parentFrameId < 0 ) {
316326 bindTabToPageStats ( tabId , uriTools . normalizeURI ( details . url ) ) ;
317327 }
318328
@@ -323,6 +333,7 @@ function headersReceivedHandler(details) {
323333 // Worst case scenario, if no pageURL can be found for this
324334 // request, use global scope to evaluate whether it should be blocked
325335 // or allowed.
336+ // https://github.com/gorhill/httpswitchboard/issues/75
326337 var pageURL = pageStats ? pageUrlFromPageStats ( pageStats ) : '*' ;
327338 var hostname = uriTools . hostnameFromURI ( details . url ) ;
328339
0 commit comments