@@ -5,6 +5,7 @@ const Cr = Components.results;
55const CI = Components . interfaces ;
66const CC = Components . classes ;
77const CR = Components . results ;
8+ const CU = Components . utils ;
89
910// Log levels
1011VERB = 1 ;
@@ -71,6 +72,10 @@ function SSLObservatory() {
7172 this . torbutton_installed = false ;
7273 }
7374
75+ this . HTTPSEverywhere = CC [ "@eff.org/https-everywhere;1" ]
76+ . getService ( Components . interfaces . nsISupports )
77+ . wrappedJSObject ;
78+
7479 /* The proxy test result starts out null until the test is attempted.
7580 * This is for UI notification purposes */
7681 this . proxy_test_successful = null ;
@@ -318,7 +323,8 @@ SSLObservatory.prototype = {
318323
319324 if ( "http-on-examine-response" == topic ) {
320325
321- if ( ! this . observatoryActive ( ) ) return ;
326+ var channel = subject ;
327+ if ( ! this . observatoryActive ( channel ) ) return ;
322328
323329 var host_ip = "-1" ;
324330 var httpchannelinternal = subject . QueryInterface ( Ci . nsIHttpChannelInternal ) ;
@@ -364,7 +370,7 @@ SSLObservatory.prototype = {
364370 }
365371 } ,
366372
367- observatoryActive : function ( ) {
373+ observatoryActive : function ( channel ) {
368374
369375 if ( ! this . myGetBoolPref ( "enabled" ) )
370376 return false ;
@@ -390,12 +396,30 @@ SSLObservatory.prototype = {
390396 // submit certs without strong anonymisation. Because the
391397 // anonymisation is weak, we avoid submitting during private browsing
392398 // mode.
399+ return ( ! this . inPrivateBrowsingMode ( channel ) ) ;
400+ }
401+
402+ return false ;
403+ } ,
404+
405+ inPrivateBrowsingMode : function ( channel ) {
406+ // In classic firefox fashion, there are multiple versions of this API
407+ // https://developer.mozilla.org/EN/docs/Supporting_per-window_private_browsing
408+ try {
409+ // Firefox 20+, this state is per-window
410+ if ( ! ( channel instanceof CI . nsIHttpChannel ) ) {
411+ this . log ( WARN , "observatoryActive() without a channel" ) ;
412+ throw "no window for private browsing detection, trying the old way" ;
413+ }
414+ var win = this . HTTPSEverywhere . getWindowForChannel ( channel ) ;
415+ CU . import ( "resource://gre/modules/PrivateBrowsingUtils.jsm" ) ;
416+ if ( PrivateBrowsingUtils . isWindowPrivate ( win ) ) return true ;
417+ } catch ( e ) {
418+ // Firefox < 20, this state is global
393419 try {
394420 var pbs = CC [ "@mozilla.org/privatebrowsing;1" ] . getService ( CI . nsIPrivateBrowsingService ) ;
395- if ( pbs . privateBrowsingEnabled ) return false ;
421+ if ( pbs . privateBrowsingEnabled ) return true ;
396422 } catch ( e ) { /* seamonkey or old firefox */ }
397-
398- return true ;
399423 }
400424
401425 return false ;
@@ -608,10 +632,7 @@ SSLObservatory.prototype = {
608632
609633 var that = this ; // We have neither SSLObservatory nor this in scope in the lambda
610634
611- var HTTPSEverywhere = CC [ "@eff.org/https-everywhere;1" ]
612- . getService ( Components . interfaces . nsISupports )
613- . wrappedJSObject ;
614- var win = channel ? HTTPSEverywhere . getWindowForChannel ( channel ) : null ;
635+ var win = channel ? this . HTTPSEverywhere . getWindowForChannel ( channel ) : null ;
615636 var req = this . buildRequest ( params ) ;
616637 req . timeout = TIMEOUT ;
617638
0 commit comments