| Index: chrome/browser/printing/print_view_manager_common.cc
|
| diff --git a/chrome/browser/printing/print_view_manager_common.cc b/chrome/browser/printing/print_view_manager_common.cc
|
| index 097220415f1ea81bec36122b1a23d4437c74e5eb..61f185131c061a46538b9f067bd3399bafc80309 100644
|
| --- a/chrome/browser/printing/print_view_manager_common.cc
|
| +++ b/chrome/browser/printing/print_view_manager_common.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "chrome/browser/printing/print_view_manager_common.h"
|
|
|
| +#include "content/public/browser/render_frame_host.h"
|
| +
|
| #if defined(ENABLE_EXTENSIONS)
|
| #include "components/guest_view/browser/guest_view_manager.h"
|
| #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
|
| @@ -16,6 +18,7 @@
|
| #endif // defined(ENABLE_PRINT_PREVIEW)
|
|
|
| namespace printing {
|
| +
|
| namespace {
|
| #if defined(ENABLE_EXTENSIONS)
|
| // Stores |guest_contents| in |result| and returns true if |guest_contents| is a
|
| @@ -48,43 +51,73 @@ content::WebContents* GetWebContentsToUse(content::WebContents* contents) {
|
| return contents;
|
| }
|
|
|
| +// Pick the right RenderFrameHost based on the WebContentses.
|
| +content::RenderFrameHost* GetRenderFrameHostToUse(
|
| + content::WebContents* original_contents,
|
| + content::WebContents* contents_to_use) {
|
| + if (original_contents != contents_to_use)
|
| + return contents_to_use->GetMainFrame();
|
| + return GetFrameToPrint(contents_to_use);
|
| +}
|
| +
|
| } // namespace
|
|
|
| void StartPrint(content::WebContents* contents,
|
| bool print_preview_disabled,
|
| - bool selection_only) {
|
| + bool has_selection) {
|
| #if defined(ENABLE_PRINT_PREVIEW)
|
| using PrintViewManagerImpl = PrintViewManager;
|
| #else
|
| using PrintViewManagerImpl = PrintViewManagerBasic;
|
| #endif // defined(ENABLE_PRINT_PREVIEW)
|
|
|
| + content::WebContents* contents_to_use = GetWebContentsToUse(contents);
|
| auto* print_view_manager =
|
| - PrintViewManagerImpl::FromWebContents(GetWebContentsToUse(contents));
|
| + PrintViewManagerImpl::FromWebContents(contents_to_use);
|
| if (!print_view_manager)
|
| return;
|
| +
|
| + content::RenderFrameHost* rfh_to_use =
|
| + GetRenderFrameHostToUse(contents, contents_to_use);
|
| + if (!rfh_to_use)
|
| + return;
|
| +
|
| #if defined(ENABLE_PRINT_PREVIEW)
|
| if (!print_preview_disabled) {
|
| - print_view_manager->PrintPreviewNow(selection_only);
|
| + print_view_manager->PrintPreviewNow(rfh_to_use, has_selection);
|
| return;
|
| }
|
| #endif // ENABLE_PRINT_PREVIEW
|
|
|
| #if defined(ENABLE_BASIC_PRINTING)
|
| - print_view_manager->PrintNow();
|
| + print_view_manager->PrintNow(rfh_to_use);
|
| #endif // ENABLE_BASIC_PRINTING
|
| }
|
|
|
| #if defined(ENABLE_BASIC_PRINTING)
|
| void StartBasicPrint(content::WebContents* contents) {
|
| #if defined(ENABLE_PRINT_PREVIEW)
|
| + content::WebContents* contents_to_use = GetWebContentsToUse(contents);
|
| PrintViewManager* print_view_manager =
|
| - PrintViewManager::FromWebContents(GetWebContentsToUse(contents));
|
| + PrintViewManager::FromWebContents(contents_to_use);
|
| if (!print_view_manager)
|
| return;
|
| - print_view_manager->BasicPrint();
|
| +
|
| + content::RenderFrameHost* rfh_to_use =
|
| + GetRenderFrameHostToUse(contents, contents_to_use);
|
| + if (!rfh_to_use)
|
| + return;
|
| +
|
| + print_view_manager->BasicPrint(rfh_to_use);
|
| #endif // ENABLE_PRINT_PREVIEW
|
| }
|
| #endif // ENABLE_BASIC_PRINTING
|
|
|
| +content::RenderFrameHost* GetFrameToPrint(content::WebContents* contents) {
|
| + auto* focused_frame = contents->GetFocusedFrame();
|
| + return (focused_frame && focused_frame->HasSelection())
|
| + ? focused_frame
|
| + : contents->GetMainFrame();
|
| +}
|
| +
|
| } // namespace printing
|
|
|