diff --git a/Cargo.lock b/Cargo.lock index 9155f3484fd..ed4fc72063a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,7 +194,7 @@ dependencies = [ "ipc-channel 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "servo_config 0.0.1", "servo_rand 0.0.1", - "tinyfiledialogs 2.5.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tinyfiledialogs 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1865,7 +1865,7 @@ dependencies = [ "servo_url 0.0.1", "threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "tinyfiledialogs 2.5.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tinyfiledialogs 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2490,7 +2490,7 @@ dependencies = [ "style_traits 0.0.1", "swapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "tinyfiledialogs 2.5.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tinyfiledialogs 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "utf-8 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2674,6 +2674,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)", @@ -3222,7 +3223,7 @@ dependencies = [ [[package]] name = "tinyfiledialogs" -version = "2.5.9" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.47 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3890,7 +3891,7 @@ dependencies = [ "checksum thread_profiler 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5920e77802b177479ab5795767fa48e68f61b2f516c2ac0041e2978dd8efe483" "checksum threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "59f6d3eff89920113dac9db44dde461d71d01e88a5b57b258a0466c32b5d7fe1" "checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3" -"checksum tinyfiledialogs 2.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d401358cd71aca93d5f4fccd3db5b87d970ae70fe457911929d99f4a87f7531" +"checksum tinyfiledialogs 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d92a5f7395a9e2895a2361c3121d4a0be0f8dac3be7d91841a5c1c5291b1c6dc" "checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum truetype 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec30350633d6dac9dc1a625786b6cbe9150664be941aac2c35ad7199eab877" diff --git a/components/bluetooth/Cargo.toml b/components/bluetooth/Cargo.toml index cdb304e785c..3fd11443d8c 100644 --- a/components/bluetooth/Cargo.toml +++ b/components/bluetooth/Cargo.toml @@ -19,4 +19,4 @@ servo_rand = {path = "../rand"} uuid = {version = "0.5", features = ["v4"]} [target.'cfg(target_os = "linux")'.dependencies] -tinyfiledialogs = "2.5.9" +tinyfiledialogs = "3.0" diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index 4329215010a..27807663744 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -44,7 +44,7 @@ uuid = {version = "0.5", features = ["v4"]} webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} [target.'cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))'.dependencies] -tinyfiledialogs = "2.5.9" +tinyfiledialogs = "3.0" [[test]] name = "main" diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index a22553d8a1d..3db7e697011 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -24,7 +24,7 @@ phf_shared = "0.7.18" serde_json = "1.0" [target.'cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))'.dependencies] -tinyfiledialogs = "2.5.9" +tinyfiledialogs = "3.0" [dependencies] app_units = "0.6" diff --git a/ports/servo/Cargo.toml b/ports/servo/Cargo.toml index 150ebd5fd32..37ccf82906d 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 88c14873b7d..ecad83116c6 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 acea44ee220..35a61d9d0fc 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 b94f11e3481..5d21c38b10a 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 }