1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINTER_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINTER_HANDLER_H_
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
16 class DictionaryValue
;
18 class RefCountedMemory
;
29 // Wrapper around PrinterProviderAPI to be used by print preview.
30 // It makes request lifetime management easier, and hides details of more
31 // complex operations like printing from the print preview handler.
32 // TODO(tbarzic): Use the same interface for other printer types.
33 class PrinterHandler
{
35 using GetPrintersCallback
=
36 base::Callback
<void(const base::ListValue
& printers
, bool done
)>;
37 using GetCapabilityCallback
=
38 base::Callback
<void(const std::string
& printer_id
,
39 const base::DictionaryValue
& capability
)>;
41 base::Callback
<void(bool success
, const std::string
& error
)>;
43 // Creates an instance of an PrinterHandler for extension printers.
44 static scoped_ptr
<PrinterHandler
> CreateForExtensionPrinters(
45 content::BrowserContext
* browser_context
);
47 virtual ~PrinterHandler() {}
49 // Cancels all pending requests.
50 virtual void Reset() = 0;
52 // Starts getting available printers.
53 // |callback| should be called in the response to the request.
54 virtual void StartGetPrinters(const GetPrintersCallback
& callback
) = 0;
56 // Starts getting printing capability of the printer with the provided
58 // |callback| should be called in the response to the request.
59 virtual void StartGetCapability(const std::string
& destination_id
,
60 const GetCapabilityCallback
& callback
) = 0;
62 // Starts a print request.
63 // |destination_id|: The printer to which print job should be sent.
64 // |capability|: Capability reported by the printer.
65 // |job_title|: The title used for print job.
66 // |ticket_json|: The print job ticket as JSON string.
67 // |page_size|: The document page size.
68 // |print_data|: The document bytes to print.
69 // |callback| should be called in the response to the request.
70 // TODO(tbarzic): Page size should be extracted from print data.
71 virtual void StartPrint(
72 const std::string
& destination_id
,
73 const std::string
& capability
,
74 const base::string16
& job_title
,
75 const std::string
& ticket_json
,
76 const gfx::Size
& page_size
,
77 const scoped_refptr
<base::RefCountedMemory
>& print_data
,
78 const PrintCallback
& callback
) = 0;
81 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINTER_HANDLER_H_