electron_pdf_document_helper_client.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2015 Slack Technologies, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/electron_pdf_document_helper_client.h"
  5. #include "chrome/browser/pdf/pdf_frame_util.h"
  6. #include "content/public/browser/web_contents.h"
  7. #include "pdf/content_restriction.h"
  8. #include "shell/browser/api/electron_api_web_contents.h"
  9. ElectronPDFDocumentHelperClient::ElectronPDFDocumentHelperClient() = default;
  10. ElectronPDFDocumentHelperClient::~ElectronPDFDocumentHelperClient() = default;
  11. content::RenderFrameHost* ElectronPDFDocumentHelperClient::FindPdfFrame(
  12. content::WebContents* contents) {
  13. content::RenderFrameHost* main_frame = contents->GetPrimaryMainFrame();
  14. content::RenderFrameHost* pdf_frame =
  15. pdf_frame_util::FindPdfChildFrame(main_frame);
  16. return pdf_frame ? pdf_frame : main_frame;
  17. }
  18. void ElectronPDFDocumentHelperClient::UpdateContentRestrictions(
  19. content::RenderFrameHost* render_frame_host,
  20. int content_restrictions) {
  21. // UpdateContentRestrictions potentially gets called twice from
  22. // pdf/pdf_view_web_plugin.cc. The first time it is potentially called is
  23. // when loading starts and it is called with a restriction on printing. The
  24. // second time it is called is when loading is finished and if printing is
  25. // allowed there won't be a printing restriction passed, so we can use this
  26. // second call to notify that the pdf document is ready to print.
  27. if (!(content_restrictions & chrome_pdf::kContentRestrictionPrint)) {
  28. content::WebContents* web_contents =
  29. content::WebContents::FromRenderFrameHost(render_frame_host);
  30. electron::api::WebContents* api_web_contents =
  31. electron::api::WebContents::From(
  32. web_contents->GetOutermostWebContents());
  33. if (api_web_contents) {
  34. api_web_contents->PDFReadyToPrint();
  35. }
  36. }
  37. }