Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: extensions/browser/api/printer_provider/printer_provider_api.h

Issue 900503002: List printers managed by extensions in print preview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 PRINT_ERROR_INVALID_TICKET, 42 PRINT_ERROR_INVALID_TICKET,
43 PRINT_ERROR_INVALID_DATA 43 PRINT_ERROR_INVALID_DATA
44 }; 44 };
45 45
46 // Struct describing print job that should be forwarded to an extension via 46 // Struct describing print job that should be forwarded to an extension via
47 // chrome.printerProvider.onPrintRequested event. 47 // chrome.printerProvider.onPrintRequested event.
48 struct PrintJob { 48 struct PrintJob {
49 PrintJob(); 49 PrintJob();
50 ~PrintJob(); 50 ~PrintJob();
51 51
52 // The id of the printer that should handle the print job. This identifies 52 // The id of the printer that should handle the print job. The id is
53 // a printer within an extension and is provided by the extension via 53 // formatted as <extension_id>:<printer_id>, where <extension_id> is the
54 // chrome.printerProvider.onGetPrintersRequested event callback. 54 // id of the extension that manages the printer, and <printer_id> is
55 // the the printer's id within the extension (as reported via
56 // chrome.printerProvider.onGetPrintersRequested event callback).
55 std::string printer_id; 57 std::string printer_id;
56 58
57 // The print job ticket. 59 // The print job ticket.
58 std::string ticket_json; 60 std::string ticket_json;
59 61
60 // Content type of the document that should be printed. 62 // Content type of the document that should be printed.
61 std::string content_type; 63 std::string content_type;
62 64
63 // The document data that should be printed. 65 // The document data that should be printed.
64 std::string document_bytes; 66 std::string document_bytes;
(...skipping 11 matching lines...) Expand all
76 explicit PrinterProviderAPI(content::BrowserContext* browser_context); 78 explicit PrinterProviderAPI(content::BrowserContext* browser_context);
77 ~PrinterProviderAPI() override; 79 ~PrinterProviderAPI() override;
78 80
79 // Requests list of supported printers from extensions implementing 81 // Requests list of supported printers from extensions implementing
80 // chrome.printerProvider API. It dispatches 82 // chrome.printerProvider API. It dispatches
81 // chrome.printerProvider.onGetPrintersRequested event. The callback is 83 // chrome.printerProvider.onGetPrintersRequested event. The callback is
82 // called once for every extension handling the event with a list of its 84 // called once for every extension handling the event with a list of its
83 // supported printers. The printer values reported by an extension are 85 // supported printers. The printer values reported by an extension are
84 // added "extensionId" property that is set to the ID of the extension 86 // added "extensionId" property that is set to the ID of the extension
85 // returning the list. 87 // returning the list.
88 // Note that the "id" property of printer values reported by an extension are
89 // rewriten as "<extension_id>:<id>" to ensure they are unique across
90 // different extensions.
86 void DispatchGetPrintersRequested(const GetPrintersCallback& callback); 91 void DispatchGetPrintersRequested(const GetPrintersCallback& callback);
87 92
88 // Requests printer capability from the extension with id |extension_id| for 93 // Requests printer capability for a printer with id |printer_id|.
89 // the printer with id |printer_id|. |printer_id| should be one of the printer 94 // |printer_id| should be one of the printer ids reported by |GetPrinters|
90 // ids reported by |GetPrinters| callback. 95 // callback.
91 // It dispatches chrome.printerProvider.onGetCapabilityRequested event 96 // It dispatches chrome.printerProvider.onGetCapabilityRequested event
92 // to the extension. 97 // to the extension that manages the printer (which can be determined from
98 // |printer_id| value).
93 // |callback| is passed a dictionary value containing printer capabilities as 99 // |callback| is passed a dictionary value containing printer capabilities as
94 // reported by the extension. 100 // reported by the extension.
95 void DispatchGetCapabilityRequested(const std::string& extension_id, 101 void DispatchGetCapabilityRequested(const std::string& printer_id,
96 const std::string& printer_id,
97 const GetCapabilityCallback& callback); 102 const GetCapabilityCallback& callback);
98 103
99 // It dispatches chrome.printerProvider.onPrintRequested event to the 104 // It dispatches chrome.printerProvider.onPrintRequested event with the
100 // extension with id |extension_id| with the provided print job. 105 // provided print job. The event is dispatched only to the extension that
106 // manages printer with id |job.printer_id|.
101 // |callback| is passed the print status returned by the extension, and it 107 // |callback| is passed the print status returned by the extension, and it
102 // must not be null. 108 // must not be null.
103 void DispatchPrintRequested(const std::string& extension_id, 109 void DispatchPrintRequested(const PrintJob& job,
104 const PrintJob& job,
105 const PrintCallback& callback); 110 const PrintCallback& callback);
106 111
107 private: 112 private:
108 friend class BrowserContextKeyedAPIFactory<PrinterProviderAPI>; 113 friend class BrowserContextKeyedAPIFactory<PrinterProviderAPI>;
109 114
110 // Holds information about a pending onGetPrintersRequested request; 115 // Holds information about a pending onGetPrintersRequested request;
111 // in particular, the list of extensions to which the event was dispatched but 116 // in particular, the list of extensions to which the event was dispatched but
112 // which haven't yet responded, and the |GetPrinters| callback associated with 117 // which haven't yet responded, and the |GetPrinters| callback associated with
113 // the event. 118 // the event.
114 class GetPrintersRequest { 119 class GetPrintersRequest {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 205
201 private: 206 private:
202 int last_request_id_; 207 int last_request_id_;
203 std::map<int, PrintCallback> pending_requests_; 208 std::map<int, PrintCallback> pending_requests_;
204 }; 209 };
205 210
206 // BrowserContextKeyedAPI implementation. 211 // BrowserContextKeyedAPI implementation.
207 static const char* service_name() { return "PrinterProvider"; } 212 static const char* service_name() { return "PrinterProvider"; }
208 213
209 // PrinterProviderInternalAPIObserver implementation: 214 // PrinterProviderInternalAPIObserver implementation:
210 void OnGetPrintersResult(const Extension* extension, 215 void OnGetPrintersResult(
211 int request_id, 216 const Extension* extension,
212 const base::ListValue& result) override; 217 int request_id,
218 const PrinterProviderInternalAPIObserver::PrinterInfoVector& result)
219 override;
213 void OnGetCapabilityResult(const Extension* extension, 220 void OnGetCapabilityResult(const Extension* extension,
214 int request_id, 221 int request_id,
215 const base::DictionaryValue& result) override; 222 const base::DictionaryValue& result) override;
216 void OnPrintResult( 223 void OnPrintResult(
217 const Extension* extension, 224 const Extension* extension,
218 int request_id, 225 int request_id,
219 core_api::printer_provider_internal::PrintError error) override; 226 core_api::printer_provider_internal::PrintError error) override;
220 227
221 // Called before chrome.printerProvider.onGetPrintersRequested event is 228 // Called before chrome.printerProvider.onGetPrintersRequested event is
222 // dispatched to an extension. It returns whether the extension is interested 229 // dispatched to an extension. It returns whether the extension is interested
(...skipping 20 matching lines...) Expand all
243 DISALLOW_COPY_AND_ASSIGN(PrinterProviderAPI); 250 DISALLOW_COPY_AND_ASSIGN(PrinterProviderAPI);
244 }; 251 };
245 252
246 template <> 253 template <>
247 void BrowserContextKeyedAPIFactory< 254 void BrowserContextKeyedAPIFactory<
248 PrinterProviderAPI>::DeclareFactoryDependencies(); 255 PrinterProviderAPI>::DeclareFactoryDependencies();
249 256
250 } // namespace extensions 257 } // namespace extensions
251 258
252 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ 259 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698