| 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 <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 void OnPrintForSystemDialog(); | 135 void OnPrintForSystemDialog(); |
| 136 | 136 |
| 137 // Initiate print preview. | 137 // Initiate print preview. |
| 138 void OnInitiatePrintPreview(); | 138 void OnInitiatePrintPreview(); |
| 139 | 139 |
| 140 // Start the process of generating a print preview using |settings|. | 140 // Start the process of generating a print preview using |settings|. |
| 141 void OnPrintPreview(const base::DictionaryValue& settings); | 141 void OnPrintPreview(const base::DictionaryValue& settings); |
| 142 // Initialize the print preview document. | 142 // Initialize the print preview document. |
| 143 bool CreatePreviewDocument(); | 143 bool CreatePreviewDocument(); |
| 144 | 144 |
| 145 // Continue generating the print preview. |requested_preview_page_index| | |
| 146 // specifies the browser requested preview page index. It is 1-based or | |
| 147 // |printing::INVALID_PAGE_INDEX| to continue with next page. | |
| 148 void OnContinuePreview(int requested_preview_page_index); | |
| 149 // Renders a print preview page. |page_number| is 0-based. | 145 // Renders a print preview page. |page_number| is 0-based. |
| 150 void RenderPreviewPage(int page_number); | 146 // Returns true if print preview should continue, false on failure. |
| 147 bool RenderPreviewPage(int page_number); |
| 148 |
| 151 // Finalize the print preview document. | 149 // Finalize the print preview document. |
| 152 bool FinalizePreviewDocument(); | 150 bool FinalizePreviewDocument(); |
| 153 | 151 |
| 154 // Abort the preview to put |print_preview_context_| into the 'UNINITIALIZED' | |
| 155 // state. | |
| 156 void OnAbortPreview(); | |
| 157 | |
| 158 // Print / preview the node under the context menu. | 152 // Print / preview the node under the context menu. |
| 159 void OnPrintNodeUnderContextMenu(); | 153 void OnPrintNodeUnderContextMenu(); |
| 160 | 154 |
| 161 // 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 |
| 162 // for user settings. |job_settings| has new print job settings values. | 156 // for user settings. |job_settings| has new print job settings values. |
| 163 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); | 157 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); |
| 164 | 158 |
| 165 void OnPrintingDone(bool success); | 159 void OnPrintingDone(bool success); |
| 166 | 160 |
| 167 // Main printing code ------------------------------------------------------- | 161 // Main printing code ------------------------------------------------------- |
| 168 | 162 |
| 169 void Print(WebKit::WebFrame* frame, WebKit::WebNode* node); | 163 void Print(WebKit::WebFrame* frame, WebKit::WebNode* node); |
| 170 | 164 |
| 171 enum PrintingResult { | 165 enum PrintingResult { |
| 172 OK, | 166 OK, |
| 173 FAIL_PRINT, | 167 FAIL_PRINT, |
| 174 FAIL_PREVIEW, | 168 FAIL_PREVIEW, |
| 175 ABORT_PREVIEW, | |
| 176 }; | 169 }; |
| 177 | 170 |
| 178 // Notification when printing is done - signal tear-down/free resources. | 171 // Notification when printing is done - signal tear-down/free resources. |
| 179 void DidFinishPrinting(PrintingResult result); | 172 void DidFinishPrinting(PrintingResult result); |
| 180 | 173 |
| 181 // Print Settings ----------------------------------------------------------- | 174 // Print Settings ----------------------------------------------------------- |
| 182 | 175 |
| 183 // Initialize print page settings with default settings. | 176 // Initialize print page settings with default settings. |
| 184 bool InitPrintSettings(WebKit::WebFrame* frame, WebKit::WebNode* node); | 177 bool InitPrintSettings(WebKit::WebFrame* frame, WebKit::WebNode* node); |
| 185 | 178 |
| 186 // Initialize print page settings with default settings and prepare the frame | 179 // Initialize print page settings with default settings and prepare the frame |
| 187 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the | 180 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the |
| 188 // request and is filled into the |prepare| argument. | 181 // request and is filled into the |prepare| argument. |
| 189 bool InitPrintSettingsAndPrepareFrame( | 182 bool InitPrintSettingsAndPrepareFrame( |
| 190 WebKit::WebFrame* frame, | 183 WebKit::WebFrame* frame, |
| 191 WebKit::WebNode* node, | 184 WebKit::WebNode* node, |
| 192 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); | 185 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); |
| 193 | 186 |
| 194 // Parse the request id out of |job_settings| and store it in |params|. | |
| 195 // Returns false on failure. | |
| 196 bool UpdatePrintSettingsRequestId(const base::DictionaryValue& job_settings, | |
| 197 PrintMsg_Print_Params* params); | |
| 198 | |
| 199 // Update the current print settings with new |job_settings|. |job_settings| | 187 // Update the current print settings with new |job_settings|. |job_settings| |
| 200 // dictionary contains print job details such as printer name, number of | 188 // dictionary contains print job details such as printer name, number of |
| 201 // copies, page range, etc. | 189 // copies, page range, etc. |
| 202 bool UpdatePrintSettings(const base::DictionaryValue& job_settings); | 190 bool UpdatePrintSettings(const base::DictionaryValue& job_settings); |
| 203 | 191 |
| 204 // Get final print settings from the user. | 192 // Get final print settings from the user. |
| 205 // Return false if the user cancels or on error. | 193 // Return false if the user cancels or on error. |
| 206 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 194 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
| 207 int expected_pages_count, | 195 int expected_pages_count, |
| 208 bool use_browser_overlays); | 196 bool use_browser_overlays); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 286 |
| 299 // Increment the counter for script initiated printing. | 287 // Increment the counter for script initiated printing. |
| 300 // Scripted printing will be blocked for a limited amount of time. | 288 // Scripted printing will be blocked for a limited amount of time. |
| 301 void IncrementScriptedPrintCount(); | 289 void IncrementScriptedPrintCount(); |
| 302 | 290 |
| 303 // Displays the print job error message to the user. | 291 // Displays the print job error message to the user. |
| 304 void DisplayPrintJobError(); | 292 void DisplayPrintJobError(); |
| 305 | 293 |
| 306 void RequestPrintPreview(); | 294 void RequestPrintPreview(); |
| 307 | 295 |
| 308 // Notify the browser a print preview page has been rendered. | 296 // Checks whether print preview should continue or not. |
| 309 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check | 297 // Returns true if cancelling, false if continuing. |
| 310 // for pending preview requests. | 298 bool CheckForCancel(); |
| 311 void PreviewPageRendered(int page_number, printing::Metafile* metafile); | 299 |
| 300 // Notifies the browser a print preview page has been rendered. |
| 301 // |page_number| is 0-based. |
| 302 // For a valid |page_number| with modifiable content, |
| 303 // |metafile| is the rendered page. Otherwise |metafile| is NULL. |
| 304 // Returns true if print preview should continue, false on failure. |
| 305 bool PreviewPageRendered(int page_number, printing::Metafile* metafile); |
| 312 | 306 |
| 313 WebKit::WebView* print_web_view_; | 307 WebKit::WebView* print_web_view_; |
| 314 | 308 |
| 315 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 309 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
| 316 bool is_preview_; | 310 bool is_preview_; |
| 317 | 311 |
| 318 // Used for scripted initiated printing blocking. | 312 // Used for scripted initiated printing blocking. |
| 319 base::Time last_cancelled_script_print_; | 313 base::Time last_cancelled_script_print_; |
| 320 int user_cancelled_scripted_print_count_; | 314 int user_cancelled_scripted_print_count_; |
| 321 | 315 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 347 |
| 354 // Finalizes the print preview document. | 348 // Finalizes the print preview document. |
| 355 void FinalizePreviewDocument(); | 349 void FinalizePreviewDocument(); |
| 356 | 350 |
| 357 // Cleanup after print preview finishes. | 351 // Cleanup after print preview finishes. |
| 358 void Finished(); | 352 void Finished(); |
| 359 | 353 |
| 360 // Cleanup after print preview fails. | 354 // Cleanup after print preview fails. |
| 361 void Failed(); | 355 void Failed(); |
| 362 | 356 |
| 363 // Abort the print preview. | |
| 364 void Abort(); | |
| 365 | |
| 366 // Helper functions | 357 // Helper functions |
| 367 int GetNextPageNumber(); | 358 int GetNextPageNumber(); |
| 368 bool IsReadyToRender() const; | 359 bool IsReadyToRender() const; |
| 369 bool IsBusy() const; | |
| 370 bool IsModifiable() const; | 360 bool IsModifiable() const; |
| 371 | 361 |
| 372 // Getters | 362 // Getters |
| 373 WebKit::WebFrame* frame() const; | 363 WebKit::WebFrame* frame() const; |
| 374 WebKit::WebNode* node() const; | 364 WebKit::WebNode* node() const; |
| 375 int total_page_count() const; | 365 int total_page_count() const; |
| 376 printing::PreviewMetafile* metafile() const; | 366 printing::PreviewMetafile* metafile() const; |
| 377 const PrintMsg_Print_Params& print_params() const; | 367 const PrintMsg_Print_Params& print_params() const; |
| 378 const gfx::Size& GetPrintCanvasSize() const; | 368 const gfx::Size& GetPrintCanvasSize() const; |
| 379 | 369 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 396 scoped_ptr<printing::PreviewMetafile> metafile_; | 386 scoped_ptr<printing::PreviewMetafile> metafile_; |
| 397 scoped_ptr<PrintMsg_Print_Params> print_params_; | 387 scoped_ptr<PrintMsg_Print_Params> print_params_; |
| 398 | 388 |
| 399 // Total page count in the renderer. | 389 // Total page count in the renderer. |
| 400 int total_page_count_; | 390 int total_page_count_; |
| 401 | 391 |
| 402 // Number of pages to render. | 392 // Number of pages to render. |
| 403 int actual_page_count_; | 393 int actual_page_count_; |
| 404 | 394 |
| 405 // The current page to render. | 395 // The current page to render. |
| 406 int current_page_number_; | 396 int current_page_index_; |
| 407 | 397 |
| 408 // |rendered_pages_| tracks which pages need to be printed as well as | 398 std::vector<int> pages_to_render_; |
| 409 // the page slot it should be printed in. See GetPageSlotForPage. | |
| 410 typedef std::pair<bool, int> PreviewPageInfo; | |
| 411 std::vector<PreviewPageInfo> rendered_pages_; | |
| 412 | 399 |
| 413 base::TimeDelta document_render_time_; | 400 base::TimeDelta document_render_time_; |
| 414 base::TimeTicks begin_time_; | 401 base::TimeTicks begin_time_; |
| 415 | 402 |
| 416 State state_; | 403 State state_; |
| 417 }; | 404 }; |
| 418 | 405 |
| 419 PrintPreviewContext print_preview_context_; | 406 PrintPreviewContext print_preview_context_; |
| 420 | 407 |
| 421 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 408 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 422 }; | 409 }; |
| 423 | 410 |
| 424 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 411 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |