[email protected] | f081575 | 2011-02-01 22:23:44 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | d9d4299 | 2010-09-13 19:39:19 | [diff] [blame] | 10 | #include "base/string16.h" |
[email protected] | 299425b | 2011-03-02 07:45:20 | [diff] [blame] | 11 | #include "content/browser/tab_contents/tab_contents_observer.h" |
[email protected] | ebbbb9f | 2011-03-09 13:16:14 | [diff] [blame] | 12 | #include "content/common/notification_observer.h" |
| 13 | #include "content/common/notification_registrar.h" |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 14 | #include "printing/printed_pages_source.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | |
| 16 | class RenderViewHost; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 17 | class TabContents; |
[email protected] | 1375e3ab | 2011-03-24 17:07:22 | [diff] [blame] | 18 | struct PrintHostMsg_DidPrintPage_Params; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
| 20 | namespace printing { |
| 21 | |
| 22 | class JobEventDetails; |
| 23 | class PrintJob; |
| 24 | class PrintJobWorkerOwner; |
| 25 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 26 | // Manages the print commands in relation to a TabContents. TabContents |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | // delegates a few printing related commands to this instance. |
| 28 | class PrintViewManager : public NotificationObserver, |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 29 | public PrintedPagesSource, |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 30 | public TabContentsObserver { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | public: |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 32 | explicit PrintViewManager(TabContents* tab_contents); |
[email protected] | 2d4537d5 | 2008-12-17 02:25:44 | [diff] [blame] | 33 | virtual ~PrintViewManager(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | |
[email protected] | 101f66b6 | 2011-04-07 19:46:06 | [diff] [blame] | 35 | // Override the title for this PrintViewManager's PrintJobs using the title |
| 36 | // in |tab_contents|. |
| 37 | void OverrideTitle(TabContents* tab_contents); |
| 38 | |
[email protected] | 49fe226 | 2011-04-15 20:56:15 | [diff] [blame^] | 39 | // Prints the current document immediately. Since the rendering is |
| 40 | // asynchronous, the actual printing will not be completed on the return of |
| 41 | // this function. Returns false if printing is impossible at the moment. |
| 42 | bool PrintNow(); |
| 43 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 44 | // PrintedPagesSource implementation. |
[email protected] | d9d4299 | 2010-09-13 19:39:19 | [diff] [blame] | 45 | virtual string16 RenderSourceName(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | virtual GURL RenderSourceUrl(); |
| 47 | |
| 48 | // NotificationObserver implementation. |
| 49 | virtual void Observe(NotificationType type, |
| 50 | const NotificationSource& source, |
| 51 | const NotificationDetails& details); |
| 52 | |
[email protected] | 585b3036 | 2011-01-28 02:30:17 | [diff] [blame] | 53 | // TabContentsObserver implementation. |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 54 | virtual bool OnMessageReceived(const IPC::Message& message); |
| 55 | |
[email protected] | 2e3f457 | 2011-03-25 19:24:47 | [diff] [blame] | 56 | // Terminates or cancels the print job if one was pending. |
[email protected] | dfcb0e5 | 2011-03-25 19:51:00 | [diff] [blame] | 57 | virtual void RenderViewGone(); |
[email protected] | 2e3f457 | 2011-03-25 19:24:47 | [diff] [blame] | 58 | |
| 59 | // Cancels the print job. |
| 60 | virtual void StopNavigation(); |
| 61 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 62 | private: |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 63 | void OnDidGetPrintedPagesCount(int cookie, int number_pages); |
[email protected] | 1375e3ab | 2011-03-24 17:07:22 | [diff] [blame] | 64 | void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); |
[email protected] | 34f128d | 2011-01-25 19:07:44 | [diff] [blame] | 65 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 66 | // Processes a NOTIFY_PRINT_JOB_EVENT notification. |
| 67 | void OnNotifyPrintJobEvent(const JobEventDetails& event_details); |
| 68 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | // Requests the RenderView to render all the missing pages for the print job. |
| 70 | // Noop if no print job is pending. Returns true if at least one page has been |
| 71 | // requested to the renderer. |
| 72 | bool RenderAllMissingPagesNow(); |
| 73 | |
| 74 | // Quits the current message loop if these conditions hold true: a document is |
| 75 | // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This |
| 76 | // function is called in DidPrintPage() or on ALL_PAGES_REQUESTED |
| 77 | // notification. The inner message loop is created was created by |
| 78 | // RenderAllMissingPagesNow(). |
| 79 | void ShouldQuitFromInnerMessageLoop(); |
| 80 | |
| 81 | // Creates a new empty print job. It has no settings loaded. If there is |
| 82 | // currently a print job, safely disconnect from it. Returns false if it is |
| 83 | // impossible to safely disconnect from the current print job or it is |
| 84 | // impossible to create a new print job. |
| 85 | bool CreateNewPrintJob(PrintJobWorkerOwner* job); |
| 86 | |
| 87 | // Makes sure the current print_job_ has all its data before continuing, and |
| 88 | // disconnect from it. |
| 89 | void DisconnectFromCurrentPrintJob(); |
| 90 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 91 | // Notify that the printing is done. |
| 92 | void PrintingDone(bool success); |
| 93 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 94 | // Terminates the print job. Noop if no print job has been created. If |
| 95 | // |cancel| is true, cancel it instead of waiting for the job to finish. Will |
| 96 | // call ReleasePrintJob(). |
| 97 | void TerminatePrintJob(bool cancel); |
| 98 | |
| 99 | // Releases print_job_. Correctly deregisters from notifications. Noop if |
| 100 | // no print job has been created. |
| 101 | void ReleasePrintJob(); |
| 102 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 103 | // Runs an inner message loop. It will set inside_inner_message_loop_ to true |
| 104 | // while the blocking inner message loop is running. This is useful in cases |
| 105 | // where the RenderView is about to be destroyed while a printing job isn't |
| 106 | // finished. |
| 107 | bool RunInnerMessageLoop(); |
| 108 | |
| 109 | // In the case of Scripted Printing, where the renderer is controlling the |
| 110 | // control flow, print_job_ is initialized whenever possible. No-op is |
| 111 | // print_job_ is initialized. |
| 112 | bool OpportunisticallyCreatePrintJob(int cookie); |
| 113 | |
[email protected] | 0f08bf3 | 2009-05-21 20:33:17 | [diff] [blame] | 114 | NotificationRegistrar registrar_; |
| 115 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 116 | // Manages the low-level talk to the printer. |
| 117 | scoped_refptr<PrintJob> print_job_; |
| 118 | |
[email protected] | f081575 | 2011-02-01 22:23:44 | [diff] [blame] | 119 | // Number of pages to print in the print job. |
| 120 | int number_pages_; |
| 121 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | // Waiting for print_job_ initialization to be completed to start printing. |
| 123 | // Specifically the DEFAULT_INIT_DONE notification. Set when PrintNow() is |
| 124 | // called. |
| 125 | bool waiting_to_print_; |
| 126 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 127 | // Indication of success of the print job. |
| 128 | bool printing_succeeded_; |
| 129 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 130 | // Running an inner message loop inside RenderAllMissingPagesNow(). This means |
| 131 | // we are _blocking_ until all the necessary pages have been rendered or the |
| 132 | // print settings are being loaded. |
| 133 | bool inside_inner_message_loop_; |
| 134 | |
[email protected] | da4eefd | 2011-03-03 23:40:27 | [diff] [blame] | 135 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 136 | // Set to true when OnDidPrintPage() should be expecting the first page. |
| 137 | bool expecting_first_page_; |
| 138 | #endif |
| 139 | |
[email protected] | 101f66b6 | 2011-04-07 19:46:06 | [diff] [blame] | 140 | // Title override. |
| 141 | bool is_title_overridden_; |
| 142 | string16 overridden_title_; |
| 143 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 144 | DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | } // namespace printing |
| 148 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 149 | #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |