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

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: Fix tests 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 * @private 164 * @private
165 */ 165 */
166 this.overlayEl_ = null; 166 this.overlayEl_ = null;
167 167
168 /** 168 /**
169 * The "Open system dialog" button. 169 * The "Open system dialog" button.
170 * @type {HTMLButtonElement} 170 * @type {HTMLButtonElement}
171 * @private 171 * @private
172 */ 172 */
173 this.openSystemDialogButton_ = null; 173 this.openSystemDialogButton_ = null;
174
175 /**
176 * If this is in a browser test (fake plugin).
177 * @private {boolean}
178 */
179 this.isBrowserTest_ = false;
dpapad 2017/06/29 20:58:31 Is this new boolean necessary? How did the tests w
rbpotter 2017/06/29 22:31:22 This is used for the InvalidSettings test. Most te
dpapad 2017/06/29 23:28:31 Thanks for the explanation. I think the way the In
174 } 180 }
175 181
176 /** 182 /**
177 * Event types dispatched by the preview area. 183 * Event types dispatched by the preview area.
178 * @enum {string} 184 * @enum {string}
179 */ 185 */
180 PreviewArea.EventType = { 186 PreviewArea.EventType = {
181 // Dispatched when the "Open system dialog" button is clicked. 187 // Dispatched when the "Open system dialog" button is clicked.
182 OPEN_SYSTEM_DIALOG_CLICK: 188 OPEN_SYSTEM_DIALOG_CLICK:
183 'print_preview.PreviewArea.OPEN_SYSTEM_DIALOG_CLICK', 189 'print_preview.PreviewArea.OPEN_SYSTEM_DIALOG_CLICK',
184 190
185 // Dispatched when the document preview is complete. 191 // Dispatched when the document preview is complete.
186 PREVIEW_GENERATION_DONE: 192 PREVIEW_GENERATION_DONE:
187 'print_preview.PreviewArea.PREVIEW_GENERATION_DONE', 193 'print_preview.PreviewArea.PREVIEW_GENERATION_DONE',
188 194
189 // Dispatched when the document preview failed to be generated. 195 // Dispatched when the document preview failed to be generated.
190 PREVIEW_GENERATION_FAIL: 196 PREVIEW_GENERATION_FAIL:
191 'print_preview.PreviewArea.PREVIEW_GENERATION_FAIL', 197 'print_preview.PreviewArea.PREVIEW_GENERATION_FAIL',
192 198
193 // Dispatched when a new document preview is being generated. 199 // Dispatched when a new document preview is being generated.
194 PREVIEW_GENERATION_IN_PROGRESS: 200 PREVIEW_GENERATION_IN_PROGRESS:
195 'print_preview.PreviewArea.PREVIEW_GENERATION_IN_PROGRESS' 201 'print_preview.PreviewArea.PREVIEW_GENERATION_IN_PROGRESS',
202
203 // Dispatched when invalid printer settings are detected.
204 SETTINGS_INVALID: 'print_preview.PreviewArea.SETTINGS_INVALID'
196 }; 205 };
197 206
198 /** 207 /**
199 * CSS classes used by the preview area. 208 * CSS classes used by the preview area.
200 * @enum {string} 209 * @enum {string}
201 * @private 210 * @private
202 */ 211 */
203 PreviewArea.Classes_ = { 212 PreviewArea.Classes_ = {
204 OUT_OF_PROCESS_COMPATIBILITY_OBJECT: 213 OUT_OF_PROCESS_COMPATIBILITY_OBJECT:
205 'preview-area-compatibility-object-out-of-process', 214 'preview-area-compatibility-object-out-of-process',
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 this.tracker.add( 353 this.tracker.add(
345 this.previewGenerator_, 354 this.previewGenerator_,
346 print_preview.PreviewGenerator.EventType.PREVIEW_START, 355 print_preview.PreviewGenerator.EventType.PREVIEW_START,
347 this.onPreviewStart_.bind(this)); 356 this.onPreviewStart_.bind(this));
348 this.tracker.add( 357 this.tracker.add(
349 this.previewGenerator_, 358 this.previewGenerator_,
350 print_preview.PreviewGenerator.EventType.PAGE_READY, 359 print_preview.PreviewGenerator.EventType.PAGE_READY,
351 this.onPagePreviewReady_.bind(this)); 360 this.onPagePreviewReady_.bind(this));
352 this.tracker.add( 361 this.tracker.add(
353 this.previewGenerator_, 362 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, 363 print_preview.PreviewGenerator.EventType.DOCUMENT_READY,
359 this.onDocumentReady_.bind(this)); 364 this.onDocumentReady_.bind(this));
360 } else { 365 } else {
361 this.showCustomMessage(loadTimeData.getString('noPlugin')); 366 this.showCustomMessage(loadTimeData.getString('noPlugin'));
362 } 367 }
363 }, 368 },
364 369
365 /** @override */ 370 /** @override */
366 exitDocument: function() { 371 exitDocument: function() {
367 print_preview.Component.prototype.exitDocument.call(this); 372 print_preview.Component.prototype.exitDocument.call(this);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 setIsVisible(openSystemDialogThrobber, true); 521 setIsVisible(openSystemDialogThrobber, true);
517 cr.dispatchSimpleEvent( 522 cr.dispatchSimpleEvent(
518 this, PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK); 523 this, PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK);
519 }, 524 },
520 525
521 /** 526 /**
522 * Called when the print ticket changes. Updates the preview. 527 * Called when the print ticket changes. Updates the preview.
523 * @private 528 * @private
524 */ 529 */
525 onTicketChange_: function() { 530 onTicketChange_: function() {
526 if (this.previewGenerator_ && this.previewGenerator_.requestPreview()) { 531 var requestPreview = this.previewGenerator_ ?
dpapad 2017/06/29 20:58:31 Do we know if checking if previewGenerator_ exists
rbpotter 2017/06/29 22:31:22 Think so, as if the plugin is not compatible previ
dpapad 2017/06/29 20:58:31 Nit (optional): |requestPreview| sounds like a fun
rbpotter 2017/06/29 22:31:22 Done.
527 cr.dispatchSimpleEvent( 532 this.previewGenerator_.requestPreview() :
528 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); 533 null;
529 if (this.loadingTimeout_ == null) { 534 var requestId = requestPreview ? requestPreview.id : -1;
530 this.loadingTimeout_ = setTimeout( 535 if (requestId == -1) {
531 this.showMessage_.bind(
532 this, print_preview.PreviewAreaMessageId_.LOADING),
533 PreviewArea.LOADING_TIMEOUT_);
534 }
535 } else {
536 this.marginControlContainer_.showMarginControlsIfNeeded(); 536 this.marginControlContainer_.showMarginControlsIfNeeded();
537 return;
537 } 538 }
539 cr.dispatchSimpleEvent(
540 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS);
541 if (this.loadingTimeout_ == null) {
542 this.loadingTimeout_ = setTimeout(
543 this.showMessage_.bind(
544 this, print_preview.PreviewAreaMessageId_.LOADING),
545 PreviewArea.LOADING_TIMEOUT_);
546 }
547 requestPreview.request.then(
548 /** @param {number} previewUid The unique id of the preview. */
549 function(previewUid) {
550 this.previewGenerator_.onPreviewGenerationDone(
551 requestPreview.id, previewUid);
552 }.bind(this),
553 /**
554 * @param {*} type The type of print preview failure that
555 * occurred.
556 */
557 function(type) {
558 if (/** @type{string} */ (type) == 'SETTINGS_INVALID') {
559 this.cancelTimeout();
560 this.showCustomMessage(
561 loadTimeData.getString('invalidPrinterSettings'));
562 cr.dispatchSimpleEvent(
563 this, PreviewArea.EventType.SETTINGS_INVALID);
564 } else {
565 this.onPreviewGenerationFail_();
566 }
567 }.bind(this));
538 }, 568 },
539 569
540 /** 570 /**
541 * Called when the preview generator begins loading the preview. 571 * Called when the preview generator begins loading the preview.
542 * @param {Event} event Contains the URL to initialize the plugin to. 572 * @param {Event} event Contains the URL to initialize the plugin to.
543 * @private 573 * @private
544 */ 574 */
545 onPreviewStart_: function(event) { 575 onPreviewStart_: function(event) {
546 this.isDocumentReady_ = false; 576 this.isDocumentReady_ = false;
547 this.isPluginReloaded_ = false; 577 this.isPluginReloaded_ = false;
(...skipping 19 matching lines...) Expand all
567 this.plugin_.loadPreviewPage(event.previewUrl, event.previewIndex); 597 this.plugin_.loadPreviewPage(event.previewUrl, event.previewIndex);
568 }, 598 },
569 599
570 /** 600 /**
571 * Called when the preview generation is complete and the document is ready 601 * Called when the preview generation is complete and the document is ready
572 * to print. 602 * to print.
573 * @private 603 * @private
574 */ 604 */
575 onDocumentReady_: function(event) { 605 onDocumentReady_: function(event) {
576 this.isDocumentReady_ = true; 606 this.isDocumentReady_ = true;
607 if (this.isBrowserTest_)
608 this.isPluginReloaded_ = true;
577 this.dispatchPreviewGenerationDoneIfReady_(); 609 this.dispatchPreviewGenerationDoneIfReady_();
578 }, 610 },
579 611
580 /** 612 /**
581 * Cancels the timeout so that an error message can be shown. 613 * Cancels the timeout so that an error message can be shown.
582 */ 614 */
583 cancelTimeout: function() { 615 cancelTimeout: function() {
584 if (this.loadingTimeout_) { 616 if (this.loadingTimeout_) {
585 clearTimeout(this.loadingTimeout_); 617 clearTimeout(this.loadingTimeout_);
586 this.loadingTimeout_ = null; 618 this.loadingTimeout_ = null;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 */ 666 */
635 onMarginDragChanged_: function(isDragging) { 667 onMarginDragChanged_: function(isDragging) {
636 if (!this.plugin_) 668 if (!this.plugin_)
637 return; 669 return;
638 670
639 // When hovering over the plugin (which may be in a separate iframe) 671 // When hovering over the plugin (which may be in a separate iframe)
640 // pointer events will be sent to the frame. When dragging the margins, 672 // 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 673 // we don't want this to happen as it can cause the margin to stop
642 // being draggable. 674 // being draggable.
643 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; 675 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto';
676 },
677
678 /** @param {boolean} isTest Whether this instance is in a browser test. */
679 setIsBrowserTest: function(isTest) {
680 this.isBrowserTest_ = isTest;
644 } 681 }
645 }; 682 };
646 683
647 // Export 684 // Export
648 return {PreviewArea: PreviewArea}; 685 return {PreviewArea: PreviewArea};
649 }); 686 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698