blob: 1702461b9a1473810fd8eae3ac426bf230935f02 [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
16class RenderViewHost;
[email protected]34d38be2011-06-09 20:44:5817class TabContentsWrapper;
[email protected]1375e3ab2011-03-24 17:07:2218struct PrintHostMsg_DidPrintPage_Params;
initial.commit09911bf2008-07-26 23:55:2919
20namespace printing {
21
22class JobEventDetails;
23class PrintJob;
24class PrintJobWorkerOwner;
[email protected]0b481bf2011-06-29 20:33:0025class PrintViewManagerObserver;
initial.commit09911bf2008-07-26 23:55:2926
[email protected]57c6a652009-05-04 07:58:3427// Manages the print commands in relation to a TabContents. TabContents
initial.commit09911bf2008-07-26 23:55:2928// delegates a few printing related commands to this instance.
[email protected]6c2381d2011-10-19 02:52:5329class PrintViewManager : public content::NotificationObserver,
[email protected]8d3347f2009-07-09 22:00:2130 public PrintedPagesSource,
[email protected]585b30362011-01-28 02:30:1731 public TabContentsObserver {
initial.commit09911bf2008-07-26 23:55:2932 public:
[email protected]34d38be2011-06-09 20:44:5833 explicit PrintViewManager(TabContentsWrapper* tab);
[email protected]2d4537d52008-12-17 02:25:4434 virtual ~PrintViewManager();
initial.commit09911bf2008-07-26 23:55:2935
[email protected]c2e71d2e2011-11-15 09:12:0336 // Override the title for this PrintViewManager's PrintJobs using the title
37 // in |tab_contents|.
38 void OverrideTitle(TabContents* tab_contents);
39
[email protected]49fe2262011-04-15 20:56:1540 // Prints the current document immediately. Since the rendering is
41 // asynchronous, the actual printing will not be completed on the return of
42 // this function. Returns false if printing is impossible at the moment.
43 bool PrintNow();
44
[email protected]3121c76b2011-07-22 02:34:3245 // Same as PrintNow(), but for the case where a user prints with the system
46 // dialog from print preview.
47 bool PrintForSystemDialogNow();
48
[email protected]0996e9b2011-08-26 17:59:0149 // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
50 // show the native system dialog. This can happen from both initiator tab and
51 // preview tab.
52 bool AdvancedPrintNow();
53
[email protected]8980e0d2011-05-27 19:16:2354 // Initiate print preview of the current document by first notifying the
55 // renderer. Since this happens asynchronous, the print preview tab creation
56 // will not be completed on the return of this function. Returns false if
57 // print preview is impossible at the moment.
58 bool PrintPreviewNow();
59
[email protected]428f02392011-06-11 01:30:5560 // Handles cancelled preview printing request.
61 void PreviewPrintingRequestCancelled();
62
[email protected]0b481bf2011-06-29 20:33:0063 // Sets |observer| as the current PrintViewManagerObserver. Pass in NULL to
64 // remove the current observer. |observer| may always be NULL, but |observer_|
65 // must be NULL if |observer| is non-NULL.
66 void set_observer(PrintViewManagerObserver* observer);
67
[email protected]c2e71d2e2011-11-15 09:12:0368 // Reset |is_title_overridden_| to false.
69 void ResetTitleOverride();
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]b3ee0b522011-05-06 04:06:4089 // IPC Message handlers.
[email protected]34f128d2011-01-25 19:07:4490 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
[email protected]da089562011-07-01 01:54:4691 void OnDidGetDocumentCookie(int cookie);
[email protected]0b481bf2011-06-29 20:33:0092 void OnDidShowPrintDialog();
[email protected]1375e3ab2011-03-24 17:07:2293 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
[email protected]b3ee0b522011-05-06 04:06:4094 void OnPrintingFailed(int cookie);
[email protected]34f128d2011-01-25 19:07:4495
initial.commit09911bf2008-07-26 23:55:2996 // Processes a NOTIFY_PRINT_JOB_EVENT notification.
97 void OnNotifyPrintJobEvent(const JobEventDetails& event_details);
98
initial.commit09911bf2008-07-26 23:55:2999 // Requests the RenderView to render all the missing pages for the print job.
[email protected]184a6c8f2011-10-04 20:07:30100 // No-op if no print job is pending. Returns true if at least one page has
101 // been requested to the renderer.
initial.commit09911bf2008-07-26 23:55:29102 bool RenderAllMissingPagesNow();
103
104 // Quits the current message loop if these conditions hold true: a document is
105 // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This
106 // function is called in DidPrintPage() or on ALL_PAGES_REQUESTED
107 // notification. The inner message loop is created was created by
108 // RenderAllMissingPagesNow().
109 void ShouldQuitFromInnerMessageLoop();
110
111 // Creates a new empty print job. It has no settings loaded. If there is
112 // currently a print job, safely disconnect from it. Returns false if it is
113 // impossible to safely disconnect from the current print job or it is
114 // impossible to create a new print job.
115 bool CreateNewPrintJob(PrintJobWorkerOwner* job);
116
117 // Makes sure the current print_job_ has all its data before continuing, and
118 // disconnect from it.
119 void DisconnectFromCurrentPrintJob();
120
[email protected]82270452009-06-19 15:58:01121 // Notify that the printing is done.
122 void PrintingDone(bool success);
123
[email protected]da089562011-07-01 01:54:46124 // Terminates the print job. No-op if no print job has been created. If
initial.commit09911bf2008-07-26 23:55:29125 // |cancel| is true, cancel it instead of waiting for the job to finish. Will
126 // call ReleasePrintJob().
127 void TerminatePrintJob(bool cancel);
128
[email protected]da089562011-07-01 01:54:46129 // Releases print_job_. Correctly deregisters from notifications. No-op if
initial.commit09911bf2008-07-26 23:55:29130 // no print job has been created.
131 void ReleasePrintJob();
132
initial.commit09911bf2008-07-26 23:55:29133 // Runs an inner message loop. It will set inside_inner_message_loop_ to true
134 // while the blocking inner message loop is running. This is useful in cases
135 // where the RenderView is about to be destroyed while a printing job isn't
136 // finished.
137 bool RunInnerMessageLoop();
138
139 // In the case of Scripted Printing, where the renderer is controlling the
140 // control flow, print_job_ is initialized whenever possible. No-op is
141 // print_job_ is initialized.
142 bool OpportunisticallyCreatePrintJob(int cookie);
143
[email protected]3121c76b2011-07-22 02:34:32144 // Helper method for Print*Now().
145 bool PrintNowInternal(IPC::Message* message);
146
[email protected]34d38be2011-06-09 20:44:58147 // TabContentsWrapper we're associated with.
148 TabContentsWrapper* tab_;
149
[email protected]6c2381d2011-10-19 02:52:53150 content::NotificationRegistrar registrar_;
[email protected]0f08bf32009-05-21 20:33:17151
initial.commit09911bf2008-07-26 23:55:29152 // Manages the low-level talk to the printer.
153 scoped_refptr<PrintJob> print_job_;
154
[email protected]f0815752011-02-01 22:23:44155 // Number of pages to print in the print job.
156 int number_pages_;
157
[email protected]82270452009-06-19 15:58:01158 // Indication of success of the print job.
159 bool printing_succeeded_;
160
initial.commit09911bf2008-07-26 23:55:29161 // Running an inner message loop inside RenderAllMissingPagesNow(). This means
162 // we are _blocking_ until all the necessary pages have been rendered or the
163 // print settings are being loaded.
164 bool inside_inner_message_loop_;
165
[email protected]da4eefd2011-03-03 23:40:27166#if defined(OS_POSIX) && !defined(OS_MACOSX)
167 // Set to true when OnDidPrintPage() should be expecting the first page.
168 bool expecting_first_page_;
169#endif
170
[email protected]c2e71d2e2011-11-15 09:12:03171 // Title override.
172 bool is_title_overridden_;
173 string16 overridden_title_;
174
[email protected]0b481bf2011-06-29 20:33:00175 // Weak pointer to an observer that is notified when the print dialog is
176 // shown.
177 PrintViewManagerObserver* observer_;
178
[email protected]da089562011-07-01 01:54:46179 // The document cookie of the current PrinterQuery.
180 int cookie_;
181
[email protected]bfd04a62009-02-01 18:16:56182 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
initial.commit09911bf2008-07-26 23:55:29183};
184
185} // namespace printing
186
[email protected]bfd04a62009-02-01 18:16:56187#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_