Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / printing / print_view_manager_base.h
blob8b265742edcab03c0625c1f14a2c57d7fe63cf1d
1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_
6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/prefs/pref_member.h"
10 #include "base/strings/string16.h"
11 #include "components/printing/browser/print_manager.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "printing/printed_pages_source.h"
16 struct PrintHostMsg_DidPrintPage_Params;
18 namespace content {
19 class RenderViewHost;
22 namespace printing {
24 class JobEventDetails;
25 class MetafilePlayer;
26 class PrintJob;
27 class PrintJobWorkerOwner;
28 class PrintQueriesQueue;
30 // Base class for managing the print commands for a WebContents.
31 class PrintViewManagerBase : public content::NotificationObserver,
32 public PrintedPagesSource,
33 public PrintManager {
34 public:
35 ~PrintViewManagerBase() override;
37 #if defined(ENABLE_BASIC_PRINTING)
38 // Prints the current document immediately. Since the rendering is
39 // asynchronous, the actual printing will not be completed on the return of
40 // this function. Returns false if printing is impossible at the moment.
41 virtual bool PrintNow();
42 #endif // ENABLE_BASIC_PRINTING
44 // Whether to block scripted printing for our tab or not.
45 void UpdateScriptedPrintingBlocked();
47 // PrintedPagesSource implementation.
48 base::string16 RenderSourceName() override;
50 protected:
51 explicit PrintViewManagerBase(content::WebContents* web_contents);
53 // Helper method for Print*Now().
54 bool PrintNowInternal(IPC::Message* message);
56 // Terminates or cancels the print job if one was pending.
57 void RenderProcessGone(base::TerminationStatus status) override;
59 // content::WebContentsObserver implementation.
60 bool OnMessageReceived(const IPC::Message& message) override;
62 private:
63 // content::NotificationObserver implementation.
64 void Observe(int type,
65 const content::NotificationSource& source,
66 const content::NotificationDetails& details) override;
68 // content::WebContentsObserver implementation.
69 void DidStartLoading() override;
71 // Cancels the print job.
72 void NavigationStopped() override;
74 // IPC Message handlers.
75 void OnDidGetPrintedPagesCount(int cookie, int number_pages) override;
76 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
77 void OnPrintingFailed(int cookie) override;
78 void OnShowInvalidPrinterSettingsError();
80 // Processes a NOTIFY_PRINT_JOB_EVENT notification.
81 void OnNotifyPrintJobEvent(const JobEventDetails& event_details);
83 // Requests the RenderView to render all the missing pages for the print job.
84 // No-op if no print job is pending. Returns true if at least one page has
85 // been requested to the renderer.
86 bool RenderAllMissingPagesNow();
88 // Quits the current message loop if these conditions hold true: a document is
89 // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This
90 // function is called in DidPrintPage() or on ALL_PAGES_REQUESTED
91 // notification. The inner message loop is created was created by
92 // RenderAllMissingPagesNow().
93 void ShouldQuitFromInnerMessageLoop();
95 // Creates a new empty print job. It has no settings loaded. If there is
96 // currently a print job, safely disconnect from it. Returns false if it is
97 // impossible to safely disconnect from the current print job or it is
98 // impossible to create a new print job.
99 bool CreateNewPrintJob(PrintJobWorkerOwner* job);
101 // Makes sure the current print_job_ has all its data before continuing, and
102 // disconnect from it.
103 void DisconnectFromCurrentPrintJob();
105 // Notify that the printing is done.
106 void PrintingDone(bool success);
108 // Terminates the print job. No-op if no print job has been created. If
109 // |cancel| is true, cancel it instead of waiting for the job to finish. Will
110 // call ReleasePrintJob().
111 void TerminatePrintJob(bool cancel);
113 // Releases print_job_. Correctly deregisters from notifications. No-op if
114 // no print job has been created.
115 void ReleasePrintJob();
117 // Runs an inner message loop. It will set inside_inner_message_loop_ to true
118 // while the blocking inner message loop is running. This is useful in cases
119 // where the RenderView is about to be destroyed while a printing job isn't
120 // finished.
121 bool RunInnerMessageLoop();
123 // In the case of Scripted Printing, where the renderer is controlling the
124 // control flow, print_job_ is initialized whenever possible. No-op is
125 // print_job_ is initialized.
126 bool OpportunisticallyCreatePrintJob(int cookie);
128 // Release the PrinterQuery associated with our |cookie_|.
129 void ReleasePrinterQuery();
131 content::NotificationRegistrar registrar_;
133 // Manages the low-level talk to the printer.
134 scoped_refptr<PrintJob> print_job_;
136 // Indication of success of the print job.
137 bool printing_succeeded_;
139 // Running an inner message loop inside RenderAllMissingPagesNow(). This means
140 // we are _blocking_ until all the necessary pages have been rendered or the
141 // print settings are being loaded.
142 bool inside_inner_message_loop_;
144 #if !defined(OS_MACOSX)
145 // Set to true when OnDidPrintPage() should be expecting the first page.
146 bool expecting_first_page_;
147 #endif // OS_MACOSX
149 // Whether printing is enabled.
150 BooleanPrefMember printing_enabled_;
152 scoped_refptr<printing::PrintQueriesQueue> queue_;
154 DISALLOW_COPY_AND_ASSIGN(PrintViewManagerBase);
157 } // namespace printing
159 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_