Commit 170b95cf authored by tbarzic's avatar tbarzic Committed by Commit bot

Add title property to chrome.printerProvider print job

BUG=470647

Review URL: https://codereview.chromium.org/1006583003

Cr-Commit-Position: refs/heads/master@{#322267}
parent 56f35ff9
...@@ -108,6 +108,7 @@ void ExtensionPrinterHandler::StartGetCapability( ...@@ -108,6 +108,7 @@ void ExtensionPrinterHandler::StartGetCapability(
void ExtensionPrinterHandler::StartPrint( void ExtensionPrinterHandler::StartPrint(
const std::string& destination_id, const std::string& destination_id,
const std::string& capability, const std::string& capability,
const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedMemory>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
...@@ -115,6 +116,7 @@ void ExtensionPrinterHandler::StartPrint( ...@@ -115,6 +116,7 @@ void ExtensionPrinterHandler::StartPrint(
scoped_ptr<extensions::PrinterProviderPrintJob> print_job( scoped_ptr<extensions::PrinterProviderPrintJob> print_job(
new extensions::PrinterProviderPrintJob()); new extensions::PrinterProviderPrintJob());
print_job->printer_id = destination_id; print_job->printer_id = destination_id;
print_job->job_title = job_title;
print_job->ticket_json = ticket_json; print_job->ticket_json = ticket_json;
cloud_devices::CloudDeviceDescription printer_description; cloud_devices::CloudDeviceDescription printer_description;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/webui/print_preview/printer_handler.h" #include "chrome/browser/ui/webui/print_preview/printer_handler.h"
#include "extensions/browser/api/printer_provider/printer_provider_api.h" #include "extensions/browser/api/printer_provider/printer_provider_api.h"
...@@ -59,6 +60,7 @@ class ExtensionPrinterHandler : public PrinterHandler { ...@@ -59,6 +60,7 @@ class ExtensionPrinterHandler : public PrinterHandler {
// TODO(tbarzic): It might make sense to have the strings in a single struct. // TODO(tbarzic): It might make sense to have the strings in a single struct.
void StartPrint(const std::string& destination_id, void StartPrint(const std::string& destination_id,
const std::string& capability, const std::string& capability,
const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedMemory>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/local_discovery/pwg_raster_converter.h" #include "chrome/browser/local_discovery/pwg_raster_converter.h"
#include "chrome/browser/ui/webui/print_preview/extension_printer_handler.h" #include "chrome/browser/ui/webui/print_preview/extension_printer_handler.h"
...@@ -512,10 +514,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pdf) { ...@@ -512,10 +514,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pdf) {
scoped_refptr<base::RefCountedString> print_data( scoped_refptr<base::RefCountedString> print_data(
new base::RefCountedString()); new base::RefCountedString());
print_data->data() = "print data, PDF"; print_data->data() = "print data, PDF";
base::string16 title = base::ASCIIToUTF16("Title");
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
kPrinterId, kPdfSupportedPrinter, kEmptyPrintTicket, gfx::Size(100, 100), kPrinterId, kPdfSupportedPrinter, title, kEmptyPrintTicket,
print_data, gfx::Size(100, 100), print_data,
base::Bind(&RecordPrintResult, &call_count, &success, &status)); base::Bind(&RecordPrintResult, &call_count, &success, &status));
EXPECT_EQ(0u, call_count); EXPECT_EQ(0u, call_count);
...@@ -527,6 +530,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pdf) { ...@@ -527,6 +530,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pdf) {
ASSERT_TRUE(print_job); ASSERT_TRUE(print_job);
EXPECT_EQ(kPrinterId, print_job->printer_id); EXPECT_EQ(kPrinterId, print_job->printer_id);
EXPECT_EQ(title, print_job->job_title);
EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json); EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json);
EXPECT_EQ(kContentTypePDF, print_job->content_type); EXPECT_EQ(kContentTypePDF, print_job->content_type);
EXPECT_TRUE(print_job->document_path.empty()); EXPECT_TRUE(print_job->document_path.empty());
...@@ -549,10 +553,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pdf_Reset) { ...@@ -549,10 +553,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pdf_Reset) {
scoped_refptr<base::RefCountedString> print_data( scoped_refptr<base::RefCountedString> print_data(
new base::RefCountedString()); new base::RefCountedString());
print_data->data() = "print data, PDF"; print_data->data() = "print data, PDF";
base::string16 title = base::ASCIIToUTF16("Title");
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
kPrinterId, kPdfSupportedPrinter, kEmptyPrintTicket, gfx::Size(100, 100), kPrinterId, kPdfSupportedPrinter, title, kEmptyPrintTicket,
print_data, gfx::Size(100, 100), print_data,
base::Bind(&RecordPrintResult, &call_count, &success, &status)); base::Bind(&RecordPrintResult, &call_count, &success, &status));
EXPECT_EQ(0u, call_count); EXPECT_EQ(0u, call_count);
...@@ -575,9 +580,10 @@ TEST_F(ExtensionPrinterHandlerTest, Print_All) { ...@@ -575,9 +580,10 @@ TEST_F(ExtensionPrinterHandlerTest, Print_All) {
scoped_refptr<base::RefCountedString> print_data( scoped_refptr<base::RefCountedString> print_data(
new base::RefCountedString()); new base::RefCountedString());
print_data->data() = "print data, PDF"; print_data->data() = "print data, PDF";
base::string16 title = base::ASCIIToUTF16("Title");
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
kPrinterId, kAllContentTypesSupportedPrinter, kEmptyPrintTicket, kPrinterId, kAllContentTypesSupportedPrinter, title, kEmptyPrintTicket,
gfx::Size(100, 100), print_data, gfx::Size(100, 100), print_data,
base::Bind(&RecordPrintResult, &call_count, &success, &status)); base::Bind(&RecordPrintResult, &call_count, &success, &status));
...@@ -591,6 +597,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_All) { ...@@ -591,6 +597,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_All) {
ASSERT_TRUE(print_job); ASSERT_TRUE(print_job);
EXPECT_EQ(kPrinterId, print_job->printer_id); EXPECT_EQ(kPrinterId, print_job->printer_id);
EXPECT_EQ(title, print_job->job_title);
EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json); EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json);
EXPECT_EQ(kContentTypePDF, print_job->content_type); EXPECT_EQ(kContentTypePDF, print_job->content_type);
EXPECT_TRUE(print_job->document_path.empty()); EXPECT_TRUE(print_job->document_path.empty());
...@@ -613,10 +620,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg) { ...@@ -613,10 +620,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg) {
scoped_refptr<base::RefCountedString> print_data( scoped_refptr<base::RefCountedString> print_data(
new base::RefCountedString()); new base::RefCountedString());
print_data->data() = "print data, PDF"; print_data->data() = "print data, PDF";
base::string16 title = base::ASCIIToUTF16("Title");
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, kEmptyPrintTicket, kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, title,
gfx::Size(100, 50), print_data, kEmptyPrintTicket, gfx::Size(100, 50), print_data,
base::Bind(&RecordPrintResult, &call_count, &success, &status)); base::Bind(&RecordPrintResult, &call_count, &success, &status));
EXPECT_EQ(0u, call_count); EXPECT_EQ(0u, call_count);
...@@ -642,6 +650,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg) { ...@@ -642,6 +650,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg) {
ASSERT_TRUE(print_job); ASSERT_TRUE(print_job);
EXPECT_EQ(kPrinterId, print_job->printer_id); EXPECT_EQ(kPrinterId, print_job->printer_id);
EXPECT_EQ(title, print_job->job_title);
EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json); EXPECT_EQ(kEmptyPrintTicket, print_job->ticket_json);
EXPECT_EQ(kContentTypePWG, print_job->content_type); EXPECT_EQ(kContentTypePWG, print_job->content_type);
EXPECT_FALSE(print_job->document_bytes); EXPECT_FALSE(print_job->document_bytes);
...@@ -665,9 +674,10 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_NonDefaultSettings) { ...@@ -665,9 +674,10 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_NonDefaultSettings) {
scoped_refptr<base::RefCountedString> print_data( scoped_refptr<base::RefCountedString> print_data(
new base::RefCountedString()); new base::RefCountedString());
print_data->data() = "print data, PDF"; print_data->data() = "print data, PDF";
base::string16 title = base::ASCIIToUTF16("Title");
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
kPrinterId, kPWGRasterOnlyPrinter, kPrintTicketWithDuplex, kPrinterId, kPWGRasterOnlyPrinter, title, kPrintTicketWithDuplex,
gfx::Size(100, 50), print_data, gfx::Size(100, 50), print_data,
base::Bind(&RecordPrintResult, &call_count, &success, &status)); base::Bind(&RecordPrintResult, &call_count, &success, &status));
...@@ -694,6 +704,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_NonDefaultSettings) { ...@@ -694,6 +704,7 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_NonDefaultSettings) {
ASSERT_TRUE(print_job); ASSERT_TRUE(print_job);
EXPECT_EQ(kPrinterId, print_job->printer_id); EXPECT_EQ(kPrinterId, print_job->printer_id);
EXPECT_EQ(title, print_job->job_title);
EXPECT_EQ(kPrintTicketWithDuplex, print_job->ticket_json); EXPECT_EQ(kPrintTicketWithDuplex, print_job->ticket_json);
EXPECT_EQ(kContentTypePWG, print_job->content_type); EXPECT_EQ(kContentTypePWG, print_job->content_type);
EXPECT_FALSE(print_job->document_bytes); EXPECT_FALSE(print_job->document_bytes);
...@@ -717,10 +728,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_Reset) { ...@@ -717,10 +728,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_Reset) {
scoped_refptr<base::RefCountedString> print_data( scoped_refptr<base::RefCountedString> print_data(
new base::RefCountedString()); new base::RefCountedString());
print_data->data() = "print data, PDF"; print_data->data() = "print data, PDF";
base::string16 title = base::ASCIIToUTF16("Title");
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, kEmptyPrintTicket, kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, title,
gfx::Size(100, 50), print_data, kEmptyPrintTicket, gfx::Size(100, 50), print_data,
base::Bind(&RecordPrintResult, &call_count, &success, &status)); base::Bind(&RecordPrintResult, &call_count, &success, &status));
EXPECT_EQ(0u, call_count); EXPECT_EQ(0u, call_count);
...@@ -746,10 +758,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_InvalidTicket) { ...@@ -746,10 +758,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_InvalidTicket) {
scoped_refptr<base::RefCountedString> print_data( scoped_refptr<base::RefCountedString> print_data(
new base::RefCountedString()); new base::RefCountedString());
print_data->data() = "print data, PDF"; print_data->data() = "print data, PDF";
base::string16 title = base::ASCIIToUTF16("Title");
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, "{}" /* ticket */, kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, title,
gfx::Size(100, 100), print_data, "{}" /* ticket */, gfx::Size(100, 100), print_data,
base::Bind(&RecordPrintResult, &call_count, &success, &status)); base::Bind(&RecordPrintResult, &call_count, &success, &status));
EXPECT_EQ(1u, call_count); EXPECT_EQ(1u, call_count);
...@@ -768,10 +781,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_FailedConversion) { ...@@ -768,10 +781,11 @@ TEST_F(ExtensionPrinterHandlerTest, Print_Pwg_FailedConversion) {
scoped_refptr<base::RefCountedString> print_data( scoped_refptr<base::RefCountedString> print_data(
new base::RefCountedString()); new base::RefCountedString());
print_data->data() = "print data, PDF"; print_data->data() = "print data, PDF";
base::string16 title = base::ASCIIToUTF16("Title");
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, kEmptyPrintTicket, kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, title,
gfx::Size(100, 100), print_data, kEmptyPrintTicket, gfx::Size(100, 100), print_data,
base::Bind(&RecordPrintResult, &call_count, &success, &status)); base::Bind(&RecordPrintResult, &call_count, &success, &status));
EXPECT_EQ(1u, call_count); EXPECT_EQ(1u, call_count);
......
...@@ -915,9 +915,10 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { ...@@ -915,9 +915,10 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
EnsureExtensionPrinterHandlerSet(); EnsureExtensionPrinterHandlerSet();
extension_printer_handler_->StartPrint( extension_printer_handler_->StartPrint(
destination_id, capabilities, print_ticket, gfx::Size(width, height), destination_id, capabilities, title, print_ticket,
data, base::Bind(&PrintPreviewHandler::OnExtensionPrintResult, gfx::Size(width, height), data,
base::Unretained(this))); base::Bind(&PrintPreviewHandler::OnExtensionPrintResult,
base::Unretained(this)));
return; return;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
...@@ -61,6 +62,7 @@ class PrinterHandler { ...@@ -61,6 +62,7 @@ class PrinterHandler {
// Starts a print request. // Starts a print request.
// |destination_id|: The printer to which print job should be sent. // |destination_id|: The printer to which print job should be sent.
// |capability|: Capability reported by the printer. // |capability|: Capability reported by the printer.
// |job_title|: The title used for print job.
// |ticket_json|: The print job ticket as JSON string. // |ticket_json|: The print job ticket as JSON string.
// |page_size|: The document page size. // |page_size|: The document page size.
// |print_data|: The document bytes to print. // |print_data|: The document bytes to print.
...@@ -69,6 +71,7 @@ class PrinterHandler { ...@@ -69,6 +71,7 @@ class PrinterHandler {
virtual void StartPrint( virtual void StartPrint(
const std::string& destination_id, const std::string& destination_id,
const std::string& capability, const std::string& capability,
const base::string16& job_title,
const std::string& ticket_json, const std::string& ticket_json,
const gfx::Size& page_size, const gfx::Size& page_size,
const scoped_refptr<base::RefCountedMemory>& print_data, const scoped_refptr<base::RefCountedMemory>& print_data,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "extensions/browser/api/printer_provider/printer_provider_print_job.h" #include "extensions/browser/api/printer_provider/printer_provider_print_job.h"
#include "extensions/browser/api/printer_provider_internal/printer_provider_internal_api.h" #include "extensions/browser/api/printer_provider_internal/printer_provider_internal_api.h"
...@@ -510,6 +511,7 @@ void PrinterProviderAPIImpl::DispatchPrintRequested( ...@@ -510,6 +511,7 @@ void PrinterProviderAPIImpl::DispatchPrintRequested(
} }
print_job.content_type = job.content_type; print_job.content_type = job.content_type;
print_job.title = base::UTF16ToUTF8(job.job_title);
int request_id = pending_print_requests_[extension_id].Add(job, callback); int request_id = pending_print_requests_[extension_id].Add(job, callback);
scoped_ptr<base::ListValue> internal_args(new base::ListValue); scoped_ptr<base::ListValue> internal_args(new base::ListValue);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "extensions/browser/api/printer_provider/printer_provider_api.h" #include "extensions/browser/api/printer_provider/printer_provider_api.h"
#include "extensions/browser/api/printer_provider/printer_provider_api_factory.h" #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h"
#include "extensions/browser/api/printer_provider/printer_provider_print_job.h" #include "extensions/browser/api/printer_provider/printer_provider_print_job.h"
...@@ -106,6 +107,7 @@ class PrinterProviderApiTest : public extensions::ShellApiTest { ...@@ -106,6 +107,7 @@ class PrinterProviderApiTest : public extensions::ShellApiTest {
const PrinterProviderAPI::PrintCallback& callback) { const PrinterProviderAPI::PrintCallback& callback) {
extensions::PrinterProviderPrintJob job; extensions::PrinterProviderPrintJob job;
job.printer_id = extension_id + ":printer_id"; job.printer_id = extension_id + ":printer_id";
job.job_title = base::ASCIIToUTF16("Print job");
job.ticket_json = "{}"; job.ticket_json = "{}";
job.content_type = "application/pdf"; job.content_type = "application/pdf";
const unsigned char kDocumentBytes[] = {'b', 'y', 't', 'e', 's'}; const unsigned char kDocumentBytes[] = {'b', 'y', 't', 'e', 's'};
...@@ -130,6 +132,7 @@ class PrinterProviderApiTest : public extensions::ShellApiTest { ...@@ -130,6 +132,7 @@ class PrinterProviderApiTest : public extensions::ShellApiTest {
} }
job.printer_id = extension_id + ":printer_id"; job.printer_id = extension_id + ":printer_id";
job.job_title = base::ASCIIToUTF16("Print job");
job.ticket_json = "{}"; job.ticket_json = "{}";
job.content_type = "image/pwg-raster"; job.content_type = "image/pwg-raster";
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/strings/string16.h"
namespace extensions { namespace extensions {
...@@ -30,6 +31,9 @@ struct PrinterProviderPrintJob { ...@@ -30,6 +31,9 @@ struct PrinterProviderPrintJob {
// chrome.printerProvider.onGetPrintersRequested event callback). // chrome.printerProvider.onGetPrintersRequested event callback).
std::string printer_id; std::string printer_id;
// The print job title.
base::string16 job_title;
// The print job ticket. // The print job ticket.
std::string ticket_json; std::string ticket_json;
......
...@@ -43,6 +43,9 @@ namespace printerProvider { ...@@ -43,6 +43,9 @@ namespace printerProvider {
// ID of the printer which should handle the job. // ID of the printer which should handle the job.
DOMString printerId; DOMString printerId;
// The print job title.
DOMString title;
// Print ticket in // Print ticket in
// <a href="https://developers.google.com/cloud-print/docs/cdd#cjt"> // <a href="https://developers.google.com/cloud-print/docs/cdd#cjt">
// CJT format</a>. // CJT format</a>.
......
...@@ -64,6 +64,8 @@ chrome.test.sendMessage('loaded', function(test) { ...@@ -64,6 +64,8 @@ chrome.test.sendMessage('loaded', function(test) {
if (content) if (content)
chrome.test.assertEq('bytes', content); chrome.test.assertEq('bytes', content);
chrome.test.assertEq('Print job', job.title);
chrome.test.succeed(); chrome.test.succeed();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment