mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +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::keyboard_types::{Key, KeyState, KeyboardEvent};
|
||||
use servo::net_traits::pub_domains::is_reg_domain;
|
||||
pub use servo::script_traits::{MediaSessionActionType, MouseButton};
|
||||
use servo::script_traits::{TouchEventType, TouchId, TraversalDirection};
|
||||
use servo::servo_config::{opts, pref};
|
||||
|
@ -378,10 +379,19 @@ impl ServoGlue {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// 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)
|
||||
/// Load an URL. If this is not a valid URL, try to "fix" it by adding a scheme or if all else fails,
|
||||
/// interpret the string as a search term.
|
||||
pub fn load_uri(&mut self, request: &str) -> Result<(), &'static str> {
|
||||
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")
|
||||
.and_then(|url| {
|
||||
let browser_id = self.get_browser_id()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue