Skip to content

Commit

Permalink
android: parse search bar field in rust
Browse files Browse the repository at this point in the history
Signed-off-by: Gae24 <[email protected]>
  • Loading branch information
Gae24 committed Jun 6, 2024
1 parent f1a50ba commit 31d6d24
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
14 changes: 7 additions & 7 deletions ports/jniapi/src/simpleservo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 31d6d24

Please sign in to comment.