| 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 #ifndef COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 5 #ifndef COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| 6 #define COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 6 #define COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 442 |
| 443 // Cleanup after print preview finishes. | 443 // Cleanup after print preview finishes. |
| 444 void Finished(); | 444 void Finished(); |
| 445 | 445 |
| 446 // Cleanup after print preview fails. | 446 // Cleanup after print preview fails. |
| 447 void Failed(bool report_error); | 447 void Failed(bool report_error); |
| 448 | 448 |
| 449 // Helper functions | 449 // Helper functions |
| 450 int GetNextPageNumber(); | 450 int GetNextPageNumber(); |
| 451 bool IsRendering() const; | 451 bool IsRendering() const; |
| 452 bool IsModifiable(); | 452 bool IsModifiable() const; |
| 453 bool HasSelection(); | 453 bool HasSelection(); |
| 454 bool IsLastPageOfPrintReadyMetafile() const; | 454 bool IsLastPageOfPrintReadyMetafile() const; |
| 455 bool IsFinalPageRendered() const; | 455 bool IsFinalPageRendered() const; |
| 456 | 456 |
| 457 // Setters | 457 // Setters |
| 458 void set_generate_draft_pages(bool generate_draft_pages); | 458 void set_generate_draft_pages(bool generate_draft_pages); |
| 459 void set_error(enum PrintPreviewErrorBuckets error); | 459 void set_error(enum PrintPreviewErrorBuckets error); |
| 460 | 460 |
| 461 // Getters | 461 // Getters |
| 462 // Original frame for which preview was requested. | 462 // Original frame for which preview was requested. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 480 enum State { | 480 enum State { |
| 481 UNINITIALIZED, // Not ready to render. | 481 UNINITIALIZED, // Not ready to render. |
| 482 INITIALIZED, // Ready to render. | 482 INITIALIZED, // Ready to render. |
| 483 RENDERING, // Rendering. | 483 RENDERING, // Rendering. |
| 484 DONE // Finished rendering. | 484 DONE // Finished rendering. |
| 485 }; | 485 }; |
| 486 | 486 |
| 487 // Reset some of the internal rendering context. | 487 // Reset some of the internal rendering context. |
| 488 void ClearContext(); | 488 void ClearContext(); |
| 489 | 489 |
| 490 void CalculateIsModifiable(); |
| 491 |
| 490 // Specifies what to render for print preview. | 492 // Specifies what to render for print preview. |
| 491 FrameReference source_frame_; | 493 FrameReference source_frame_; |
| 492 blink::WebNode source_node_; | 494 blink::WebNode source_node_; |
| 493 | 495 |
| 494 std::unique_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 496 std::unique_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
| 495 std::unique_ptr<PdfMetafileSkia> metafile_; | 497 std::unique_ptr<PdfMetafileSkia> metafile_; |
| 496 | 498 |
| 497 // Total page count in the renderer. | 499 // Total page count in the renderer. |
| 498 int total_page_count_; | 500 int total_page_count_; |
| 499 | 501 |
| 500 // The current page to render. | 502 // The current page to render. |
| 501 int current_page_index_; | 503 int current_page_index_; |
| 502 | 504 |
| 503 // List of page indices that need to be rendered. | 505 // List of page indices that need to be rendered. |
| 504 std::vector<int> pages_to_render_; | 506 std::vector<int> pages_to_render_; |
| 505 | 507 |
| 506 // True, when draft pages needs to be generated. | 508 // True, when draft pages needs to be generated. |
| 507 bool generate_draft_pages_; | 509 bool generate_draft_pages_; |
| 508 | 510 |
| 511 // True, if the document source is modifiable. e.g. HTML and not PDF. |
| 512 bool is_modifiable_; |
| 513 |
| 509 // Specifies the total number of pages in the print ready metafile. | 514 // Specifies the total number of pages in the print ready metafile. |
| 510 int print_ready_metafile_page_count_; | 515 int print_ready_metafile_page_count_; |
| 511 | 516 |
| 512 base::TimeDelta document_render_time_; | 517 base::TimeDelta document_render_time_; |
| 513 base::TimeTicks begin_time_; | 518 base::TimeTicks begin_time_; |
| 514 | 519 |
| 515 enum PrintPreviewErrorBuckets error_; | 520 enum PrintPreviewErrorBuckets error_; |
| 516 | 521 |
| 517 State state_; | 522 State state_; |
| 523 |
| 524 DISALLOW_COPY_AND_ASSIGN(PrintPreviewContext); |
| 518 }; | 525 }; |
| 519 | 526 |
| 520 class ScriptingThrottler { | 527 class ScriptingThrottler { |
| 521 public: | 528 public: |
| 522 ScriptingThrottler(); | 529 ScriptingThrottler(); |
| 523 | 530 |
| 524 // Returns false if script initiated printing occurs too often. | 531 // Returns false if script initiated printing occurs too often. |
| 525 bool IsAllowed(blink::WebLocalFrame* frame); | 532 bool IsAllowed(blink::WebLocalFrame* frame); |
| 526 | 533 |
| 527 // Reset the counter for script initiated printing. | 534 // Reset the counter for script initiated printing. |
| 528 // Scripted printing will be allowed to continue. | 535 // Scripted printing will be allowed to continue. |
| 529 void Reset(); | 536 void Reset(); |
| 530 | 537 |
| 531 private: | 538 private: |
| 532 base::Time last_print_; | 539 base::Time last_print_; |
| 533 int count_ = 0; | 540 int count_ = 0; |
| 534 DISALLOW_COPY_AND_ASSIGN(ScriptingThrottler); | 541 DISALLOW_COPY_AND_ASSIGN(ScriptingThrottler); |
| 535 }; | 542 }; |
| 536 | 543 |
| 537 ScriptingThrottler scripting_throttler_; | 544 ScriptingThrottler scripting_throttler_; |
| 538 | 545 |
| 539 bool print_node_in_progress_; | 546 bool print_node_in_progress_; |
| 540 PrintPreviewContext print_preview_context_; | 547 PrintPreviewContext print_preview_context_; |
| 541 bool is_loading_; | 548 bool is_loading_; |
| 542 bool is_scripted_preview_delayed_; | 549 bool is_scripted_preview_delayed_; |
| 543 int ipc_nesting_level_; | 550 int ipc_nesting_level_; |
| 551 bool render_frame_gone_; |
| 544 | 552 |
| 545 // Used to fix a race condition where the source is a PDF and print preview | 553 // Used to fix a race condition where the source is a PDF and print preview |
| 546 // hangs because RequestPrintPreview is called before DidStopLoading() is | 554 // hangs because RequestPrintPreview is called before DidStopLoading() is |
| 547 // called. This is a store for the RequestPrintPreview() call and its | 555 // called. This is a store for the RequestPrintPreview() call and its |
| 548 // parameters so that it can be invoked after DidStopLoading. | 556 // parameters so that it can be invoked after DidStopLoading. |
| 549 base::Closure on_stop_loading_closure_; | 557 base::Closure on_stop_loading_closure_; |
| 550 | 558 |
| 551 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_; | 559 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_; |
| 552 | 560 |
| 553 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 561 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 554 }; | 562 }; |
| 555 | 563 |
| 556 } // namespace printing | 564 } // namespace printing |
| 557 | 565 |
| 558 #endif // COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 566 #endif // COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |