Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / print_preview / extension_printer_handler.h
blob76e707b125b5ad9cea9ce3ab668bf1943272459d
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_EXTENSION_PRINTER_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_
8 #include <string>
9 #include <vector>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "chrome/browser/ui/webui/print_preview/printer_handler.h"
16 #include "extensions/browser/api/printer_provider/printer_provider_api.h"
18 namespace base {
19 class DictionaryValue;
20 class ListValue;
21 class RefCountedMemory;
22 class TaskRunner;
25 namespace content {
26 class BrowserContext;
29 namespace cloud_devices {
30 class CloudDeviceDescription;
33 namespace device {
34 class UsbDevice;
37 namespace gfx {
38 class Size;
41 namespace local_discovery {
42 class PWGRasterConverter;
45 // Implementation of PrinterHandler interface backed by printerProvider
46 // extension API.
47 class ExtensionPrinterHandler : public PrinterHandler {
48 public:
49 using PrintJobCallback =
50 base::Callback<void(scoped_ptr<extensions::PrinterProviderPrintJob>)>;
52 ExtensionPrinterHandler(
53 content::BrowserContext* browser_context,
54 const scoped_refptr<base::TaskRunner>& slow_task_runner);
56 ~ExtensionPrinterHandler() override;
58 // PrinterHandler implementation:
59 void Reset() override;
60 void StartGetPrinters(
61 const PrinterHandler::GetPrintersCallback& callback) override;
62 void StartGetCapability(
63 const std::string& destination_id,
64 const PrinterHandler::GetCapabilityCallback& calback) override;
65 // TODO(tbarzic): It might make sense to have the strings in a single struct.
66 void StartPrint(const std::string& destination_id,
67 const std::string& capability,
68 const base::string16& job_title,
69 const std::string& ticket_json,
70 const gfx::Size& page_size,
71 const scoped_refptr<base::RefCountedMemory>& print_data,
72 const PrinterHandler::PrintCallback& callback) override;
73 void StartGrantPrinterAccess(
74 const std::string& printer_id,
75 const PrinterHandler::GetPrinterInfoCallback& callback) override;
77 private:
78 friend class ExtensionPrinterHandlerTest;
80 void SetPwgRasterConverterForTesting(
81 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter);
83 // Converts |data| to PWG raster format (from PDF) for a printer described
84 // by |printer_description|.
85 // |callback| is called with the converted data.
86 void ConvertToPWGRaster(
87 const scoped_refptr<base::RefCountedMemory>& data,
88 const cloud_devices::CloudDeviceDescription& printer_description,
89 const cloud_devices::CloudDeviceDescription& ticket,
90 const gfx::Size& page_size,
91 scoped_ptr<extensions::PrinterProviderPrintJob> job,
92 const PrintJobCallback& callback);
94 // Sets print job document data and dispatches it using printerProvider API.
95 void DispatchPrintJob(
96 const PrinterHandler::PrintCallback& callback,
97 scoped_ptr<extensions::PrinterProviderPrintJob> print_job);
99 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI
100 // methods, primarily so the callbacks can be bound to this class' weak ptr.
101 // They just propagate results to callbacks passed to them.
102 void WrapGetPrintersCallback(
103 const PrinterHandler::GetPrintersCallback& callback,
104 const base::ListValue& printers,
105 bool done);
106 void WrapGetCapabilityCallback(
107 const PrinterHandler::GetCapabilityCallback& callback,
108 const std::string& destination_id,
109 const base::DictionaryValue& capability);
110 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback,
111 bool success,
112 const std::string& status);
113 void WrapGetPrinterInfoCallback(const GetPrinterInfoCallback& callback,
114 const base::DictionaryValue& printer_info);
116 void OnUsbDevicesEnumerated(
117 const PrinterHandler::GetPrintersCallback& callback,
118 const std::vector<scoped_refptr<device::UsbDevice>>& devices);
120 content::BrowserContext* browser_context_;
122 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_;
123 int pending_enumeration_count_ = 0;
125 scoped_refptr<base::TaskRunner> slow_task_runner_;
127 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_;
129 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler);
132 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_