Ignore Early Hints for <embed> and <object>
Early Hints for <embed> and <object> are already ignored even
without this CL as we check FrameTreeNode::GetParentOrOuterDocument(),
but we should have an explicit check for <embed> and <object> so that
we won't handle Early Hints for these navigations when we allow
Early Hints for sub frames in the future.
Bug: 1305896
Change-Id: Ifd077e2fabbc6403bf94577183d542dd2cde4221
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3631786
Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1001390}
diff --git a/loading/early-hints/embed-object.h2.window.js b/loading/early-hints/embed-object.h2.window.js
new file mode 100644
index 0000000..82365fa
--- /dev/null
+++ b/loading/early-hints/embed-object.h2.window.js
@@ -0,0 +1,44 @@
+// META: script=/common/utils.js
+// META: script=resources/early-hints-helpers.sub.js
+
+promise_test(async (t) => {
+ const resource_url = SAME_ORIGIN_RESOURCES_URL + "/empty.js?" + token();
+ const promise = new Promise((resolve) => {
+ const params = new URLSearchParams();
+ params.set("resource-url", resource_url);
+ params.set("token", token());
+ const embed_url = SAME_ORIGIN_RESOURCES_URL + "/png-with-early-hints.h2.py?" + params.toString();
+
+ const el = document.createElement("embed");
+ el.src = embed_url;
+ el.onload = resolve;
+ document.body.appendChild(el);
+ });
+ await promise;
+
+ await fetchScript(resource_url);
+ const entries = performance.getEntriesByName(resource_url);
+ assert_equals(entries.length, 1);
+ assert_not_equals(entries[0].transferSize, 0);
+}, "Early hints for an embed element should be ignored.");
+
+promise_test(async (t) => {
+ const resource_url = SAME_ORIGIN_RESOURCES_URL + "/empty.js?" + token();
+ const promise = new Promise((resolve) => {
+ const params = new URLSearchParams();
+ params.set("resource-url", resource_url);
+ params.set("token", token());
+ const object_url = SAME_ORIGIN_RESOURCES_URL + "/png-with-early-hints.h2.py?" + params.toString();
+
+ const el = document.createElement("object");
+ el.data = object_url;
+ el.onload = resolve;
+ document.body.appendChild(el);
+ });
+ await promise;
+
+ await fetchScript(resource_url);
+ const entries = performance.getEntriesByName(resource_url);
+ assert_equals(entries.length, 1);
+ assert_not_equals(entries[0].transferSize, 0);
+}, "Early hints for an object element should be ignored.");
diff --git a/loading/early-hints/resources/png-with-early-hints.h2.py b/loading/early-hints/resources/png-with-early-hints.h2.py
new file mode 100644
index 0000000..0785d51
--- /dev/null
+++ b/loading/early-hints/resources/png-with-early-hints.h2.py
@@ -0,0 +1,26 @@
+import os
+import time
+
+def handle_headers(frame, request, response):
+ resource_url = request.GET.first(b"resource-url").decode()
+ link_header_value = "<{}>; rel=preload; as=script".format(resource_url)
+ early_hints = [
+ (b":status", b"103"),
+ (b"link", link_header_value),
+ ]
+ response.writer.write_raw_header_frame(headers=early_hints,
+ end_headers=True)
+
+ # Sleep to simulate a slow generation of the final response.
+ time.sleep(0.1)
+ response.status = 200
+ response.headers[b"content-type"] = "image/png"
+ response.write_status_headers()
+
+
+def main(request, response):
+ current_dir = os.path.dirname(os.path.realpath(__file__))
+ file_path = os.path.join(current_dir, "square.png")
+ with open(file_path, "rb") as f:
+ test_content = f.read()
+ response.writer.write_data(item=test_content, last=True)