Implement srcdoc support for iframes.

This commit is contained in:
jaymodi98 2019-10-28 17:21:45 -04:00 committed by Josh Matthews
parent 944c1e9f97
commit bf69b6fea7
56 changed files with 116 additions and 172 deletions

View file

@ -229,7 +229,30 @@ impl HTMLIFrameElement {
/// <https://html.spec.whatwg.org/multipage/#process-the-iframe-attributes>
fn process_the_iframe_attributes(&self, mode: ProcessingMode) {
// TODO: srcdoc
if self
.upcast::<Element>()
.has_attribute(&local_name!("srcdoc"))
{
let url = ServoUrl::parse("about:srcdoc").unwrap();
let document = document_from_node(self);
let window = window_from_node(self);
let pipeline_id = Some(window.upcast::<GlobalScope>().pipeline_id());
let mut load_data = LoadData::new(
LoadOrigin::Script(document.origin().immutable().clone()),
url,
pipeline_id,
Some(Referrer::ReferrerUrl(document.url())),
document.get_referrer_policy(),
);
let element = self.upcast::<Element>();
load_data.srcdoc = String::from(element.get_string_attribute(&local_name!("srcdoc")));
self.navigate_or_reload_child_browsing_context(
load_data,
NavigationType::InitialAboutBlank,
HistoryEntryReplacement::Disabled,
);
return;
}
let window = window_from_node(self);
@ -480,6 +503,12 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
make_url_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-iframe-srcdoc
make_getter!(Srcdoc, "srcdoc");
// https://html.spec.whatwg.org/multipage/#dom-iframe-srcdoc
make_setter!(SetSrcdoc, "srcdoc");
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
fn Sandbox(&self) -> DomRoot<DOMTokenList> {
self.sandbox
@ -580,13 +609,29 @@ impl VirtualMethods for HTMLIFrameElement {
modes
}));
},
&local_name!("srcdoc") => {
// https://html.spec.whatwg.org/multipage/#the-iframe-element:the-iframe-element-9
// "Whenever an iframe element with a non-null nested browsing context has its
// srcdoc attribute set, changed, or removed, the user agent must process the
// iframe attributes."
// but we can't check that directly, since the child browsing context
// may be in a different script thread. Instead, we check to see if the parent
// is in a document tree and has a browsing context, which is what causes
// the child browsing context to be created.
// trigger the processing of iframe attributes whenever "srcdoc" attribute is set, changed or removed
if self.upcast::<Node>().is_connected_with_browsing_context() {
debug!("iframe srcdoc modified while in browsing context.");
self.process_the_iframe_attributes(ProcessingMode::NotFirstTime);
}
},
&local_name!("src") => {
// https://html.spec.whatwg.org/multipage/#the-iframe-element
// "Similarly, whenever an iframe element with a non-null nested browsing context
// but with no srcdoc attribute specified has its src attribute set, changed, or removed,
// the user agent must process the iframe attributes,"
// but we can't check that directly, since the child browsing context
// may be in a different script thread. Instread, we check to see if the parent
// may be in a different script thread. Instead, we check to see if the parent
// is in a document tree and has a browsing context, which is what causes
// the child browsing context to be created.
if self.upcast::<Node>().is_connected_with_browsing_context() {

View file

@ -9,8 +9,8 @@ interface HTMLIFrameElement : HTMLElement {
[CEReactions]
attribute USVString src;
// [CEReactions]
// attribute DOMString srcdoc;
[CEReactions]
attribute DOMString srcdoc;
[CEReactions]
attribute DOMString name;

View file

@ -2430,6 +2430,8 @@ impl ScriptThread {
);
if load_data.url.as_str() == "about:blank" {
self.start_page_load_about_blank(new_load, load_data.js_eval_result);
} else if load_data.url.as_str() == "about:srcdoc" {
self.page_load_about_srcdoc(new_load, load_data.srcdoc);
} else {
self.pre_page_load(new_load, load_data);
}
@ -3177,7 +3179,8 @@ impl ScriptThread {
self.timer_event_chan.clone(),
);
let origin = if final_url.as_str() == "about:blank" {
let origin = if final_url.as_str() == "about:blank" || final_url.as_str() == "about:srcdoc"
{
incomplete.origin.clone()
} else {
MutableOrigin::new(final_url.origin())
@ -3838,6 +3841,25 @@ impl ScriptThread {
context.process_response_eof(Ok(ResourceFetchTiming::new(ResourceTimingType::None)));
}
/// Synchronously parse a srcdoc document from a giving HTML string.
fn page_load_about_srcdoc(&self, incomplete: InProgressLoad, src_doc: String) {
let id = incomplete.pipeline_id;
self.incomplete_loads.borrow_mut().push(incomplete);
let url = ServoUrl::parse("about:srcdoc").unwrap();
let mut context = ParserContext::new(id, url.clone());
let mut meta = Metadata::default(url);
meta.set_content_type(Some(&mime::TEXT_HTML));
let chunk = src_doc.into_bytes();
context.process_response(Ok(FetchMetadata::Unfiltered(meta)));
context.process_response_chunk(chunk);
context.process_response_eof(Ok(ResourceFetchTiming::new(ResourceTimingType::None)));
}
fn handle_css_error_reporting(
&self,
pipeline_id: PipelineId,

View file

@ -163,6 +163,9 @@ pub struct LoadData {
pub referrer: Option<Referrer>,
/// The referrer policy.
pub referrer_policy: Option<ReferrerPolicy>,
/// The source to use instead of a network response for a srcdoc document.
pub srcdoc: String,
}
/// The result of evaluating a javascript scheme url.
@ -194,6 +197,7 @@ impl LoadData {
js_eval_result: None,
referrer: referrer,
referrer_policy: referrer_policy,
srcdoc: "".to_string(),
}
}
}

View file

@ -14,6 +14,9 @@
[Revoke blob URL after creating Request, will fetch]
expected: FAIL
[Revoke blob URL after calling fetch, fetch should succeed]
expected: FAIL
[url-with-fetch.any.html]
[Untitled]

View file

@ -1,14 +1,5 @@
[current-realm.html]
type: testharness
[NamedNodeMap item]
expected: FAIL
[NamedNodeMap getNamedItem]
expected: FAIL
[NamedNodeMap getNamedItemNS]
expected: FAIL
[createImageData]
expected: FAIL

View file

@ -1,2 +0,0 @@
[floats-in-table-caption-001.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[hyphens-out-of-flow-001.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[line-break-normal-018.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[line-break-strict-018.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-transform-full-size-kana-001.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-transform-full-size-kana-002.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-transform-full-size-kana-003.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-transform-full-size-kana-004.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[trailing-ideographic-space-004.html]
expected: FAIL

View file

@ -1,5 +1,4 @@
[perspective-interpolation.html]
expected: CRASH
[ perspective interpolation]
expected: FAIL

View file

@ -1,2 +1,2 @@
[no-transition-from-ua-to-blocking-stylesheet.html]
expected: FAIL
expected: TIMEOUT

View file

@ -1,2 +0,0 @@
[matchMedia-display-none-iframe.html]
expected: ERROR

View file

@ -1,2 +0,0 @@
[HTMLMediaElement.html]
expected: CRASH

View file

@ -1,2 +0,0 @@
[contenttype_html.html]
expected: CRASH

View file

@ -1,2 +0,0 @@
[contenttype_txt.html]
expected: CRASH

View file

@ -1,2 +0,0 @@
[contenttype_xml.html]
expected: CRASH

View file

@ -1,2 +1,5 @@
[realms.window.html]
expected: TIMEOUT
expected: ERROR
[realms]
expected: FAIL

View file

@ -1,48 +1,26 @@
[dangling-markup-mitigation-data-url.tentative.sub.html]
type: testharness
expected: TIMEOUT
[<img id="dangling" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=">]
expected: FAIL
[<img id="dangling" src="data:image/png;base64,&#10;iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=">]
expected: FAIL
[<img id="dangling" src="data:image/png;base64,i&#10;VBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=">]
expected: FAIL
[<img id="dangling" src="data:image/svg+xml;utf8,\\n <svg width='1' height='1' xmlns='http://www.w3.org/2000/svg'>\\n <rect width='100%' height='100%' fill='rebeccapurple'/>\\n <rect x='10%' y='10%' width='80%' height='80%' fill='lightgreen'/>\\n </svg>">]
expected: FAIL
[<iframe id="dangling"\\n src="data:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/gr&#10;een-256x256.png'>\\n ">\\n </iframe>]
expected: TIMEOUT
[<iframe id="dangling"\\n src="data:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/green-256x256.png?&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
[<iframe id="dangling"\\n src="data:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/gr&#10;een-256x256.png?&amp;amp;lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
[<iframe id="dangling"\\n src="data:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/green-256x256.png?&amp;amp;#10;&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
[<iframe id="dangling"\\n src="data:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/gr&#10;een-256x256.png?&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
expected: FAIL
[<iframe id="dangling"\\n src=" data:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/gr&#10;een-256x256.png?&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
expected: FAIL
[<iframe id="dangling"\\n src="\\ndata:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/gr&#10;een-256x256.png?&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
expected: FAIL
[<iframe id="dangling"\\n src="&#10;data:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/gr&#10;een-256x256.png?&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
expected: FAIL
[<iframe id="dangling"\\n src="\\tdata:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/gr&#10;een-256x256.png?&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
expected: FAIL
[<iframe id="dangling"\\n src="\\rdata:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/gr&#10;een-256x256.png?&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
[<iframe id="dangling"\\n src="data:text/html,\\n <img\\n onload='window.parent.postMessage(&quot;loaded&quot;, &quot;*&quot;);'\\n onerror='window.parent.postMessage(&quot;error&quot;, &quot;*&quot;);'\\n src='http://web-platform.test:8000/images/green-256x256.png?&amp;amp;%2310;&lt;'>\\n ">\\n </iframe>]
expected: TIMEOUT
expected: FAIL

View file

@ -54,12 +54,3 @@
[<img id="dangling" src="data:image/svg+xml;utf8,\\n <svg width='1' height='1' xmlns='http://www.w3.org/2000/svg'>\\n <rect width='100%' height='100%' fill='rebeccapurple'/>\\n <rect x='10%' y='10%' width='80%' height='80%' fill='lightgreen'/>\\n </svg>">]
expected: FAIL
[<img id="dangling" src="/images/green-1x1.png?img=&#10;&lt;b">]
expected: FAIL
[<img id="dangling" src="/images/green-1x1.png?img=&lt;&#10;b">]
expected: FAIL
[\\n <img id="dangling" src="/images/green-1x1.png?img=\\n &lt;\\n &#10;b\\n ">\\n ]
expected: FAIL

View file

@ -1,4 +0,0 @@
[traverse_the_history_2.html]
[Multiple history traversals, last would be aborted]
expected: FAIL

View file

@ -18,3 +18,6 @@
[Set HTTP URL frame location.protocol to x]
expected: FAIL
[Set data URL frame location.protocol to data]
expected: FAIL

View file

@ -1,8 +1,5 @@
[location_hash.html]
type: testharness
[Setting location.hash on srcdoc iframe]
expected: FAIL
[Setting hash which is partially encoded should only encode incompatible characters]
expected: FAIL

View file

@ -1,12 +0,0 @@
[document_domain_setter_srcdoc.html]
type: testharness
expected: TIMEOUT
[srcdoc can access with no 'document.domain' modification.]
expected: TIMEOUT
[srcdoc can access with valid 'document.domain'.]
expected: NOTRUN
[srcdoc can access when parent modifies 'document.domain'.]
expected: NOTRUN

View file

@ -0,0 +1,2 @@
[sandbox-parse-noscript.html]
expected: FAIL

View file

@ -1,5 +1,4 @@
[embedded-opener-remove-frame.html]
expected: CRASH
[opener and "removed" embedded documents]
expected: FAIL

View file

@ -4230,9 +4230,6 @@
[HTMLInputElement interface: calling setCustomValidity(DOMString) on createInput("button") with too few arguments must throw TypeError]
expected: FAIL
[HTMLIFrameElement interface: attribute srcdoc]
expected: FAIL
[HTMLInputElement interface: createInput("week") must inherit property "checkValidity()" with the proper type]
expected: FAIL

View file

@ -1,4 +0,0 @@
[focusable-area-in-top-document.html]
[If topDocument's focused area is not topDocument, autofocus is not processed.]
expected: FAIL

View file

@ -0,0 +1,3 @@
[skip-not-fully-active.html]
[Autofocus element in not-fully-active document should be skipped while flusing.]
expected: FAIL

View file

@ -1,4 +1,5 @@
[iframe_sandbox_anchor_download_allow_downloads_without_user_activation.sub.tentative.html]
expected: TIMEOUT
[<a download> triggered download in sandbox is allowed by allow-downloads-without-user-activation.]
expected: FAIL
expected: TIMEOUT

View file

@ -1,4 +0,0 @@
[iframe_sandbox_anchor_download_block_downloads_without_user_activation.sub.tentative.html]
[<a download> triggered download in sandbox is blocked.]
expected: FAIL

View file

@ -1,4 +1,5 @@
[iframe_sandbox_navigation_download_allow_downloads_without_user_activation.sub.tentative.html]
expected: TIMEOUT
[Navigation resulted download in sandbox is allowed by allow-downloads-without-user-activation.]
expected: FAIL
expected: TIMEOUT

View file

@ -1,4 +0,0 @@
[iframe_sandbox_navigation_download_block_downloads_without_user_activation.sub.tentative.html]
[Navigation resulted download in sandbox is blocked.]
expected: FAIL

View file

@ -1,6 +1,5 @@
[iframe_sandbox_popups_escaping-1.html]
type: testharness
expected: TIMEOUT
[Check that popups from a sandboxed iframe escape the sandbox if\n allow-popups-to-escape-sandbox is used]
expected: TIMEOUT
expected: FAIL

View file

@ -1,14 +0,0 @@
[srcdoc_process_attributes.html]
expected: TIMEOUT
[Removing `srcdoc` attribute triggers attributes processing]
expected: FAIL
[Changing `srcdoc` (via property) triggers attributes processing]
expected: FAIL
[Adding `srcdoc` attribute triggers attributes processing]
expected: TIMEOUT
[Setting `srcdoc` (via property) triggers attributes processing]
expected: FAIL

View file

@ -1,2 +0,0 @@
[sizes-dynamic-001.html]
expected: TIMEOUT

View file

@ -1,5 +1,5 @@
[form-double-submit-2.html]
expected: ERROR
[preventDefault should allow onclick submit() to succeed]
expected: TIMEOUT
expected: FAIL

View file

@ -1,5 +1,5 @@
[form-double-submit-3.html]
expected: ERROR
[<button> should have the same double-submit protection as <input type=submit>]
expected: TIMEOUT
expected: FAIL

View file

@ -5,14 +5,14 @@
expected: NOTRUN
[Check that rel=noopener with target=_parent does a normal load]
expected: FAIL
expected: NOTRUN
[Check that rel=noopener with target=_top does a normal load]
expected: FAIL
expected: NOTRUN
[Check that targeting of rel=noopener with a given name reuses an existing window with that name]
expected: NOTRUN
[Check that rel=noopener with target=_self does a normal load]
expected: FAIL
expected: NOTRUN

View file

@ -1,5 +0,0 @@
[099.html]
type: testharness
[ scheduler: defer adding iframe containing script]
expected: FAIL

View file

@ -1,2 +0,0 @@
[data-xhtml-with-dtd.html]
expected: FAIL

View file

@ -1,5 +0,0 @@
[document-close-with-pending-script.html]
expected: TIMEOUT
[document.close called while a script is pending]
expected: TIMEOUT

View file

@ -1,5 +1,4 @@
[location-set-and-document-open.html]
expected: TIMEOUT
[Location sets should cancel current navigation and prevent later document.open() from doing anything]
expected: TIMEOUT
expected: FAIL

View file

@ -1,4 +1,5 @@
[promise-rejection-events.html]
expected: TIMEOUT
[delayed handling: delaying handling rejected promise created from createImageBitmap will cause both events to fire]
expected: FAIL
@ -8,3 +9,6 @@
[no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a promise created from createImageBitmap]
expected: FAIL
[rejectionhandled is dispatched from a queued task, and not immediately]
expected: TIMEOUT

View file

@ -1,5 +1,4 @@
[child-document-raf-order.html]
expected: TIMEOUT
[Ordering of steps in "Update the Rendering" - child document requestAnimationFrame order]
expected: TIMEOUT
expected: FAIL

View file

@ -1,5 +1,4 @@
[iframe-inheritance-srcdoc-child.html]
expected: TIMEOUT
[iframes srcdoc child correctly inherit the ancestor's referrer policy]
expected: NOTRUN
expected: FAIL

View file

@ -1,4 +1,5 @@
[realtimeanalyser-fft-scaling.html]
expected: TIMEOUT
[X 2048-point FFT peak position is not equal to 64. Got 0.]
expected: FAIL

View file

@ -1,5 +0,0 @@
[018.html]
expected: TIMEOUT
[origin of the script that invoked the method, javascript:]
expected: TIMEOUT

View file

@ -1,5 +0,0 @@
[remove-own-iframe-during-onerror.window.html]
expected: TIMEOUT
[removing an iframe from within an onerror handler should work]
expected: TIMEOUT

View file

@ -1,5 +1,4 @@
[005.html]
expected: ERROR
[dedicated worker in shared worker in dedicated worker]
expected: FAIL

View file

@ -1,6 +1,5 @@
[003.html]
type: testharness
expected: ERROR
[shared]
expected: FAIL