From 6577409b95bc782c0493cc5186fa4ed0d31d680d Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Mon, 21 Mar 2016 19:19:48 +0800 Subject: [PATCH] Add history information to mozbrowserlocationchange event --- components/compositing/constellation.rs | 7 ++- components/script/dom/htmliframeelement.rs | 10 +++- .../script/dom/webidls/BrowserElement.webidl | 6 ++ components/script_traits/lib.rs | 4 +- tests/wpt/mozilla/meta/MANIFEST.json | 6 ++ .../mozilla/mozbrowser/iframe_goback.html | 4 +- .../mozbrowserlocationchange_event.html | 59 +++++++++++++++++++ .../tests/mozilla/mozbrowser/redirect.html | 2 +- 8 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 tests/wpt/mozilla/tests/mozilla/mozbrowser/mozbrowserlocationchange_event.html diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 86f9e9620a0..a8d7952efaf 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -1655,8 +1655,11 @@ impl Constellation // If this is an iframe, then send the event with new url if let Some((containing_pipeline_id, subpage_id, url)) = event_info { let parent_pipeline = self.pipeline(containing_pipeline_id); - parent_pipeline.trigger_mozbrowser_event(subpage_id, - MozBrowserEvent::LocationChange(url)); + let frame_id = *self.pipeline_to_frame_map.get(&pipeline_id).unwrap(); + let can_go_backward = !self.frame(frame_id).prev.is_empty(); + let can_go_forward = !self.frame(frame_id).next.is_empty(); + let event = MozBrowserEvent::LocationChange(url, can_go_backward, can_go_forward); + parent_pipeline.trigger_mozbrowser_event(subpage_id, event); } } } diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 4cf2c3f467e..a4ccafd2d4c 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -6,6 +6,7 @@ use document_loader::{LoadType, LoadBlocker}; use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementIconChangeEventDetail; +use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementLocationChangeEventDetail; use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserElementSecurityChangeDetail; use dom::bindings::codegen::Bindings::BrowserElementBinding::BrowserShowModalPromptEventDetail; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding; @@ -323,9 +324,16 @@ impl MozBrowserEventDetailBuilder for HTMLIFrameElement { mixedState: None, }.to_jsval(cx, rval); } - MozBrowserEvent::LocationChange(ref string) | MozBrowserEvent::TitleChange(ref string) => { + MozBrowserEvent::TitleChange(ref string) => { string.to_jsval(cx, rval); } + MozBrowserEvent::LocationChange(uri, can_go_back, can_go_forward) => { + BrowserElementLocationChangeEventDetail { + uri: Some(DOMString::from(uri)), + canGoBack: Some(can_go_back), + canGoForward: Some(can_go_forward), + }.to_jsval(cx, rval); + } MozBrowserEvent::IconChange(rel, href, sizes) => { BrowserElementIconChangeEventDetail { rel: Some(DOMString::from(rel)), diff --git a/components/script/dom/webidls/BrowserElement.webidl b/components/script/dom/webidls/BrowserElement.webidl index 33f1fa6fd5e..6e658a1b5b7 100644 --- a/components/script/dom/webidls/BrowserElement.webidl +++ b/components/script/dom/webidls/BrowserElement.webidl @@ -54,6 +54,12 @@ dictionary BrowserElementSecurityChangeDetail { boolean mixedContent; }; +dictionary BrowserElementLocationChangeEventDetail { + DOMString uri; + boolean canGoBack; + boolean canGoForward; +}; + dictionary BrowserElementIconChangeEventDetail { DOMString rel; DOMString href; diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 9b69525d205..6aeca4068ec 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -424,7 +424,7 @@ pub enum MozBrowserEvent { /// Sent when the browser `