summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/ui/webui/print_preview
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-08-24 12:15:48 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-08-28 13:30:04 +0000
commitb014812705fc80bff0a5c120dfcef88f349816dc (patch)
tree25a2e2d9fa285f1add86aa333389a839f81a39ae /chromium/chrome/browser/ui/webui/print_preview
parent9f4560b1027ae06fdb497023cdcaf91b8511fa74 (diff)
downloadqtwebengine-chromium-b014812705fc80bff0a5c120dfcef88f349816dc.tar.gz
BASELINE: Update Chromium to 68.0.3440.125
Change-Id: I23f19369e01f688e496f5bf179abb521ad73874f Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/chrome/browser/ui/webui/print_preview')
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.cc81
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.h1
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler_unittest.cc63
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.cc9
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.h2
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.cc250
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc12
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.cc22
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.h3
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc2
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/printer_handler.h1
11 files changed, 216 insertions, 230 deletions
diff --git a/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.cc b/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.cc
index 395ee71d9f4..78b67d27f48 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.cc
@@ -9,9 +9,6 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/files/file.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h"
@@ -58,35 +55,15 @@ const char kInvalidTicketPrintError[] = "INVALID_TICKET";
const char kProvisionalUsbLabel[] = "provisional-usb";
-// Updates |job| with raster file path, size and last modification time.
-// Returns the updated print job.
-std::unique_ptr<extensions::PrinterProviderPrintJob>
-UpdateJobFileInfoOnWorkerThread(
- const base::FilePath& raster_path,
- std::unique_ptr<extensions::PrinterProviderPrintJob> job) {
- if (base::GetFileInfo(raster_path, &job->file_info))
- job->document_path = raster_path;
- return job;
-}
-
-// Callback to PWG raster conversion.
-// Posts a task to update print job with info about file containing converted
-// PWG raster data.
+// Updates |job| with raster data. Returns the updated print job.
void UpdateJobFileInfo(std::unique_ptr<extensions::PrinterProviderPrintJob> job,
ExtensionPrinterHandler::PrintJobCallback callback,
- bool success,
- const base::FilePath& pwg_file_path) {
- if (!success) {
- std::move(callback).Run(std::move(job));
- return;
- }
-
- base::PostTaskWithTraitsAndReplyWithResult(
- FROM_HERE,
- {base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
- base::BindOnce(&UpdateJobFileInfoOnWorkerThread, pwg_file_path,
- std::move(job)),
- std::move(callback));
+ base::ReadOnlySharedMemoryRegion pwg_region) {
+ auto data =
+ base::RefCountedSharedMemoryMapping::CreateFromWholeRegion(pwg_region);
+ if (data)
+ job->document_bytes = data;
+ std::move(callback).Run(std::move(job));
}
bool HasUsbPrinterProviderPermissions(const Extension* extension) {
@@ -120,6 +97,11 @@ bool ParseProvisionalUsbPrinterId(const std::string& printer_id,
return true;
}
+extensions::PrinterProviderAPI* GetPrinterProviderAPI(Profile* profile) {
+ return extensions::PrinterProviderAPIFactory::GetInstance()
+ ->GetForBrowserContext(profile);
+}
+
} // namespace
ExtensionPrinterHandler::ExtensionPrinterHandler(Profile* profile)
@@ -161,22 +143,18 @@ void ExtensionPrinterHandler::StartGetPrinters(
weak_ptr_factory_.GetWeakPtr(), callback));
}
- extensions::PrinterProviderAPIFactory::GetInstance()
- ->GetForBrowserContext(profile_)
- ->DispatchGetPrintersRequested(
- base::Bind(&ExtensionPrinterHandler::WrapGetPrintersCallback,
- weak_ptr_factory_.GetWeakPtr(), callback));
+ GetPrinterProviderAPI(profile_)->DispatchGetPrintersRequested(
+ base::BindRepeating(&ExtensionPrinterHandler::WrapGetPrintersCallback,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
void ExtensionPrinterHandler::StartGetCapability(
const std::string& destination_id,
GetCapabilityCallback callback) {
- extensions::PrinterProviderAPIFactory::GetInstance()
- ->GetForBrowserContext(profile_)
- ->DispatchGetCapabilityRequested(
- destination_id,
- base::BindOnce(&ExtensionPrinterHandler::WrapGetCapabilityCallback,
- weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
+ GetPrinterProviderAPI(profile_)->DispatchGetCapabilityRequested(
+ destination_id,
+ base::BindOnce(&ExtensionPrinterHandler::WrapGetCapabilityCallback,
+ weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void ExtensionPrinterHandler::StartPrint(
@@ -198,12 +176,9 @@ void ExtensionPrinterHandler::StartPrint(
cloud_devices::printer::ContentTypesCapability content_types;
content_types.LoadFrom(printer_description);
- const bool kUsePdf = content_types.Contains(kContentTypePdf) ||
+ const bool use_pdf = content_types.Contains(kContentTypePdf) ||
content_types.Contains(kContentTypeAll);
-
- if (kUsePdf) {
- // TODO(tbarzic): Consider writing larger PDF to disk and provide the data
- // the same way as it's done with PWG raster.
+ if (use_pdf) {
print_job->content_type = kContentTypePdf;
print_job->document_bytes = print_data;
DispatchPrintJob(std::move(callback), std::move(print_job));
@@ -245,12 +220,10 @@ void ExtensionPrinterHandler::StartGrantPrinterAccess(
DevicePermissionsManager::Get(profile_);
permissions_manager->AllowUsbDevice(extension_id, device);
- extensions::PrinterProviderAPIFactory::GetInstance()
- ->GetForBrowserContext(profile_)
- ->DispatchGetUsbPrinterInfoRequested(
- extension_id, device,
- base::BindOnce(&ExtensionPrinterHandler::WrapGetPrinterInfoCallback,
- weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
+ GetPrinterProviderAPI(profile_)->DispatchGetUsbPrinterInfoRequested(
+ extension_id, device,
+ base::BindOnce(&ExtensionPrinterHandler::WrapGetPrinterInfoCallback,
+ weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void ExtensionPrinterHandler::SetPwgRasterConverterForTesting(
@@ -281,7 +254,7 @@ void ExtensionPrinterHandler::ConvertToPWGRaster(
void ExtensionPrinterHandler::DispatchPrintJob(
PrintCallback callback,
std::unique_ptr<extensions::PrinterProviderPrintJob> print_job) {
- if (print_job->document_path.empty() && !print_job->document_bytes) {
+ if (!print_job->document_bytes) {
WrapPrintCallback(std::move(callback), base::Value(kInvalidDataPrintError));
return;
}
@@ -373,7 +346,7 @@ void ExtensionPrinterHandler::OnUsbDevicesEnumerated(
device->product_string(), base::string16(), false))
.Set("extensionId", extension->id())
.Set("extensionName", extension->name())
- .SetBoolean("provisional", true)
+ .Set("provisional", true)
.Build());
}
}
diff --git a/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.h b/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.h
index ce7ab8f5ac4..6259a197bb1 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.h
+++ b/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.h
@@ -56,7 +56,6 @@ class ExtensionPrinterHandler : public PrinterHandler {
GetPrintersDoneCallback done_callback) override;
void StartGetCapability(const std::string& destination_id,
GetCapabilityCallback callback) override;
- // TODO(tbarzic): It might make sense to have the strings in a single struct.
void StartPrint(const std::string& destination_id,
const std::string& capability,
const base::string16& job_title,
diff --git a/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler_unittest.cc b/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler_unittest.cc
index 0ef9c338198..e1f1803d1f7 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler_unittest.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler_unittest.cc
@@ -13,8 +13,6 @@
#include "base/bind.h"
#include "base/containers/queue.h"
-#include "base/files/file_util.h"
-#include "base/files/scoped_temp_dir.h"
#include "base/json/json_string_value_serializer.h"
#include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
@@ -278,47 +276,38 @@ std::string RefCountedMemoryToString(
// Fake PwgRasterConverter used in the tests.
class FakePwgRasterConverter : public PwgRasterConverter {
public:
- FakePwgRasterConverter() : fail_conversion_(false), initialized_(false) {}
+ FakePwgRasterConverter() {}
~FakePwgRasterConverter() override = default;
- // PwgRasterConverter implementation. It writes |data| to a temp file.
+ // PwgRasterConverter implementation. It writes |data| to shared memory.
// Also, remembers conversion and bitmap settings passed into the method.
- void Start(base::RefCountedMemory* data,
+ void Start(const base::RefCountedMemory* data,
const printing::PdfRenderSettings& conversion_settings,
const printing::PwgRasterSettings& bitmap_settings,
ResultCallback callback) override {
+ base::ReadOnlySharedMemoryRegion invalid_pwg_region;
if (fail_conversion_) {
- std::move(callback).Run(false, base::FilePath());
+ std::move(callback).Run(std::move(invalid_pwg_region));
return;
}
- if (!initialized_ && !temp_dir_.CreateUniqueTempDir()) {
- ADD_FAILURE() << "Unable to create target dir for cenverter";
- std::move(callback).Run(false, base::FilePath());
- return;
- }
-
- initialized_ = true;
-
- path_ = temp_dir_.GetPath().AppendASCII("output.pwg");
- std::string data_str(data->front_as<char>(), data->size());
- int written = WriteFile(path_, data_str.c_str(), data_str.size());
- if (written != static_cast<int>(data_str.size())) {
- ADD_FAILURE() << "Failed to write pwg raster file.";
- std::move(callback).Run(false, base::FilePath());
+ base::MappedReadOnlyRegion memory =
+ base::ReadOnlySharedMemoryRegion::Create(data->size());
+ if (!memory.IsValid()) {
+ ADD_FAILURE() << "Failed to create pwg raster shared memory.";
+ std::move(callback).Run(std::move(invalid_pwg_region));
return;
}
+ memcpy(memory.mapping.memory(), data->front(), data->size());
conversion_settings_ = conversion_settings;
bitmap_settings_ = bitmap_settings;
-
- std::move(callback).Run(true, path_);
+ std::move(callback).Run(std::move(memory.region));
}
// Makes |Start| method always return an error.
void FailConversion() { fail_conversion_ = true; }
- const base::FilePath& path() { return path_; }
const printing::PdfRenderSettings& conversion_settings() const {
return conversion_settings_;
}
@@ -328,13 +317,9 @@ class FakePwgRasterConverter : public PwgRasterConverter {
}
private:
- base::ScopedTempDir temp_dir_;
-
- base::FilePath path_;
printing::PdfRenderSettings conversion_settings_;
printing::PwgRasterSettings bitmap_settings_;
- bool fail_conversion_;
- bool initialized_;
+ bool fail_conversion_ = false;
DISALLOW_COPY_AND_ASSIGN(FakePwgRasterConverter);
};
@@ -595,7 +580,7 @@ TEST_F(ExtensionPrinterHandlerTest, GetUsbPrinters) {
.Set("name", "USB Printer")
.Set("extensionName", "Provider 1")
.Set("extensionId", extension_1->id())
- .SetBoolean("provisional", true)
+ .Set("provisional", true)
.Build());
std::unique_ptr<base::DictionaryValue> extension_2_entry(
DictionaryBuilder()
@@ -605,7 +590,7 @@ TEST_F(ExtensionPrinterHandlerTest, GetUsbPrinters) {
.Set("name", "USB Printer")
.Set("extensionName", "Provider 2")
.Set("extensionId", extension_2->id())
- .SetBoolean("provisional", true)
+ .Set("provisional", true)
.Build());
EXPECT_TRUE(printers->Find(*extension_1_entry) != printers->end());
EXPECT_TRUE(printers->Find(*extension_2_entry) != printers->end());
@@ -696,7 +681,6 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pdf) {
EXPECT_EQ(title, print_job->job_title);
EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json);
EXPECT_EQ(kContentTypePDF, print_job->content_type);
- EXPECT_TRUE(print_job->document_path.empty());
ASSERT_TRUE(print_job->document_bytes);
EXPECT_EQ(RefCountedMemoryToString(print_data),
RefCountedMemoryToString(print_job->document_bytes));
@@ -761,7 +745,6 @@ TEST_F(ExtensionPrinterHandlerTest, Print_All) {
EXPECT_EQ(title, print_job->job_title);
EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json);
EXPECT_EQ(kContentTypePDF, print_job->content_type);
- EXPECT_TRUE(print_job->document_path.empty());
ASSERT_TRUE(print_job->document_bytes);
EXPECT_EQ(RefCountedMemoryToString(print_data),
RefCountedMemoryToString(print_job->document_bytes));
@@ -816,11 +799,9 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg) {
EXPECT_EQ(title, print_job->job_title);
EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json);
EXPECT_EQ(kContentTypePWG, print_job->content_type);
- EXPECT_FALSE(print_job->document_bytes);
- EXPECT_FALSE(print_job->document_path.empty());
- EXPECT_EQ(pwg_raster_converter_->path(), print_job->document_path);
- EXPECT_EQ(static_cast<int64_t>(print_data->size()),
- print_job->file_info.size);
+ ASSERT_TRUE(print_job->document_bytes);
+ EXPECT_EQ(RefCountedMemoryToString(print_data),
+ RefCountedMemoryToString(print_job->document_bytes));
fake_api->TriggerNextPrintCallback(kPrintRequestSuccess);
@@ -872,11 +853,9 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_NonDefaultSettings) {
EXPECT_EQ(title, print_job->job_title);
EXPECT_EQ(kPrintTicketWithDuplex, print_job->ticket_json);
EXPECT_EQ(kContentTypePWG, print_job->content_type);
- EXPECT_FALSE(print_job->document_bytes);
- EXPECT_FALSE(print_job->document_path.empty());
- EXPECT_EQ(pwg_raster_converter_->path(), print_job->document_path);
- EXPECT_EQ(static_cast<int64_t>(print_data->size()),
- print_job->file_info.size);
+ ASSERT_TRUE(print_job->document_bytes);
+ EXPECT_EQ(RefCountedMemoryToString(print_data),
+ RefCountedMemoryToString(print_job->document_bytes));
fake_api->TriggerNextPrintCallback(kPrintRequestSuccess);
diff --git a/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.cc b/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.cc
index da909f11bbb..5b128dc114d 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/chromeos/printing/cups_print_job_manager.h"
#include "chrome/browser/chromeos/printing/cups_print_job_manager_factory.h"
#include "chrome/browser/chromeos/printing/cups_printers_manager.h"
+#include "chrome/browser/chromeos/printing/cups_printers_manager_factory.h"
#include "chrome/browser/chromeos/printing/ppd_provider_factory.h"
#include "chrome/browser/chromeos/printing/printer_configurer.h"
#include "chrome/browser/profiles/profile.h"
@@ -31,6 +32,7 @@
namespace {
using chromeos::CupsPrintersManager;
+using chromeos::CupsPrintersManagerFactory;
// Store the name used in CUPS, Printer#id in |printer_name|, the description
// as the system_driverinfo option value, and the Printer#display_name in
@@ -76,7 +78,9 @@ LocalPrinterHandlerChromeos::LocalPrinterHandlerChromeos(
Profile* profile,
content::WebContents* preview_web_contents)
: preview_web_contents_(preview_web_contents),
- printers_manager_(CupsPrintersManager::Create(profile)),
+ printers_manager_(
+ CupsPrintersManagerFactory::GetInstance()->GetForBrowserContext(
+ profile)),
printer_configurer_(chromeos::PrinterConfigurer::Create(profile)),
weak_factory_(this) {
// Construct the CupsPrintJobManager to listen for printing events.
@@ -181,9 +185,12 @@ void LocalPrinterHandlerChromeos::HandlePrinterSetup(
break;
case chromeos::PrinterSetupResult::kPrinterUnreachable:
case chromeos::PrinterSetupResult::kDbusError:
+ case chromeos::PrinterSetupResult::kComponentUnavailable:
case chromeos::PrinterSetupResult::kPpdTooLarge:
case chromeos::PrinterSetupResult::kInvalidPpd:
case chromeos::PrinterSetupResult::kFatalError:
+ case chromeos::PrinterSetupResult::kNativePrintersNotAllowed:
+ case chromeos::PrinterSetupResult::kInvalidPrinterUpdate:
LOG(ERROR) << "Unexpected error in printer setup." << result;
break;
case chromeos::PrinterSetupResult::kMaxValue:
diff --git a/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.h b/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.h
index a96aa70ee77..a846e6ffefd 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.h
+++ b/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.h
@@ -50,7 +50,7 @@ class LocalPrinterHandlerChromeos : public PrinterHandler {
chromeos::PrinterSetupResult result);
content::WebContents* const preview_web_contents_;
- std::unique_ptr<chromeos::CupsPrintersManager> printers_manager_;
+ chromeos::CupsPrintersManager* printers_manager_;
scoped_refptr<chromeos::PpdProvider> ppd_provider_;
std::unique_ptr<chromeos::PrinterConfigurer> printer_configurer_;
base::WeakPtrFactory<LocalPrinterHandlerChromeos> weak_factory_;
diff --git a/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
index 4a5410e4a56..07e885d8b19 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
@@ -107,6 +107,7 @@ enum UserActionBuckets {
PRINT_WITH_CLOUD_PRINT,
PRINT_WITH_PRIVET,
PRINT_WITH_EXTENSION,
+ OPEN_IN_MAC_PREVIEW,
USERACTION_BUCKET_BOUNDARY
};
@@ -133,6 +134,7 @@ enum PrintSettingsBuckets {
DISTILL_PAGE_UNUSED,
SCALING,
PRINT_AS_IMAGE,
+ PAGES_PER_SHEET,
PRINT_SETTINGS_BUCKET_BOUNDARY
};
@@ -144,19 +146,89 @@ enum PrintDocumentTypeBuckets {
PRINT_DOCUMENT_TYPE_BUCKET_BOUNDARY
};
-void ReportUserActionHistogram(enum UserActionBuckets event) {
+void ReportUserActionHistogram(UserActionBuckets event) {
UMA_HISTOGRAM_ENUMERATION("PrintPreview.UserAction", event,
USERACTION_BUCKET_BOUNDARY);
}
-void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) {
+void ReportPrintSettingHistogram(PrintSettingsBuckets setting) {
UMA_HISTOGRAM_ENUMERATION("PrintPreview.PrintSettings", setting,
PRINT_SETTINGS_BUCKET_BOUNDARY);
}
-void ReportPrintDocumentTypeHistogram(enum PrintDocumentTypeBuckets doctype) {
+void ReportPrintDocumentTypeAndSizeHistograms(PrintDocumentTypeBuckets doctype,
+ size_t average_page_size_in_kb) {
UMA_HISTOGRAM_ENUMERATION("PrintPreview.PrintDocumentType", doctype,
PRINT_DOCUMENT_TYPE_BUCKET_BOUNDARY);
+ switch (doctype) {
+ case HTML_DOCUMENT:
+ UMA_HISTOGRAM_MEMORY_KB("PrintPreview.PrintDocumentSize.HTML",
+ average_page_size_in_kb);
+ break;
+ case PDF_DOCUMENT:
+ UMA_HISTOGRAM_MEMORY_KB("PrintPreview.PrintDocumentSize.PDF",
+ average_page_size_in_kb);
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
+bool ReportPageCountHistogram(UserActionBuckets user_action, int page_count) {
+ switch (user_action) {
+ case PRINT_TO_PRINTER:
+ UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count);
+ return true;
+ case PRINT_TO_PDF:
+ UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count);
+ return true;
+ case FALLBACK_TO_ADVANCED_SETTINGS_DIALOG:
+ UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", page_count);
+ return true;
+ case PRINT_WITH_CLOUD_PRINT:
+ UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint",
+ page_count);
+ return true;
+ case PRINT_WITH_PRIVET:
+ UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet",
+ page_count);
+ return true;
+ case PRINT_WITH_EXTENSION:
+ UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithExtension",
+ page_count);
+ return true;
+ case OPEN_IN_MAC_PREVIEW:
+ UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.OpenInMacPreview",
+ page_count);
+ return true;
+ default:
+ return false;
+ }
+}
+
+PrinterType GetPrinterTypeForUserAction(UserActionBuckets user_action) {
+ switch (user_action) {
+ case PRINT_WITH_PRIVET:
+ return PrinterType::kPrivetPrinter;
+ case PRINT_WITH_EXTENSION:
+ return PrinterType::kExtensionPrinter;
+ case PRINT_TO_PDF:
+ return PrinterType::kPdfPrinter;
+ case PRINT_TO_PRINTER:
+ case FALLBACK_TO_ADVANCED_SETTINGS_DIALOG:
+ case OPEN_IN_MAC_PREVIEW:
+ return PrinterType::kLocalPrinter;
+ default:
+ NOTREACHED();
+ return PrinterType::kLocalPrinter;
+ }
+}
+
+base::Value GetErrorValue(UserActionBuckets user_action,
+ base::StringPiece description) {
+ return user_action == PRINT_WITH_PRIVET ? base::Value(-1)
+ : base::Value(description);
}
// Dictionary Fields for Print Preview initial settings. Keep in sync with
@@ -248,6 +320,13 @@ void ReportPrintSettingsStats(const base::DictionaryValue& settings) {
ReportPrintSettingHistogram(SCALING);
}
+ int num_pages_per_sheet = 1;
+ if (settings.GetInteger(printing::kSettingPagesPerSheet,
+ &num_pages_per_sheet) &&
+ num_pages_per_sheet != 1) {
+ ReportPrintSettingHistogram(PAGES_PER_SHEET);
+ }
+
bool collate = false;
if (settings.GetBoolean(printing::kSettingCollate, &collate) && collate)
ReportPrintSettingHistogram(COLLATE);
@@ -299,6 +378,30 @@ void ReportPrintSettingsStats(const base::DictionaryValue& settings) {
}
}
+UserActionBuckets DetermineUserAction(const base::DictionaryValue& settings) {
+ bool value = false;
+#if defined(OS_MACOSX)
+ value = settings.HasKey(printing::kSettingOpenPDFInPreview);
+#endif
+ if (value)
+ return OPEN_IN_MAC_PREVIEW;
+ if (settings.HasKey(printing::kSettingCloudPrintId))
+ return PRINT_WITH_CLOUD_PRINT;
+ settings.GetBoolean(printing::kSettingPrintWithPrivet, &value);
+ if (value)
+ return PRINT_WITH_PRIVET;
+ settings.GetBoolean(printing::kSettingPrintWithExtension, &value);
+ if (value)
+ return PRINT_WITH_EXTENSION;
+ settings.GetBoolean(printing::kSettingPrintToPDF, &value);
+ if (value)
+ return PRINT_TO_PDF;
+ settings.GetBoolean(printing::kSettingShowSystemDialog, &value);
+ if (value)
+ return FALLBACK_TO_ADVANCED_SETTINGS_DIALOG;
+ return PRINT_TO_PRINTER;
+}
+
base::LazyInstance<printing::StickySettings>::DestructorAtExit
g_sticky_settings = LAZY_INSTANCE_INITIALIZER;
@@ -561,7 +664,7 @@ void PrintPreviewHandler::HandleGetPrinterCapabilities(
}
void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) {
- DCHECK_EQ(3U, args->GetSize());
+ DCHECK_EQ(2U, args->GetSize());
std::string callback_id;
std::string json_str;
@@ -617,29 +720,6 @@ void PrintPreviewHandler::HandleGetPreview(const base::ListValue* args) {
initiator_url.ReplaceComponents(url_sanitizer).spec());
}
- bool generate_draft_data = false;
- success = settings->GetBoolean(printing::kSettingGenerateDraftData,
- &generate_draft_data);
- DCHECK(success);
-
- if (!generate_draft_data) {
- int page_count = -1;
- success = args->GetInteger(2, &page_count);
- DCHECK(success);
-
- if (page_count != -1) {
- bool preview_modifiable = false;
- success = settings->GetBoolean(printing::kSettingPreviewModifiable,
- &preview_modifiable);
- DCHECK(success);
-
- if (preview_modifiable &&
- print_preview_ui()->GetAvailableDraftPageCount() != page_count) {
- settings->SetBoolean(printing::kSettingGenerateDraftData, true);
- }
- }
- }
-
VLOG(1) << "Print preview request start";
rfh->Send(new PrintMsg_PrintPreview(rfh->GetRoutingID(), *settings));
@@ -663,109 +743,71 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
return;
}
- ReportPrintSettingsStats(*settings);
-
- // Report whether the user printed a PDF or an HTML document.
- ReportPrintDocumentTypeHistogram(print_preview_ui()->source_is_modifiable() ?
- HTML_DOCUMENT : PDF_DOCUMENT);
-
- bool print_to_pdf = false;
- bool is_cloud_printer = false;
- bool print_with_privet = false;
- bool print_with_extension = false;
- bool show_system_dialog = false;
- bool open_pdf_in_preview = false;
-#if defined(OS_MACOSX)
- open_pdf_in_preview = settings->HasKey(printing::kSettingOpenPDFInPreview);
-#endif
-
- if (!open_pdf_in_preview) {
- settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
- settings->GetBoolean(printing::kSettingPrintWithPrivet, &print_with_privet);
- settings->GetBoolean(printing::kSettingPrintWithExtension,
- &print_with_extension);
- settings->GetBoolean(printing::kSettingShowSystemDialog,
- &show_system_dialog);
- is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId);
- }
+ const UserActionBuckets user_action = DetermineUserAction(*settings);
int page_count = 0;
if (!settings->GetInteger(printing::kSettingPreviewPageCount, &page_count) ||
page_count <= 0) {
- RejectJavascriptCallback(base::Value(callback_id), base::Value(-1));
+ RejectJavascriptCallback(base::Value(callback_id),
+ GetErrorValue(user_action, "NO_PAGE_COUNT"));
return;
}
- if (print_with_privet) {
-#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet", page_count);
- ReportUserActionHistogram(PRINT_WITH_PRIVET);
-#endif
- } else if (print_with_extension) {
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithExtension",
- page_count);
- ReportUserActionHistogram(PRINT_WITH_EXTENSION);
- } else if (print_to_pdf) {
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count);
- ReportUserActionHistogram(PRINT_TO_PDF);
- } else if (show_system_dialog) {
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", page_count);
- ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG);
- } else if (!open_pdf_in_preview) {
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count);
- ReportUserActionHistogram(PRINT_TO_PRINTER);
- } else if (is_cloud_printer) {
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint",
- page_count);
- ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT);
- }
-
scoped_refptr<base::RefCountedMemory> data;
print_preview_ui()->GetPrintPreviewDataForIndex(
printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
if (!data) {
// Nothing to print, no preview available.
- RejectJavascriptCallback(
- base::Value(callback_id),
- print_with_privet ? base::Value(-1) : base::Value("NO_DATA"));
+ RejectJavascriptCallback(base::Value(callback_id),
+ GetErrorValue(user_action, "NO_DATA"));
return;
}
DCHECK(data->size());
DCHECK(data->front());
- if (is_cloud_printer) {
- // Does not send the title like the other printer handler types below,
- // because JS already has the document title from the initial settings.
- SendCloudPrintJob(callback_id, data.get());
- return;
- }
-
std::string destination_id;
std::string print_ticket;
std::string capabilities;
int width = 0;
int height = 0;
- if ((print_with_privet || print_with_extension) &&
- (!settings->GetString(printing::kSettingDeviceName, &destination_id) ||
- !settings->GetString(printing::kSettingTicket, &print_ticket) ||
- !settings->GetString(printing::kSettingCapabilities, &capabilities) ||
- !settings->GetInteger(printing::kSettingPageWidth, &width) ||
- !settings->GetInteger(printing::kSettingPageHeight, &height) ||
- width <= 0 || height <= 0)) {
+ if (user_action == PRINT_WITH_PRIVET || user_action == PRINT_WITH_EXTENSION) {
+ if (!settings->GetString(printing::kSettingDeviceName, &destination_id) ||
+ !settings->GetString(printing::kSettingTicket, &print_ticket) ||
+ !settings->GetString(printing::kSettingCapabilities, &capabilities) ||
+ !settings->GetInteger(printing::kSettingPageWidth, &width) ||
+ !settings->GetInteger(printing::kSettingPageHeight, &height) ||
+ width <= 0 || height <= 0) {
+ NOTREACHED();
+ RejectJavascriptCallback(base::Value(callback_id),
+ GetErrorValue(user_action, "FAILED"));
+ return;
+ }
+ }
+
+ // After validating |settings|, record metrics.
+ ReportPrintSettingsStats(*settings);
+ {
+ PrintDocumentTypeBuckets doc_type =
+ print_preview_ui()->source_is_modifiable() ? HTML_DOCUMENT
+ : PDF_DOCUMENT;
+ size_t average_page_size_in_kb = data->size() / page_count;
+ average_page_size_in_kb /= 1024;
+ ReportPrintDocumentTypeAndSizeHistograms(doc_type, average_page_size_in_kb);
+ }
+ ReportUserActionHistogram(user_action);
+ if (!ReportPageCountHistogram(user_action, page_count)) {
NOTREACHED();
- RejectJavascriptCallback(
- base::Value(callback_id),
- print_with_privet ? base::Value(-1) : base::Value("FAILED"));
return;
}
- PrinterType type = PrinterType::kLocalPrinter;
- if (print_with_extension)
- type = PrinterType::kExtensionPrinter;
- else if (print_with_privet)
- type = PrinterType::kPrivetPrinter;
- else if (print_to_pdf)
- type = PrinterType::kPdfPrinter;
+ if (user_action == PRINT_WITH_CLOUD_PRINT) {
+ // Does not send the title like the other printer handler types below,
+ // because JS already has the document title from the initial settings.
+ SendCloudPrintJob(callback_id, data.get());
+ return;
+ }
+
+ PrinterType type = GetPrinterTypeForUserAction(user_action);
PrinterHandler* handler = GetPrinterHandler(type);
handler->StartPrint(
destination_id, capabilities, print_preview_ui()->initiator_title(),
diff --git a/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc b/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc
index 785b773740c..281cbfbf549 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc
@@ -90,7 +90,6 @@ base::Value GetPrintPreviewTicket(bool is_pdf) {
print_ticket.SetKey(kIsFirstRequest, base::Value(true));
print_ticket.SetKey(kPreviewRequestID, base::Value(0));
print_ticket.SetKey(kSettingPreviewModifiable, base::Value(is_pdf));
- print_ticket.SetKey(kSettingGenerateDraftData, base::Value(true));
print_ticket.RemoveKey(kSettingPageWidth);
print_ticket.RemoveKey(kSettingPageHeight);
print_ticket.RemoveKey(kSettingShowSystemDialog);
@@ -106,7 +105,6 @@ std::unique_ptr<base::ListValue> ConstructPreviewArgs(
std::string json;
base::JSONWriter::Write(print_ticket, &json);
args.GetList().emplace_back(json);
- args.GetList().emplace_back(-1);
return base::ListValue::From(base::Value::ToUniquePtrValue(std::move(args)));
}
@@ -188,8 +186,6 @@ class FakePrintPreviewUI : public PrintPreviewUI {
sizeof(kTestData) - 1);
}
- int GetAvailableDraftPageCount() const override { return 1; }
-
void OnPrintPreviewRequest(int request_id) override {}
void OnCancelPendingPreviewRequest() override {}
void OnHidePreviewDialog() override {}
@@ -248,11 +244,11 @@ class PrintPreviewHandlerTest : public testing::Test {
PrintPreviewHandlerTest() {
TestingProfile::Builder builder;
profile_ = builder.Build();
- initiator_web_contents_.reset(content::WebContents::Create(
- content::WebContents::CreateParams(profile_.get())));
+ initiator_web_contents_ = content::WebContents::Create(
+ content::WebContents::CreateParams(profile_.get()));
content::WebContents* initiator = initiator_web_contents_.get();
- preview_web_contents_.reset(content::WebContents::Create(
- content::WebContents::CreateParams(profile_.get())));
+ preview_web_contents_ = content::WebContents::Create(
+ content::WebContents::CreateParams(profile_.get()));
printing::PrintViewManager::CreateForWebContents(initiator);
printing::PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(
initiator->GetMainFrame(), false);
diff --git a/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.cc b/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.cc
index c2deb06ddf2..9be9474eb72 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.cc
@@ -192,6 +192,9 @@ void AddPrintPreviewStrings(content::WebUIDataSource* source) {
IDS_PRINT_PREVIEW_DESTINATION_LABEL);
source->AddLocalizedString("copiesLabel", IDS_PRINT_PREVIEW_COPIES_LABEL);
source->AddLocalizedString("scalingLabel", IDS_PRINT_PREVIEW_SCALING_LABEL);
+ source->AddLocalizedString("pagesPerSheetLabel",
+ IDS_PRINT_PREVIEW_PAGES_PER_SHEET_LABEL);
+
source->AddLocalizedString("examplePageRangeText",
IDS_PRINT_PREVIEW_EXAMPLE_PAGE_RANGE_TEXT);
source->AddLocalizedString("layoutLabel", IDS_PRINT_PREVIEW_LAYOUT_LABEL);
@@ -395,14 +398,6 @@ void AddPrintPreviewImages(content::WebUIDataSource* source) {
}
void AddPrintPreviewFlags(content::WebUIDataSource* source, Profile* profile) {
-#if !defined(OS_MACOSX) && !defined(OS_WIN)
- bool print_pdf_as_image_enabled = base::FeatureList::IsEnabled(
- features::kPrintPdfAsImage);
- source->AddBoolean("printPdfAsImageEnabled", print_pdf_as_image_enabled);
-#else
- source->AddBoolean("printPdfAsImageEnabled", false);
-#endif
-
#if defined(OS_CHROMEOS)
source->AddBoolean("useSystemDefaultPrinter", false);
#else
@@ -420,6 +415,10 @@ void AddPrintPreviewFlags(content::WebUIDataSource* source, Profile* profile) {
enterprise_managed = base::win::IsEnterpriseManaged();
#endif
source->AddBoolean("isEnterpriseManaged", enterprise_managed);
+
+ bool nup_printing_enabled =
+ base::FeatureList::IsEnabled(features::kNupPrinting);
+ source->AddBoolean("pagesPerSheetEnabled", nup_printing_enabled);
}
void SetupPrintPreviewPlugin(content::WebUIDataSource* source) {
@@ -621,11 +620,6 @@ void PrintPreviewUI::ClearAllPreviewData() {
PrintPreviewDataService::GetInstance()->RemoveEntry(id_);
}
-int PrintPreviewUI::GetAvailableDraftPageCount() const {
- return PrintPreviewDataService::GetInstance()->GetAvailableDraftPageCount(
- id_);
-}
-
void PrintPreviewUI::SetInitiatorTitle(
const base::string16& job_title) {
initiator_title_ = job_title;
@@ -786,7 +780,7 @@ void PrintPreviewUI::OnHidePreviewDialog() {
delegate->ReleaseWebContents();
DCHECK_EQ(preview_dialog, preview_contents.get());
background_printing_manager->OwnPrintPreviewDialog(
- preview_contents.release());
+ std::move(preview_contents));
OnClosePrintPreviewDialog();
}
diff --git a/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.h b/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.h
index db9a4933bf5..87d879753fe 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.h
+++ b/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.h
@@ -58,9 +58,6 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
// Clear the existing print preview data.
void ClearAllPreviewData();
- // Returns the available draft page count.
- virtual int GetAvailableDraftPageCount() const;
-
// Setters
void SetInitiatorTitle(const base::string16& initiator_title);
diff --git a/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc b/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc
index 8d8187548ad..bff768e8b7b 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/print_preview_ui_browsertest.cc
@@ -57,7 +57,7 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewBrowserTest, PrintCommands) {
ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_PRINT));
-#if BUILDFLAG(ENABLE_BASIC_PRINTING) && !defined(OS_CHROMEOS)
+#if BUILDFLAG(ENABLE_PRINTING) && !defined(OS_CHROMEOS)
// This is analagous to ENABLE_BASIC_PRINT_DIALOG but helps to verify
// that it is defined as expected.
bool is_basic_print_expected = true;
diff --git a/chromium/chrome/browser/ui/webui/print_preview/printer_handler.h b/chromium/chrome/browser/ui/webui/print_preview/printer_handler.h
index ec72a5998e3..66f5f29df0c 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/printer_handler.h
+++ b/chromium/chrome/browser/ui/webui/print_preview/printer_handler.h
@@ -120,7 +120,6 @@ class PrinterHandler {
// |page_size|: The document page size.
// |print_data|: The document bytes to print.
// |callback| should be called in the response to the request.
- // TODO(tbarzic): Page size should be extracted from print data.
virtual void StartPrint(
const std::string& destination_id,
const std::string& capability,