Skip to content

Commit 04138a0

Browse files
committed
Fix support for Kiwi browser
1. Fix finding field mId of TabImpl 2. Fix finding method createAppMenuPropertiesDelegate 2. Fix finding method prepareMenu However, it seems that Developer Options menu is removed from the browser
1 parent eff3c14 commit 04138a0

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

app/src/main/java/org/matrix/chromext/hook/PageMenu.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.matrix.chromext.hook
22

33
import android.content.Context
4+
import android.os.Bundle
45
import android.os.Handler
56
import android.util.DisplayMetrics
67
import android.view.Menu
@@ -104,6 +105,10 @@ object PageMenuHook : BaseHook() {
104105
findMethod(proxy.chromeTabbedActivity) {
105106
parameterTypes.size == 0 &&
106107
returnType.declaredMethods.size >= 6 &&
108+
(returnType.declaredMethods.find {
109+
// Bundle getBundleForMenuItem(int itemId);
110+
it.returnType == Bundle::class.java && it.parameterTypes.size == 1
111+
} != null) &&
107112
(returnType.declaredFields.size == 0 ||
108113
returnType.declaredFields.find { it.type == Context::class.java } != null) &&
109114
(returnType.isInterface() || Modifier.isAbstract(returnType.modifiers))
@@ -150,7 +155,8 @@ object PageMenuHook : BaseHook() {
150155
findMethod(appMenuPropertiesDelegateImpl, true) {
151156
parameterTypes.size == 2 &&
152157
parameterTypes.first() == Menu::class.java &&
153-
returnType == Void.TYPE
158+
returnType == Void.TYPE &&
159+
!Modifier.isStatic(modifiers)
154160
}
155161
// public void prepareMenu(Menu menu, AppMenuHandler handler)
156162
.hookAfter inflate@{

app/src/main/java/org/matrix/chromext/proxy/UserScript.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.matrix.chromext.proxy
22

33
import android.net.Uri
4+
import android.view.ContextThemeWrapper
45
import org.matrix.chromext.Chrome
56
import org.matrix.chromext.script.ScriptDbManager
67
import org.matrix.chromext.utils.Log
@@ -51,8 +52,14 @@ object UserScriptProxy {
5152
val target = find { it.name == "mId" }
5253
if (target == null) {
5354
val profile = Chrome.load("org.chromium.chrome.browser.profiles.Profile")
54-
val startIndex = indexOfFirst { it.type == gURL }
55-
val endIndex = indexOfFirst { it.type == profile }
55+
val windowAndroid = Chrome.load("org.chromium.ui.base.WindowAndroid")
56+
var startIndex = indexOfFirst { it.type == gURL }
57+
if (startIndex == -1) startIndex = 0
58+
val endIndex = indexOfFirst {
59+
it.type == profile ||
60+
it.type == ContextThemeWrapper::class.java ||
61+
it.type == windowAndroid
62+
}
5663
slice(startIndex..endIndex).findLast { it.type == Int::class.java }!!
5764
} else target
5865
}

0 commit comments

Comments
 (0)