From 9eade1989738709a2170818a6287fed320dac5cf Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 15 Jun 2015 13:24:49 +0100 Subject: [PATCH] Add support for the Get URL WebDriver command. --- components/compositing/constellation.rs | 4 ++++ components/msg/constellation_msg.rs | 1 + components/webdriver_server/lib.rs | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 7dd06342790..963363c29a7 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -917,6 +917,10 @@ impl Constellation { self.webdriver.load_channel = Some((id, reply)); } }, + WebDriverCommandMsg::GetUrl(pipeline_id, reply) => { + let pipeline = self.pipeline(pipeline_id); + reply.send(pipeline.url.clone()).unwrap(); + } WebDriverCommandMsg::ScriptCommand(pipeline_id, cmd) => { let pipeline = self.pipeline(pipeline_id); let control_msg = ConstellationControlMsg::WebDriverScriptCommand(pipeline_id, cmd); diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 52b883615e5..db6216c6568 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -336,6 +336,7 @@ impl MozBrowserEvent { #[derive(Deserialize, Serialize)] pub enum WebDriverCommandMsg { LoadUrl(PipelineId, LoadData, IpcSender), + GetUrl(PipelineId, IpcSender), ScriptCommand(PipelineId, WebDriverScriptCommand), TakeScreenshot(PipelineId, IpcSender>) } diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 6713fbfe453..500e7d220dc 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -191,6 +191,21 @@ impl Handler { } } + fn handle_get_current_url(&self) -> WebDriverResult { + let pipeline_id = try!(self.get_root_pipeline()); + + let (sender, reciever) = channel(); + + let ConstellationChan(ref const_chan) = self.constellation_chan; + let cmd_msg = WebDriverCommandMsg::GetUrl(pipeline_id, sender); + const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap(); + + //Wait to get a load event + let url = reciever.recv().unwrap(); + + Ok(WebDriverResponse::Generic(ValueResponse::new(url.serialize().to_json()))) + } + fn handle_go_back(&self) -> WebDriverResult { let ConstellationChan(ref const_chan) = self.constellation_chan; const_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Back)).unwrap(); @@ -489,6 +504,7 @@ impl WebDriverHandler for Handler { match msg.command { WebDriverCommand::NewSession => self.handle_new_session(), WebDriverCommand::Get(ref parameters) => self.handle_get(parameters), + WebDriverCommand::GetCurrentUrl => self.handle_get_current_url(), WebDriverCommand::GoBack => self.handle_go_back(), WebDriverCommand::GoForward => self.handle_go_forward(), WebDriverCommand::GetTitle => self.handle_get_title(),