From 5c53f5b7fa1b639ad3f30f1202e10e374de698c7 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Tue, 2 May 2017 11:22:36 -0600 Subject: Make History attributes and methods throw --- components/script/dom/history.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 537e9cbbb22..5488d02d9bf 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::HistoryBinding; use dom::bindings::codegen::Bindings::HistoryBinding::HistoryMethods; use dom::bindings::codegen::Bindings::LocationBinding::LocationBinding::LocationMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::error::Fallible; +use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; @@ -40,27 +40,34 @@ impl History { } impl History { - fn traverse_history(&self, direction: TraversalDirection) { + fn traverse_history(&self, direction: TraversalDirection) -> ErrorResult { + if !self.window.Document().is_fully_active() { + return Err(Error::Security); + } let global_scope = self.window.upcast::(); let pipeline = global_scope.pipeline_id(); let msg = ConstellationMsg::TraverseHistory(Some(pipeline), direction); let _ = global_scope.constellation_chan().send(msg); + Ok(()) } } impl HistoryMethods for History { // https://html.spec.whatwg.org/multipage/#dom-history-length - fn Length(&self) -> u32 { + fn GetLength(&self) -> Fallible { + if !self.window.Document().is_fully_active() { + return Err(Error::Security); + } let global_scope = self.window.upcast::(); let pipeline = global_scope.pipeline_id(); let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length."); let msg = ConstellationMsg::JointSessionHistoryLength(pipeline, sender); let _ = global_scope.constellation_chan().send(msg); - recv.recv().unwrap() + Ok(recv.recv().unwrap()) } // https://html.spec.whatwg.org/multipage/#dom-history-go - fn Go(&self, delta: i32) -> Fallible<()> { + fn Go(&self, delta: i32) -> ErrorResult { let direction = if delta > 0 { TraversalDirection::Forward(delta as usize) } else if delta < 0 { @@ -69,17 +76,16 @@ impl HistoryMethods for History { return self.window.Location().Reload(); }; - self.traverse_history(direction); - Ok(()) + self.traverse_history(direction) } // https://html.spec.whatwg.org/multipage/#dom-history-back - fn Back(&self) { - self.traverse_history(TraversalDirection::Back(1)); + fn Back(&self) -> ErrorResult { + self.traverse_history(TraversalDirection::Back(1)) } // https://html.spec.whatwg.org/multipage/#dom-history-forward - fn Forward(&self) { - self.traverse_history(TraversalDirection::Forward(1)); + fn Forward(&self) -> ErrorResult { + self.traverse_history(TraversalDirection::Forward(1)) } } -- cgit v1.2.3 From 79743b5358c989da23c11c025509dd2c46dba48b Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Mon, 22 May 2017 09:40:17 -0500 Subject: Webdriver uses browsing context ids rather than pipeline ids. --- components/script/dom/history.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 5488d02d9bf..b9601d2ca1c 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -44,10 +44,9 @@ impl History { if !self.window.Document().is_fully_active() { return Err(Error::Security); } - let global_scope = self.window.upcast::(); - let pipeline = global_scope.pipeline_id(); - let msg = ConstellationMsg::TraverseHistory(Some(pipeline), direction); - let _ = global_scope.constellation_chan().send(msg); + let top_level_browsing_context_id = self.window.window_proxy().top_level_browsing_context_id(); + let msg = ConstellationMsg::TraverseHistory(top_level_browsing_context_id, direction); + let _ = self.window.upcast::().constellation_chan().send(msg); Ok(()) } } @@ -58,13 +57,12 @@ impl HistoryMethods for History { if !self.window.Document().is_fully_active() { return Err(Error::Security); } - let global_scope = self.window.upcast::(); - let pipeline = global_scope.pipeline_id(); + let top_level_browsing_context_id = self.window.window_proxy().top_level_browsing_context_id(); let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length."); - let msg = ConstellationMsg::JointSessionHistoryLength(pipeline, sender); - let _ = global_scope.constellation_chan().send(msg); + let msg = ConstellationMsg::JointSessionHistoryLength(top_level_browsing_context_id, sender); + let _ = self.window.upcast::().constellation_chan().send(msg); Ok(recv.recv().unwrap()) - } +} // https://html.spec.whatwg.org/multipage/#dom-history-go fn Go(&self, delta: i32) -> ErrorResult { -- cgit v1.2.3 From d2413891292bfb4d5f17d7eb1e3882e07f6ac626 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Tue, 18 Jul 2017 08:19:44 +0200 Subject: make use of ScriptToConstellationChan --- components/script/dom/history.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index b9601d2ca1c..9344f3f4b80 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -15,7 +15,7 @@ use dom::window::Window; use dom_struct::dom_struct; use ipc_channel::ipc; use msg::constellation_msg::TraversalDirection; -use script_traits::ScriptMsg as ConstellationMsg; +use script_traits::ScriptMsg; // https://html.spec.whatwg.org/multipage/#the-history-interface #[dom_struct] @@ -44,9 +44,8 @@ impl History { if !self.window.Document().is_fully_active() { return Err(Error::Security); } - let top_level_browsing_context_id = self.window.window_proxy().top_level_browsing_context_id(); - let msg = ConstellationMsg::TraverseHistory(top_level_browsing_context_id, direction); - let _ = self.window.upcast::().constellation_chan().send(msg); + let msg = ScriptMsg::TraverseHistory(direction); + let _ = self.window.upcast::().script_to_constellation_chan().send(msg); Ok(()) } } @@ -57,10 +56,9 @@ impl HistoryMethods for History { if !self.window.Document().is_fully_active() { return Err(Error::Security); } - let top_level_browsing_context_id = self.window.window_proxy().top_level_browsing_context_id(); let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length."); - let msg = ConstellationMsg::JointSessionHistoryLength(top_level_browsing_context_id, sender); - let _ = self.window.upcast::().constellation_chan().send(msg); + let msg = ScriptMsg::JointSessionHistoryLength(sender); + let _ = self.window.upcast::().script_to_constellation_chan().send(msg); Ok(recv.recv().unwrap()) } -- cgit v1.2.3 From 0e3c54c1911ba2c3bf305ee04f04fcd9bf2fc2fe Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 25 Sep 2017 23:30:24 +0200 Subject: Rename dom::bindings::js to dom::bindings::root --- components/script/dom/history.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 9344f3f4b80..bc22a3e3af2 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -8,8 +8,8 @@ use dom::bindings::codegen::Bindings::LocationBinding::LocationBinding::Location use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; -use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::root::{JS, Root}; use dom::globalscope::GlobalScope; use dom::window::Window; use dom_struct::dom_struct; -- cgit v1.2.3 From 7be32fb2371a14ba61b008a37e79761f66c073c7 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 25 Sep 2017 23:56:32 +0200 Subject: Rename JS to Dom --- components/script/dom/history.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index bc22a3e3af2..7cca59380b6 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; use dom::bindings::reflector::{Reflector, reflect_dom_object}; -use dom::bindings::root::{JS, Root}; +use dom::bindings::root::{Dom, Root}; use dom::globalscope::GlobalScope; use dom::window::Window; use dom_struct::dom_struct; @@ -21,14 +21,14 @@ use script_traits::ScriptMsg; #[dom_struct] pub struct History { reflector_: Reflector, - window: JS, + window: Dom, } impl History { pub fn new_inherited(window: &Window) -> History { History { reflector_: Reflector::new(), - window: JS::from_ref(&window), + window: Dom::from_ref(&window), } } -- cgit v1.2.3 From f87c2a8d7616112ca924e30292db2d244cf87eec Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 26 Sep 2017 01:53:40 +0200 Subject: Rename Root to DomRoot In a later PR, DomRoot will become a type alias of Root>, where Root will be able to handle all the things that need to be rooted that have a stable traceable address that doesn't move for the whole lifetime of the root. Stay tuned. --- components/script/dom/history.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 7cca59380b6..9e97a3d5e95 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; use dom::bindings::reflector::{Reflector, reflect_dom_object}; -use dom::bindings::root::{Dom, Root}; +use dom::bindings::root::{Dom, DomRoot}; use dom::globalscope::GlobalScope; use dom::window::Window; use dom_struct::dom_struct; @@ -32,7 +32,7 @@ impl History { } } - pub fn new(window: &Window) -> Root { + pub fn new(window: &Window) -> DomRoot { reflect_dom_object(box History::new_inherited(window), window, HistoryBinding::Wrap) -- cgit v1.2.3 From aa15dc269f41503d81ad44cd7e85d69e6f4aeac7 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 16 Oct 2017 14:35:30 +0200 Subject: Remove use of unstable box syntax. http://www.robohornet.org gives a score of 101.36 on master, and 102.68 with this PR. The latter is slightly better, but probably within noise level. So it looks like this PR does not affect DOM performance. This is expected since `Box::new` is defined as: ```rust impl Box { #[inline(always)] pub fn new(x: T) -> Box { box x } } ``` With inlining, it should compile to the same as box syntax. --- components/script/dom/history.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 9e97a3d5e95..71e8c0c7e4e 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -33,7 +33,7 @@ impl History { } pub fn new(window: &Window) -> DomRoot { - reflect_dom_object(box History::new_inherited(window), + reflect_dom_object(Box::new(History::new_inherited(window)), window, HistoryBinding::Wrap) } -- cgit v1.2.3 From 198ea8f7676d60fdb80b34304da700d51e1e04f8 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Thu, 26 Oct 2017 14:47:31 -0500 Subject: Implement initial part of history.state --- components/script/dom/history.rs | 94 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 71e8c0c7e4e..17ee0d29cb6 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -10,25 +10,38 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot}; +use dom::bindings::str::{DOMString, USVString}; +use dom::bindings::structuredclone::StructuredCloneData; use dom::globalscope::GlobalScope; use dom::window::Window; use dom_struct::dom_struct; use ipc_channel::ipc; +use js::jsapi::{HandleValue, Heap, JSContext}; +use js::jsval::{JSVal, NullValue, UndefinedValue}; use msg::constellation_msg::TraversalDirection; use script_traits::ScriptMsg; +enum PushOrReplace { + Push, + Replace, +} + // https://html.spec.whatwg.org/multipage/#the-history-interface #[dom_struct] pub struct History { reflector_: Reflector, window: Dom, + state: Heap, } impl History { pub fn new_inherited(window: &Window) -> History { + let state = Heap::default(); + state.set(NullValue()); History { reflector_: Reflector::new(), window: Dom::from_ref(&window), + state: state, } } @@ -48,9 +61,68 @@ impl History { let _ = self.window.upcast::().script_to_constellation_chan().send(msg); Ok(()) } + + // https://html.spec.whatwg.org/multipage/#dom-history-pushstate + // https://html.spec.whatwg.org/multipage/#dom-history-replacestate + fn push_or_replace_state(&self, + cx: *mut JSContext, + data: HandleValue, + _title: DOMString, + _url: Option, + _push_or_replace: PushOrReplace) -> ErrorResult { + // Step 1 + let document = self.window.Document(); + + // Step 2 + if !document.is_fully_active() { + return Err(Error::Security); + } + + // TODO: Step 3 Optionally abort these steps + // https://github.com/servo/servo/issues/19159 + + // TODO: Step 4 + + // Step 5 + let serialized_data = StructuredCloneData::write(cx, data)?; + + // TODO: Steps 6-7 Url Handling + // https://github.com/servo/servo/issues/19157 + + // TODO: Step 8 Push/Replace session history entry + // https://github.com/servo/servo/issues/19156 + + // TODO: Step 9 Update current entry to represent a GET request + // https://github.com/servo/servo/issues/19156 + + // TODO: Step 10 Set document's URL to new URL + // https://github.com/servo/servo/issues/19157 + + // Step 11 + let global_scope = self.window.upcast::(); + rooted!(in(cx) let mut state = UndefinedValue()); + serialized_data.read(&global_scope, state.handle_mut()); + + // Step 12 + self.state.set(state.get()); + + // TODO: Step 13 Update Document's latest entry to current entry + // https://github.com/servo/servo/issues/19158 + + Ok(()) + } } impl HistoryMethods for History { + // https://html.spec.whatwg.org/multipage/#dom-history-state + #[allow(unsafe_code)] + unsafe fn GetState(&self, _cx: *mut JSContext) -> Fallible { + if !self.window.Document().is_fully_active() { + return Err(Error::Security); + } + Ok(self.state.get()) + } + // https://html.spec.whatwg.org/multipage/#dom-history-length fn GetLength(&self) -> Fallible { if !self.window.Document().is_fully_active() { @@ -60,7 +132,7 @@ impl HistoryMethods for History { let msg = ScriptMsg::JointSessionHistoryLength(sender); let _ = self.window.upcast::().script_to_constellation_chan().send(msg); Ok(recv.recv().unwrap()) -} + } // https://html.spec.whatwg.org/multipage/#dom-history-go fn Go(&self, delta: i32) -> ErrorResult { @@ -84,4 +156,24 @@ impl HistoryMethods for History { fn Forward(&self) -> ErrorResult { self.traverse_history(TraversalDirection::Forward(1)) } + + // https://html.spec.whatwg.org/multipage/#dom-history-pushstate + #[allow(unsafe_code)] + unsafe fn PushState(&self, + cx: *mut JSContext, + data: HandleValue, + title: DOMString, + url: Option) -> ErrorResult { + self.push_or_replace_state(cx, data, title, url, PushOrReplace::Push) + } + + // https://html.spec.whatwg.org/multipage/#dom-history-replacestate + #[allow(unsafe_code)] + unsafe fn ReplaceState(&self, + cx: *mut JSContext, + data: HandleValue, + title: DOMString, + url: Option) -> ErrorResult { + self.push_or_replace_state(cx, data, title, url, PushOrReplace::Replace) + } } -- cgit v1.2.3 From 7d4e2b11e940545eaa74877b75908e1e02f6eeb5 Mon Sep 17 00:00:00 2001 From: Nakul Jindal Date: Mon, 26 Feb 2018 09:07:08 -0800 Subject: Implements profiler for blocked recv --- components/script/dom/history.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 17ee0d29cb6..d70c58963b5 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -8,17 +8,17 @@ use dom::bindings::codegen::Bindings::LocationBinding::LocationBinding::Location use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; -use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::str::{DOMString, USVString}; use dom::bindings::structuredclone::StructuredCloneData; use dom::globalscope::GlobalScope; use dom::window::Window; use dom_struct::dom_struct; -use ipc_channel::ipc; use js::jsapi::{HandleValue, Heap, JSContext}; use js::jsval::{JSVal, NullValue, UndefinedValue}; use msg::constellation_msg::TraversalDirection; +use profile_traits::ipc::channel; use script_traits::ScriptMsg; enum PushOrReplace { @@ -128,7 +128,8 @@ impl HistoryMethods for History { if !self.window.Document().is_fully_active() { return Err(Error::Security); } - let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length."); + let (sender, recv) = + channel(self.global().time_profiler_chan().clone()).expect("Failed to create channel to send jsh length."); let msg = ScriptMsg::JointSessionHistoryLength(sender); let _ = self.window.upcast::().script_to_constellation_chan().send(msg); Ok(recv.recv().unwrap()) -- cgit v1.2.3 From 356c57e628255ed338b32246ce5e7de75da621f0 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Wed, 28 Mar 2018 21:28:30 +0200 Subject: Adapt Servo for mozjs 0.6 and the changes introduced in servo/rust-mozjs#393 --- components/script/dom/history.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index d70c58963b5..4b296fb236f 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -15,8 +15,9 @@ use dom::bindings::structuredclone::StructuredCloneData; use dom::globalscope::GlobalScope; use dom::window::Window; use dom_struct::dom_struct; -use js::jsapi::{HandleValue, Heap, JSContext}; +use js::jsapi::{Heap, JSContext}; use js::jsval::{JSVal, NullValue, UndefinedValue}; +use js::rust::HandleValue; use msg::constellation_msg::TraversalDirection; use profile_traits::ipc::channel; use script_traits::ScriptMsg; -- cgit v1.2.3 From 17bd80a7b17e002e325985dbe3135a318f2fbaca Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Sat, 14 Apr 2018 01:53:11 -0500 Subject: Implement history state --- components/script/dom/history.rs | 78 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 6 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 4b296fb236f..b158a9d44fd 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -12,15 +12,20 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::str::{DOMString, USVString}; use dom::bindings::structuredclone::StructuredCloneData; +use dom::eventtarget::EventTarget; use dom::globalscope::GlobalScope; +use dom::popstateevent::PopStateEvent; use dom::window::Window; use dom_struct::dom_struct; use js::jsapi::{Heap, JSContext}; use js::jsval::{JSVal, NullValue, UndefinedValue}; use js::rust::HandleValue; -use msg::constellation_msg::TraversalDirection; +use msg::constellation_msg::{HistoryStateId, TraversalDirection}; +use net_traits::{CoreResourceMsg, IpcSend}; +use profile_traits::ipc; use profile_traits::ipc::channel; use script_traits::ScriptMsg; +use std::cell::Cell; enum PushOrReplace { Push, @@ -33,6 +38,7 @@ pub struct History { reflector_: Reflector, window: Dom, state: Heap, + state_id: Cell>, } impl History { @@ -43,6 +49,7 @@ impl History { reflector_: Reflector::new(), window: Dom::from_ref(&window), state: state, + state_id: Cell::new(None), } } @@ -63,6 +70,38 @@ impl History { Ok(()) } + #[allow(unsafe_code)] + pub fn activate_state(&self, state_id: Option) { + self.state_id.set(state_id); + let serialized_data = match state_id { + Some(state_id) => { + let (tx, rx) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap(); + let _ = self.window + .upcast::() + .resource_threads() + .send(CoreResourceMsg::GetHistoryState(state_id, tx)); + rx.recv().unwrap() + }, + None => None, + }; + + match serialized_data { + Some(serialized_data) => { + let global_scope = self.window.upcast::(); + rooted!(in(global_scope.get_cx()) let mut state = UndefinedValue()); + StructuredCloneData::Vector(serialized_data).read(&global_scope, state.handle_mut()); + self.state.set(state.get()); + }, + None => { + self.state.set(NullValue()); + } + } + + unsafe { + PopStateEvent::dispatch_jsval(self.window.upcast::(), &*self.window, self.state.handle()); + } + } + // https://html.spec.whatwg.org/multipage/#dom-history-pushstate // https://html.spec.whatwg.org/multipage/#dom-history-replacestate fn push_or_replace_state(&self, @@ -70,7 +109,7 @@ impl History { data: HandleValue, _title: DOMString, _url: Option, - _push_or_replace: PushOrReplace) -> ErrorResult { + push_or_replace: PushOrReplace) -> ErrorResult { // Step 1 let document = self.window.Document(); @@ -85,13 +124,40 @@ impl History { // TODO: Step 4 // Step 5 - let serialized_data = StructuredCloneData::write(cx, data)?; + let serialized_data = StructuredCloneData::write(cx, data)?.move_to_arraybuffer(); // TODO: Steps 6-7 Url Handling // https://github.com/servo/servo/issues/19157 - // TODO: Step 8 Push/Replace session history entry - // https://github.com/servo/servo/issues/19156 + // Step 8 + let state_id = match push_or_replace { + PushOrReplace::Push => { + let state_id = HistoryStateId::new(); + self.state_id.set(Some(state_id)); + let msg = ScriptMsg::PushHistoryState(state_id); + let _ = self.window.upcast::().script_to_constellation_chan().send(msg); + state_id + }, + PushOrReplace::Replace => { + let state_id = match self.state_id.get() { + Some(state_id) => state_id, + None => { + let state_id = HistoryStateId::new(); + self.state_id.set(Some(state_id)); + state_id + }, + }; + let msg = ScriptMsg::ReplaceHistoryState(state_id); + let _ = self.window.upcast::().script_to_constellation_chan().send(msg); + state_id + }, + }; + + let _ = self.window + .upcast::() + .resource_threads() + .send(CoreResourceMsg::SetHistoryState(state_id, serialized_data.clone())); + // TODO: Step 9 Update current entry to represent a GET request // https://github.com/servo/servo/issues/19156 @@ -102,7 +168,7 @@ impl History { // Step 11 let global_scope = self.window.upcast::(); rooted!(in(cx) let mut state = UndefinedValue()); - serialized_data.read(&global_scope, state.handle_mut()); + StructuredCloneData::Vector(serialized_data).read(&global_scope, state.handle_mut()); // Step 12 self.state.set(state.get()); -- cgit v1.2.3 From c08ad456818a1e73dee3a14a4a0706774ffd2a59 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Tue, 17 Apr 2018 19:21:51 -0500 Subject: Remove insaccessible history states --- components/script/dom/history.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index b158a9d44fd..e18e06cecea 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -102,6 +102,13 @@ impl History { } } + pub fn remove_states(&self, states: Vec) { + let _ = self.window + .upcast::() + .resource_threads() + .send(CoreResourceMsg::RemoveHistoryStates(states)); + } + // https://html.spec.whatwg.org/multipage/#dom-history-pushstate // https://html.spec.whatwg.org/multipage/#dom-history-replacestate fn push_or_replace_state(&self, -- cgit v1.2.3 From 68c4791c7d5ff71e60ab0edf966e9888a945b1a3 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Wed, 18 Apr 2018 13:30:22 -0700 Subject: History: update document URL on pushState/replaceState https://html.spec.whatwg.org/multipage/#dom-history-pushstate Steps 6, 7, 10 --- components/script/dom/history.rs | 44 +++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index b158a9d44fd..a4ba5886373 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -25,6 +25,7 @@ use net_traits::{CoreResourceMsg, IpcSend}; use profile_traits::ipc; use profile_traits::ipc::channel; use script_traits::ScriptMsg; +use servo_url::ServoUrl; use std::cell::Cell; enum PushOrReplace { @@ -108,7 +109,7 @@ impl History { cx: *mut JSContext, data: HandleValue, _title: DOMString, - _url: Option, + url: Option, push_or_replace: PushOrReplace) -> ErrorResult { // Step 1 let document = self.window.Document(); @@ -126,8 +127,41 @@ impl History { // Step 5 let serialized_data = StructuredCloneData::write(cx, data)?.move_to_arraybuffer(); - // TODO: Steps 6-7 Url Handling - // https://github.com/servo/servo/issues/19157 + let new_url: ServoUrl = match url { + // Step 6 + Some(urlstring) => { + let document_url = document.url(); + + // Step 6.1 + let new_url = match ServoUrl::parse_with_base(Some(&document_url), &urlstring.0) { + // Step 6.3 + Ok(parsed_url) => parsed_url, + // Step 6.2 + Err(_) => return Err(Error::Security), + }; + + // Step 6.4 + if new_url.scheme() != document_url.scheme() || + new_url.host() != document_url.host() || + new_url.port() != document_url.port() || + new_url.username() != document_url.username() || + new_url.password() != document_url.password() + { + return Err(Error::Security); + } + + // Step 6.5 + if new_url.origin() != document_url.origin() { + return Err(Error::Security); + } + + new_url + }, + // Step 7 + None => { + document.url() + } + }; // Step 8 let state_id = match push_or_replace { @@ -162,8 +196,8 @@ impl History { // TODO: Step 9 Update current entry to represent a GET request // https://github.com/servo/servo/issues/19156 - // TODO: Step 10 Set document's URL to new URL - // https://github.com/servo/servo/issues/19157 + // Step 10 + document.set_url(new_url); // Step 11 let global_scope = self.window.upcast::(); -- cgit v1.2.3 From e7ef9cfb303598e582f0f589da855bdd33c1dd08 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Fri, 20 Apr 2018 22:44:59 -0500 Subject: Make session history aware of URLs --- components/script/dom/history.rs | 44 +++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 46288fffb07..51f9a42c06c 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -12,8 +12,10 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::str::{DOMString, USVString}; use dom::bindings::structuredclone::StructuredCloneData; +use dom::event::Event; use dom::eventtarget::EventTarget; use dom::globalscope::GlobalScope; +use dom::hashchangeevent::HashChangeEvent; use dom::popstateevent::PopStateEvent; use dom::window::Window; use dom_struct::dom_struct; @@ -71,8 +73,22 @@ impl History { Ok(()) } + // https://html.spec.whatwg.org/multipage/#history-traversal + // Steps 5-16 #[allow(unsafe_code)] - pub fn activate_state(&self, state_id: Option) { + pub fn activate_state(&self, state_id: Option, url: ServoUrl) { + // Steps 5 + let document = self.window.Document(); + let old_url = document.url().clone(); + document.set_url(url.clone()); + + // Step 6 + let hash_changed = old_url.fragment() != url.fragment(); + + // TODO: Step 8 - scroll restoration + + // Step 11 + let state_changed = state_id != self.state_id.get(); self.state_id.set(state_id); let serialized_data = match state_id { Some(state_id) => { @@ -98,8 +114,26 @@ impl History { } } - unsafe { - PopStateEvent::dispatch_jsval(self.window.upcast::(), &*self.window, self.state.handle()); + // TODO: Queue events on DOM Manipulation task source if non-blocking flag is set. + // Step 16.1 + if state_changed { + PopStateEvent::dispatch_jsval( + self.window.upcast::(), + &*self.window, + unsafe { self.state.handle() } + ); + } + + // Step 16.3 + if hash_changed { + let event = HashChangeEvent::new( + &self.window, + atom!("hashchange"), + true, + false, + old_url.into_string(), + url.into_string()); + event.upcast::().fire(self.window.upcast::()); } } @@ -175,7 +209,7 @@ impl History { PushOrReplace::Push => { let state_id = HistoryStateId::new(); self.state_id.set(Some(state_id)); - let msg = ScriptMsg::PushHistoryState(state_id); + let msg = ScriptMsg::PushHistoryState(state_id, new_url.clone()); let _ = self.window.upcast::().script_to_constellation_chan().send(msg); state_id }, @@ -188,7 +222,7 @@ impl History { state_id }, }; - let msg = ScriptMsg::ReplaceHistoryState(state_id); + let msg = ScriptMsg::ReplaceHistoryState(state_id, new_url.clone()); let _ = self.window.upcast::().script_to_constellation_chan().send(msg); state_id }, -- cgit v1.2.3 From d0cc9d2cd56a197fdfb72d8c0168d4cf2bb23bdb Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 30 May 2018 14:44:47 -0500 Subject: Updated to mozjs v0.7.1. --- components/script/dom/history.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 51f9a42c06c..1f3b652b0e9 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -120,7 +120,7 @@ impl History { PopStateEvent::dispatch_jsval( self.window.upcast::(), &*self.window, - unsafe { self.state.handle() } + unsafe { HandleValue::from_raw(self.state.handle()) } ); } -- cgit v1.2.3 From ecb65474a79684a0f84694336297d24e746dfc3e Mon Sep 17 00:00:00 2001 From: tigercosmos Date: Sun, 17 Jun 2018 11:13:36 -0700 Subject: Let the popstate and hashchange events not bubble --- components/script/dom/history.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 1f3b652b0e9..369c59b524c 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -129,7 +129,7 @@ impl History { let event = HashChangeEvent::new( &self.window, atom!("hashchange"), - true, + false, false, old_url.into_string(), url.into_string()); -- cgit v1.2.3 From 61442cce4b93ef6b88b4ce59bad2358e8ce8bf4e Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Tue, 12 Jun 2018 22:12:17 +0200 Subject: Track hash changes in session history Notify history changed on pushState and scroll to frag --- components/script/dom/history.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 369c59b524c..939cf9a8c20 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -85,7 +85,10 @@ impl History { // Step 6 let hash_changed = old_url.fragment() != url.fragment(); - // TODO: Step 8 - scroll restoration + // Step 8 + if let Some(fragment) = url.fragment() { + document.check_and_scroll_fragment(fragment); + } // Step 11 let state_changed = state_id != self.state_id.get(); -- cgit v1.2.3 From c37a345dc9f4dda6ea29c42f96f6c7201c42cbac Mon Sep 17 00:00:00 2001 From: chansuke Date: Tue, 18 Sep 2018 23:24:15 +0900 Subject: Format script component --- components/script/dom/history.rs | 116 ++++++++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 45 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 939cf9a8c20..ee5c38e8c89 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -57,9 +57,11 @@ impl History { } pub fn new(window: &Window) -> DomRoot { - reflect_dom_object(Box::new(History::new_inherited(window)), - window, - HistoryBinding::Wrap) + reflect_dom_object( + Box::new(History::new_inherited(window)), + window, + HistoryBinding::Wrap, + ) } } @@ -69,7 +71,11 @@ impl History { return Err(Error::Security); } let msg = ScriptMsg::TraverseHistory(direction); - let _ = self.window.upcast::().script_to_constellation_chan().send(msg); + let _ = self + .window + .upcast::() + .script_to_constellation_chan() + .send(msg); Ok(()) } @@ -83,7 +89,7 @@ impl History { document.set_url(url.clone()); // Step 6 - let hash_changed = old_url.fragment() != url.fragment(); + let hash_changed = old_url.fragment() != url.fragment(); // Step 8 if let Some(fragment) = url.fragment() { @@ -96,7 +102,8 @@ impl History { let serialized_data = match state_id { Some(state_id) => { let (tx, rx) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap(); - let _ = self.window + let _ = self + .window .upcast::() .resource_threads() .send(CoreResourceMsg::GetHistoryState(state_id, tx)); @@ -109,12 +116,13 @@ impl History { Some(serialized_data) => { let global_scope = self.window.upcast::(); rooted!(in(global_scope.get_cx()) let mut state = UndefinedValue()); - StructuredCloneData::Vector(serialized_data).read(&global_scope, state.handle_mut()); + StructuredCloneData::Vector(serialized_data) + .read(&global_scope, state.handle_mut()); self.state.set(state.get()); }, None => { self.state.set(NullValue()); - } + }, } // TODO: Queue events on DOM Manipulation task source if non-blocking flag is set. @@ -123,7 +131,7 @@ impl History { PopStateEvent::dispatch_jsval( self.window.upcast::(), &*self.window, - unsafe { HandleValue::from_raw(self.state.handle()) } + unsafe { HandleValue::from_raw(self.state.handle()) }, ); } @@ -135,13 +143,17 @@ impl History { false, false, old_url.into_string(), - url.into_string()); - event.upcast::().fire(self.window.upcast::()); + url.into_string(), + ); + event + .upcast::() + .fire(self.window.upcast::()); } } pub fn remove_states(&self, states: Vec) { - let _ = self.window + let _ = self + .window .upcast::() .resource_threads() .send(CoreResourceMsg::RemoveHistoryStates(states)); @@ -149,12 +161,14 @@ impl History { // https://html.spec.whatwg.org/multipage/#dom-history-pushstate // https://html.spec.whatwg.org/multipage/#dom-history-replacestate - fn push_or_replace_state(&self, - cx: *mut JSContext, - data: HandleValue, - _title: DOMString, - url: Option, - push_or_replace: PushOrReplace) -> ErrorResult { + fn push_or_replace_state( + &self, + cx: *mut JSContext, + data: HandleValue, + _title: DOMString, + url: Option, + push_or_replace: PushOrReplace, + ) -> ErrorResult { // Step 1 let document = self.window.Document(); @@ -186,10 +200,10 @@ impl History { // Step 6.4 if new_url.scheme() != document_url.scheme() || - new_url.host() != document_url.host() || - new_url.port() != document_url.port() || - new_url.username() != document_url.username() || - new_url.password() != document_url.password() + new_url.host() != document_url.host() || + new_url.port() != document_url.port() || + new_url.username() != document_url.username() || + new_url.password() != document_url.password() { return Err(Error::Security); } @@ -202,9 +216,7 @@ impl History { new_url }, // Step 7 - None => { - document.url() - } + None => document.url(), }; // Step 8 @@ -213,7 +225,11 @@ impl History { let state_id = HistoryStateId::new(); self.state_id.set(Some(state_id)); let msg = ScriptMsg::PushHistoryState(state_id, new_url.clone()); - let _ = self.window.upcast::().script_to_constellation_chan().send(msg); + let _ = self + .window + .upcast::() + .script_to_constellation_chan() + .send(msg); state_id }, PushOrReplace::Replace => { @@ -226,16 +242,18 @@ impl History { }, }; let msg = ScriptMsg::ReplaceHistoryState(state_id, new_url.clone()); - let _ = self.window.upcast::().script_to_constellation_chan().send(msg); + let _ = self + .window + .upcast::() + .script_to_constellation_chan() + .send(msg); state_id }, }; - let _ = self.window - .upcast::() - .resource_threads() - .send(CoreResourceMsg::SetHistoryState(state_id, serialized_data.clone())); - + let _ = self.window.upcast::().resource_threads().send( + CoreResourceMsg::SetHistoryState(state_id, serialized_data.clone()), + ); // TODO: Step 9 Update current entry to represent a GET request // https://github.com/servo/servo/issues/19156 @@ -273,10 +291,14 @@ impl HistoryMethods for History { if !self.window.Document().is_fully_active() { return Err(Error::Security); } - let (sender, recv) = - channel(self.global().time_profiler_chan().clone()).expect("Failed to create channel to send jsh length."); + let (sender, recv) = channel(self.global().time_profiler_chan().clone()) + .expect("Failed to create channel to send jsh length."); let msg = ScriptMsg::JointSessionHistoryLength(sender); - let _ = self.window.upcast::().script_to_constellation_chan().send(msg); + let _ = self + .window + .upcast::() + .script_to_constellation_chan() + .send(msg); Ok(recv.recv().unwrap()) } @@ -305,21 +327,25 @@ impl HistoryMethods for History { // https://html.spec.whatwg.org/multipage/#dom-history-pushstate #[allow(unsafe_code)] - unsafe fn PushState(&self, - cx: *mut JSContext, - data: HandleValue, - title: DOMString, - url: Option) -> ErrorResult { + unsafe fn PushState( + &self, + cx: *mut JSContext, + data: HandleValue, + title: DOMString, + url: Option, + ) -> ErrorResult { self.push_or_replace_state(cx, data, title, url, PushOrReplace::Push) } // https://html.spec.whatwg.org/multipage/#dom-history-replacestate #[allow(unsafe_code)] - unsafe fn ReplaceState(&self, - cx: *mut JSContext, - data: HandleValue, - title: DOMString, - url: Option) -> ErrorResult { + unsafe fn ReplaceState( + &self, + cx: *mut JSContext, + data: HandleValue, + title: DOMString, + url: Option, + ) -> ErrorResult { self.push_or_replace_state(cx, data, title, url, PushOrReplace::Replace) } } -- cgit v1.2.3 From 45f7199eee82c66637ec68287eafa40a651001c4 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 1 Nov 2018 23:45:06 +0100 Subject: `cargo fix --edition` --- components/script/dom/history.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index ee5c38e8c89..b23b4a2d330 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -2,22 +2,22 @@ * 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::LocationBinding::LocationMethods; -use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::error::{Error, ErrorResult, Fallible}; -use dom::bindings::inheritance::Castable; -use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; -use dom::bindings::root::{Dom, DomRoot}; -use dom::bindings::str::{DOMString, USVString}; -use dom::bindings::structuredclone::StructuredCloneData; -use dom::event::Event; -use dom::eventtarget::EventTarget; -use dom::globalscope::GlobalScope; -use dom::hashchangeevent::HashChangeEvent; -use dom::popstateevent::PopStateEvent; -use dom::window::Window; +use crate::dom::bindings::codegen::Bindings::HistoryBinding; +use crate::dom::bindings::codegen::Bindings::HistoryBinding::HistoryMethods; +use crate::dom::bindings::codegen::Bindings::LocationBinding::LocationBinding::LocationMethods; +use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use crate::dom::bindings::error::{Error, ErrorResult, Fallible}; +use crate::dom::bindings::inheritance::Castable; +use crate::dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::bindings::str::{DOMString, USVString}; +use crate::dom::bindings::structuredclone::StructuredCloneData; +use crate::dom::event::Event; +use crate::dom::eventtarget::EventTarget; +use crate::dom::globalscope::GlobalScope; +use crate::dom::hashchangeevent::HashChangeEvent; +use crate::dom::popstateevent::PopStateEvent; +use crate::dom::window::Window; use dom_struct::dom_struct; use js::jsapi::{Heap, JSContext}; use js::jsval::{JSVal, NullValue, UndefinedValue}; -- cgit v1.2.3 From 9e92eb205a2a12fe0be883e42cb7f82deebc9031 Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Tue, 6 Nov 2018 20:38:02 +0100 Subject: Reorder imports --- components/script/dom/history.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index b23b4a2d330..da0e1c325b8 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::LocationBinding::LocationBinding::L use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use crate::dom::bindings::error::{Error, ErrorResult, Fallible}; use crate::dom::bindings::inheritance::Castable; -use crate::dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; +use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::{DOMString, USVString}; use crate::dom::bindings::structuredclone::StructuredCloneData; -- cgit v1.2.3 From a1a14459c141afc6ac6771b8a6c9ca374537edf2 Mon Sep 17 00:00:00 2001 From: Jan Andre Ikenmeyer Date: Mon, 19 Nov 2018 14:47:12 +0100 Subject: Update MPL license to https (part 3) --- components/script/dom/history.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index da0e1c325b8..e468b79440c 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -1,6 +1,6 @@ /* 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/. */ + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::dom::bindings::codegen::Bindings::HistoryBinding; use crate::dom::bindings::codegen::Bindings::HistoryBinding::HistoryMethods; -- cgit v1.2.3 From 57d2b5a92df4348ba6131691fc41b05148bf5904 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 27 Mar 2019 14:18:18 -0400 Subject: Remove mozjs dep from malloc_size_of. --- components/script/dom/history.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index e468b79440c..787591af8a3 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -40,6 +40,7 @@ enum PushOrReplace { pub struct History { reflector_: Reflector, window: Dom, + #[ignore_malloc_size_of = "mozjs"] state: Heap, state_id: Cell>, } -- cgit v1.2.3 From 2c5d0a6ebc39ad263e2bbe623e357a11b4cec5aa Mon Sep 17 00:00:00 2001 From: marmeladema Date: Mon, 22 Jul 2019 01:09:24 +0100 Subject: Convert CGTraitInterface to use safe JSContext instead of raw JSContext --- components/script/dom/history.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 787591af8a3..4bbcba64bad 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -18,6 +18,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::hashchangeevent::HashChangeEvent; use crate::dom::popstateevent::PopStateEvent; use crate::dom::window::Window; +use crate::script_runtime::JSContext as SafeJSContext; use dom_struct::dom_struct; use js::jsapi::{Heap, JSContext}; use js::jsval::{JSVal, NullValue, UndefinedValue}; @@ -279,8 +280,7 @@ impl History { impl HistoryMethods for History { // https://html.spec.whatwg.org/multipage/#dom-history-state - #[allow(unsafe_code)] - unsafe fn GetState(&self, _cx: *mut JSContext) -> Fallible { + fn GetState(&self, _cx: SafeJSContext) -> Fallible { if !self.window.Document().is_fully_active() { return Err(Error::Security); } @@ -327,26 +327,24 @@ impl HistoryMethods for History { } // https://html.spec.whatwg.org/multipage/#dom-history-pushstate - #[allow(unsafe_code)] - unsafe fn PushState( + fn PushState( &self, - cx: *mut JSContext, + cx: SafeJSContext, data: HandleValue, title: DOMString, url: Option, ) -> ErrorResult { - self.push_or_replace_state(cx, data, title, url, PushOrReplace::Push) + self.push_or_replace_state(*cx, data, title, url, PushOrReplace::Push) } // https://html.spec.whatwg.org/multipage/#dom-history-replacestate - #[allow(unsafe_code)] - unsafe fn ReplaceState( + fn ReplaceState( &self, - cx: *mut JSContext, + cx: SafeJSContext, data: HandleValue, title: DOMString, url: Option, ) -> ErrorResult { - self.push_or_replace_state(cx, data, title, url, PushOrReplace::Replace) + self.push_or_replace_state(*cx, data, title, url, PushOrReplace::Replace) } } -- cgit v1.2.3 From 88cacfb0098e20be70c27bfde6b74cd3290f1fe4 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Mon, 22 Jul 2019 22:14:11 +0100 Subject: Modify *::get_cx methods to return a safe JSContext instead of a raw one --- components/script/dom/history.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 4bbcba64bad..583c58a00f1 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -117,7 +117,7 @@ impl History { match serialized_data { Some(serialized_data) => { let global_scope = self.window.upcast::(); - rooted!(in(global_scope.get_cx()) let mut state = UndefinedValue()); + rooted!(in(*global_scope.get_cx()) let mut state = UndefinedValue()); StructuredCloneData::Vector(serialized_data) .read(&global_scope, state.handle_mut()); self.state.set(state.get()); -- cgit v1.2.3 From d1282dc8cce120189f0c72b98f790561df557728 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sat, 27 Jul 2019 15:31:06 +0100 Subject: Remove some usage of unsafe code in History --- components/script/dom/history.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 583c58a00f1..92c27dfb82d 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -18,9 +18,9 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::hashchangeevent::HashChangeEvent; use crate::dom::popstateevent::PopStateEvent; use crate::dom::window::Window; -use crate::script_runtime::JSContext as SafeJSContext; +use crate::script_runtime::JSContext; use dom_struct::dom_struct; -use js::jsapi::{Heap, JSContext}; +use js::jsapi::Heap; use js::jsval::{JSVal, NullValue, UndefinedValue}; use js::rust::HandleValue; use msg::constellation_msg::{HistoryStateId, TraversalDirection}; @@ -165,7 +165,7 @@ impl History { // https://html.spec.whatwg.org/multipage/#dom-history-replacestate fn push_or_replace_state( &self, - cx: *mut JSContext, + cx: JSContext, data: HandleValue, _title: DOMString, url: Option, @@ -185,7 +185,7 @@ impl History { // TODO: Step 4 // Step 5 - let serialized_data = StructuredCloneData::write(cx, data)?.move_to_arraybuffer(); + let serialized_data = StructuredCloneData::write(*cx, data)?.move_to_arraybuffer(); let new_url: ServoUrl = match url { // Step 6 @@ -265,7 +265,7 @@ impl History { // Step 11 let global_scope = self.window.upcast::(); - rooted!(in(cx) let mut state = UndefinedValue()); + rooted!(in(*cx) let mut state = UndefinedValue()); StructuredCloneData::Vector(serialized_data).read(&global_scope, state.handle_mut()); // Step 12 @@ -280,7 +280,7 @@ impl History { impl HistoryMethods for History { // https://html.spec.whatwg.org/multipage/#dom-history-state - fn GetState(&self, _cx: SafeJSContext) -> Fallible { + fn GetState(&self, _cx: JSContext) -> Fallible { if !self.window.Document().is_fully_active() { return Err(Error::Security); } @@ -329,22 +329,22 @@ impl HistoryMethods for History { // https://html.spec.whatwg.org/multipage/#dom-history-pushstate fn PushState( &self, - cx: SafeJSContext, + cx: JSContext, data: HandleValue, title: DOMString, url: Option, ) -> ErrorResult { - self.push_or_replace_state(*cx, data, title, url, PushOrReplace::Push) + self.push_or_replace_state(cx, data, title, url, PushOrReplace::Push) } // https://html.spec.whatwg.org/multipage/#dom-history-replacestate fn ReplaceState( &self, - cx: SafeJSContext, + cx: JSContext, data: HandleValue, title: DOMString, url: Option, ) -> ErrorResult { - self.push_or_replace_state(*cx, data, title, url, PushOrReplace::Replace) + self.push_or_replace_state(cx, data, title, url, PushOrReplace::Replace) } } -- cgit v1.2.3 From c3b17c1201441c9a24c4b272108aea0196fbf1b9 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sun, 11 Dec 2016 03:52:08 -0800 Subject: begin messageport, transferable objects, impl Accept transfer argument for StructuredCloneData::write Allow structured clone reads to return a boolean Add Transferable trait Add basic skeletons to MessagePort Implement transfer and transfer-receiving steps on MessagePort Use transfer and transfer_receive in StructuredClone callbacks Implement MessageChannel Freeze the array object for the MessageEvent ports attribute Implement transfer argument on window.postMessage Use ReentrantMutex instead for MessagePortInternal Accept origin as a parameter in dispatch_jsval Fix BorrowMut crash with pending_port_message Detach port on closure and check for detached during transfer Enable webmessaging tests fix webidl fix --- components/script/dom/history.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 92c27dfb82d..05dff680c2c 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -185,7 +185,8 @@ impl History { // TODO: Step 4 // Step 5 - let serialized_data = StructuredCloneData::write(*cx, data)?.move_to_arraybuffer(); + rooted!(in(cx) let transfer = UndefinedValue()); + let serialized_data = StructuredCloneData::write(*cx, data, transfer.handle())?.move_to_arraybuffer(); let new_url: ServoUrl = match url { // Step 6 -- cgit v1.2.3 From 2f8932a6a1e2666567435114383b3acd1899aca7 Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Wed, 26 Jun 2019 00:25:48 +0800 Subject: continue messageport, transferable, postmessage options --- components/script/dom/history.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 05dff680c2c..c02cdb42472 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -11,7 +11,7 @@ use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::{DOMString, USVString}; -use crate::dom::bindings::structuredclone::StructuredCloneData; +use crate::dom::bindings::structuredclone; use crate::dom::event::Event; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; @@ -27,7 +27,7 @@ use msg::constellation_msg::{HistoryStateId, TraversalDirection}; use net_traits::{CoreResourceMsg, IpcSend}; use profile_traits::ipc; use profile_traits::ipc::channel; -use script_traits::ScriptMsg; +use script_traits::{ScriptMsg, StructuredSerializedData}; use servo_url::ServoUrl; use std::cell::Cell; @@ -115,11 +115,16 @@ impl History { }; match serialized_data { - Some(serialized_data) => { + Some(data) => { + let data = StructuredSerializedData { + serialized: data, + ports: None, + }; let global_scope = self.window.upcast::(); rooted!(in(*global_scope.get_cx()) let mut state = UndefinedValue()); - StructuredCloneData::Vector(serialized_data) - .read(&global_scope, state.handle_mut()); + if let Err(_) = structuredclone::read(&global_scope, data, state.handle_mut()) { + warn!("Error reading structuredclone data"); + } self.state.set(state.get()); }, None => { @@ -185,8 +190,7 @@ impl History { // TODO: Step 4 // Step 5 - rooted!(in(cx) let transfer = UndefinedValue()); - let serialized_data = StructuredCloneData::write(*cx, data, transfer.handle())?.move_to_arraybuffer(); + let serialized_data = structuredclone::write(cx, data, None)?; let new_url: ServoUrl = match url { // Step 6 @@ -255,7 +259,7 @@ impl History { }; let _ = self.window.upcast::().resource_threads().send( - CoreResourceMsg::SetHistoryState(state_id, serialized_data.clone()), + CoreResourceMsg::SetHistoryState(state_id, serialized_data.serialized.clone()), ); // TODO: Step 9 Update current entry to represent a GET request @@ -267,7 +271,9 @@ impl History { // Step 11 let global_scope = self.window.upcast::(); rooted!(in(*cx) let mut state = UndefinedValue()); - StructuredCloneData::Vector(serialized_data).read(&global_scope, state.handle_mut()); + if let Err(_) = structuredclone::read(&global_scope, serialized_data, state.handle_mut()) { + warn!("Error reading structuredclone data"); + } // Step 12 self.state.set(state.get()); -- cgit v1.2.3 From 6e8a85482c2068d4dbccb992954271f725570f91 Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Sun, 1 Sep 2019 03:18:42 +0800 Subject: re-structure blob, structured serialization --- components/script/dom/history.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index c02cdb42472..ef7a6fbe916 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -119,6 +119,7 @@ impl History { let data = StructuredSerializedData { serialized: data, ports: None, + blobs: None, }; let global_scope = self.window.upcast::(); rooted!(in(*global_scope.get_cx()) let mut state = UndefinedValue()); -- cgit v1.2.3 From 3ea6d87bcc37167464e856949a4b9b77d0e9318a Mon Sep 17 00:00:00 2001 From: YUAN LYU Date: Fri, 20 Mar 2020 22:14:18 -0400 Subject: Add trait DomObjectWrap to provide WRAP function --- components/script/dom/history.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'components/script/dom/history.rs') diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index ef7a6fbe916..9023a397c66 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -2,7 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use crate::dom::bindings::codegen::Bindings::HistoryBinding; use crate::dom::bindings::codegen::Bindings::HistoryBinding::HistoryMethods; use crate::dom::bindings::codegen::Bindings::LocationBinding::LocationBinding::LocationMethods; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; @@ -59,11 +58,7 @@ impl History { } pub fn new(window: &Window) -> DomRoot { - reflect_dom_object( - Box::new(History::new_inherited(window)), - window, - HistoryBinding::Wrap, - ) + reflect_dom_object(Box::new(History::new_inherited(window)), window) } } -- cgit v1.2.3