From fd52486ccc98c78a17296435ac1a80a8ff5826d9 Mon Sep 17 00:00:00 2001 From: areteruhiro <108941410+areteruhiro@users.noreply.github.com> Date: Wed, 9 Oct 2024 04:35:37 +0900 Subject: [PATCH] =?UTF-8?q?RedirectWebView=20=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=20(#183)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Syuugo --- .../lime/hooks/RedirectWebView.java | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/github/chipppppppppp/lime/hooks/RedirectWebView.java b/app/src/main/java/io/github/chipppppppppp/lime/hooks/RedirectWebView.java index 789c5d42..1e5974d2 100644 --- a/app/src/main/java/io/github/chipppppppppp/lime/hooks/RedirectWebView.java +++ b/app/src/main/java/io/github/chipppppppppp/lime/hooks/RedirectWebView.java @@ -5,9 +5,11 @@ import android.net.Uri; import android.support.customtabs.CustomTabsIntent; import android.view.View; +import android.view.ViewGroup; import android.webkit.WebView; import de.robv.android.xposed.XC_MethodHook; +import de.robv.android.xposed.XposedBridge; import de.robv.android.xposed.XposedHelpers; import de.robv.android.xposed.callbacks.XC_LoadPackage; import io.github.chipppppppppp.lime.LimeOptions; @@ -24,24 +26,47 @@ public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPa @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Activity activity = (Activity) param.thisObject; - int webViewResId = activity.getResources().getIdentifier("iab_webview", "id", activity.getPackageName()); - WebView webView = (WebView) activity.findViewById(webViewResId); - webView.setVisibility(View.GONE); - webView.stopLoading(); - Uri uri = Uri.parse(webView.getUrl()); - if (limeOptions.openInBrowser.checked) { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(uri); - activity.startActivity(intent); - } else { - CustomTabsIntent tabsIntent = new CustomTabsIntent.Builder() - .setShowTitle(true) - .build(); - tabsIntent.launchUrl(activity, uri); + View rootView = activity.getWindow().getDecorView().getRootView(); + WebView webView = findWebView(rootView); + + if (webView != null) { + webView.setVisibility(View.GONE); + webView.stopLoading(); + + Uri uri = Uri.parse(webView.getUrl()); + + if (limeOptions.openInBrowser.checked) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(uri); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.startActivity(intent); + } else { + CustomTabsIntent tabsIntent = new CustomTabsIntent.Builder() + .setShowTitle(true) + .build(); + tabsIntent.launchUrl(activity, uri); + } + + activity.finish(); + } - activity.finish(); } } ); } + + private WebView findWebView(View view) { + if (view instanceof WebView) { + return (WebView) view; + } else if (view instanceof ViewGroup) { + ViewGroup group = (ViewGroup) view; + for (int i = 0; i < group.getChildCount(); i++) { + WebView result = findWebView(group.getChildAt(i)); + if (result != null) { + return result; + } + } + } + return null; + } }