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