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