diff options
-rw-r--r-- | components/constellation/constellation.rs | 17 | ||||
-rw-r--r-- | components/msg/constellation_msg.rs | 4 | ||||
-rw-r--r-- | components/msg/webdriver_msg.rs | 6 | ||||
-rw-r--r-- | components/script/script_thread.rs | 4 | ||||
-rw-r--r-- | components/script/webdriver_handlers.rs | 20 | ||||
-rw-r--r-- | components/webdriver_server/lib.rs | 28 |
6 files changed, 34 insertions, 45 deletions
diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 88f8bd02265..5a75d43df3e 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -292,13 +292,15 @@ impl<'a> Iterator for FrameTreeIterator<'a> { } struct WebDriverData { - load_channel: Option<(PipelineId, IpcSender<webdriver_msg::LoadStatus>)> + load_channel: Option<(PipelineId, IpcSender<webdriver_msg::LoadStatus>)>, + resize_channel: Option<IpcSender<WindowSizeData>>, } impl WebDriverData { pub fn new() -> WebDriverData { WebDriverData { - load_channel: None + load_channel: None, + resize_channel: None, } } } @@ -1484,6 +1486,13 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> // Find the script channel for the given parent pipeline, // and pass the event to that script thread. match msg { + WebDriverCommandMsg::GetWindowSize(_, reply) => { + let _ = reply.send(self.window_size); + }, + WebDriverCommandMsg::SetWindowSize(_, size, reply) => { + self.webdriver.resize_channel = Some(reply); + self.compositor_proxy.send(ToCompositorMsg::ResizeTo(size)); + }, WebDriverCommandMsg::LoadUrl(pipeline_id, load_data, reply) => { self.load_url_for_webdriver(pipeline_id, load_data, reply); }, @@ -1703,6 +1712,10 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> } } + if let Some(resize_channel) = self.webdriver.resize_channel.take() { + let _ = resize_channel.send(new_size); + } + self.window_size = new_size; } diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 3433b6915f0..543e4277f23 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -6,7 +6,7 @@ //! reduce coupling between these two components. use euclid::scale_factor::ScaleFactor; -use euclid::size::TypedSize2D; +use euclid::size::{Size2D, TypedSize2D}; use hyper::header::Headers; use hyper::method::Method; use ipc_channel::ipc::{IpcSender, IpcSharedMemory}; @@ -188,10 +188,12 @@ bitflags! { #[derive(Deserialize, Serialize)] pub enum WebDriverCommandMsg { + GetWindowSize(PipelineId, IpcSender<WindowSizeData>), LoadUrl(PipelineId, LoadData, IpcSender<LoadStatus>), Refresh(PipelineId, IpcSender<LoadStatus>), ScriptCommand(PipelineId, WebDriverScriptCommand), SendKeys(PipelineId, Vec<(Key, KeyModifiers, KeyState)>), + SetWindowSize(PipelineId, Size2D<u32>, IpcSender<WindowSizeData>), TakeScreenshot(PipelineId, IpcSender<Option<Image>>), } diff --git a/components/msg/webdriver_msg.rs b/components/msg/webdriver_msg.rs index fca22ab61e5..a6c94c3a439 100644 --- a/components/msg/webdriver_msg.rs +++ b/components/msg/webdriver_msg.rs @@ -2,13 +2,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use constellation_msg::{PipelineId, WindowSizeData}; +use constellation_msg::PipelineId; use euclid::rect::Rect; -use euclid::size::TypedSize2D; use ipc_channel::ipc::IpcSender; use rustc_serialize::json::{Json, ToJson}; use url::Url; -use util::geometry::ViewportPx; #[derive(Deserialize, Serialize)] pub enum WebDriverScriptCommand { @@ -25,8 +23,6 @@ pub enum WebDriverScriptCommand { GetElementText(String, IpcSender<Result<String, ()>>), GetFrameId(WebDriverFrameId, IpcSender<Result<Option<PipelineId>, ()>>), GetUrl(IpcSender<Url>), - GetWindowSize(IpcSender<Option<WindowSizeData>>), - SetWindowSize(TypedSize2D<ViewportPx, f32>, IpcSender<()>), IsEnabled(String, IpcSender<Result<bool, ()>>), IsSelected(String, IpcSender<Result<bool, ()>>), GetTitle(IpcSender<String>) diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index e8c87629b06..c791000cae4 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1016,10 +1016,6 @@ impl ScriptThread { webdriver_handlers::handle_get_frame_id(&context, pipeline_id, frame_id, reply), WebDriverScriptCommand::GetUrl(reply) => webdriver_handlers::handle_get_url(&context, pipeline_id, reply), - WebDriverScriptCommand::GetWindowSize(reply) => - webdriver_handlers::handle_get_window_size(&context, pipeline_id, reply), - WebDriverScriptCommand::SetWindowSize(size, reply) => - webdriver_handlers::handle_set_window_size(&context, pipeline_id, size, reply), WebDriverScriptCommand::IsEnabled(element_id, reply) => webdriver_handlers::handle_is_enabled(&context, pipeline_id, element_id, reply), WebDriverScriptCommand::IsSelected(element_id, reply) => diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index 5e5424b131e..8c84c950ae0 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -283,26 +283,6 @@ pub fn handle_get_url(context: &BrowsingContext, reply.send((*url).clone()).unwrap(); } -pub fn handle_get_window_size(context: &BrowsingContext, - _pipeline: PipelineId, - reply: IpcSender<Option<WindowSizeData>>) { - let window = context.active_window(); - let size = window.window_size(); - reply.send(size).unwrap(); -} - -pub fn handle_set_window_size(context: &BrowsingContext, - _pipeline: PipelineId, - size: TypedSize2D<ViewportPx, f32>, - reply: IpcSender<()>) { - let window = context.active_window(); - // TODO: converting to a dimensionless size is error-prone - let untyped = size.to_untyped(); - // TODO: when window puts in security checks for resize, we will need to rewrite this - window.ResizeTo(untyped.width as i32, untyped.height as i32); - reply.send(()).unwrap(); -} - pub fn handle_is_enabled(context: &BrowsingContext, pipeline: PipelineId, element_id: String, diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 151c6efddb6..57174704408 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -357,27 +357,29 @@ impl Handler { fn handle_window_size(&self) -> WebDriverResult<WebDriverResponse> { let (sender, receiver) = ipc::channel().unwrap(); + let pipeline_id = try!(self.root_pipeline()); + let cmd_msg = WebDriverCommandMsg::GetWindowSize(pipeline_id, sender); - try!(self.root_script_command(WebDriverScriptCommand::GetWindowSize(sender))); + self.constellation_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - match receiver.recv().unwrap() { - Some(window_size) => { - let vp = window_size.visible_viewport; - let window_size_response = WindowSizeResponse::new(vp.width.get() as u64, vp.height.get() as u64); - Ok(WebDriverResponse::WindowSize(window_size_response)) - }, - None => Err(WebDriverError::new(ErrorStatus::NoSuchWindow, "Unable to determine window size")) - } + let window_size = receiver.recv().unwrap(); + let vp = window_size.visible_viewport; + let window_size_response = WindowSizeResponse::new(vp.width.get() as u64, vp.height.get() as u64); + Ok(WebDriverResponse::WindowSize(window_size_response)) } fn handle_set_window_size(&self, params: &WindowSizeParameters) -> WebDriverResult<WebDriverResponse> { let (sender, receiver) = ipc::channel().unwrap(); - let size = Size2D::from_untyped(&Size2D::new(params.width as f32, params.height as f32)); + let size = Size2D::new(params.width as u32, params.height as u32); + let pipeline_id = try!(self.root_pipeline()); + let cmd_msg = WebDriverCommandMsg::SetWindowSize(pipeline_id, size, sender); - try!(self.root_script_command(WebDriverScriptCommand::SetWindowSize(size, sender))); - receiver.recv().unwrap(); + self.constellation_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); - Ok(WebDriverResponse::Void) + let window_size = receiver.recv().unwrap(); + let vp = window_size.visible_viewport; + let window_size_response = WindowSizeResponse::new(vp.width.get() as u64, vp.height.get() as u64); + Ok(WebDriverResponse::WindowSize(window_size_response)) } fn handle_is_enabled(&self, element: &WebElement) -> WebDriverResult<WebDriverResponse> { |