| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 8 /** |
| 9 * Object used to get and persist the print preview application state. | 9 * Object used to get and persist the print preview application state. |
| 10 * @constructor | 10 * @constructor |
| 11 */ | 11 */ |
| 12 function AppState() { | 12 function AppState() { |
| 13 /** | 13 /** |
| 14 * ID of the selected destination. | 14 * ID of the selected destination. |
| 15 * @type {?string} | 15 * @type {?string} |
| 16 * @private | 16 * @private |
| 17 */ | 17 */ |
| 18 this.selectedDestinationId_ = null; | 18 this.selectedDestinationId_ = null; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Whether the selected destination is a local destination. | 21 * Whether the selected destination is a local destination. |
| 22 * @type {?boolean} | 22 * @type {?boolean} |
| 23 * @private | 23 * @private |
| 24 */ | 24 */ |
| 25 this.isSelectedDestinationLocal_ = null; | 25 this.isSelectedDestinationLocal_ = null; |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Whether the GCP promotion has been dismissed. |
| 29 * @type {boolean} |
| 30 * @private |
| 31 */ |
| 32 this.isGcpPromoDismissed_ = true; |
| 33 |
| 34 /** |
| 28 * Margins type. | 35 * Margins type. |
| 29 * @type {print_preview.ticket_items.MarginsType.Value} | 36 * @type {print_preview.ticket_items.MarginsType.Value} |
| 30 * @private | 37 * @private |
| 31 */ | 38 */ |
| 32 this.marginsType_ = null; | 39 this.marginsType_ = null; |
| 33 | 40 |
| 34 /** | 41 /** |
| 35 * Custom margins. | 42 * Custom margins. |
| 36 * @type {print_preview.Margins} | 43 * @type {print_preview.Margins} |
| 37 * @private | 44 * @private |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 92 |
| 86 /** | 93 /** |
| 87 * Enumeration of field names for serialized app state. | 94 * Enumeration of field names for serialized app state. |
| 88 * @enum {string} | 95 * @enum {string} |
| 89 * @private | 96 * @private |
| 90 */ | 97 */ |
| 91 AppState.Field_ = { | 98 AppState.Field_ = { |
| 92 VERSION: 'version', | 99 VERSION: 'version', |
| 93 SELECTED_DESTINATION_ID: 'selectedDestinationId', | 100 SELECTED_DESTINATION_ID: 'selectedDestinationId', |
| 94 IS_SELECTED_DESTINATION_LOCAL: 'isSelectedDestinationLocal', | 101 IS_SELECTED_DESTINATION_LOCAL: 'isSelectedDestinationLocal', |
| 102 IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', |
| 95 MARGINS_TYPE: 'marginsType', | 103 MARGINS_TYPE: 'marginsType', |
| 96 CUSTOM_MARGINS: 'customMargins', | 104 CUSTOM_MARGINS: 'customMargins', |
| 97 IS_COLOR_ENABLED: 'isColorEnabled', | 105 IS_COLOR_ENABLED: 'isColorEnabled', |
| 98 IS_DUPLEX_ENABLED: 'isDuplexEnabled', | 106 IS_DUPLEX_ENABLED: 'isDuplexEnabled', |
| 99 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', | 107 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', |
| 100 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', | 108 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', |
| 101 IS_COLLATE_ENABLED: 'isCollateEnabled' | 109 IS_COLLATE_ENABLED: 'isCollateEnabled' |
| 102 }; | 110 }; |
| 103 | 111 |
| 104 /** | 112 /** |
| 105 * Name of C++ layer function to persist app state. | 113 * Name of C++ layer function to persist app state. |
| 106 * @type {string} | 114 * @type {string} |
| 107 * @const | 115 * @const |
| 108 * @private | 116 * @private |
| 109 */ | 117 */ |
| 110 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; | 118 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; |
| 111 | 119 |
| 112 AppState.prototype = { | 120 AppState.prototype = { |
| 113 /** @return {?string} ID of the selected destination. */ | 121 /** @return {?string} ID of the selected destination. */ |
| 114 get selectedDestinationId() { | 122 get selectedDestinationId() { |
| 115 return this.selectedDestinationId_; | 123 return this.selectedDestinationId_; |
| 116 }, | 124 }, |
| 117 | 125 |
| 118 /** @return {?boolean} Whether the selected destination is local. */ | 126 /** @return {?boolean} Whether the selected destination is local. */ |
| 119 get isSelectedDestinationLocal() { | 127 get isSelectedDestinationLocal() { |
| 120 return this.isSelectedDestinationLocal_; | 128 return this.isSelectedDestinationLocal_; |
| 121 }, | 129 }, |
| 122 | 130 |
| 131 /** @return {boolean} Whether the GCP promotion has been dismissed. */ |
| 132 get isGcpPromoDismissed() { |
| 133 return this.isGcpPromoDismissed_; |
| 134 }, |
| 135 |
| 123 /** @return {print_preview.ticket_items.MarginsType.Value} Margins type. */ | 136 /** @return {print_preview.ticket_items.MarginsType.Value} Margins type. */ |
| 124 get marginsType() { | 137 get marginsType() { |
| 125 return this.marginsType_; | 138 return this.marginsType_; |
| 126 }, | 139 }, |
| 127 | 140 |
| 128 /** @return {print_preview.Margins} Custom margins. */ | 141 /** @return {print_preview.Margins} Custom margins. */ |
| 129 get customMargins() { | 142 get customMargins() { |
| 130 return this.customMargins_; | 143 return this.customMargins_; |
| 131 }, | 144 }, |
| 132 | 145 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 181 |
| 169 var state = JSON.parse(serializedAppStateStr); | 182 var state = JSON.parse(serializedAppStateStr); |
| 170 if (state[AppState.Field_.VERSION] == 2) { | 183 if (state[AppState.Field_.VERSION] == 2) { |
| 171 this.selectedDestinationId_ = | 184 this.selectedDestinationId_ = |
| 172 state[AppState.Field_.SELECTED_DESTINATION_ID] || null; | 185 state[AppState.Field_.SELECTED_DESTINATION_ID] || null; |
| 173 if (state.hasOwnProperty( | 186 if (state.hasOwnProperty( |
| 174 AppState.Field_.IS_SELECTED_DESTINATION_LOCAL)) { | 187 AppState.Field_.IS_SELECTED_DESTINATION_LOCAL)) { |
| 175 this.isSelectedDestinationLocal_ = | 188 this.isSelectedDestinationLocal_ = |
| 176 state[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL]; | 189 state[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL]; |
| 177 } | 190 } |
| 191 this.isGcpPromoDismissed_ = |
| 192 state[AppState.Field_.IS_GCP_PROMO_DISMISSED] || false; |
| 178 if (state.hasOwnProperty(AppState.Field_.MARGINS_TYPE)) { | 193 if (state.hasOwnProperty(AppState.Field_.MARGINS_TYPE)) { |
| 179 this.marginsType_ = state[AppState.Field_.MARGINS_TYPE]; | 194 this.marginsType_ = state[AppState.Field_.MARGINS_TYPE]; |
| 180 } | 195 } |
| 181 if (state[AppState.Field_.CUSTOM_MARGINS]) { | 196 if (state[AppState.Field_.CUSTOM_MARGINS]) { |
| 182 this.customMargins_ = print_preview.Margins.parse( | 197 this.customMargins_ = print_preview.Margins.parse( |
| 183 state[AppState.Field_.CUSTOM_MARGINS]); | 198 state[AppState.Field_.CUSTOM_MARGINS]); |
| 184 } | 199 } |
| 185 if (state.hasOwnProperty(AppState.Field_.IS_COLOR_ENABLED)) { | 200 if (state.hasOwnProperty(AppState.Field_.IS_COLOR_ENABLED)) { |
| 186 this.isColorEnabled_ = state[AppState.Field_.IS_COLOR_ENABLED]; | 201 this.isColorEnabled_ = state[AppState.Field_.IS_COLOR_ENABLED]; |
| 187 } | 202 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 205 /** | 220 /** |
| 206 * Persists the selected destination. | 221 * Persists the selected destination. |
| 207 * @param {!print_preview.Destination} dest Destination to persist. | 222 * @param {!print_preview.Destination} dest Destination to persist. |
| 208 */ | 223 */ |
| 209 persistSelectedDestination: function(dest) { | 224 persistSelectedDestination: function(dest) { |
| 210 this.selectedDestinationId_ = dest.id; | 225 this.selectedDestinationId_ = dest.id; |
| 211 this.isSelectedDestinationLocal_ = dest.isLocal; | 226 this.isSelectedDestinationLocal_ = dest.isLocal; |
| 212 this.persist_(); | 227 this.persist_(); |
| 213 }, | 228 }, |
| 214 | 229 |
| 230 /** |
| 231 * Persists whether the GCP promotion has been dismissed. |
| 232 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been |
| 233 * dismissed. |
| 234 */ |
| 235 persistIsGcpPromoDismissed: function(isGcpPromoDismissed) { |
| 236 this.isGcpPromoDismissed_ = isGcpPromoDismissed; |
| 237 this.persist_(); |
| 238 }, |
| 239 |
| 215 /** | 240 /** |
| 216 * Persists the margins type. | 241 * Persists the margins type. |
| 217 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Margins | 242 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Margins |
| 218 * type. | 243 * type. |
| 219 */ | 244 */ |
| 220 persistMarginsType: function(marginsType) { | 245 persistMarginsType: function(marginsType) { |
| 221 this.marginsType_ = marginsType; | 246 this.marginsType_ = marginsType; |
| 222 this.persist_(); | 247 this.persist_(); |
| 223 }, | 248 }, |
| 224 | 249 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 * Calls into the native layer to persist the application state. | 305 * Calls into the native layer to persist the application state. |
| 281 * @private | 306 * @private |
| 282 */ | 307 */ |
| 283 persist_: function() { | 308 persist_: function() { |
| 284 var obj = {}; | 309 var obj = {}; |
| 285 obj[AppState.Field_.VERSION] = AppState.VERSION_; | 310 obj[AppState.Field_.VERSION] = AppState.VERSION_; |
| 286 obj[AppState.Field_.SELECTED_DESTINATION_ID] = | 311 obj[AppState.Field_.SELECTED_DESTINATION_ID] = |
| 287 this.selectedDestinationId_; | 312 this.selectedDestinationId_; |
| 288 obj[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL] = | 313 obj[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL] = |
| 289 this.isSelectedDestinationLocal_; | 314 this.isSelectedDestinationLocal_; |
| 315 obj[AppState.Field_.IS_GCP_PROMO_DISMISSED] = this.isGcpPromoDismissed_; |
| 290 obj[AppState.Field_.MARGINS_TYPE] = this.marginsType_; | 316 obj[AppState.Field_.MARGINS_TYPE] = this.marginsType_; |
| 291 if (this.customMargins_) { | 317 if (this.customMargins_) { |
| 292 obj[AppState.Field_.CUSTOM_MARGINS] = this.customMargins_.serialize(); | 318 obj[AppState.Field_.CUSTOM_MARGINS] = this.customMargins_.serialize(); |
| 293 } | 319 } |
| 294 obj[AppState.Field_.IS_COLOR_ENABLED] = this.isColorEnabled_; | 320 obj[AppState.Field_.IS_COLOR_ENABLED] = this.isColorEnabled_; |
| 295 obj[AppState.Field_.IS_DUPLEX_ENABLED] = this.isDuplexEnabled_; | 321 obj[AppState.Field_.IS_DUPLEX_ENABLED] = this.isDuplexEnabled_; |
| 296 obj[AppState.Field_.IS_HEADER_FOOTER_ENABLED] = | 322 obj[AppState.Field_.IS_HEADER_FOOTER_ENABLED] = |
| 297 this.isHeaderFooterEnabled_; | 323 this.isHeaderFooterEnabled_; |
| 298 obj[AppState.Field_.IS_LANDSCAPE_ENABLED] = this.isLandscapeEnabled_; | 324 obj[AppState.Field_.IS_LANDSCAPE_ENABLED] = this.isLandscapeEnabled_; |
| 299 obj[AppState.Field_.IS_COLLATE_ENABLED] = this.isCollateEnabled_; | 325 obj[AppState.Field_.IS_COLLATE_ENABLED] = this.isCollateEnabled_; |
| 300 chrome.send(AppState.NATIVE_FUNCTION_NAME_, [JSON.stringify(obj)]); | 326 chrome.send(AppState.NATIVE_FUNCTION_NAME_, [JSON.stringify(obj)]); |
| 301 } | 327 } |
| 302 }; | 328 }; |
| 303 | 329 |
| 304 return { | 330 return { |
| 305 AppState: AppState | 331 AppState: AppState |
| 306 }; | 332 }; |
| 307 }); | 333 }); |
| OLD | NEW |