| 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 24 matching lines...) Expand all Loading... |
| 35 #define MAYBE_PrintWebViewHelperTest DISABLED_PrintWebViewHelperTest | 35 #define MAYBE_PrintWebViewHelperTest DISABLED_PrintWebViewHelperTest |
| 36 #define MAYBE_PrintWebViewHelperPreviewTest \ | 36 #define MAYBE_PrintWebViewHelperPreviewTest \ |
| 37 DISABLED_PrintWebViewHelperPreviewTest | 37 DISABLED_PrintWebViewHelperPreviewTest |
| 38 #else | 38 #else |
| 39 #define MAYBE_PrintWebViewHelperTest PrintWebViewHelperTest | 39 #define MAYBE_PrintWebViewHelperTest PrintWebViewHelperTest |
| 40 #define MAYBE_PrintWebViewHelperPreviewTest PrintWebViewHelperPreviewTest | 40 #define MAYBE_PrintWebViewHelperPreviewTest PrintWebViewHelperPreviewTest |
| 41 #endif // defined(OS_ANDROID) | 41 #endif // defined(OS_ANDROID) |
| 42 | 42 |
| 43 namespace base { | 43 namespace base { |
| 44 class DictionaryValue; | 44 class DictionaryValue; |
| 45 class ScopedClosureRunner; |
| 45 } | 46 } |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 class WebFrame; | 49 class WebFrame; |
| 49 class WebLocalFrame; | 50 class WebLocalFrame; |
| 50 class WebView; | 51 class WebView; |
| 51 } | 52 } |
| 52 | 53 |
| 53 namespace printing { | 54 namespace printing { |
| 54 | 55 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 65 ~FrameReference(); | 66 ~FrameReference(); |
| 66 | 67 |
| 67 void Reset(blink::WebLocalFrame* frame); | 68 void Reset(blink::WebLocalFrame* frame); |
| 68 | 69 |
| 69 blink::WebLocalFrame* GetFrame(); | 70 blink::WebLocalFrame* GetFrame(); |
| 70 blink::WebView* view(); | 71 blink::WebView* view(); |
| 71 | 72 |
| 72 private: | 73 private: |
| 73 blink::WebView* view_; | 74 blink::WebView* view_; |
| 74 blink::WebLocalFrame* frame_; | 75 blink::WebLocalFrame* frame_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(FrameReference); |
| 75 }; | 78 }; |
| 76 | 79 |
| 77 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 80 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
| 78 // We plan on making print asynchronous and that will require copying the DOM | 81 // We plan on making print asynchronous and that will require copying the DOM |
| 79 // of the document and creating a new WebView with the contents. | 82 // of the document and creating a new WebView with the contents. |
| 80 class PrintWebViewHelper | 83 class PrintWebViewHelper |
| 81 : public content::RenderFrameObserver, | 84 : public content::RenderFrameObserver, |
| 82 public content::RenderFrameObserverTracker<PrintWebViewHelper> { | 85 public content::RenderFrameObserverTracker<PrintWebViewHelper> { |
| 83 public: | 86 public: |
| 87 using GetPrintSettingsFromUserCallback = base::Callback<void( |
| 88 const PrintMsg_PrintPages_Params& /* print_settings */)>; |
| 89 |
| 84 class Delegate { | 90 class Delegate { |
| 85 public: | 91 public: |
| 86 virtual ~Delegate() {} | 92 virtual ~Delegate() {} |
| 87 | 93 |
| 88 // Cancels prerender if it's currently in progress and returns true if the | 94 // Cancels prerender if it's currently in progress and returns true if the |
| 89 // cancellation succeeded. | 95 // cancellation succeeded. |
| 90 virtual bool CancelPrerender(content::RenderFrame* render_frame) = 0; | 96 virtual bool CancelPrerender(content::RenderFrame* render_frame) = 0; |
| 91 | 97 |
| 92 // Returns the element to be printed. Returns a null WebElement if | 98 // Returns the element to be printed. Returns a null WebElement if |
| 93 // a pdf plugin element can't be extracted from the frame. | 99 // a pdf plugin element can't be extracted from the frame. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // Finalize the print ready preview document. | 221 // Finalize the print ready preview document. |
| 216 bool FinalizePrintReadyDocument(); | 222 bool FinalizePrintReadyDocument(); |
| 217 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 223 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 218 | 224 |
| 219 // Enable/Disable printing. | 225 // Enable/Disable printing. |
| 220 void OnSetPrintingEnabled(bool enabled); | 226 void OnSetPrintingEnabled(bool enabled); |
| 221 | 227 |
| 222 // Main printing code ------------------------------------------------------- | 228 // Main printing code ------------------------------------------------------- |
| 223 | 229 |
| 224 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 230 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 225 // |is_scripted| should be true when the call is coming from window.print() | 231 // Start printing with the system dialog. Continues to FinishPrint() below |
| 226 void Print(blink::WebLocalFrame* frame, | 232 // eventually. |
| 227 const blink::WebNode& node, | 233 // |is_scripted| should be true when the call is coming from window.print(). |
| 228 bool is_scripted); | 234 // WARNING: |this| may be gone after this method returns. |
| 235 void StartPrint(blink::WebLocalFrame* frame, |
| 236 const blink::WebNode& node, |
| 237 bool is_scripted, |
| 238 bool reset_print_node_in_progress); |
| 239 |
| 240 // Do the second phase of printing, since showing the system dialog in the |
| 241 // middle may require callbacks. Use the saved parameters and do the |
| 242 // rendering. |
| 243 void FinishPrint(std::unique_ptr<FrameReference> frame_ref, |
| 244 const blink::WebNode& node); |
| 229 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 245 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 230 | 246 |
| 231 // Notification when printing is done - signal tear-down/free resources. | 247 // Notification when printing is done - signal tear-down/free resources. |
| 232 void DidFinishPrinting(PrintingResult result); | 248 void DidFinishPrinting(PrintingResult result); |
| 233 | 249 |
| 234 // Print Settings ----------------------------------------------------------- | 250 // Print Settings ----------------------------------------------------------- |
| 235 | 251 |
| 236 // Initialize print page settings with default settings. | 252 // Initialize print page settings with default settings. |
| 237 // Used only for native printing workflow. | 253 // Used only for native printing workflow. |
| 238 bool InitPrintSettings(bool fit_to_paper_size); | 254 bool InitPrintSettings(bool fit_to_paper_size); |
| 239 | 255 |
| 240 // Calculate number of pages in source document. | 256 // Calculate number of pages in source document. |
| 241 bool CalculateNumberOfPages(blink::WebLocalFrame* frame, | 257 bool CalculateNumberOfPages(blink::WebLocalFrame* frame, |
| 242 const blink::WebNode& node, | 258 const blink::WebNode& node, |
| 243 int* number_of_pages); | 259 int* number_of_pages); |
| 244 | 260 |
| 245 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 261 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 246 // Set options for print preset from source PDF document. | 262 // Set options for print preset from source PDF document. |
| 247 bool SetOptionsFromPdfDocument( | 263 bool SetOptionsFromPdfDocument( |
| 248 PrintHostMsg_SetOptionsFromDocument_Params* options); | 264 PrintHostMsg_SetOptionsFromDocument_Params* options); |
| 249 | 265 |
| 250 // Update the current print settings with new |passed_job_settings|. | 266 // Update the current print settings with new |passed_job_settings|. |
| 251 // |passed_job_settings| dictionary contains print job details such as printer | 267 // |passed_job_settings| dictionary contains print job details such as printer |
| 252 // name, number of copies, page range, etc. | 268 // name, number of copies, page range, etc. |
| 253 bool UpdatePrintSettings(blink::WebLocalFrame* frame, | 269 bool UpdatePrintSettings(blink::WebLocalFrame* frame, |
| 254 const blink::WebNode& node, | 270 const blink::WebNode& node, |
| 255 const base::DictionaryValue& passed_job_settings); | 271 const base::DictionaryValue& passed_job_settings); |
| 256 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 272 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 257 | 273 |
| 258 // Get final print settings from the user. | 274 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 259 // Return false if the user cancels or on error. | 275 // Get final print settings from the user and eventually call |
| 260 bool GetPrintSettingsFromUser(blink::WebLocalFrame* frame, | 276 // OnGetPrintSettingsFromUser(). |
| 261 const blink::WebNode& node, | 277 // WARNING: |this| may be gone after this method returns. |
| 262 int expected_pages_count, | 278 void GetPrintSettingsFromUser( |
| 263 bool is_scripted); | 279 std::unique_ptr<FrameReference> frame_ref, |
| 280 const blink::WebNode& node, |
| 281 int expected_pages_count, |
| 282 bool is_scripted, |
| 283 std::unique_ptr<base::ScopedClosureRunner> on_finish_calback); |
| 284 |
| 285 // Do the actual printing rendering after Print() gets settings from the |
| 286 // system dialog. |
| 287 void OnGetPrintSettingsFromUser( |
| 288 std::unique_ptr<FrameReference> frame_ref, |
| 289 const blink::WebNode& node, |
| 290 std::unique_ptr<base::ScopedClosureRunner> on_finish_calback, |
| 291 const PrintMsg_PrintPages_Params& print_settings); |
| 292 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 264 | 293 |
| 265 // Page Printing / Rendering ------------------------------------------------ | 294 // Page Printing / Rendering ------------------------------------------------ |
| 266 | |
| 267 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 295 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 268 void OnFramePreparedForPrintPages(); | 296 void OnFramePreparedForPrintPages(); |
| 269 void PrintPages(); | 297 void PrintPages(); |
| 270 bool PrintPagesNative(blink::WebLocalFrame* frame, int page_count); | 298 bool PrintPagesNative(blink::WebLocalFrame* frame, int page_count); |
| 271 void FinishFramePrinting(); | 299 void FinishFramePrinting(); |
| 272 // Render the frame for printing. | 300 // Render the frame for printing. |
| 273 bool RenderPagesForPrint(blink::WebLocalFrame* frame, | 301 bool RenderPagesForPrint(blink::WebLocalFrame* frame, |
| 274 const blink::WebNode& node); | 302 const blink::WebNode& node); |
| 275 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 303 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 276 | 304 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // Return true if script initiated printing is currently | 373 // Return true if script initiated printing is currently |
| 346 // allowed. |user_initiated| should be true when a user event triggered the | 374 // allowed. |user_initiated| should be true when a user event triggered the |
| 347 // script, most likely by pressing a print button on the page. | 375 // script, most likely by pressing a print button on the page. |
| 348 bool IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, | 376 bool IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, |
| 349 bool user_initiated); | 377 bool user_initiated); |
| 350 | 378 |
| 351 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 379 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 352 // Shows scripted print preview when options from plugin are available. | 380 // Shows scripted print preview when options from plugin are available. |
| 353 void ShowScriptedPrintPreview(); | 381 void ShowScriptedPrintPreview(); |
| 354 | 382 |
| 383 // WARNING: |this| may be gone after this method returns when |type| is |
| 384 // PRINT_PREVIEW_SCRIPTED. |
| 355 void RequestPrintPreview(PrintPreviewRequestType type); | 385 void RequestPrintPreview(PrintPreviewRequestType type); |
| 356 | 386 |
| 357 // Checks whether print preview should continue or not. | 387 // Checks whether print preview should continue or not. |
| 358 // Returns true if canceling, false if continuing. | 388 // Returns true if canceling, false if continuing. |
| 359 bool CheckForCancel(); | 389 bool CheckForCancel(); |
| 360 | 390 |
| 361 // Notifies the browser a print preview page has been rendered. | 391 // Notifies the browser a print preview page has been rendered. |
| 362 // |page_number| is 0-based. | 392 // |page_number| is 0-based. |
| 363 // For a valid |page_number| with modifiable content, | 393 // For a valid |page_number| with modifiable content, |
| 364 // |metafile| is the rendered page. Otherwise |metafile| is NULL. | 394 // |metafile| is the rendered page. Otherwise |metafile| is NULL. |
| 365 // Returns true if print preview should continue, false on failure. | 395 // Returns true if print preview should continue, false on failure. |
| 366 bool PreviewPageRendered(int page_number, PdfMetafileSkia* metafile); | 396 bool PreviewPageRendered(int page_number, PdfMetafileSkia* metafile); |
| 367 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 397 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 368 | 398 |
| 399 void reset_scripted_preview_delayed() { |
| 400 is_scripted_preview_delayed_ = false; |
| 401 } |
| 402 |
| 403 void print_node_in_progress_finished() { print_node_in_progress_ = false; } |
| 404 |
| 369 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings); | 405 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings); |
| 370 | 406 |
| 371 // WebView used only to print the selection. | 407 // WebView used only to print the selection. |
| 372 std::unique_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 408 std::unique_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
| 373 bool reset_prep_frame_view_; | 409 bool reset_prep_frame_view_; |
| 374 | 410 |
| 375 std::unique_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 411 std::unique_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
| 376 bool is_print_ready_metafile_sent_; | 412 bool is_print_ready_metafile_sent_; |
| 377 bool ignore_css_margins_; | 413 bool ignore_css_margins_; |
| 378 | 414 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 base::Closure on_stop_loading_closure_; | 564 base::Closure on_stop_loading_closure_; |
| 529 | 565 |
| 530 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_; | 566 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_; |
| 531 | 567 |
| 532 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 568 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 533 }; | 569 }; |
| 534 | 570 |
| 535 } // namespace printing | 571 } // namespace printing |
| 536 | 572 |
| 537 #endif // COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 573 #endif // COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |