blob: 195c3bab0cf96ed7885bb5347c8e72cfb81a0424 [file] [log] [blame]
[email protected]f0815752011-02-01 22:23:441// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]bfd04a62009-02-01 18:16:565#ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
6#define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commit09911bf2008-07-26 23:55:298
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/ref_counted.h"
[email protected]d9d42992010-09-13 19:39:1910#include "base/string16.h"
[email protected]299425b2011-03-02 07:45:2011#include "content/browser/tab_contents/tab_contents_observer.h"
[email protected]6c2381d2011-10-19 02:52:5312#include "content/public/browser/notification_observer.h"
13#include "content/public/browser/notification_registrar.h"
[email protected]8ff1d422009-07-07 21:31:3914#include "printing/printed_pages_source.h"
initial.commit09911bf2008-07-26 23:55:2915
[email protected]34d38be2011-06-09 20:44:5816class TabContentsWrapper;
[email protected]1375e3ab2011-03-24 17:07:2217struct PrintHostMsg_DidPrintPage_Params;
initial.commit09911bf2008-07-26 23:55:2918
[email protected]a9c36832011-11-23 08:55:2419namespace content {
20class RenderProcessHost;
21}
22
initial.commit09911bf2008-07-26 23:55:2923namespace printing {
24
25class JobEventDetails;
26class PrintJob;
27class PrintJobWorkerOwner;
[email protected]0b481bf2011-06-29 20:33:0028class PrintViewManagerObserver;
initial.commit09911bf2008-07-26 23:55:2929
[email protected]57c6a652009-05-04 07:58:3430// Manages the print commands in relation to a TabContents. TabContents
initial.commit09911bf2008-07-26 23:55:2931// delegates a few printing related commands to this instance.
[email protected]6c2381d2011-10-19 02:52:5332class PrintViewManager : public content::NotificationObserver,
[email protected]8d3347f2009-07-09 22:00:2133 public PrintedPagesSource,
[email protected]585b30362011-01-28 02:30:1734 public TabContentsObserver {
initial.commit09911bf2008-07-26 23:55:2935 public:
[email protected]34d38be2011-06-09 20:44:5836 explicit PrintViewManager(TabContentsWrapper* tab);
[email protected]2d4537d52008-12-17 02:25:4437 virtual ~PrintViewManager();
initial.commit09911bf2008-07-26 23:55:2938
[email protected]49fe2262011-04-15 20:56:1539 // 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
[email protected]3121c76b2011-07-22 02:34:3244 // Same as PrintNow(), but for the case where a user prints with the system
45 // dialog from print preview.
46 bool PrintForSystemDialogNow();
47
[email protected]0996e9b2011-08-26 17:59:0148 // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
49 // show the native system dialog. This can happen from both initiator tab and
50 // preview tab.
51 bool AdvancedPrintNow();
52
[email protected]8980e0d2011-05-27 19:16:2353 // Initiate print preview of the current document by first notifying the
54 // renderer. Since this happens asynchronous, the print preview tab creation
55 // will not be completed on the return of this function. Returns false if
56 // print preview is impossible at the moment.
57 bool PrintPreviewNow();
58
[email protected]a9c36832011-11-23 08:55:2459 // Notify PrintViewManager that print preview has finished. Unfreeze the
60 // renderer in the case of scripted print preview.
61 void PrintPreviewDone();
62
[email protected]428f02392011-06-11 01:30:5563 // Handles cancelled preview printing request.
64 void PreviewPrintingRequestCancelled();
65
[email protected]0b481bf2011-06-29 20:33:0066 // Sets |observer| as the current PrintViewManagerObserver. Pass in NULL to
67 // remove the current observer. |observer| may always be NULL, but |observer_|
68 // must be NULL if |observer| is non-NULL.
69 void set_observer(PrintViewManagerObserver* observer);
70
initial.commit09911bf2008-07-26 23:55:2971 // PrintedPagesSource implementation.
[email protected]184a6c8f2011-10-04 20:07:3072 virtual string16 RenderSourceName() OVERRIDE;
initial.commit09911bf2008-07-26 23:55:2973
[email protected]6c2381d2011-10-19 02:52:5374 // content::NotificationObserver implementation.
[email protected]432115822011-07-10 15:52:2775 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:5376 const content::NotificationSource& source,
77 const content::NotificationDetails& details) OVERRIDE;
initial.commit09911bf2008-07-26 23:55:2978
[email protected]585b30362011-01-28 02:30:1779 // TabContentsObserver implementation.
[email protected]184a6c8f2011-10-04 20:07:3080 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
[email protected]34f128d2011-01-25 19:07:4481
[email protected]2e3f4572011-03-25 19:24:4782 // Terminates or cancels the print job if one was pending.
[email protected]9cddb1a22011-11-15 15:04:2783 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
[email protected]2e3f4572011-03-25 19:24:4784
85 // Cancels the print job.
[email protected]9cddb1a22011-11-15 15:04:2786 virtual void StopNavigation() OVERRIDE;
[email protected]2e3f4572011-03-25 19:24:4787
initial.commit09911bf2008-07-26 23:55:2988 private:
[email protected]a9c36832011-11-23 08:55:2489 enum PrintPreviewState {
90 NOT_PREVIEWING,
91 USER_INITIATED_PREVIEW,
92 SCRIPTED_PREVIEW,
93 };
94
[email protected]b3ee0b522011-05-06 04:06:4095 // IPC Message handlers.
[email protected]34f128d2011-01-25 19:07:4496 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
[email protected]da089562011-07-01 01:54:4697 void OnDidGetDocumentCookie(int cookie);
[email protected]0b481bf2011-06-29 20:33:0098 void OnDidShowPrintDialog();
[email protected]1375e3ab2011-03-24 17:07:2299 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
[email protected]b3ee0b522011-05-06 04:06:40100 void OnPrintingFailed(int cookie);
[email protected]34f128d2011-01-25 19:07:44101
[email protected]a9c36832011-11-23 08:55:24102 void OnScriptedPrintPreview(IPC::Message* reply_msg);
103 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg);
104
initial.commit09911bf2008-07-26 23:55:29105 // Processes a NOTIFY_PRINT_JOB_EVENT notification.
106 void OnNotifyPrintJobEvent(const JobEventDetails& event_details);
107
initial.commit09911bf2008-07-26 23:55:29108 // Requests the RenderView to render all the missing pages for the print job.
[email protected]184a6c8f2011-10-04 20:07:30109 // No-op if no print job is pending. Returns true if at least one page has
110 // been requested to the renderer.
initial.commit09911bf2008-07-26 23:55:29111 bool RenderAllMissingPagesNow();
112
113 // Quits the current message loop if these conditions hold true: a document is
114 // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This
115 // function is called in DidPrintPage() or on ALL_PAGES_REQUESTED
116 // notification. The inner message loop is created was created by
117 // RenderAllMissingPagesNow().
118 void ShouldQuitFromInnerMessageLoop();
119
120 // Creates a new empty print job. It has no settings loaded. If there is
121 // currently a print job, safely disconnect from it. Returns false if it is
122 // impossible to safely disconnect from the current print job or it is
123 // impossible to create a new print job.
124 bool CreateNewPrintJob(PrintJobWorkerOwner* job);
125
126 // Makes sure the current print_job_ has all its data before continuing, and
127 // disconnect from it.
128 void DisconnectFromCurrentPrintJob();
129
[email protected]82270452009-06-19 15:58:01130 // Notify that the printing is done.
131 void PrintingDone(bool success);
132
[email protected]da089562011-07-01 01:54:46133 // Terminates the print job. No-op if no print job has been created. If
initial.commit09911bf2008-07-26 23:55:29134 // |cancel| is true, cancel it instead of waiting for the job to finish. Will
135 // call ReleasePrintJob().
136 void TerminatePrintJob(bool cancel);
137
[email protected]da089562011-07-01 01:54:46138 // Releases print_job_. Correctly deregisters from notifications. No-op if
initial.commit09911bf2008-07-26 23:55:29139 // no print job has been created.
140 void ReleasePrintJob();
141
initial.commit09911bf2008-07-26 23:55:29142 // Runs an inner message loop. It will set inside_inner_message_loop_ to true
143 // while the blocking inner message loop is running. This is useful in cases
144 // where the RenderView is about to be destroyed while a printing job isn't
145 // finished.
146 bool RunInnerMessageLoop();
147
148 // In the case of Scripted Printing, where the renderer is controlling the
149 // control flow, print_job_ is initialized whenever possible. No-op is
150 // print_job_ is initialized.
151 bool OpportunisticallyCreatePrintJob(int cookie);
152
[email protected]3121c76b2011-07-22 02:34:32153 // Helper method for Print*Now().
154 bool PrintNowInternal(IPC::Message* message);
155
[email protected]34d38be2011-06-09 20:44:58156 // TabContentsWrapper we're associated with.
157 TabContentsWrapper* tab_;
158
[email protected]6c2381d2011-10-19 02:52:53159 content::NotificationRegistrar registrar_;
[email protected]0f08bf32009-05-21 20:33:17160
initial.commit09911bf2008-07-26 23:55:29161 // Manages the low-level talk to the printer.
162 scoped_refptr<PrintJob> print_job_;
163
[email protected]f0815752011-02-01 22:23:44164 // Number of pages to print in the print job.
165 int number_pages_;
166
[email protected]82270452009-06-19 15:58:01167 // Indication of success of the print job.
168 bool printing_succeeded_;
169
initial.commit09911bf2008-07-26 23:55:29170 // Running an inner message loop inside RenderAllMissingPagesNow(). This means
171 // we are _blocking_ until all the necessary pages have been rendered or the
172 // print settings are being loaded.
173 bool inside_inner_message_loop_;
174
[email protected]da4eefd2011-03-03 23:40:27175#if defined(OS_POSIX) && !defined(OS_MACOSX)
176 // Set to true when OnDidPrintPage() should be expecting the first page.
177 bool expecting_first_page_;
178#endif
179
[email protected]0b481bf2011-06-29 20:33:00180 // Weak pointer to an observer that is notified when the print dialog is
181 // shown.
182 PrintViewManagerObserver* observer_;
183
[email protected]da089562011-07-01 01:54:46184 // The document cookie of the current PrinterQuery.
185 int cookie_;
186
[email protected]a9c36832011-11-23 08:55:24187 // Current state of print preview for this view.
188 PrintPreviewState print_preview_state_;
189
190 // Keeps track of the pending callback during scripted print preview.
191 content::RenderProcessHost* scripted_print_preview_rph_;
192
[email protected]bfd04a62009-02-01 18:16:56193 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
initial.commit09911bf2008-07-26 23:55:29194};
195
196} // namespace printing
197
[email protected]bfd04a62009-02-01 18:16:56198#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_