From 31d6d2434044930244ac22d413a6f00e8dcdbe4d Mon Sep 17 00:00:00 2001 From: Gae24 <96017547+Gae24@users.noreply.github.com> Date: Thu, 6 Jun 2024 09:45:57 +0200 Subject: [PATCH] android: parse search bar field in rust Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> --- ports/jniapi/src/simpleservo.rs | 14 +++++++------- .../main/java/org/mozilla/servo/MainActivity.java | 15 ++------------- .../java/org/mozilla/servoview/ServoView.java | 6 +++--- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/ports/jniapi/src/simpleservo.rs b/ports/jniapi/src/simpleservo.rs index f895860fa07d7..7b40d37954335 100644 --- a/ports/jniapi/src/simpleservo.rs +++ b/ports/jniapi/src/simpleservo.rs @@ -380,15 +380,15 @@ impl ServoGlue { } /// Load an URL. This needs to be a valid url. - pub fn load_uri(&mut self, url: &str) -> Result<(), &'static str> { - info!("load_uri: {}", url); - ServoUrl::parse(url) + pub fn load_uri(&mut self, request: &str) -> Result<(), &'static str> { + info!("load_uri: {}", request); + ServoUrl::parse(request) .or_else(|_| { - if url.contains('/') || is_reg_domain(url) { - ServoUrl::parse(&format!("https://{}", url)) + if request.contains('/') || is_reg_domain(request) { + ServoUrl::parse(&format!("https://{}", request)) } else { - let url = pref!(shell.searchpage).replace("%s", url); - ServoUrl::parse(&url) + let search_url = pref!(shell.searchpage).replace("%s", request); + ServoUrl::parse(&search_url) } }) .map_err(|_| "Can't parse URL") diff --git a/support/android/apk/servoapp/src/main/java/org/mozilla/servo/MainActivity.java b/support/android/apk/servoapp/src/main/java/org/mozilla/servo/MainActivity.java index 3cbf2cb48a532..13b1985ad5158 100644 --- a/support/android/apk/servoapp/src/main/java/org/mozilla/servo/MainActivity.java +++ b/support/android/apk/servoapp/src/main/java/org/mozilla/servo/MainActivity.java @@ -14,11 +14,9 @@ import android.system.ErrnoException; import android.system.Os; import android.util.Log; -import android.util.Patterns; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; -import android.webkit.URLUtil; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; @@ -80,7 +78,7 @@ protected void onCreate(Bundle savedInstanceState) { mServoView.setServoArgs(args, log); if (Intent.ACTION_VIEW.equals(intent.getAction())) { - mServoView.loadUri(intent.getData()); + mServoView.loadUri(intent.getData().toString()); } setupUrlField(); } @@ -115,17 +113,8 @@ private void setupUrlField() { private void loadUrlFromField() { String text = mUrlField.getText().toString(); text = text.trim(); - String url; -// if (Patterns.WEB_URL.matcher(text).matches()) { -// url = URLUtil.guessUrl(text).replaceFirst("http://", "https://"); -// } else if (text.matches("(http://)?localhost:\\d{1,5}(/.*)?")) { -// url = text.startsWith("http://") ? text : "http://" + text; -// } else { -// url = URLUtil.composeSearchUrl(text, "https://duckduckgo.com/html/?q=%s", "%s"); -// } - - mServoView.loadUri(Uri.parse(text)); + mServoView.loadUri(text); } // From activity_main.xml: diff --git a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoView.java b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoView.java index 1ab99a4375639..b9e6d47e64dc0 100644 --- a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoView.java +++ b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoView.java @@ -211,11 +211,11 @@ public void stop() { mServo.stop(); } - public void loadUri(Uri uri) { + public void loadUri(String uri) { if (mServo != null) { - mServo.loadUri(uri.toString()); + mServo.loadUri(uri); } else { - mInitialUri = uri.toString(); + mInitialUri = uri; } }