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_
10 #include "base/callback.h"
11 #include "components/keyed_service/core/keyed_service.h"
14 class DictionaryValue
;
22 namespace extensions
{
24 struct PrinterProviderPrintJob
;
27 namespace extensions
{
29 // Implements chrome.printerProvider API events.
30 class PrinterProviderAPI
: public KeyedService
{
32 using GetPrintersCallback
=
33 base::Callback
<void(const base::ListValue
& printers
, bool done
)>;
34 using GetCapabilityCallback
=
35 base::Callback
<void(const base::DictionaryValue
& capability
)>;
37 base::Callback
<void(bool success
, const std::string
& error
)>;
39 static PrinterProviderAPI
* Create(content::BrowserContext
* context
);
41 // Returns generic error string for print request.
42 static std::string
GetDefaultPrintError();
44 ~PrinterProviderAPI() override
{}
46 // Requests list of supported printers from extensions implementing
47 // chrome.printerProvider API. It dispatches
48 // chrome.printerProvider.onGetPrintersRequested event. The callback is
49 // called once for every extension handling the event with a list of its
50 // supported printers. The printer values reported by an extension are
51 // added "extensionId" property that is set to the ID of the extension
52 // returning the list and "extensionName" property set to the extension's
54 // Note that the "id" property of printer values reported by an extension are
55 // rewriten as "<extension_id>:<id>" to ensure they are unique across
56 // different extensions.
57 virtual void DispatchGetPrintersRequested(
58 const GetPrintersCallback
& callback
) = 0;
60 // Requests printer capability for a printer with id |printer_id|.
61 // |printer_id| should be one of the printer ids reported by |GetPrinters|
63 // It dispatches chrome.printerProvider.onGetCapabilityRequested event
64 // to the extension that manages the printer (which can be determined from
65 // |printer_id| value).
66 // |callback| is passed a dictionary value containing printer capabilities as
67 // reported by the extension.
68 virtual void DispatchGetCapabilityRequested(
69 const std::string
& printer_id
,
70 const GetCapabilityCallback
& callback
) = 0;
72 // It dispatches chrome.printerProvider.onPrintRequested event with the
73 // provided print job. The event is dispatched only to the extension that
74 // manages printer with id |job.printer_id|.
75 // |callback| is passed the print status returned by the extension, and it
77 virtual void DispatchPrintRequested(const PrinterProviderPrintJob
& job
,
78 const PrintCallback
& callback
) = 0;
80 // Returns print job associated with the print request with id |request_id|
81 // for extension |extension|.
82 // It should return NULL if the job for the request does not exist.
83 virtual const PrinterProviderPrintJob
* GetPrintJob(const Extension
* extension
,
84 int request_id
) const = 0;
87 } // namespace extensions
89 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_