aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--components/config/opts.rs24
-rw-r--r--ports/servoshell/Cargo.toml1
-rw-r--r--ports/servoshell/app.rs28
-rw-r--r--ports/servoshell/browser.rs20
-rw-r--r--ports/servoshell/main2.rs12
-rw-r--r--ports/servoshell/parser.rs61
-rw-r--r--ports/servoshell/test.rs (renamed from components/config/tests/opts.rs)2
-rw-r--r--python/servo/testing_commands.py1
9 files changed, 84 insertions, 66 deletions
diff --git a/Cargo.lock b/Cargo.lock
index abad99d6e19..6c67e44b037 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5535,6 +5535,7 @@ dependencies = [
"sig",
"surfman",
"tinyfiledialogs",
+ "url",
"vergen",
"webxr",
"winapi",
diff --git a/components/config/opts.rs b/components/config/opts.rs
index 721f86af5c1..95675c0b9c1 100644
--- a/components/config/opts.rs
+++ b/components/config/opts.rs
@@ -24,9 +24,6 @@ use url::{self, Url};
pub struct Opts {
pub is_running_problem_test: bool,
- /// The initial URL to load.
- pub url: Option<ServoUrl>,
-
/// Whether or not the legacy layout system is enabled.
pub legacy_layout: bool,
@@ -386,7 +383,6 @@ pub fn multiprocess() -> bool {
pub fn default_opts() -> Opts {
Opts {
is_running_problem_test: false,
- url: None,
legacy_layout: false,
tile_size: 512,
time_profiling: None,
@@ -598,15 +594,6 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
url.starts_with("http://web-platform.test:8000/_mozilla/css/canvas_over_area.html")
});
- let url_opt = url_opt.and_then(|url_string| {
- parse_url_or_filename(&cwd, url_string)
- .map_err(|error| {
- warn!("URL parsing failed ({:?}).", error);
- error
- })
- .ok()
- });
-
let tile_size: usize = match opt_match.opt_str("s") {
Some(tile_size_str) => tile_size_str
.parse()
@@ -752,7 +739,6 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
let opts = Opts {
debug: debug_options.clone(),
is_running_problem_test,
- url: url_opt,
legacy_layout,
tile_size,
time_profiling,
@@ -815,13 +801,3 @@ pub fn set_options(opts: Opts) {
pub fn get() -> RwLockReadGuard<'static, Opts> {
OPTIONS.read().unwrap()
}
-
-pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result<ServoUrl, ()> {
- match ServoUrl::parse(input) {
- Ok(url) => Ok(url),
- Err(url::ParseError::RelativeUrlWithoutBase) => {
- Url::from_file_path(&*cwd.join(input)).map(ServoUrl::from_url)
- },
- Err(_) => Err(()),
- }
-}
diff --git a/ports/servoshell/Cargo.toml b/ports/servoshell/Cargo.toml
index 53774624463..1be6ffbbf16 100644
--- a/ports/servoshell/Cargo.toml
+++ b/ports/servoshell/Cargo.toml
@@ -65,6 +65,7 @@ surfman = { workspace = true, features = ["sm-x11", "sm-raw-window-handle"] }
tinyfiledialogs = "3.0"
webxr = { git = "https://github.com/servo/webxr", features = ["ipc", "glwindow", "headless"] }
winit = "0.28.6"
+url = { workspace = true }
[target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]
image = { workspace = true }
diff --git a/ports/servoshell/app.rs b/ports/servoshell/app.rs
index 290ca0bc38a..12ed43785c7 100644
--- a/ports/servoshell/app.rs
+++ b/ports/servoshell/app.rs
@@ -8,23 +8,21 @@ use crate::browser::Browser;
use crate::embedder::EmbedderCallbacks;
use crate::events_loop::{EventsLoop, WakerEvent};
use crate::minibrowser::Minibrowser;
+use crate::parser::get_default_url;
use crate::window_trait::WindowPortsMethods;
use crate::{headed_window, headless_window};
use gleam::gl;
-use winit::window::WindowId;
-use winit::event_loop::EventLoopWindowTarget;
use servo::compositing::windowing::EmbedderEvent;
-use servo::config::opts::{self, parse_url_or_filename};
+use servo::config::opts;
use servo::servo_config::pref;
-use servo::servo_url::ServoUrl;
use servo::Servo;
use std::cell::{Cell, RefCell, RefMut};
use std::collections::HashMap;
-use std::env;
-
use std::rc::Rc;
use surfman::GLApi;
use webxr::glwindow::GlWindowDiscovery;
+use winit::window::WindowId;
+use winit::event_loop::EventLoopWindowTarget;
pub struct App {
servo: Option<Servo<dyn WindowPortsMethods>>,
@@ -46,6 +44,7 @@ impl App {
no_native_titlebar: bool,
device_pixels_per_px: Option<f32>,
user_agent: Option<String>,
+ url: Option<String>,
) {
let events_loop = EventsLoop::new(opts::get().headless, opts::get().output_file.is_some());
@@ -63,6 +62,7 @@ impl App {
// Handle browser state.
let browser = Browser::new(window.clone());
+ let initial_url = get_default_url(url);
let mut app = App {
event_queue: RefCell::new(vec![]),
@@ -139,7 +139,7 @@ impl App {
// is ready to present, so that we can paint the minibrowser then present.
servo.set_external_present(app.minibrowser.is_some());
- servo.handle_events(vec![EmbedderEvent::NewBrowser(get_default_url(), servo_data.browser_id)]);
+ servo.handle_events(vec![EmbedderEvent::NewBrowser(initial_url.to_owned(), servo_data.browser_id)]);
servo.setup_logging();
app.windows.insert(window.id(), window.clone());
@@ -341,17 +341,3 @@ impl App {
self.minibrowser.as_ref().map(|x| x.borrow_mut())
}
}
-
-fn get_default_url() -> ServoUrl {
- // If the url is not provided, we fallback to the homepage in prefs,
- // or a blank page in case the homepage is not set either.
- let cwd = env::current_dir().unwrap();
- let cmdline_url = opts::get().url.clone();
- let pref_url = {
- let homepage_url = pref!(shell.homepage);
- parse_url_or_filename(&cwd, &homepage_url).ok()
- };
- let blank_url = ServoUrl::parse("about:blank").ok();
-
- cmdline_url.or(pref_url).or(blank_url).unwrap()
-}
diff --git a/ports/servoshell/browser.rs b/ports/servoshell/browser.rs
index 2dc1447297c..b947a9b6b84 100644
--- a/ports/servoshell/browser.rs
+++ b/ports/servoshell/browser.rs
@@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::keyutils::{CMD_OR_ALT, CMD_OR_CONTROL};
+use crate::parser::sanitize_url;
use crate::window_trait::{WindowPortsMethods, LINE_HEIGHT};
use arboard::Clipboard;
use euclid::{Point2D, Vector2D};
@@ -14,10 +15,8 @@ use servo::embedder_traits::{
};
use servo::msg::constellation_msg::TopLevelBrowsingContextId as BrowserId;
use servo::msg::constellation_msg::TraversalDirection;
-use servo::net_traits::pub_domains::is_reg_domain;
use servo::script_traits::TouchEventType;
use servo::servo_config::opts;
-use servo::servo_config::pref;
use servo::servo_url::ServoUrl;
use servo::webrender_api::ScrollLocation;
use std::env;
@@ -634,23 +633,6 @@ fn get_selected_files(patterns: Vec<FilterPattern>, multiple_files: bool) -> Opt
.expect("Thread spawning failed")
}
-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!("https://{}", request)).ok()
- } else {
- None
- }
- })
- .or_else(|| {
- let url = pref!(shell.searchpage).replace("%s", request);
- ServoUrl::parse(&url).ok()
- })
-}
-
// This is a mitigation for #25498, not a verified solution.
// There may be codepaths in tinyfiledialog.c that this is
// inadquate against, as it passes the string via shell to
diff --git a/ports/servoshell/main2.rs b/ports/servoshell/main2.rs
index 2cccdb9550d..f1254dc2aa7 100644
--- a/ports/servoshell/main2.rs
+++ b/ports/servoshell/main2.rs
@@ -10,6 +10,9 @@ extern crate log;
#[macro_use]
extern crate sig;
+#[cfg(test)]
+mod test;
+
mod app;
mod backtrace;
mod browser;
@@ -21,6 +24,7 @@ mod headed_window;
mod headless_window;
mod keyutils;
mod minibrowser;
+mod parser;
mod prefs;
mod resources;
mod window_trait;
@@ -164,7 +168,13 @@ pub fn main() {
let user_agent = opts_matches.opt_str("u");
- App::run(do_not_use_native_titlebar, device_pixels_per_px, user_agent);
+ let url_opt = if !opts_matches.free.is_empty() {
+ Some(&opts_matches.free[0][..])
+ } else {
+ None
+ };
+
+ App::run(do_not_use_native_titlebar, device_pixels_per_px, user_agent, url_opt.map(|s| s.to_string()));
platform::deinit(clean_shutdown)
}
diff --git a/ports/servoshell/parser.rs b/ports/servoshell/parser.rs
new file mode 100644
index 00000000000..002370747b2
--- /dev/null
+++ b/ports/servoshell/parser.rs
@@ -0,0 +1,61 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+use std::env;
+use std::path::Path;
+use log::warn;
+use servo::net_traits::pub_domains::is_reg_domain;
+use servo::servo_config::pref;
+use servo::servo_url::ServoUrl;
+use url::{self, Url};
+
+pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result<ServoUrl, ()> {
+ match ServoUrl::parse(input) {
+ Ok(url) => Ok(url),
+ Err(url::ParseError::RelativeUrlWithoutBase) => {
+ Url::from_file_path(&*cwd.join(input)).map(ServoUrl::from_url)
+ },
+ Err(_) => Err(()),
+ }
+}
+
+pub fn get_default_url(url_opt: Option<String>) -> ServoUrl {
+ // If the url is not provided, we fallback to the homepage in prefs,
+ // or a blank page in case the homepage is not set either.
+ let cwd = env::current_dir().unwrap();
+
+ let cmdline_url = url_opt.map(|s| s.to_string()).and_then(|url_string| {
+ parse_url_or_filename(&cwd, &url_string)
+ .map_err(|error| {
+ warn!("URL parsing failed ({:?}).", error);
+ error
+ })
+ .ok()
+ });
+
+ let pref_url = {
+ let homepage_url = pref!(shell.homepage);
+ parse_url_or_filename(&cwd, &homepage_url).ok()
+ };
+ let blank_url = ServoUrl::parse("about:blank").ok();
+
+ cmdline_url.or(pref_url).or(blank_url).unwrap()
+}
+
+pub 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!("https://{}", request)).ok()
+ } else {
+ None
+ }
+ })
+ .or_else(|| {
+ let url = pref!(shell.searchpage).replace("%s", request);
+ ServoUrl::parse(&url).ok()
+ })
+}
diff --git a/components/config/tests/opts.rs b/ports/servoshell/test.rs
index e0b36456c90..7c22d06d1ff 100644
--- a/components/config/tests/opts.rs
+++ b/ports/servoshell/test.rs
@@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use servo_config::opts::parse_url_or_filename;
use std::path::Path;
+use crate::parser::parse_url_or_filename;
#[cfg(not(target_os = "windows"))]
const FAKE_CWD: &'static str = "/fake/cwd";
diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py
index 9ac9cffdda9..328a82a7a23 100644
--- a/python/servo/testing_commands.py
+++ b/python/servo/testing_commands.py
@@ -197,6 +197,7 @@ class MachCommands(CommandBase):
test_patterns.append(test)
self_contained_tests = [
+ "servoshell",
"background_hang_monitor",
"gfx",
"layout_2013",