Commit 68aabd92 authored by Wei Li's avatar Wei Li Committed by Commit Bot

Identify PDF file being printed by checking URL

There are two cases that PDF files are being printed: from print
preview or directly from PDF plugin extension. Our previous way of
identifying a PDF file being printed replies on the printed
document's setting 'is_modifiable' is correctly set up. However,
it was only set up when print preview is enabled, not when using
system dialog. This CL fixed that by directly checking the web URL.

Also since the web url can be checked for print preview, we no
longer need to keep the flag 'for_preview' inside print composite
client. So removed that.

BUG=820143

Change-Id: I8c9051d5e2945b1d5a4b9f74494fbe3f6ad795f2
Reviewed-on: https://chromium-review.googlesource.com/958298
Commit-Queue: Wei Li <weili@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542630}
parent f68fa532
......@@ -377,7 +377,7 @@ WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog(
content::HostZoomMap::Get(preview_dialog->GetSiteInstance())
->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0);
PrintViewManager::CreateForWebContents(preview_dialog);
CreateCompositeClientIfNeeded(preview_dialog, true /* for_preview */);
CreateCompositeClientIfNeeded(preview_dialog);
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
preview_dialog);
......
......@@ -24,6 +24,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/print_view_manager_common.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/simple_message_box.h"
......@@ -353,8 +354,7 @@ void PrintViewManagerBase::OnDidPrintDocument(
}
auto* client = PrintCompositeClient::FromWebContents(web_contents());
if (IsOopifEnabled() && !client->for_preview() &&
document->settings().is_modifiable()) {
if (IsOopifEnabled() && !PrintingPdfContent(render_frame_host)) {
client->DoCompositeDocumentToPdf(
params.document_cookie, render_frame_host, content.metafile_data_handle,
content.data_size, content.subframe_content_info,
......
......@@ -4,9 +4,12 @@
#include "chrome/browser/printing/print_view_manager_common.h"
#include "chrome/common/webui_url_constants.h"
#include "content/public/browser/render_frame_host.h"
#include "extensions/buildflags/buildflags.h"
#include "extensions/common/constants.h"
#include "printing/features/features.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "components/guest_view/browser/guest_view_manager.h"
......@@ -122,4 +125,12 @@ content::RenderFrameHost* GetFrameToPrint(content::WebContents* contents) {
: contents->GetMainFrame();
}
bool PrintingPdfContent(content::RenderFrameHost* rfh) {
GURL url = rfh->GetLastCommittedURL();
// Whether it is inside print preview or pdf plugin extension.
return url.GetOrigin() == chrome::kChromeUIPrintURL ||
(url.SchemeIs(extensions::kExtensionScheme) &&
url.host_piece() == extension_misc::kPdfExtensionId);
}
} // namespace printing
......@@ -28,6 +28,13 @@ void StartBasicPrint(content::WebContents* contents);
// frame (this makes print selection work for multiple frames).
content::RenderFrameHost* GetFrameToPrint(content::WebContents* contents);
// Whether the content sent to |rfh| is in PDF format.
// When print preview dialog is printed, the content returned is always
// in PDF format because print preview already stores the PDF file for
// the previewed web page; When a full page PDF plugin is printed, the document
// in it is in PDF format so will return in PDF also.
bool PrintingPdfContent(content::RenderFrameHost* rfh);
} // namespace printing
#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_COMMON_H_
......@@ -24,7 +24,7 @@ void InitializePrinting(content::WebContents* web_contents) {
#else
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
CreateCompositeClientIfNeeded(web_contents, false /* for_preview */);
CreateCompositeClientIfNeeded(web_contents);
}
} // namespace printing
......@@ -31,7 +31,7 @@ uint64_t GenerateFrameGuid(int process_id, int frame_id) {
namespace printing {
PrintCompositeClient::PrintCompositeClient(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), for_preview_(false) {}
: content::WebContentsObserver(web_contents) {}
PrintCompositeClient::~PrintCompositeClient() {}
......
......@@ -75,9 +75,6 @@ class PrintCompositeClient
const ContentToProxyIdMap& subframe_content_info,
mojom::PdfCompositor::CompositeDocumentToPdfCallback callback);
void set_for_preview(bool for_preview) { for_preview_ = for_preview; }
bool for_preview() const { return for_preview_; }
// Converts a ContentToProxyIdMap to ContentToFrameMap.
// ContentToProxyIdMap maps content id to its corresponding render frame proxy
// routing id. This is generated when the content holder was created;
......@@ -116,9 +113,6 @@ class PrintCompositeClient
mojom::PdfCompositorPtr CreateCompositeRequest();
// Whether this client is created for print preview dialog.
bool for_preview_;
std::unique_ptr<service_manager::Connector> connector_;
// Stores the mapping between document cookies and their corresponding
......
......@@ -25,8 +25,7 @@ bool IsOopifEnabled() {
return g_oopif_enabled;
}
void CreateCompositeClientIfNeeded(content::WebContents* web_contents,
bool for_preview) {
void CreateCompositeClientIfNeeded(content::WebContents* web_contents) {
// TODO(weili): We only create pdf compositor client and use pdf compositor
// service when site-per-process or isolate-origins flag/feature is enabled,
// or top-document-isolation feature is enabled. This may not cover all cases
......@@ -43,10 +42,6 @@ void CreateCompositeClientIfNeeded(content::WebContents* web_contents,
switches::kDisableSiteIsolationTrials)) ||
base::FeatureList::IsEnabled(features::kTopDocumentIsolation)) {
PrintCompositeClient::CreateForWebContents(web_contents);
if (for_preview) {
PrintCompositeClient::FromWebContents(web_contents)
->set_for_preview(true);
}
SetOopifEnabled();
}
}
......
......@@ -20,8 +20,7 @@ bool IsOopifEnabled();
// Check on the current feature settings to decide whether we need to
// create a PDF compositor client for this |web_contents|.
void CreateCompositeClientIfNeeded(content::WebContents* web_contents,
bool for_preview);
void CreateCompositeClientIfNeeded(content::WebContents* web_contents);
// Converts given settings to Print_Params and stores them in the output
// parameter |params|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment