Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2306)

Unified Diff: chrome/browser/printing/print_view_manager_common.cc

Issue 2508923003: Make printing work better with OOPIF. (try 2) (Closed)
Patch Set: Fix android_webview Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 83a94f7f5b21f4afca2e69cc1bff910cd6bc131f..1832389b903dbcecca9c41c942db7b7ee6e32121 100644
--- a/chrome/browser/printing/print_view_manager_common.cc
+++ b/chrome/browser/printing/print_view_manager_common.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/printing/print_view_manager_common.h"
+#include "content/public/browser/render_frame_host.h"
#include "extensions/features/features.h"
#include "printing/features/features.h"
@@ -19,6 +20,7 @@
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
namespace printing {
+
namespace {
#if BUILDFLAG(ENABLE_EXTENSIONS)
// Stores |guest_contents| in |result| and returns true if |guest_contents| is a
@@ -51,43 +53,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 BUILDFLAG(ENABLE_PRINT_PREVIEW)
using PrintViewManagerImpl = PrintViewManager;
#else
using PrintViewManagerImpl = PrintViewManagerBasic;
#endif // BUILDFLAG(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 BUILDFLAG(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 BUILDFLAG(ENABLE_BASIC_PRINTING)
- print_view_manager->PrintNow();
+ print_view_manager->PrintNow(rfh_to_use);
#endif // ENABLE_BASIC_PRINTING
}
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
void StartBasicPrint(content::WebContents* contents) {
#if BUILDFLAG(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
« no previous file with comments | « chrome/browser/printing/print_view_manager_common.h ('k') | chrome/browser/printing/printing_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698