diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-06-02 21:51:10 -0500 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-06-02 21:51:10 -0500 |
commit | 530b5a649eb7284c0ff4e316b8eabd5cc62c1e80 (patch) | |
tree | 7722f71ebc10f8b6488daf8a08d44676ef810cb3 /components/script/dom/document.rs | |
parent | 77e6ea95873c1fc06ea6e19fa20c727b9ca808a9 (diff) | |
parent | 687d0cd7c393ad95209a1220ff728700d9929ac6 (diff) | |
download | servo-530b5a649eb7284c0ff4e316b8eabd5cc62c1e80.tar.gz servo-530b5a649eb7284c0ff4e316b8eabd5cc62c1e80.zip |
Auto merge of #11468 - rebstar6:refPol4, r=nox
Implement meta referrer policy delivery (3)
<!-- Please describe your changes on the following line: -->
---
<!-- 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 #10311 (github issue number if applicable).
<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11468)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 3f8c15fa1a8..9272c7f6da1 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -237,7 +237,7 @@ pub struct Document { /// The document's origin. origin: Origin, /// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-states - referrer_policy: Option<ReferrerPolicy>, + referrer_policy: Cell<Option<ReferrerPolicy>>, } #[derive(JSTraceable, HeapSizeOf)] @@ -1697,7 +1697,7 @@ impl Document { touchpad_pressure_phase: Cell::new(TouchpadPressurePhase::BeforeClick), origin: origin, //TODO - setting this for now so no Referer header set - referrer_policy: Some(ReferrerPolicy::NoReferrer), + referrer_policy: Cell::new(Some(ReferrerPolicy::NoReferrer)), } } @@ -1827,9 +1827,13 @@ impl Document { } } - //TODO - for now, returns no-referrer for all until reading in the value + pub fn set_referrer_policy(&self, policy: Option<ReferrerPolicy>) { + self.referrer_policy.set(policy); + } + + //TODO - default still at no-referrer pub fn get_referrer_policy(&self) -> Option<ReferrerPolicy> { - return self.referrer_policy.clone(); + return self.referrer_policy.get(); } } @@ -2800,6 +2804,20 @@ fn update_with_current_time_ms(marker: &Cell<u64>) { } } +/// https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token +pub fn determine_policy_for_token(token: &str) -> Option<ReferrerPolicy> { + let lower = token.to_lowercase(); + return match lower.as_ref() { + "never" | "no-referrer" => Some(ReferrerPolicy::NoReferrer), + "default" | "no-referrer-when-downgrade" => Some(ReferrerPolicy::NoRefWhenDowngrade), + "origin" => Some(ReferrerPolicy::OriginOnly), + "origin-when-cross-origin" => Some(ReferrerPolicy::OriginWhenCrossOrigin), + "always" | "unsafe-url" => Some(ReferrerPolicy::UnsafeUrl), + "" => Some(ReferrerPolicy::NoReferrer), + _ => None, + } +} + pub struct DocumentProgressHandler { addr: Trusted<Document> } |