license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 8 | #include "base/ref_counted.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | #include "chrome/browser/printing/printed_pages_source.h" |
[email protected] | 0f08bf3 | 2009-05-21 20:33:17 | [diff] [blame^] | 10 | #include "chrome/common/notification_registrar.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | |
| 12 | class RenderViewHost; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 13 | class TabContents; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 14 | struct ViewHostMsg_DidPrintPage_Params; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | |
| 16 | namespace printing { |
| 17 | |
| 18 | class JobEventDetails; |
| 19 | class PrintJob; |
| 20 | class PrintJobWorkerOwner; |
| 21 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 22 | // Manages the print commands in relation to a TabContents. TabContents |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | // delegates a few printing related commands to this instance. |
| 24 | class PrintViewManager : public NotificationObserver, |
| 25 | public PrintedPagesSource { |
| 26 | public: |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 27 | PrintViewManager(TabContents& owner); |
[email protected] | 2d4537d5 | 2008-12-17 02:25:44 | [diff] [blame] | 28 | virtual ~PrintViewManager(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 29 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | // Cancels the print job. |
| 31 | void Stop(); |
| 32 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 33 | // Terminates or cancels the print job if one was pending, depending on the |
| 34 | // current state. Returns false if the renderer was not valuable. |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 35 | bool OnRenderViewGone(RenderViewHost* render_view_host); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 36 | |
| 37 | // Received a notification from the renderer that the number of printed page |
| 38 | // has just been calculated.. |
| 39 | void DidGetPrintedPagesCount(int cookie, int number_pages); |
| 40 | |
| 41 | // Received a notification from the renderer that a printed page page is |
| 42 | // finished renderering. |
| 43 | void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); |
| 44 | |
| 45 | // PrintedPagesSource implementation. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | virtual std::wstring RenderSourceName(); |
| 47 | virtual GURL RenderSourceUrl(); |
| 48 | |
| 49 | // NotificationObserver implementation. |
| 50 | virtual void Observe(NotificationType type, |
| 51 | const NotificationSource& source, |
| 52 | const NotificationDetails& details); |
| 53 | |
| 54 | private: |
| 55 | // Processes a NOTIFY_PRINT_JOB_EVENT notification. |
| 56 | void OnNotifyPrintJobEvent(const JobEventDetails& event_details); |
| 57 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | // Requests the RenderView to render all the missing pages for the print job. |
| 59 | // Noop if no print job is pending. Returns true if at least one page has been |
| 60 | // requested to the renderer. |
| 61 | bool RenderAllMissingPagesNow(); |
| 62 | |
| 63 | // Quits the current message loop if these conditions hold true: a document is |
| 64 | // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This |
| 65 | // function is called in DidPrintPage() or on ALL_PAGES_REQUESTED |
| 66 | // notification. The inner message loop is created was created by |
| 67 | // RenderAllMissingPagesNow(). |
| 68 | void ShouldQuitFromInnerMessageLoop(); |
| 69 | |
| 70 | // Creates a new empty print job. It has no settings loaded. If there is |
| 71 | // currently a print job, safely disconnect from it. Returns false if it is |
| 72 | // impossible to safely disconnect from the current print job or it is |
| 73 | // impossible to create a new print job. |
| 74 | bool CreateNewPrintJob(PrintJobWorkerOwner* job); |
| 75 | |
| 76 | // Makes sure the current print_job_ has all its data before continuing, and |
| 77 | // disconnect from it. |
| 78 | void DisconnectFromCurrentPrintJob(); |
| 79 | |
| 80 | // Terminates the print job. Noop if no print job has been created. If |
| 81 | // |cancel| is true, cancel it instead of waiting for the job to finish. Will |
| 82 | // call ReleasePrintJob(). |
| 83 | void TerminatePrintJob(bool cancel); |
| 84 | |
| 85 | // Releases print_job_. Correctly deregisters from notifications. Noop if |
| 86 | // no print job has been created. |
| 87 | void ReleasePrintJob(); |
| 88 | |
| 89 | // Prints the document. Starts the actual print job. Requests asynchronously |
| 90 | // the renderered pages from the renderer. Is called once the printing context |
| 91 | // is initialized, on a DEFAULT_INIT_DONE notification when waiting_to_print_ |
| 92 | // is true. |
| 93 | void PrintNowInternal(); |
| 94 | |
| 95 | // Runs an inner message loop. It will set inside_inner_message_loop_ to true |
| 96 | // while the blocking inner message loop is running. This is useful in cases |
| 97 | // where the RenderView is about to be destroyed while a printing job isn't |
| 98 | // finished. |
| 99 | bool RunInnerMessageLoop(); |
| 100 | |
| 101 | // In the case of Scripted Printing, where the renderer is controlling the |
| 102 | // control flow, print_job_ is initialized whenever possible. No-op is |
| 103 | // print_job_ is initialized. |
| 104 | bool OpportunisticallyCreatePrintJob(int cookie); |
| 105 | |
[email protected] | 0f08bf3 | 2009-05-21 20:33:17 | [diff] [blame^] | 106 | NotificationRegistrar registrar_; |
| 107 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 108 | // Manages the low-level talk to the printer. |
| 109 | scoped_refptr<PrintJob> print_job_; |
| 110 | |
| 111 | // Waiting for print_job_ initialization to be completed to start printing. |
| 112 | // Specifically the DEFAULT_INIT_DONE notification. Set when PrintNow() is |
| 113 | // called. |
| 114 | bool waiting_to_print_; |
| 115 | |
| 116 | // Running an inner message loop inside RenderAllMissingPagesNow(). This means |
| 117 | // we are _blocking_ until all the necessary pages have been rendered or the |
| 118 | // print settings are being loaded. |
| 119 | bool inside_inner_message_loop_; |
| 120 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 121 | // PrintViewManager is created as an extension of WebContent specialized for |
| 122 | // printing-related behavior. Still, access to the renderer is needed so a |
| 123 | // back reference is kept the the "parent object". |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 124 | TabContents& owner_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 125 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 126 | DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | } // namespace printing |
| 130 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 131 | #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |