diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-05-04 18:50:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-04 18:50:17 -0500 |
commit | ca2a5025e50819f3fc54f66f681f9d73479386e4 (patch) | |
tree | eab672307d0897545a3cbca47742aef52645b587 /components/script/dom | |
parent | 896f0c49b299197eff6101ee434b4feceeb77c4d (diff) | |
parent | 5c53f5b7fa1b639ad3f30f1202e10e374de698c7 (diff) | |
download | servo-ca2a5025e50819f3fc54f66f681f9d73479386e4.tar.gz servo-ca2a5025e50819f3fc54f66f681f9d73479386e4.zip |
Auto merge of #16697 - cbrewster:history_throw, r=KiChjang
Make History attributes and methods throw
<!-- Please describe your changes on the following line: -->
All History methods and attributes should throw a `SecurityError` if the document associated with the `History` object is not fully active.
https://html.spec.whatwg.org/multipage/browsers.html#history-3
---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16697)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/history.rs | 28 | ||||
-rw-r--r-- | components/script/dom/webidls/History.webidl | 10 |
2 files changed, 26 insertions, 12 deletions
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::<GlobalScope>(); 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<u32> { + if !self.window.Document().is_fully_active() { + return Err(Error::Security); + } let global_scope = self.window.upcast::<GlobalScope>(); 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)) } } diff --git a/components/script/dom/webidls/History.webidl b/components/script/dom/webidls/History.webidl index 56171470877..d5b72996182 100644 --- a/components/script/dom/webidls/History.webidl +++ b/components/script/dom/webidls/History.webidl @@ -7,12 +7,20 @@ // https://html.spec.whatwg.org/multipage/#the-history-interface [Exposed=(Window,Worker)] interface History { + [Throws] readonly attribute unsigned long length; + // [Throws] // attribute ScrollRestoration scrollRestoration; + // [Throws] // readonly attribute any state; - [Throws] void go(optional long delta = 0); + [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); }; |