@@ -82,19 +82,22 @@ httpsEverywhere.toolbarButton = {
8282 false
8383 ) ;
8484
85- // hook event for when page loads
86- var onPageLoad = function ( ) {
87- // Timeout is used for a number of reasons.
88- // 1) For Performance since we want to defer computation.
89- // 2) Sometimes the page is loaded before all applied rulesets are
90- // calculated; in such a case, a half-second wait works.
91- setTimeout ( tb . updateRulesetsApplied , 500 ) ;
85+ // add listener for top-level location change across all tabs
86+ let httpseProgressListener = {
87+ onLocationChange : function ( aBrowser , aWebProgress , aReq , aLoc ) {
88+ HTTPSEverywhere . log ( DBUG , "Got on location change!" ) ;
89+ HTTPSEverywhere . onLocationChange ( aBrowser ) ;
90+ } ,
91+ onStateChange : function ( aBrowser , aWebProgress , aReq , aFlags , aStatus ) {
92+ if ( ( gBrowser . selectedBrowser === aBrowser ) &&
93+ ( aFlags & CI . nsIWebProgressListener . STATE_STOP ) &&
94+ aWebProgress . isTopLevel ) {
95+ HTTPSEverywhere . log ( DBUG , "Got on state change" ) ;
96+ tb . updateRulesetsApplied ( ) ;
97+ }
98+ }
9299 } ;
93-
94- var appcontent = document . getElementById ( 'appcontent' ) ;
95- if ( appcontent ) {
96- appcontent . addEventListener ( 'load' , onPageLoad , true ) ;
97- }
100+ gBrowser . addTabsProgressListener ( httpseProgressListener ) ;
98101
99102 // decide whether to show toolbar hint
100103 let hintPref = "extensions.https_everywhere.toolbar_hint_shown" ;
@@ -145,8 +148,8 @@ httpsEverywhere.toolbarButton = {
145148 return ;
146149 }
147150
148- var domWin = content . document . defaultView . top ;
149- var alist = HTTPSEverywhere . getExpando ( domWin , "applicable_rules" , null ) ;
151+ var browser = window . gBrowser . selectedBrowser ;
152+ var alist = HTTPSEverywhere . getExpando ( browser , "applicable_rules" ) ;
150153 if ( ! alist ) {
151154 return ;
152155 }
@@ -270,20 +273,20 @@ function stitch_context_menu2() {
270273var rulesetTestsMenuItem = null ;
271274
272275function show_applicable_list ( menupopup ) {
273- var domWin = content . document . defaultView . top ;
274- if ( ! ( domWin instanceof CI . nsIDOMWindow ) ) {
275- alert ( domWin + " is not an nsIDOMWindow ") ;
276- return null ;
276+ var browser = gBrowser . selectedBrowser ;
277+ if ( ! browser ) {
278+ HTTPSEverywhere . log ( WARN , "No browser for applicable list ") ;
279+ return ;
277280 }
278281
279- var alist = HTTPSEverywhere . getExpando ( domWin , "applicable_rules" , null ) ;
282+ var alist = HTTPSEverywhere . getExpando ( browser , "applicable_rules" ) ;
280283 var weird = false ;
281-
284+
282285 if ( ! alist ) {
283286 // This case occurs for error pages and similar. We need a dummy alist
284287 // because populate_menu lives in there. Would be good to refactor this
285288 // away.
286- alist = new HTTPSEverywhere . ApplicableList ( HTTPSEverywhere . log , document , domWin ) ;
289+ alist = new HTTPSEverywhere . ApplicableList ( HTTPSEverywhere . log , browser . currentURI ) ;
287290 weird = true ;
288291 }
289292 alist . populate_menu ( document , menupopup , weird ) ;
@@ -303,38 +306,16 @@ function show_applicable_list(menupopup) {
303306 if ( ! menupopup . contains ( rulesetTestsMenuItem ) )
304307 menupopup . appendChild ( rulesetTestsMenuItem ) ;
305308 }
306-
307309}
308310
309311function toggle_rule ( rule_id ) {
310312 // toggle the rule state
311313 HTTPSEverywhere . https_rules . rulesetsByID [ rule_id ] . toggle ( ) ;
312- var domWin = content . document . defaultView . top ;
313- /*if (domWin instanceof CI.nsIDOMWindow) {
314- var alist = HTTPSEverywhere.getExpando(domWin,"applicable_rules", null);
315- if (alist) alist.empty();
316- }*/
317314 reload_window ( ) ;
318315}
319316
320317function reload_window ( ) {
321- var domWin = content . document . defaultView . top ;
322- if ( ! ( domWin instanceof CI . nsIDOMWindow ) ) {
323- HTTPSEverywhere . log ( WARN , domWin + " is not an nsIDOMWindow" ) ;
324- return null ;
325- }
326- try {
327- var webNav = domWin . QueryInterface ( CI . nsIInterfaceRequestor )
328- . getInterface ( CI . nsIWebNavigation )
329- . QueryInterface ( CI . nsIDocShell ) ;
330- } catch ( e ) {
331- HTTPSEverywhere . log ( WARN , "failed to get webNav" ) ;
332- return null ;
333- }
334- // The choice of LOAD_FLAGS_CHARSET_CHANGE comes from NoScript's quickReload
335- // function; not sure if it's optimal
336- let flags = webNav . LOAD_FLAGS_BYPASS_CACHE & webNav . LOAD_FLAGS_CHARSET_CHANGE ;
337- webNav . reload ( flags ) ;
318+ gBrowser . reloadTab ( gBrowser . selectedTab ) ;
338319}
339320
340321function toggleEnabledState ( ) {
@@ -402,4 +383,3 @@ function migratePreferences() {
402383 HTTPSEverywhere . prefs . setIntPref ( "prefs_version" , prefs_version + 1 ) ;
403384 }
404385}
405-
0 commit comments