blob: 2562885b89b531369d7e1c3ef19c078ecd88a478 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.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_
initial.commit09911bf2008-07-26 23:55:297
[email protected]674741932009-02-04 23:44:468#include "base/ref_counted.h"
initial.commit09911bf2008-07-26 23:55:299#include "chrome/browser/printing/printed_pages_source.h"
[email protected]0f08bf32009-05-21 20:33:1710#include "chrome/common/notification_registrar.h"
initial.commit09911bf2008-07-26 23:55:2911
12class RenderViewHost;
[email protected]57c6a652009-05-04 07:58:3413class TabContents;
[email protected]674741932009-02-04 23:44:4614struct ViewHostMsg_DidPrintPage_Params;
initial.commit09911bf2008-07-26 23:55:2915
16namespace printing {
17
18class JobEventDetails;
19class PrintJob;
20class PrintJobWorkerOwner;
21
[email protected]57c6a652009-05-04 07:58:3422// Manages the print commands in relation to a TabContents. TabContents
initial.commit09911bf2008-07-26 23:55:2923// delegates a few printing related commands to this instance.
24class PrintViewManager : public NotificationObserver,
25 public PrintedPagesSource {
26 public:
[email protected]57c6a652009-05-04 07:58:3427 PrintViewManager(TabContents& owner);
[email protected]2d4537d52008-12-17 02:25:4428 virtual ~PrintViewManager();
initial.commit09911bf2008-07-26 23:55:2929
initial.commit09911bf2008-07-26 23:55:2930 // Cancels the print job.
31 void Stop();
32
initial.commit09911bf2008-07-26 23:55:2933 // 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]6de74452009-02-25 18:04:5935 bool OnRenderViewGone(RenderViewHost* render_view_host);
initial.commit09911bf2008-07-26 23:55:2936
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.commit09911bf2008-07-26 23:55:2946 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.commit09911bf2008-07-26 23:55:2958 // 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]0f08bf32009-05-21 20:33:17106 NotificationRegistrar registrar_;
107
initial.commit09911bf2008-07-26 23:55:29108 // 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.commit09911bf2008-07-26 23:55:29121 // 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]57c6a652009-05-04 07:58:34124 TabContents& owner_;
initial.commit09911bf2008-07-26 23:55:29125
[email protected]bfd04a62009-02-01 18:16:56126 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
initial.commit09911bf2008-07-26 23:55:29127};
128
129} // namespace printing
130
[email protected]bfd04a62009-02-01 18:16:56131#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_