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 #include "chrome/browser/ui/webui/print_preview/extension_printer_handler.h"
8 #include "base/callback.h"
9 #include "base/values.h"
10 #include "extensions/browser/api/printer_provider/printer_provider_api.h"
12 ExtensionPrinterHandler::ExtensionPrinterHandler(
13 content::BrowserContext
* browser_context
)
14 : browser_context_(browser_context
), weak_ptr_factory_(this) {
17 ExtensionPrinterHandler::~ExtensionPrinterHandler() {
20 void ExtensionPrinterHandler::Reset() {
21 // TODO(tbarzic): Keep track of pending request ids issued by |this| and
22 // cancel them from here.
23 weak_ptr_factory_
.InvalidateWeakPtrs();
26 void ExtensionPrinterHandler::StartGetPrinters(
27 const PrinterHandler::GetPrintersCallback
& callback
) {
28 extensions::PrinterProviderAPI::GetFactoryInstance()
29 ->Get(browser_context_
)
30 ->DispatchGetPrintersRequested(
31 base::Bind(&ExtensionPrinterHandler::WrapGetPrintersCallback
,
32 weak_ptr_factory_
.GetWeakPtr(), callback
));
35 void ExtensionPrinterHandler::StartGetCapability(
36 const std::string
& destination_id
,
37 const PrinterHandler::GetCapabilityCallback
& callback
) {
38 extensions::PrinterProviderAPI::GetFactoryInstance()
39 ->Get(browser_context_
)
40 ->DispatchGetCapabilityRequested(
42 base::Bind(&ExtensionPrinterHandler::WrapGetCapabilityCallback
,
43 weak_ptr_factory_
.GetWeakPtr(), callback
, destination_id
));
46 void ExtensionPrinterHandler::StartPrint(
47 const base::DictionaryValue
& print_job_settings
,
48 const scoped_refptr
<base::RefCountedMemory
>& print_data
,
49 const PrinterHandler::PrintCallback
& callback
) {
50 // TODO(tbarzic): Implement this.
51 WrapPrintCallback(callback
, false, "NOT_IMPLEMENTED");
54 void ExtensionPrinterHandler::WrapGetPrintersCallback(
55 const PrinterHandler::GetPrintersCallback
& callback
,
56 const base::ListValue
& printers
,
58 callback
.Run(printers
, done
);
61 void ExtensionPrinterHandler::WrapGetCapabilityCallback(
62 const PrinterHandler::GetCapabilityCallback
& callback
,
63 const std::string
& destination_id
,
64 const base::DictionaryValue
& capability
) {
65 callback
.Run(destination_id
, capability
);
68 void ExtensionPrinterHandler::WrapPrintCallback(
69 const PrinterHandler::PrintCallback
& callback
,
71 const std::string
& status
) {
72 callback
.Run(success
, status
);