blob: afd551985794ecb8bf2efd9dadaa3ecaa77ed21e [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
initial.commit09911bf2008-07-26 23:55:2935 // PrintedPagesSource implementation.
[email protected]d9d42992010-09-13 19:39:1936 virtual string16 RenderSourceName();
initial.commit09911bf2008-07-26 23:55:2937 virtual GURL RenderSourceUrl();
38
39 // NotificationObserver implementation.
40 virtual void Observe(NotificationType type,
41 const NotificationSource& source,
42 const NotificationDetails& details);
43
[email protected]585b30362011-01-28 02:30:1744 // TabContentsObserver implementation.
[email protected]34f128d2011-01-25 19:07:4445 virtual bool OnMessageReceived(const IPC::Message& message);
46
[email protected]2e3f4572011-03-25 19:24:4747 // Terminates or cancels the print job if one was pending.
[email protected]dfcb0e52011-03-25 19:51:0048 virtual void RenderViewGone();
[email protected]2e3f4572011-03-25 19:24:4749
50 // Cancels the print job.
51 virtual void StopNavigation();
52
initial.commit09911bf2008-07-26 23:55:2953 private:
[email protected]34f128d2011-01-25 19:07:4454 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
[email protected]1375e3ab2011-03-24 17:07:2255 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
[email protected]34f128d2011-01-25 19:07:4456
initial.commit09911bf2008-07-26 23:55:2957 // Processes a NOTIFY_PRINT_JOB_EVENT notification.
58 void OnNotifyPrintJobEvent(const JobEventDetails& event_details);
59
initial.commit09911bf2008-07-26 23:55:2960 // Requests the RenderView to render all the missing pages for the print job.
61 // Noop if no print job is pending. Returns true if at least one page has been
62 // requested to the renderer.
63 bool RenderAllMissingPagesNow();
64
65 // Quits the current message loop if these conditions hold true: a document is
66 // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This
67 // function is called in DidPrintPage() or on ALL_PAGES_REQUESTED
68 // notification. The inner message loop is created was created by
69 // RenderAllMissingPagesNow().
70 void ShouldQuitFromInnerMessageLoop();
71
72 // Creates a new empty print job. It has no settings loaded. If there is
73 // currently a print job, safely disconnect from it. Returns false if it is
74 // impossible to safely disconnect from the current print job or it is
75 // impossible to create a new print job.
76 bool CreateNewPrintJob(PrintJobWorkerOwner* job);
77
78 // Makes sure the current print_job_ has all its data before continuing, and
79 // disconnect from it.
80 void DisconnectFromCurrentPrintJob();
81
[email protected]82270452009-06-19 15:58:0182 // Notify that the printing is done.
83 void PrintingDone(bool success);
84
initial.commit09911bf2008-07-26 23:55:2985 // Terminates the print job. Noop if no print job has been created. If
86 // |cancel| is true, cancel it instead of waiting for the job to finish. Will
87 // call ReleasePrintJob().
88 void TerminatePrintJob(bool cancel);
89
90 // Releases print_job_. Correctly deregisters from notifications. Noop if
91 // no print job has been created.
92 void ReleasePrintJob();
93
initial.commit09911bf2008-07-26 23:55:2994 // Runs an inner message loop. It will set inside_inner_message_loop_ to true
95 // while the blocking inner message loop is running. This is useful in cases
96 // where the RenderView is about to be destroyed while a printing job isn't
97 // finished.
98 bool RunInnerMessageLoop();
99
100 // In the case of Scripted Printing, where the renderer is controlling the
101 // control flow, print_job_ is initialized whenever possible. No-op is
102 // print_job_ is initialized.
103 bool OpportunisticallyCreatePrintJob(int cookie);
104
[email protected]0f08bf32009-05-21 20:33:17105 NotificationRegistrar registrar_;
106
initial.commit09911bf2008-07-26 23:55:29107 // Manages the low-level talk to the printer.
108 scoped_refptr<PrintJob> print_job_;
109
[email protected]f0815752011-02-01 22:23:44110 // Number of pages to print in the print job.
111 int number_pages_;
112
initial.commit09911bf2008-07-26 23:55:29113 // Waiting for print_job_ initialization to be completed to start printing.
114 // Specifically the DEFAULT_INIT_DONE notification. Set when PrintNow() is
115 // called.
116 bool waiting_to_print_;
117
[email protected]82270452009-06-19 15:58:01118 // Indication of success of the print job.
119 bool printing_succeeded_;
120
initial.commit09911bf2008-07-26 23:55:29121 // Running an inner message loop inside RenderAllMissingPagesNow(). This means
122 // we are _blocking_ until all the necessary pages have been rendered or the
123 // print settings are being loaded.
124 bool inside_inner_message_loop_;
125
[email protected]da4eefd2011-03-03 23:40:27126#if defined(OS_POSIX) && !defined(OS_MACOSX)
127 // Set to true when OnDidPrintPage() should be expecting the first page.
128 bool expecting_first_page_;
129#endif
130
[email protected]bfd04a62009-02-01 18:16:56131 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
initial.commit09911bf2008-07-26 23:55:29132};
133
134} // namespace printing
135
[email protected]bfd04a62009-02-01 18:16:56136#endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_