Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / print_preview / printer_handler.h
blobad49469f325c0ecc98c32b11034a199ccf7d95f1
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_
8 #include <string>
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"
15 namespace base {
16 class DictionaryValue;
17 class ListValue;
18 class RefCountedMemory;
21 namespace content {
22 class BrowserContext;
25 namespace gfx {
26 class Size;
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 {
34 public:
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)>;
40 using PrintCallback =
41 base::Callback<void(bool success, const std::string& error)>;
42 using GetPrinterInfoCallback =
43 base::Callback<void(const base::DictionaryValue& printer_info)>;
45 // Creates an instance of an PrinterHandler for extension printers.
46 static scoped_ptr<PrinterHandler> CreateForExtensionPrinters(
47 content::BrowserContext* browser_context);
49 virtual ~PrinterHandler() {}
51 // Cancels all pending requests.
52 virtual void Reset() = 0;
54 // Starts getting available printers.
55 // |callback| should be called in the response to the request.
56 virtual void StartGetPrinters(const GetPrintersCallback& callback) = 0;
58 // Starts getting printing capability of the printer with the provided
59 // destination ID.
60 // |callback| should be called in the response to the request.
61 virtual void StartGetCapability(const std::string& destination_id,
62 const GetCapabilityCallback& callback) = 0;
64 // Starts granting access to the given provisional printer. The print handler
65 // will respond with more information about the printer including its non-
66 // provisional printer id.
67 // |callback| should be called in response to the request.
68 virtual void StartGrantPrinterAccess(
69 const std::string& printer_id,
70 const GetPrinterInfoCallback& callback) = 0;
72 // Starts a print request.
73 // |destination_id|: The printer to which print job should be sent.
74 // |capability|: Capability reported by the printer.
75 // |job_title|: The title used for print job.
76 // |ticket_json|: The print job ticket as JSON string.
77 // |page_size|: The document page size.
78 // |print_data|: The document bytes to print.
79 // |callback| should be called in the response to the request.
80 // TODO(tbarzic): Page size should be extracted from print data.
81 virtual void StartPrint(
82 const std::string& destination_id,
83 const std::string& capability,
84 const base::string16& job_title,
85 const std::string& ticket_json,
86 const gfx::Size& page_size,
87 const scoped_refptr<base::RefCountedMemory>& print_data,
88 const PrintCallback& callback) = 0;
91 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINTER_HANDLER_H_