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, |
+ 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) { |
+ var splitID = destinationID.split(ExtensionDestinationParser.ID_SEPARATOR_); |
+ var extensionId = splitID[0]; |
+ splitID.shift(); |
+ return { |
+ extensionID: extensionId, |
+ printerID: splitID.join(ExtensionDestinationParser.ID_SEPARATOR_) |
+ }; |
+ }; |
+ |
+ /** |
+ * 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}); |
+ }; |
+ |
// Export |
return { |
LocalDestinationParser: LocalDestinationParser, |
- PrivetDestinationParser: PrivetDestinationParser |
+ PrivetDestinationParser: PrivetDestinationParser, |
+ ExtensionDestinationParser: ExtensionDestinationParser |
}; |
}); |