<!-- Please describe your changes on the following line: --> SubpageId was originally introduced in 2013 to help iframes keep track of their associated (children) pipelines. However, since each pipeline already has a PipelineId, and those are unique, those are sufficient to keep track of children. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #11694 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 161e0741cd4942d337b8d0fca2e0eaa86482ad9a
81 lines
2.7 KiB
Rust
81 lines
2.7 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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 dom::bindings::codegen::Bindings::HistoryBinding;
|
|
use dom::bindings::codegen::Bindings::HistoryBinding::HistoryMethods;
|
|
use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods;
|
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
|
use dom::bindings::global::GlobalRef;
|
|
use dom::bindings::js::{JS, Root};
|
|
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
|
use dom::window::Window;
|
|
use ipc_channel::ipc;
|
|
use msg::constellation_msg::TraversalDirection;
|
|
use script_traits::ScriptMsg as ConstellationMsg;
|
|
|
|
// https://html.spec.whatwg.org/multipage/#the-history-interface
|
|
#[dom_struct]
|
|
pub struct History {
|
|
reflector_: Reflector,
|
|
window: JS<Window>,
|
|
}
|
|
|
|
impl History {
|
|
pub fn new_inherited(window: &Window) -> History {
|
|
History {
|
|
reflector_: Reflector::new(),
|
|
window: JS::from_ref(&window),
|
|
}
|
|
}
|
|
|
|
pub fn new(window: &Window) -> Root<History> {
|
|
reflect_dom_object(box History::new_inherited(window),
|
|
GlobalRef::Window(window),
|
|
HistoryBinding::Wrap)
|
|
}
|
|
}
|
|
|
|
impl History {
|
|
fn traverse_history(&self, direction: TraversalDirection) {
|
|
let pipeline = self.window.pipeline_id();
|
|
let msg = ConstellationMsg::TraverseHistory(Some(pipeline), direction);
|
|
let _ = self.window.constellation_chan().send(msg);
|
|
}
|
|
}
|
|
|
|
impl HistoryMethods for History {
|
|
// https://html.spec.whatwg.org/multipage/#dom-history-length
|
|
fn Length(&self) -> u32 {
|
|
let pipeline = self.window.pipeline_id();
|
|
let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length.");
|
|
let msg = ConstellationMsg::JointSessionHistoryLength(pipeline, sender);
|
|
let _ = self.window.constellation_chan().send(msg);
|
|
recv.recv().unwrap()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-history-go
|
|
fn Go(&self, delta: i32) {
|
|
let direction = if delta > 0 {
|
|
TraversalDirection::Forward(delta as usize)
|
|
} else if delta < 0 {
|
|
TraversalDirection::Back(-delta as usize)
|
|
} else {
|
|
self.window.Location().Reload();
|
|
return;
|
|
};
|
|
|
|
self.traverse_history(direction);
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-history-back
|
|
fn Back(&self) {
|
|
self.traverse_history(TraversalDirection::Back(1));
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-history-forward
|
|
fn Forward(&self) {
|
|
self.traverse_history(TraversalDirection::Forward(1));
|
|
}
|
|
}
|