mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-21 14:40:49 +01:00
alloy: Fix printing of PDF viewer (see issue #3047)
Match the logic for printing::StartPrint() used by Chrome.
This commit is contained in:
parent
171d525aa4
commit
dc0a45d429
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "chrome/browser/printing/print_view_manager.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 "chrome/browser/ui/prefs/prefs_tab_helper.h"
|
||||||
#include "components/find_in_page/find_tab_helper.h"
|
#include "components/find_in_page/find_tab_helper.h"
|
||||||
#include "components/find_in_page/find_types.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_view_host.h"
|
||||||
#include "content/public/browser/render_widget_host.h"
|
#include "content/public/browser/render_widget_host.h"
|
||||||
#include "extensions/browser/process_manager.h"
|
#include "extensions/browser/process_manager.h"
|
||||||
|
#include "pdf/pdf_features.h"
|
||||||
#include "printing/mojom/print.mojom.h"
|
#include "printing/mojom/print.mojom.h"
|
||||||
#include "third_party/blink/public/mojom/frame/find_in_page.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 {
|
bool CefBrowserPlatformDelegateAlloy::IsPrintPreviewSupported() const {
|
||||||
REQUIRE_ALLOY_RUNTIME();
|
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.
|
// 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() {
|
void CefBrowserPlatformDelegateAlloy::Print() {
|
||||||
REQUIRE_ALLOY_RUNTIME();
|
REQUIRE_ALLOY_RUNTIME();
|
||||||
|
|
||||||
auto actionable_contents = GetActionableWebContents();
|
auto contents_to_use = printing::GetWebContentsToUse(web_contents_);
|
||||||
if (!actionable_contents)
|
if (!contents_to_use)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto rfh = actionable_contents->GetMainFrame();
|
auto rfh_to_use = printing::GetRenderFrameHostToUse(contents_to_use);
|
||||||
|
if (!rfh_to_use)
|
||||||
|
return;
|
||||||
|
|
||||||
if (IsPrintPreviewSupported()) {
|
if (IsPrintPreviewSupported()) {
|
||||||
GetPrintViewManager(actionable_contents)->PrintPreviewNow(rfh, false);
|
GetPrintViewManager(contents_to_use)->PrintPreviewNow(rfh_to_use, false);
|
||||||
} else {
|
} else {
|
||||||
GetPrintViewManager(actionable_contents)->PrintNow(rfh);
|
GetPrintViewManager(contents_to_use)->PrintNow(rfh_to_use);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,17 +376,22 @@ void CefBrowserPlatformDelegateAlloy::PrintToPDF(
|
|||||||
CefRefPtr<CefPdfPrintCallback> callback) {
|
CefRefPtr<CefPdfPrintCallback> callback) {
|
||||||
REQUIRE_ALLOY_RUNTIME();
|
REQUIRE_ALLOY_RUNTIME();
|
||||||
|
|
||||||
content::WebContents* actionable_contents = GetActionableWebContents();
|
auto contents_to_use = printing::GetWebContentsToUse(web_contents_);
|
||||||
if (!actionable_contents)
|
if (!contents_to_use)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto rfh_to_use = printing::GetRenderFrameHostToUse(contents_to_use);
|
||||||
|
if (!rfh_to_use)
|
||||||
|
return;
|
||||||
|
|
||||||
printing::CefPrintViewManager::PdfPrintCallback pdf_callback;
|
printing::CefPrintViewManager::PdfPrintCallback pdf_callback;
|
||||||
if (callback.get()) {
|
if (callback.get()) {
|
||||||
pdf_callback = base::BindOnce(&CefPdfPrintCallback::OnPdfPrintFinished,
|
pdf_callback = base::BindOnce(&CefPdfPrintCallback::OnPdfPrintFinished,
|
||||||
callback.get(), path);
|
callback.get(), path);
|
||||||
}
|
}
|
||||||
GetPrintViewManager(actionable_contents)
|
GetPrintViewManager(contents_to_use)
|
||||||
->PrintToPDF(actionable_contents->GetMainFrame(), base::FilePath(path),
|
->PrintToPDF(rfh_to_use, base::FilePath(path), settings,
|
||||||
settings, std::move(pdf_callback));
|
std::move(pdf_callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefBrowserPlatformDelegateAlloy::Find(const CefString& searchText,
|
void CefBrowserPlatformDelegateAlloy::Find(const CefString& searchText,
|
||||||
@ -442,17 +446,6 @@ CefBrowserPlatformDelegateAlloy::GetBoundsChangedCallback() {
|
|||||||
return base::RepeatingClosure();
|
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(
|
void CefBrowserPlatformDelegateAlloy::SetOwnedWebContents(
|
||||||
content::WebContents* owned_contents) {
|
content::WebContents* owned_contents) {
|
||||||
DCHECK(primary_);
|
DCHECK(primary_);
|
||||||
|
@ -81,12 +81,6 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
|
|||||||
|
|
||||||
base::RepeatingClosure GetBoundsChangedCallback();
|
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().
|
// Called from BrowserPlatformDelegateNative::set_windowless_handler().
|
||||||
void set_as_secondary() { primary_ = false; }
|
void set_as_secondary() { primary_ = false; }
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include "chrome/browser/browser_process.h"
|
#include "chrome/browser/browser_process.h"
|
||||||
#include "chrome/browser/printing/print_preview_dialog_controller.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/browser_plugin/browser_plugin_guest.h"
|
||||||
#include "content/browser/web_contents/web_contents_impl.h"
|
#include "content/browser/web_contents/web_contents_impl.h"
|
||||||
#include "content/public/browser/browser_context.h"
|
#include "content/public/browser/browser_context.h"
|
||||||
@ -36,21 +35,6 @@ bool InsertWebContents(std::vector<content::WebContents*>* vector,
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
content::WebContents* GetFullPageGuestForOwnerContents(
|
|
||||||
content::WebContents* owner) {
|
|
||||||
content::WebContentsImpl* owner_impl =
|
|
||||||
static_cast<content::WebContentsImpl*>(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,
|
void GetAllGuestsForOwnerContents(content::WebContents* owner,
|
||||||
std::vector<content::WebContents*>* guests) {
|
std::vector<content::WebContents*>* guests) {
|
||||||
content::BrowserPluginGuestManager* plugin_guest_manager =
|
content::BrowserPluginGuestManager* plugin_guest_manager =
|
||||||
|
@ -26,10 +26,6 @@ namespace extensions {
|
|||||||
|
|
||||||
class Extension;
|
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|.
|
// Populates |guests| with all guest WebContents with the specified |owner|.
|
||||||
void GetAllGuestsForOwnerContents(content::WebContents* owner,
|
void GetAllGuestsForOwnerContents(content::WebContents* owner,
|
||||||
std::vector<content::WebContents*>* guests);
|
std::vector<content::WebContents*>* guests);
|
||||||
|
@ -333,6 +333,11 @@ patches = [
|
|||||||
# https://bitbucket.org/chromiumembedded/cef/issues/2196
|
# https://bitbucket.org/chromiumembedded/cef/issues/2196
|
||||||
'name': 'printing_context_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.
|
# Windows: Remove llvmlibthin as the combine_libs.py can't handle those.
|
||||||
# https://bitbucket.org/chromiumembedded/cef/issues/2470
|
# https://bitbucket.org/chromiumembedded/cef/issues/2470
|
||||||
|
37
patch/patches/printing_pdf_3047.patch
Normal file
37
patch/patches/printing_pdf_3047.patch
Normal file
@ -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<mojom::PrintRenderer> 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_
|
Loading…
x
Reference in New Issue
Block a user