Add history information to mozbrowserlocationchange event

This commit is contained in:
Paul Rouget 2016-03-21 19:19:48 +08:00
parent aa35d7721b
commit 6577409b95
8 changed files with 90 additions and 8 deletions

View file

@ -1655,8 +1655,11 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
// 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);
}
}
}

View file

@ -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)),

View file

@ -54,6 +54,12 @@ dictionary BrowserElementSecurityChangeDetail {
boolean mixedContent;
};
dictionary BrowserElementLocationChangeEventDetail {
DOMString uri;
boolean canGoBack;
boolean canGoForward;
};
dictionary BrowserElementIconChangeEventDetail {
DOMString rel;
DOMString href;

View file

@ -424,7 +424,7 @@ pub enum MozBrowserEvent {
/// Sent when the browser `<iframe>` starts to load a new page.
LoadStart,
/// Sent when a browser `<iframe>`'s location changes.
LocationChange(String),
LocationChange(String, bool, bool),
/// Sent when window.open() is called within a browser `<iframe>`.
OpenWindow,
/// Sent when the SSL state changes within a browser `<iframe>`.
@ -451,7 +451,7 @@ impl MozBrowserEvent {
MozBrowserEvent::IconChange(_, _, _) => "mozbrowsericonchange",
MozBrowserEvent::LoadEnd => "mozbrowserloadend",
MozBrowserEvent::LoadStart => "mozbrowserloadstart",
MozBrowserEvent::LocationChange(_) => "mozbrowserlocationchange",
MozBrowserEvent::LocationChange(_, _, _) => "mozbrowserlocationchange",
MozBrowserEvent::OpenWindow => "mozbrowseropenwindow",
MozBrowserEvent::SecurityChange(_) => "mozbrowsersecuritychange",
MozBrowserEvent::ShowModalPrompt(_, _, _, _) => "mozbrowsershowmodalprompt",