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 Nov 24, 2024
1 parent f943ba0 commit 633ab06
Show file tree
Hide file tree
Showing 24 changed files with 38 additions and 440 deletions.
45 changes: 36 additions & 9 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 @@ -147,7 +150,7 @@ impl HTMLIFrameElement {

{
let load_blocker = &self.load_blocker;
// Any oustanding load is finished from the point of view of the blocked
// Any outstanding load is finished from the point of view of the blocked
// document; the new navigation will continue blocking it.
LoadBlocker::terminate(load_blocker, can_gc);
}
Expand Down Expand Up @@ -259,7 +262,7 @@ impl HTMLIFrameElement {
url,
pipeline_id,
window.upcast::<GlobalScope>().get_referrer(),
document.get_referrer_policy(),
ReferrerPolicy::EmptyString,
Some(window.upcast::<GlobalScope>().is_secure_context()),
);
let element = self.upcast::<Element>();
Expand Down Expand Up @@ -300,6 +303,21 @@ impl HTMLIFrameElement {
// > `element`.
let url = self.get_url();

// Step 2.3: If url matches about:blank and initialInsertion is true, then:
if url.as_str() == "about:blank" && mode == ProcessingMode::FirstTime {
// Step 2.3.1: Run the iframe load event steps given element.
let pipeline_id = window.upcast::<GlobalScope>().pipeline_id();

self.iframe_load_event_steps(pipeline_id, can_gc);

// Step 2.3.2: Return.
return;
}

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

// 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 @@ -337,7 +355,7 @@ impl HTMLIFrameElement {
url,
creator_pipeline_id,
window.upcast::<GlobalScope>().get_referrer(),
document.get_referrer_policy(),
determine_policy_for_token(referrer_policy.str()),
Some(window.upcast::<GlobalScope>().is_secure_context()),
);

Expand Down Expand Up @@ -500,17 +518,18 @@ impl HTMLIFrameElement {
// TODO A cross-origin child document would not be easily accessible
// from this script thread. It's unclear how to implement
// steps 2, 3, and 5 efficiently in this case.
// TODO Step 2 - check child document `mute iframe load` flag
// TODO Step 3 - set child document `mut iframe load` flag

// Step 4
// TODO Step 3 - check child document `mute iframe load` flag
// TODO Step 5 - set child document `mut iframe load` flag

// Step 6: Fire an event named load at element.
self.upcast::<EventTarget>()
.fire_event(atom!("load"), can_gc);

let blocker = &self.load_blocker;
LoadBlocker::terminate(blocker, can_gc);

// TODO Step 5 - unset child document `mut iframe load` flag
// TODO Step 7 - unset child document `mut iframe load` flag
}
}

Expand Down Expand Up @@ -610,6 +629,14 @@ impl HTMLIFrameElementMethods 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[iframe-src-aboutblank-wait-for-load.html]
[Navigating to a different document with src]
expected: FAIL

[Navigating to a different document with location.href]
expected: FAIL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[initial-content-replacement.html]
[Content synchronously added to <iframe> with src='' won't get replaced]
expected: FAIL
[Content synchronously added to <iframe> with src='about:blank' won't get replaced]
expected: FAIL

[Content synchronously added to <iframe> with src='about:blank#foo' won't get replaced]
expected: FAIL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7300,9 +7300,6 @@
[HTMLIFrameElement interface: attribute allow]
expected: FAIL

[HTMLIFrameElement interface: attribute referrerPolicy]
expected: FAIL

[HTMLIFrameElement interface: attribute loading]
expected: FAIL

Expand Down Expand Up @@ -7330,9 +7327,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.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[iframe-src-aboutblank-wait-for-load.html]
[Navigating to a different document with src]
expected: FAIL

[Navigating to a different document with location.href]
expected: FAIL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[initial-content-replacement.html]
[Content synchronously added to <iframe> with src='' won't get replaced]
expected: FAIL
[Content synchronously added to <iframe> with src='about:blank' won't get replaced]
expected: FAIL

[Content synchronously added to <iframe> with src='about:blank#foo' won't get replaced]
expected: FAIL
Expand Down
Loading

0 comments on commit 633ab06

Please sign in to comment.