OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ |
6 #define EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ | 6 #define EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "components/keyed_service/core/keyed_service.h" | 11 #include "components/keyed_service/core/keyed_service.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class DictionaryValue; | 14 class DictionaryValue; |
15 class ListValue; | 15 class ListValue; |
16 } | 16 } |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class BrowserContext; | 19 class BrowserContext; |
20 } | 20 } |
21 | 21 |
22 namespace extensions { | 22 namespace extensions { |
| 23 class Extension; |
23 struct PrinterProviderPrintJob; | 24 struct PrinterProviderPrintJob; |
24 } | 25 } |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
27 | 28 |
28 // Implements chrome.printerProvider API events. | 29 // Implements chrome.printerProvider API events. |
29 class PrinterProviderAPI : public KeyedService { | 30 class PrinterProviderAPI : public KeyedService { |
30 public: | 31 public: |
31 using GetPrintersCallback = | 32 using GetPrintersCallback = |
32 base::Callback<void(const base::ListValue& printers, bool done)>; | 33 base::Callback<void(const base::ListValue& printers, bool done)>; |
33 using GetCapabilityCallback = | 34 using GetCapabilityCallback = |
34 base::Callback<void(const base::DictionaryValue& capability)>; | 35 base::Callback<void(const base::DictionaryValue& capability)>; |
35 using PrintCallback = | 36 using PrintCallback = |
36 base::Callback<void(bool success, const std::string& error)>; | 37 base::Callback<void(bool success, const std::string& error)>; |
37 | 38 |
38 static PrinterProviderAPI* Create(content::BrowserContext* context); | 39 static PrinterProviderAPI* Create(content::BrowserContext* context); |
39 | 40 |
40 // Returns generic error string for print request. | 41 // Returns generic error string for print request. |
41 static std::string GetDefaultPrintError(); | 42 static std::string GetDefaultPrintError(); |
42 | 43 |
43 // The API currently cannot handle very large files, so the document size that | |
44 // may be sent to an extension is restricted. | |
45 // TODO(tbarzic): Fix the API to support huge documents. | |
46 static const int kMaxDocumentSize = 50 * 1000 * 1000; | |
47 | |
48 ~PrinterProviderAPI() override {} | 44 ~PrinterProviderAPI() override {} |
49 | 45 |
50 virtual void DispatchGetPrintersRequested( | 46 virtual void DispatchGetPrintersRequested( |
51 const GetPrintersCallback& callback) = 0; | 47 const GetPrintersCallback& callback) = 0; |
52 | 48 |
53 // Requests printer capability for a printer with id |printer_id|. | 49 // Requests printer capability for a printer with id |printer_id|. |
54 // |printer_id| should be one of the printer ids reported by |GetPrinters| | 50 // |printer_id| should be one of the printer ids reported by |GetPrinters| |
55 // callback. | 51 // callback. |
56 // It dispatches chrome.printerProvider.onGetCapabilityRequested event | 52 // It dispatches chrome.printerProvider.onGetCapabilityRequested event |
57 // to the extension that manages the printer (which can be determined from | 53 // to the extension that manages the printer (which can be determined from |
58 // |printer_id| value). | 54 // |printer_id| value). |
59 // |callback| is passed a dictionary value containing printer capabilities as | 55 // |callback| is passed a dictionary value containing printer capabilities as |
60 // reported by the extension. | 56 // reported by the extension. |
61 virtual void DispatchGetCapabilityRequested( | 57 virtual void DispatchGetCapabilityRequested( |
62 const std::string& printer_id, | 58 const std::string& printer_id, |
63 const GetCapabilityCallback& callback) = 0; | 59 const GetCapabilityCallback& callback) = 0; |
64 | 60 |
65 // It dispatches chrome.printerProvider.onPrintRequested event with the | 61 // It dispatches chrome.printerProvider.onPrintRequested event with the |
66 // provided print job. The event is dispatched only to the extension that | 62 // provided print job. The event is dispatched only to the extension that |
67 // manages printer with id |job.printer_id|. | 63 // manages printer with id |job.printer_id|. |
68 // |callback| is passed the print status returned by the extension, and it | 64 // |callback| is passed the print status returned by the extension, and it |
69 // must not be null. | 65 // must not be null. |
70 virtual void DispatchPrintRequested(const PrinterProviderPrintJob& job, | 66 virtual void DispatchPrintRequested(const PrinterProviderPrintJob& job, |
71 const PrintCallback& callback) = 0; | 67 const PrintCallback& callback) = 0; |
| 68 |
| 69 // Returns print job associated with the print request with id |request_id| |
| 70 // for extension |extension|. |
| 71 // It should return NULL if the job for the request does not exist. |
| 72 virtual const PrinterProviderPrintJob* GetPrintJob(const Extension* extension, |
| 73 int request_id) const = 0; |
72 }; | 74 }; |
73 | 75 |
74 } // namespace extensions | 76 } // namespace extensions |
75 | 77 |
76 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ | 78 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ |
OLD | NEW |