diff --git a/Cargo.lock b/Cargo.lock index a2f927675a2a..b626b9588f55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2650,6 +2650,7 @@ dependencies = [ "servo_url 0.0.1", "sig 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "style_traits 0.0.1", + "tinyfiledialogs 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "webrender_api 0.57.0 (git+https://github.com/servo/webrender)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/servo/Cargo.toml b/ports/servo/Cargo.toml index 150ebd5fd32e..37ccf82906dc 100644 --- a/ports/servo/Cargo.toml +++ b/ports/servo/Cargo.toml @@ -40,6 +40,7 @@ servo_geometry = {path = "../../components/geometry"} servo_config = {path = "../../components/config"} servo_url = {path = "../../components/url"} style_traits = {path = "../../components/style_traits"} +tinyfiledialogs = "3.0" webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} [target.'cfg(not(target_os = "android"))'.dependencies] diff --git a/ports/servo/glutin_app/window.rs b/ports/servo/glutin_app/window.rs index 88c14873b7d1..ecad83116c65 100644 --- a/ports/servo/glutin_app/window.rs +++ b/ports/servo/glutin_app/window.rs @@ -21,6 +21,7 @@ use glutin::os::macos::{ActivationPolicy, WindowBuilderExt}; use msg::constellation_msg::{self, Key, TopLevelBrowsingContextId as BrowserId}; use msg::constellation_msg::{KeyModifiers, KeyState, TraversalDirection}; use net_traits::net_error_list::NetError; +use net_traits::pub_domains::is_reg_domain; #[cfg(any(target_os = "linux", target_os = "macos"))] use osmesa_sys; use script_traits::{LoadData, TouchEventType}; @@ -43,6 +44,7 @@ use std::time; use style_traits::DevicePixel; use style_traits::cursor::CursorKind; use super::NestedEventLoopListener; +use tinyfiledialogs; #[cfg(target_os = "windows")] use user32; use webrender_api::{DeviceUintRect, DeviceUintSize, ScrollLocation}; @@ -1321,6 +1323,21 @@ impl WindowMethods for Window { self.event_queue.borrow_mut().push(WindowEvent::Reload(browser_id)); } } + (CMD_OR_CONTROL, Some('l'), _) => { + if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() { + let url: String = if let Some(ref url) = *self.current_url.borrow() { + url.to_string() + } else { + String::from("") + }; + let title = "URL or search query"; + if let Some(input) = tinyfiledialogs::input_box(title, title, &url) { + if let Some(url) = sanitize_url(&input) { + self.event_queue.borrow_mut().push(WindowEvent::LoadUrl(browser_id, url)); + } + } + } + } (CMD_OR_CONTROL, Some('q'), _) => { if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() { self.event_queue.borrow_mut().push(WindowEvent::Quit); @@ -1448,3 +1465,20 @@ fn filter_nonprintable(ch: char, key_code: VirtualKeyCode) -> Option { None } } + +fn sanitize_url(request: &str) -> Option { + let request = request.trim(); + ServoUrl::parse(&request).ok() + .or_else(|| { + if request.contains('/') || is_reg_domain(request) { + ServoUrl::parse(&format!("http://{}", request)).ok() + } else { + None + } + }).or_else(|| { + PREFS.get("shell.searchpage").as_string().and_then(|s: &str| { + let url = s.replace("%s", request); + ServoUrl::parse(&url).ok() + }) + }) +} diff --git a/ports/servo/main.rs b/ports/servo/main.rs index 1b34745eee36..f270e000b862 100644 --- a/ports/servo/main.rs +++ b/ports/servo/main.rs @@ -40,6 +40,7 @@ extern crate servo_url; #[macro_use] extern crate sig; extern crate style_traits; +extern crate tinyfiledialogs; extern crate webrender_api; #[cfg(target_os = "windows")] extern crate winapi; #[cfg(target_os = "windows")] extern crate user32; diff --git a/resources/prefs.json b/resources/prefs.json index b94f11e3481a..5d21c38b10a3 100644 --- a/resources/prefs.json +++ b/resources/prefs.json @@ -68,5 +68,6 @@ "shell.keep_screen_on.enabled": false, "shell.native-orientation": "both", "shell.native-titlebar.enabled": true, + "shell.searchpage": "https://duckduckgo.com/html/?q=%s", "webgl.testing.context_creation_error": false }