blob: ad49469f325c0ecc98c32b11034a199ccf7d95f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINTER_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINTER_HANDLER_H_
#include <string>
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
namespace base {
class DictionaryValue;
class ListValue;
class RefCountedMemory;
}
namespace content {
class BrowserContext;
}
namespace gfx {
class Size;
}
// Wrapper around PrinterProviderAPI to be used by print preview.
// It makes request lifetime management easier, and hides details of more
// complex operations like printing from the print preview handler.
// TODO(tbarzic): Use the same interface for other printer types.
class PrinterHandler {
public:
using GetPrintersCallback =
base::Callback<void(const base::ListValue& printers, bool done)>;
using GetCapabilityCallback =
base::Callback<void(const std::string& printer_id,
const base::DictionaryValue& capability)>;
using PrintCallback =
base::Callback<void(bool success, const std::string& error)>;
using GetPrinterInfoCallback =
base::Callback<void(const base::DictionaryValue& printer_info)>;
// Creates an instance of an PrinterHandler for extension printers.
static scoped_ptr<PrinterHandler> CreateForExtensionPrinters(
content::BrowserContext* browser_context);
virtual ~PrinterHandler() {}
// Cancels all pending requests.
virtual void Reset() = 0;
// Starts getting available printers.
// |callback| should be called in the response to the request.
virtual void StartGetPrinters(const GetPrintersCallback& callback) = 0;
// Starts getting printing capability of the printer with the provided
// destination ID.
// |callback| should be called in the response to the request.
virtual void StartGetCapability(const std::string& destination_id,
const GetCapabilityCallback& callback) = 0;
// Starts granting access to the given provisional printer. The print handler
// will respond with more information about the printer including its non-
// provisional printer id.
// |callback| should be called in response to the request.
virtual void StartGrantPrinterAccess(
const std::string& printer_id,
const GetPrinterInfoCallback& callback) = 0;
// Starts a print request.
// |destination_id|: The printer to which print job should be sent.
// |capability|: Capability reported by the printer.
// |job_title|: The title used for print job.
// |ticket_json|: The print job ticket as JSON string.
// |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,
const base::string16& job_title,
const std::string& ticket_json,
const gfx::Size& page_size,
const scoped_refptr<base::RefCountedMemory>& print_data,
const PrintCallback& callback) = 0;
};
#endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINTER_HANDLER_H_
|