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 <utility> | |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
14 #include "base/time.h" | 13 #include "base/time.h" |
15 #include "content/renderer/render_view_observer.h" | 14 #include "content/renderer/render_view_observer.h" |
16 #include "content/renderer/render_view_observer_tracker.h" | 15 #include "content/renderer/render_view_observer_tracker.h" |
17 #include "printing/metafile.h" | 16 #include "printing/metafile.h" |
18 #include "printing/metafile_impl.h" | 17 #include "printing/metafile_impl.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, | 102 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, |
104 BlockScriptInitiatedPrinting); | 103 BlockScriptInitiatedPrinting); |
105 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages); | 104 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages); |
106 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreview); | 105 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreview); |
107 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel); | 106 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel); |
108 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewFail); | 107 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewFail); |
109 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, | 108 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, |
110 OnPrintForPrintPreview); | 109 OnPrintForPrintPreview); |
111 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, | 110 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, |
112 OnPrintForPrintPreviewFail); | 111 OnPrintForPrintPreviewFail); |
| 112 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, |
| 113 OnPrintPreviewForSelectedPages); |
113 | 114 |
114 #if defined(OS_WIN) || defined(OS_MACOSX) | 115 #if defined(OS_WIN) || defined(OS_MACOSX) |
115 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest); | 116 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest); |
116 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe); | 117 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe); |
117 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 118 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
118 | 119 |
119 // RenderViewObserver implementation. | 120 // RenderViewObserver implementation. |
120 virtual bool OnMessageReceived(const IPC::Message& message); | 121 virtual bool OnMessageReceived(const IPC::Message& message); |
121 virtual void PrintPage(WebKit::WebFrame* frame); | 122 virtual void PrintPage(WebKit::WebFrame* frame); |
122 | 123 |
123 // Message handlers --------------------------------------------------------- | 124 // Message handlers --------------------------------------------------------- |
124 | 125 |
125 // Print the document. | 126 // Print the document. |
126 void OnPrintPages(); | 127 void OnPrintPages(); |
127 | 128 |
128 // Print the document with the print preview frame/node. | 129 // Print the document with the print preview frame/node. |
129 void OnPrintForSystemDialog(); | 130 void OnPrintForSystemDialog(); |
130 | 131 |
131 // Initiate print preview. | 132 // Initiate print preview. |
132 void OnInitiatePrintPreview(); | 133 void OnInitiatePrintPreview(); |
133 | 134 |
134 // Start the process of generating a print preview using |settings|. | 135 // Start the process of generating a print preview using |settings|. |
135 void OnPrintPreview(const base::DictionaryValue& settings); | 136 void OnPrintPreview(const base::DictionaryValue& settings); |
136 // Initialize the print preview document. | 137 // Initialize the print preview document. |
137 bool CreatePreviewDocument(); | 138 bool CreatePreviewDocument(); |
138 | 139 |
139 // Continue generating the print preview. |requested_preview_page_index| | 140 // Continue generating the print preview. |
140 // specifies the browser requested preview page index. It is 1-based or | 141 void OnContinuePreview(); |
141 // |printing::INVALID_PAGE_INDEX| to continue with next page. | |
142 void OnContinuePreview(int requested_preview_page_index); | |
143 // Renders a print preview page. |page_number| is 0-based. | 142 // Renders a print preview page. |page_number| is 0-based. |
144 void RenderPreviewPage(int page_number); | 143 void RenderPreviewPage(int page_number); |
145 // Finalize the print preview document. | 144 // Finalize the print ready preview document. |
146 bool FinalizePreviewDocument(); | 145 bool FinalizePrintReadyDocument(); |
147 | 146 |
148 // Abort the preview to put |print_preview_context_| into the 'UNINITIALIZED' | 147 // Abort the preview to put |print_preview_context_| into the 'UNINITIALIZED' |
149 // state. | 148 // state. |
150 void OnAbortPreview(); | 149 void OnAbortPreview(); |
151 | 150 |
152 // Print / preview the node under the context menu. | 151 // Print / preview the node under the context menu. |
153 void OnPrintNodeUnderContextMenu(); | 152 void OnPrintNodeUnderContextMenu(); |
154 | 153 |
155 // Print the pages for print preview. Do not display the native print dialog | 154 // Print the pages for print preview. Do not display the native print dialog |
156 // for user settings. |job_settings| has new print job settings values. | 155 // for user settings. |job_settings| has new print job settings values. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 290 |
292 // Notify the browser a print preview page has been rendered. | 291 // Notify the browser a print preview page has been rendered. |
293 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check | 292 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check |
294 // for pending preview requests. | 293 // for pending preview requests. |
295 void PreviewPageRendered(int page_number, printing::Metafile* metafile); | 294 void PreviewPageRendered(int page_number, printing::Metafile* metafile); |
296 | 295 |
297 WebKit::WebView* print_web_view_; | 296 WebKit::WebView* print_web_view_; |
298 | 297 |
299 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 298 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
300 bool is_preview_; | 299 bool is_preview_; |
| 300 bool is_print_ready_metafile_sent_; |
301 | 301 |
302 // Used for scripted initiated printing blocking. | 302 // Used for scripted initiated printing blocking. |
303 base::Time last_cancelled_script_print_; | 303 base::Time last_cancelled_script_print_; |
304 int user_cancelled_scripted_print_count_; | 304 int user_cancelled_scripted_print_count_; |
305 | 305 |
306 // Let the browser process know of a printing failure. Only set to false when | 306 // Let the browser process know of a printing failure. Only set to false when |
307 // the failure came from the browser in the first place. | 307 // the failure came from the browser in the first place. |
308 bool notify_browser_of_print_failure_; | 308 bool notify_browser_of_print_failure_; |
309 | 309 |
310 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 310 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
(...skipping 13 matching lines...) Expand all Loading... |
324 void OnPrintPreview(); | 324 void OnPrintPreview(); |
325 | 325 |
326 // Create the print preview document. |pages| is empty to print all pages. | 326 // Create the print preview document. |pages| is empty to print all pages. |
327 bool CreatePreviewDocument(PrintMsg_Print_Params* params, | 327 bool CreatePreviewDocument(PrintMsg_Print_Params* params, |
328 const std::vector<int>& pages); | 328 const std::vector<int>& pages); |
329 | 329 |
330 // Called after a page gets rendered. |page_time| is how long the | 330 // Called after a page gets rendered. |page_time| is how long the |
331 // rendering took. | 331 // rendering took. |
332 void RenderedPreviewPage(const base::TimeDelta& page_time); | 332 void RenderedPreviewPage(const base::TimeDelta& page_time); |
333 | 333 |
334 // Finalizes the print preview document. | 334 // Updates the print preview context when the required pages are rendered. |
335 void FinalizePreviewDocument(); | 335 void AllPagesRendered(); |
| 336 |
| 337 // Finalizes the print ready preview document. |
| 338 void FinalizePrintReadyDocument(); |
336 | 339 |
337 // Cleanup after print preview finishes. | 340 // Cleanup after print preview finishes. |
338 void Finished(); | 341 void Finished(); |
339 | 342 |
340 // Cleanup after print preview fails. | 343 // Cleanup after print preview fails. |
341 void Failed(); | 344 void Failed(); |
342 | 345 |
343 // Abort the print preview. | 346 // Abort the print preview. |
344 void Abort(); | 347 void Abort(); |
345 | 348 |
346 // Helper functions | 349 // Helper functions |
347 int GetNextPageNumber(); | 350 int GetNextPageNumber(); |
348 bool IsReadyToRender() const; | 351 bool IsReadyToRender() const; |
349 bool IsBusy() const; | 352 bool IsBusy() const; |
350 bool IsModifiable() const; | 353 bool IsModifiable() const; |
| 354 bool IsLastPageOfPrintReadyMetafile() const; |
| 355 bool IsFinalPageRendered() const; |
| 356 |
| 357 // Setters |
| 358 void set_generate_draft_pages(bool generate_draft_pages); |
351 | 359 |
352 // Getters | 360 // Getters |
353 WebKit::WebFrame* frame() const; | 361 WebKit::WebFrame* frame() const; |
354 WebKit::WebNode* node() const; | 362 WebKit::WebNode* node() const; |
355 int total_page_count() const; | 363 int total_page_count() const; |
| 364 bool generate_draft_pages(); |
356 printing::PreviewMetafile* metafile() const; | 365 printing::PreviewMetafile* metafile() const; |
357 const PrintMsg_Print_Params& print_params() const; | 366 const PrintMsg_Print_Params& print_params() const; |
358 const gfx::Size& GetPrintCanvasSize() const; | 367 const gfx::Size& GetPrintCanvasSize() const; |
359 | 368 |
360 private: | 369 private: |
361 enum State { | 370 enum State { |
362 UNINITIALIZED, // Not ready to render. | 371 UNINITIALIZED, // Not ready to render. |
363 INITIALIZED, // Ready to render. | 372 INITIALIZED, // Ready to render. |
364 RENDERING, // Rendering. | 373 RENDERING, // Rendering. |
365 DONE // Finished rendering. | 374 DONE // Finished rendering. |
366 }; | 375 }; |
367 | 376 |
368 // Reset some of the internal rendering context. | 377 // Reset some of the internal rendering context. |
369 void ClearContext(); | 378 void ClearContext(); |
370 | 379 |
371 // Specifies what to render for print preview. | 380 // Specifies what to render for print preview. |
372 WebKit::WebFrame* frame_; | 381 WebKit::WebFrame* frame_; |
373 scoped_ptr<WebKit::WebNode> node_; | 382 scoped_ptr<WebKit::WebNode> node_; |
374 | 383 |
375 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 384 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
376 scoped_ptr<printing::PreviewMetafile> metafile_; | 385 scoped_ptr<printing::PreviewMetafile> metafile_; |
377 scoped_ptr<PrintMsg_Print_Params> print_params_; | 386 scoped_ptr<PrintMsg_Print_Params> print_params_; |
378 | 387 |
379 // Total page count in the renderer. | 388 // Total page count in the renderer. |
380 int total_page_count_; | 389 int total_page_count_; |
381 | 390 |
382 // Number of pages to render. | 391 // List of page indices that need to be rendered. |
383 int actual_page_count_; | 392 std::vector<int> render_page_list_; |
384 | 393 |
385 // The current page to render. | 394 // Specifies the current list index. |
386 int current_page_number_; | 395 int render_page_list_index_; |
387 | 396 |
388 // |rendered_pages_| tracks which pages need to be printed as well as | 397 // True, when draft pages needs to be generated. |
389 // the page slot it should be printed in. See GetPageSlotForPage. | 398 bool generate_draft_pages_; |
390 typedef std::pair<bool, int> PreviewPageInfo; | 399 |
391 std::vector<PreviewPageInfo> rendered_pages_; | 400 // Specifies the total number of pages in the print ready metafile. |
| 401 int print_ready_metafile_page_count_; |
392 | 402 |
393 base::TimeDelta document_render_time_; | 403 base::TimeDelta document_render_time_; |
394 base::TimeTicks begin_time_; | 404 base::TimeTicks begin_time_; |
395 | 405 |
396 State state_; | 406 State state_; |
397 }; | 407 }; |
398 | 408 |
399 PrintPreviewContext print_preview_context_; | 409 PrintPreviewContext print_preview_context_; |
400 | 410 |
401 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 411 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
402 }; | 412 }; |
403 | 413 |
404 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 414 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |