diff options
author | rltoscano@google.com <rltoscano@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:22:13 +0000 |
---|---|---|
committer | rltoscano@google.com <rltoscano@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:22:13 +0000 |
commit | 58c86a7f73d4e4c771db31cbb3c611a9532a858f (patch) | |
tree | d1f517b8c4c3aeff4e54410ea6df57538f334ad7 /chrome/browser/resources/print_preview | |
parent | c97d12626e9273d595c6e75d20f70f536de86ee1 (diff) | |
download | chromium_src-58c86a7f73d4e4c771db31cbb3c611a9532a858f.zip chromium_src-58c86a7f73d4e4c771db31cbb3c611a9532a858f.tar.gz chromium_src-58c86a7f73d4e4c771db31cbb3c611a9532a858f.tar.bz2 |
Adds support for fedex printer.
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10495009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141996 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/print_preview')
10 files changed, 236 insertions, 22 deletions
diff --git a/chrome/browser/resources/print_preview/cloud_print_interface.js b/chrome/browser/resources/print_preview/cloud_print_interface.js index b29f510..a0c8758 100644 --- a/chrome/browser/resources/print_preview/cloud_print_interface.js +++ b/chrome/browser/resources/print_preview/cloud_print_interface.js @@ -79,6 +79,7 @@ cr.define('cloudprint', function() { params['q'] = '^recent'; } params['connection_status'] = 'ALL'; + params['client'] = 'chrome'; this.sendRequest_('GET', 'search', params, null, this.onSearchDone_); }, @@ -100,6 +101,23 @@ cr.define('cloudprint', function() { }, /** + * Sends a Google Cloud Print update API request to accept (or reject) the + * terms-of-service of the given printer. + * @param {string} printerId ID of the printer to accept the + * terms-of-service for. + * @param {boolean} isAccepted Whether the user accepted the + * terms-of-service. + */ + updatePrinterTosAcceptance: function(printerId, isAccepted) { + var params = { + 'printerid': printerId, + 'is_tos_accepted': isAccepted + }; + this.sendRequest_('POST', 'update', params, null, + this.onUpdatePrinterTosAcceptanceDone_); + }, + + /** * Creates an object that represents a Google Cloud Print print ticket. * @param {!print_preview.Destination} destination Destination to print to. * @param {!print_preview.PrintTicketStore} printTicketStore Used to create @@ -271,8 +289,10 @@ cr.define('cloudprint', function() { * @private */ onSubmitDone_: function(result) { - this.dispatchEvent( - new cr.Event(CloudPrintInterface.EventType.SUBMIT_DONE)); + var submitDoneEvent = new cr.Event( + CloudPrintInterface.EventType.SUBMIT_DONE); + submitDoneEvent.jobId = result['job']['id']; + this.dispatchEvent(submitDoneEvent); }, /** @@ -295,6 +315,16 @@ cr.define('cloudprint', function() { new cr.Event(CloudPrintInterface.EventType.PRINTER_DONE); printerDoneEvent.printer = printer; this.dispatchEvent(printerDoneEvent); + }, + + /** + * Called when the update printer TOS acceptance request completes + * successfully. + * @param {Object} result JSON response. + * @private + */ + onUpdatePrinterTosAcceptanceDone_: function(result) { + // Do nothing. } }; diff --git a/chrome/browser/resources/print_preview/data/cloud_parsers.js b/chrome/browser/resources/print_preview/data/cloud_parsers.js index 0893361..45f9905 100644 --- a/chrome/browser/resources/print_preview/data/cloud_parsers.js +++ b/chrome/browser/resources/print_preview/data/cloud_parsers.js @@ -20,6 +20,7 @@ cr.define('cloudprint', function() { DISPLAY_NAME: 'displayName', FORMAT: 'capsFormat', ID: 'id', + IS_TOS_ACCEPTED: 'isTosAccepted', TAGS: 'tags', TYPE: 'type' }; @@ -64,24 +65,27 @@ cr.define('cloudprint', function() { !json.hasOwnProperty(CloudDestinationParser.Field_.DISPLAY_NAME)) { throw Error('Cloud destination does not have an ID or a display name'); } + var id = json[CloudDestinationParser.Field_.ID]; var tags = json[CloudDestinationParser.Field_.TAGS] || []; - var isRecent = arrayContains(tags, CloudDestinationParser.RECENT_TAG_); - var isOwned = arrayContains(tags, CloudDestinationParser.OWNED_TAG_); var connectionStatus = json[CloudDestinationParser.Field_.CONNECTION_STATUS] || print_preview.Destination.ConnectionStatus.UNKNOWN; - var lastAccess = parseInt( - json[CloudDestinationParser.Field_.LAST_ACCESS], 10) || Date.now(); + var optionalParams = { + tags: tags, + isOwned: arrayContains(tags, CloudDestinationParser.OWNED_TAG_), + lastAccessTime: parseInt( + json[CloudDestinationParser.Field_.LAST_ACCESS], 10) || Date.now(), + isTosAccepted: (id == print_preview.Destination.GooglePromotedId.FEDEX) ? + json[CloudDestinationParser.Field_.IS_TOS_ACCEPTED] : null + }; var cloudDest = new print_preview.Destination( - json[CloudDestinationParser.Field_.ID], + id, CloudDestinationParser.parseType_( json[CloudDestinationParser.Field_.TYPE]), json[CloudDestinationParser.Field_.DISPLAY_NAME], - isRecent, + arrayContains(tags, CloudDestinationParser.RECENT_TAG_) /*isRecent*/, connectionStatus, - tags, - isOwned, - lastAccess); + optionalParams); if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES) && json.hasOwnProperty(CloudDestinationParser.Field_.FORMAT)) { cloudDest.capabilities = CloudCapabilitiesParser.parse( diff --git a/chrome/browser/resources/print_preview/data/destination.js b/chrome/browser/resources/print_preview/data/destination.js index 72089dd..bffc30c 100644 --- a/chrome/browser/resources/print_preview/data/destination.js +++ b/chrome/browser/resources/print_preview/data/destination.js @@ -14,15 +14,15 @@ cr.define('print_preview', function() { * @param {boolean} isRecent Whether the destination has been used recently. * @param {!print_preview.Destination.ConnectionStatus} connectionStatus * Connection status of the print destination. - * @param {Array.<string>=} opt_tags Tags associated with the destination. - * @param {boolean=} opt_isOwned Whether the destination is owned by the user. - * Only applies to cloud-based destinations. - * @param {number=} opt_lastAccessTime Number of milliseconds since the epoch - * when the printer was last accessed. + * @param {{tags: Array.<string>, + * isOwned: ?boolean, + * lastAccessTime: ?number, + * isTosAccepted: ?boolean}=} opt_params Optional parameters for the + * destination. * @constructor */ function Destination(id, type, displayName, isRecent, connectionStatus, - opt_tags, opt_isOwned, opt_lastAccessTime) { + opt_params) { /** * ID of the destination. * @type {string} @@ -56,7 +56,7 @@ cr.define('print_preview', function() { * @type {!Array.<string>} * @private */ - this.tags_ = opt_tags || []; + this.tags_ = (opt_params && opt_params.tags) || []; /** * Print capabilities of the destination. @@ -70,7 +70,7 @@ cr.define('print_preview', function() { * @type {boolean} * @private */ - this.isOwned_ = opt_isOwned || false; + this.isOwned_ = (opt_params && opt_params.isOwned) || false; /** * Cache of destination location fetched from tags. @@ -92,7 +92,17 @@ cr.define('print_preview', function() { * @type {number} * @private */ - this.lastAccessTime_ = opt_lastAccessTime || Date.now(); + this.lastAccessTime_ = (opt_params && opt_params.lastAccessTime) || + Date.now(); + + /** + * Whether the user has accepted the terms-of-service for the print + * destination. Only applies to the FedEx Office cloud-based printer. + * {@code} null if terms-of-service does not apply to the print destination. + * @type {?boolean} + * @private + */ + this.isTosAccepted_ = (opt_params && opt_params.isTosAccepted) || false; }; /** @@ -274,6 +284,24 @@ cr.define('print_preview', function() { }, /** + * @return {?boolean} Whether the user has accepted the terms-of-service of + * the print destination or {@code null} if a terms-of-service does not + * apply. + */ + get isTosAccepted() { + return this.isTosAccepted_; + }, + + /** + * @param {?boolean} Whether the user has accepted the terms-of-service of + * the print destination or {@code null} if a terms-of-service does not + * apply. + */ + set isTosAccepted(isTosAccepted) { + this.isTosAccepted_ = isTosAccepted; + }, + + /** * Matches a query against the destination. * @param {string} query Query to match against the destination. * @return {boolean} {@code true} if the query matches this destination, diff --git a/chrome/browser/resources/print_preview/data/destination_store.js b/chrome/browser/resources/print_preview/data/destination_store.js index 17d6d7e..9478096 100644 --- a/chrome/browser/resources/print_preview/data/destination_store.js +++ b/chrome/browser/resources/print_preview/data/destination_store.js @@ -214,6 +214,14 @@ cr.define('print_preview', function() { clearTimeout(this.autoSelectTimeout_); this.autoSelectTimeout_ = null; } + if (destination.id == print_preview.Destination.GooglePromotedId.FEDEX && + !destination.isTosAccepted) { + assert(this.cloudPrintInterface_ != null, + 'Selected FedEx Office destination, but Google Cloud Print is ' + + 'not enabled'); + destination.isTosAccepted = true; + this.cloudPrintInterface_.acceptPrinterTos(destination.id, true); + } cr.dispatchSimpleEvent( this, DestinationStore.EventType.DESTINATION_SELECT); if (destination.capabilities == null) { diff --git a/chrome/browser/resources/print_preview/print_preview.html b/chrome/browser/resources/print_preview/print_preview.html index f1b283b..34a49b2 100644 --- a/chrome/browser/resources/print_preview/print_preview.html +++ b/chrome/browser/resources/print_preview/print_preview.html @@ -22,6 +22,7 @@ <link rel="stylesheet" href="search/destination_list_item.css"/> <link rel="stylesheet" href="search/destination_search.css"/> <link rel="stylesheet" href="search/search_box.css"/> + <link rel="stylesheet" href="search/fedex_tos.css"/> <script src="chrome://print/strings.js"></script> <script src="chrome://resources/js/cr.js"></script> @@ -70,6 +71,7 @@ <include src="previewarea/margin_control.html"/> <include src="search/destination_list.html"/> <include src="search/destination_list_item.html"/> + <include src="search/fedex_tos.html"/> </body> </html> diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js index 3635062..b0b3655 100644 --- a/chrome/browser/resources/print_preview/print_preview.js +++ b/chrome/browser/resources/print_preview/print_preview.js @@ -520,19 +520,26 @@ cr.define('print_preview', function() { /** * Called after successfully submitting a job to Google Cloud Print. + * @param {!cr.Event} event Contains the ID of the submitted print job. * @private */ - onCloudPrintSubmitDone_: function() { + onCloudPrintSubmitDone_: function(event) { assert(this.uiState_ == PrintPreview.UiState_.PRINTING, 'Submited job to Google Cloud Print but not in printing state ' + this.uiState_); + if (this.destinationStore_.selectedDestination.id == + print_preview.Destination.GooglePromotedId.FEDEX) { + window.open( + 'https://www.google.com/cloudprint/fedexcode.html?jobid=' + + event.jobId); + } this.close_(); }, /** * Called when there was an error communicating with Google Cloud print. * Displays an error message in the print header. - * @param {cr.Event} event Contains the error message. + * @param {!cr.Event} event Contains the error message. * @private */ onCloudPrintError_: function(event) { @@ -762,6 +769,7 @@ cr.define('print_preview', function() { <include src="search/destination_list_item.js"/> <include src="search/destination_search.js"/> <include src="search/search_box.js"/> +<include src="search/fedex_tos.js"/> window.addEventListener('DOMContentLoaded', function() { printPreview = new print_preview.PrintPreview(); diff --git a/chrome/browser/resources/print_preview/search/destination_list_item.js b/chrome/browser/resources/print_preview/search/destination_list_item.js index bf3169f..b2f4433 100644 --- a/chrome/browser/resources/print_preview/search/destination_list_item.js +++ b/chrome/browser/resources/print_preview/search/destination_list_item.js @@ -30,6 +30,14 @@ cr.define('print_preview', function() { * @private */ this.destination_ = destination; + + /** + * FedEx terms-of-service widget or {@code null} if this list item does not + * render the FedEx Office print destination. + * @type {print_preview.FedexTos} + * @private + */ + this.fedexTos_ = null; }; /** @@ -111,6 +119,31 @@ cr.define('print_preview', function() { * @private */ onActivate_: function() { + if (this.destination_.id == + print_preview.Destination.GooglePromotedId.FEDEX && + !this.destination_.isTosAccepted) { + if (!this.fedexTos_) { + this.fedexTos_ = new print_preview.FedexTos(); + this.fedexTos_.render(this.getElement()); + this.tracker.add( + this.fedexTos_, + print_preview.FedexTos.EventType.AGREE, + this.onTosAgree_.bind(this)); + } + this.fedexTos_.setIsVisible(true); + } else { + var selectEvt = new cr.Event(DestinationListItem.EventType.SELECT); + selectEvt.destination = this.destination_; + this.eventTarget_.dispatchEvent(selectEvt); + } + }, + + /** + * Called when the user agrees to the print destination's terms-of-service. + * Selects the print destination that was agreed to. + * @private + */ + onTosAgree_: function() { var selectEvt = new cr.Event(DestinationListItem.EventType.SELECT); selectEvt.destination = this.destination_; this.eventTarget_.dispatchEvent(selectEvt); diff --git a/chrome/browser/resources/print_preview/search/fedex_tos.css b/chrome/browser/resources/print_preview/search/fedex_tos.css new file mode 100644 index 0000000..506ae10 --- /dev/null +++ b/chrome/browser/resources/print_preview/search/fedex_tos.css @@ -0,0 +1,18 @@ +/* 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. */ + +.fedex-tos { + -webkit-transition: height 300ms; + overflow: hidden; + padding: 0 36px; + text-align: center; +} + +.fedex-tos .tos-text { + padding: 8px 0; +} + +.fedex-tos .agreement-box { + -webkit-padding-after: 8px; +} diff --git a/chrome/browser/resources/print_preview/search/fedex_tos.html b/chrome/browser/resources/print_preview/search/fedex_tos.html new file mode 100644 index 0000000..5973065 --- /dev/null +++ b/chrome/browser/resources/print_preview/search/fedex_tos.html @@ -0,0 +1,12 @@ +<div id="fedex-tos-template" class="fedex-tos" aria-hidden="false" + aria-live="polite" hidden style="height: 0;"> + <div class="height-helper"> + <div class="tos-text"></div> + <div class="agreement-box"> + <label> + <input class="agree-checkbox" type="checkbox"/> + <span i18n-content="tosCheckboxLabel"></span> + </label> + </div> + </div> +</div> diff --git a/chrome/browser/resources/print_preview/search/fedex_tos.js b/chrome/browser/resources/print_preview/search/fedex_tos.js new file mode 100644 index 0000000..1c0504f --- /dev/null +++ b/chrome/browser/resources/print_preview/search/fedex_tos.js @@ -0,0 +1,71 @@ +// 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('print_preview', function() { + 'use strict'; + + /** + * Widget that renders a terms-of-service agreement for using the FedEx Office + * print destination. + * @constructor + * @extends {print_preview.Component} + */ + function FedexTos() { + print_preview.Component.call(this); + }; + + /** + * Enumeration of event types dispatched by the widget. + * @enum {string} + */ + FedexTos.EventType = { + // Dispatched when the user agrees to the terms-of-service. + AGREE: 'print_preview.FedexTos.AGREE' + }; + + FedexTos.prototype = { + __proto__: print_preview.Component.prototype, + + /** @param {boolean} isVisible Whether the widget is visible. */ + setIsVisible: function(isVisible) { + if (isVisible) { + var heightHelperEl = this.getElement().querySelector('.height-helper'); + this.getElement().style.height = heightHelperEl.offsetHeight + 'px'; + } else { + this.getElement().style.height = 0; + } + }, + + /** @override */ + createDom: function() { + this.setElementInternal(this.cloneTemplateInternal('fedex-tos-template')); + var tosTextEl = this.getElement().querySelector('.tos-text'); + tosTextEl.innerHTML = localStrings.getStringF( + 'fedexTos', + '<a href="http://www.fedex.com/us/office/copyprint/online/' + + 'googlecloudprint/termsandconditions">', + '</a>'); + }, + + /** @override */ + enterDocument: function() { + var agreeCheckbox = this.getElement().querySelector('.agree-checkbox'); + this.tracker.add( + agreeCheckbox, 'click', this.onAgreeCheckboxClick_.bind(this)); + }, + + /** + * Called when the agree checkbox is clicked. Dispatches a AGREE event. + * @private + */ + onAgreeCheckboxClick_: function() { + cr.dispatchSimpleEvent(this, FedexTos.EventType.AGREE); + } + }; + + // Export + return { + FedexTos: FedexTos + }; +}); |