Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: chrome/browser/ui/webui/print_preview/extension_printer_handler.h

Issue 919213002: Handle an extension printer supporting only PWG raster data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix a comment Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/print_preview/extension_printer_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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& page_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 std::string& ticket,
72 const gfx::Size& page_size,
73 const RefCountedMemoryCallback& callback);
74
75 // Sets print job document data and dispatches it using printerProvider API.
76 // TODO(tbarzic): Move PrinterProvider::PrintJob to it's own file so it can
77 // be forward-declared.
78 void DispatchPrintJob(
79 const PrinterHandler::PrintCallback& callback,
80 scoped_ptr<extensions::PrinterProviderAPI::PrintJob> print_job,
81 const scoped_refptr<base::RefCountedMemory>& data);
82
48 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI 83 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI
49 // methods, primarily so the callbacks can be bound to this class' weak ptr. 84 // methods, primarily so the callbacks can be bound to this class' weak ptr.
50 // They just propagate results to callbacks passed to them. 85 // They just propagate results to callbacks passed to them.
51 void WrapGetPrintersCallback( 86 void WrapGetPrintersCallback(
52 const PrinterHandler::GetPrintersCallback& callback, 87 const PrinterHandler::GetPrintersCallback& callback,
53 const base::ListValue& pritners, 88 const base::ListValue& pritners,
54 bool done); 89 bool done);
55 void WrapGetCapabilityCallback( 90 void WrapGetCapabilityCallback(
56 const PrinterHandler::GetCapabilityCallback& callback, 91 const PrinterHandler::GetCapabilityCallback& callback,
57 const std::string& destination_id, 92 const std::string& destination_id,
58 const base::DictionaryValue& capability); 93 const base::DictionaryValue& capability);
59 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, 94 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback,
60 bool success, 95 bool success,
61 const std::string& status); 96 const std::string& status);
62 97
63 content::BrowserContext* browser_context_; 98 content::BrowserContext* browser_context_;
64 99
100 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_;
101
65 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; 102 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_;
66 103
67 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); 104 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler);
68 }; 105 };
69 106
70 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ 107 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/print_preview/extension_printer_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698