[go: nahoru, domu]

[OOPIF PDF] Fix presentation mode not working correctly

Fix presentation mode failing to work by changing the PDF outer <embed>
to an <iframe>. Give the iframe the 'allow' attribute and allow
fullscreen for all origins so that the PDF extension in the iframe can
use Element.requestFullscreen().

The web spec for Element.requestFullscreen() requires that the element
requesting fullscreen must be in the top-level document or in an
<iframe> with the 'allow' attribute allowing fullscreen. The element
requesting fullscreen resides in the PDF extension.

In GuestView PDF viewer, the PDF extension is in the top-level document
of the inner WebContents, so the element is allowed to fullscreen.

In OOPIF PDF viewer, the PDF extension is no longer in the top-level
document. This CL uses the other <iframe> requirement to allow
fullscreen.

The <embed> used to be an <iframe>, but was changed in
https://crrev.com/659508. After https://crrev.com/1257705, OOPIF tests
don't need the element to be an <embed> anymore.

Bug: 41495166
Change-Id: I4031c782f24e7f3656c430767f2a6e67ba8d01b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5269765
Commit-Queue: Andy Phan <andyphan@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Kevin McNee <mcnee@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1262032}
diff --git a/chrome/browser/pdf/pdf_extension_js_test.cc b/chrome/browser/pdf/pdf_extension_js_test.cc
index 8e7c2f9..da2ee12 100644
--- a/chrome/browser/pdf/pdf_extension_js_test.cc
+++ b/chrome/browser/pdf/pdf_extension_js_test.cc
@@ -272,11 +272,6 @@
 }
 
 IN_PROC_BROWSER_TEST_P(PDFExtensionJSTest, Fullscreen) {
-  // TODO(crbug.com/1445746): Remove this once the test passes for OOPIF PDF.
-  if (UseOopif()) {
-    GTEST_SKIP();
-  }
-
   // Use a PDF document with multiple pages, to exercise navigating between
   // pages.
   RunTestsInJsModule("fullscreen_test.js", "test-bookmarks.pdf");
diff --git a/components/pdf/resources/pdf_embedder.html b/components/pdf/resources/pdf_embedder.html
index 2c639a4..b76d3d1 100644
--- a/components/pdf/resources/pdf_embedder.html
+++ b/components/pdf/resources/pdf_embedder.html
@@ -14,15 +14,17 @@
   <body>
     <template shadowrootmode="closed">
       <style>
-        embed {
+        iframe {
           position: absolute;
           left: 0;
           top: 0;
           height: 100%;
           width: 100%;
+          border-style: none;
         }
       </style>
-      <embed name="$4" src="about:blank" type="$5" internalid="$6">
+      <iframe name="$4" src="about:blank" type="$5" internalid="$6"
+          allow="fullscreen *">
     </template>
   </body>
 </html>