@@ -742,61 +742,126 @@ HTTPSEverywhere.prototype = {
742742 } ,
743743
744744 toggleEnabledState : function ( ) {
745- if ( this . prefs . getBoolPref ( "globalEnabled" ) ) {
746- try {
747- this . obsService . removeObserver ( this , "profile-before-change" ) ;
748- this . obsService . removeObserver ( this , "profile-after-change" ) ;
749- this . obsService . removeObserver ( this , "sessionstore-windows-restored" ) ;
750- OS . removeObserver ( this , "cookie-changed" ) ;
751- OS . removeObserver ( this , "http-on-modify-request" ) ;
752- OS . removeObserver ( this , "http-on-examine-merged-response" ) ;
753- OS . removeObserver ( this , "http-on-examine-response" ) ;
754-
755- var catman = Components . classes [ "@mozilla.org/categorymanager;1" ]
756- . getService ( Components . interfaces . nsICategoryManager ) ;
757- catman . deleteCategoryEntry ( "net-channel-event-sinks" , SERVICE_CTRID , true ) ;
758-
759- var dls = CC [ '@mozilla.org/docloaderservice;1' ]
760- . getService ( CI . nsIWebProgress ) ;
761- dls . removeProgressListener ( this ) ;
762-
763- this . prefs . setBoolPref ( "globalEnabled" , false ) ;
764- }
765- catch ( e ) {
766- this . log ( WARN , "Couldn't remove observers: " + e ) ;
745+ if ( this . prefs . getBoolPref ( "globalEnabled" ) ) {
746+ try {
747+ this . obsService . removeObserver ( this , "profile-before-change" ) ;
748+ this . obsService . removeObserver ( this , "profile-after-change" ) ;
749+ this . obsService . removeObserver ( this , "sessionstore-windows-restored" ) ;
750+ OS . removeObserver ( this , "cookie-changed" ) ;
751+ OS . removeObserver ( this , "http-on-modify-request" ) ;
752+ OS . removeObserver ( this , "http-on-examine-merged-response" ) ;
753+ OS . removeObserver ( this , "http-on-examine-response" ) ;
754+
755+ var catman = CC [ "@mozilla.org/categorymanager;1" ]
756+ . getService ( CI . nsICategoryManager ) ;
757+ catman . deleteCategoryEntry ( "net-channel-event-sinks" ,
758+ SERVICE_CTRID , true ) ;
759+
760+ var dls = CC [ '@mozilla.org/docloaderservice;1' ]
761+ . getService ( CI . nsIWebProgress ) ;
762+ dls . removeProgressListener ( this ) ;
763+
764+ this . prefs . setBoolPref ( "globalEnabled" , false ) ;
765+ } catch ( e ) {
766+ this . log ( WARN , "Couldn't remove observers: " + e ) ;
767+ }
768+ } else {
769+ try {
770+ this . obsService . addObserver ( this , "profile-before-change" , false ) ;
771+ this . obsService . addObserver ( this , "profile-after-change" , false ) ;
772+ this . obsService . addObserver ( this , "sessionstore-windows-restored" , false ) ;
773+ OS . addObserver ( this , "cookie-changed" , false ) ;
774+ OS . addObserver ( this , "http-on-modify-request" , false ) ;
775+ OS . addObserver ( this , "http-on-examine-merged-response" , false ) ;
776+ OS . addObserver ( this , "http-on-examine-response" , false ) ;
777+
778+ var dls = CC [ '@mozilla.org/docloaderservice;1' ]
779+ . getService ( CI . nsIWebProgress ) ;
780+ dls . addProgressListener ( this , CI . nsIWebProgress . NOTIFY_LOCATION ) ;
781+
782+ this . log ( INFO ,
783+ "ChannelReplacement.supported = " + ChannelReplacement . supported ) ;
784+
785+ if ( ! Thread . hostRunning ) {
786+ Thread . hostRunning = true ;
767787 }
788+
789+ var catman = CC [ "@mozilla.org/categorymanager;1" ]
790+ . getService ( CI . nsICategoryManager ) ;
791+ // hook on redirections (non persistent, otherwise crashes on 1.8.x)
792+ catman . addCategoryEntry ( "net-channel-event-sinks" , SERVICE_CTRID ,
793+ SERVICE_CTRID , false , true ) ;
794+
795+ HTTPSRules . init ( ) ;
796+ this . prefs . setBoolPref ( "globalEnabled" , true ) ;
797+ } catch ( e ) {
798+ this . log ( WARN , "Couldn't add observers: " + e ) ;
799+ }
768800 }
769- else {
770- try {
771- this . obsService . addObserver ( this , "profile-before-change" , false ) ;
772- this . obsService . addObserver ( this , "profile-after-change" , false ) ;
773- this . obsService . addObserver ( this , "sessionstore-windows-restored" , false ) ;
774- OS . addObserver ( this , "cookie-changed" , false ) ;
775- OS . addObserver ( this , "http-on-modify-request" , false ) ;
776- OS . addObserver ( this , "http-on-examine-merged-response" , false ) ;
777- OS . addObserver ( this , "http-on-examine-response" , false ) ;
778-
779- var dls = CC [ '@mozilla.org/docloaderservice;1' ]
780- . getService ( CI . nsIWebProgress ) ;
781- dls . addProgressListener ( this , CI . nsIWebProgress . NOTIFY_LOCATION ) ;
782-
783- this . log ( INFO , "ChannelReplacement.supported = " + ChannelReplacement . supported ) ;
801+ } ,
784802
785- if ( ! Thread . hostRunning )
786- Thread . hostRunning = true ;
787-
788- var catman = Components . classes [ "@mozilla.org/categorymanager;1" ]
789- . getService ( Components . interfaces . nsICategoryManager ) ;
790- // hook on redirections (non persistent, otherwise crashes on 1.8.x)
791- catman . addCategoryEntry ( "net-channel-event-sinks" , SERVICE_CTRID ,
792- SERVICE_CTRID , false , true ) ;
793-
794- HTTPSRules . init ( ) ;
795- this . prefs . setBoolPref ( "globalEnabled" , true ) ;
796- }
797- catch ( e ) {
798- this . log ( WARN , "Couldn't add observers: " + e ) ;
799- }
803+ toggleHttpNowhere : function ( ) {
804+ let prefService = Services . prefs ;
805+ let thisBranch =
806+ prefService . getBranch ( "extensions.https_everywhere.http_nowhere." ) ;
807+
808+ // Proxy type. 0: none, 1: manual, 2: autoconfig by URL, 3: same as 0,
809+ // 4: autodetect proxy settings, 5: use system proxy settings (default)
810+ let PROXY_TYPE = "network.proxy.type" ;
811+ // HTTP proxy host
812+ let PROXY_HTTP = "network.proxy.http" ;
813+ // HTTP proxy port
814+ let PROXY_PORT = "network.proxy.http_port" ;
815+
816+ // Whether cert is treated as invalid when OCSP connection fails
817+ let OCSP_REQUIRED = "security.ocsp.require" ;
818+
819+ // Original settings
820+ let ORIG_PROXY_TYPE = "orig.proxy.type" ;
821+ let ORIG_PROXY_HTTP = "orig.proxy.http" ;
822+ let ORIG_PROXY_PORT = "orig.proxy.http_port" ;
823+ let ORIG_OCSP_REQUIRED = "orig.ocsp.required" ;
824+
825+
826+ if ( thisBranch . getBoolPref ( "enabled" ) ) {
827+ // Restore original proxy/OCSP settings. TODO: What if user manually edits
828+ // these while HTTP Nowhere is enabled?
829+ let origProxyType = thisBranch . getIntPref ( ORIG_PROXY_TYPE ) ;
830+ prefService . setIntPref ( PROXY_TYPE , origProxyType ) ;
831+
832+ let origProxyHttp = thisBranch . getCharPref ( ORIG_PROXY_HTTP ) ;
833+ prefService . setCharPref ( PROXY_HTTP , origProxyHttp ) ;
834+
835+ let origProxyPort = thisBranch . getIntPref ( ORIG_PROXY_PORT ) ;
836+ prefService . setIntPref ( PROXY_PORT , origProxyPort ) ;
837+
838+ let origOcspRequired = thisBranch . getBoolPref ( ORIG_OCSP_REQUIRED ) ;
839+ prefService . setBoolPref ( OCSP_REQUIRED , origOcspRequired ) ;
840+
841+ thisBranch . setBoolPref ( "enabled" , false ) ;
842+ } else {
843+ // Save original proxy settings in HTTP Nowhere preferences branch.
844+ let origProxyType = prefService . getIntPref ( PROXY_TYPE ) ;
845+ thisBranch . setIntPref ( ORIG_PROXY_TYPE , origProxyType ) ;
846+
847+ let origProxyHttp = prefService . getCharPref ( PROXY_HTTP ) ;
848+ thisBranch . setCharPref ( ORIG_PROXY_HTTP , origProxyHttp ) ;
849+
850+ let origProxyPort = prefService . getIntPref ( PROXY_PORT ) ;
851+ thisBranch . setIntPref ( ORIG_PROXY_PORT , origProxyPort ) ;
852+
853+ let origOcspRequired = prefService . getBoolPref ( OCSP_REQUIRED ) ;
854+ thisBranch . setBoolPref ( ORIG_OCSP_REQUIRED , origOcspRequired ) ;
855+
856+ // Set a null proxy for HTTP requests
857+ prefService . setIntPref ( PROXY_TYPE , 1 ) ; // manual
858+ prefService . setCharPref ( PROXY_HTTP , "localhost" ) ;
859+ prefService . setIntPref ( PROXY_PORT , 4 ) ; // any arbitrary unused port
860+
861+ // Disable OCSP enforcement
862+ thisBranch . setBoolPref ( OCSP_REQUIRED , false ) ;
863+
864+ thisBranch . setBoolPref ( "enabled" , true ) ;
800865 }
801866 }
802867} ;
0 commit comments