Add a new PrintRasterizePdfDpi policy.
This new policy is to provide an optional control on the resolution used when rasterizing a PDF to images. This happens when using the Print to image option in Print Preview. The Print to image option is always available on Linux and ChromeOS, and is available on Windows and macOS via the PrintAsImageAvailableForPdf policy. This equates to all of the platforms for which Print Preview is enabled. The policy specifies an integer for the DPI to rasterize to. Without this policy the printer specific or system default (depends upon OS) resolution will be used. A non-positive resolution value would be nonsensical, and behaves the same as if the policy were not even present. This enables administrators to choose a resolution to be used with print rasterization that balances image quality with printing speed that is acceptable for an organization. TESTED=Manually on Windows by setting a registry DWORD value for Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Chromium\PrintAsImageAvailableForPdf and also setting a registry DWORD value for Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Chromium\PrintRasterizePdfDpi and manually tested for ChromeOS on Linux with policy file placed in /etc/chromium/policies/managed Bug: 1233149 Change-Id: Iefbb6814030124adfe885e0e90847fe26f1ddffa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3084502 Commit-Queue: Alan Screen <awscreen@chromium.org> Reviewed-by: Alex Gough <ajgo@chromium.org> Reviewed-by: Owen Min <zmin@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#911490}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
600af8c875
commit
dce2e585ba
chrome
browser
policy
printing
profiles
common
test
data
policy
components
policy
resources
printing
printing
print_job_constants.ccprint_job_constants.hprint_settings.ccprint_settings.hprint_settings_conversion.ccprint_settings_conversion_unittest.cc
tools/metrics/histograms
@ -1285,6 +1285,12 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
|
||||
base::Value::Type::BOOLEAN },
|
||||
#endif // defined(OS_WIN) || defined(OS_MAC)
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
||||
{ key::kPrintRasterizePdfDpi,
|
||||
prefs::kPrintRasterizePdfDpi,
|
||||
base::Value::Type::INTEGER },
|
||||
#endif // BUILDFLAGS(ENABLE_PRINT_PREVIEW)
|
||||
|
||||
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
|
||||
{ key::kNativeMessagingUserLevelHosts,
|
||||
extensions::pref_names::kNativeMessagingUserLevelHosts,
|
||||
|
@ -61,6 +61,7 @@
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
||||
#include "chrome/browser/printing/print_error_dialog.h"
|
||||
#include "chrome/browser/printing/print_view_manager.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
|
||||
@ -673,6 +674,16 @@ void PrintViewManagerBase::UpdatePrintSettings(
|
||||
return;
|
||||
}
|
||||
|
||||
content::BrowserContext* context =
|
||||
web_contents() ? web_contents()->GetBrowserContext() : nullptr;
|
||||
PrefService* prefs =
|
||||
context ? Profile::FromBrowserContext(context)->GetPrefs() : nullptr;
|
||||
if (prefs && prefs->HasPrefPath(prefs::kPrintRasterizePdfDpi)) {
|
||||
int value = prefs->GetInteger(prefs::kPrintRasterizePdfDpi);
|
||||
if (value > 0)
|
||||
job_settings.SetIntKey(kSettingRasterizePdfDpi, value);
|
||||
}
|
||||
|
||||
content::RenderFrameHost* render_frame_host = GetCurrentTargetFrame();
|
||||
auto callback_wrapper =
|
||||
base::BindOnce(&PrintViewManagerBase::UpdatePrintSettingsReply,
|
||||
|
@ -428,6 +428,9 @@ void ProfileImpl::RegisterProfilePrefs(
|
||||
#if defined(OS_WIN) && BUILDFLAG(ENABLE_PRINTING)
|
||||
registry->RegisterIntegerPref(prefs::kPrintRasterizationMode, 0);
|
||||
#endif
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
||||
registry->RegisterIntegerPref(prefs::kPrintRasterizePdfDpi, 0);
|
||||
#endif
|
||||
|
||||
registry->RegisterBooleanPref(prefs::kForceEphemeralProfiles, false);
|
||||
registry->RegisterBooleanPref(prefs::kEnableMediaRouter, true);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "chrome/common/pref_font_webkit_names.h"
|
||||
#include "extensions/buildflags/buildflags.h"
|
||||
#include "ppapi/buildflags/buildflags.h"
|
||||
#include "printing/buildflags/buildflags.h"
|
||||
|
||||
namespace prefs {
|
||||
|
||||
@ -1349,6 +1350,12 @@ const char kPrintPdfAsImageAvailability[] =
|
||||
"printing.print_pdf_as_image_availability";
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
||||
// An integer resolution to use for DPI when rasterizing PDFs with "Print to
|
||||
// image".
|
||||
const char kPrintRasterizePdfDpi[] = "printing.rasterize_pdf_dpi";
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN) && BUILDFLAG(ENABLE_PRINTING)
|
||||
// An integer pref that holds the rasterization mode to use when printing.
|
||||
const char kPrintRasterizationMode[] = "printing.rasterization_mode";
|
||||
|
@ -442,6 +442,10 @@ extern const char kPrintPreviewDefaultDestinationSelectionRules[];
|
||||
extern const char kPrintPdfAsImageAvailability[];
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
|
||||
extern const char kPrintRasterizePdfDpi[];
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN) && BUILDFLAG(ENABLE_PRINTING)
|
||||
extern const char kPrintRasterizationMode[];
|
||||
#endif
|
||||
|
@ -653,6 +653,25 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"PrintRasterizePdfDpi": {
|
||||
"os": [
|
||||
"win",
|
||||
"linux",
|
||||
"mac",
|
||||
"chromeos_ash",
|
||||
"chromeos_lacros"
|
||||
],
|
||||
"policy_pref_mapping_tests": [
|
||||
{
|
||||
"policies": {
|
||||
"PrintRasterizePdfDpi": 300
|
||||
},
|
||||
"prefs": {
|
||||
"printing.rasterize_pdf_dpi": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PrinterTypeDenyList": {
|
||||
"os": [
|
||||
"win",
|
||||
|
@ -1123,6 +1123,7 @@
|
||||
'PrinterTypeDenyList',
|
||||
'PrintRasterizationMode',
|
||||
'PrintPdfAsImageAvailability',
|
||||
'PrintRasterizePdfDpi',
|
||||
'DeletePrintJobHistoryAllowed',
|
||||
'CloudPrintWarningsSuppressed',
|
||||
]
|
||||
@ -24073,6 +24074,32 @@
|
||||
|
||||
When this policy is set to Disabled or not set <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> the Print as image option will not be available to users in Print Preview and PDFs will be printed as usual without being rasterized to an image before being sent to the destination.'''
|
||||
},
|
||||
{
|
||||
'name': 'PrintRasterizePdfDpi',
|
||||
'owners': ['awscreen@chromium.org', 'file://printing/OWNERS'],
|
||||
'type': 'int',
|
||||
'schema': {
|
||||
'type': 'integer',
|
||||
'minimum': 0,
|
||||
},
|
||||
'supported_on': ['chrome.*:94-', 'chrome_os:94-'],
|
||||
'features': {
|
||||
'dynamic_refresh': True,
|
||||
'per_profile': True,
|
||||
},
|
||||
'example_value': 300,
|
||||
'default': 0,
|
||||
'id': 890,
|
||||
'caption': '''Print Rasterize PDF DPI''',
|
||||
'tags': [],
|
||||
'desc': '''Controls print image resolution when <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> prints PDFs with rasterization.
|
||||
|
||||
When printing a PDF using the Print to image option, it can be beneficial to specify a print resolution other than a device's printer setting or the PDF default. A high resolution will significantly increase the processing and printing time while a low resolution can lead to poor imaging quality.
|
||||
|
||||
This policy allows a particular resolution to be specified for use when rasterizing PDFs for printing.
|
||||
|
||||
If this policy is set to zero or not set at all then the system default resolution will be used during rasterization of page images.'''
|
||||
},
|
||||
{
|
||||
'name': 'DeletePrintJobHistoryAllowed',
|
||||
'owners': ['jimmyxgong@chromium.org', 'file://printing/OWNERS'],
|
||||
@ -28021,6 +28048,6 @@ The recommended way to configure policy on Windows is via GPO, although provisio
|
||||
'placeholders': [],
|
||||
'deleted_policy_ids': [114, 115, 204, 205, 206, 412, 476, 544, 546, 562, 569, 578, 583, 585, 586, 587, 588, 589, 590, 591, 600, 668, 669],
|
||||
'deleted_atomic_policy_group_ids': [19],
|
||||
'highest_id_currently_used': 889,
|
||||
'highest_id_currently_used': 890,
|
||||
'highest_atomic_group_id_currently_used': 41
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ void RenderParamsFromPrintSettings(const PrintSettings& settings,
|
||||
params->dpi = settings.dpi_size();
|
||||
params->scale_factor = settings.scale_factor();
|
||||
params->rasterize_pdf = settings.rasterize_pdf();
|
||||
params->rasterize_pdf_dpi = settings.rasterize_pdf_dpi();
|
||||
// Always use an invalid cookie.
|
||||
params->document_cookie = 0;
|
||||
params->selection_only = settings.selection_only();
|
||||
|
@ -148,6 +148,10 @@ struct PrintParams {
|
||||
mojo_base.mojom.String16 footer_template;
|
||||
// Whether to rasterize a PDF for printing
|
||||
bool rasterize_pdf = false;
|
||||
// Override of the DPI to use if `rasterize_pdf` is true. A non-positive
|
||||
// value would be an invalid choice of a DPI, and indicates no override
|
||||
// should be applied.
|
||||
int32 rasterize_pdf_dpi = 0;
|
||||
// True if print backgrounds is requested by the user.
|
||||
bool should_print_backgrounds = false;
|
||||
// The document type of printed page(s) from render.
|
||||
|
@ -331,6 +331,9 @@ void ComputeWebKitPrintParamsInDesiredDpi(
|
||||
// See https://crbug.com/943462
|
||||
webkit_print_params->printer_dpi = kDefaultPdfDpi;
|
||||
#endif
|
||||
|
||||
if (print_params.rasterize_pdf && print_params.rasterize_pdf_dpi > 0)
|
||||
webkit_print_params->printer_dpi = print_params.rasterize_pdf_dpi;
|
||||
}
|
||||
webkit_print_params->rasterize_pdf = print_params.rasterize_pdf;
|
||||
webkit_print_params->print_scaling_option = print_params.print_scaling_option;
|
||||
|
@ -180,6 +180,9 @@ const char kSettingPagesPerSheet[] = "pagesPerSheet";
|
||||
// Whether to rasterize the PDF for printing.
|
||||
const char kSettingRasterizePdf[] = "rasterizePDF";
|
||||
|
||||
// The DPI override to use when rasterize the PDF for printing.
|
||||
const char kSettingRasterizePdfDpi[] = "rasterizePdfDpi";
|
||||
|
||||
// Ticket option. Contains the ticket in CJT format.
|
||||
const char kSettingTicket[] = "ticket";
|
||||
|
||||
|
@ -117,6 +117,8 @@ extern const char kSettingPrinterType[];
|
||||
COMPONENT_EXPORT(PRINTING_BASE)
|
||||
extern const char kSettingRasterizePdf[];
|
||||
COMPONENT_EXPORT(PRINTING_BASE)
|
||||
extern const char kSettingRasterizePdfDpi[];
|
||||
COMPONENT_EXPORT(PRINTING_BASE)
|
||||
extern const char kSettingScaleFactor[];
|
||||
COMPONENT_EXPORT(PRINTING_BASE)
|
||||
extern const char kSettingScalingType[];
|
||||
|
@ -274,6 +274,7 @@ void PrintSettings::Clear() {
|
||||
dpi_ = gfx::Size();
|
||||
scale_factor_ = 1.0f;
|
||||
rasterize_pdf_ = false;
|
||||
rasterize_pdf_dpi_ = 0;
|
||||
landscape_ = false;
|
||||
supports_alpha_blend_ = true;
|
||||
#if defined(OS_WIN)
|
||||
|
@ -137,6 +137,9 @@ class COMPONENT_EXPORT(PRINTING) PrintSettings {
|
||||
void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
|
||||
bool rasterize_pdf() const { return rasterize_pdf_; }
|
||||
|
||||
void set_rasterize_pdf_dpi(int32_t dpi) { rasterize_pdf_dpi_ = dpi; }
|
||||
int32_t rasterize_pdf_dpi() const { return rasterize_pdf_dpi_; }
|
||||
|
||||
void set_supports_alpha_blend(bool supports_alpha_blend) {
|
||||
supports_alpha_blend_ = supports_alpha_blend;
|
||||
}
|
||||
@ -297,6 +300,11 @@ class COMPONENT_EXPORT(PRINTING) PrintSettings {
|
||||
// True if PDF should be printed as a raster PDF
|
||||
bool rasterize_pdf_;
|
||||
|
||||
// The DPI which overrides the calculated value normally used when
|
||||
// rasterizing a PDF. A non-positive value would be an invalid choice of a
|
||||
// DPI and indicates no override.
|
||||
int32_t rasterize_pdf_dpi_;
|
||||
|
||||
// Is the orientation landscape or portrait.
|
||||
bool landscape_;
|
||||
|
||||
|
@ -192,6 +192,11 @@ std::unique_ptr<PrintSettings> PrintSettingsFromJobSettings(
|
||||
return nullptr;
|
||||
settings->set_dpi_xy(dpi_horizontal.value(), dpi_vertical.value());
|
||||
|
||||
absl::optional<int> rasterize_pdf_dpi =
|
||||
job_settings.FindIntKey(kSettingRasterizePdfDpi);
|
||||
if (rasterize_pdf_dpi.has_value())
|
||||
settings->set_rasterize_pdf_dpi(rasterize_pdf_dpi.value());
|
||||
|
||||
settings->set_collate(collate.value());
|
||||
settings->set_copies(copies.value());
|
||||
settings->SetOrientation(landscape.value());
|
||||
|
@ -38,6 +38,7 @@ const char kPrinterSettings[] = R"({
|
||||
"deviceName": "printer",
|
||||
"scaleFactor": 100,
|
||||
"rasterizePDF": false,
|
||||
"rasterizePdfDpi": 150,
|
||||
"pagesPerSheet": 1,
|
||||
"dpiHorizontal": 300,
|
||||
"dpiVertical": 300,
|
||||
@ -71,6 +72,7 @@ TEST(PrintSettingsConversionTest, ConversionTest) {
|
||||
value->SetIntKey("dpiVertical", 600);
|
||||
settings = PrintSettingsFromJobSettings(value.value());
|
||||
ASSERT_TRUE(settings);
|
||||
EXPECT_EQ(settings->rasterize_pdf_dpi(), 150);
|
||||
EXPECT_EQ(settings->dpi_horizontal(), 300);
|
||||
EXPECT_EQ(settings->dpi_vertical(), 600);
|
||||
EXPECT_TRUE(value->RemoveKey("dpiVertical"));
|
||||
|
@ -26017,6 +26017,7 @@ Called by update_document_policy_enum.py.-->
|
||||
<int value="887" label="ArcAppToWebAppSharingEnabled"/>
|
||||
<int value="888" label="EnhancedNetworkVoicesInSelectToSpeakAllowed"/>
|
||||
<int value="889" label="PrintPdfAsImageAvailability"/>
|
||||
<int value="890" label="PrintRasterizePdfDpi"/>
|
||||
</enum>
|
||||
|
||||
<enum name="EnterprisePolicyDeviceIdValidity">
|
||||
|
Reference in New Issue
Block a user