mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Android: fix url resolution (#32422)
* fix localhost Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * android: parse search bar field in rust Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * Update comment to reflect new function behavior --------- Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
6f414df867
commit
e6ea4a9c29
3 changed files with 29 additions and 27 deletions
|
@ -30,6 +30,7 @@ use servo::embedder_traits::{
|
||||||
};
|
};
|
||||||
use servo::euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
|
use servo::euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
|
||||||
use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
|
use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
|
||||||
|
use servo::net_traits::pub_domains::is_reg_domain;
|
||||||
pub use servo::script_traits::{MediaSessionActionType, MouseButton};
|
pub use servo::script_traits::{MediaSessionActionType, MouseButton};
|
||||||
use servo::script_traits::{TouchEventType, TouchId, TraversalDirection};
|
use servo::script_traits::{TouchEventType, TouchId, TraversalDirection};
|
||||||
use servo::servo_config::{opts, pref};
|
use servo::servo_config::{opts, pref};
|
||||||
|
@ -378,10 +379,19 @@ impl ServoGlue {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load an URL. This needs to be a valid url.
|
/// Load an URL. If this is not a valid URL, try to "fix" it by adding a scheme or if all else fails,
|
||||||
pub fn load_uri(&mut self, url: &str) -> Result<(), &'static str> {
|
/// interpret the string as a search term.
|
||||||
info!("load_uri: {}", url);
|
pub fn load_uri(&mut self, request: &str) -> Result<(), &'static str> {
|
||||||
ServoUrl::parse(url)
|
info!("load_uri: {}", request);
|
||||||
|
ServoUrl::parse(request)
|
||||||
|
.or_else(|_| {
|
||||||
|
if request.contains('/') || is_reg_domain(request) {
|
||||||
|
ServoUrl::parse(&format!("https://{}", request))
|
||||||
|
} else {
|
||||||
|
let search_url = pref!(shell.searchpage).replace("%s", request);
|
||||||
|
ServoUrl::parse(&search_url)
|
||||||
|
}
|
||||||
|
})
|
||||||
.map_err(|_| "Can't parse URL")
|
.map_err(|_| "Can't parse URL")
|
||||||
.and_then(|url| {
|
.and_then(|url| {
|
||||||
let browser_id = self.get_browser_id()?;
|
let browser_id = self.get_browser_id()?;
|
||||||
|
|
|
@ -17,7 +17,6 @@ import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.webkit.URLUtil;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
@ -79,7 +78,7 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
mServoView.setServoArgs(args, log);
|
mServoView.setServoArgs(args, log);
|
||||||
|
|
||||||
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||||
mServoView.loadUri(intent.getData());
|
mServoView.loadUri(intent.getData().toString());
|
||||||
}
|
}
|
||||||
setupUrlField();
|
setupUrlField();
|
||||||
}
|
}
|
||||||
|
@ -102,8 +101,9 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
mUrlField.setOnFocusChangeListener((v, hasFocus) -> {
|
mUrlField.setOnFocusChangeListener((v, hasFocus) -> {
|
||||||
if(v.getId() == R.id.urlfield && !hasFocus) {
|
if (v.getId() == R.id.urlfield && !hasFocus) {
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm =
|
||||||
|
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||||
}
|
}
|
||||||
|
@ -113,41 +113,33 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
private void loadUrlFromField() {
|
private void loadUrlFromField() {
|
||||||
String text = mUrlField.getText().toString();
|
String text = mUrlField.getText().toString();
|
||||||
text = text.trim();
|
text = text.trim();
|
||||||
String uri;
|
|
||||||
|
|
||||||
if (text.contains(" ") || !text.contains(".")) {
|
mServoView.loadUri(text);
|
||||||
uri = URLUtil.composeSearchUrl(text, "https://duckduckgo.com/html/?q=%s", "%s");
|
|
||||||
} else {
|
|
||||||
uri = URLUtil.guessUrl(text);
|
|
||||||
|
|
||||||
if (uri.startsWith("http://") && !text.startsWith("http://")) {
|
|
||||||
uri = uri.replaceFirst("http://", "https://");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mServoView.loadUri(Uri.parse(uri));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// From activity_main.xml:
|
// From activity_main.xml:
|
||||||
public void onReloadClicked(View v) {
|
public void onReloadClicked(View v) {
|
||||||
mServoView.reload();
|
mServoView.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBackClicked(View v) {
|
public void onBackClicked(View v) {
|
||||||
mServoView.goBack();
|
mServoView.goBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onForwardClicked(View v) {
|
public void onForwardClicked(View v) {
|
||||||
mServoView.goForward();
|
mServoView.goForward();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStopClicked(View v) {
|
public void onStopClicked(View v) {
|
||||||
mServoView.stop();
|
mServoView.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAlert(String message) {
|
public void onAlert(String message) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setMessage(message);
|
builder.setMessage(message);
|
||||||
AlertDialog alert = builder.create();
|
AlertDialog alert = builder.create();
|
||||||
alert.show();
|
alert.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -211,11 +211,11 @@ public class ServoView extends SurfaceView
|
||||||
mServo.stop();
|
mServo.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadUri(Uri uri) {
|
public void loadUri(String uri) {
|
||||||
if (mServo != null) {
|
if (mServo != null) {
|
||||||
mServo.loadUri(uri.toString());
|
mServo.loadUri(uri);
|
||||||
} else {
|
} else {
|
||||||
mInitialUri = uri.toString();
|
mInitialUri = uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue