@@ -98,6 +98,10 @@ function SSLObservatory() {
9898 // Used to track current number of pending requests to the server
9999 this . current_outstanding_requests = 0 ;
100100
101+ // We can't always know private browsing state per request, sometimes
102+ // we have to guess based on what we've seen in the past
103+ this . everSeenPrivateBrowsing = false ;
104+
101105 // Generate nonce to append to url, to catch in nsIProtocolProxyFilter
102106 // and to protect against CSRF
103107 this . csrf_nonce = "#" + Math . random ( ) . toString ( ) + Math . random ( ) . toString ( ) ;
@@ -396,29 +400,38 @@ SSLObservatory.prototype = {
396400 // submit certs without strong anonymisation. Because the
397401 // anonymisation is weak, we avoid submitting during private browsing
398402 // mode.
399- return ( ! this . inPrivateBrowsingMode ( channel ) ) ;
403+ var pbm = this . inPrivateBrowsingMode ( channel ) ;
404+ this . log ( NOTE , "Private browsing mode: " + pbm ) ;
405+ return ! pbm ;
400406 }
401-
402- return false ;
403407 } ,
404408
405409 inPrivateBrowsingMode : function ( channel ) {
406410 // In classic firefox fashion, there are multiple versions of this API
407411 // https://developer.mozilla.org/EN/docs/Supporting_per-window_private_browsing
408412 try {
413+ CU . import ( "resource://gre/modules/PrivateBrowsingUtils.jsm" ) ;
409414 // Firefox 20+, this state is per-window
410415 if ( ! ( channel instanceof CI . nsIHttpChannel ) ) {
411416 this . log ( WARN , "observatoryActive() without a channel" ) ;
412- throw "no window for private browsing detection, trying the old way" ;
417+ // This is a windowless request. We cannot tell if private browsing
418+ // applies. Conservatively, if we have ever seen PBM, it might be
419+ // active now
420+ return this . everSeenPrivateBrowsing ;
413421 }
414422 var win = this . HTTPSEverywhere . getWindowForChannel ( channel ) ;
415- CU . import ( "resource://gre/modules/PrivateBrowsingUtils.jsm" ) ;
416- if ( PrivateBrowsingUtils . isWindowPrivate ( win ) ) return true ;
423+ if ( PrivateBrowsingUtils . isWindowPrivate ( win ) ) {
424+ this . everSeenPrivateBrowsing = true ;
425+ return true ;
426+ }
417427 } catch ( e ) {
418428 // Firefox < 20, this state is global
419429 try {
420430 var pbs = CC [ "@mozilla.org/privatebrowsing;1" ] . getService ( CI . nsIPrivateBrowsingService ) ;
421- if ( pbs . privateBrowsingEnabled ) return true ;
431+ if ( pbs . privateBrowsingEnabled ) {
432+ this . everSeenPrivateBrowsing = true ;
433+ return true ;
434+ }
422435 } catch ( e ) { /* seamonkey or old firefox */ }
423436 }
424437
0 commit comments