Skip to content

Commit

Permalink
fix: fetching PDF element from WebLocalFrame (#34176)
Browse files Browse the repository at this point in the history
fix: fetching PDF element from WebLocalFrame
  • Loading branch information
codebytere committed May 13, 2022
1 parent a810369 commit 8b5613e
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions shell/renderer/printing/print_render_frame_helper_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "third_party/blink/public/web/web_local_frame.h"

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/common/pdf_util.h"
#include "extensions/common/constants.h"
#include "extensions/renderer/guest_view/mime_handler_view/post_message_support.h"
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Expand All @@ -24,22 +25,11 @@ PrintRenderFrameHelperDelegate::~PrintRenderFrameHelperDelegate() = default;
blink::WebElement PrintRenderFrameHelperDelegate::GetPdfElement(
blink::WebLocalFrame* frame) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
GURL url = frame->GetDocument().Url();
bool inside_pdf_extension =
url.SchemeIs(extensions::kExtensionScheme) &&
url.host_piece() == extension_misc::kPdfExtensionId;
if (inside_pdf_extension) {
// <object> with id="plugin" is created in
// chrome/browser/resources/pdf/pdf_viewer_base.js.
auto viewer_element = frame->GetDocument().GetElementById("viewer");
if (!viewer_element.IsNull() && !viewer_element.ShadowRoot().IsNull()) {
auto plugin_element =
viewer_element.ShadowRoot().QuerySelector("#plugin");
if (!plugin_element.IsNull()) {
return plugin_element;
}
}
NOTREACHED();
if (frame->Parent() &&
IsPdfInternalPluginAllowedOrigin(frame->Parent()->GetSecurityOrigin())) {
auto plugin_element = frame->GetDocument().QuerySelector("embed");
DCHECK(!plugin_element.IsNull());
return plugin_element;
}
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
return blink::WebElement();
Expand Down

0 comments on commit 8b5613e

Please sign in to comment.