diff options
author | Connor Brewster <connor.brewster@eagles.oc.edu> | 2017-10-26 14:47:31 -0500 |
---|---|---|
committer | Connor Brewster <connor.brewster@eagles.oc.edu> | 2018-01-30 14:12:37 -0600 |
commit | 198ea8f7676d60fdb80b34304da700d51e1e04f8 (patch) | |
tree | ff8496606b3ca15ad8948aba980c1e382d09dbf8 | |
parent | 76b4e5cefb68e64a1bb2df78b32b05eba41eb678 (diff) | |
download | servo-198ea8f7676d60fdb80b34304da700d51e1e04f8.tar.gz servo-198ea8f7676d60fdb80b34304da700d51e1e04f8.zip |
Implement initial part of history.state
26 files changed, 130 insertions, 105 deletions
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<Window>, + state: Heap<JSVal>, } 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::<GlobalScope>().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<USVString>, + _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::<GlobalScope>(); + 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<JSVal> { + 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<u32> { if !self.window.Document().is_fully_active() { @@ -60,7 +132,7 @@ impl HistoryMethods for History { let msg = ScriptMsg::JointSessionHistoryLength(sender); let _ = self.window.upcast::<GlobalScope>().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<USVString>) -> 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<USVString>) -> ErrorResult { + self.push_or_replace_state(cx, data, title, url, PushOrReplace::Replace) + } } diff --git a/components/script/dom/webidls/History.webidl b/components/script/dom/webidls/History.webidl index d5b72996182..f22b3ab882e 100644 --- a/components/script/dom/webidls/History.webidl +++ b/components/script/dom/webidls/History.webidl @@ -11,16 +11,16 @@ interface History { readonly attribute unsigned long length; // [Throws] // attribute ScrollRestoration scrollRestoration; - // [Throws] - // readonly attribute any state; + [Throws] + readonly attribute any state; [Throws] void go(optional long delta = 0); [Throws] void back(); [Throws] void forward(); - // [Throws] - // void pushState(any data, DOMString title, optional USVString? url = null); - // [Throws] - // void replaceState(any data, DOMString title, optional USVString? url = null); + [Throws] + void pushState(any data, DOMString title, optional USVString? url = null); + [Throws] + void replaceState(any data, DOMString title, optional USVString? url = null); }; diff --git a/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-samedoc.html.ini b/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-samedoc.html.ini index 3322eb2c441..05ee8e95625 100644 --- a/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-samedoc.html.ini +++ b/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-samedoc.html.ini @@ -1,5 +1,7 @@ [scroll-restoration-fragment-scrolling-samedoc.html] type: testharness + expected: TIMEOUT + bug: https://github.com/servo/servo/issues/14970 [Manual scroll restoration should take precedent over scrolling to fragment in cross doc navigation] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-samedoc.html.ini b/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-samedoc.html.ini index a83f5e92d92..f12bd68a787 100644 --- a/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-samedoc.html.ini +++ b/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-samedoc.html.ini @@ -1,5 +1,7 @@ [scroll-restoration-navigation-samedoc.html] type: testharness + expected: TIMEOUT + bug: https://github.com/servo/servo/issues/14970 [history.{push,replace}State retain scroll restoration mode and navigation in the same document respects it] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/popstate_event.html.ini b/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/popstate_event.html.ini index bbe5b73b922..73a5f162254 100644 --- a/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/popstate_event.html.ini +++ b/tests/wpt/metadata/html/browsers/browsing-the-web/history-traversal/popstate_event.html.ini @@ -1,5 +1,7 @@ [popstate_event.html] type: testharness + expected: TIMEOUT + bug: https://github.com/servo/servo/issues/19905 [Queue a task to fire popstate event] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/005.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/005.html.ini index 76099606688..230bbac6edb 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/005.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/005.html.ini @@ -1,8 +1,5 @@ [005.html] type: testharness - [history.pushState support is needed for this testcase] - expected: FAIL - [<body onpopstate="..."> should register a listener for the popstate event] expected: FAIL diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/006.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/006.html.ini deleted file mode 100644 index 505c9b8cf83..00000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/006.html.ini +++ /dev/null @@ -1,14 +0,0 @@ -[006.html] - type: testharness - [history.state should initially be null] - expected: FAIL - - [history.state should still be null onload] - expected: FAIL - - [history.state should still be null after onload] - expected: FAIL - - [writing to history.state should be silently ignored and not throw an error] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/007.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/007.html.ini index 5c3b95e454e..b50f240fd73 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/007.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/007.html.ini @@ -1,14 +1,5 @@ [007.html] type: testharness - [history.state should initially be null] - expected: FAIL - - [history.pushState support is needed for this testcase] - expected: FAIL - - [history.state should reflect pushed state] - expected: FAIL - [popstate event should fire before onload fires] expected: FAIL diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/011.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/011.html.ini index 0867b0401e0..70ac6b2b422 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/011.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/011.html.ini @@ -1,8 +1,5 @@ [011.html] type: testharness - [pushState should be able to set the location state] - expected: FAIL - [pushed location should be reflected immediately] expected: FAIL diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/012.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/012.html.ini index b153bc5f21c..6d4c74df6ee 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/012.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/012.html.ini @@ -1,8 +1,5 @@ [012.html] type: testharness - [replaceState should be able to set the location state] - expected: FAIL - [replaced location should be reflected immediately] expected: FAIL diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_001.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_001.html.ini deleted file mode 100644 index 6c1948b3884..00000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_001.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[combination_history_001.html] - type: testharness - [Combine pushState and replaceSate methods] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_004.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_004.html.ini index 703bccbb334..51df5f93945 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_004.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_004.html.ini @@ -1,5 +1,6 @@ [combination_history_004.html] type: testharness + expected: TIMEOUT [After calling of back method, check length] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_005.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_005.html.ini index 969bd2d84f1..07e75fb2f31 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_005.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_005.html.ini @@ -1,5 +1,6 @@ [combination_history_005.html] type: testharness + expected: TIMEOUT [After calling of forward method, check length] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_006.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_006.html.ini index 416b9e58d13..74fbd209238 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_006.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_006.html.ini @@ -1,5 +1,6 @@ [combination_history_006.html] type: testharness + expected: TIMEOUT [After calling of go method, check length] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_007.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_007.html.ini index 5db6960533d..3d6c729c91e 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_007.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/combination_history_007.html.ini @@ -1,5 +1,6 @@ [combination_history_007.html] type: testharness + expected: TIMEOUT [After calling of back and pushState method, check length] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_back.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_back.html.ini index 5e01759025d..90019928495 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_back.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_back.html.ini @@ -1,5 +1,6 @@ [history_back.html] type: testharness + expected: TIMEOUT [history back] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_forward.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_forward.html.ini index d3c12080dfa..ea54a7fdf97 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_forward.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_forward.html.ini @@ -1,5 +1,6 @@ [history_forward.html] type: testharness + expected: TIMEOUT [history forward] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_go_minus.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_go_minus.html.ini index 01f21b30960..ef94a41258b 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_go_minus.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_go_minus.html.ini @@ -1,5 +1,6 @@ [history_go_minus.html] type: testharness + expected: TIMEOUT [history go minus] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_go_plus.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_go_plus.html.ini index e2999746053..b95882d3dcd 100644 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_go_plus.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_go_plus.html.ini @@ -1,5 +1,6 @@ [history_go_plus.html] type: testharness + expected: TIMEOUT [history go plus] - expected: FAIL + expected: TIMEOUT diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate.html.ini deleted file mode 100644 index d9c5e0b38af..00000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[history_pushstate.html] - type: testharness - [history pushState] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate_nooptionalparam.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate_nooptionalparam.html.ini deleted file mode 100644 index 40a1deb0cc3..00000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate_nooptionalparam.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[history_pushstate_nooptionalparam.html] - type: testharness - [history pushState NoOptionalParam] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate.html.ini deleted file mode 100644 index e2068698c0d..00000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[history_replacestate.html] - type: testharness - [history replaceState] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate_nooptionalparam.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate_nooptionalparam.html.ini deleted file mode 100644 index d523d0b78d0..00000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate_nooptionalparam.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[history_replacestate_nooptionalparam.html] - type: testharness - [history replaceStateNoOptionalParam] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_state.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_state.html.ini deleted file mode 100644 index 2819759ee82..00000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_state.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[history_state.html] - type: testharness - [history state] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 67ffcb48adc..10e41464e70 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -4455,9 +4455,6 @@ [BarProp interface: attribute visible] expected: FAIL - [History interface: attribute state] - expected: FAIL - [History interface: operation pushState(any,DOMString,DOMString)] expected: FAIL @@ -13644,30 +13641,9 @@ [Window interface: calling createImageBitmap(ImageBitmapSource, long, long, long, long, ImageBitmapOptions) on window with too few arguments must throw TypeError] expected: FAIL - [History interface: operation pushState(any, DOMString, USVString)] - expected: FAIL - - [History interface: operation replaceState(any, DOMString, USVString)] - expected: FAIL - [History interface: window.history must inherit property "scrollRestoration" with the proper type] expected: FAIL - [History interface: window.history must inherit property "state" with the proper type] - expected: FAIL - - [History interface: window.history must inherit property "pushState(any, DOMString, USVString)" with the proper type] - expected: FAIL - - [History interface: calling pushState(any, DOMString, USVString) on window.history with too few arguments must throw TypeError] - expected: FAIL - - [History interface: window.history must inherit property "replaceState(any, DOMString, USVString)" with the proper type] - expected: FAIL - - [History interface: calling replaceState(any, DOMString, USVString) on window.history with too few arguments must throw TypeError] - expected: FAIL - [ApplicationCache interface: window.applicationCache must inherit property "UNCACHED" with the proper type] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html.ini b/tests/wpt/metadata/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html.ini index 8820e0fbda8..20dcacd1969 100644 --- a/tests/wpt/metadata/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html.ini @@ -1,3 +1,8 @@ [formAction_document_address.html] type: testharness - expected: ERROR + [Check if button.formAction is the document's new address when formaction content attribute is missing and pushState has been used] + expected: FAIL + + [Check if input.formAction is the document's new address when formaction content attribute is missing and pushState has been used] + expected: FAIL + |