| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** @enum {string} */ | 8 /** @enum {string} */ |
| 9 var ResolverState = { | 9 var ResolverState = { |
| 10 INITIAL: 'INITIAL', | 10 INITIAL: 'INITIAL', |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 this.promiseResolver_ = null; | 48 this.promiseResolver_ = null; |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * @param {!print_preview.DestinationStore} store | 52 * @param {!print_preview.DestinationStore} store |
| 53 * @param {!print_preview.Destination} destination | 53 * @param {!print_preview.Destination} destination |
| 54 * @return {?ProvisionalDestinationResolver} | 54 * @return {?ProvisionalDestinationResolver} |
| 55 */ | 55 */ |
| 56 ProvisionalDestinationResolver.create = function(store, destination) { | 56 ProvisionalDestinationResolver.create = function(store, destination) { |
| 57 if (destination.provisionalType != | 57 if (destination.provisionalType != |
| 58 print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION) { | 58 print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION) { |
| 59 return null; | 59 return null; |
| 60 } | 60 } |
| 61 return new ProvisionalDestinationResolver(store, destination); | 61 return new ProvisionalDestinationResolver(store, destination); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 ProvisionalDestinationResolver.prototype = { | 64 ProvisionalDestinationResolver.prototype = { |
| 65 __proto__: print_preview.Overlay.prototype, | 65 __proto__: print_preview.Overlay.prototype, |
| 66 | 66 |
| 67 /** @override */ | 67 /** @override */ |
| 68 enterDocument: function() { | 68 enterDocument: function() { |
| 69 print_preview.Overlay.prototype.enterDocument.call(this); | 69 print_preview.Overlay.prototype.enterDocument.call(this); |
| 70 | 70 |
| 71 this.tracker.add( | 71 this.tracker.add( |
| 72 this.getChildElement('.usb-permission-ok-button'), | 72 this.getChildElement('.usb-permission-ok-button'), 'click', |
| 73 'click', | |
| 74 this.startResolveDestination_.bind(this)); | 73 this.startResolveDestination_.bind(this)); |
| 75 this.tracker.add( | 74 this.tracker.add( |
| 76 this.getChildElement('.cancel'), | 75 this.getChildElement('.cancel'), 'click', this.cancel.bind(this)); |
| 77 'click', | |
| 78 this.cancel.bind(this)); | |
| 79 | 76 |
| 80 this.tracker.add( | 77 this.tracker.add( |
| 81 this.destinationStore_, | 78 this.destinationStore_, print_preview.DestinationStore.EventType |
| 82 print_preview.DestinationStore.EventType | 79 .PROVISIONAL_DESTINATION_RESOLVED, |
| 83 .PROVISIONAL_DESTINATION_RESOLVED, | |
| 84 this.onDestinationResolved_.bind(this)); | 80 this.onDestinationResolved_.bind(this)); |
| 85 }, | 81 }, |
| 86 | 82 |
| 87 /** @override */ | 83 /** @override */ |
| 88 onSetVisibleInternal: function(visible) { | 84 onSetVisibleInternal: function(visible) { |
| 89 if (visible) { | 85 if (visible) { |
| 90 assert(this.state_ == ResolverState.INITIAL, | 86 assert( |
| 91 'Showing overlay while not in initial state.'); | 87 this.state_ == ResolverState.INITIAL, |
| 88 'Showing overlay while not in initial state.'); |
| 92 assert(!this.promiseResolver_, 'Promise resolver already set.'); | 89 assert(!this.promiseResolver_, 'Promise resolver already set.'); |
| 93 this.setState_(ResolverState.ACTIVE); | 90 this.setState_(ResolverState.ACTIVE); |
| 94 this.promiseResolver_ = new PromiseResolver(); | 91 this.promiseResolver_ = new PromiseResolver(); |
| 95 this.getChildElement('.default').focus(); | 92 this.getChildElement('.default').focus(); |
| 96 } else if (this.state_ != ResolverState.DONE) { | 93 } else if (this.state_ != ResolverState.DONE) { |
| 97 assert(this.state_ != ResolverState.INITIAL, 'Hiding in initial state'); | 94 assert(this.state_ != ResolverState.INITIAL, 'Hiding in initial state'); |
| 98 this.setState_(ResolverState.DONE); | 95 this.setState_(ResolverState.DONE); |
| 99 this.promiseResolver_.reject(); | 96 this.promiseResolver_.reject(); |
| 100 this.promiseResolver_ = null; | 97 this.promiseResolver_ = null; |
| 101 } | 98 } |
| 102 }, | 99 }, |
| 103 | 100 |
| 104 /** @override */ | 101 /** @override */ |
| 105 createDom: function() { | 102 createDom: function() { |
| 106 this.setElementInternal(this.cloneTemplateInternal( | 103 this.setElementInternal( |
| 107 'extension-usb-resolver')); | 104 this.cloneTemplateInternal('extension-usb-resolver')); |
| 108 | 105 |
| 109 var extNameEl = this.getChildElement('.usb-permission-extension-name'); | 106 var extNameEl = this.getChildElement('.usb-permission-extension-name'); |
| 110 extNameEl.title = this.destination_.extensionName; | 107 extNameEl.title = this.destination_.extensionName; |
| 111 extNameEl.textContent = this.destination_.extensionName; | 108 extNameEl.textContent = this.destination_.extensionName; |
| 112 | 109 |
| 113 var extIconEl = this.getChildElement('.usb-permission-extension-icon'); | 110 var extIconEl = this.getChildElement('.usb-permission-extension-icon'); |
| 114 extIconEl.style.backgroundImage = '-webkit-image-set(' + | 111 extIconEl.style.backgroundImage = '-webkit-image-set(' + |
| 115 'url(chrome://extension-icon/' + | 112 'url(chrome://extension-icon/' + this.destination_.extensionId + |
| 116 this.destination_.extensionId + '/24/1) 1x,' + | 113 '/24/1) 1x,' + |
| 117 'url(chrome://extension-icon/' + | 114 'url(chrome://extension-icon/' + this.destination_.extensionId + |
| 118 this.destination_.extensionId + '/48/1) 2x)'; | 115 '/48/1) 2x)'; |
| 119 }, | 116 }, |
| 120 | 117 |
| 121 /** | 118 /** |
| 122 * Handler for click on OK button. It initiates destination resolving. | 119 * Handler for click on OK button. It initiates destination resolving. |
| 123 * @private | 120 * @private |
| 124 */ | 121 */ |
| 125 startResolveDestination_: function() { | 122 startResolveDestination_: function() { |
| 126 assert(this.state_ == ResolverState.ACTIVE, | 123 assert( |
| 127 'Invalid state in request grant permission'); | 124 this.state_ == ResolverState.ACTIVE, |
| 125 'Invalid state in request grant permission'); |
| 128 | 126 |
| 129 this.setState_(ResolverState.GRANTING_PERMISSION); | 127 this.setState_(ResolverState.GRANTING_PERMISSION); |
| 130 this.destinationStore_.resolveProvisionalDestination(this.destination_); | 128 this.destinationStore_.resolveProvisionalDestination(this.destination_); |
| 131 }, | 129 }, |
| 132 | 130 |
| 133 /** | 131 /** |
| 134 * Handler for PROVISIONAL_DESTINATION_RESOLVED event. It finalizes the | 132 * Handler for PROVISIONAL_DESTINATION_RESOLVED event. It finalizes the |
| 135 * resolver state once the destination associated with the resolver gets | 133 * resolver state once the destination associated with the resolver gets |
| 136 * resolved. | 134 * resolved. |
| 137 * @param {Event} event | 135 * @param {Event} event |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 updateUI_: function() { | 172 updateUI_: function() { |
| 175 this.getChildElement('.usb-permission-ok-button').hidden = | 173 this.getChildElement('.usb-permission-ok-button').hidden = |
| 176 this.state_ == ResolverState.ERROR; | 174 this.state_ == ResolverState.ERROR; |
| 177 this.getChildElement('.usb-permission-ok-button').disabled = | 175 this.getChildElement('.usb-permission-ok-button').disabled = |
| 178 this.state_ != ResolverState.ACTIVE; | 176 this.state_ != ResolverState.ACTIVE; |
| 179 | 177 |
| 180 // If OK button is disabled, make sure Cancel button gets focus. | 178 // If OK button is disabled, make sure Cancel button gets focus. |
| 181 if (this.state_ != ResolverState.ACTIVE) | 179 if (this.state_ != ResolverState.ACTIVE) |
| 182 this.getChildElement('.cancel').focus(); | 180 this.getChildElement('.cancel').focus(); |
| 183 | 181 |
| 184 this.getChildElement('.throbber-placeholder').classList.toggle( | 182 this.getChildElement('.throbber-placeholder') |
| 185 'throbber', | 183 .classList.toggle( |
| 186 this.state_ == ResolverState.GRANTING_PERMISSION); | 184 'throbber', this.state_ == ResolverState.GRANTING_PERMISSION); |
| 187 | 185 |
| 188 this.getChildElement('.usb-permission-extension-desc').hidden = | 186 this.getChildElement('.usb-permission-extension-desc').hidden = |
| 189 this.state_ == ResolverState.ERROR; | 187 this.state_ == ResolverState.ERROR; |
| 190 | 188 |
| 191 this.getChildElement('.usb-permission-message').textContent = | 189 this.getChildElement('.usb-permission-message').textContent = |
| 192 this.state_ == ResolverState.ERROR ? | 190 this.state_ == ResolverState.ERROR ? |
| 193 loadTimeData.getStringF('resolveExtensionUSBErrorMessage', | 191 loadTimeData.getStringF( |
| 194 this.destination_.extensionName) : | 192 'resolveExtensionUSBErrorMessage', |
| 195 loadTimeData.getString('resolveExtensionUSBPermissionMessage'); | 193 this.destination_.extensionName) : |
| 194 loadTimeData.getString('resolveExtensionUSBPermissionMessage'); |
| 196 }, | 195 }, |
| 197 | 196 |
| 198 /** | 197 /** |
| 199 * Initiates and shows the resolver overlay. | 198 * Initiates and shows the resolver overlay. |
| 200 * @param {!HTMLElement} parent The element that should parent the resolver | 199 * @param {!HTMLElement} parent The element that should parent the resolver |
| 201 * UI. | 200 * UI. |
| 202 * @return {!Promise<!print_preview.Destination>} Promise that will be | 201 * @return {!Promise<!print_preview.Destination>} Promise that will be |
| 203 * fulfilled when the destination resolving is finished. | 202 * fulfilled when the destination resolving is finished. |
| 204 */ | 203 */ |
| 205 run: function(parent) { | 204 run: function(parent) { |
| 206 this.render(parent); | 205 this.render(parent); |
| 207 this.setIsVisible(true); | 206 this.setIsVisible(true); |
| 208 | 207 |
| 209 assert(this.promiseResolver_, 'Promise resolver not created.'); | 208 assert(this.promiseResolver_, 'Promise resolver not created.'); |
| 210 return this.promiseResolver_.promise; | 209 return this.promiseResolver_.promise; |
| 211 } | 210 } |
| 212 }; | 211 }; |
| 213 | 212 |
| 214 return { | 213 return {ProvisionalDestinationResolver: ProvisionalDestinationResolver}; |
| 215 ProvisionalDestinationResolver: ProvisionalDestinationResolver | |
| 216 }; | |
| 217 }); | 214 }); |
| OLD | NEW |