Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/resources/print_preview/data/app_state.js

Issue 14340003: Rename AuthType to Origin of destination. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename AuthType to Origin. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 this.isCssBackgroundEnabled_ = null; 88 this.isCssBackgroundEnabled_ = null;
89 }; 89 };
90 90
91 /** 91 /**
92 * Current version of the app state. This value helps to understand how to 92 * Current version of the app state. This value helps to understand how to
93 * parse earlier versions of the app state. 93 * parse earlier versions of the app state.
94 * @type {number} 94 * @type {number}
95 * @const 95 * @const
96 * @private 96 * @private
97 */ 97 */
98 AppState.VERSION_ = 2; 98 AppState.VERSION_ = 3;
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_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', 109 IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed',
110 MARGINS_TYPE: 'marginsType', 110 MARGINS_TYPE: 'marginsType',
111 CUSTOM_MARGINS: 'customMargins', 111 CUSTOM_MARGINS: 'customMargins',
112 IS_COLOR_ENABLED: 'isColorEnabled', 112 IS_COLOR_ENABLED: 'isColorEnabled',
113 IS_DUPLEX_ENABLED: 'isDuplexEnabled', 113 IS_DUPLEX_ENABLED: 'isDuplexEnabled',
114 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', 114 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled',
115 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', 115 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled',
116 IS_COLLATE_ENABLED: 'isCollateEnabled', 116 IS_COLLATE_ENABLED: 'isCollateEnabled',
117 IS_CSS_BACKGROUND_ENABLED: 'isCssBackgroundEnabled' 117 IS_CSS_BACKGROUND_ENABLED: 'isCssBackgroundEnabled'
118 }; 118 };
119 119
120 /** 120 /**
121 * Name of C++ layer function to persist app state. 121 * Name of C++ layer function to persist app state.
122 * @type {string} 122 * @type {string}
123 * @const 123 * @const
124 * @private 124 * @private
125 */ 125 */
126 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState'; 126 AppState.NATIVE_FUNCTION_NAME_ = 'saveAppState';
127 127
128 AppState.prototype = { 128 AppState.prototype = {
129 /** @return {?string} ID of the selected destination. */ 129 /** @return {?string} ID of the selected destination. */
130 get selectedDestinationId() { 130 get selectedDestinationId() {
131 return this.selectedDestinationId_; 131 return this.selectedDestinationId_;
132 }, 132 },
133 133
134 /** @return {?boolean} Whether the selected destination is local. */ 134 /** @return {?string} Origin of the selected destination. */
135 get isSelectedDestinationLocal() { 135 get selectedDestinationOrigin() {
136 return this.isSelectedDestinationLocal_; 136 return this.selectedDestinationOrigin_;
137 }, 137 },
138 138
139 /** @return {boolean} Whether the GCP promotion has been dismissed. */ 139 /** @return {boolean} Whether the GCP promotion has been dismissed. */
140 get isGcpPromoDismissed() { 140 get isGcpPromoDismissed() {
141 return this.isGcpPromoDismissed_; 141 return this.isGcpPromoDismissed_;
142 }, 142 },
143 143
144 /** @return {print_preview.ticket_items.MarginsType.Value} Margins type. */ 144 /** @return {print_preview.ticket_items.MarginsType.Value} Margins type. */
145 get marginsType() { 145 get marginsType() {
146 return this.marginsType_; 146 return this.marginsType_;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 * of the app state. 188 * of the app state.
189 */ 189 */
190 init: function(serializedAppStateStr) { 190 init: function(serializedAppStateStr) {
191 if (!serializedAppStateStr) { 191 if (!serializedAppStateStr) {
192 // Set some state defaults. 192 // Set some state defaults.
193 this.isGcpPromoDismissed_ = false; 193 this.isGcpPromoDismissed_ = false;
194 return; 194 return;
195 } 195 }
196 196
197 var state = JSON.parse(serializedAppStateStr); 197 var state = JSON.parse(serializedAppStateStr);
198 if (state[AppState.Field_.VERSION] == 2) { 198 if (state[AppState.Field_.VERSION] == AppState.VERSION_) {
Toscano 2013/04/18 19:26:41 You'll have to handle an AppState whose version is
Vitaly Buka (NO REVIEWS) 2013/04/18 20:48:23 Done.
199 this.selectedDestinationId_ = 199 this.selectedDestinationId_ =
200 state[AppState.Field_.SELECTED_DESTINATION_ID] || null; 200 state[AppState.Field_.SELECTED_DESTINATION_ID] || null;
201 if (state.hasOwnProperty( 201 this.selectedDestinationOrigin_ =
202 AppState.Field_.IS_SELECTED_DESTINATION_LOCAL)) { 202 state[AppState.Field_.SELECTED_DESTINATION_ORIGIN] || null;
203 this.isSelectedDestinationLocal_ = 203
204 state[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL];
205 }
206 this.isGcpPromoDismissed_ = 204 this.isGcpPromoDismissed_ =
207 state[AppState.Field_.IS_GCP_PROMO_DISMISSED] || false; 205 state[AppState.Field_.IS_GCP_PROMO_DISMISSED] || false;
208 if (state.hasOwnProperty(AppState.Field_.MARGINS_TYPE)) { 206 if (state.hasOwnProperty(AppState.Field_.MARGINS_TYPE)) {
209 this.marginsType_ = state[AppState.Field_.MARGINS_TYPE]; 207 this.marginsType_ = state[AppState.Field_.MARGINS_TYPE];
210 } 208 }
211 if (state[AppState.Field_.CUSTOM_MARGINS]) { 209 if (state[AppState.Field_.CUSTOM_MARGINS]) {
212 this.customMargins_ = print_preview.Margins.parse( 210 this.customMargins_ = print_preview.Margins.parse(
213 state[AppState.Field_.CUSTOM_MARGINS]); 211 state[AppState.Field_.CUSTOM_MARGINS]);
214 } 212 }
215 if (state.hasOwnProperty(AppState.Field_.IS_COLOR_ENABLED)) { 213 if (state.hasOwnProperty(AppState.Field_.IS_COLOR_ENABLED)) {
(...skipping 19 matching lines...) Expand all
235 } 233 }
236 } 234 }
237 }, 235 },
238 236
239 /** 237 /**
240 * Persists the selected destination. 238 * Persists the selected destination.
241 * @param {!print_preview.Destination} dest Destination to persist. 239 * @param {!print_preview.Destination} dest Destination to persist.
242 */ 240 */
243 persistSelectedDestination: function(dest) { 241 persistSelectedDestination: function(dest) {
244 this.selectedDestinationId_ = dest.id; 242 this.selectedDestinationId_ = dest.id;
245 this.isSelectedDestinationLocal_ = dest.isLocal; 243 this.selectedDestinationOrigin_ = dest.origin;
246 this.persist_(); 244 this.persist_();
247 }, 245 },
248 246
249 /** 247 /**
250 * Persists whether the GCP promotion has been dismissed. 248 * Persists whether the GCP promotion has been dismissed.
251 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been 249 * @param {boolean} isGcpPromoDismissed Whether the GCP promotion has been
252 * dismissed. 250 * dismissed.
253 */ 251 */
254 persistIsGcpPromoDismissed: function(isGcpPromoDismissed) { 252 persistIsGcpPromoDismissed: function(isGcpPromoDismissed) {
255 this.isGcpPromoDismissed_ = isGcpPromoDismissed; 253 this.isGcpPromoDismissed_ = isGcpPromoDismissed;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 330
333 /** 331 /**
334 * Calls into the native layer to persist the application state. 332 * Calls into the native layer to persist the application state.
335 * @private 333 * @private
336 */ 334 */
337 persist_: function() { 335 persist_: function() {
338 var obj = {}; 336 var obj = {};
339 obj[AppState.Field_.VERSION] = AppState.VERSION_; 337 obj[AppState.Field_.VERSION] = AppState.VERSION_;
340 obj[AppState.Field_.SELECTED_DESTINATION_ID] = 338 obj[AppState.Field_.SELECTED_DESTINATION_ID] =
341 this.selectedDestinationId_; 339 this.selectedDestinationId_;
342 obj[AppState.Field_.IS_SELECTED_DESTINATION_LOCAL] = 340 obj[AppState.Field_.SELECTED_DESTINATION_ORIGIN] =
343 this.isSelectedDestinationLocal_; 341 this.selectedDestinationOrigin_;
344 obj[AppState.Field_.IS_GCP_PROMO_DISMISSED] = this.isGcpPromoDismissed_; 342 obj[AppState.Field_.IS_GCP_PROMO_DISMISSED] = this.isGcpPromoDismissed_;
345 obj[AppState.Field_.MARGINS_TYPE] = this.marginsType_; 343 obj[AppState.Field_.MARGINS_TYPE] = this.marginsType_;
346 if (this.customMargins_) { 344 if (this.customMargins_) {
347 obj[AppState.Field_.CUSTOM_MARGINS] = this.customMargins_.serialize(); 345 obj[AppState.Field_.CUSTOM_MARGINS] = this.customMargins_.serialize();
348 } 346 }
349 obj[AppState.Field_.IS_COLOR_ENABLED] = this.isColorEnabled_; 347 obj[AppState.Field_.IS_COLOR_ENABLED] = this.isColorEnabled_;
350 obj[AppState.Field_.IS_DUPLEX_ENABLED] = this.isDuplexEnabled_; 348 obj[AppState.Field_.IS_DUPLEX_ENABLED] = this.isDuplexEnabled_;
351 obj[AppState.Field_.IS_HEADER_FOOTER_ENABLED] = 349 obj[AppState.Field_.IS_HEADER_FOOTER_ENABLED] =
352 this.isHeaderFooterEnabled_; 350 this.isHeaderFooterEnabled_;
353 obj[AppState.Field_.IS_LANDSCAPE_ENABLED] = this.isLandscapeEnabled_; 351 obj[AppState.Field_.IS_LANDSCAPE_ENABLED] = this.isLandscapeEnabled_;
354 obj[AppState.Field_.IS_COLLATE_ENABLED] = this.isCollateEnabled_; 352 obj[AppState.Field_.IS_COLLATE_ENABLED] = this.isCollateEnabled_;
355 obj[AppState.Field_.IS_CSS_BACKGROUND_ENABLED] = 353 obj[AppState.Field_.IS_CSS_BACKGROUND_ENABLED] =
356 this.isCssBackgroundEnabled_; 354 this.isCssBackgroundEnabled_;
357 chrome.send(AppState.NATIVE_FUNCTION_NAME_, [JSON.stringify(obj)]); 355 chrome.send(AppState.NATIVE_FUNCTION_NAME_, [JSON.stringify(obj)]);
358 } 356 }
359 }; 357 };
360 358
361 return { 359 return {
362 AppState: AppState 360 AppState: AppState
363 }; 361 };
364 }); 362 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698