From 2b396b2485f7646107ea786a0a9a303f8445c2a1 Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 1 Jun 2015 18:28:39 +0100 Subject: [PATCH] Allow Window implementations to indicate that they don't support a clipboard. This is important for the SERVO_HEADLESS configuration, because creating a clipboard on linux creates an X context which then causes reftest instability. --- components/compositing/constellation.rs | 21 +++++++++++++-------- components/compositing/windowing.rs | 3 +++ components/servo/lib.rs | 17 ++++++++++++++--- ports/cef/window.rs | 4 ++++ ports/glutin/window.rs | 8 ++++++++ ports/gonk/src/window.rs | 4 ++++ 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 8c4b2557cd8..099a2031394 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -122,7 +122,7 @@ pub struct Constellation { pub window_size: WindowSizeData, /// Means of accessing the clipboard - clipboard_ctx: ClipboardContext, + clipboard_ctx: Option, /// Bits of state used to interact with the webdriver implementation webdriver: WebDriverData @@ -215,7 +215,8 @@ impl Constellation { time_profiler_chan: time::ProfilerChan, mem_profiler_chan: mem::ProfilerChan, devtools_chan: Option, - storage_task: StorageTask) + storage_task: StorageTask, + supports_clipboard: bool) -> ConstellationChan { let (constellation_port, constellation_chan) = ConstellationChan::new(); let constellation_chan_clone = constellation_chan.clone(); @@ -248,7 +249,11 @@ impl Constellation { device_pixel_ratio: ScaleFactor::new(1.0), }, phantom: PhantomData, - clipboard_ctx: ClipboardContext::new().unwrap(), + clipboard_ctx: if supports_clipboard { + ClipboardContext::new().ok() + } else { + None + }, webdriver: WebDriverData::new() }; constellation.run(); @@ -438,13 +443,13 @@ impl Constellation { self.handle_focus_msg(pipeline_id); } ConstellationMsg::GetClipboardContents(sender) => { - let result = match self.clipboard_ctx.get_contents() { - Ok(s) => s, - Err(e) => { + let result = self.clipboard_ctx.as_ref().map_or( + "".to_string(), + |ctx| ctx.get_contents().unwrap_or_else(|e| { debug!("Error getting clipboard contents ({}), defaulting to empty string", e); "".to_string() - }, - }; + }) + ); sender.send(result).unwrap(); } ConstellationMsg::WebDriverCommand(command) => { diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 1b1cac23025..7ba7fffe449 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -135,4 +135,7 @@ pub trait WindowMethods { /// Process a key event. fn handle_key(&self, key: Key, mods: KeyModifiers); + + /// Does this window support a clipboard + fn supports_clipboard(&self) -> bool; } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 1cc349de1dd..8afb4e90b69 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -57,6 +57,7 @@ use profile_traits::mem; use profile_traits::time; use util::opts; +use std::borrow::Borrow; use std::rc::Rc; use std::sync::mpsc::Sender; @@ -91,6 +92,13 @@ impl Browser { // to deliver the message. let (compositor_proxy, compositor_receiver) = WindowMethods::create_compositor_channel(&window); + let supports_clipboard = match window { + Some(ref win_rc) => { + let win: &Window = win_rc.borrow(); + win.supports_clipboard() + } + None => false + }; let time_profiler_chan = profile_time::Profiler::create(opts.time_profiler_period); let mem_profiler_chan = profile_mem::Profiler::create(opts.mem_profiler_period); let devtools_chan = opts.devtools_port.map(|port| { @@ -104,7 +112,8 @@ impl Browser { compositor_proxy.clone_compositor_proxy(), time_profiler_chan.clone(), devtools_chan, - mem_profiler_chan.clone()); + mem_profiler_chan.clone(), + supports_clipboard); if let Some(port) = opts.webdriver_port { webdriver_server::start_server(port, constellation_chan.clone()); @@ -149,7 +158,8 @@ fn create_constellation(opts: opts::Opts, compositor_proxy: Box, time_profiler_chan: time::ProfilerChan, devtools_chan: Option>, - mem_profiler_chan: mem::ProfilerChan) -> ConstellationChan { + mem_profiler_chan: mem::ProfilerChan, + supports_clipboard: bool) -> ConstellationChan { let resource_task = new_resource_task(opts.user_agent.clone(), devtools_chan.clone()); let image_cache_task = new_image_cache_task(resource_task.clone()); @@ -165,7 +175,8 @@ fn create_constellation(opts: opts::Opts, time_profiler_chan, mem_profiler_chan, devtools_chan, - storage_task); + storage_task, + supports_clipboard); // Send the URL command to the constellation. match opts.url { diff --git a/ports/cef/window.rs b/ports/cef/window.rs index 05af8fdbf8f..8af65a1c4e7 100644 --- a/ports/cef/window.rs +++ b/ports/cef/window.rs @@ -451,6 +451,10 @@ impl WindowMethods for Window { } } } + + fn supports_clipboard(&self) -> bool { + true + } } struct CefCompositorProxy { diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 44c1d225979..3c934f50871 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -614,6 +614,10 @@ impl WindowMethods for Window { _ => {} } } + + fn supports_clipboard(&self) -> bool { + true + } } /// The type of a window. @@ -718,6 +722,10 @@ impl WindowMethods for Window { /// Helper function to handle keyboard events. fn handle_key(&self, _: Key, _: constellation_msg::KeyModifiers) { } + + fn supports_clipboard(&self) -> bool { + false + } } struct GlutinCompositorProxy { diff --git a/ports/gonk/src/window.rs b/ports/gonk/src/window.rs index 67254dd663c..a2c9f6b020a 100644 --- a/ports/gonk/src/window.rs +++ b/ports/gonk/src/window.rs @@ -841,6 +841,10 @@ impl WindowMethods for Window { fn prepare_for_composite(&self, _width: usize, _height: usize) -> bool { true } + + fn supports_clipboard(&self) -> bool { + true + } } struct GonkCompositorProxy {