servo: Merge #20182 - Prompt URL on Cmd/Ctrl-L (from paulrouget:ctrl_l); r=jdm

<!-- Please describe your changes on the following line: -->

The `sanitize_url` code is very naive. I'm sure we can do better.
This ServoShell issue describes the problem: https://github.com/paulrouget/servoshell/issues/59

I can fix that now if someone can help me figure out how to tell if a string is a valid url which is just missing a scheme. Or we can do that in a follow up.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #20165

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: ec3aa8bd7a985b26f894a73f9b84fc53a005d453

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 7c313a0358fb1b5923cad0221afdfae11ba11b03
This commit is contained in:
Paul Rouget 2018-03-04 12:48:30 -05:00
Родитель 9137f16912
Коммит fdb8f25cb4
8 изменённых файлов: 46 добавлений и 8 удалений

11
servo/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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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]

Просмотреть файл

@ -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<char> {
None
}
}
fn sanitize_url(request: &str) -> Option<ServoUrl> {
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()
})
})
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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
}