Skip to content

Commit

Permalink
Add ReferrerPolicy IDL attribute to iframes
Browse files Browse the repository at this point in the history
Signed-off-by: Shane Handley <shanehandley@fastmail.com>
  • Loading branch information
shanehandley committed Dec 8, 2024
1 parent bc7fe41 commit b097cea
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 206 deletions.
31 changes: 27 additions & 4 deletions components/script/dom/htmliframeelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bitflags::bitflags;
use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use net_traits::ReferrerPolicy;
use profile_traits::ipc as ProfiledIpc;
use script_traits::IFrameSandboxState::{IFrameSandboxed, IFrameUnsandboxed};
use script_traits::{
Expand All @@ -29,9 +30,11 @@ use crate::dom::bindings::refcounted::Trusted;
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::document::Document;
use crate::dom::document::{determine_policy_for_token, Document};
use crate::dom::domtokenlist::DOMTokenList;
use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers};
use crate::dom::element::{
reflect_referrer_policy_attribute, AttributeMutation, Element, LayoutElementHelpers,
};
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlelement::HTMLElement;
Expand Down Expand Up @@ -300,6 +303,19 @@ impl HTMLIFrameElement {
// > `element`.
let url = self.get_url();

// Step 2.4: Let referrerPolicy be the current state of element's referrerpolicy content
// attribute.
let document = document_from_node(self);
let referrer_policy_token = self.ReferrerPolicy();

// Note: despite not being explicitly stated in the spec steps, this falls back to
// document's referrer policy here because it satisfies the expectations that when unset,
// the iframe should inherit the referrer policy of its parent
let referrer_policy = match determine_policy_for_token(referrer_policy_token.str()) {
ReferrerPolicy::EmptyString => document.get_referrer_policy(),
policy => policy,
};

// TODO(#25748):
// By spec, we return early if there's an ancestor browsing context
// "whose active document's url, ignoring fragments, is equal".
Expand Down Expand Up @@ -331,13 +347,12 @@ impl HTMLIFrameElement {
None
};

let document = document_from_node(self);
let load_data = LoadData::new(
LoadOrigin::Script(document.origin().immutable().clone()),
url,
creator_pipeline_id,
window.upcast::<GlobalScope>().get_referrer(),
document.get_referrer_policy(),
referrer_policy,
Some(window.upcast::<GlobalScope>().is_secure_context()),
);

Expand Down Expand Up @@ -610,6 +625,14 @@ impl HTMLIFrameElementMethods<crate::DomTypeHolder> for HTMLIFrameElement {
Some(document)
}

// https://html.spec.whatwg.org/multipage/#attr-iframe-referrerpolicy
fn ReferrerPolicy(&self) -> DOMString {
reflect_referrer_policy_attribute(self.upcast::<Element>())
}

// https://html.spec.whatwg.org/multipage/#attr-iframe-referrerpolicy
make_setter!(SetReferrerPolicy, "referrerpolicy");

// https://html.spec.whatwg.org/multipage/#attr-iframe-allowfullscreen
make_bool_getter!(AllowFullscreen, "allowfullscreen");
// https://html.spec.whatwg.org/multipage/#attr-iframe-allowfullscreen
Expand Down
2 changes: 2 additions & 0 deletions components/script/dom/webidls/HTMLIFrameElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface HTMLIFrameElement : HTMLElement {
attribute boolean allowFullscreen;
[CEReactions]
attribute DOMString width;
[CEReactions]
attribute DOMString referrerPolicy;
[CEReactions]
attribute DOMString height;
readonly attribute Document? contentDocument;
Expand Down
6 changes: 0 additions & 6 deletions tests/wpt/meta/html/dom/idlharness.https.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6415,9 +6415,6 @@
[HTMLIFrameElement interface: attribute allow]
expected: FAIL

[HTMLIFrameElement interface: attribute referrerPolicy]
expected: FAIL

[HTMLIFrameElement interface: attribute loading]
expected: FAIL

Expand Down Expand Up @@ -6445,9 +6442,6 @@
[HTMLIFrameElement interface: document.createElement("iframe") must inherit property "allow" with the proper type]
expected: FAIL

[HTMLIFrameElement interface: document.createElement("iframe") must inherit property "referrerPolicy" with the proper type]
expected: FAIL

[HTMLIFrameElement interface: document.createElement("iframe") must inherit property "loading" with the proper type]
expected: FAIL

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit b097cea

Please sign in to comment.