Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / extensions / browser / api / printer_provider / printer_provider_api.h
blob2112a76be2742c9047aede078fc494f4de35c975
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 EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_
6 #define EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "base/memory/ref_counted.h"
12 #include "components/keyed_service/core/keyed_service.h"
14 namespace base {
15 class DictionaryValue;
16 class ListValue;
19 namespace content {
20 class BrowserContext;
23 namespace device {
24 class UsbDevice;
27 namespace extensions {
28 class Extension;
29 struct PrinterProviderPrintJob;
32 namespace extensions {
34 // Implements chrome.printerProvider API events.
35 class PrinterProviderAPI : public KeyedService {
36 public:
37 using GetPrintersCallback =
38 base::Callback<void(const base::ListValue& printers, bool done)>;
39 using GetCapabilityCallback =
40 base::Callback<void(const base::DictionaryValue& capability)>;
41 using PrintCallback =
42 base::Callback<void(bool success, const std::string& error)>;
43 using GetPrinterInfoCallback =
44 base::Callback<void(const base::DictionaryValue& printer_info)>;
46 static PrinterProviderAPI* Create(content::BrowserContext* context);
48 // Returns generic error string for print request.
49 static std::string GetDefaultPrintError();
51 ~PrinterProviderAPI() override {}
53 // Requests list of supported printers from extensions implementing
54 // chrome.printerProvider API. It dispatches
55 // chrome.printerProvider.onGetPrintersRequested event. The callback is
56 // called once for every extension handling the event with a list of its
57 // supported printers. The printer values reported by an extension are
58 // added "extensionId" property that is set to the ID of the extension
59 // returning the list and "extensionName" property set to the extension's
60 // name.
61 // Note that the "id" property of printer values reported by an extension are
62 // rewriten as "<extension_id>:<id>" to ensure they are unique across
63 // different extensions.
64 virtual void DispatchGetPrintersRequested(
65 const GetPrintersCallback& callback) = 0;
67 // Requests printer capability for a printer with id |printer_id|.
68 // |printer_id| should be one of the printer ids reported by |GetPrinters|
69 // callback.
70 // It dispatches chrome.printerProvider.onGetCapabilityRequested event
71 // to the extension that manages the printer (which can be determined from
72 // |printer_id| value).
73 // |callback| is passed a dictionary value containing printer capabilities as
74 // reported by the extension.
75 virtual void DispatchGetCapabilityRequested(
76 const std::string& printer_id,
77 const GetCapabilityCallback& callback) = 0;
79 // It dispatches chrome.printerProvider.onPrintRequested event with the
80 // provided print job. The event is dispatched only to the extension that
81 // manages printer with id |job.printer_id|.
82 // |callback| is passed the print status returned by the extension, and it
83 // must not be null.
84 virtual void DispatchPrintRequested(const PrinterProviderPrintJob& job,
85 const PrintCallback& callback) = 0;
87 // Returns print job associated with the print request with id |request_id|
88 // for extension |extension|.
89 // It should return NULL if the job for the request does not exist.
90 virtual const PrinterProviderPrintJob* GetPrintJob(const Extension* extension,
91 int request_id) const = 0;
93 // Dispatches a chrome.printerProvider.getUsbPrinterInfo event requesting
94 // information about |device_id|. The event is only dispatched to the
95 // extension identified by |extension_id|.
96 virtual void DispatchGetUsbPrinterInfoRequested(
97 const std::string& extension_id,
98 scoped_refptr<device::UsbDevice> device,
99 const PrinterProviderAPI::GetPrinterInfoCallback& callback) = 0;
102 } // namespace extensions
104 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_