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

Side by Side Diff: chrome/browser/resources/print_preview/previewarea/preview_area.js

Issue 2962983002: Print Preview: change getPreview to cr.sendWithPromise (Closed)
Patch Set: Rebase Created 3 years, 5 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 * Enumeration of IDs shown in the preview area. 8 * Enumeration of IDs shown in the preview area.
9 * @enum {string} 9 * @enum {string}
10 * @private 10 * @private
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // Dispatched when the document preview is complete. 185 // Dispatched when the document preview is complete.
186 PREVIEW_GENERATION_DONE: 186 PREVIEW_GENERATION_DONE:
187 'print_preview.PreviewArea.PREVIEW_GENERATION_DONE', 187 'print_preview.PreviewArea.PREVIEW_GENERATION_DONE',
188 188
189 // Dispatched when the document preview failed to be generated. 189 // Dispatched when the document preview failed to be generated.
190 PREVIEW_GENERATION_FAIL: 190 PREVIEW_GENERATION_FAIL:
191 'print_preview.PreviewArea.PREVIEW_GENERATION_FAIL', 191 'print_preview.PreviewArea.PREVIEW_GENERATION_FAIL',
192 192
193 // Dispatched when a new document preview is being generated. 193 // Dispatched when a new document preview is being generated.
194 PREVIEW_GENERATION_IN_PROGRESS: 194 PREVIEW_GENERATION_IN_PROGRESS:
195 'print_preview.PreviewArea.PREVIEW_GENERATION_IN_PROGRESS' 195 'print_preview.PreviewArea.PREVIEW_GENERATION_IN_PROGRESS',
196
197 // Dispatched when invalid printer settings are detected.
198 SETTINGS_INVALID: 'print_preview.PreviewArea.SETTINGS_INVALID'
196 }; 199 };
197 200
198 /** 201 /**
199 * CSS classes used by the preview area. 202 * CSS classes used by the preview area.
200 * @enum {string} 203 * @enum {string}
201 * @private 204 * @private
202 */ 205 */
203 PreviewArea.Classes_ = { 206 PreviewArea.Classes_ = {
204 OUT_OF_PROCESS_COMPATIBILITY_OBJECT: 207 OUT_OF_PROCESS_COMPATIBILITY_OBJECT:
205 'preview-area-compatibility-object-out-of-process', 208 'preview-area-compatibility-object-out-of-process',
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 this.tracker.add( 347 this.tracker.add(
345 this.previewGenerator_, 348 this.previewGenerator_,
346 print_preview.PreviewGenerator.EventType.PREVIEW_START, 349 print_preview.PreviewGenerator.EventType.PREVIEW_START,
347 this.onPreviewStart_.bind(this)); 350 this.onPreviewStart_.bind(this));
348 this.tracker.add( 351 this.tracker.add(
349 this.previewGenerator_, 352 this.previewGenerator_,
350 print_preview.PreviewGenerator.EventType.PAGE_READY, 353 print_preview.PreviewGenerator.EventType.PAGE_READY,
351 this.onPagePreviewReady_.bind(this)); 354 this.onPagePreviewReady_.bind(this));
352 this.tracker.add( 355 this.tracker.add(
353 this.previewGenerator_, 356 this.previewGenerator_,
354 print_preview.PreviewGenerator.EventType.FAIL,
355 this.onPreviewGenerationFail_.bind(this));
356 this.tracker.add(
357 this.previewGenerator_,
358 print_preview.PreviewGenerator.EventType.DOCUMENT_READY, 357 print_preview.PreviewGenerator.EventType.DOCUMENT_READY,
359 this.onDocumentReady_.bind(this)); 358 this.onDocumentReady_.bind(this));
360 } else { 359 } else {
361 this.showCustomMessage(loadTimeData.getString('noPlugin')); 360 this.showCustomMessage(loadTimeData.getString('noPlugin'));
362 } 361 }
363 }, 362 },
364 363
365 /** @override */ 364 /** @override */
366 exitDocument: function() { 365 exitDocument: function() {
367 print_preview.Component.prototype.exitDocument.call(this); 366 print_preview.Component.prototype.exitDocument.call(this);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 setIsVisible(openSystemDialogThrobber, true); 515 setIsVisible(openSystemDialogThrobber, true);
517 cr.dispatchSimpleEvent( 516 cr.dispatchSimpleEvent(
518 this, PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK); 517 this, PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK);
519 }, 518 },
520 519
521 /** 520 /**
522 * Called when the print ticket changes. Updates the preview. 521 * Called when the print ticket changes. Updates the preview.
523 * @private 522 * @private
524 */ 523 */
525 onTicketChange_: function() { 524 onTicketChange_: function() {
526 if (this.previewGenerator_ && this.previewGenerator_.requestPreview()) { 525 var requestPreview = this.previewGenerator_ ?
527 cr.dispatchSimpleEvent( 526 this.previewGenerator_.requestPreview() :
528 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); 527 null;
529 if (this.loadingTimeout_ == null) { 528 var requestId = requestPreview ? requestPreview.id : -1;
530 this.loadingTimeout_ = setTimeout( 529 if (requestId == -1) {
531 this.showMessage_.bind(
532 this, print_preview.PreviewAreaMessageId_.LOADING),
533 PreviewArea.LOADING_TIMEOUT_);
534 }
535 } else {
536 this.marginControlContainer_.showMarginControlsIfNeeded(); 530 this.marginControlContainer_.showMarginControlsIfNeeded();
531 return;
537 } 532 }
533 cr.dispatchSimpleEvent(
534 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS);
535 if (this.loadingTimeout_ == null) {
536 this.loadingTimeout_ = setTimeout(
537 this.showMessage_.bind(
538 this, print_preview.PreviewAreaMessageId_.LOADING),
539 PreviewArea.LOADING_TIMEOUT_);
540 }
541 requestPreview.request.then(
542 /** @param {number} previewUid The unique id of the preview. */
543 function(previewUid) {
544 this.previewGenerator_.onPreviewGenerationDone(
545 requestPreview.id, previewUid);
546 }.bind(this),
547 /**
548 * @param {*} type The type of print preview failure that
549 * occurred.
550 */
551 function(type) {
552 if (/** @type{string} */ (type) == 'SETTINGS_INVALID') {
553 this.cancelTimeout();
554 this.showCustomMessage(
555 loadTimeData.getString('invalidPrinterSettings'));
556 cr.dispatchSimpleEvent(
557 this, PreviewArea.EventType.SETTINGS_INVALID);
558 } else {
559 this.onPreviewGenerationFail_();
560 }
561 }.bind(this));
538 }, 562 },
539 563
540 /** 564 /**
541 * Called when the preview generator begins loading the preview. 565 * Called when the preview generator begins loading the preview.
542 * @param {Event} event Contains the URL to initialize the plugin to. 566 * @param {Event} event Contains the URL to initialize the plugin to.
543 * @private 567 * @private
544 */ 568 */
545 onPreviewStart_: function(event) { 569 onPreviewStart_: function(event) {
546 this.isDocumentReady_ = false; 570 this.isDocumentReady_ = false;
547 this.isPluginReloaded_ = false; 571 this.isPluginReloaded_ = false;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 // pointer events will be sent to the frame. When dragging the margins, 664 // pointer events will be sent to the frame. When dragging the margins,
641 // we don't want this to happen as it can cause the margin to stop 665 // we don't want this to happen as it can cause the margin to stop
642 // being draggable. 666 // being draggable.
643 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; 667 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto';
644 } 668 }
645 }; 669 };
646 670
647 // Export 671 // Export
648 return {PreviewArea: PreviewArea}; 672 return {PreviewArea: PreviewArea};
649 }); 673 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698