OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "content/browser/tab_contents/tab_contents_observer.h" | 11 #include "content/browser/tab_contents/tab_contents_observer.h" |
12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
14 #include "printing/printed_pages_source.h" | 14 #include "printing/printed_pages_source.h" |
15 | 15 |
16 class RenderViewHost; | 16 class RenderProcessHost; |
17 class TabContentsWrapper; | 17 class TabContentsWrapper; |
18 struct PrintHostMsg_DidPrintPage_Params; | 18 struct PrintHostMsg_DidPrintPage_Params; |
19 | 19 |
20 namespace printing { | 20 namespace printing { |
21 | 21 |
22 class JobEventDetails; | 22 class JobEventDetails; |
23 class PrintJob; | 23 class PrintJob; |
24 class PrintJobWorkerOwner; | 24 class PrintJobWorkerOwner; |
25 class PrintViewManagerObserver; | 25 class PrintViewManagerObserver; |
26 | 26 |
(...skipping 19 matching lines...) Expand all Loading... |
46 // show the native system dialog. This can happen from both initiator tab and | 46 // show the native system dialog. This can happen from both initiator tab and |
47 // preview tab. | 47 // preview tab. |
48 bool AdvancedPrintNow(); | 48 bool AdvancedPrintNow(); |
49 | 49 |
50 // Initiate print preview of the current document by first notifying the | 50 // Initiate print preview of the current document by first notifying the |
51 // renderer. Since this happens asynchronous, the print preview tab creation | 51 // renderer. Since this happens asynchronous, the print preview tab creation |
52 // will not be completed on the return of this function. Returns false if | 52 // will not be completed on the return of this function. Returns false if |
53 // print preview is impossible at the moment. | 53 // print preview is impossible at the moment. |
54 bool PrintPreviewNow(); | 54 bool PrintPreviewNow(); |
55 | 55 |
| 56 // Notify PrintViewManager that print preview has finished. Unfreeze the |
| 57 // renderer in the case of scripted print preview. |
| 58 void PrintPreviewDone(); |
| 59 |
56 // Handles cancelled preview printing request. | 60 // Handles cancelled preview printing request. |
57 void PreviewPrintingRequestCancelled(); | 61 void PreviewPrintingRequestCancelled(); |
58 | 62 |
59 // Sets |observer| as the current PrintViewManagerObserver. Pass in NULL to | 63 // Sets |observer| as the current PrintViewManagerObserver. Pass in NULL to |
60 // remove the current observer. |observer| may always be NULL, but |observer_| | 64 // remove the current observer. |observer| may always be NULL, but |observer_| |
61 // must be NULL if |observer| is non-NULL. | 65 // must be NULL if |observer| is non-NULL. |
62 void set_observer(PrintViewManagerObserver* observer); | 66 void set_observer(PrintViewManagerObserver* observer); |
63 | 67 |
64 // PrintedPagesSource implementation. | 68 // PrintedPagesSource implementation. |
65 virtual string16 RenderSourceName() OVERRIDE; | 69 virtual string16 RenderSourceName() OVERRIDE; |
66 | 70 |
67 // content::NotificationObserver implementation. | 71 // content::NotificationObserver implementation. |
68 virtual void Observe(int type, | 72 virtual void Observe(int type, |
69 const content::NotificationSource& source, | 73 const content::NotificationSource& source, |
70 const content::NotificationDetails& details) OVERRIDE; | 74 const content::NotificationDetails& details) OVERRIDE; |
71 | 75 |
72 // TabContentsObserver implementation. | 76 // TabContentsObserver implementation. |
73 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 77 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
74 | 78 |
75 // Terminates or cancels the print job if one was pending. | 79 // Terminates or cancels the print job if one was pending. |
76 virtual void RenderViewGone(); | 80 virtual void RenderViewGone(); |
77 | 81 |
78 // Cancels the print job. | 82 // Cancels the print job. |
79 virtual void StopNavigation(); | 83 virtual void StopNavigation(); |
80 | 84 |
81 private: | 85 private: |
| 86 enum PrintPreviewState { |
| 87 NOT_PREVIEWING, |
| 88 USER_INITIATED_PREVIEW, |
| 89 SCRIPTED_PREVIEW, |
| 90 }; |
| 91 |
82 // IPC Message handlers. | 92 // IPC Message handlers. |
83 void OnDidGetPrintedPagesCount(int cookie, int number_pages); | 93 void OnDidGetPrintedPagesCount(int cookie, int number_pages); |
84 void OnDidGetDocumentCookie(int cookie); | 94 void OnDidGetDocumentCookie(int cookie); |
85 void OnDidShowPrintDialog(); | 95 void OnDidShowPrintDialog(); |
86 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); | 96 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); |
87 void OnPrintingFailed(int cookie); | 97 void OnPrintingFailed(int cookie); |
88 | 98 |
| 99 void OnScriptedPrintPreview(IPC::Message* reply_msg); |
| 100 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg); |
| 101 |
89 // Processes a NOTIFY_PRINT_JOB_EVENT notification. | 102 // Processes a NOTIFY_PRINT_JOB_EVENT notification. |
90 void OnNotifyPrintJobEvent(const JobEventDetails& event_details); | 103 void OnNotifyPrintJobEvent(const JobEventDetails& event_details); |
91 | 104 |
92 // Requests the RenderView to render all the missing pages for the print job. | 105 // Requests the RenderView to render all the missing pages for the print job. |
93 // No-op if no print job is pending. Returns true if at least one page has | 106 // No-op if no print job is pending. Returns true if at least one page has |
94 // been requested to the renderer. | 107 // been requested to the renderer. |
95 bool RenderAllMissingPagesNow(); | 108 bool RenderAllMissingPagesNow(); |
96 | 109 |
97 // Quits the current message loop if these conditions hold true: a document is | 110 // Quits the current message loop if these conditions hold true: a document is |
98 // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This | 111 // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 bool expecting_first_page_; | 174 bool expecting_first_page_; |
162 #endif | 175 #endif |
163 | 176 |
164 // Weak pointer to an observer that is notified when the print dialog is | 177 // Weak pointer to an observer that is notified when the print dialog is |
165 // shown. | 178 // shown. |
166 PrintViewManagerObserver* observer_; | 179 PrintViewManagerObserver* observer_; |
167 | 180 |
168 // The document cookie of the current PrinterQuery. | 181 // The document cookie of the current PrinterQuery. |
169 int cookie_; | 182 int cookie_; |
170 | 183 |
| 184 // Current state of print preview for this view. |
| 185 PrintPreviewState print_preview_state_; |
| 186 |
| 187 // Keeps track of the pending callback during scripted print preview. |
| 188 RenderProcessHost* scripted_print_preview_rph_; |
| 189 |
171 DISALLOW_COPY_AND_ASSIGN(PrintViewManager); | 190 DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
172 }; | 191 }; |
173 | 192 |
174 } // namespace printing | 193 } // namespace printing |
175 | 194 |
176 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ | 195 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
OLD | NEW |