aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/history.rs70
-rw-r--r--components/script/dom/mod.rs1
-rw-r--r--components/script/dom/webidls/History.webidl18
-rw-r--r--components/script/dom/webidls/Window.webidl2
-rw-r--r--components/script/dom/window.rs8
5 files changed, 98 insertions, 1 deletions
diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs
new file mode 100644
index 00000000000..061d7616f4a
--- /dev/null
+++ b/components/script/dom/history.rs
@@ -0,0 +1,70 @@
+/* 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 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();
+ 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-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));
+ }
+}
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 172026c4d8e..effc7f2c761 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -270,6 +270,7 @@ pub mod forcetouchevent;
pub mod formdata;
pub mod hashchangeevent;
pub mod headers;
+pub mod history;
pub mod htmlanchorelement;
pub mod htmlappletelement;
pub mod htmlareaelement;
diff --git a/components/script/dom/webidls/History.webidl b/components/script/dom/webidls/History.webidl
new file mode 100644
index 00000000000..04742d52601
--- /dev/null
+++ b/components/script/dom/webidls/History.webidl
@@ -0,0 +1,18 @@
+/* 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/. */
+
+// enum ScrollRestoration { "auto", "manual" };
+
+// https://html.spec.whatwg.org/multipage/#the-history-interface
+[Exposed=(Window,Worker)]
+interface History {
+ // readonly attribute unsigned long length;
+ // attribute ScrollRestoration scrollRestoration;
+ // readonly attribute any state;
+ void go(optional long delta = 0);
+ void back();
+ void forward();
+ // void pushState(any data, DOMString title, optional USVString? url = null);
+ // void replaceState(any data, DOMString title, optional USVString? url = null);
+};
diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl
index bda73c9479a..651c7081305 100644
--- a/components/script/dom/webidls/Window.webidl
+++ b/components/script/dom/webidls/Window.webidl
@@ -11,7 +11,7 @@
[Unforgeable] readonly attribute Document document;
// attribute DOMString name;
[/*PutForwards=href, */Unforgeable] readonly attribute Location location;
- //readonly attribute History history;
+ readonly attribute History history;
//[Replaceable] readonly attribute BarProp locationbar;
//[Replaceable] readonly attribute BarProp menubar;
//[Replaceable] readonly attribute BarProp personalbar;
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index b4984bb2a4a..2237514bd3d 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -30,6 +30,7 @@ use dom::document::Document;
use dom::element::Element;
use dom::event::Event;
use dom::eventtarget::EventTarget;
+use dom::history::History;
use dom::htmliframeelement::build_mozbrowser_custom_event;
use dom::location::Location;
use dom::navigator::Navigator;
@@ -158,6 +159,7 @@ pub struct Window {
#[ignore_heap_size_of = "channels are hard"]
image_cache_chan: ImageCacheChan,
browsing_context: MutNullableHeap<JS<BrowsingContext>>,
+ history: MutNullableHeap<JS<History>>,
performance: MutNullableHeap<JS<Performance>>,
navigation_start: u64,
navigation_start_precise: f64,
@@ -475,6 +477,11 @@ impl WindowMethods for Window {
self.browsing_context().active_document()
}
+ // https://html.spec.whatwg.org/multipage/#dom-history
+ fn History(&self) -> Root<History> {
+ self.history.or_init(|| History::new(self))
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-location
fn Location(&self) -> Root<Location> {
self.Document().GetLocation().unwrap()
@@ -1648,6 +1655,7 @@ impl Window {
mem_profiler_chan: mem_profiler_chan,
time_profiler_chan: time_profiler_chan,
devtools_chan: devtools_chan,
+ history: Default::default(),
browsing_context: Default::default(),
performance: Default::default(),
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,