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 * Origin of the selected destination. |
22 * @type {?boolean} | 22 * @type {?string} |
23 * @private | 23 * @private |
24 */ | 24 */ |
25 this.isSelectedDestinationLocal_ = null; | 25 this.selectedDestinationOrigin_ = null; |
26 | 26 |
27 /** | 27 /** |
28 * Whether the GCP promotion has been dismissed. | 28 * Whether the GCP promotion has been dismissed. |
29 * @type {boolean} | 29 * @type {boolean} |
30 * @private | 30 * @private |
31 */ | 31 */ |
32 this.isGcpPromoDismissed_ = true; | 32 this.isGcpPromoDismissed_ = true; |
33 | 33 |
34 /** | 34 /** |
35 * Margins type. | 35 * Margins type. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 AppState.VERSION_ = 2; | 98 AppState.VERSION_ = 2; |
99 | 99 |
100 /** | 100 /** |
101 * Enumeration of field names for serialized app state. | 101 * Enumeration of field names for serialized app state. |
102 * @enum {string} | 102 * @enum {string} |
103 * @private | 103 * @private |
104 */ | 104 */ |
105 AppState.Field_ = { | 105 AppState.Field_ = { |
106 VERSION: 'version', | 106 VERSION: 'version', |
107 SELECTED_DESTINATION_ID: 'selectedDestinationId', | 107 SELECTED_DESTINATION_ID: 'selectedDestinationId', |
108 IS_SELECTED_DESTINATION_LOCAL: 'isSelectedDestinationLocal', | 108 SELECTED_DESTINATION_ORIGIN: 'selectedDestinationOrigin', |
| 109 IS_SELECTED_DESTINATION_LOCAL: 'isSelectedDestinationLocal', // Deprecated |
109 IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', | 110 IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', |
110 MARGINS_TYPE: 'marginsType', | 111 MARGINS_TYPE: 'marginsType', |
111 CUSTOM_MARGINS: 'customMargins', | 112 CUSTOM_MARGINS: 'customMargins', |
112 IS_COLOR_ENABLED: 'isColorEnabled', | 113 IS_COLOR_ENABLED: 'isColorEnabled', |
113 IS_DUPLEX_ENABLED: 'isDuplexEnabled', | 114 IS_DUPLEX_ENABLED: 'isDuplexEnabled', |
114 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', | 115 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', |
115 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', | 116 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', |
116 IS_COLLATE_ENABLED: 'isCollateEnabled', | 117 IS_COLLATE_ENABLED: 'isCollateEnabled', |
117 IS_CSS_BACKGROUND_ENABLED: 'isCssBackgroundEnabled' | 118 IS_CSS_BACKGROUND_ENABLED: 'isCssBackgroundEnabled' |
118 }; | 119 }; |
119 | 120 |
120 /** | 121 /** |
121 * Name of C++ layer function to persist app state. | 122 * Name of C++ layer function to persist app state. |
122 * @type {string} | 123 * @type {string} |
123 * @const | 124 * @const |
124 * @private | 125 * @private |
125 */ | 126 */ |
126 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; | 127 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; |
127 | 128 |
128 AppState.prototype = { | 129 AppState.prototype = { |
129 /** @return {?string} ID of the selected destination. */ | 130 /** @return {?string} ID of the selected destination. */ |
130 get selectedDestinationId() { | 131 get selectedDestinationId() { |
131 return this.selectedDestinationId_; | 132 return this.selectedDestinationId_; |
132 }, | 133 }, |
133 | 134 |
134 /** @return {?boolean} Whether the selected destination is local. */ | 135 /** @return {?string} Origin of the selected destination. */ |
135 get isSelectedDestinationLocal() { | 136 get selectedDestinationOrigin() { |
136 return this.isSelectedDestinationLocal_; | 137 return this.selectedDestinationOrigin_; |
137 }, | 138 }, |
138 | 139 |
139 /** @return {boolean} Whether the GCP promotion has been dismissed. */ | 140 /** @return {boolean} Whether the GCP promotion has been dismissed. */ |
140 get isGcpPromoDismissed() { | 141 get isGcpPromoDismissed() { |
141 return this.isGcpPromoDismissed_; | 142 return this.isGcpPromoDismissed_; |
142 }, | 143 }, |
143 | 144 |
144 /** @return {print_preview.ticket_items.MarginsType.Value} Margins type. */ | 145 /** @return {print_preview.ticket_items.MarginsType.Value} Margins type. */ |
145 get marginsType() { | 146 get marginsType() { |
146 return this.marginsType_; | 147 return this.marginsType_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 * of the app state. | 189 * of the app state. |
189 */ | 190 */ |
190 init: function(serializedAppStateStr) { | 191 init: function(serializedAppStateStr) { |
191 if (!serializedAppStateStr) { | 192 if (!serializedAppStateStr) { |
192 // Set some state defaults. | 193 // Set some state defaults. |
193 this.isGcpPromoDismissed_ = false; | 194 this.isGcpPromoDismissed_ = false; |
194 return; | 195 return; |
195 } | 196 } |
196 | 197 |
197 var state = JSON.parse(serializedAppStateStr); | 198 var state = JSON.parse(serializedAppStateStr); |
198 if (state[AppState.Field_.VERSION] == 2) { | 199 if (state[AppState.Field_.VERSION] == AppState.VERSION_) { |
199 this.selectedDestinationId_ = | 200 this.selectedDestinationId_ = |
200 state[AppState.Field_.SELECTED_DESTINATION_ID] || null; | 201 state[AppState.Field_.SELECTED_DESTINATION_ID] || null; |
201 if (state.hasOwnProperty( | 202 if (state.hasOwnProperty( |
202 AppState.Field_.IS_SELECTED_DESTINATION_LOCAL)) { | 203 AppState.Field_.IS_SELECTED_DESTINATION_LOCAL)) { |
203 this.isSelectedDestinationLocal_ = | 204 this.selectedDestinationOrigin_ = |
204 state[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL]; | 205 state[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL] ? |
| 206 print_preview.Destination.Origin.LOCAL : |
| 207 print_preview.Destination.Origin.COOKIES; |
| 208 } else { |
| 209 this.selectedDestinationOrigin_ = |
| 210 state[AppState.Field_.SELECTED_DESTINATION_ORIGIN] || null; |
205 } | 211 } |
| 212 |
206 this.isGcpPromoDismissed_ = | 213 this.isGcpPromoDismissed_ = |
207 state[AppState.Field_.IS_GCP_PROMO_DISMISSED] || false; | 214 state[AppState.Field_.IS_GCP_PROMO_DISMISSED] || false; |
208 if (state.hasOwnProperty(AppState.Field_.MARGINS_TYPE)) { | 215 if (state.hasOwnProperty(AppState.Field_.MARGINS_TYPE)) { |
209 this.marginsType_ = state[AppState.Field_.MARGINS_TYPE]; | 216 this.marginsType_ = state[AppState.Field_.MARGINS_TYPE]; |
210 } | 217 } |
211 if (state[AppState.Field_.CUSTOM_MARGINS]) { | 218 if (state[AppState.Field_.CUSTOM_MARGINS]) { |
212 this.customMargins_ = print_preview.Margins.parse( | 219 this.customMargins_ = print_preview.Margins.parse( |
213 state[AppState.Field_.CUSTOM_MARGINS]); | 220 state[AppState.Field_.CUSTOM_MARGINS]); |
214 } | 221 } |
215 if (state.hasOwnProperty(AppState.Field_.IS_COLOR_ENABLED)) { | 222 if (state.hasOwnProperty(AppState.Field_.IS_COLOR_ENABLED)) { |
(...skipping 19 matching lines...) Expand all Loading... |
235 } | 242 } |
236 } | 243 } |
237 }, | 244 }, |
238 | 245 |
239 /** | 246 /** |
240 * Persists the selected destination. | 247 * Persists the selected destination. |
241 * @param {!print_preview.Destination} dest Destination to persist. | 248 * @param {!print_preview.Destination} dest Destination to persist. |
242 */ | 249 */ |
243 persistSelectedDestination: function(dest) { | 250 persistSelectedDestination: function(dest) { |
244 this.selectedDestinationId_ = dest.id; | 251 this.selectedDestinationId_ = dest.id; |
245 this.isSelectedDestinationLocal_ = dest.isLocal; | 252 this.selectedDestinationOrigin_ = dest.origin; |
246 this.persist_(); | 253 this.persist_(); |
247 }, | 254 }, |
248 | 255 |
249 /** | 256 /** |
250 * Persists whether the GCP promotion has been dismissed. | 257 * Persists whether the GCP promotion has been dismissed. |
251 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been | 258 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been |
252 * dismissed. | 259 * dismissed. |
253 */ | 260 */ |
254 persistIsGcpPromoDismissed: function(isGcpPromoDismissed) { | 261 persistIsGcpPromoDismissed: function(isGcpPromoDismissed) { |
255 this.isGcpPromoDismissed_ = isGcpPromoDismissed; | 262 this.isGcpPromoDismissed_ = isGcpPromoDismissed; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 339 |
333 /** | 340 /** |
334 * Calls into the native layer to persist the application state. | 341 * Calls into the native layer to persist the application state. |
335 * @private | 342 * @private |
336 */ | 343 */ |
337 persist_: function() { | 344 persist_: function() { |
338 var obj = {}; | 345 var obj = {}; |
339 obj[AppState.Field_.VERSION] = AppState.VERSION_; | 346 obj[AppState.Field_.VERSION] = AppState.VERSION_; |
340 obj[AppState.Field_.SELECTED_DESTINATION_ID] = | 347 obj[AppState.Field_.SELECTED_DESTINATION_ID] = |
341 this.selectedDestinationId_; | 348 this.selectedDestinationId_; |
342 obj[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL] = | 349 obj[AppState.Field_.SELECTED_DESTINATION_ORIGIN] = |
343 this.isSelectedDestinationLocal_; | 350 this.selectedDestinationOrigin_; |
344 obj[AppState.Field_.IS_GCP_PROMO_DISMISSED] = this.isGcpPromoDismissed_; | 351 obj[AppState.Field_.IS_GCP_PROMO_DISMISSED] = this.isGcpPromoDismissed_; |
345 obj[AppState.Field_.MARGINS_TYPE] = this.marginsType_; | 352 obj[AppState.Field_.MARGINS_TYPE] = this.marginsType_; |
346 if (this.customMargins_) { | 353 if (this.customMargins_) { |
347 obj[AppState.Field_.CUSTOM_MARGINS] = this.customMargins_.serialize(); | 354 obj[AppState.Field_.CUSTOM_MARGINS] = this.customMargins_.serialize(); |
348 } | 355 } |
349 obj[AppState.Field_.IS_COLOR_ENABLED] = this.isColorEnabled_; | 356 obj[AppState.Field_.IS_COLOR_ENABLED] = this.isColorEnabled_; |
350 obj[AppState.Field_.IS_DUPLEX_ENABLED] = this.isDuplexEnabled_; | 357 obj[AppState.Field_.IS_DUPLEX_ENABLED] = this.isDuplexEnabled_; |
351 obj[AppState.Field_.IS_HEADER_FOOTER_ENABLED] = | 358 obj[AppState.Field_.IS_HEADER_FOOTER_ENABLED] = |
352 this.isHeaderFooterEnabled_; | 359 this.isHeaderFooterEnabled_; |
353 obj[AppState.Field_.IS_LANDSCAPE_ENABLED] = this.isLandscapeEnabled_; | 360 obj[AppState.Field_.IS_LANDSCAPE_ENABLED] = this.isLandscapeEnabled_; |
354 obj[AppState.Field_.IS_COLLATE_ENABLED] = this.isCollateEnabled_; | 361 obj[AppState.Field_.IS_COLLATE_ENABLED] = this.isCollateEnabled_; |
355 obj[AppState.Field_.IS_CSS_BACKGROUND_ENABLED] = | 362 obj[AppState.Field_.IS_CSS_BACKGROUND_ENABLED] = |
356 this.isCssBackgroundEnabled_; | 363 this.isCssBackgroundEnabled_; |
357 chrome.send(AppState.NATIVE_FUNCTION_NAME_, [JSON.stringify(obj)]); | 364 chrome.send(AppState.NATIVE_FUNCTION_NAME_, [JSON.stringify(obj)]); |
358 } | 365 } |
359 }; | 366 }; |
360 | 367 |
361 return { | 368 return { |
362 AppState: AppState | 369 AppState: AppState |
363 }; | 370 }; |
364 }); | 371 }); |
OLD | NEW |