Chromium Code Reviews| 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 #if defined(ENABLE_SERVICE_DISCOVERY) | |
| 35 namespace local_discovery { | |
| 36 class PWGRasterConverter; | |
| 37 } | |
| 38 #endif | |
| 39 | |
| 25 // Implementation of PrinterHandler interface backed by printerProvider | 40 // Implementation of PrinterHandler interface backed by printerProvider |
| 26 // extension API. | 41 // extension API. |
| 27 class ExtensionPrinterHandler : public PrinterHandler { | 42 class ExtensionPrinterHandler : public PrinterHandler { |
| 28 public: | 43 public: |
| 44 using RefCountedMemoryCallback = | |
| 45 base::Callback<void(const scoped_refptr<base::RefCountedMemory>&)>; | |
| 46 | |
| 29 explicit ExtensionPrinterHandler(content::BrowserContext* browser_context); | 47 explicit ExtensionPrinterHandler(content::BrowserContext* browser_context); |
| 30 | 48 |
| 31 ~ExtensionPrinterHandler() override; | 49 ~ExtensionPrinterHandler() override; |
| 32 | 50 |
| 33 // PrinterHandler implementation: | 51 // PrinterHandler implementation: |
| 34 void Reset() override; | 52 void Reset() override; |
| 35 void StartGetPrinters( | 53 void StartGetPrinters( |
| 36 const PrinterHandler::GetPrintersCallback& callback) override; | 54 const PrinterHandler::GetPrintersCallback& callback) override; |
| 37 void StartGetCapability( | 55 void StartGetCapability( |
| 38 const std::string& destination_id, | 56 const std::string& destination_id, |
| 39 const PrinterHandler::GetCapabilityCallback& calback) override; | 57 const PrinterHandler::GetCapabilityCallback& calback) override; |
| 40 // TODO(tbarzic): It might make sense to have the strings in a single struct. | 58 // TODO(tbarzic): It might make sense to have the strings in a single struct. |
| 41 void StartPrint(const std::string& destination_id, | 59 void StartPrint(const std::string& destination_id, |
| 42 const std::string& capability, | 60 const std::string& capability, |
| 43 const std::string& ticket_json, | 61 const std::string& ticket_json, |
| 62 const gfx::Size& size, | |
| 44 const scoped_refptr<base::RefCountedMemory>& print_data, | 63 const scoped_refptr<base::RefCountedMemory>& print_data, |
| 45 const PrinterHandler::PrintCallback& callback) override; | 64 const PrinterHandler::PrintCallback& callback) override; |
| 46 | 65 |
| 47 private: | 66 private: |
| 67 // Converts |data| to PWG raster format (from PDF) for a printer described | |
| 68 // by |printer_description|. | |
| 69 // |callback| is called with the converted data. | |
| 70 void ConvertToPWGRaster( | |
| 71 const scoped_refptr<base::RefCountedMemory>& data, | |
| 72 const cloud_devices::CloudDeviceDescription& printer_description, | |
| 73 const gfx::Size& size, | |
| 74 const RefCountedMemoryCallback& callback); | |
| 75 | |
| 76 // Sets print job document data and dispatches it using printerProvider API. | |
| 77 // TODO(tbarzic): Move PrinterProvider::PrintJob to it's own file so it can | |
| 78 // be forward-declared. | |
| 79 void DispatchPrintJob( | |
| 80 const PrinterHandler::PrintCallback& callback, | |
| 81 scoped_ptr<extensions::PrinterProviderAPI::PrintJob> print_job, | |
| 82 const scoped_refptr<base::RefCountedMemory>& data); | |
| 83 | |
| 48 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI | 84 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI |
| 49 // methods, primarily so the callbacks can be bound to this class' weak ptr. | 85 // methods, primarily so the callbacks can be bound to this class' weak ptr. |
| 50 // They just propagate results to callbacks passed to them. | 86 // They just propagate results to callbacks passed to them. |
| 51 void WrapGetPrintersCallback( | 87 void WrapGetPrintersCallback( |
| 52 const PrinterHandler::GetPrintersCallback& callback, | 88 const PrinterHandler::GetPrintersCallback& callback, |
| 53 const base::ListValue& pritners, | 89 const base::ListValue& pritners, |
| 54 bool done); | 90 bool done); |
| 55 void WrapGetCapabilityCallback( | 91 void WrapGetCapabilityCallback( |
| 56 const PrinterHandler::GetCapabilityCallback& callback, | 92 const PrinterHandler::GetCapabilityCallback& callback, |
| 57 const std::string& destination_id, | 93 const std::string& destination_id, |
| 58 const base::DictionaryValue& capability); | 94 const base::DictionaryValue& capability); |
| 59 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, | 95 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, |
| 60 bool success, | 96 bool success, |
| 61 const std::string& status); | 97 const std::string& status); |
| 62 | 98 |
| 63 content::BrowserContext* browser_context_; | 99 content::BrowserContext* browser_context_; |
| 64 | 100 |
| 101 #if defined(ENABLE_SERVICE_DISCOVERY) | |
|
tbarzic
2015/02/13 03:08:13
actually, looking at chrome_browser_gypi, this is
Vitaly Buka (NO REVIEWS)
2015/02/17 19:43:54
ok
| |
| 102 // TODO(tbarzic): See if local_discovery::PWGRasterConverter can be moved to a | |
| 103 // place that can be used without ifdefs. | |
| 104 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_; | |
| 105 #endif | |
| 106 | |
| 65 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; | 107 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; |
| 66 | 108 |
| 67 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); | 109 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); |
| 68 }; | 110 }; |
| 69 | 111 |
| 70 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 112 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
| OLD | NEW |