Don't commit Early Hints preloads for PDF

The HTML spec says that these preloads should not commit [1].
Clear NavigationEarlyHintsManager so that these preloads wouldn't
be committed.

[1] https://github.com/whatwg/html/issues/7823#issuecomment-1114952701

Bug: 1305896
Change-Id: I6ed351929c29b0f314384d6eaf82ab7f3a3d45b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3636957
Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1002478}
diff --git a/loading/early-hints/iframe-pdf.h2.window.js b/loading/early-hints/iframe-pdf.h2.window.js
new file mode 100644
index 0000000..11c1443
--- /dev/null
+++ b/loading/early-hints/iframe-pdf.h2.window.js
@@ -0,0 +1,31 @@
+// META: script=/common/utils.js
+// META: script=resources/early-hints-helpers.sub.js
+
+promise_test(async (t) => {
+    if (!navigator.pdfViewerEnabled) {
+        return;
+    }
+
+    const iframe = document.createElement("iframe");
+    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 iframe_url = SAME_ORIGIN_RESOURCES_URL + "/pdf-with-early-hints.h2.py?" + params.toString();
+
+        iframe.src = iframe_url;
+        iframe.onload = resolve;
+        document.body.appendChild(iframe);
+    });
+    await promise;
+
+    // `iframe` should not preload the hinted resource.
+    const iframe_entries = iframe.contentWindow.performance.getEntriesByName(resource_url);
+    assert_equals(iframe_entries.length, 0);
+
+    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 iframe of which content is pdf should be ignored.");
diff --git a/loading/early-hints/resources/example.pdf b/loading/early-hints/resources/example.pdf
new file mode 100644
index 0000000..7bad251
--- /dev/null
+++ b/loading/early-hints/resources/example.pdf
@@ -0,0 +1,50 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /MediaBox [ 0 0 200 300 ]
+  /Count 1
+  /Kids [ 3 0 R ]
+>>
+endobj
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+>>
+endobj
+4 0 obj <<
+>>
+stream
+q
+0 0 0 rg
+0 290 10 10 re B*
+10 150 50 30 re B*
+0 0 1 rg
+190 290 10 10 re B*
+70 232 50 30 re B*
+0 1 0 rg
+190 0 10 10 re B*
+130 150 50 30 re B*
+1 0 0 rg
+0 0 10 10 re B*
+70 67 50 30 re B*
+Q
+endstream
+endobj
+xref
+0 5
+0000000000 65535 f 
+0000000015 00000 n 
+0000000068 00000 n 
+0000000161 00000 n 
+0000000230 00000 n 
+trailer<< /Root 1 0 R /Size 5 >>
+startxref
+456
+%%EOF
diff --git a/loading/early-hints/resources/pdf-with-early-hints.h2.py b/loading/early-hints/resources/pdf-with-early-hints.h2.py
new file mode 100644
index 0000000..0d05f2a
--- /dev/null
+++ b/loading/early-hints/resources/pdf-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"] = "application/pdf"
+    response.write_status_headers()
+
+
+def main(request, response):
+    current_dir = os.path.dirname(os.path.realpath(__file__))
+    file_path = os.path.join(current_dir, "example.pdf")
+    with open(file_path, "rb") as f:
+        content = f.read()
+    response.writer.write_data(item=content, last=True)