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
;
52 // BrowserContextKeyedAPI implementation.
53 static const bool kServiceRedirectedInIncognito
= true;
54 static const char* service_name() { return "PrinterProviderInternal"; }
56 // Notifies observers that a printerProvider.onGetPrintersRequested callback
57 // has been called. Called from
58 // |PrinterProviderInternalReportPrintersFunction|.
59 void NotifyGetPrintersResult(
60 const Extension
* extension
,
62 const PrinterProviderInternalAPIObserver::PrinterInfoVector
& printers
);
64 // Notifies observers that a printerProvider.onGetCapabilityRequested callback
65 // has been called. Called from
66 // |PrinterProviderInternalReportPrinterCapabilityFunction|.
67 void NotifyGetCapabilityResult(const Extension
* extension
,
69 const base::DictionaryValue
& capability
);
71 // Notifies observers that a printerProvider.onPrintRequested callback has
72 // been called. Called from
73 // |PrinterProviderInternalReportPrintResultFunction|.
74 void NotifyPrintResult(const Extension
* extension
,
76 core_api::printer_provider_internal::PrintError error
);
78 ObserverList
<PrinterProviderInternalAPIObserver
> observers_
;
80 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalAPI
);
83 class PrinterProviderInternalReportPrintResultFunction
84 : public UIThreadExtensionFunction
{
86 PrinterProviderInternalReportPrintResultFunction();
89 ~PrinterProviderInternalReportPrintResultFunction() override
;
91 ExtensionFunction::ResponseAction
Run() override
;
94 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrintResult",
95 PRINTERPROVIDERINTERNAL_REPORTPRINTRESULT
)
97 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintResultFunction
);
100 class PrinterProviderInternalReportPrinterCapabilityFunction
101 : public UIThreadExtensionFunction
{
103 PrinterProviderInternalReportPrinterCapabilityFunction();
106 ~PrinterProviderInternalReportPrinterCapabilityFunction() override
;
108 ExtensionFunction::ResponseAction
Run() override
;
111 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinterCapability",
112 PRINTERPROVIDERINTERNAL_REPORTPRINTERCAPABILITY
)
114 DISALLOW_COPY_AND_ASSIGN(
115 PrinterProviderInternalReportPrinterCapabilityFunction
);
118 class PrinterProviderInternalReportPrintersFunction
119 : public UIThreadExtensionFunction
{
121 PrinterProviderInternalReportPrintersFunction();
124 ~PrinterProviderInternalReportPrintersFunction() override
;
125 ExtensionFunction::ResponseAction
Run() override
;
128 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinters",
129 PRINTERPROVIDERINTERNAL_REPORTPRINTERS
)
131 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintersFunction
);
134 class PrinterProviderInternalGetPrintDataFunction
135 : public UIThreadExtensionFunction
{
137 PrinterProviderInternalGetPrintDataFunction();
140 ~PrinterProviderInternalGetPrintDataFunction() override
;
141 ExtensionFunction::ResponseAction
Run() override
;
144 void OnBlob(const std::string
& type
,
146 const scoped_refptr
<base::RefCountedMemory
>& data
,
147 scoped_ptr
<content::BlobHandle
> blob
);
148 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.getPrintData",
149 PRINTERPROVIDERINTERNAL_GETPRINTDATA
)
151 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalGetPrintDataFunction
);
154 } // namespace extensions
156 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_