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_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_
6 #define EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_
10 #include "base/macros.h"
11 #include "base/observer_list.h"
12 #include "extensions/browser/api/printer_provider_internal/printer_provider_internal_api_observer.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/extension_function.h"
15 #include "extensions/common/api/printer_provider_internal.h"
18 class DictionaryValue
;
27 namespace extensions
{
31 namespace extensions
{
33 // Internal API instance. Primarily used to enable observers to watch for when
34 // printerProviderInternal API functions are called.
35 class PrinterProviderInternalAPI
: public BrowserContextKeyedAPI
{
37 static BrowserContextKeyedAPIFactory
<PrinterProviderInternalAPI
>*
40 explicit PrinterProviderInternalAPI(content::BrowserContext
* browser_context
);
41 ~PrinterProviderInternalAPI() override
;
43 void AddObserver(PrinterProviderInternalAPIObserver
* observer
);
44 void RemoveObserver(PrinterProviderInternalAPIObserver
* observer
);
47 friend class BrowserContextKeyedAPIFactory
<PrinterProviderInternalAPI
>;
48 friend class PrinterProviderInternalReportPrintersFunction
;
49 friend class PrinterProviderInternalReportPrinterCapabilityFunction
;
50 friend class PrinterProviderInternalReportPrintResultFunction
;
51 friend class PrinterProviderInternalReportUsbPrinterInfoFunction
;
53 // BrowserContextKeyedAPI implementation.
54 static const bool kServiceRedirectedInIncognito
= true;
55 static const char* service_name() { return "PrinterProviderInternal"; }
57 // Notifies observers that a printerProvider.onGetPrintersRequested callback
58 // has been called. Called from
59 // |PrinterProviderInternalReportPrintersFunction|.
60 void NotifyGetPrintersResult(
61 const Extension
* extension
,
63 const PrinterProviderInternalAPIObserver::PrinterInfoVector
& printers
);
65 // Notifies observers that a printerProvider.onGetCapabilityRequested callback
66 // has been called. Called from
67 // |PrinterProviderInternalReportPrinterCapabilityFunction|.
68 void NotifyGetCapabilityResult(const Extension
* extension
,
70 const base::DictionaryValue
& capability
);
72 // Notifies observers that a printerProvider.onPrintRequested callback has
73 // been called. Called from
74 // |PrinterProviderInternalReportPrintResultFunction|.
75 void NotifyPrintResult(const Extension
* extension
,
77 core_api::printer_provider_internal::PrintError error
);
79 // Notifies observers that a printerProvider.onGetUsbPrinterInfoRequested
80 // callback has been called. Called from
81 // |PrinterProviderInternalReportUsbPrinterInfoFunction|.
82 void NotifyGetUsbPrinterInfoResult(
83 const Extension
* extension
,
85 const core_api::printer_provider::PrinterInfo
* printer_info
);
87 base::ObserverList
<PrinterProviderInternalAPIObserver
> observers_
;
89 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalAPI
);
92 class PrinterProviderInternalReportPrintResultFunction
93 : public UIThreadExtensionFunction
{
95 PrinterProviderInternalReportPrintResultFunction();
98 ~PrinterProviderInternalReportPrintResultFunction() override
;
100 ExtensionFunction::ResponseAction
Run() override
;
103 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrintResult",
104 PRINTERPROVIDERINTERNAL_REPORTPRINTRESULT
)
106 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintResultFunction
);
109 class PrinterProviderInternalReportPrinterCapabilityFunction
110 : public UIThreadExtensionFunction
{
112 PrinterProviderInternalReportPrinterCapabilityFunction();
115 ~PrinterProviderInternalReportPrinterCapabilityFunction() override
;
117 ExtensionFunction::ResponseAction
Run() override
;
120 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinterCapability",
121 PRINTERPROVIDERINTERNAL_REPORTPRINTERCAPABILITY
)
123 DISALLOW_COPY_AND_ASSIGN(
124 PrinterProviderInternalReportPrinterCapabilityFunction
);
127 class PrinterProviderInternalReportPrintersFunction
128 : public UIThreadExtensionFunction
{
130 PrinterProviderInternalReportPrintersFunction();
133 ~PrinterProviderInternalReportPrintersFunction() override
;
134 ExtensionFunction::ResponseAction
Run() override
;
137 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinters",
138 PRINTERPROVIDERINTERNAL_REPORTPRINTERS
)
140 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintersFunction
);
143 class PrinterProviderInternalGetPrintDataFunction
144 : public UIThreadExtensionFunction
{
146 PrinterProviderInternalGetPrintDataFunction();
149 ~PrinterProviderInternalGetPrintDataFunction() override
;
150 ExtensionFunction::ResponseAction
Run() override
;
153 void OnBlob(const std::string
& type
,
155 const scoped_refptr
<base::RefCountedMemory
>& data
,
156 scoped_ptr
<content::BlobHandle
> blob
);
157 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.getPrintData",
158 PRINTERPROVIDERINTERNAL_GETPRINTDATA
)
160 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalGetPrintDataFunction
);
163 class PrinterProviderInternalReportUsbPrinterInfoFunction
164 : public UIThreadExtensionFunction
{
166 PrinterProviderInternalReportUsbPrinterInfoFunction();
169 ~PrinterProviderInternalReportUsbPrinterInfoFunction() override
;
170 ExtensionFunction::ResponseAction
Run() override
;
173 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportUsbPrinterInfo",
174 PRINTERPROVIDERINTERNAL_REPORTUSBPRINTERINFO
)
176 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportUsbPrinterInfoFunction
);
179 } // namespace extensions
181 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_