| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" | 13 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" |
| 14 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class DictionaryValue; | 17 class DictionaryValue; |
| 17 class ListValue; | 18 class ListValue; |
| 18 class RefCountedMemory; | 19 class RefCountedMemory; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 class BrowserContext; | 23 class BrowserContext; |
| 23 } | 24 } |
| 24 | 25 |
| 26 namespace cloud_devices { |
| 27 class CloudDeviceDescription; |
| 28 } |
| 29 |
| 30 namespace gfx { |
| 31 class Size; |
| 32 } |
| 33 |
| 34 namespace local_discovery { |
| 35 class PWGRasterConverter; |
| 36 } |
| 37 |
| 25 // Implementation of PrinterHandler interface backed by printerProvider | 38 // Implementation of PrinterHandler interface backed by printerProvider |
| 26 // extension API. | 39 // extension API. |
| 27 class ExtensionPrinterHandler : public PrinterHandler { | 40 class ExtensionPrinterHandler : public PrinterHandler { |
| 28 public: | 41 public: |
| 42 using RefCountedMemoryCallback = |
| 43 base::Callback<void(const scoped_refptr<base::RefCountedMemory>&)>; |
| 44 |
| 29 explicit ExtensionPrinterHandler(content::BrowserContext* browser_context); | 45 explicit ExtensionPrinterHandler(content::BrowserContext* browser_context); |
| 30 | 46 |
| 31 ~ExtensionPrinterHandler() override; | 47 ~ExtensionPrinterHandler() override; |
| 32 | 48 |
| 33 // PrinterHandler implementation: | 49 // PrinterHandler implementation: |
| 34 void Reset() override; | 50 void Reset() override; |
| 35 void StartGetPrinters( | 51 void StartGetPrinters( |
| 36 const PrinterHandler::GetPrintersCallback& callback) override; | 52 const PrinterHandler::GetPrintersCallback& callback) override; |
| 37 void StartGetCapability( | 53 void StartGetCapability( |
| 38 const std::string& destination_id, | 54 const std::string& destination_id, |
| 39 const PrinterHandler::GetCapabilityCallback& calback) override; | 55 const PrinterHandler::GetCapabilityCallback& calback) override; |
| 40 // TODO(tbarzic): It might make sense to have the strings in a single struct. | 56 // TODO(tbarzic): It might make sense to have the strings in a single struct. |
| 41 void StartPrint(const std::string& destination_id, | 57 void StartPrint(const std::string& destination_id, |
| 42 const std::string& capability, | 58 const std::string& capability, |
| 43 const std::string& ticket_json, | 59 const std::string& ticket_json, |
| 60 const gfx::Size& size, |
| 44 const scoped_refptr<base::RefCountedMemory>& print_data, | 61 const scoped_refptr<base::RefCountedMemory>& print_data, |
| 45 const PrinterHandler::PrintCallback& callback) override; | 62 const PrinterHandler::PrintCallback& callback) override; |
| 46 | 63 |
| 47 private: | 64 private: |
| 65 // Converts |data| to PWG raster format (from PDF) for a printer described |
| 66 // by |printer_description|. |
| 67 // |callback| is called with the converted data. |
| 68 void ConvertToPWGRaster( |
| 69 const scoped_refptr<base::RefCountedMemory>& data, |
| 70 const cloud_devices::CloudDeviceDescription& printer_description, |
| 71 const gfx::Size& size, |
| 72 const RefCountedMemoryCallback& callback); |
| 73 |
| 74 // Sets print job document data and dispatches it using printerProvider API. |
| 75 // TODO(tbarzic): Move PrinterProvider::PrintJob to it's own file so it can |
| 76 // be forward-declared. |
| 77 void DispatchPrintJob( |
| 78 const PrinterHandler::PrintCallback& callback, |
| 79 scoped_ptr<extensions::PrinterProviderAPI::PrintJob> print_job, |
| 80 const scoped_refptr<base::RefCountedMemory>& data); |
| 81 |
| 48 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI | 82 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI |
| 49 // methods, primarily so the callbacks can be bound to this class' weak ptr. | 83 // methods, primarily so the callbacks can be bound to this class' weak ptr. |
| 50 // They just propagate results to callbacks passed to them. | 84 // They just propagate results to callbacks passed to them. |
| 51 void WrapGetPrintersCallback( | 85 void WrapGetPrintersCallback( |
| 52 const PrinterHandler::GetPrintersCallback& callback, | 86 const PrinterHandler::GetPrintersCallback& callback, |
| 53 const base::ListValue& pritners, | 87 const base::ListValue& pritners, |
| 54 bool done); | 88 bool done); |
| 55 void WrapGetCapabilityCallback( | 89 void WrapGetCapabilityCallback( |
| 56 const PrinterHandler::GetCapabilityCallback& callback, | 90 const PrinterHandler::GetCapabilityCallback& callback, |
| 57 const std::string& destination_id, | 91 const std::string& destination_id, |
| 58 const base::DictionaryValue& capability); | 92 const base::DictionaryValue& capability); |
| 59 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, | 93 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, |
| 60 bool success, | 94 bool success, |
| 61 const std::string& status); | 95 const std::string& status); |
| 62 | 96 |
| 63 content::BrowserContext* browser_context_; | 97 content::BrowserContext* browser_context_; |
| 64 | 98 |
| 99 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_; |
| 100 |
| 65 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; | 101 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; |
| 66 | 102 |
| 67 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); | 103 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); |
| 68 }; | 104 }; |
| 69 | 105 |
| 70 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 106 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
| OLD | NEW |