| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } else { | 142 } else { |
| 143 return this.state_[field]; | 143 return this.state_[field]; |
| 144 } | 144 } |
| 145 }, | 145 }, |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * Initializes the app state from a serialized string returned by the native | 148 * Initializes the app state from a serialized string returned by the native |
| 149 * layer. | 149 * layer. |
| 150 * @param {?string} serializedAppStateStr Serialized string representation | 150 * @param {?string} serializedAppStateStr Serialized string representation |
| 151 * of the app state. | 151 * of the app state. |
| 152 * @param {?string} systemDefaultDestinationId ID of the system default | |
| 153 * destination. | |
| 154 */ | 152 */ |
| 155 init: function(serializedAppStateStr, systemDefaultDestinationId) { | 153 init: function(serializedAppStateStr) { |
| 156 if (serializedAppStateStr) { | 154 if (serializedAppStateStr) { |
| 157 try { | 155 try { |
| 158 var state = JSON.parse(serializedAppStateStr); | 156 var state = JSON.parse(serializedAppStateStr); |
| 159 if (state[AppState.Field.VERSION] == AppState.VERSION_) { | 157 if (state[AppState.Field.VERSION] == AppState.VERSION_) { |
| 160 this.state_ = state; | 158 this.state_ = state; |
| 161 } | 159 } |
| 162 } catch(e) { | 160 } catch(e) { |
| 163 console.error('Unable to parse state: ' + e); | 161 console.error('Unable to parse state: ' + e); |
| 164 // Proceed with default state. | 162 // Proceed with default state. |
| 165 } | 163 } |
| 166 } else { | 164 } else { |
| 167 // Set some state defaults. | 165 // Set some state defaults. |
| 168 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = false; | 166 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = false; |
| 169 } | 167 } |
| 170 // Default to system destination, if no destination was selected. | |
| 171 if (!this.state_[AppState.Field.SELECTED_DESTINATION_ID] || | |
| 172 !this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN]) { | |
| 173 if (systemDefaultDestinationId) { | |
| 174 this.state_[AppState.Field.SELECTED_DESTINATION_ID] = | |
| 175 systemDefaultDestinationId; | |
| 176 this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN] = | |
| 177 print_preview.Destination.Origin.LOCAL; | |
| 178 this.state_[AppState.Field.SELECTED_DESTINATION_ACCOUNT] = ''; | |
| 179 } | |
| 180 } | |
| 181 }, | 168 }, |
| 182 | 169 |
| 183 /** | 170 /** |
| 184 * Sets to initialized state. Now object will accept persist requests. | 171 * Sets to initialized state. Now object will accept persist requests. |
| 185 */ | 172 */ |
| 186 setInitialized: function() { | 173 setInitialized: function() { |
| 187 this.isInitialized_ = true; | 174 this.isInitialized_ = true; |
| 188 }, | 175 }, |
| 189 | 176 |
| 190 /** | 177 /** |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 persist_: function() { | 229 persist_: function() { |
| 243 chrome.send(AppState.NATIVE_FUNCTION_NAME_, | 230 chrome.send(AppState.NATIVE_FUNCTION_NAME_, |
| 244 [JSON.stringify(this.state_)]); | 231 [JSON.stringify(this.state_)]); |
| 245 } | 232 } |
| 246 }; | 233 }; |
| 247 | 234 |
| 248 return { | 235 return { |
| 249 AppState: AppState | 236 AppState: AppState |
| 250 }; | 237 }; |
| 251 }); | 238 }); |
| OLD | NEW |