summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/ui/webui/print_preview
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-01-31 16:33:43 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-02-06 16:33:22 +0000
commitda51f56cc21233c2d30f0fe0d171727c3102b2e0 (patch)
tree4e579ab70ce4b19bee7984237f3ce05a96d59d83 /chromium/chrome/browser/ui/webui/print_preview
parentc8c2d1901aec01e934adf561a9fdf0cc776cdef8 (diff)
downloadqtwebengine-chromium-da51f56cc21233c2d30f0fe0d171727c3102b2e0.tar.gz
BASELINE: Update Chromium to 65.0.3525.40
Also imports missing submodules Change-Id: I36901b7c6a325cda3d2c10cedb2186c25af3b79b Reviewed-by: Alexandru Croitor <alexandru.croitor@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.cc14
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler.h8
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/extension_printer_handler_unittest.cc27
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.cc30
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_chromeos.h10
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.cc7
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.h11
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc2
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_unittest.cc38
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_win_unittest.cc5
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.cc185
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.h6
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_handler_unittest.cc17
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/print_preview_ui.cc53
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.cc56
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.h11
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/printer_capabilities_unittest.cc3
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/printer_handler.cc12
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/printer_handler.h1
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/privet_printer_handler.cc6
-rw-r--r--chromium/chrome/browser/ui/webui/print_preview/sticky_settings.cc5
21 files changed, 299 insertions, 208 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 e99d344330f..12529779ca8 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
@@ -45,7 +45,7 @@ using extensions::Extension;
using extensions::ExtensionRegistry;
using extensions::ListBuilder;
using extensions::UsbPrinterManifestData;
-using printing::PWGRasterConverter;
+using printing::PwgRasterConverter;
namespace {
@@ -187,7 +187,7 @@ void ExtensionPrinterHandler::StartPrint(
const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data,
PrintCallback callback) {
- auto print_job = base::MakeUnique<extensions::PrinterProviderPrintJob>();
+ auto print_job = std::make_unique<extensions::PrinterProviderPrintJob>();
print_job->printer_id = destination_id;
print_job->job_title = job_title;
print_job->ticket_json = ticket_json;
@@ -253,8 +253,8 @@ void ExtensionPrinterHandler::StartGrantPrinterAccess(
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
-void ExtensionPrinterHandler::SetPWGRasterConverterForTesting(
- std::unique_ptr<PWGRasterConverter> pwg_raster_converter) {
+void ExtensionPrinterHandler::SetPwgRasterConverterForTesting(
+ std::unique_ptr<PwgRasterConverter> pwg_raster_converter) {
pwg_raster_converter_ = std::move(pwg_raster_converter);
}
@@ -266,12 +266,12 @@ void ExtensionPrinterHandler::ConvertToPWGRaster(
std::unique_ptr<extensions::PrinterProviderPrintJob> job,
PrintJobCallback callback) {
if (!pwg_raster_converter_) {
- pwg_raster_converter_ = PWGRasterConverter::CreateDefault();
+ pwg_raster_converter_ = PwgRasterConverter::CreateDefault();
}
pwg_raster_converter_->Start(
data.get(),
- PWGRasterConverter::GetConversionSettings(printer_description, page_size),
- PWGRasterConverter::GetBitmapSettings(printer_description, ticket),
+ PwgRasterConverter::GetConversionSettings(printer_description, page_size),
+ PwgRasterConverter::GetBitmapSettings(printer_description, ticket),
base::BindOnce(&UpdateJobFileInfo, std::move(job), std::move(callback)));
}
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 7ec540ce1e2..005ad93b637 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
@@ -37,7 +37,7 @@ class Size;
}
namespace printing {
-class PWGRasterConverter;
+class PwgRasterConverter;
}
// Implementation of PrinterHandler interface backed by printerProvider
@@ -71,8 +71,8 @@ class ExtensionPrinterHandler : public PrinterHandler {
private:
friend class ExtensionPrinterHandlerTest;
- void SetPWGRasterConverterForTesting(
- std::unique_ptr<printing::PWGRasterConverter> pwg_raster_converter);
+ void SetPwgRasterConverterForTesting(
+ std::unique_ptr<printing::PwgRasterConverter> pwg_raster_converter);
// Converts |data| to PWG raster format (from PDF) for a printer described
// by |printer_description|.
@@ -109,7 +109,7 @@ class ExtensionPrinterHandler : public PrinterHandler {
Profile* const profile_;
GetPrintersDoneCallback done_callback_;
PrintJobCallback print_job_callback_;
- std::unique_ptr<printing::PWGRasterConverter> pwg_raster_converter_;
+ std::unique_ptr<printing::PwgRasterConverter> pwg_raster_converter_;
int pending_enumeration_count_ = 0;
base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_;
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 771236a7633..fb98de43578 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
@@ -17,7 +17,6 @@
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_string_value_serializer.h"
#include "base/macros.h"
-#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
#include "base/strings/string16.h"
@@ -53,7 +52,7 @@ using extensions::Extension;
using extensions::PrinterProviderAPI;
using extensions::PrinterProviderPrintJob;
using extensions::TestExtensionEnvironment;
-using printing::PWGRasterConverter;
+using printing::PwgRasterConverter;
namespace {
@@ -276,13 +275,13 @@ std::string RefCountedMemoryToString(
return std::string(memory->front_as<char>(), memory->size());
}
-// Fake PWGRasterConverter used in the tests.
-class FakePWGRasterConverter : public PWGRasterConverter {
+// Fake PwgRasterConverter used in the tests.
+class FakePwgRasterConverter : public PwgRasterConverter {
public:
- FakePWGRasterConverter() : fail_conversion_(false), initialized_(false) {}
- ~FakePWGRasterConverter() override = default;
+ FakePwgRasterConverter() : fail_conversion_(false), initialized_(false) {}
+ ~FakePwgRasterConverter() override = default;
- // PWGRasterConverter implementation. It writes |data| to a temp file.
+ // PwgRasterConverter implementation. It writes |data| to a temp file.
// Also, remembers conversion and bitmap settings passed into the method.
void Start(base::RefCountedMemory* data,
const printing::PdfRenderSettings& conversion_settings,
@@ -337,7 +336,7 @@ class FakePWGRasterConverter : public PWGRasterConverter {
bool fail_conversion_;
bool initialized_;
- DISALLOW_COPY_AND_ASSIGN(FakePWGRasterConverter);
+ DISALLOW_COPY_AND_ASSIGN(FakePwgRasterConverter);
};
// Information about received print requests.
@@ -456,7 +455,7 @@ class FakePrinterProviderAPI : public PrinterProviderAPI {
std::unique_ptr<KeyedService> BuildTestingPrinterProviderAPI(
content::BrowserContext* context) {
- return base::MakeUnique<FakePrinterProviderAPI>();
+ return std::make_unique<FakePrinterProviderAPI>();
}
} // namespace
@@ -470,11 +469,11 @@ class ExtensionPrinterHandlerTest : public testing::Test {
extensions::PrinterProviderAPIFactory::GetInstance()->SetTestingFactory(
env_.profile(), &BuildTestingPrinterProviderAPI);
extension_printer_handler_ =
- base::MakeUnique<ExtensionPrinterHandler>(env_.profile());
+ std::make_unique<ExtensionPrinterHandler>(env_.profile());
- auto pwg_raster_converter = base::MakeUnique<FakePWGRasterConverter>();
+ auto pwg_raster_converter = std::make_unique<FakePwgRasterConverter>();
pwg_raster_converter_ = pwg_raster_converter.get();
- extension_printer_handler_->SetPWGRasterConverterForTesting(
+ extension_printer_handler_->SetPwgRasterConverterForTesting(
std::move(pwg_raster_converter));
}
@@ -494,7 +493,7 @@ class ExtensionPrinterHandlerTest : public testing::Test {
std::unique_ptr<ExtensionPrinterHandler> extension_printer_handler_;
// Owned by |extension_printer_handler_|.
- FakePWGRasterConverter* pwg_raster_converter_ = nullptr;
+ FakePwgRasterConverter* pwg_raster_converter_ = nullptr;
private:
DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandlerTest);
@@ -800,6 +799,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg) {
pwg_raster_converter_->bitmap_settings().odd_page_transform);
EXPECT_FALSE(pwg_raster_converter_->bitmap_settings().rotate_all_pages);
EXPECT_FALSE(pwg_raster_converter_->bitmap_settings().reverse_page_order);
+ EXPECT_TRUE(pwg_raster_converter_->bitmap_settings().use_color);
EXPECT_EQ(printing::kDefaultPdfDpi,
pwg_raster_converter_->conversion_settings().dpi);
@@ -853,6 +853,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_NonDefaultSettings) {
pwg_raster_converter_->bitmap_settings().odd_page_transform);
EXPECT_TRUE(pwg_raster_converter_->bitmap_settings().rotate_all_pages);
EXPECT_TRUE(pwg_raster_converter_->bitmap_settings().reverse_page_order);
+ EXPECT_TRUE(pwg_raster_converter_->bitmap_settings().use_color);
EXPECT_EQ(200, // max(vertical_dpi, horizontal_dpi)
pwg_raster_converter_->conversion_settings().dpi);
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 3be7d9a74bf..7615db3985a 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
@@ -71,8 +71,11 @@ void FetchCapabilities(std::unique_ptr<chromeos::Printer> printer,
} // namespace
-LocalPrinterHandlerChromeos::LocalPrinterHandlerChromeos(Profile* profile)
- : printers_manager_(CupsPrintersManager::Create(profile)),
+LocalPrinterHandlerChromeos::LocalPrinterHandlerChromeos(
+ Profile* profile,
+ content::WebContents* preview_web_contents)
+ : preview_web_contents_(preview_web_contents),
+ printers_manager_(CupsPrintersManager::Create(profile)),
printer_configurer_(chromeos::PrinterConfigurer::Create(profile)),
weak_factory_(this) {
printers_manager_->Start();
@@ -152,17 +155,6 @@ void LocalPrinterHandlerChromeos::StartGetCapability(
std::move(cb)));
}
-void LocalPrinterHandlerChromeos::StartPrint(
- const std::string& destination_id,
- const std::string& capability,
- const base::string16& job_title,
- const std::string& ticket_json,
- const gfx::Size& page_size,
- const scoped_refptr<base::RefCountedBytes>& print_data,
- PrintCallback callback) {
- NOTREACHED();
-}
-
void LocalPrinterHandlerChromeos::HandlePrinterSetup(
std::unique_ptr<chromeos::Printer> printer,
GetCapabilityCallback cb,
@@ -203,3 +195,15 @@ void LocalPrinterHandlerChromeos::HandlePrinterSetup(
// TODO(skau): Open printer settings if this is resolvable.
std::move(cb).Run(nullptr);
}
+
+void LocalPrinterHandlerChromeos::StartPrint(
+ const std::string& destination_id,
+ const std::string& capability,
+ const base::string16& job_title,
+ const std::string& ticket_json,
+ const gfx::Size& page_size,
+ const scoped_refptr<base::RefCountedBytes>& print_data,
+ PrintCallback callback) {
+ printing::StartLocalPrint(ticket_json, print_data, preview_web_contents_,
+ std::move(callback));
+}
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 263bd975ab3..b22c9bc58dd 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
@@ -17,11 +17,16 @@
#include "chrome/browser/ui/webui/print_preview/printer_handler.h"
#include "chromeos/printing/printer_configuration.h"
+namespace content {
+class WebContents;
+}
+
class Profile;
class LocalPrinterHandlerChromeos : public PrinterHandler {
public:
- explicit LocalPrinterHandlerChromeos(Profile* profile);
+ LocalPrinterHandlerChromeos(Profile* profile,
+ content::WebContents* preview_web_contents);
~LocalPrinterHandlerChromeos() override;
// PrinterHandler implementation
@@ -31,7 +36,6 @@ class LocalPrinterHandlerChromeos : public PrinterHandler {
GetPrintersDoneCallback done_callback) override;
void StartGetCapability(const std::string& printer_name,
GetCapabilityCallback cb) override;
- // Required by PrinterHandler interface but should never be called.
void StartPrint(const std::string& destination_id,
const std::string& capability,
const base::string16& job_title,
@@ -44,6 +48,8 @@ class LocalPrinterHandlerChromeos : public PrinterHandler {
void HandlePrinterSetup(std::unique_ptr<chromeos::Printer> printer,
GetCapabilityCallback cb,
chromeos::PrinterSetupResult result);
+
+ content::WebContents* const preview_web_contents_;
std::unique_ptr<chromeos::CupsPrintersManager> printers_manager_;
scoped_refptr<chromeos::PpdProvider> ppd_provider_;
std::unique_ptr<chromeos::PrinterConfigurer> printer_configurer_;
diff --git a/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.cc b/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.cc
index ae37e902528..5d3076d23dc 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.cc
@@ -61,7 +61,9 @@ std::string GetDefaultPrinterAsync() {
} // namespace
-LocalPrinterHandlerDefault::LocalPrinterHandlerDefault() {}
+LocalPrinterHandlerDefault::LocalPrinterHandlerDefault(
+ content::WebContents* preview_web_contents)
+ : preview_web_contents_(preview_web_contents) {}
LocalPrinterHandlerDefault::~LocalPrinterHandlerDefault() {}
@@ -106,5 +108,6 @@ void LocalPrinterHandlerDefault::StartPrint(
const gfx::Size& page_size,
const scoped_refptr<base::RefCountedBytes>& print_data,
PrintCallback callback) {
- NOTREACHED();
+ printing::StartLocalPrint(ticket_json, print_data, preview_web_contents_,
+ std::move(callback));
}
diff --git a/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.h b/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.h
index de224224a69..ab07dea98dc 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.h
+++ b/chromium/chrome/browser/ui/webui/print_preview/local_printer_handler_default.h
@@ -10,14 +10,18 @@
#include "base/callback_forward.h"
#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "chrome/browser/ui/webui/print_preview/printer_handler.h"
+namespace content {
+class WebContents;
+}
+
class LocalPrinterHandlerDefault : public PrinterHandler {
public:
- LocalPrinterHandlerDefault();
+ explicit LocalPrinterHandlerDefault(
+ content::WebContents* preview_web_contents);
~LocalPrinterHandlerDefault() override;
// PrinterHandler implementation.
@@ -27,7 +31,6 @@ class LocalPrinterHandlerDefault : public PrinterHandler {
GetPrintersDoneCallback done_callback) override;
void StartGetCapability(const std::string& destination_id,
GetCapabilityCallback callback) override;
- // Required by PrinterHandler interface but should never be called.
void StartPrint(const std::string& destination_id,
const std::string& capability,
const base::string16& job_title,
@@ -37,6 +40,8 @@ class LocalPrinterHandlerDefault : public PrinterHandler {
PrintCallback callback) override;
private:
+ content::WebContents* const preview_web_contents_;
+
DISALLOW_COPY_AND_ASSIGN(LocalPrinterHandlerDefault);
};
diff --git a/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc b/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
index 8133b34e262..4da653cb56b 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
@@ -166,7 +166,7 @@ void PdfPrinterHandler::StartGetPrinters(
void PdfPrinterHandler::StartGetCapability(const std::string& destination_id,
GetCapabilityCallback callback) {
- auto printer_info = base::MakeUnique<base::DictionaryValue>();
+ auto printer_info = std::make_unique<base::DictionaryValue>();
printer_info->SetString(printing::kSettingDeviceName, destination_id);
printer_info->Set(
printing::kSettingCapabilities,
diff --git a/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_unittest.cc b/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_unittest.cc
index ccd8f719454..4393bc38295 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_unittest.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_unittest.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/ui/webui/print_preview/pdf_printer_handler.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/url_formatter/url_formatter.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -64,3 +65,40 @@ TEST_F(PdfPrinterHandlerTest, GetFileNameForPrintJobURL) {
EXPECT_EQ(data.expected_output, path.value());
}
}
+
+TEST_F(PdfPrinterHandlerTest, GetFileName) {
+ static const struct {
+ const char* url;
+ const char* job_title;
+ bool is_savable;
+ const base::FilePath::CharType* expected_output;
+ } kTestData[] = {
+ {"http://example.com", "Example Website", true,
+ FPL("Example Website.pdf")},
+ {"http://example.com/foo.html", "Website", true, FPL("Website.pdf")},
+ {"http://example.com/foo.html", "Print Me.html", true,
+ FPL("Print Me.html.pdf")},
+ {"http://mail.google.com/mail/u/0/#inbox/hash",
+ "Baz.com Mail - This is email. What does it mean.", true,
+ FPL("Baz.com Mail - This is email. What does it mean_.pdf")},
+ {"data:text/html,foo", "data:text/html,foo", true, FPL("dataurl.pdf")},
+ {"data:text/html,<title>someone@example.com", "someone@example.com", true,
+ FPL("someone@example.com.pdf")},
+ {"file:///tmp/test.png", "test.png (420x150)", false, FPL("test.pdf")},
+ {"http://empty.com", "", true, FPL("empty.com.pdf")},
+ {"http://empty.com/image", "", false, FPL("image.pdf")},
+ {"http://empty.com/nomimetype", "", false, FPL("nomimetype.pdf")},
+ {"http://empty.com/weird.extension", "", false, FPL("weird.pdf")},
+ {"chrome-extension://foo/views/app.html", "demo.docx", true,
+ FPL("demo.docx.pdf")},
+ };
+
+ for (const auto& data : kTestData) {
+ SCOPED_TRACE(std::string(data.url) + " | " + data.job_title);
+ GURL url(data.url);
+ base::string16 job_title = base::ASCIIToUTF16(data.job_title);
+ base::FilePath path =
+ PdfPrinterHandler::GetFileName(url, job_title, data.is_savable);
+ EXPECT_EQ(data.expected_output, path.value());
+ }
+}
diff --git a/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_win_unittest.cc b/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_win_unittest.cc
index 07f3e9b793f..9246f32c1a3 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_win_unittest.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/pdf_printer_handler_win_unittest.cc
@@ -4,8 +4,9 @@
#include "chrome/browser/ui/webui/print_preview/pdf_printer_handler.h"
+#include <windows.h> // Must be in front of other Windows header files.
+
#include <commdlg.h>
-#include <windows.h>
#include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h"
@@ -127,7 +128,7 @@ class PdfPrinterHandlerWinTest : public BrowserWithTestWindowTest {
AddTab(browser(), GURL("chrome://print"));
// Create the PDF printer
- pdf_printer_ = base::MakeUnique<FakePdfPrinterHandler>(
+ pdf_printer_ = std::make_unique<FakePdfPrinterHandler>(
profile(), browser()->tab_strip_model()->GetWebContentsAt(0), nullptr);
}
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 d9d9cbdb91e..2913dbfdc78 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
@@ -20,7 +20,6 @@
#include "base/json/json_reader.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
-#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
#include "base/values.h"
@@ -28,6 +27,7 @@
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/bad_message.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/printing/background_printing_manager.h"
#include "chrome/browser/printing/print_dialog_cloud.h"
#include "chrome/browser/printing/print_error_dialog.h"
#include "chrome/browser/printing/print_job_manager.h"
@@ -661,7 +661,7 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
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);
@@ -672,26 +672,40 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
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);
}
int page_count = 0;
- settings->GetInteger(printing::kSettingPreviewPageCount, &page_count);
+ if (!settings->GetInteger(printing::kSettingPreviewPageCount, &page_count) ||
+ page_count <= 0) {
+ RejectJavascriptCallback(base::Value(callback_id), base::Value(-1));
+ return;
+ }
-#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
if (print_with_privet) {
+#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithPrivet", page_count);
ReportUserActionHistogram(PRINT_WITH_PRIVET);
- }
#endif
- if (print_with_extension) {
+ } else if (print_with_extension) {
UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintWithExtension",
page_count);
ReportUserActionHistogram(PRINT_WITH_EXTENSION);
- }
- if (print_to_pdf) {
+ } 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::RefCountedBytes> data;
@@ -707,112 +721,50 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
DCHECK(data->size());
DCHECK(data->front());
- if (print_with_privet || print_with_extension || print_to_pdf) {
- std::string destination_id;
- std::string print_ticket;
- std::string capabilities;
- int width = 0;
- int height = 0;
- if (!print_to_pdf &&
- (!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),
- print_with_privet ? base::Value(-1) : base::Value("FAILED"));
- return;
- }
-
- PrinterType type = PrinterType::kPdfPrinter;
- if (print_with_extension)
- type = PrinterType::kExtensionPrinter;
- else if (print_with_privet)
- type = PrinterType::kPrivetPrinter;
- PrinterHandler* handler = GetPrinterHandler(type);
- handler->StartPrint(
- destination_id, capabilities, print_preview_ui()->initiator_title(),
- print_ticket, gfx::Size(width, height), data,
- base::BindOnce(&PrintPreviewHandler::OnPrintResult,
- weak_factory_.GetWeakPtr(), callback_id));
- return;
- }
-
if (is_cloud_printer) {
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint",
- page_count);
- ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT);
- // Does not send the title like the printer handler types above, because JS
- // already has the document title from the initial settings.
+ // 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;
}
-#if BUILDFLAG(ENABLE_BASIC_PRINTING)
- bool system_dialog = false;
- settings->GetBoolean(printing::kSettingShowSystemDialog, &system_dialog);
- if (system_dialog) {
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", page_count);
- ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG);
- } else {
- UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count);
- ReportUserActionHistogram(PRINT_TO_PRINTER);
- }
-
- WebContents* initiator = GetInitiator();
- if (initiator) {
- // Save initiator IDs. PrintMsg_PrintForPrintPreview below should cause
- // the renderer to send PrintHostMsg_UpdatePrintSettings and trigger
- // PrintingMessageFilter::OnUpdatePrintSettings(), which needs this info.
- auto* main_render_frame = initiator->GetMainFrame();
- settings->SetInteger(printing::kPreviewInitiatorHostId,
- main_render_frame->GetProcess()->GetID());
- settings->SetInteger(printing::kPreviewInitiatorRoutingId,
- main_render_frame->GetRoutingID());
+ 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)) {
+ NOTREACHED();
+ RejectJavascriptCallback(
+ base::Value(callback_id),
+ print_with_privet ? base::Value(-1) : base::Value("FAILED"));
+ return;
}
- // Set ID to know whether printing is for preview.
- settings->SetInteger(printing::kPreviewUIID,
- print_preview_ui()->GetIDForPrintPreviewUI());
-
- // Save the settings and notify print preview. Print preview will respond
- // with a "hidePreviewDialog" message, and then the message can be sent to
- // the renderer in HandleHidePreview().
- settings_ = std::move(settings);
- ResolveJavascriptCallback(base::Value(callback_id), base::Value());
-
-#else
- NOTREACHED();
-#endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
+ 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;
+ PrinterHandler* handler = GetPrinterHandler(type);
+ handler->StartPrint(
+ destination_id, capabilities, print_preview_ui()->initiator_title(),
+ type == PrinterType::kLocalPrinter ? json_str : print_ticket,
+ gfx::Size(width, height), data,
+ base::BindOnce(&PrintPreviewHandler::OnPrintResult,
+ weak_factory_.GetWeakPtr(), callback_id));
}
void PrintPreviewHandler::HandleHidePreview(const base::ListValue* /*args*/) {
print_preview_ui()->OnHidePreviewDialog();
-#if BUILDFLAG(ENABLE_BASIC_PRINTING)
- if (settings_) {
- // Print preview is responding to a resolution of "print" promise. Send the
- // print message to the renderer.
- RenderFrameHost* rfh = preview_web_contents()->GetMainFrame();
- rfh->Send(
- new PrintMsg_PrintForPrintPreview(rfh->GetRoutingID(), *settings_));
- settings_.reset();
-
- // Clear the initiator so that it can open a new print preview dialog, while
- // the current print preview dialog is still handling its print job.
- WebContents* initiator = GetInitiator();
- ClearInitiatorDetails();
-
- // Since the preview dialog is hidden and not closed, we need to make this
- // call.
- if (initiator) {
- auto* print_view_manager = PrintViewManager::FromWebContents(initiator);
- print_view_manager->PrintPreviewDone();
- }
- }
-#endif
}
void PrintPreviewHandler::HandleCancelPendingPrintRequest(
@@ -880,7 +832,7 @@ void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) {
DCHECK(ok);
if (!token_service_)
- token_service_ = base::MakeUnique<AccessTokenService>(this);
+ token_service_ = std::make_unique<AccessTokenService>(this);
token_service_->RequestToken(type, callback_id);
}
@@ -1048,10 +1000,10 @@ void PrintPreviewHandler::SendPrinterSetup(
const std::string& callback_id,
const std::string& printer_name,
std::unique_ptr<base::DictionaryValue> destination_info) {
- auto response = base::MakeUnique<base::DictionaryValue>();
+ auto response = std::make_unique<base::DictionaryValue>();
bool success = true;
- auto caps_value = base::MakeUnique<base::Value>();
- auto caps = base::MakeUnique<base::DictionaryValue>();
+ auto caps_value = std::make_unique<base::Value>();
+ auto caps = std::make_unique<base::DictionaryValue>();
if (destination_info &&
destination_info->Remove(printing::kSettingCapabilities, &caps_value) &&
caps_value->is_dict()) {
@@ -1253,8 +1205,8 @@ PrinterHandler* PrintPreviewHandler::GetPrinterHandler(
}
if (printer_type == PrinterType::kLocalPrinter) {
if (!local_printer_handler_) {
- local_printer_handler_ =
- PrinterHandler::CreateForLocalPrinters(Profile::FromWebUI(web_ui()));
+ local_printer_handler_ = PrinterHandler::CreateForLocalPrinters(
+ preview_web_contents(), Profile::FromWebUI(web_ui()));
}
return local_printer_handler_.get();
}
@@ -1298,11 +1250,20 @@ void PrintPreviewHandler::OnGotExtensionPrinterInfo(
void PrintPreviewHandler::OnPrintResult(const std::string& callback_id,
const base::Value& error) {
- if (error.is_none()) {
+ if (error.is_none())
ResolveJavascriptCallback(base::Value(callback_id), error);
- return;
+ else
+ RejectJavascriptCallback(base::Value(callback_id), error);
+ // Remove the preview dialog from the background printing manager if it is
+ // being stored there. Since the PDF has been sent and the callback is
+ // resolved or rejected, it is no longer needed and can be destroyed.
+ printing::BackgroundPrintingManager* background_printing_manager =
+ g_browser_process->background_printing_manager();
+ if (background_printing_manager->HasPrintPreviewDialog(
+ preview_web_contents())) {
+ background_printing_manager->OnPrintRequestCancelled(
+ preview_web_contents());
}
- RejectJavascriptCallback(base::Value(callback_id), error);
}
void PrintPreviewHandler::RegisterForGaiaCookieChanges() {
diff --git a/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.h b/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.h
index 7552bb23f82..894f5e9adca 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.h
+++ b/chromium/chrome/browser/ui/webui/print_preview/print_preview_handler.h
@@ -322,12 +322,6 @@ class PrintPreviewHandler
base::queue<std::string> preview_callbacks_;
-#if BUILDFLAG(ENABLE_BASIC_PRINTING)
- // Print settings to use in the local print request to send when
- // HandleHidePreview() is called.
- std::unique_ptr<base::DictionaryValue> settings_;
-#endif
-
base::WeakPtrFactory<PrintPreviewHandler> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler);
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 111c46e9c7d..382461c39d9 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
@@ -82,6 +82,7 @@ PrinterInfo GetEmptyPrinterInfo() {
base::Value GetPrintTicket(printing::PrinterType type, bool cloud) {
bool is_privet_printer = !cloud && type == printing::kPrivetPrinter;
bool is_extension_printer = !cloud && type == printing::kExtensionPrinter;
+
base::Value ticket(base::Value::Type::DICTIONARY);
// Letter
@@ -597,8 +598,8 @@ TEST_F(PrintPreviewHandlerTest, Print) {
handler()->HandlePrint(list_args.get());
// Verify correct PrinterHandler was called or that no handler was requested
- // for local and cloud printers.
- if (cloud || type == printing::kLocalPrinter) {
+ // for cloud printers.
+ if (cloud) {
EXPECT_TRUE(handler()->NotCalled());
} else {
EXPECT_TRUE(handler()->CalledOnlyForType(type));
@@ -608,18 +609,6 @@ TEST_F(PrintPreviewHandlerTest, Print) {
const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
CheckWebUIResponse(data, callback_id_in, true);
- // For local printers, the Print Preview UI will respond to the resolution
- // by sending a "hidePreview" message, which should prompt an IPC message
- // to the renderer.
- if (type == printing::kLocalPrinter) {
- base::Value hide_args(base::Value::Type::LIST);
- std::unique_ptr<base::ListValue> hide_args_ptr = base::ListValue::From(
- base::Value::ToUniquePtrValue(std::move(hide_args)));
- handler()->HandleHidePreview(hide_args_ptr.get());
- EXPECT_TRUE(preview_sink().GetUniqueMessageMatching(
- PrintMsg_PrintForPrintPreview::ID));
- }
-
// For cloud print, should also get the encoded data back as a string.
if (cloud) {
std::string print_data;
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 ffca326089f..003106131a5 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
@@ -13,7 +13,6 @@
#include "base/feature_list.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
-#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
@@ -42,6 +41,7 @@
#include "components/prefs/pref_service.h"
#include "components/printing/common/print_messages.h"
#include "components/strings/grit/components_strings.h"
+#include "components/user_manager/user_manager.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_data_source.h"
@@ -54,6 +54,12 @@
#include "ui/web_dialogs/web_dialog_delegate.h"
#include "ui/web_dialogs/web_dialog_ui.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#elif defined(OS_WIN)
+#include "base/win/win_util.h"
+#endif
+
using content::WebContents;
using printing::PageSizeMargins;
@@ -167,6 +173,7 @@ bool HandleRequestCallback(
void AddPrintPreviewStrings(content::WebUIDataSource* source) {
source->AddLocalizedString("title", IDS_PRINT_PREVIEW_TITLE);
+ source->AddLocalizedString("learnMore", IDS_LEARN_MORE);
source->AddLocalizedString("loading", IDS_PRINT_PREVIEW_LOADING);
source->AddLocalizedString("noPlugin", IDS_PRINT_PREVIEW_NO_PLUGIN);
source->AddLocalizedString("launchNativeDialog",
@@ -174,6 +181,8 @@ void AddPrintPreviewStrings(content::WebUIDataSource* source) {
source->AddLocalizedString("previewFailed", IDS_PRINT_PREVIEW_FAILED);
source->AddLocalizedString("invalidPrinterSettings",
IDS_PRINT_INVALID_PRINTER_SETTINGS);
+ source->AddLocalizedString("unsupportedCloudPrinter",
+ IDS_PRINT_PREVIEW_UNSUPPORTED_CLOUD_PRINTER);
source->AddLocalizedString("printButton", IDS_PRINT_PREVIEW_PRINT_BUTTON);
source->AddLocalizedString("saveButton", IDS_PRINT_PREVIEW_SAVE_BUTTON);
source->AddLocalizedString("printing", IDS_PRINT_PREVIEW_PRINTING);
@@ -304,6 +313,8 @@ void AddPrintPreviewStrings(content::WebUIDataSource* source) {
source->AddLocalizedString("offlineForWeek",
IDS_PRINT_PREVIEW_OFFLINE_FOR_WEEK);
source->AddLocalizedString("offline", IDS_PRINT_PREVIEW_OFFLINE);
+ source->AddLocalizedString("noLongerSupported",
+ IDS_PRINT_PREVIEW_NO_LONGER_SUPPORTED);
source->AddLocalizedString("couldNotPrint",
IDS_PRINT_PREVIEW_COULD_NOT_PRINT);
source->AddLocalizedString("registerPromoButtonText",
@@ -394,6 +405,29 @@ void AddPrintPreviewFlags(content::WebUIDataSource* source, Profile* profile) {
prefs::kPrintPreviewUseSystemDefaultPrinter);
source->AddBoolean("useSystemDefaultPrinter", system_default_printer);
#endif
+
+ bool enterprise_managed = false;
+#if defined(OS_CHROMEOS)
+ policy::BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos();
+ enterprise_managed = connector->IsEnterpriseManaged();
+#elif defined(OS_WIN)
+ enterprise_managed = base::win::IsEnterpriseManaged();
+#endif
+ source->AddBoolean("isEnterpriseManaged", enterprise_managed);
+}
+
+void SetupPrintPreviewPlugin(content::WebUIDataSource* source) {
+ source->AddResourcePath("pdf_preview.html",
+ IDR_PRINT_PREVIEW_PDF_PREVIEW_HTML);
+ source->SetRequestFilter(base::BindRepeating(&HandleRequestCallback));
+ source->OverrideContentSecurityPolicyScriptSrc(
+ base::StringPrintf("script-src chrome://resources 'self' 'unsafe-eval' "
+ "chrome-extension://%s;",
+ extension_misc::kPdfExtensionId));
+ source->OverrideContentSecurityPolicyChildSrc("child-src 'self';");
+ source->DisableDenyXFrameOptions();
+ source->OverrideContentSecurityPolicyObjectSrc("object-src 'self';");
}
content::WebUIDataSource* CreateNewPrintPreviewUISource(Profile* profile) {
@@ -407,6 +441,8 @@ content::WebUIDataSource* CreateNewPrintPreviewUISource(Profile* profile) {
}
AddPrintPreviewImages(source);
source->SetDefaultResource(IDR_PRINT_PREVIEW_NEW_HTML);
+ SetupPrintPreviewPlugin(source);
+ AddPrintPreviewFlags(source, profile);
return source;
}
@@ -416,18 +452,9 @@ content::WebUIDataSource* CreatePrintPreviewUISource(Profile* profile) {
AddPrintPreviewStrings(source);
source->SetJsonPath("strings.js");
source->AddResourcePath("print_preview.js", IDR_PRINT_PREVIEW_JS);
- source->AddResourcePath("pdf_preview.html",
- IDR_PRINT_PREVIEW_PDF_PREVIEW_HTML);
AddPrintPreviewImages(source);
source->SetDefaultResource(IDR_PRINT_PREVIEW_HTML);
- source->SetRequestFilter(base::Bind(&HandleRequestCallback));
- source->OverrideContentSecurityPolicyScriptSrc(
- base::StringPrintf("script-src chrome://resources 'self' 'unsafe-eval' "
- "chrome-extension://%s;",
- extension_misc::kPdfExtensionId));
- source->OverrideContentSecurityPolicyChildSrc("child-src 'self';");
- source->DisableDenyXFrameOptions();
- source->OverrideContentSecurityPolicyObjectSrc("object-src 'self';");
+ SetupPrintPreviewPlugin(source);
AddPrintPreviewFlags(source, profile);
return source;
}
@@ -474,10 +501,10 @@ PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui)
// Set up the chrome://theme/ source.
content::URLDataSource::Add(profile, new ThemeSource(profile));
- auto handler = base::MakeUnique<PrintPreviewHandler>();
+ auto handler = std::make_unique<PrintPreviewHandler>();
handler_ = handler.get();
web_ui->AddMessageHandler(std::move(handler));
- web_ui->AddMessageHandler(base::MakeUnique<MetricsHandler>());
+ web_ui->AddMessageHandler(std::make_unique<MetricsHandler>());
g_print_preview_request_id_map.Get().Set(id_, -1);
}
diff --git a/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.cc b/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.cc
index 33b8bef65ee..6205ef5ca36 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.cc
@@ -9,18 +9,24 @@
#include <utility>
#include <vector>
+#include "base/json/json_reader.h"
#include "base/logging.h"
-#include "base/memory/ptr_util.h"
+#include "base/memory/ref_counted_memory.h"
#include "base/stl_util.h"
#include "base/strings/string_piece.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
+#include "chrome/browser/printing/print_preview_dialog_controller.h"
+#include "chrome/browser/printing/print_view_manager.h"
+#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include "chrome/browser/ui/webui/print_preview/printer_handler.h"
#include "chrome/common/cloud_print/cloud_print_cdd_conversion.h"
#include "chrome/common/crash_keys.h"
+#include "content/public/browser/render_frame_host.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h"
+#include "printing/page_range.h"
#if defined(OS_WIN)
#include "base/strings/string_split.h"
@@ -101,7 +107,7 @@ std::string GetUserFriendlyName(const std::string& printer_name) {
void PrintersToValues(const PrinterList& printer_list,
base::ListValue* printers) {
for (const PrinterBasicInfo& printer : printer_list) {
- auto printer_info = base::MakeUnique<base::DictionaryValue>();
+ auto printer_info = std::make_unique<base::DictionaryValue>();
printer_info->SetString(kSettingDeviceName, printer.printer_name);
const auto printer_name_description = GetPrinterNameAndDescription(printer);
@@ -110,7 +116,7 @@ void PrintersToValues(const PrinterList& printer_list,
printer_info->SetString(kSettingPrinterName, printer_name);
printer_info->SetString(kSettingPrinterDescription, printer_description);
- auto options = base::MakeUnique<base::DictionaryValue>();
+ auto options = std::make_unique<base::DictionaryValue>();
for (const auto opt_it : printer.options)
options->SetString(opt_it.first, opt_it.second);
@@ -161,6 +167,10 @@ bool VendorCapabilityInvalid(const base::Value& val) {
return false;
}
+void SystemDialogDone(const base::Value& error) {
+ // intentional no-op
+}
+
} // namespace
std::pair<std::string, std::string> GetPrinterNameAndDescription(
@@ -193,7 +203,7 @@ std::unique_ptr<base::DictionaryValue> GetSettingsOnBlockingPool(
const std::string& printer_name = printer_name_description.first;
const std::string& printer_description = printer_name_description.second;
- auto printer_info = base::MakeUnique<base::DictionaryValue>();
+ auto printer_info = std::make_unique<base::DictionaryValue>();
printer_info->SetString(kSettingDeviceName, device_name);
printer_info->SetString(kSettingPrinterName, printer_name);
printer_info->SetString(kSettingPrinterDescription, printer_description);
@@ -281,4 +291,42 @@ std::unique_ptr<base::DictionaryValue> ValidateCddForPrintPreview(
return validated_cdd;
}
+void StartLocalPrint(const std::string& ticket_json,
+ const scoped_refptr<base::RefCountedBytes>& print_data,
+ content::WebContents* preview_web_contents,
+ PrinterHandler::PrintCallback callback) {
+ std::unique_ptr<base::DictionaryValue> job_settings =
+ base::DictionaryValue::From(base::JSONReader::Read(ticket_json));
+ if (!job_settings) {
+ std::move(callback).Run(base::Value("Invalid settings"));
+ return;
+ }
+
+ // Get print view manager.
+ PrintPreviewDialogController* dialog_controller =
+ PrintPreviewDialogController::GetInstance();
+ content::WebContents* initiator =
+ dialog_controller ? dialog_controller->GetInitiator(preview_web_contents)
+ : nullptr;
+ PrintViewManager* print_view_manager =
+ PrintViewManager::FromWebContents(initiator);
+ if (!print_view_manager) {
+ std::move(callback).Run(base::Value("Initiator closed"));
+ return;
+ }
+
+ bool system_dialog = false;
+ job_settings->GetBoolean(printing::kSettingShowSystemDialog, &system_dialog);
+ bool open_in_pdf = false;
+ job_settings->GetBoolean(printing::kSettingOpenPDFInPreview, &open_in_pdf);
+ if (system_dialog || open_in_pdf) {
+ // Run the callback early, or the modal dialogs will prevent the preview
+ // from closing until they do.
+ std::move(callback).Run(base::Value());
+ callback = base::BindOnce(&SystemDialogDone);
+ }
+ print_view_manager->PrintForPrintPreview(std::move(job_settings), print_data,
+ preview_web_contents->GetMainFrame(),
+ std::move(callback));
+}
} // namespace printing
diff --git a/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.h b/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.h
index 47bd80f68fb..04dd0fee87c 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.h
+++ b/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities.h
@@ -13,6 +13,10 @@
#include "chrome/browser/ui/webui/print_preview/printer_handler.h"
#include "printing/backend/print_backend.h"
+namespace content {
+class WebContents;
+}
+
namespace printing {
struct PrinterBasicInfo;
@@ -50,6 +54,13 @@ void ConvertPrinterListForCallback(
// and remove any lists/options that are empty or only contain null values.
std::unique_ptr<base::DictionaryValue> ValidateCddForPrintPreview(
const base::DictionaryValue& cdd);
+
+// Starts a local print of |print_data| with print settings dictionary
+// |ticket_json|. Runs |callback| on failure or success.
+void StartLocalPrint(const std::string& ticket_json,
+ const scoped_refptr<base::RefCountedBytes>& print_data,
+ content::WebContents* preview_web_contents,
+ PrinterHandler::PrintCallback callback);
} // namespace printing
#endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINTER_CAPABILITIES_H_
diff --git a/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities_unittest.cc b/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities_unittest.cc
index a079534193f..4be22d60559 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities_unittest.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/printer_capabilities_unittest.cc
@@ -5,7 +5,6 @@
#include <memory>
#include "base/bind.h"
-#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/stl_util.h"
#include "base/test/values_test_util.h"
@@ -250,7 +249,7 @@ TEST_F(PrinterCapabilitiesTest, NonNullForMissingPrinter) {
TEST_F(PrinterCapabilitiesTest, ProvidedCapabilitiesUsed) {
std::string printer_name = "test_printer";
PrinterBasicInfo basic_info;
- auto caps = base::MakeUnique<PrinterSemanticCapsAndDefaults>();
+ auto caps = std::make_unique<PrinterSemanticCapsAndDefaults>();
// set a capability
caps->dpis = {gfx::Size(600, 600)};
diff --git a/chromium/chrome/browser/ui/webui/print_preview/printer_handler.cc b/chromium/chrome/browser/ui/webui/print_preview/printer_handler.cc
index 43126964a2e..bf297f51a01 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/printer_handler.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/printer_handler.cc
@@ -22,16 +22,18 @@
// static
std::unique_ptr<PrinterHandler> PrinterHandler::CreateForExtensionPrinters(
Profile* profile) {
- return base::MakeUnique<ExtensionPrinterHandler>(profile);
+ return std::make_unique<ExtensionPrinterHandler>(profile);
}
// static
std::unique_ptr<PrinterHandler> PrinterHandler::CreateForLocalPrinters(
+ content::WebContents* preview_web_contents,
Profile* profile) {
#if defined(OS_CHROMEOS)
- return base::MakeUnique<LocalPrinterHandlerChromeos>(profile);
+ return std::make_unique<LocalPrinterHandlerChromeos>(profile,
+ preview_web_contents);
#else
- return base::MakeUnique<LocalPrinterHandlerDefault>();
+ return std::make_unique<LocalPrinterHandlerDefault>(preview_web_contents);
#endif
}
@@ -40,7 +42,7 @@ std::unique_ptr<PrinterHandler> PrinterHandler::CreateForPdfPrinter(
Profile* profile,
content::WebContents* preview_web_contents,
printing::StickySettings* sticky_settings) {
- return base::MakeUnique<PdfPrinterHandler>(profile, preview_web_contents,
+ return std::make_unique<PdfPrinterHandler>(profile, preview_web_contents,
sticky_settings);
}
@@ -48,7 +50,7 @@ std::unique_ptr<PrinterHandler> PrinterHandler::CreateForPdfPrinter(
// static
std::unique_ptr<PrinterHandler> PrinterHandler::CreateForPrivetPrinters(
Profile* profile) {
- return base::MakeUnique<PrivetPrinterHandler>(profile);
+ return std::make_unique<PrivetPrinterHandler>(profile);
}
#endif
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 96a2fcbc656..6231bafd927 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/printer_handler.h
+++ b/chromium/chrome/browser/ui/webui/print_preview/printer_handler.h
@@ -71,6 +71,7 @@ class PrinterHandler {
printing::StickySettings* sticky_settings);
static std::unique_ptr<PrinterHandler> CreateForLocalPrinters(
+ content::WebContents* preview_web_contents,
Profile* profile);
#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
diff --git a/chromium/chrome/browser/ui/webui/print_preview/privet_printer_handler.cc b/chromium/chrome/browser/ui/webui/print_preview/privet_printer_handler.cc
index f76fa14cf68..eedc4c4573b 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/privet_printer_handler.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/privet_printer_handler.cc
@@ -102,7 +102,7 @@ void PrivetPrinterHandler::LocalPrinterChanged(
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (has_local_printing ||
command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) {
- auto printer_info = base::MakeUnique<base::DictionaryValue>();
+ auto printer_info = std::make_unique<base::DictionaryValue>();
FillPrinterDescription(name, description, has_local_printing,
printer_info.get());
base::ListValue printers;
@@ -134,9 +134,9 @@ void PrivetPrinterHandler::StartLister(
DCHECK(!service_discovery_client_.get() ||
service_discovery_client_.get() == client.get());
service_discovery_client_ = client;
- printer_lister_ = base::MakeUnique<cloud_print::PrivetLocalPrinterLister>(
+ printer_lister_ = std::make_unique<cloud_print::PrivetLocalPrinterLister>(
service_discovery_client_.get(), profile_->GetRequestContext(), this);
- privet_lister_timer_ = base::MakeUnique<base::OneShotTimer>();
+ privet_lister_timer_ = std::make_unique<base::OneShotTimer>();
privet_lister_timer_->Start(FROM_HERE,
base::TimeDelta::FromSeconds(kSearchTimeoutSec),
this, &PrivetPrinterHandler::StopLister);
diff --git a/chromium/chrome/browser/ui/webui/print_preview/sticky_settings.cc b/chromium/chrome/browser/ui/webui/print_preview/sticky_settings.cc
index 222469eb911..e69c53e94b9 100644
--- a/chromium/chrome/browser/ui/webui/print_preview/sticky_settings.cc
+++ b/chromium/chrome/browser/ui/webui/print_preview/sticky_settings.cc
@@ -4,7 +4,8 @@
#include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
-#include "base/memory/ptr_util.h"
+#include <memory>
+
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
@@ -32,7 +33,7 @@ void StickySettings::StoreAppState(const std::string& data) {
}
void StickySettings::SaveInPrefs(PrefService* prefs) const {
- auto value = base::MakeUnique<base::DictionaryValue>();
+ auto value = std::make_unique<base::DictionaryValue>();
if (printer_app_state_)
value->SetString(kSettingAppState, printer_app_state_.value());
prefs->Set(prefs::kPrintPreviewStickySettings, *value);