OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 5 #ifndef CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
6 #define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 6 #define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "content/public/renderer/render_view_observer.h" | 14 #include "content/public/renderer/render_view_observer.h" |
15 #include "content/public/renderer/render_view_observer_tracker.h" | 15 #include "content/public/renderer/render_view_observer_tracker.h" |
16 #include "printing/metafile.h" | 16 #include "printing/metafile.h" |
17 #include "printing/metafile_impl.h" | 17 #include "printing/metafile_impl.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
22 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
23 | 23 |
| 24 class MessageLoop; |
24 struct PrintMsg_Print_Params; | 25 struct PrintMsg_Print_Params; |
25 struct PrintMsg_PrintPage_Params; | 26 struct PrintMsg_PrintPage_Params; |
26 struct PrintMsg_PrintPages_Params; | 27 struct PrintMsg_PrintPages_Params; |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class DictionaryValue; | 30 class DictionaryValue; |
30 } | 31 } |
31 namespace printing { | 32 namespace printing { |
32 struct PageSizeMargins; | 33 struct PageSizeMargins; |
33 } | 34 } |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // Returns true if cancelling, false if continuing. | 291 // Returns true if cancelling, false if continuing. |
291 bool CheckForCancel(); | 292 bool CheckForCancel(); |
292 | 293 |
293 // Notifies the browser a print preview page has been rendered. | 294 // Notifies the browser a print preview page has been rendered. |
294 // |page_number| is 0-based. | 295 // |page_number| is 0-based. |
295 // For a valid |page_number| with modifiable content, | 296 // For a valid |page_number| with modifiable content, |
296 // |metafile| is the rendered page. Otherwise |metafile| is NULL. | 297 // |metafile| is the rendered page. Otherwise |metafile| is NULL. |
297 // Returns true if print preview should continue, false on failure. | 298 // Returns true if print preview should continue, false on failure. |
298 bool PreviewPageRendered(int page_number, printing::Metafile* metafile); | 299 bool PreviewPageRendered(int page_number, printing::Metafile* metafile); |
299 | 300 |
| 301 // Stop the nested message loop when print preview has finished. |
| 302 void OnPrintPreviewDone(); |
| 303 |
300 WebKit::WebView* print_web_view_; | 304 WebKit::WebView* print_web_view_; |
301 | 305 |
302 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 306 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
303 bool is_preview_; | 307 bool is_preview_; |
304 bool is_print_ready_metafile_sent_; | 308 bool is_print_ready_metafile_sent_; |
305 | 309 |
306 // Used for scripted initiated printing blocking. | 310 // Used for scripted initiated printing blocking. |
307 base::Time last_cancelled_script_print_; | 311 base::Time last_cancelled_script_print_; |
308 int user_cancelled_scripted_print_count_; | 312 int user_cancelled_scripted_print_count_; |
309 | 313 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Helper functions | 371 // Helper functions |
368 int GetNextPageNumber(); | 372 int GetNextPageNumber(); |
369 bool IsReadyToRender() const; | 373 bool IsReadyToRender() const; |
370 bool IsModifiable() const; | 374 bool IsModifiable() const; |
371 bool IsLastPageOfPrintReadyMetafile() const; | 375 bool IsLastPageOfPrintReadyMetafile() const; |
372 bool IsFinalPageRendered() const; | 376 bool IsFinalPageRendered() const; |
373 | 377 |
374 // Setters | 378 // Setters |
375 void set_generate_draft_pages(bool generate_draft_pages); | 379 void set_generate_draft_pages(bool generate_draft_pages); |
376 void set_error(enum PrintPreviewErrorBuckets error); | 380 void set_error(enum PrintPreviewErrorBuckets error); |
| 381 void set_message_loop(MessageLoop* message_loop); |
377 | 382 |
378 // Getters | 383 // Getters |
379 WebKit::WebFrame* frame() const; | 384 WebKit::WebFrame* frame() const; |
380 const WebKit::WebNode& node() const; | 385 const WebKit::WebNode& node() const; |
| 386 MessageLoop* message_loop() const; |
381 int total_page_count() const; | 387 int total_page_count() const; |
382 bool generate_draft_pages(); | 388 bool generate_draft_pages(); |
383 printing::PreviewMetafile* metafile() const; | 389 printing::PreviewMetafile* metafile() const; |
384 const PrintMsg_Print_Params& print_params() const; | 390 const PrintMsg_Print_Params& print_params() const; |
385 const gfx::Size& GetPrintCanvasSize() const; | 391 const gfx::Size& GetPrintCanvasSize() const; |
386 int last_error() const; | 392 int last_error() const; |
387 | 393 |
388 private: | 394 private: |
389 enum State { | 395 enum State { |
390 UNINITIALIZED, // Not ready to render. | 396 UNINITIALIZED, // Not ready to render. |
391 INITIALIZED, // Ready to render. | 397 INITIALIZED, // Ready to render. |
392 RENDERING, // Rendering. | 398 RENDERING, // Rendering. |
393 DONE // Finished rendering. | 399 DONE // Finished rendering. |
394 }; | 400 }; |
395 | 401 |
396 // Reset some of the internal rendering context. | 402 // Reset some of the internal rendering context. |
397 void ClearContext(); | 403 void ClearContext(); |
398 | 404 |
399 // Specifies what to render for print preview. | 405 // Specifies what to render for print preview. |
400 WebKit::WebFrame* frame_; | 406 WebKit::WebFrame* frame_; |
401 WebKit::WebNode node_; | 407 WebKit::WebNode node_; |
402 | 408 |
403 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 409 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
404 scoped_ptr<printing::PreviewMetafile> metafile_; | 410 scoped_ptr<printing::PreviewMetafile> metafile_; |
405 scoped_ptr<PrintMsg_Print_Params> print_params_; | 411 scoped_ptr<PrintMsg_Print_Params> print_params_; |
406 | 412 |
| 413 MessageLoop* message_loop_; |
| 414 |
407 // Total page count in the renderer. | 415 // Total page count in the renderer. |
408 int total_page_count_; | 416 int total_page_count_; |
409 | 417 |
410 // The current page to render. | 418 // The current page to render. |
411 int current_page_index_; | 419 int current_page_index_; |
412 | 420 |
413 // List of page indices that need to be rendered. | 421 // List of page indices that need to be rendered. |
414 std::vector<int> pages_to_render_; | 422 std::vector<int> pages_to_render_; |
415 | 423 |
416 // True, when draft pages needs to be generated. | 424 // True, when draft pages needs to be generated. |
417 bool generate_draft_pages_; | 425 bool generate_draft_pages_; |
418 | 426 |
419 // Specifies the total number of pages in the print ready metafile. | 427 // Specifies the total number of pages in the print ready metafile. |
420 int print_ready_metafile_page_count_; | 428 int print_ready_metafile_page_count_; |
421 | 429 |
422 base::TimeDelta document_render_time_; | 430 base::TimeDelta document_render_time_; |
423 base::TimeTicks begin_time_; | 431 base::TimeTicks begin_time_; |
424 | 432 |
425 enum PrintPreviewErrorBuckets error_; | 433 enum PrintPreviewErrorBuckets error_; |
426 | 434 |
427 State state_; | 435 State state_; |
428 }; | 436 }; |
429 | 437 |
430 PrintPreviewContext print_preview_context_; | 438 PrintPreviewContext print_preview_context_; |
431 | 439 |
432 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 440 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
433 }; | 441 }; |
434 | 442 |
435 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 443 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |