Skip to content

Commit 31f5ade

Browse files
committed
Fix reference to missing gBrowser on Android.
1 parent de56293 commit 31f5ade

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

makexpi.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ else
167167
echo >&2 "Total included rules: `sqlite3 $RULESETS_SQLITE 'select count(*) from rulesets'`"
168168
echo >&2 "Rules disabled by default: `find chrome/content/rules -name "*.xml" | xargs grep -F default_off | wc -l`"
169169
echo >&2 "Created $XPI_NAME"
170+
../utils/android-push.sh "$XPI_NAME"
170171
if [ -n "$BRANCH" ]; then
171172
cd ../..
172173
cp $SUBDIR/$XPI_NAME pkg

src/chrome/content/code/HTTPSRules.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const Cc = Components.classes;
12
// Compilation of RegExps is now delayed until they are first used...
23

34
function Rule(from, to) {

src/components/https-everywhere.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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: " +

utils/android-push.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -o errexit
3+
4+
cd $(dirname $0)
5+
XPI_NAME=$1
6+
ANDROID_APP_ID=org.mozilla.firefox
7+
if [ -z "$XPI_NAME" ] ; then
8+
echo "No package name given to android-push.sh."
9+
exit 1
10+
fi
11+
12+
# Push to Android Firefox if device is connected
13+
# XXX on some systems, adb may require sudo...
14+
if type adb > /dev/null && adb devices > /dev/null 2>/dev/null ; then
15+
ADB_FOUND=`adb devices | tail -2 | head -1 | cut -f 1 | sed 's/ *$//g'`
16+
if [ "$ADB_FOUND" != "List of devices attached" ]; then
17+
echo Pushing "$XPI_NAME" to /sdcard/"$XPI_NAME"
18+
adb push "../$XPI_NAME" /sdcard/"$XPI_NAME"
19+
adb shell am start -a android.intent.action.VIEW \
20+
-c android.intent.category.DEFAULT \
21+
-d file:///mnt/sdcard/"$XPI_NAME" \
22+
-n $ANDROID_APP_ID/.App
23+
fi
24+
fi
25+
26+

0 commit comments

Comments
 (0)