Skip to content

Commit 708c561

Browse files
committed
Pass URL to Browser::new(), delegate url checking logic to third party
Use Option instead of ServoUrl for url in opts Cleaner mapping from parse_url to url_opt Add comment about url parsing error Print reason for parsing error Remove comment about warning Add home url when openning new browser window in CEF Fix merge error
1 parent a6b3bf1 commit 708c561

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

components/config/opts.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ const DEFAULT_USER_AGENT: UserAgent = UserAgent::Desktop;
480480
pub fn default_opts() -> Opts {
481481
Opts {
482482
is_running_problem_test: false,
483-
url: Some(ServoUrl::parse("about:blank").unwrap()),
483+
url: None,
484484
tile_size: 512,
485485
device_pixels_per_px: None,
486486
time_profiling: None,
@@ -631,11 +631,10 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
631631
}
632632

633633
let cwd = env::current_dir().unwrap();
634-
let homepage_pref = PREFS.get("shell.homepage");
635634
let url_opt = if !opt_match.free.is_empty() {
636635
Some(&opt_match.free[0][..])
637636
} else {
638-
homepage_pref.as_string()
637+
None
639638
};
640639
let is_running_problem_test =
641640
url_opt
@@ -645,16 +644,11 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
645644
url.starts_with("http://web-platform.test:8000/_mozilla/mozilla/canvas/") ||
646645
url.starts_with("http://web-platform.test:8000/_mozilla/css/canvas_over_area.html"));
647646

648-
let url = match url_opt {
649-
Some(url_string) => {
650-
parse_url_or_filename(&cwd, url_string)
651-
.unwrap_or_else(|()| args_fail("URL parsing failed"))
652-
},
653-
None => {
654-
print_usage(app_name, &opts);
655-
args_fail("servo asks that you provide a URL")
656-
}
657-
};
647+
let url_opt = url_opt.and_then(|url_string| parse_url_or_filename(&cwd, url_string)
648+
.or_else(|error| {
649+
warn!("URL parsing failed ({:?}).", error);
650+
Err(error)
651+
}).ok());
658652

659653
let tile_size: usize = match opt_match.opt_str("s") {
660654
Some(tile_size_str) => tile_size_str.parse()
@@ -775,7 +769,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
775769

776770
let opts = Opts {
777771
is_running_problem_test: is_running_problem_test,
778-
url: Some(url),
772+
url: url_opt,
779773
tile_size: tile_size,
780774
device_pixels_per_px: device_pixels_per_px,
781775
time_profiling: time_profiling,

components/servo/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub struct Browser<Window: WindowMethods + 'static> {
122122
}
123123

124124
impl<Window> Browser<Window> where Window: WindowMethods + 'static {
125-
pub fn new(window: Rc<Window>) -> Browser<Window> {
125+
pub fn new(window: Rc<Window>, target_url: ServoUrl) -> Browser<Window> {
126126
// Global configuration options, parsed from the command line.
127127
let opts = opts::get();
128128

@@ -203,7 +203,7 @@ impl<Window> Browser<Window> where Window: WindowMethods + 'static {
203203
// as the navigation context.
204204
let (constellation_chan, sw_senders) = create_constellation(opts.user_agent.clone(),
205205
opts.config_dir.clone(),
206-
opts.url.clone(),
206+
target_url,
207207
compositor_proxy.clone_compositor_proxy(),
208208
time_profiler_chan.clone(),
209209
mem_profiler_chan.clone(),
@@ -287,7 +287,7 @@ fn create_compositor_channel(event_loop_waker: Box<compositor_thread::EventLoopW
287287

288288
fn create_constellation(user_agent: Cow<'static, str>,
289289
config_dir: Option<PathBuf>,
290-
url: Option<ServoUrl>,
290+
url: ServoUrl,
291291
compositor_proxy: CompositorProxy,
292292
time_profiler_chan: time::ProfilerChan,
293293
mem_profiler_chan: mem::ProfilerChan,
@@ -337,9 +337,7 @@ fn create_constellation(user_agent: Cow<'static, str>,
337337
constellation_chan.send(ConstellationMsg::SetWebVRThread(webvr_thread)).unwrap();
338338
}
339339

340-
if let Some(url) = url {
341-
constellation_chan.send(ConstellationMsg::InitLoadUrl(url)).unwrap();
342-
};
340+
constellation_chan.send(ConstellationMsg::InitLoadUrl(url)).unwrap();
343341

344342
// channels to communicate with Service Worker Manager
345343
let sw_senders = SWManagerSenders {

ports/cef/browser.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use interfaces::{CefBrowser, CefBrowserHost, CefClient, CefFrame, CefRequestCont
99
use interfaces::{cef_browser_t, cef_browser_host_t, cef_client_t, cef_frame_t};
1010
use interfaces::{cef_request_context_t};
1111
use servo::Browser;
12+
use servo::servo_config::prefs::PREFS;
13+
use servo::servo_url::ServoUrl;
1214
use types::{cef_browser_settings_t, cef_string_t, cef_window_info_t, cef_window_handle_t};
1315
use window;
1416
use wrappers::CefWrap;
@@ -130,7 +132,9 @@ impl ServoCefBrowser {
130132
let (glutin_window, servo_browser) = if window_info.windowless_rendering_enabled == 0 {
131133
let parent_window = glutin_app::WindowID::new(window_info.parent_window as *mut _);
132134
let glutin_window = glutin_app::create_window(Some(parent_window));
133-
let servo_browser = Browser::new(glutin_window.clone());
135+
let home_url = ServoUrl::parse(PREFS.get("shell.homepage").as_string()
136+
.unwrap_or("about:blank")).unwrap();
137+
let servo_browser = Browser::new(glutin_window.clone(), home_url);
134138
window_handle = glutin_window.platform_window().window as cef_window_handle_t;
135139
(Some(glutin_window), ServoBrowser::OnScreen(servo_browser))
136140
} else {
@@ -171,7 +175,9 @@ impl ServoCefBrowserExtensions for CefBrowser {
171175
if window_info.windowless_rendering_enabled != 0 {
172176
let window = window::Window::new(window_info.width, window_info.height);
173177
window.set_browser(self.clone());
174-
let servo_browser = Browser::new(window.clone());
178+
let home_url = ServoUrl::parse(PREFS.get("shell.homepage").as_string()
179+
.unwrap_or("about:blank")).unwrap();
180+
let servo_browser = Browser::new(window.clone(), home_url);
175181
*self.downcast().servo_browser.borrow_mut() = ServoBrowser::OffScreen(servo_browser);
176182
}
177183

ports/servo/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ use servo::compositing::windowing::WindowEvent;
3737
use servo::config;
3838
use servo::config::opts::{self, ArgumentParsingResult};
3939
use servo::config::servo_version;
40+
use servo::servo_config::prefs::PREFS;
41+
use servo::servo_url::ServoUrl;
4042
use std::env;
4143
use std::panic;
4244
use std::process;
@@ -143,10 +145,16 @@ fn main() {
143145

144146
let window = app::create_window(None);
145147

148+
// If the url is not provided, we fallback to the homepage in PREFS,
149+
// or a blank page in case the homepage is not set either.
150+
let target_url = opts::get().url.clone()
151+
.unwrap_or(ServoUrl::parse(PREFS.get("shell.homepage").as_string()
152+
.unwrap_or("about:blank")).unwrap());
153+
146154
// Our wrapper around `Browser` that also implements some
147155
// callbacks required by the glutin window implementation.
148156
let mut browser = BrowserWrapper {
149-
browser: Browser::new(window.clone()),
157+
browser: Browser::new(window.clone(), target_url)
150158
};
151159

152160
browser.browser.setup_logging();

0 commit comments

Comments
 (0)