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 17 matching lines...) Expand all Loading... | |
28 this.isInitialized_ = false; | 28 this.isInitialized_ = false; |
29 }; | 29 }; |
30 | 30 |
31 /** | 31 /** |
32 * Enumeration of field names for serialized app state. | 32 * Enumeration of field names for serialized app state. |
33 * @enum {string} | 33 * @enum {string} |
34 */ | 34 */ |
35 AppState.Field = { | 35 AppState.Field = { |
36 VERSION: 'version', | 36 VERSION: 'version', |
37 SELECTED_DESTINATION_ID: 'selectedDestinationId', | 37 SELECTED_DESTINATION_ID: 'selectedDestinationId', |
38 SELECTED_DESTINATION_ACCOUNT: 'selectedDestinationAccount', | |
38 SELECTED_DESTINATION_ORIGIN: 'selectedDestinationOrigin', | 39 SELECTED_DESTINATION_ORIGIN: 'selectedDestinationOrigin', |
39 SELECTED_DESTINATION_CAPABILITIES: 'selectedDestinationCapabilities', | 40 SELECTED_DESTINATION_CAPABILITIES: 'selectedDestinationCapabilities', |
40 SELECTED_DESTINATION_NAME: 'selectedDestinationName', | 41 SELECTED_DESTINATION_NAME: 'selectedDestinationName', |
41 IS_SELECTED_DESTINATION_LOCAL: 'isSelectedDestinationLocal', // Deprecated | |
42 IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', | 42 IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', |
43 MARGINS_TYPE: 'marginsType', | 43 MARGINS_TYPE: 'marginsType', |
44 CUSTOM_MARGINS: 'customMargins', | 44 CUSTOM_MARGINS: 'customMargins', |
45 IS_COLOR_ENABLED: 'isColorEnabled', | 45 IS_COLOR_ENABLED: 'isColorEnabled', |
46 IS_DUPLEX_ENABLED: 'isDuplexEnabled', | 46 IS_DUPLEX_ENABLED: 'isDuplexEnabled', |
47 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', | 47 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', |
48 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', | 48 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', |
49 IS_COLLATE_ENABLED: 'isCollateEnabled', | 49 IS_COLLATE_ENABLED: 'isCollateEnabled', |
50 IS_CSS_BACKGROUND_ENABLED: 'isCssBackgroundEnabled' | 50 IS_CSS_BACKGROUND_ENABLED: 'isCssBackgroundEnabled' |
51 }; | 51 }; |
(...skipping 14 matching lines...) Expand all Loading... | |
66 * @private | 66 * @private |
67 */ | 67 */ |
68 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; | 68 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; |
69 | 69 |
70 AppState.prototype = { | 70 AppState.prototype = { |
71 /** @return {?string} ID of the selected destination. */ | 71 /** @return {?string} ID of the selected destination. */ |
72 get selectedDestinationId() { | 72 get selectedDestinationId() { |
73 return this.state_[AppState.Field.SELECTED_DESTINATION_ID]; | 73 return this.state_[AppState.Field.SELECTED_DESTINATION_ID]; |
74 }, | 74 }, |
75 | 75 |
76 /** @return {?string} Account the selected destination is registered for. */ | |
77 get selectedDestinationAccount() { | |
78 return this.state_[AppState.Field.SELECTED_DESTINATION_ACCOUNT]; | |
79 }, | |
80 | |
76 /** @return {?string} Origin of the selected destination. */ | 81 /** @return {?string} Origin of the selected destination. */ |
77 get selectedDestinationOrigin() { | 82 get selectedDestinationOrigin() { |
78 return this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN]; | 83 return this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN]; |
79 }, | 84 }, |
80 | 85 |
81 /** @return {?print_preview.Cdd} CDD of the selected destination. */ | 86 /** @return {?print_preview.Cdd} CDD of the selected destination. */ |
82 get selectedDestinationCapabilities() { | 87 get selectedDestinationCapabilities() { |
83 return this.state_[AppState.Field.SELECTED_DESTINATION_CAPBILITIES]; | 88 return this.state_[AppState.Field.SELECTED_DESTINATION_CAPABILITIES]; |
84 }, | 89 }, |
85 | 90 |
86 /** @return {?string} Name of the selected destination. */ | 91 /** @return {?string} Name of the selected destination. */ |
87 get selectedDestinationName() { | 92 get selectedDestinationName() { |
88 return this.state_[AppState.Field.SELECTED_DESTINATION_NAME]; | 93 return this.state_[AppState.Field.SELECTED_DESTINATION_NAME]; |
89 }, | 94 }, |
90 | 95 |
91 /** @return {boolean} Whether the GCP promotion has been dismissed. */ | 96 /** @return {boolean} Whether the GCP promotion has been dismissed. */ |
92 get isGcpPromoDismissed() { | 97 get isGcpPromoDismissed() { |
93 return this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED]; | 98 return this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED]; |
(...skipping 19 matching lines...) Expand all Loading... | |
113 } else { | 118 } else { |
114 return this.state_[field]; | 119 return this.state_[field]; |
115 } | 120 } |
116 }, | 121 }, |
117 | 122 |
118 /** | 123 /** |
119 * Initializes the app state from a serialized string returned by the native | 124 * Initializes the app state from a serialized string returned by the native |
120 * layer. | 125 * layer. |
121 * @param {?string} serializedAppStateStr Serialized string representation | 126 * @param {?string} serializedAppStateStr Serialized string representation |
122 * of the app state. | 127 * of the app state. |
128 * @param {?string} systemDefaultDestinationId ID of the system default | |
129 * destination. | |
123 */ | 130 */ |
124 init: function(serializedAppStateStr) { | 131 init: function(serializedAppStateStr, systemDefaultDestinationId) { |
125 if (serializedAppStateStr) { | 132 if (serializedAppStateStr) { |
126 var state = JSON.parse(serializedAppStateStr); | 133 var state = JSON.parse(serializedAppStateStr); |
127 if (state[AppState.Field.VERSION] == AppState.VERSION_) { | 134 if (state[AppState.Field.VERSION] == AppState.VERSION_) { |
128 if (state.hasOwnProperty( | |
129 AppState.Field.IS_SELECTED_DESTINATION_LOCAL)) { | |
130 state[AppState.Field.SELECTED_DESTINATION_ORIGIN] = | |
131 state[AppState.Field.IS_SELECTED_DESTINATION_LOCAL] ? | |
132 print_preview.Destination.Origin.LOCAL : | |
133 print_preview.Destination.Origin.COOKIES; | |
134 delete state[AppState.Field.IS_SELECTED_DESTINATION_LOCAL]; | |
135 } | |
136 this.state_ = state; | 135 this.state_ = state; |
137 } | 136 } |
138 } else { | 137 } else { |
139 // Set some state defaults. | 138 // Set some state defaults. |
140 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = false; | 139 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = false; |
141 } | 140 } |
141 // Default to system destination, if no destination was selected. | |
142 if (!this.state_[AppState.Field.SELECTED_DESTINATION_ID] || | |
143 !this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN]) { | |
144 if (systemDefaultDestinationId) { | |
145 this.state_[AppState.Field.SELECTED_DESTINATION_ID] = | |
Vitaly Buka (NO REVIEWS)
2014/04/11 02:32:57
this could be separate CL
Toscano
2014/04/11 04:24:00
agreed
Aleksey Shlyapnikov
2014/04/11 19:09:29
Done.
Aleksey Shlyapnikov
2014/04/11 19:09:29
Done.
| |
146 systemDefaultDestinationId; | |
147 this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN] = | |
148 print_preview.Destination.Origin.LOCAL; | |
149 } | |
150 } | |
142 }, | 151 }, |
143 | 152 |
144 /** | 153 /** |
145 * Sets to initialized state. Now object will accept persist requests. | 154 * Sets to initialized state. Now object will accept persist requests. |
146 */ | 155 */ |
147 setInitialized: function() { | 156 setInitialized: function() { |
148 this.isInitialized_ = true; | 157 this.isInitialized_ = true; |
149 }, | 158 }, |
150 | 159 |
151 /** | 160 /** |
(...skipping 13 matching lines...) Expand all Loading... | |
165 }, | 174 }, |
166 | 175 |
167 /** | 176 /** |
168 * Persists the selected destination. | 177 * Persists the selected destination. |
169 * @param {!print_preview.Destination} dest Destination to persist. | 178 * @param {!print_preview.Destination} dest Destination to persist. |
170 */ | 179 */ |
171 persistSelectedDestination: function(dest) { | 180 persistSelectedDestination: function(dest) { |
172 if (!this.isInitialized_) | 181 if (!this.isInitialized_) |
173 return; | 182 return; |
174 this.state_[AppState.Field.SELECTED_DESTINATION_ID] = dest.id; | 183 this.state_[AppState.Field.SELECTED_DESTINATION_ID] = dest.id; |
184 this.state_[AppState.Field.SELECTED_DESTINATION_ACCOUNT] = dest.account; | |
175 this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN] = dest.origin; | 185 this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN] = dest.origin; |
176 this.state_[AppState.Field.SELECTED_DESTINATION_CAPBILITIES] = | 186 this.state_[AppState.Field.SELECTED_DESTINATION_CAPABILITIES] = |
177 dest.capabilities; | 187 dest.capabilities; |
178 this.state_[AppState.Field.SELECTED_DESTINATION_NAME] = dest.displayName; | 188 this.state_[AppState.Field.SELECTED_DESTINATION_NAME] = dest.displayName; |
179 this.persist_(); | 189 this.persist_(); |
180 }, | 190 }, |
181 | 191 |
182 /** | 192 /** |
183 * Persists whether the GCP promotion has been dismissed. | 193 * Persists whether the GCP promotion has been dismissed. |
184 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been | 194 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been |
185 * dismissed. | 195 * dismissed. |
186 */ | 196 */ |
(...skipping 11 matching lines...) Expand all Loading... | |
198 persist_: function() { | 208 persist_: function() { |
199 chrome.send(AppState.NATIVE_FUNCTION_NAME_, | 209 chrome.send(AppState.NATIVE_FUNCTION_NAME_, |
200 [JSON.stringify(this.state_)]); | 210 [JSON.stringify(this.state_)]); |
201 } | 211 } |
202 }; | 212 }; |
203 | 213 |
204 return { | 214 return { |
205 AppState: AppState | 215 AppState: AppState |
206 }; | 216 }; |
207 }); | 217 }); |
OLD | NEW |