blob: fa766c91eda96d473826f75d0103ff3babf91cc1 [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]ebbbb9f2011-03-09 13:16:1412#include "content/common/notification_observer.h"
13#include "content/common/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]57c6a652009-05-04 07:58:3417class TabContents;
[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;
25
[email protected]57c6a652009-05-04 07:58:3426// Manages the print commands in relation to a TabContents. TabContents
initial.commit09911bf2008-07-26 23:55:2927// delegates a few printing related commands to this instance.
28class PrintViewManager : public NotificationObserver,
[email protected]8d3347f2009-07-09 22:00:2129 public PrintedPagesSource,
[email protected]585b30362011-01-28 02:30:1730 public TabContentsObserver {
initial.commit09911bf2008-07-26 23:55:2931 public:
[email protected]b5a1d11c2011-02-17 03:09:4232 explicit PrintViewManager(TabContents* tab_contents);
[email protected]2d4537d52008-12-17 02:25:4433 virtual ~PrintViewManager();
initial.commit09911bf2008-07-26 23:55:2934
[email protected]101f66b62011-04-07 19:46:0635 // Override the title for this PrintViewManager's PrintJobs using the title
36 // in |tab_contents|.
37 void OverrideTitle(TabContents* tab_contents);
38
[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
initial.commit09911bf2008-07-26 23:55:2944 // PrintedPagesSource implementation.
[email protected]d9d42992010-09-13 19:39:1945 virtual string16 RenderSourceName();
initial.commit09911bf2008-07-26 23:55:2946 virtual GURL RenderSourceUrl();
47
48 // NotificationObserver implementation.
49 virtual void Observe(NotificationType type,
50 const NotificationSource& source,
51 const NotificationDetails& details);
52
[email protected]585b30362011-01-28 02:30:1753 // TabContentsObserver implementation.
[email protected]34f128d2011-01-25 19:07:4454 virtual bool OnMessageReceived(const IPC::Message& message);
55
[email protected]2e3f4572011-03-25 19:24:4756 // Terminates or cancels the print job if one was pending.
[email protected]dfcb0e52011-03-25 19:51:0057 virtual void RenderViewGone();
[email protected]2e3f4572011-03-25 19:24:4758
59 // Cancels the print job.
60 virtual void StopNavigation();
61
initial.commit09911bf2008-07-26 23:55:2962 private:
[email protected]34f128d2011-01-25 19:07:4463 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
[email protected]1375e3ab2011-03-24 17:07:2264 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
[email protected]34f128d2011-01-25 19:07:4465
initial.commit09911bf2008-07-26 23:55:2966 // Processes a NOTIFY_PRINT_JOB_EVENT notification.
67 void OnNotifyPrintJobEvent(const JobEventDetails& event_details);
68
initial.commit09911bf2008-07-26 23:55:2969 // 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]82270452009-06-19 15:58:0191 // Notify that the printing is done.
92 void PrintingDone(bool success);
93
initial.commit09911bf2008-07-26 23:55:2994 // 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.commit09911bf2008-07-26 23:55:29103 // 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]0f08bf32009-05-21 20:33:17114 NotificationRegistrar registrar_;
115
initial.commit09911bf2008-07-26 23:55:29116 // Manages the low-level talk to the printer.
117 scoped_refptr<PrintJob> print_job_;
118
[email protected]f0815752011-02-01 22:23:44119 // Number of pages to print in the print job.
120 int number_pages_;
121
initial.commit09911bf2008-07-26 23:55:29122 // 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]82270452009-06-19 15:58:01127 // Indication of success of the print job.
128 bool printing_succeeded_;
129
initial.commit09911bf2008-07-26 23:55:29130 // 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]da4eefd2011-03-03 23:40:27135#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]101f66b62011-04-07 19:46:06140 // Title override.
141 bool is_title_overridden_;
142 string16 overridden_title_;
143
[email protected]bfd04a62009-02-01 18:16:56144 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
initial.commit09911bf2008-07-26 23:55:29145};
146
147} // namespace printing
148
[email protected]bfd04a62009-02-01 18:16:56149#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_