@@ -355,15 +355,29 @@ HTTPSEverywhere.prototype = {
355355 . getInterface ( Ci . nsIDOMWindow ) ;
356356 // this is the gBrowser object of the firefox window this tab is in
357357 var gBrowser = aDOMWindow . gBrowser ;
358- // this is the clickable tab xul element, the one found in the tab strip
359- // of the firefox window, aTab.linkedBrowser is same as browser var above
360- var aTab = gBrowser . _getTabForContentWindow ( contentWindow . top ) ;
361- // this is the browser within the tab
362- if ( aTab ) {
363- var browser = aTab . linkedBrowser ;
364- return browser ;
358+ // On Firefox for Android, gBrowser is not available. Instead use the
359+ // BrowserApp API:
360+ // https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/BrowserApp
361+ if ( gBrowser ) {
362+ var aTab = gBrowser . _getTabForContentWindow ( contentWindow . top ) ;
363+ // this is the clickable tab xul element, the one found in the tab strip
364+ // of the firefox window, aTab.linkedBrowser is same as browser var above
365+ // this is the browser within the tab
366+ if ( aTab ) {
367+ var browser = aTab . linkedBrowser ;
368+ return browser ;
369+ } else {
370+ this . log ( NOTE , "getBrowserForChannel: aTab was null." ) ;
371+ }
365372 } else {
366- this . log ( NOTE , "getBrowserForChannel: aTab was null." ) ;
373+ // This code gets called on Android.
374+ var mTab = aDOMWindow . BrowserApp . getTabForWindow ( contentWindow . top ) ;
375+ if ( mTab ) {
376+ var browser = mTab . browser ;
377+ return browser ;
378+ } else {
379+ this . log ( NOTE , "getBrowserForChannel: mTab was null" ) ;
380+ }
367381 }
368382 } else {
369383 this . log ( NOTE , "getBrowserForChannel: No loadContext for: " +
0 commit comments