diff --git a/libcef/browser/alloy/browser_platform_delegate_alloy.cc b/libcef/browser/alloy/browser_platform_delegate_alloy.cc index c0528d071..23d26945c 100644 --- a/libcef/browser/alloy/browser_platform_delegate_alloy.cc +++ b/libcef/browser/alloy/browser_platform_delegate_alloy.cc @@ -17,6 +17,7 @@ #include "base/logging.h" #include "chrome/browser/printing/print_view_manager.h" +#include "chrome/browser/printing/print_view_manager_common.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "components/find_in_page/find_tab_helper.h" #include "components/find_in_page/find_types.h" @@ -26,6 +27,7 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host.h" #include "extensions/browser/process_manager.h" +#include "pdf/pdf_features.h" #include "printing/mojom/print.mojom.h" #include "third_party/blink/public/mojom/frame/find_in_page.mojom.h" @@ -341,33 +343,30 @@ void CefBrowserPlatformDelegateAlloy::SetAccessibilityState( bool CefBrowserPlatformDelegateAlloy::IsPrintPreviewSupported() const { REQUIRE_ALLOY_RUNTIME(); - auto actionable_contents = GetActionableWebContents(); - if (!actionable_contents) - return false; - - auto cef_browser_context = CefBrowserContext::FromBrowserContext( - actionable_contents->GetBrowserContext()); - if (!cef_browser_context->IsPrintPreviewSupported()) { - return false; - } - // Print preview is not currently supported with OSR. - return !IsWindowless(); + if (IsWindowless()) + return false; + + auto cef_browser_context = + CefBrowserContext::FromBrowserContext(web_contents_->GetBrowserContext()); + return cef_browser_context->IsPrintPreviewSupported(); } void CefBrowserPlatformDelegateAlloy::Print() { REQUIRE_ALLOY_RUNTIME(); - auto actionable_contents = GetActionableWebContents(); - if (!actionable_contents) + auto contents_to_use = printing::GetWebContentsToUse(web_contents_); + if (!contents_to_use) return; - auto rfh = actionable_contents->GetMainFrame(); + auto rfh_to_use = printing::GetRenderFrameHostToUse(contents_to_use); + if (!rfh_to_use) + return; if (IsPrintPreviewSupported()) { - GetPrintViewManager(actionable_contents)->PrintPreviewNow(rfh, false); + GetPrintViewManager(contents_to_use)->PrintPreviewNow(rfh_to_use, false); } else { - GetPrintViewManager(actionable_contents)->PrintNow(rfh); + GetPrintViewManager(contents_to_use)->PrintNow(rfh_to_use); } } @@ -377,17 +376,22 @@ void CefBrowserPlatformDelegateAlloy::PrintToPDF( CefRefPtr callback) { REQUIRE_ALLOY_RUNTIME(); - content::WebContents* actionable_contents = GetActionableWebContents(); - if (!actionable_contents) + auto contents_to_use = printing::GetWebContentsToUse(web_contents_); + if (!contents_to_use) return; + + auto rfh_to_use = printing::GetRenderFrameHostToUse(contents_to_use); + if (!rfh_to_use) + return; + printing::CefPrintViewManager::PdfPrintCallback pdf_callback; if (callback.get()) { pdf_callback = base::BindOnce(&CefPdfPrintCallback::OnPdfPrintFinished, callback.get(), path); } - GetPrintViewManager(actionable_contents) - ->PrintToPDF(actionable_contents->GetMainFrame(), base::FilePath(path), - settings, std::move(pdf_callback)); + GetPrintViewManager(contents_to_use) + ->PrintToPDF(rfh_to_use, base::FilePath(path), settings, + std::move(pdf_callback)); } void CefBrowserPlatformDelegateAlloy::Find(const CefString& searchText, @@ -442,17 +446,6 @@ CefBrowserPlatformDelegateAlloy::GetBoundsChangedCallback() { return base::RepeatingClosure(); } -content::WebContents* -CefBrowserPlatformDelegateAlloy::GetActionableWebContents() const { - if (web_contents_ && extensions::ExtensionsEnabled()) { - content::WebContents* guest_contents = - extensions::GetFullPageGuestForOwnerContents(web_contents_); - if (guest_contents) - return guest_contents; - } - return web_contents_; -} - void CefBrowserPlatformDelegateAlloy::SetOwnedWebContents( content::WebContents* owned_contents) { DCHECK(primary_); diff --git a/libcef/browser/alloy/browser_platform_delegate_alloy.h b/libcef/browser/alloy/browser_platform_delegate_alloy.h index 72fed13b2..30d4b633b 100644 --- a/libcef/browser/alloy/browser_platform_delegate_alloy.h +++ b/libcef/browser/alloy/browser_platform_delegate_alloy.h @@ -81,12 +81,6 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate { base::RepeatingClosure GetBoundsChangedCallback(); - // Returns the WebContents most likely to handle an action. If extensions are - // enabled and this browser has a full-page guest (for example, a full-page - // PDF viewer extension) then the guest's WebContents will be returned. - // Otherwise, the browser's WebContents will be returned. - content::WebContents* GetActionableWebContents() const; - // Called from BrowserPlatformDelegateNative::set_windowless_handler(). void set_as_secondary() { primary_ = false; } diff --git a/libcef/browser/extensions/browser_extensions_util.cc b/libcef/browser/extensions/browser_extensions_util.cc index 3c48921d3..74e94b9e2 100644 --- a/libcef/browser/extensions/browser_extensions_util.cc +++ b/libcef/browser/extensions/browser_extensions_util.cc @@ -15,7 +15,6 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/printing/print_preview_dialog_controller.h" -#include "content/browser/browser_plugin/browser_plugin_embedder.h" #include "content/browser/browser_plugin/browser_plugin_guest.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_context.h" @@ -36,21 +35,6 @@ bool InsertWebContents(std::vector* vector, } // namespace -content::WebContents* GetFullPageGuestForOwnerContents( - content::WebContents* owner) { - content::WebContentsImpl* owner_impl = - static_cast(owner); - content::BrowserPluginEmbedder* plugin_embedder = - owner_impl->GetBrowserPluginEmbedder(); - if (plugin_embedder) { - content::BrowserPluginGuest* plugin_guest = - plugin_embedder->GetFullPageGuest(); - if (plugin_guest) - return plugin_guest->web_contents(); - } - return nullptr; -} - void GetAllGuestsForOwnerContents(content::WebContents* owner, std::vector* guests) { content::BrowserPluginGuestManager* plugin_guest_manager = diff --git a/libcef/browser/extensions/browser_extensions_util.h b/libcef/browser/extensions/browser_extensions_util.h index fda76055c..b4adb7baf 100644 --- a/libcef/browser/extensions/browser_extensions_util.h +++ b/libcef/browser/extensions/browser_extensions_util.h @@ -26,10 +26,6 @@ namespace extensions { class Extension; -// Returns the full-page guest WebContents for the specified |owner|, if any. -content::WebContents* GetFullPageGuestForOwnerContents( - content::WebContents* owner); - // Populates |guests| with all guest WebContents with the specified |owner|. void GetAllGuestsForOwnerContents(content::WebContents* owner, std::vector* guests); diff --git a/patch/patch.cfg b/patch/patch.cfg index c258c3087..18b928b9c 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -333,6 +333,11 @@ patches = [ # https://bitbucket.org/chromiumembedded/cef/issues/2196 'name': 'printing_context_2196', }, + { + # Expose the printing::GetRenderFrameHostToUse() method. + # https://bitbucket.org/chromiumembedded/cef/issues/3057 + 'name': 'printing_pdf_3047', + }, { # Windows: Remove llvmlibthin as the combine_libs.py can't handle those. # https://bitbucket.org/chromiumembedded/cef/issues/2470 diff --git a/patch/patches/printing_pdf_3047.patch b/patch/patches/printing_pdf_3047.patch new file mode 100644 index 000000000..12ea5e060 --- /dev/null +++ b/patch/patches/printing_pdf_3047.patch @@ -0,0 +1,37 @@ +diff --git chrome/browser/printing/print_view_manager_common.cc chrome/browser/printing/print_view_manager_common.cc +index fe86f14eeacb8..41858f4357f8e 100644 +--- chrome/browser/printing/print_view_manager_common.cc ++++ chrome/browser/printing/print_view_manager_common.cc +@@ -53,6 +53,8 @@ bool StoreFullPagePlugin(content::WebContents** result, + } + #endif // BUILDFLAG(ENABLE_EXTENSIONS) + ++} // namespace ++ + // Pick the right RenderFrameHost based on the WebContents. + content::RenderFrameHost* GetRenderFrameHostToUse( + content::WebContents* contents) { +@@ -68,8 +70,6 @@ content::RenderFrameHost* GetRenderFrameHostToUse( + return contents->GetMainFrame(); + } + +-} // namespace +- + void StartPrint( + content::WebContents* contents, + mojo::PendingAssociatedRemote print_renderer, +diff --git chrome/browser/printing/print_view_manager_common.h chrome/browser/printing/print_view_manager_common.h +index bf67ddba35b34..7f4dcc216bbb4 100644 +--- chrome/browser/printing/print_view_manager_common.h ++++ chrome/browser/printing/print_view_manager_common.h +@@ -36,6 +36,10 @@ content::RenderFrameHost* GetFrameToPrint(content::WebContents* contents); + // guest's WebContents instead. + content::WebContents* GetWebContentsToUse(content::WebContents* contents); + ++// Pick the right RenderFrameHost based on the WebContents. ++content::RenderFrameHost* GetRenderFrameHostToUse( ++ content::WebContents* contents); ++ + } // namespace printing + + #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_COMMON_H_