Chromium Code Reviews| 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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 /** | 22 /** |
| 23 * Whether the app state has been initialized. The app state will ignore all | 23 * Whether the app state has been initialized. The app state will ignore all |
| 24 * writes until it has been initialized. | 24 * writes until it has been initialized. |
| 25 * @type {boolean} | 25 * @type {boolean} |
| 26 * @private | 26 * @private |
| 27 */ | 27 */ |
| 28 this.isInitialized_ = false; | 28 this.isInitialized_ = false; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Number of recent print destinations to store across browser sessions. | |
| 33 * @const {number} | |
| 34 */ | |
| 35 AppState.NUM_DESTINATIONS_ = 3; | |
| 36 | |
| 37 | |
| 38 /** | |
| 32 * Enumeration of field names for serialized app state. | 39 * Enumeration of field names for serialized app state. |
| 33 * @enum {string} | 40 * @enum {string} |
| 34 */ | 41 */ |
| 35 AppState.Field = { | 42 AppState.Field = { |
| 36 VERSION: 'version', | 43 VERSION: 'version', |
| 37 SELECTED_DESTINATION_ID: 'selectedDestinationId', | 44 RECENT_DESTINATION_IDS: 'recentDestinationIds', |
| 38 SELECTED_DESTINATION_ACCOUNT: 'selectedDestinationAccount', | 45 RECENT_DESTINATION_ACCOUNTS: 'recentDestinationAccounts', |
| 39 SELECTED_DESTINATION_ORIGIN: 'selectedDestinationOrigin', | 46 RECENT_DESTINATION_ORIGINS: 'recentDestinationOrigins', |
| 40 SELECTED_DESTINATION_CAPABILITIES: 'selectedDestinationCapabilities', | 47 RECENT_DESTINATION_CAPABILITIES: 'recentDestinationCapabilities', |
| 41 SELECTED_DESTINATION_NAME: 'selectedDestinationName', | 48 RECENT_DESTINATION_NAMES: 'recentDestinationNames', |
| 42 SELECTED_DESTINATION_EXTENSION_ID: 'selectedDestinationExtensionId', | 49 RECENT_DESTINATION_EXTENSION_IDS: 'recentDestinationExtensionIds', |
| 43 SELECTED_DESTINATION_EXTENSION_NAME: 'selectedDestinationExtensionName', | 50 RECENT_DESTINATION_EXTENSION_NAMES: 'recentDestinationExtensionNames', |
| 44 IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', | 51 IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', |
| 45 DPI: 'dpi', | 52 DPI: 'dpi', |
| 46 MEDIA_SIZE: 'mediaSize', | 53 MEDIA_SIZE: 'mediaSize', |
| 47 MARGINS_TYPE: 'marginsType', | 54 MARGINS_TYPE: 'marginsType', |
| 48 CUSTOM_MARGINS: 'customMargins', | 55 CUSTOM_MARGINS: 'customMargins', |
| 49 IS_COLOR_ENABLED: 'isColorEnabled', | 56 IS_COLOR_ENABLED: 'isColorEnabled', |
| 50 IS_DUPLEX_ENABLED: 'isDuplexEnabled', | 57 IS_DUPLEX_ENABLED: 'isDuplexEnabled', |
| 51 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', | 58 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', |
| 52 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', | 59 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', |
| 53 IS_COLLATE_ENABLED: 'isCollateEnabled', | 60 IS_COLLATE_ENABLED: 'isCollateEnabled', |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 67 | 74 |
| 68 /** | 75 /** |
| 69 * Name of C++ layer function to persist app state. | 76 * Name of C++ layer function to persist app state. |
| 70 * @type {string} | 77 * @type {string} |
| 71 * @const | 78 * @const |
| 72 * @private | 79 * @private |
| 73 */ | 80 */ |
| 74 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; | 81 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; |
| 75 | 82 |
| 76 AppState.prototype = { | 83 AppState.prototype = { |
| 84 | |
| 85 /** | |
| 86 * Helper function to get the most recent value of one of the destination | |
| 87 * fields in the app state. | |
| 88 * @param {?print_preview.AppState.field} The state field to return the | |
|
dpapad
2016/09/19 22:16:19
Type annotation is missing the parameter name, and
rbpotter
2016/09/20 23:47:37
Done.
| |
| 89 * value of. | |
| 90 * @return {?string or ?print_preview.Cdd} The most recent value of the | |
|
dpapad
2016/09/19 22:16:19
This is not a valid type annotation. I am not sure
rbpotter
2016/09/20 23:47:37
Done - I did not realize there was actually a comp
| |
| 91 * destination state field. ?print_preview.Cdd if the state field is | |
| 92 * RECENT_DESTINATION_CAPABILIITIES, ?string otherwise. | |
| 93 */ | |
| 94 getStateValue_: function(fieldName) { | |
| 95 return (this.state_[fieldName] && this.state_[fieldName].length > 0) ? | |
| 96 this.state_[fieldName][0] : null; | |
| 97 }, | |
| 98 | |
| 77 /** @return {?string} ID of the selected destination. */ | 99 /** @return {?string} ID of the selected destination. */ |
| 78 get selectedDestinationId() { | 100 get selectedDestinationId() { |
| 79 return this.state_[AppState.Field.SELECTED_DESTINATION_ID]; | 101 return this.getStateValue_(AppState.Field.RECENT_DESTINATION_IDS); |
| 80 }, | 102 }, |
| 81 | 103 |
| 82 /** @return {?string} Account the selected destination is registered for. */ | 104 /** @return {?string} Account the selected destination is registered for. */ |
| 83 get selectedDestinationAccount() { | 105 get selectedDestinationAccount() { |
| 84 return this.state_[AppState.Field.SELECTED_DESTINATION_ACCOUNT]; | 106 return this.getStateValue_(AppState.Field.RECENT_DESTINATION_ACCOUNTS); |
| 85 }, | 107 }, |
| 86 | 108 |
| 87 /** | 109 /** |
| 88 * @return {?print_preview.Destination.Origin<string>} Origin of the | 110 * @return {?print_preview.Destination.Origin<string>} Origin of the |
| 89 * selected destination. | 111 * selected destination. |
| 90 */ | 112 */ |
| 91 get selectedDestinationOrigin() { | 113 get selectedDestinationOrigin() { |
| 92 return this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN]; | 114 return this.getStateValue_(AppState.Field.RECENT_DESTINATION_ORIGINS); |
| 93 }, | 115 }, |
| 94 | 116 |
| 95 /** @return {?print_preview.Cdd} CDD of the selected destination. */ | 117 /** @return {?print_preview.Cdd} CDD of the selected destination. */ |
| 96 get selectedDestinationCapabilities() { | 118 get selectedDestinationCapabilities() { |
| 97 return this.state_[AppState.Field.SELECTED_DESTINATION_CAPABILITIES]; | 119 return this.getStateValue_( |
| 120 AppState.Field.RECENT_DESTINATION_CAPABILITIES); | |
| 98 }, | 121 }, |
| 99 | 122 |
| 100 /** @return {?string} Name of the selected destination. */ | 123 /** @return {?string} Name of the selected destination. */ |
| 101 get selectedDestinationName() { | 124 get selectedDestinationName() { |
| 102 return this.state_[AppState.Field.SELECTED_DESTINATION_NAME]; | 125 return this.getStateValue_(AppState.Field.RECENT_DESTINATION_NAMES); |
| 103 }, | 126 }, |
| 104 | 127 |
| 105 /** | 128 /** |
| 106 * @return {?string} Extension ID associated with the selected destination. | 129 * @return {?string} Extension ID associated with the selected destination. |
| 107 */ | 130 */ |
| 108 get selectedDestinationExtensionId() { | 131 get selectedDestinationExtensionId() { |
| 109 return this.state_[AppState.Field.SELECTED_DESTINATION_EXTENSION_ID]; | 132 return this.getStateValue_( |
| 133 AppState.Field.RECENT_DESTINATION_EXTENSION_IDS); | |
| 110 }, | 134 }, |
| 111 | 135 |
| 112 /** | 136 /** |
| 113 * @return {?string} Extension name associated with the selected | 137 * @return {?string} Extension name associated with the selected |
| 114 * destination. | 138 * destination. |
| 115 */ | 139 */ |
| 116 get selectedDestinationExtensionName() { | 140 get selectedDestinationExtensionName() { |
| 117 return this.state_[AppState.Field.SELECTED_DESTINATION_EXTENSION_NAME]; | 141 return this.getStateValue_( |
| 142 AppState.Field.RECENT_DESTINATION_EXTENSION_NAMES); | |
| 143 }, | |
| 144 | |
| 145 /** @return {?Array<string>} IDs of the recent destinations. */ | |
| 146 get recentDestinationIds() { | |
| 147 return this.state_[AppState.Field.RECENT_DESTINATION_IDS]; | |
| 148 }, | |
| 149 | |
| 150 /** | |
| 151 * @return {?Array<string>} Accounts the recent destinations are registered | |
| 152 * for. | |
| 153 */ | |
| 154 get recentDestinationAccounts() { | |
| 155 return this.state_[AppState.Field.RECENT_DESTINATION_ACCOUNTS]; | |
| 156 }, | |
| 157 | |
| 158 /** @return {?Array<string>} Origins of the recent destinations. */ | |
| 159 get recentDestinationOrigins() { | |
| 160 return this.state_[AppState.Field.RECENT_DESTINATION_ORIGINS]; | |
| 161 }, | |
| 162 | |
| 163 /** @return {?Array<print_preview.Cdd>} CDDs of the recent destinations. */ | |
| 164 get recentDestinationCapabilities() { | |
| 165 return this.state_[AppState.Field.RECENT_DESTINATION_CAPABILITIES]; | |
| 166 }, | |
| 167 | |
| 168 /** @return {?Array<string>} Names of the recent destinations. */ | |
| 169 get recentDestinationNames() { | |
| 170 return this.state_[AppState.Field.RECENT_DESTINATION_NAMES]; | |
| 171 }, | |
| 172 | |
| 173 /** | |
| 174 * @return {?Array<string>} Extension IDs associated with the recent | |
| 175 * destinations. | |
| 176 */ | |
| 177 get recentDestinationExtensionIds() { | |
| 178 return this.state_[AppState.Field.RECENT_DESTINATION_EXTENSION_IDS]; | |
| 179 }, | |
| 180 | |
| 181 /** | |
| 182 * @return {?Array<string>} Extension names associated with the recent | |
| 183 * destinations. | |
| 184 */ | |
| 185 get recentDestinationExtensionNames() { | |
| 186 return this.state_[AppState.Field.RECENT_DESTINATION_EXTENSION_NAMES]; | |
| 118 }, | 187 }, |
| 119 | 188 |
| 120 /** @return {boolean} Whether the GCP promotion has been dismissed. */ | 189 /** @return {boolean} Whether the GCP promotion has been dismissed. */ |
| 121 get isGcpPromoDismissed() { | 190 get isGcpPromoDismissed() { |
| 122 return this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED]; | 191 return this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED]; |
| 123 }, | 192 }, |
| 124 | 193 |
| 125 /** | 194 /** |
| 126 * @param {!print_preview.AppState.Field} field App state field to check if | 195 * @param {!print_preview.AppState.Field} field App state field to check if |
| 127 * set. | 196 * set. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 138 getField: function(field) { | 207 getField: function(field) { |
| 139 if (field == AppState.Field.CUSTOM_MARGINS) { | 208 if (field == AppState.Field.CUSTOM_MARGINS) { |
| 140 return this.state_[field] ? | 209 return this.state_[field] ? |
| 141 print_preview.Margins.parse(this.state_[field]) : null; | 210 print_preview.Margins.parse(this.state_[field]) : null; |
| 142 } else { | 211 } else { |
| 143 return this.state_[field]; | 212 return this.state_[field]; |
| 144 } | 213 } |
| 145 }, | 214 }, |
| 146 | 215 |
| 147 /** | 216 /** |
| 217 * Helper function to set up the recent destination fields in case they are | |
| 218 * empty or only contain one value. | |
| 219 * @param {print_preview.AppState.field} stateFieldName The state field to | |
|
dpapad
2016/09/19 22:16:19
!print_preview.AppState.Field
rbpotter
2016/09/20 23:47:37
Done.
| |
| 220 * be set up. | |
| 221 */ | |
| 222 setUpState_: function(stateFieldName) { | |
| 223 if (!this.state_[stateFieldName]) { | |
|
dpapad
2016/09/19 22:16:19
Is this check robust? Could this.state_[stateField
rbpotter
2016/09/20 23:47:37
Done - fields other than IDs could be a single ele
| |
| 224 this.state_[stateFieldName] = []; | |
| 225 } else if (!(this.state_[stateFieldName] instanceof Array)) { | |
| 226 var tmp = this.state_[stateFieldName]; | |
| 227 this.state_[stateFieldName][0] = tmp; | |
|
dpapad
2016/09/19 22:16:19
This assignment seems a odd but also wrong. Are yo
rbpotter
2016/09/20 23:47:37
Done - yes, I was trying to convert the value to a
| |
| 228 } else if (this.state_[stateFieldName].length > | |
| 229 AppState.NUM_DESTINATIONS_) { | |
| 230 this.state_[stateFieldName].splice(AppState.NUM_DESTINATIONS_, | |
| 231 this.state_[stateFieldName].length - AppState.NUM_DESTINATIONS_); | |
| 232 } | |
| 233 }, | |
| 234 | |
| 235 /** | |
| 148 * Initializes the app state from a serialized string returned by the native | 236 * Initializes the app state from a serialized string returned by the native |
| 149 * layer. | 237 * layer. |
| 150 * @param {?string} serializedAppStateStr Serialized string representation | 238 * @param {?string} serializedAppStateStr Serialized string representation |
| 151 * of the app state. | 239 * of the app state. |
| 152 */ | 240 */ |
| 153 init: function(serializedAppStateStr) { | 241 init: function(serializedAppStateStr) { |
| 154 if (serializedAppStateStr) { | 242 if (serializedAppStateStr) { |
| 155 try { | 243 try { |
| 156 var state = JSON.parse(serializedAppStateStr); | 244 var state = JSON.parse(serializedAppStateStr); |
| 157 if (state[AppState.Field.VERSION] == AppState.VERSION_) { | 245 if (state[AppState.Field.VERSION] == AppState.VERSION_) { |
| 158 this.state_ = state; | 246 this.state_ = state; |
| 159 } | 247 } |
| 160 } catch(e) { | 248 } catch(e) { |
| 161 console.error('Unable to parse state: ' + e); | 249 console.error('Unable to parse state: ' + e); |
| 162 // Proceed with default state. | 250 // Proceed with default state. |
| 163 } | 251 } |
| 164 } else { | 252 } else { |
| 165 // Set some state defaults. | 253 // Set some state defaults. |
| 166 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = false; | 254 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = false; |
| 167 } | 255 } |
| 256 | |
| 257 this.setUpState_(AppState.Field.RECENT_DESTINATION_IDS); | |
| 258 this.setUpState_(AppState.Field.RECENT_DESTINATION_ACCOUNTS); | |
| 259 this.setUpState_(AppState.Field.RECENT_DESTINATION_ORIGINS); | |
| 260 this.setUpState_(AppState.Field.RECENT_DESTINATION_CAPABILITIES); | |
| 261 this.setUpState_(AppState.Field.RECENT_DESTINATION_NAMES); | |
| 262 this.setUpState_(AppState.Field.RECENT_DESTINATION_EXTENSION_IDS); | |
| 263 this.setUpState_(AppState.Field.RECENT_DESTINATION_EXTENSION_NAMES); | |
| 264 | |
|
dpapad
2016/09/19 22:16:19
Nit: Remove blank line.
rbpotter
2016/09/20 23:47:37
Done.
| |
| 168 }, | 265 }, |
| 169 | 266 |
| 170 /** | 267 /** |
| 171 * Sets to initialized state. Now object will accept persist requests. | 268 * Sets to initialized state. Now object will accept persist requests. |
| 172 */ | 269 */ |
| 173 setInitialized: function() { | 270 setInitialized: function() { |
| 174 this.isInitialized_ = true; | 271 this.isInitialized_ = true; |
| 175 }, | 272 }, |
| 176 | 273 |
| 177 /** | 274 /** |
| 178 * Persists the given value for the given field. | 275 * Persists the given value for the given field. |
| 179 * @param {!print_preview.AppState.Field} field Field to persist. | 276 * @param {!print_preview.AppState.Field} field Field to persist. |
| 180 * @param {?} value Value of field to persist. | 277 * @param {?} value Value of field to persist. |
| 181 */ | 278 */ |
| 182 persistField: function(field, value) { | 279 persistField: function(field, value) { |
| 183 if (!this.isInitialized_) | 280 if (!this.isInitialized_) |
| 184 return; | 281 return; |
| 185 if (field == AppState.Field.CUSTOM_MARGINS) { | 282 if (field == AppState.Field.CUSTOM_MARGINS) { |
| 186 this.state_[field] = value ? value.serialize() : null; | 283 this.state_[field] = value ? value.serialize() : null; |
| 187 } else { | 284 } else { |
| 188 this.state_[field] = value; | 285 this.state_[field] = value; |
| 189 } | 286 } |
| 190 this.persist_(); | 287 this.persist_(); |
| 191 }, | 288 }, |
| 192 | 289 |
| 193 /** | 290 /** |
| 291 * Shifts the desired recent destination field's values as needed and places | |
| 292 * the most recent value, destVal, in position 0 in the array. | |
| 293 * @param {number} indexFound the index where the destination already exists | |
| 294 * in the array, or -1 if it is not in the array. | |
| 295 * @param {!print_preview.AppState.Field} fieldName the field array to | |
| 296 * adjust | |
| 297 * @param {string or print_preview.Cdd} the value that should be added as | |
| 298 * the most recent value in the array. | |
| 299 */ | |
| 300 shiftStateField_: function(indexFound, fieldName, destVal) { | |
| 301 if (indexFound == -1 && | |
| 302 this.state_[fieldName].length == AppState.NUM_DESTINATIONS_) | |
| 303 indexFound = AppState.NUM_DESTINATIONS_ - 1; | |
| 304 if (indexFound != -1) | |
| 305 this.state_[fieldName].splice(indexFound, 1); | |
| 306 this.state_[fieldName].reverse(); | |
|
dpapad
2016/09/19 22:16:19
No need to reverse, push, reverse. You can insert
rbpotter
2016/09/20 23:47:37
Done.
| |
| 307 this.state_[fieldName].push(destVal); | |
| 308 this.state_[fieldName].reverse(); | |
| 309 }, | |
| 310 | |
| 311 /** | |
| 194 * Persists the selected destination. | 312 * Persists the selected destination. |
| 195 * @param {!print_preview.Destination} dest Destination to persist. | 313 * @param {!print_preview.Destination} dest Destination to persist. |
| 196 */ | 314 */ |
| 197 persistSelectedDestination: function(dest) { | 315 persistSelectedDestination: function(dest) { |
|
rbpotter
2016/09/19 21:16:19
Does this function (with the helper above) look be
| |
| 198 if (!this.isInitialized_) | 316 if (!this.isInitialized_ || !dest) |
| 199 return; | 317 return; |
| 200 this.state_[AppState.Field.SELECTED_DESTINATION_ID] = dest.id; | 318 |
| 201 this.state_[AppState.Field.SELECTED_DESTINATION_ACCOUNT] = dest.account; | 319 // Determine if this destination is already in the recent destinations, |
| 202 this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN] = dest.origin; | 320 // and where in the array it is located. |
| 203 this.state_[AppState.Field.SELECTED_DESTINATION_CAPABILITIES] = | 321 var idIndexFound = this.state_[ |
| 204 dest.capabilities; | 322 AppState.Field.RECENT_DESTINATION_IDS].indexOf(dest.id); |
| 205 this.state_[AppState.Field.SELECTED_DESTINATION_NAME] = dest.displayName; | 323 var originIndexFound = this.state_[ |
| 206 this.state_[AppState.Field.SELECTED_DESTINATION_EXTENSION_ID] = | 324 AppState.Field.RECENT_DESTINATION_ORIGINS].indexOf(dest.origin); |
| 207 dest.extensionId; | 325 |
| 208 this.state_[AppState.Field.SELECTED_DESTINATION_EXTENSION_NAME] = | 326 if (idIndexFound != originIndexFound || |
| 209 dest.extensionName; | 327 idIndexFound >= AppState.NUM_DESTINATIONS_) |
| 328 idIndexFound = -1; | |
| 329 | |
| 330 if (idIndexFound == 0) { | |
| 331 this.persist_(); | |
| 332 return; | |
| 333 } | |
| 334 | |
| 335 // Shift all the destination state fields so that the are always ordered | |
| 336 // from most recent (entry 0) to least recent. | |
| 337 this.shiftStateField_(idIndexFound, | |
| 338 AppState.Field.RECENT_DESTINATION_IDS, dest.id); | |
| 339 this.shiftStateField_(idIndexFound, | |
| 340 AppState.Field.RECENT_DESTINATION_ACCOUNTS, dest.account || ''); | |
| 341 this.shiftStateField_(idIndexFound, | |
| 342 AppState.Field.RECENT_DESTINATION_ORIGINS, dest.origin); | |
| 343 this.shiftStateField_(idIndexFound, | |
| 344 AppState.Field.RECENT_DESTINATION_CAPABILITIES, | |
| 345 dest.capabilities); | |
| 346 this.shiftStateField_(idIndexFound, | |
| 347 AppState.Field.RECENT_DESTINATION_NAMES, dest.name || ''); | |
| 348 this.shiftStateField_(idIndexFound, | |
| 349 AppState.Field.RECENT_DESTINATION_EXTENSION_IDS, | |
| 350 dest.extension_id || ''); | |
| 351 this.shiftStateField_(idIndexFound, | |
| 352 AppState.Field.RECENT_DESTINATION_EXTENSION_NAMES, | |
| 353 dest.extension_name || ''); | |
| 354 | |
| 355 /* | |
| 356 | |
| 357 // Shift destinations so that they are always ordered from most recent | |
| 358 // (entry 0) to least recent (entry AppState.NUM_DESTINATIONS_ -1). | |
| 359 for (var i = AppState.NUM_DESTINATIONS - 1; i > 0; i--) { | |
| 360 var shiftDestination = true; | |
| 361 // If the selected destination is one of the destinations more recent | |
| 362 // than destination i there is no need to move destination i-1 to i, as | |
| 363 // only the more recent destinations need to be reordered and the ith | |
| 364 // entry remains the ith most recently used. | |
| 365 for (var j = i - 1; j >= 0; j--) { | |
| 366 if (!this.state_[AppState.Field.RECENT_DESTINATION_IDS] || | |
| 367 dest.id == this.state_[AppState.Field.RECENT_DESTINATION_IDS][j]) | |
| 368 shiftDestination = false; | |
| 369 } | |
| 370 // Shift destination i-1 to i. | |
| 371 if (shiftDestination) { | |
| 372 this.state_[AppState.Field.RECENT_DESTINATION_IDS][i] = | |
| 373 this.state_[AppState.Field.RECENT_DESTINATION_IDS][i - 1]; | |
| 374 this.state_[AppState.Field.RECENT_DESTINATION_ACCOUNTS][i] = | |
| 375 this.state_[AppState.Field.RECENT_DESTINATION_ACCOUNTS][i - 1]; | |
| 376 this.state_[AppState.Field.RECENT_DESTINATION_ORIGINS][i] = | |
| 377 this.state_[AppState.Field.RECENT_DESTINATION_ORIGINS][i - 1]; | |
| 378 this.state_[AppState.Field.RECENT_DESTINATION_CAPABILITIES][i] = | |
| 379 this.state_[AppState.Field.RECENT_DESTINATION_CAPABILITIES][ | |
| 380 i - 1]; | |
| 381 this.state_[AppState.Field.RECENT_DESTINATION_NAMES][i] = | |
| 382 this.state_[AppState.Field.RECENT_DESTINATION_NAMES][i - 1]; | |
| 383 this.state_[AppState.Field.RECENT_DESTINATION_EXTENSION_IDS][i] = | |
| 384 this.state_[AppState.Field.RECENT_DESTINATION_EXTENSION_IDS][ | |
| 385 i - 1]; | |
| 386 this.state_[AppState.Field.RECENT_DESTINATION_EXTENSION_NAMES][i] = | |
| 387 this.state_[AppState.Field.RECENT_DESTINATION_EXTENSION_NAMES][ | |
| 388 i - 1]; | |
| 389 } | |
| 390 } | |
| 391 // Set the most recent destination (currently selected destination) to | |
| 392 // dest. | |
| 393 this.state_[AppState.Field.RECENT_DESTINATION_IDS][0] = dest.id; | |
| 394 this.state_[AppState.Field.RECENT_DESTINATION_ACCOUNTS][0] = | |
| 395 dest.account || ''; | |
| 396 this.state_[AppState.Field.RECENT_DESTINATION_ORIGINS][0] = | |
| 397 dest.origin; | |
| 398 this.state_[AppState.Field.RECENT_DESTINATION_CAPABILITIES][0] = | |
| 399 dest.capabilities || ''; | |
| 400 this.state_[AppState.Field.RECENT_DESTINATION_NAMES][0] = | |
| 401 dest.name || ''; | |
| 402 this.state_[AppState.Field.RECENT_DESTINATION_EXTENSION_IDS][0] = | |
| 403 dest.extensionId || ''; | |
| 404 this.state_[AppState.Field.RECENT_DESTINATION_EXTENSION_NAMES][0] = | |
| 405 dest.extensionName || '';*/ | |
| 210 this.persist_(); | 406 this.persist_(); |
| 211 }, | 407 }, |
| 212 | 408 |
| 213 /** | 409 /** |
| 214 * Persists whether the GCP promotion has been dismissed. | 410 * Persists whether the GCP promotion has been dismissed. |
| 215 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been | 411 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been |
| 216 * dismissed. | 412 * dismissed. |
| 217 */ | 413 */ |
| 218 persistIsGcpPromoDismissed: function(isGcpPromoDismissed) { | 414 persistIsGcpPromoDismissed: function(isGcpPromoDismissed) { |
| 219 if (!this.isInitialized_) | 415 if (!this.isInitialized_) |
| 220 return; | 416 return; |
| 221 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = isGcpPromoDismissed; | 417 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = isGcpPromoDismissed; |
| 222 this.persist_(); | 418 this.persist_(); |
| 223 }, | 419 }, |
| 224 | 420 |
| 225 /** | 421 /** |
| 226 * Calls into the native layer to persist the application state. | 422 * Calls into the native layer to persist the application state. |
| 227 * @private | 423 * @private |
| 228 */ | 424 */ |
| 229 persist_: function() { | 425 persist_: function() { |
| 230 chrome.send(AppState.NATIVE_FUNCTION_NAME_, | 426 chrome.send(AppState.NATIVE_FUNCTION_NAME_, |
| 231 [JSON.stringify(this.state_)]); | 427 [JSON.stringify(this.state_)]); |
| 232 } | 428 } |
| 233 }; | 429 }; |
| 234 | 430 |
| 235 return { | 431 return { |
| 236 AppState: AppState | 432 AppState: AppState |
| 237 }; | 433 }; |
| 238 }); | 434 }); |
| OLD | NEW |