Chromium Code Reviews| Index: chrome/browser/resources/print_preview/data/cloud_parsers.js |
| diff --git a/chrome/browser/resources/print_preview/data/cloud_parsers.js b/chrome/browser/resources/print_preview/data/cloud_parsers.js |
| index 965e8812c5634b811bd46a9fbe94e15971481754..b61251282deca2649cdf4442c2040b8bd37ed716 100644 |
| --- a/chrome/browser/resources/print_preview/data/cloud_parsers.js |
| +++ b/chrome/browser/resources/print_preview/data/cloud_parsers.js |
| @@ -18,17 +18,27 @@ cr.define('cloudprint', function() { |
| DISPLAY_NAME: 'displayName', |
| FORMAT: 'capsFormat', |
| ID: 'id', |
| - TAGS: 'tags' |
| + TAGS: 'tags', |
| + TYPE: 'type' |
| }; |
| /** |
| * Special tag that denotes whether the destination has been recently used. |
| * @type {string} |
| + * @const |
| * @private |
| */ |
| CloudDestinationParser.RECENT_TAG_ = '^recent'; |
| /** |
| + * Special tag that denotes whether the destination is owned by the user. |
| + * @type {string} |
| + * @const |
| + * @private |
| + */ |
| + CloudDestinationParser.OWNED_TAG_ = '^own'; |
| + |
| + /** |
| * Parses a destination from JSON from a Google Cloud Print search or printer |
| * response. |
| * @param {object} json Object that represents a Google Cloud Print search or |
|
dpapad
2012/05/25 16:18:03
Nit: Should this be !Object?
Robert Toscano
2012/05/25 19:47:01
Done.
|
| @@ -37,18 +47,21 @@ cr.define('cloudprint', function() { |
| */ |
| CloudDestinationParser.parse = function(json) { |
| if (!json.hasOwnProperty(CloudDestinationParser.Field_.ID) || |
| + !json.hasOwnProperty(CloudDestinationParser.Field_.TYPE) || |
| !json.hasOwnProperty(CloudDestinationParser.Field_.DISPLAY_NAME)) { |
| throw Error('Cloud destination does not have an ID or a display name'); |
| } |
| - var isRecent = arrayContains( |
| - json[CloudDestinationParser.Field_.TAGS] || [], |
| - CloudDestinationParser.RECENT_TAG_); |
| + var tags = json[CloudDestinationParser.Field_.TAGS] || []; |
| + var isRecent = arrayContains(tags, CloudDestinationParser.RECENT_TAG_); |
| + var isOwned = arrayContains(tags, CloudDestinationParser.OWNED_TAG_); |
| var cloudDest = new print_preview.Destination( |
| json[CloudDestinationParser.Field_.ID], |
| + CloudDestinationParser.parseType_( |
| + json[CloudDestinationParser.Field_.TYPE]), |
| json[CloudDestinationParser.Field_.DISPLAY_NAME], |
| isRecent, |
| - false /*isLocal*/, |
| - json[CloudDestinationParser.Field_.TAGS] || []); |
| + tags, |
| + isOwned); |
| if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES) && |
| json.hasOwnProperty(CloudDestinationParser.Field_.FORMAT)) { |
| cloudDest.capabilities = CloudCapabilitiesParser.parse( |
| @@ -59,6 +72,24 @@ cr.define('cloudprint', function() { |
| }; |
| /** |
| + * Parses the destination type. |
| + * @param {string} typeStr Destination type given by the Google Cloud Print |
| + * server. |
| + * @return {print_preview.Destination.Type} Destination type. |
| + * @private |
| + */ |
| + CloudDestinationParser.parseType_ = function(typeStr) { |
| + if (typeStr == 'ANDROID_CHROME_SNAPSHOT' || |
|
dpapad
2012/05/25 16:18:03
Nit: Maybe define an enum somewhere instead of usi
Robert Toscano
2012/05/25 19:47:01
Done.
|
| + typeStr == 'IOS_CHROME_SNAPSHOT') { |
| + return print_preview.Destination.Type.MOBILE; |
| + } else if (typeStr == 'DOCS') { |
| + return print_preview.Destination.Type.GOOGLE_PROMOTED; |
| + } else { |
| + return print_preview.Destination.Type.GOOGLE; |
| + } |
| + }; |
| + |
| + /** |
| * Namespace which contains a method to parse a cloud destination's print |
| * capabilities. |
| */ |