| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b68ae1284fcc46e0ff1433001687c07a7bfd15e0
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/print_preview/data/cloud_parsers.js
|
| @@ -0,0 +1,81 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +cr.define('cloudprint', function() {
|
| + 'use strict';
|
| +
|
| + function CloudDestinationParser() {};
|
| +
|
| + /**
|
| + * Enumeration of cloud destination field names.
|
| + * @enum {string}
|
| + * @private
|
| + */
|
| + CloudDestinationParser.Field_ = {
|
| + CAPABILITIES: 'capabilities',
|
| + DISPLAY_NAME: 'displayName',
|
| + ID: 'id',
|
| + TAGS: 'tags'
|
| + };
|
| +
|
| + /**
|
| + * Special tag that denotes whether the destination has been recently used.
|
| + * @type {string}
|
| + * @private
|
| + */
|
| + CloudDestinationParser.RECENT_TAG_ = '^recent';
|
| +
|
| + /**
|
| + * Parses a destination from JSON from a Google Cloud Print search or printer
|
| + * response.
|
| + * @return {!print_preview.Destination} Parsed destination.
|
| + */
|
| + CloudDestinationParser.parse = function(json) {
|
| + // TODO Error handling.
|
| + var isRecent = arrayContains(
|
| + json[CloudDestinationParser.Field_.TAGS],
|
| + CloudDestinationParser.RECENT_TAG_);
|
| + var cloudDest = new print_preview.Destination(
|
| + json[CloudDestinationParser.Field_.ID],
|
| + json[CloudDestinationParser.Field_.DISPLAY_NAME],
|
| + isRecent,
|
| + false /*isLocal*/,
|
| + json[CloudDestinationParser.Field_.TAGS]);
|
| + if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES)) {
|
| + cloudDest.capabilities = CloudCapabilitiesParser.parse(
|
| + json[CloudDestinationParser.Field_.CAPABILITIES]);
|
| + }
|
| + return cloudDest;
|
| + };
|
| +
|
| + function CloudCapabilitiesParser() {};
|
| +
|
| + CloudCapabilitiesParser.parse = function(json) {
|
| + var caps = new print_preview.ChromiumCapabilities();
|
| + caps.hasPageRangeCapability = true;
|
| + caps.defaultPageRangeStr = '';
|
| + caps.hasCopiesCapability = false; // TODO
|
| + caps.defaultCopiesStr = '1';
|
| + caps.hasCollateCapability = false; // TODO
|
| + caps.defaultIsCollateEnabled = false;
|
| + caps.hasDuplexCapability = false; // TODO
|
| + caps.defaultIsDuplexEnabled = false;
|
| + caps.hasOrientationCapability = true; // TODO
|
| + caps.defaultIsLandscapeEnabled = false;
|
| + caps.hasColorCapability = false; // TODO
|
| + caps.defaultIsColorEnabled = false;
|
| + caps.hasMarginsCapability = true;
|
| + caps.defaultMarginType = print_preview.Margins.Type.DEFAULT;
|
| + caps.hasHeaderFooterCapability = true;
|
| + caps.defaultIsHeaderFooterEnabled = true;
|
| + return caps;
|
| + };
|
| +
|
| + // Export
|
| + return {
|
| + CloudCapabilitiesParser: CloudCapabilitiesParser,
|
| + CloudDestinationParser: CloudDestinationParser
|
| + };
|
| +});
|
| +
|
|
|