Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/printing/print_view_manager_base.h

Issue 2426503002: Make printing work better with OOPIF. (Closed)
Patch Set: rebase, many cleanups have been committed Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_
6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ 6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_
7 7
8 #include <memory>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
10 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
11 #include "build/build_config.h" 13 #include "build/build_config.h"
12 #include "components/prefs/pref_member.h" 14 #include "components/prefs/pref_member.h"
13 #include "components/printing/browser/print_manager.h" 15 #include "components/printing/browser/print_manager.h"
14 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
16 #include "printing/features/features.h" 18 #include "printing/features/features.h"
17 #include "printing/printed_pages_source.h" 19 #include "printing/printed_pages_source.h"
18 20
19 struct PrintHostMsg_DidPrintPage_Params; 21 struct PrintHostMsg_DidPrintPage_Params;
20 22
23 namespace content {
24 class RenderFrameHost;
25 }
26
21 namespace printing { 27 namespace printing {
22 28
23 class JobEventDetails; 29 class JobEventDetails;
24 class MetafilePlayer; 30 class MetafilePlayer;
25 class PrintJob; 31 class PrintJob;
26 class PrintJobWorkerOwner; 32 class PrintJobWorkerOwner;
27 class PrintQueriesQueue; 33 class PrintQueriesQueue;
28 34
29 // Base class for managing the print commands for a WebContents. 35 // Base class for managing the print commands for a WebContents.
30 class PrintViewManagerBase : public content::NotificationObserver, 36 class PrintViewManagerBase : public content::NotificationObserver,
31 public PrintedPagesSource, 37 public PrintedPagesSource,
32 public PrintManager { 38 public PrintManager {
33 public: 39 public:
34 ~PrintViewManagerBase() override; 40 ~PrintViewManagerBase() override;
35 41
36 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 42 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
37 // Prints the current document immediately. Since the rendering is 43 // Prints the current document immediately. Since the rendering is
38 // asynchronous, the actual printing will not be completed on the return of 44 // asynchronous, the actual printing will not be completed on the return of
39 // this function. Returns false if printing is impossible at the moment. 45 // this function. Returns false if printing is impossible at the moment.
40 virtual bool PrintNow(); 46 virtual bool PrintNow(content::RenderFrameHost* rfh);
41 #endif // ENABLE_BASIC_PRINTING 47 #endif // ENABLE_BASIC_PRINTING
42 48
43 // Whether to block scripted printing for our tab or not. 49 // Whether printing is enabled or not.
44 void UpdateScriptedPrintingBlocked(); 50 void UpdatePrintingEnabled();
45 51
46 // PrintedPagesSource implementation. 52 // PrintedPagesSource implementation.
47 base::string16 RenderSourceName() override; 53 base::string16 RenderSourceName() override;
48 54
55 // Not needed? Combined with print_preview_rfh_?
56 content::RenderFrameHost* printing_rfh() { return printing_rfh_; }
57
49 protected: 58 protected:
50 explicit PrintViewManagerBase(content::WebContents* web_contents); 59 explicit PrintViewManagerBase(content::WebContents* web_contents);
51 60
52 // Helper method for Print*Now(). 61 // Helper method for Print*Now().
53 bool PrintNowInternal(IPC::Message* message); 62 bool PrintNowInternal(content::RenderFrameHost* rfh,
54 63 std::unique_ptr<IPC::Message> message);
55 // Terminates or cancels the print job if one was pending.
56 void RenderProcessGone(base::TerminationStatus status) override;
57 64
58 // content::WebContentsObserver implementation. 65 // content::WebContentsObserver implementation.
59 bool OnMessageReceived(const IPC::Message& message) override; 66 void RenderFrameDeleted(content::RenderFrameHost* rfh) override;
67 bool OnMessageReceived(const IPC::Message& message,
68 content::RenderFrameHost* rfh) override;
60 69
61 private: 70 private:
62 // content::NotificationObserver implementation. 71 // content::NotificationObserver implementation.
63 void Observe(int type, 72 void Observe(int type,
64 const content::NotificationSource& source, 73 const content::NotificationSource& source,
65 const content::NotificationDetails& details) override; 74 const content::NotificationDetails& details) override;
66 75
67 // content::WebContentsObserver implementation. 76 // content::WebContentsObserver implementation.
68 void DidStartLoading() override; 77 void DidStartLoading() override;
69 78
(...skipping 24 matching lines...) Expand all
94 // Creates a new empty print job. It has no settings loaded. If there is 103 // Creates a new empty print job. It has no settings loaded. If there is
95 // currently a print job, safely disconnect from it. Returns false if it is 104 // currently a print job, safely disconnect from it. Returns false if it is
96 // impossible to safely disconnect from the current print job or it is 105 // impossible to safely disconnect from the current print job or it is
97 // impossible to create a new print job. 106 // impossible to create a new print job.
98 bool CreateNewPrintJob(PrintJobWorkerOwner* job); 107 bool CreateNewPrintJob(PrintJobWorkerOwner* job);
99 108
100 // Makes sure the current print_job_ has all its data before continuing, and 109 // Makes sure the current print_job_ has all its data before continuing, and
101 // disconnect from it. 110 // disconnect from it.
102 void DisconnectFromCurrentPrintJob(); 111 void DisconnectFromCurrentPrintJob();
103 112
104 // Notify that the printing is done.
105 void PrintingDone(bool success);
106
107 // Terminates the print job. No-op if no print job has been created. If 113 // Terminates the print job. No-op if no print job has been created. If
108 // |cancel| is true, cancel it instead of waiting for the job to finish. Will 114 // |cancel| is true, cancel it instead of waiting for the job to finish. Will
109 // call ReleasePrintJob(). 115 // call ReleasePrintJob().
110 void TerminatePrintJob(bool cancel); 116 void TerminatePrintJob(bool cancel);
111 117
112 // Releases print_job_. Correctly deregisters from notifications. No-op if 118 // Releases print_job_. Correctly deregisters from notifications. No-op if
113 // no print job has been created. 119 // no print job has been created.
114 void ReleasePrintJob(); 120 void ReleasePrintJob();
115 121
116 // Runs an inner message loop. It will set inside_inner_message_loop_ to true 122 // Runs an inner message loop. It will set inside_inner_message_loop_ to true
117 // while the blocking inner message loop is running. This is useful in cases 123 // while the blocking inner message loop is running. This is useful in cases
118 // where the RenderView is about to be destroyed while a printing job isn't 124 // where the RenderView is about to be destroyed while a printing job isn't
119 // finished. 125 // finished.
120 bool RunInnerMessageLoop(); 126 bool RunInnerMessageLoop();
121 127
122 // In the case of Scripted Printing, where the renderer is controlling the 128 // In the case of Scripted Printing, where the renderer is controlling the
123 // control flow, print_job_ is initialized whenever possible. No-op is 129 // control flow, print_job_ is initialized whenever possible. No-op is
124 // print_job_ is initialized. 130 // print_job_ is initialized.
125 bool OpportunisticallyCreatePrintJob(int cookie); 131 bool OpportunisticallyCreatePrintJob(int cookie);
126 132
127 // Release the PrinterQuery associated with our |cookie_|. 133 // Release the PrinterQuery associated with our |cookie_|.
128 void ReleasePrinterQuery(); 134 void ReleasePrinterQuery();
129 135
136 // Helper method for UpdatePrintingEnabled().
137 void SendPrintingEnabled(bool enabled, content::RenderFrameHost* rfh);
138
130 content::NotificationRegistrar registrar_; 139 content::NotificationRegistrar registrar_;
131 140
141 content::RenderFrameHost* printing_rfh_;
142
132 // Manages the low-level talk to the printer. 143 // Manages the low-level talk to the printer.
133 scoped_refptr<PrintJob> print_job_; 144 scoped_refptr<PrintJob> print_job_;
134 145
135 // Indication of success of the print job. 146 // Indication of success of the print job.
136 bool printing_succeeded_; 147 bool printing_succeeded_;
137 148
138 // Running an inner message loop inside RenderAllMissingPagesNow(). This means 149 // Running an inner message loop inside RenderAllMissingPagesNow(). This means
139 // we are _blocking_ until all the necessary pages have been rendered or the 150 // we are _blocking_ until all the necessary pages have been rendered or the
140 // print settings are being loaded. 151 // print settings are being loaded.
141 bool inside_inner_message_loop_; 152 bool inside_inner_message_loop_;
142 153
143 #if !defined(OS_MACOSX) 154 #if !defined(OS_MACOSX)
144 // Set to true when OnDidPrintPage() should be expecting the first page. 155 // Set to true when OnDidPrintPage() should be expecting the first page.
145 bool expecting_first_page_; 156 bool expecting_first_page_;
146 #endif 157 #endif
147 158
148 // Whether printing is enabled. 159 // Whether printing is enabled.
149 BooleanPrefMember printing_enabled_; 160 BooleanPrefMember printing_enabled_;
150 161
151 scoped_refptr<printing::PrintQueriesQueue> queue_; 162 scoped_refptr<printing::PrintQueriesQueue> queue_;
152 163
153 DISALLOW_COPY_AND_ASSIGN(PrintViewManagerBase); 164 DISALLOW_COPY_AND_ASSIGN(PrintViewManagerBase);
154 }; 165 };
155 166
156 } // namespace printing 167 } // namespace printing
157 168
158 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_ 169 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698