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