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

Side by Side Diff: chrome/browser/resources/print_preview/native_layer.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 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
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.exportPath('print_preview'); 5 cr.exportPath('print_preview');
6 6
7 /** 7 /**
8 * @typedef {{selectSaveAsPdfDestination: boolean, 8 * @typedef {{selectSaveAsPdfDestination: boolean,
9 * layoutSettings.portrait: boolean, 9 * layoutSettings.portrait: boolean,
10 * pageRange: string, 10 * pageRange: string,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 * }} 56 * }}
57 */ 57 */
58 print_preview.PrivetPrinterCapabilitiesResponse; 58 print_preview.PrivetPrinterCapabilitiesResponse;
59 59
60 /** 60 /**
61 * @typedef {{ 61 * @typedef {{
62 * printerId: string, 62 * printerId: string,
63 * success: boolean, 63 * success: boolean,
64 * capabilities: Object, 64 * capabilities: Object,
65 * }} 65 * }}
66 */ 66 */
67 print_preview.PrinterSetupResponse; 67 print_preview.PrinterSetupResponse;
68 68
69 cr.define('print_preview', function() { 69 cr.define('print_preview', function() {
70 'use strict'; 70 'use strict';
71 71
72 /** 72 /**
73 * An interface to the native Chromium printing system layer. 73 * An interface to the native Chromium printing system layer.
74 * @constructor 74 * @constructor
75 */ 75 */
76 function NativeLayer() { 76 function NativeLayer() {
77 // Bind global handlers 77 // Bind global handlers
78 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); 78 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this);
79 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); 79 global.reloadPrintersList = this.onReloadPrintersList_.bind(this);
80 global.printToCloud = this.onPrintToCloud_.bind(this); 80 global.printToCloud = this.onPrintToCloud_.bind(this);
81 global.fileSelectionCancelled = 81 global.fileSelectionCancelled = this.onFileSelectionCancelled_.bind(this);
82 this.onFileSelectionCancelled_.bind(this); 82 global.fileSelectionCompleted = this.onFileSelectionCompleted_.bind(this);
83 global.fileSelectionCompleted =
84 this.onFileSelectionCompleted_.bind(this);
85 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); 83 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this);
86 global.invalidPrinterSettings = 84 global.invalidPrinterSettings = this.onInvalidPrinterSettings_.bind(this);
87 this.onInvalidPrinterSettings_.bind(this);
88 global.onDidGetDefaultPageLayout = 85 global.onDidGetDefaultPageLayout =
89 this.onDidGetDefaultPageLayout_.bind(this); 86 this.onDidGetDefaultPageLayout_.bind(this);
90 global.onDidGetPreviewPageCount = 87 global.onDidGetPreviewPageCount = this.onDidGetPreviewPageCount_.bind(this);
91 this.onDidGetPreviewPageCount_.bind(this);
92 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); 88 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this);
93 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); 89 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this);
94 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); 90 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this);
95 global.onEnableManipulateSettingsForTest = 91 global.onEnableManipulateSettingsForTest =
96 this.onEnableManipulateSettingsForTest_.bind(this); 92 this.onEnableManipulateSettingsForTest_.bind(this);
97 global.printPresetOptionsFromDocument = 93 global.printPresetOptionsFromDocument =
98 this.onPrintPresetOptionsFromDocument_.bind(this); 94 this.onPrintPresetOptionsFromDocument_.bind(this);
99 global.onProvisionalPrinterResolved = 95 global.onProvisionalPrinterResolved =
100 this.onProvisionalDestinationResolved_.bind(this); 96 this.onProvisionalDestinationResolved_.bind(this);
101 global.failedToResolveProvisionalPrinter = 97 global.failedToResolveProvisionalPrinter =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', 148 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID',
153 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', 149 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS',
154 PROVISIONAL_DESTINATION_RESOLVED: 150 PROVISIONAL_DESTINATION_RESOLVED:
155 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED' 151 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED'
156 }; 152 };
157 153
158 /** 154 /**
159 * Constant values matching printing::DuplexMode enum. 155 * Constant values matching printing::DuplexMode enum.
160 * @enum {number} 156 * @enum {number}
161 */ 157 */
162 NativeLayer.DuplexMode = { 158 NativeLayer.DuplexMode = {SIMPLEX: 0, LONG_EDGE: 1, UNKNOWN_DUPLEX_MODE: -1};
163 SIMPLEX: 0,
164 LONG_EDGE: 1,
165 UNKNOWN_DUPLEX_MODE: -1
166 };
167 159
168 /** 160 /**
169 * Enumeration of color modes used by Chromium. 161 * Enumeration of color modes used by Chromium.
170 * @enum {number} 162 * @enum {number}
171 * @private 163 * @private
172 */ 164 */
173 NativeLayer.ColorMode_ = { 165 NativeLayer.ColorMode_ = {GRAY: 1, COLOR: 2};
174 GRAY: 1,
175 COLOR: 2
176 };
177 166
178 /** 167 /**
179 * Version of the serialized state of the print preview. 168 * Version of the serialized state of the print preview.
180 * @type {number} 169 * @type {number}
181 * @const 170 * @const
182 * @private 171 * @private
183 */ 172 */
184 NativeLayer.SERIALIZED_STATE_VERSION_ = 1; 173 NativeLayer.SERIALIZED_STATE_VERSION_ = 1;
185 174
186 NativeLayer.prototype = { 175 NativeLayer.prototype = {
187 /** @return {!cr.EventTarget} The event target for the native layer.*/ 176 /** @return {!cr.EventTarget} The event target for the native layer.*/
188 getEventTarget: function() { 177 getEventTarget: function() {
189 return this.eventTarget_; 178 return this.eventTarget_;
190 }, 179 },
191 180
192 /** 181 /**
193 * Requests access token for cloud print requests. 182 * Requests access token for cloud print requests.
194 * @param {string} authType type of access token. 183 * @param {string} authType type of access token.
195 */ 184 */
196 startGetAccessToken: function(authType) { 185 startGetAccessToken: function(authType) {
197 chrome.send('getAccessToken', [authType]); 186 chrome.send('getAccessToken', [authType]);
198 }, 187 },
199 188
200 /** 189 /**
201 * Gets the initial settings to initialize the print preview with. 190 * Gets the initial settings to initialize the print preview with.
202 * @return {!Promise<!print_preview.NativeInitialSettings>} 191 * @return {!Promise<!print_preview.NativeInitialSettings>}
203 */ 192 */
204 getInitialSettings: function() { 193 getInitialSettings: function() {
205 return cr.sendWithPromise('getInitialSettings').then( 194 return cr.sendWithPromise('getInitialSettings')
206 /** 195 .then(
207 * @param {!Object} initialSettings Object containing the raw 196 /**
208 * Print Preview settings. 197 * @param {!Object} initialSettings Object containing the raw
209 */ 198 * Print Preview settings.
210 function(initialSettings) { 199 */
211 var numberFormatSymbols = 200 function(initialSettings) {
212 print_preview.MeasurementSystem.parseNumberFormat( 201 var numberFormatSymbols =
213 initialSettings['numberFormat']); 202 print_preview.MeasurementSystem.parseNumberFormat(
214 var unitType = print_preview.MeasurementSystemUnitType.IMPERIAL; 203 initialSettings['numberFormat']);
215 if (initialSettings['measurementSystem'] != null) { 204 var unitType = print_preview.MeasurementSystemUnitType.IMPERIAL;
216 unitType = initialSettings['measurementSystem']; 205 if (initialSettings['measurementSystem'] != null) {
217 } 206 unitType = initialSettings['measurementSystem'];
218 return new print_preview.NativeInitialSettings( 207 }
219 initialSettings['printAutomaticallyInKioskMode'] || false, 208 return new print_preview.NativeInitialSettings(
220 initialSettings['appKioskMode'] || false, 209 initialSettings['printAutomaticallyInKioskMode'] || false,
221 numberFormatSymbols[0] || ',', 210 initialSettings['appKioskMode'] || false,
222 numberFormatSymbols[1] || '.', 211 numberFormatSymbols[0] || ',',
223 unitType, 212 numberFormatSymbols[1] || '.', unitType,
224 initialSettings['previewModifiable'] || false, 213 initialSettings['previewModifiable'] || false,
225 initialSettings['initiatorTitle'] || '', 214 initialSettings['initiatorTitle'] || '',
226 initialSettings['documentHasSelection'] || false, 215 initialSettings['documentHasSelection'] || false,
227 initialSettings['shouldPrintSelectionOnly'] || false, 216 initialSettings['shouldPrintSelectionOnly'] || false,
228 initialSettings['printerName'] || null, 217 initialSettings['printerName'] || null,
229 initialSettings['appState'] || null, 218 initialSettings['appState'] || null,
230 initialSettings['defaultDestinationSelectionRules'] || null); 219 initialSettings['defaultDestinationSelectionRules'] ||
231 }); 220 null);
221 });
232 }, 222 },
233 223
234 /** 224 /**
235 * Requests the system's local print destinations. The promise will be 225 * Requests the system's local print destinations. The promise will be
236 * resolved with a list of the local destinations. 226 * resolved with a list of the local destinations.
237 * @return {!Promise<!Array<print_preview.LocalDestinationInfo>>} 227 * @return {!Promise<!Array<print_preview.LocalDestinationInfo>>}
238 */ 228 */
239 getPrinters: function() { 229 getPrinters: function() {
240 return cr.sendWithPromise('getPrinters'); 230 return cr.sendWithPromise('getPrinters');
241 }, 231 },
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 273
284 /** 274 /**
285 * Requests the extension destination's printing capabilities. Returns a 275 * Requests the extension destination's printing capabilities. Returns a
286 * promise that will be resolved with the ID and capabilities if 276 * promise that will be resolved with the ID and capabilities if
287 * capabilities are obtained successfully. 277 * capabilities are obtained successfully.
288 * @param {string} destinationId The ID of the destination whose 278 * @param {string} destinationId The ID of the destination whose
289 * capabilities are requested. 279 * capabilities are requested.
290 * @return {!Promise<!print_preview.Cdd>} 280 * @return {!Promise<!print_preview.Cdd>}
291 */ 281 */
292 getExtensionPrinterCapabilities: function(destinationId) { 282 getExtensionPrinterCapabilities: function(destinationId) {
293 return cr.sendWithPromise('getExtensionPrinterCapabilities', 283 return cr.sendWithPromise(
294 destinationId); 284 'getExtensionPrinterCapabilities', destinationId);
295 }, 285 },
296 286
297 /** 287 /**
298 * Requests Chrome to resolve provisional extension destination by granting 288 * Requests Chrome to resolve provisional extension destination by granting
299 * the provider extension access to the printer. Chrome will respond with 289 * the provider extension access to the printer. Chrome will respond with
300 * the resolved destination properties by calling 290 * the resolved destination properties by calling
301 * {@code onProvisionalPrinterResolved}, or in case of an error 291 * {@code onProvisionalPrinterResolved}, or in case of an error
302 * {@code failedToResolveProvisionalPrinter} 292 * {@code failedToResolveProvisionalPrinter}
303 * @param {string} provisionalDestinationId 293 * @param {string} provisionalDestinationId
304 */ 294 */
(...skipping 14 matching lines...) Expand all
319 * @param {!print_preview.Destination} destination Destination to print to. 309 * @param {!print_preview.Destination} destination Destination to print to.
320 * @param {!print_preview.ticket_items.Color} color Color ticket item. 310 * @param {!print_preview.ticket_items.Color} color Color ticket item.
321 * @return {number} Native layer color model. 311 * @return {number} Native layer color model.
322 * @private 312 * @private
323 */ 313 */
324 getNativeColorModel_: function(destination, color) { 314 getNativeColorModel_: function(destination, color) {
325 // For non-local printers native color model is ignored anyway. 315 // For non-local printers native color model is ignored anyway.
326 var option = destination.isLocal ? color.getSelectedOption() : null; 316 var option = destination.isLocal ? color.getSelectedOption() : null;
327 var nativeColorModel = parseInt(option ? option.vendor_id : null, 10); 317 var nativeColorModel = parseInt(option ? option.vendor_id : null, 10);
328 if (isNaN(nativeColorModel)) { 318 if (isNaN(nativeColorModel)) {
329 return color.getValue() ? 319 return color.getValue() ? NativeLayer.ColorMode_.COLOR :
330 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY; 320 NativeLayer.ColorMode_.GRAY;
331 } 321 }
332 return nativeColorModel; 322 return nativeColorModel;
333 }, 323 },
334 324
335 /** 325 /**
336 * Requests that a preview be generated. The following events may be 326 * Requests that a preview be generated. The following events may be
337 * dispatched in response: 327 * dispatched in response:
338 * - PAGE_COUNT_READY 328 * - PAGE_COUNT_READY
339 * - PAGE_LAYOUT_READY 329 * - PAGE_LAYOUT_READY
340 * - PAGE_PREVIEW_READY 330 * - PAGE_PREVIEW_READY
341 * - PREVIEW_GENERATION_DONE 331 * - PREVIEW_GENERATION_DONE
342 * - PREVIEW_GENERATION_FAIL 332 * - PREVIEW_GENERATION_FAIL
343 * @param {!print_preview.Destination} destination Destination to print to. 333 * @param {!print_preview.Destination} destination Destination to print to.
344 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the 334 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the
345 * state of the print ticket. 335 * state of the print ticket.
346 * @param {!print_preview.DocumentInfo} documentInfo Document data model. 336 * @param {!print_preview.DocumentInfo} documentInfo Document data model.
347 * @param {boolean} generateDraft Tell the renderer to re-render. 337 * @param {boolean} generateDraft Tell the renderer to re-render.
348 * @param {number} requestId ID of the preview request. 338 * @param {number} requestId ID of the preview request.
349 */ 339 */
350 startGetPreview: function( 340 startGetPreview: function(
351 destination, printTicketStore, documentInfo, generateDraft, requestId) { 341 destination, printTicketStore, documentInfo, generateDraft, requestId) {
352 assert(printTicketStore.isTicketValidForPreview(), 342 assert(
353 'Trying to generate preview when ticket is not valid'); 343 printTicketStore.isTicketValidForPreview(),
344 'Trying to generate preview when ticket is not valid');
354 345
355 var ticket = { 346 var ticket = {
356 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), 347 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(),
357 'mediaSize': printTicketStore.mediaSize.getValue(), 348 'mediaSize': printTicketStore.mediaSize.getValue(),
358 'landscape': printTicketStore.landscape.getValue(), 349 'landscape': printTicketStore.landscape.getValue(),
359 'color': this.getNativeColorModel_(destination, printTicketStore.color), 350 'color': this.getNativeColorModel_(destination, printTicketStore.color),
360 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), 351 'headerFooterEnabled': printTicketStore.headerFooter.getValue(),
361 'marginsType': printTicketStore.marginsType.getValue(), 352 'marginsType': printTicketStore.marginsType.getValue(),
362 'isFirstRequest': requestId == 0, 353 'isFirstRequest': requestId == 0,
363 'requestID': requestId, 354 'requestID': requestId,
364 'previewModifiable': documentInfo.isModifiable, 355 'previewModifiable': documentInfo.isModifiable,
365 'generateDraftData': generateDraft, 356 'generateDraftData': generateDraft,
366 'fitToPageEnabled': printTicketStore.fitToPage.getValue(), 357 'fitToPageEnabled': printTicketStore.fitToPage.getValue(),
367 'scaleFactor': printTicketStore.scaling.getValueAsNumber(), 358 'scaleFactor': printTicketStore.scaling.getValueAsNumber(),
368 // NOTE: Even though the following fields don't directly relate to the 359 // NOTE: Even though the following fields don't directly relate to the
369 // preview, they still need to be included. 360 // preview, they still need to be included.
370 // e.g. printing::PrintSettingsFromJobSettings() still checks for them. 361 // e.g. printing::PrintSettingsFromJobSettings() still checks for them.
371 'collate': true, 362 'collate': true,
372 'copies': 1, 363 'copies': 1,
373 'deviceName': destination.id, 364 'deviceName': destination.id,
374 'dpiHorizontal': 'horizontal_dpi' in printTicketStore.dpi.getValue() ? 365 'dpiHorizontal': 'horizontal_dpi' in printTicketStore.dpi.getValue() ?
375 printTicketStore.dpi.getValue().horizontal_dpi : 0, 366 printTicketStore.dpi.getValue().horizontal_dpi :
367 0,
376 'dpiVertical': 'vertical_dpi' in printTicketStore.dpi.getValue() ? 368 'dpiVertical': 'vertical_dpi' in printTicketStore.dpi.getValue() ?
377 printTicketStore.dpi.getValue().vertical_dpi : 0, 369 printTicketStore.dpi.getValue().vertical_dpi :
370 0,
378 'duplex': printTicketStore.duplex.getValue() ? 371 'duplex': printTicketStore.duplex.getValue() ?
379 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, 372 NativeLayer.DuplexMode.LONG_EDGE :
373 NativeLayer.DuplexMode.SIMPLEX,
380 'printToPDF': destination.id == 374 'printToPDF': destination.id ==
381 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, 375 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
382 'printWithCloudPrint': !destination.isLocal, 376 'printWithCloudPrint': !destination.isLocal,
383 'printWithPrivet': destination.isPrivet, 377 'printWithPrivet': destination.isPrivet,
384 'printWithExtension': destination.isExtension, 378 'printWithExtension': destination.isExtension,
385 'rasterizePDF': false, 379 'rasterizePDF': false,
386 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), 380 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(),
387 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue() 381 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue()
388 }; 382 };
389 383
390 // Set 'cloudPrintID' only if the destination is not local. 384 // Set 'cloudPrintID' only if the destination is not local.
391 if (destination && !destination.isLocal) { 385 if (destination && !destination.isLocal) {
392 ticket['cloudPrintID'] = destination.id; 386 ticket['cloudPrintID'] = destination.id;
393 } 387 }
394 388
395 if (printTicketStore.marginsType.isCapabilityAvailable() && 389 if (printTicketStore.marginsType.isCapabilityAvailable() &&
396 printTicketStore.marginsType.getValue() == 390 printTicketStore.marginsType.getValue() ==
397 print_preview.ticket_items.MarginsTypeValue.CUSTOM) { 391 print_preview.ticket_items.MarginsTypeValue.CUSTOM) {
398 var customMargins = printTicketStore.customMargins.getValue(); 392 var customMargins = printTicketStore.customMargins.getValue();
399 var orientationEnum = 393 var orientationEnum =
400 print_preview.ticket_items.CustomMarginsOrientation; 394 print_preview.ticket_items.CustomMarginsOrientation;
401 ticket['marginsCustom'] = { 395 ticket['marginsCustom'] = {
402 'marginTop': customMargins.get(orientationEnum.TOP), 396 'marginTop': customMargins.get(orientationEnum.TOP),
403 'marginRight': customMargins.get(orientationEnum.RIGHT), 397 'marginRight': customMargins.get(orientationEnum.RIGHT),
404 'marginBottom': customMargins.get(orientationEnum.BOTTOM), 398 'marginBottom': customMargins.get(orientationEnum.BOTTOM),
405 'marginLeft': customMargins.get(orientationEnum.LEFT) 399 'marginLeft': customMargins.get(orientationEnum.LEFT)
406 }; 400 };
407 } 401 }
408 402
409 chrome.send( 403 chrome.send('getPreview', [
410 'getPreview', 404 JSON.stringify(ticket), requestId > 0 ? documentInfo.pageCount : -1
411 [JSON.stringify(ticket), 405 ]);
412 requestId > 0 ? documentInfo.pageCount : -1]);
413 }, 406 },
414 407
415 /** 408 /**
416 * Requests that the document be printed. 409 * Requests that the document be printed.
417 * @param {!print_preview.Destination} destination Destination to print to. 410 * @param {!print_preview.Destination} destination Destination to print to.
418 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the 411 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the
419 * state of the print ticket. 412 * state of the print ticket.
420 * @param {cloudprint.CloudPrintInterface} cloudPrintInterface Interface 413 * @param {cloudprint.CloudPrintInterface} cloudPrintInterface Interface
421 * to Google Cloud Print. 414 * to Google Cloud Print.
422 * @param {!print_preview.DocumentInfo} documentInfo Document data model. 415 * @param {!print_preview.DocumentInfo} documentInfo Document data model.
423 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the 416 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the
424 * system's preview application. 417 * system's preview application.
425 * @param {boolean=} opt_showSystemDialog Whether to open system dialog for 418 * @param {boolean=} opt_showSystemDialog Whether to open system dialog for
426 * advanced settings. 419 * advanced settings.
427 */ 420 */
428 startPrint: function(destination, printTicketStore, cloudPrintInterface, 421 startPrint: function(
429 documentInfo, opt_isOpenPdfInPreview, 422 destination, printTicketStore, cloudPrintInterface, documentInfo,
430 opt_showSystemDialog) { 423 opt_isOpenPdfInPreview, opt_showSystemDialog) {
431 assert(printTicketStore.isTicketValid(), 424 assert(
432 'Trying to print when ticket is not valid'); 425 printTicketStore.isTicketValid(),
426 'Trying to print when ticket is not valid');
433 427
434 assert(!opt_showSystemDialog || (cr.isWindows && destination.isLocal), 428 assert(
435 'Implemented for Windows only'); 429 !opt_showSystemDialog || (cr.isWindows && destination.isLocal),
430 'Implemented for Windows only');
436 431
437 var ticket = { 432 var ticket = {
438 'mediaSize': printTicketStore.mediaSize.getValue(), 433 'mediaSize': printTicketStore.mediaSize.getValue(),
439 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, 434 'pageCount': printTicketStore.pageRange.getPageNumberSet().size,
440 'landscape': printTicketStore.landscape.getValue(), 435 'landscape': printTicketStore.landscape.getValue(),
441 'color': this.getNativeColorModel_(destination, printTicketStore.color), 436 'color': this.getNativeColorModel_(destination, printTicketStore.color),
442 'headerFooterEnabled': false, // Only used in print preview 437 'headerFooterEnabled': false, // Only used in print preview
443 'marginsType': printTicketStore.marginsType.getValue(), 438 'marginsType': printTicketStore.marginsType.getValue(),
444 'duplex': printTicketStore.duplex.getValue() ? 439 'duplex': printTicketStore.duplex.getValue() ?
445 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, 440 NativeLayer.DuplexMode.LONG_EDGE :
441 NativeLayer.DuplexMode.SIMPLEX,
446 'copies': printTicketStore.copies.getValueAsNumber(), 442 'copies': printTicketStore.copies.getValueAsNumber(),
447 'collate': printTicketStore.collate.getValue(), 443 'collate': printTicketStore.collate.getValue(),
448 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), 444 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(),
449 'shouldPrintSelectionOnly': false, // Only used in print preview 445 'shouldPrintSelectionOnly': false, // Only used in print preview
450 'previewModifiable': documentInfo.isModifiable, 446 'previewModifiable': documentInfo.isModifiable,
451 'printToPDF': destination.id == 447 'printToPDF': destination.id ==
452 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, 448 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
453 'printWithCloudPrint': !destination.isLocal, 449 'printWithCloudPrint': !destination.isLocal,
454 'printWithPrivet': destination.isPrivet, 450 'printWithPrivet': destination.isPrivet,
455 'printWithExtension': destination.isExtension, 451 'printWithExtension': destination.isExtension,
456 'rasterizePDF': printTicketStore.rasterize.getValue(), 452 'rasterizePDF': printTicketStore.rasterize.getValue(),
457 'scaleFactor': printTicketStore.scaling.getValueAsNumber(), 453 'scaleFactor': printTicketStore.scaling.getValueAsNumber(),
458 'dpiHorizontal': 'horizontal_dpi' in printTicketStore.dpi.getValue() ? 454 'dpiHorizontal': 'horizontal_dpi' in printTicketStore.dpi.getValue() ?
459 printTicketStore.dpi.getValue().horizontal_dpi : 0, 455 printTicketStore.dpi.getValue().horizontal_dpi :
456 0,
460 'dpiVertical': 'vertical_dpi' in printTicketStore.dpi.getValue() ? 457 'dpiVertical': 'vertical_dpi' in printTicketStore.dpi.getValue() ?
461 printTicketStore.dpi.getValue().vertical_dpi : 0, 458 printTicketStore.dpi.getValue().vertical_dpi :
459 0,
462 'deviceName': destination.id, 460 'deviceName': destination.id,
463 'fitToPageEnabled': printTicketStore.fitToPage.getValue(), 461 'fitToPageEnabled': printTicketStore.fitToPage.getValue(),
464 'pageWidth': documentInfo.pageSize.width, 462 'pageWidth': documentInfo.pageSize.width,
465 'pageHeight': documentInfo.pageSize.height, 463 'pageHeight': documentInfo.pageSize.height,
466 'showSystemDialog': opt_showSystemDialog 464 'showSystemDialog': opt_showSystemDialog
467 }; 465 };
468 466
469 if (!destination.isLocal) { 467 if (!destination.isLocal) {
470 // We can't set cloudPrintID if the destination is "Print with Cloud 468 // We can't set cloudPrintID if the destination is "Print with Cloud
471 // Print" because the native system will try to print to Google Cloud 469 // Print" because the native system will try to print to Google Cloud
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 chrome.send('forceOpenNewTab', [url]); 549 chrome.send('forceOpenNewTab', [url]);
552 }, 550 },
553 551
554 /** 552 /**
555 * Turn on the integration of Cloud Print. 553 * Turn on the integration of Cloud Print.
556 * @param {{cloudPrintURL: string, appKioskMode: string}} settings 554 * @param {{cloudPrintURL: string, appKioskMode: string}} settings
557 * cloudPrintUrl: The URL to use for cloud print servers. 555 * cloudPrintUrl: The URL to use for cloud print servers.
558 * @private 556 * @private
559 */ 557 */
560 onSetUseCloudPrint_: function(settings) { 558 onSetUseCloudPrint_: function(settings) {
561 var cloudPrintEnableEvent = new Event( 559 var cloudPrintEnableEvent =
562 NativeLayer.EventType.CLOUD_PRINT_ENABLE); 560 new Event(NativeLayer.EventType.CLOUD_PRINT_ENABLE);
563 cloudPrintEnableEvent.baseCloudPrintUrl = settings['cloudPrintUrl'] || ''; 561 cloudPrintEnableEvent.baseCloudPrintUrl = settings['cloudPrintUrl'] || '';
564 cloudPrintEnableEvent.appKioskMode = settings['appKioskMode'] || false; 562 cloudPrintEnableEvent.appKioskMode = settings['appKioskMode'] || false;
565 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent); 563 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent);
566 }, 564 },
567 565
568 /** Reloads the printer list. */ 566 /** Reloads the printer list. */
569 onReloadPrintersList_: function() { 567 onReloadPrintersList_: function() {
570 cr.dispatchSimpleEvent(this.eventTarget_, 568 cr.dispatchSimpleEvent(
571 NativeLayer.EventType.DESTINATIONS_RELOAD); 569 this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD);
572 }, 570 },
573 571
574 /** 572 /**
575 * Called from the C++ layer. 573 * Called from the C++ layer.
576 * Take the PDF data handed to us and submit it to the cloud, closing the 574 * Take the PDF data handed to us and submit it to the cloud, closing the
577 * print preview dialog once the upload is successful. 575 * print preview dialog once the upload is successful.
578 * @param {string} data Data to send as the print job. 576 * @param {string} data Data to send as the print job.
579 * @private 577 * @private
580 */ 578 */
581 onPrintToCloud_: function(data) { 579 onPrintToCloud_: function(data) {
582 var printToCloudEvent = new Event( 580 var printToCloudEvent = new Event(NativeLayer.EventType.PRINT_TO_CLOUD);
583 NativeLayer.EventType.PRINT_TO_CLOUD);
584 printToCloudEvent.data = data; 581 printToCloudEvent.data = data;
585 this.eventTarget_.dispatchEvent(printToCloudEvent); 582 this.eventTarget_.dispatchEvent(printToCloudEvent);
586 }, 583 },
587 584
588 /** 585 /**
589 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print 586 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print
590 * preview dialog regarding the file selection cancel event. 587 * preview dialog regarding the file selection cancel event.
591 * @private 588 * @private
592 */ 589 */
593 onFileSelectionCancelled_: function() { 590 onFileSelectionCancelled_: function() {
(...skipping 22 matching lines...) Expand all
616 cr.dispatchSimpleEvent( 613 cr.dispatchSimpleEvent(
617 this.eventTarget_, NativeLayer.EventType.PREVIEW_GENERATION_FAIL); 614 this.eventTarget_, NativeLayer.EventType.PREVIEW_GENERATION_FAIL);
618 }, 615 },
619 616
620 /** 617 /**
621 * Display an error message when encountered invalid printer settings. 618 * Display an error message when encountered invalid printer settings.
622 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). 619 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings().
623 * @private 620 * @private
624 */ 621 */
625 onInvalidPrinterSettings_: function() { 622 onInvalidPrinterSettings_: function() {
626 cr.dispatchSimpleEvent(this.eventTarget_, 623 cr.dispatchSimpleEvent(
627 NativeLayer.EventType.SETTINGS_INVALID); 624 this.eventTarget_, NativeLayer.EventType.SETTINGS_INVALID);
628 }, 625 },
629 626
630 /** 627 /**
631 * @param {{contentWidth: number, contentHeight: number, marginLeft: number, 628 * @param {{contentWidth: number, contentHeight: number, marginLeft: number,
632 * marginRight: number, marginTop: number, marginBottom: number, 629 * marginRight: number, marginTop: number, marginBottom: number,
633 * printableAreaX: number, printableAreaY: number, 630 * printableAreaX: number, printableAreaY: number,
634 * printableAreaWidth: number, printableAreaHeight: number}} 631 * printableAreaWidth: number, printableAreaHeight: number}}
635 * pageLayout Specifies default page layout details in points. 632 * pageLayout Specifies default page layout details in points.
636 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed 633 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed
637 * document has a custom page size style. 634 * document has a custom page size style.
638 * @private 635 * @private
639 */ 636 */
640 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) { 637 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) {
641 var pageLayoutChangeEvent = new Event( 638 var pageLayoutChangeEvent =
642 NativeLayer.EventType.PAGE_LAYOUT_READY); 639 new Event(NativeLayer.EventType.PAGE_LAYOUT_READY);
643 pageLayoutChangeEvent.pageLayout = pageLayout; 640 pageLayoutChangeEvent.pageLayout = pageLayout;
644 pageLayoutChangeEvent.hasCustomPageSizeStyle = hasCustomPageSizeStyle; 641 pageLayoutChangeEvent.hasCustomPageSizeStyle = hasCustomPageSizeStyle;
645 this.eventTarget_.dispatchEvent(pageLayoutChangeEvent); 642 this.eventTarget_.dispatchEvent(pageLayoutChangeEvent);
646 }, 643 },
647 644
648 /** 645 /**
649 * Update the page count and check the page range. 646 * Update the page count and check the page range.
650 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). 647 * Called from PrintPreviewUI::OnDidGetPreviewPageCount().
651 * @param {number} pageCount The number of pages. 648 * @param {number} pageCount The number of pages.
652 * @param {number} previewResponseId The preview request id that resulted in 649 * @param {number} previewResponseId The preview request id that resulted in
653 * this response. 650 * this response.
654 * @param {number} fitToPageScaling The scaling percentage required to fit 651 * @param {number} fitToPageScaling The scaling percentage required to fit
655 * the document to page, rounded to the nearest integer. 652 * the document to page, rounded to the nearest integer.
656 * @private 653 * @private
657 */ 654 */
658 onDidGetPreviewPageCount_: function(pageCount, previewResponseId, 655 onDidGetPreviewPageCount_: function(
659 fitToPageScaling) { 656 pageCount, previewResponseId, fitToPageScaling) {
660 var pageCountChangeEvent = new Event( 657 var pageCountChangeEvent =
661 NativeLayer.EventType.PAGE_COUNT_READY); 658 new Event(NativeLayer.EventType.PAGE_COUNT_READY);
662 pageCountChangeEvent.pageCount = pageCount; 659 pageCountChangeEvent.pageCount = pageCount;
663 pageCountChangeEvent.previewResponseId = previewResponseId; 660 pageCountChangeEvent.previewResponseId = previewResponseId;
664 pageCountChangeEvent.fitToPageScaling = fitToPageScaling; 661 pageCountChangeEvent.fitToPageScaling = fitToPageScaling;
665 this.eventTarget_.dispatchEvent(pageCountChangeEvent); 662 this.eventTarget_.dispatchEvent(pageCountChangeEvent);
666 }, 663 },
667 664
668 /** 665 /**
669 * Notification that a print preview page has been rendered. 666 * Notification that a print preview page has been rendered.
670 * Check if the settings have changed and request a regeneration if needed. 667 * Check if the settings have changed and request a regeneration if needed.
671 * Called from PrintPreviewUI::OnDidPreviewPage(). 668 * Called from PrintPreviewUI::OnDidPreviewPage().
672 * @param {number} pageNumber The page number, 0-based. 669 * @param {number} pageNumber The page number, 0-based.
673 * @param {number} previewUid Preview unique identifier. 670 * @param {number} previewUid Preview unique identifier.
674 * @param {number} previewResponseId The preview request id that resulted in 671 * @param {number} previewResponseId The preview request id that resulted in
675 * this response. 672 * this response.
676 * @private 673 * @private
677 */ 674 */
678 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { 675 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) {
679 var pagePreviewGenEvent = new Event( 676 var pagePreviewGenEvent =
680 NativeLayer.EventType.PAGE_PREVIEW_READY); 677 new Event(NativeLayer.EventType.PAGE_PREVIEW_READY);
681 pagePreviewGenEvent.pageIndex = pageNumber; 678 pagePreviewGenEvent.pageIndex = pageNumber;
682 pagePreviewGenEvent.previewUid = previewUid; 679 pagePreviewGenEvent.previewUid = previewUid;
683 pagePreviewGenEvent.previewResponseId = previewResponseId; 680 pagePreviewGenEvent.previewResponseId = previewResponseId;
684 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); 681 this.eventTarget_.dispatchEvent(pagePreviewGenEvent);
685 }, 682 },
686 683
687 /** 684 /**
688 * Notification that access token is ready. 685 * Notification that access token is ready.
689 * @param {string} authType Type of access token. 686 * @param {string} authType Type of access token.
690 * @param {string} accessToken Access token. 687 * @param {string} accessToken Access token.
691 * @private 688 * @private
692 */ 689 */
693 onDidGetAccessToken_: function(authType, accessToken) { 690 onDidGetAccessToken_: function(authType, accessToken) {
694 var getAccessTokenEvent = new Event( 691 var getAccessTokenEvent =
695 NativeLayer.EventType.ACCESS_TOKEN_READY); 692 new Event(NativeLayer.EventType.ACCESS_TOKEN_READY);
696 getAccessTokenEvent.authType = authType; 693 getAccessTokenEvent.authType = authType;
697 getAccessTokenEvent.accessToken = accessToken; 694 getAccessTokenEvent.accessToken = accessToken;
698 this.eventTarget_.dispatchEvent(getAccessTokenEvent); 695 this.eventTarget_.dispatchEvent(getAccessTokenEvent);
699 }, 696 },
700 697
701 /** 698 /**
702 * Update the print preview when new preview data is available. 699 * Update the print preview when new preview data is available.
703 * Create the PDF plugin as needed. 700 * Create the PDF plugin as needed.
704 * Called from PrintPreviewUI::PreviewDataIsAvailable(). 701 * Called from PrintPreviewUI::PreviewDataIsAvailable().
705 * @param {number} previewUid Preview unique identifier. 702 * @param {number} previewUid Preview unique identifier.
706 * @param {number} previewResponseId The preview request id that resulted in 703 * @param {number} previewResponseId The preview request id that resulted in
707 * this response. 704 * this response.
708 * @private 705 * @private
709 */ 706 */
710 onUpdatePrintPreview_: function(previewUid, previewResponseId) { 707 onUpdatePrintPreview_: function(previewUid, previewResponseId) {
711 var previewGenDoneEvent = new Event( 708 var previewGenDoneEvent =
712 NativeLayer.EventType.PREVIEW_GENERATION_DONE); 709 new Event(NativeLayer.EventType.PREVIEW_GENERATION_DONE);
713 previewGenDoneEvent.previewUid = previewUid; 710 previewGenDoneEvent.previewUid = previewUid;
714 previewGenDoneEvent.previewResponseId = previewResponseId; 711 previewGenDoneEvent.previewResponseId = previewResponseId;
715 this.eventTarget_.dispatchEvent(previewGenDoneEvent); 712 this.eventTarget_.dispatchEvent(previewGenDoneEvent);
716 }, 713 },
717 714
718 /** 715 /**
719 * Updates print preset options from source PDF document. 716 * Updates print preset options from source PDF document.
720 * Called from PrintPreviewUI::OnSetOptionsFromDocument(). 717 * Called from PrintPreviewUI::OnSetOptionsFromDocument().
721 * @param {{disableScaling: boolean, copies: number, 718 * @param {{disableScaling: boolean, copies: number,
722 * duplex: number}} options Specifies 719 * duplex: number}} options Specifies
723 * printing options according to source document presets. 720 * printing options according to source document presets.
724 * @private 721 * @private
725 */ 722 */
726 onPrintPresetOptionsFromDocument_: function(options) { 723 onPrintPresetOptionsFromDocument_: function(options) {
727 var printPresetOptionsEvent = new Event( 724 var printPresetOptionsEvent =
728 NativeLayer.EventType.PRINT_PRESET_OPTIONS); 725 new Event(NativeLayer.EventType.PRINT_PRESET_OPTIONS);
729 printPresetOptionsEvent.optionsFromDocument = options; 726 printPresetOptionsEvent.optionsFromDocument = options;
730 this.eventTarget_.dispatchEvent(printPresetOptionsEvent); 727 this.eventTarget_.dispatchEvent(printPresetOptionsEvent);
731 }, 728 },
732 729
733 /** 730 /**
734 * Called when Chrome reports that attempt to resolve a provisional 731 * Called when Chrome reports that attempt to resolve a provisional
735 * destination failed. 732 * destination failed.
736 * @param {string} destinationId The provisional destination ID. 733 * @param {string} destinationId The provisional destination ID.
737 * @private 734 * @private
738 */ 735 */
739 failedToResolveProvisionalDestination_: function(destinationId) { 736 failedToResolveProvisionalDestination_: function(destinationId) {
740 var evt = new Event( 737 var evt =
741 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED); 738 new Event(NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED);
742 evt.provisionalId = destinationId; 739 evt.provisionalId = destinationId;
743 evt.destination = null; 740 evt.destination = null;
744 this.eventTarget_.dispatchEvent(evt); 741 this.eventTarget_.dispatchEvent(evt);
745 }, 742 },
746 743
747 /** 744 /**
748 * Called when Chrome reports that a provisional destination has been 745 * Called when Chrome reports that a provisional destination has been
749 * successfully resolved. 746 * successfully resolved.
750 * Currently used only for extension provided destinations. 747 * Currently used only for extension provided destinations.
751 * @param {string} provisionalDestinationId The provisional destination id. 748 * @param {string} provisionalDestinationId The provisional destination id.
752 * @param {!{extensionId: string, 749 * @param {!{extensionId: string,
753 * extensionName: string, 750 * extensionName: string,
754 * id: string, 751 * id: string,
755 * name: string, 752 * name: string,
756 * description: (string|undefined)}} destinationInfo The resolved 753 * description: (string|undefined)}} destinationInfo The resolved
757 * destination info. 754 * destination info.
758 * @private 755 * @private
759 */ 756 */
760 onProvisionalDestinationResolved_: function(provisionalDestinationId, 757 onProvisionalDestinationResolved_: function(
761 destinationInfo) { 758 provisionalDestinationId, destinationInfo) {
762 var evt = new Event( 759 var evt =
763 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED); 760 new Event(NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED);
764 evt.provisionalId = provisionalDestinationId; 761 evt.provisionalId = provisionalDestinationId;
765 evt.destination = destinationInfo; 762 evt.destination = destinationInfo;
766 this.eventTarget_.dispatchEvent(evt); 763 this.eventTarget_.dispatchEvent(evt);
767 }, 764 },
768 765
769 /** 766 /**
770 * Allows for onManipulateSettings to be called 767 * Allows for onManipulateSettings to be called
771 * from the native layer. 768 * from the native layer.
772 * @private 769 * @private
773 */ 770 */
774 onEnableManipulateSettingsForTest_: function() { 771 onEnableManipulateSettingsForTest_: function() {
775 global.onManipulateSettingsForTest = 772 global.onManipulateSettingsForTest =
776 this.onManipulateSettingsForTest_.bind(this); 773 this.onManipulateSettingsForTest_.bind(this);
777 }, 774 },
778 775
779 /** 776 /**
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 * @param {boolean} selectionOnly Whether only selected content should be 825 * @param {boolean} selectionOnly Whether only selected content should be
829 * printed. 826 * printed.
830 * @param {?string} systemDefaultDestinationId ID of the system default 827 * @param {?string} systemDefaultDestinationId ID of the system default
831 * destination. 828 * destination.
832 * @param {?string} serializedAppStateStr Serialized app state. 829 * @param {?string} serializedAppStateStr Serialized app state.
833 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized 830 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
834 * default destination selection rules. 831 * default destination selection rules.
835 * @constructor 832 * @constructor
836 */ 833 */
837 function NativeInitialSettings( 834 function NativeInitialSettings(
838 isInKioskAutoPrintMode, 835 isInKioskAutoPrintMode, isInAppKioskMode, thousandsDelimeter,
839 isInAppKioskMode, 836 decimalDelimeter, unitType, isDocumentModifiable, documentTitle,
840 thousandsDelimeter, 837 documentHasSelection, selectionOnly, systemDefaultDestinationId,
841 decimalDelimeter, 838 serializedAppStateStr, serializedDefaultDestinationSelectionRulesStr) {
842 unitType,
843 isDocumentModifiable,
844 documentTitle,
845 documentHasSelection,
846 selectionOnly,
847 systemDefaultDestinationId,
848 serializedAppStateStr,
849 serializedDefaultDestinationSelectionRulesStr) {
850
851 /** 839 /**
852 * Whether the print preview should be in auto-print mode. 840 * Whether the print preview should be in auto-print mode.
853 * @private {boolean} 841 * @private {boolean}
854 */ 842 */
855 this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode; 843 this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode;
856 844
857 /** 845 /**
858 * Whether the print preview should switch to App Kiosk mode. 846 * Whether the print preview should switch to App Kiosk mode.
859 * @private {boolean} 847 * @private {boolean}
860 */ 848 */
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 return this.serializedDefaultDestinationSelectionRulesStr_; 979 return this.serializedDefaultDestinationSelectionRulesStr_;
992 } 980 }
993 }; 981 };
994 982
995 // Export 983 // Export
996 return { 984 return {
997 NativeInitialSettings: NativeInitialSettings, 985 NativeInitialSettings: NativeInitialSettings,
998 NativeLayer: NativeLayer 986 NativeLayer: NativeLayer
999 }; 987 };
1000 }); 988 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698