Skip to content

Commit

Permalink
Fix support for Kiwi browser
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JingMatrix committed Mar 21, 2024
1 parent eff3c14 commit 04138a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/src/main/java/org/matrix/chromext/hook/PageMenu.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.matrix.chromext.hook

import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.util.DisplayMetrics
import android.view.Menu
Expand Down Expand Up @@ -104,6 +105,10 @@ object PageMenuHook : BaseHook() {
findMethod(proxy.chromeTabbedActivity) {
parameterTypes.size == 0 &&
returnType.declaredMethods.size >= 6 &&
(returnType.declaredMethods.find {
// Bundle getBundleForMenuItem(int itemId);
it.returnType == Bundle::class.java && it.parameterTypes.size == 1
} != null) &&
(returnType.declaredFields.size == 0 ||
returnType.declaredFields.find { it.type == Context::class.java } != null) &&
(returnType.isInterface() || Modifier.isAbstract(returnType.modifiers))
Expand Down Expand Up @@ -150,7 +155,8 @@ object PageMenuHook : BaseHook() {
findMethod(appMenuPropertiesDelegateImpl, true) {
parameterTypes.size == 2 &&
parameterTypes.first() == Menu::class.java &&
returnType == Void.TYPE
returnType == Void.TYPE &&
!Modifier.isStatic(modifiers)
}
// public void prepareMenu(Menu menu, AppMenuHandler handler)
.hookAfter inflate@{
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/org/matrix/chromext/proxy/UserScript.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.matrix.chromext.proxy

import android.net.Uri
import android.view.ContextThemeWrapper
import org.matrix.chromext.Chrome
import org.matrix.chromext.script.ScriptDbManager
import org.matrix.chromext.utils.Log
Expand Down Expand Up @@ -51,8 +52,14 @@ object UserScriptProxy {
val target = find { it.name == "mId" }
if (target == null) {
val profile = Chrome.load("org.chromium.chrome.browser.profiles.Profile")
val startIndex = indexOfFirst { it.type == gURL }
val endIndex = indexOfFirst { it.type == profile }
val windowAndroid = Chrome.load("org.chromium.ui.base.WindowAndroid")
var startIndex = indexOfFirst { it.type == gURL }
if (startIndex == -1) startIndex = 0
val endIndex = indexOfFirst {
it.type == profile ||
it.type == ContextThemeWrapper::class.java ||
it.type == windowAndroid
}
slice(startIndex..endIndex).findLast { it.type == Int::class.java }!!
} else target
}
Expand Down

0 comments on commit 04138a0

Please sign in to comment.