mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
android: Use location_bar_input_to_url instead of re-implementing (#32586)
We can use the same function as the desktop version Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
This commit is contained in:
parent
26bbfe9b55
commit
7d7574373b
2 changed files with 9 additions and 14 deletions
|
@ -371,20 +371,11 @@ impl ServoGlue {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load an URL. If this is not a valid URL, try to "fix" it by adding a scheme or if all else fails,
|
/// Load an URL.
|
||||||
/// interpret the string as a search term.
|
pub fn load_uri(&mut self, url: &str) -> Result<(), &'static str> {
|
||||||
pub fn load_uri(&mut self, request: &str) -> Result<(), &'static str> {
|
info!("load_uri: {}", url);
|
||||||
info!("load_uri: {}", request);
|
crate::parser::location_bar_input_to_url(url)
|
||||||
ServoUrl::parse(request)
|
.ok_or("Can't parse URL")
|
||||||
.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| {
|
.and_then(|url| {
|
||||||
let browser_id = self.get_browser_id()?;
|
let browser_id = self.get_browser_id()?;
|
||||||
let event = EmbedderEvent::LoadUrl(browser_id, url);
|
let event = EmbedderEvent::LoadUrl(browser_id, url);
|
||||||
|
|
|
@ -60,6 +60,10 @@ pub fn get_default_url(
|
||||||
new_url.or(pref_url).or(blank_url).unwrap()
|
new_url.or(pref_url).or(blank_url).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Interpret an input 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 location_bar_input_to_url(request: &str) -> Option<ServoUrl> {
|
pub fn location_bar_input_to_url(request: &str) -> Option<ServoUrl> {
|
||||||
let request = request.trim();
|
let request = request.trim();
|
||||||
ServoUrl::parse(request)
|
ServoUrl::parse(request)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue