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

Unified Diff: chrome/browser/resources/print_preview/data/local_parsers.js

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, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/data/local_parsers.js
diff --git a/chrome/browser/resources/print_preview/data/local_parsers.js b/chrome/browser/resources/print_preview/data/local_parsers.js
index c15fb59349086dfe0c30aa3f586b468b7a495386..04a5c0ebddb0e587a7c0f1b7e87482647a3dcd4d 100644
--- a/chrome/browser/resources/print_preview/data/local_parsers.js
+++ b/chrome/browser/resources/print_preview/data/local_parsers.js
@@ -66,9 +66,69 @@ cr.define('print_preview', function() {
return returnedPrinters;
};
+ function ExtensionDestinationParser() {}
+
+ /**
+ * Separator used to separate extension and printer ID when generating an
+ * extension destination ID.
+ * @type {string}
+ * @private
+ */
+ ExtensionDestinationParser.ID_SEPARATOR_ = ':';
+
+ /**
+ * Given an extension ID and a printer ID in the extension's namespace, it
+ * generates a destination ID for an extension managed printer.
+ * @param {string} extensionID The ID of the extension that manages the
+ * printer.
+ * @param {string} printerID The ID of the printer reported by the extension.
+ * @return {string} The generated extension destination ID.
+ */
+ ExtensionDestinationParser.generateDestinationID = function(extensionID,
Aleksey Shlyapnikov 2015/02/03 20:18:24 generateDestinationId
tbarzic 2015/02/04 02:21:23 removed
+ printerID) {
+ return [extensionID, printerID].join(
+ ExtensionDestinationParser.ID_SEPARATOR_);
+ };
+
+ /**
+ * Parses an extension destination ID.
+ * @param {string} destinationID The destination ID that should be parsed.
+ * @return {!{extensionID: string, printerID: string}} The parsed extension
+ * and printer IDs.
+ */
+ ExtensionDestinationParser.parseDestinationID = function(destinationID) {
Aleksey Shlyapnikov 2015/02/03 20:18:24 parseDestinationId
tbarzic 2015/02/04 02:21:23 removed
+ var splitID = destinationID.split(ExtensionDestinationParser.ID_SEPARATOR_);
Aleksey Shlyapnikov 2015/02/03 20:18:24 splitId
tbarzic 2015/02/04 02:21:23 removed
+ var extensionId = splitID[0];
+ splitID.shift();
+ return {
+ extensionID: extensionId,
+ printerID: splitID.join(ExtensionDestinationParser.ID_SEPARATOR_)
+ };
+ };
Aleksey Shlyapnikov 2015/02/03 20:18:24 I've read your discussion about gluing/parsing the
tbarzic 2015/02/04 02:21:23 OK sounds good; Done
+
+ /**
+ * Parses an extension destination from an extension supplied printer
+ * description.
+ * @param {!Object} destinationInfo Object describing an extension printer.
+ * @return {!print_preview.Destination} Parsed destination.
+ */
+ ExtensionDestinationParser.parse = function(destinationInfo) {
+ return new print_preview.Destination(
+ ExtensionDestinationParser.generateDestinationID(
+ destinationInfo.extensionId, destinationInfo.id),
+ print_preview.Destination.Type.LOCAL,
+ print_preview.Destination.Origin.EXTENSION,
+ destinationInfo.name,
+ false /* isRecent */,
+ print_preview.Destination.ConnectionStatus.ONLINE,
+ {description: destinationInfo.description || '',
+ extensionID: destinationInfo.extensionId});
Aleksey Shlyapnikov 2015/02/03 20:18:24 extensionId Anyway, please change all ...ID ident
tbarzic 2015/02/04 02:21:23 Done.
+ };
+
// Export
return {
LocalDestinationParser: LocalDestinationParser,
- PrivetDestinationParser: PrivetDestinationParser
+ PrivetDestinationParser: PrivetDestinationParser,
+ ExtensionDestinationParser: ExtensionDestinationParser
};
});

Powered by Google App Engine
This is Rietveld 408576698