OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // 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 | 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 | 7 |
8 #include "chrome/browser/printing/printed_pages_source.h" | 8 #include "chrome/browser/printing/printed_pages_source.h" |
9 #include "chrome/common/notification_observer.h" | 9 #include "chrome/common/notification_observer.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 PrintViewManager(WebContents& owner); | 26 PrintViewManager(WebContents& owner); |
27 virtual ~PrintViewManager(); | 27 virtual ~PrintViewManager(); |
28 | 28 |
29 // Destroys the "Print..." dialog, makes sure the pages are finished rendering | 29 // Destroys the "Print..." dialog, makes sure the pages are finished rendering |
30 // and release the print job. | 30 // and release the print job. |
31 void Destroy(); | 31 void Destroy(); |
32 | 32 |
33 // Cancels the print job. | 33 // Cancels the print job. |
34 void Stop(); | 34 void Stop(); |
35 | 35 |
36 // Shows the "Print..." dialog if none is shown and if no rendering is | |
37 // pending. This is done asynchronously. | |
38 void ShowPrintDialog(); | |
39 | |
40 // Initiates a print job immediately. This is done asynchronously. Returns | |
41 // false if printing is impossible at the moment. | |
42 bool PrintNow(); | |
43 | |
44 // Terminates or cancels the print job if one was pending, depending on the | 36 // Terminates or cancels the print job if one was pending, depending on the |
45 // current state. Returns false if the renderer was not valuable. | 37 // current state. Returns false if the renderer was not valuable. |
46 bool OnRendererGone(RenderViewHost* render_view_host); | 38 bool OnRendererGone(RenderViewHost* render_view_host); |
47 | 39 |
48 // Received a notification from the renderer that the number of printed page | 40 // Received a notification from the renderer that the number of printed page |
49 // has just been calculated.. | 41 // has just been calculated.. |
50 void DidGetPrintedPagesCount(int cookie, int number_pages); | 42 void DidGetPrintedPagesCount(int cookie, int number_pages); |
51 | 43 |
52 // Received a notification from the renderer that a printed page page is | 44 // Received a notification from the renderer that a printed page page is |
53 // finished renderering. | 45 // finished renderering. |
54 void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); | 46 void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); |
55 | 47 |
56 // PrintedPagesSource implementation. | 48 // PrintedPagesSource implementation. |
57 virtual void RenderOnePrintedPage(PrintedDocument* document, int page_number); | |
58 virtual std::wstring RenderSourceName(); | 49 virtual std::wstring RenderSourceName(); |
59 virtual GURL RenderSourceUrl(); | 50 virtual GURL RenderSourceUrl(); |
60 | 51 |
61 // NotificationObserver implementation. | 52 // NotificationObserver implementation. |
62 virtual void Observe(NotificationType type, | 53 virtual void Observe(NotificationType type, |
63 const NotificationSource& source, | 54 const NotificationSource& source, |
64 const NotificationDetails& details); | 55 const NotificationDetails& details); |
65 | 56 |
66 private: | 57 private: |
67 // Processes a NOTIFY_PRINT_JOB_EVENT notification. | 58 // Processes a NOTIFY_PRINT_JOB_EVENT notification. |
68 void OnNotifyPrintJobEvent(const JobEventDetails& event_details); | 59 void OnNotifyPrintJobEvent(const JobEventDetails& event_details); |
69 | 60 |
70 // Processes a xxx_INIT_xxx type of NOTIFY_PRINT_JOB_EVENT notification. | |
71 void OnNotifyPrintJobInitEvent(const JobEventDetails& event_details); | |
72 | |
73 // Requests the RenderView to render all the missing pages for the print job. | 61 // Requests the RenderView to render all the missing pages for the print job. |
74 // Noop if no print job is pending. Returns true if at least one page has been | 62 // Noop if no print job is pending. Returns true if at least one page has been |
75 // requested to the renderer. | 63 // requested to the renderer. |
76 bool RenderAllMissingPagesNow(); | 64 bool RenderAllMissingPagesNow(); |
77 | 65 |
78 // Quits the current message loop if these conditions hold true: a document is | 66 // Quits the current message loop if these conditions hold true: a document is |
79 // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This | 67 // loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This |
80 // function is called in DidPrintPage() or on ALL_PAGES_REQUESTED | 68 // function is called in DidPrintPage() or on ALL_PAGES_REQUESTED |
81 // notification. The inner message loop is created was created by | 69 // notification. The inner message loop is created was created by |
82 // RenderAllMissingPagesNow(). | 70 // RenderAllMissingPagesNow(). |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // Waiting for print_job_ initialization to be completed to start printing. | 115 // Waiting for print_job_ initialization to be completed to start printing. |
128 // Specifically the DEFAULT_INIT_DONE notification. Set when PrintNow() is | 116 // Specifically the DEFAULT_INIT_DONE notification. Set when PrintNow() is |
129 // called. | 117 // called. |
130 bool waiting_to_print_; | 118 bool waiting_to_print_; |
131 | 119 |
132 // Running an inner message loop inside RenderAllMissingPagesNow(). This means | 120 // Running an inner message loop inside RenderAllMissingPagesNow(). This means |
133 // we are _blocking_ until all the necessary pages have been rendered or the | 121 // we are _blocking_ until all the necessary pages have been rendered or the |
134 // print settings are being loaded. | 122 // print settings are being loaded. |
135 bool inside_inner_message_loop_; | 123 bool inside_inner_message_loop_; |
136 | 124 |
137 // The object is waiting for some information to call print_job_->Init(true). | |
138 // It is either a DEFAULT_INIT_DONE notification or the | |
139 // DidGetPrintedPagesCount() callback. | |
140 // Showing the Print... dialog box is a multi-step operation: | |
141 // - print_job_->Init(false) to get the default settings. Set | |
142 // waiting_to_show_print_dialog_ = true. | |
143 // - on DEFAULT_INIT_DONE, gathers new settings. | |
144 // - did settings() or document() change since the last intialization? | |
145 // - Call SwitchCssToPrintMediaType() | |
146 // - On DidGetPrintedPagesCount() call, if | |
147 // waiting_to_show_print_dialog_ = true | |
148 // - calls print_job_->Init(true). | |
149 // - waiting_to_show_print_dialog_ = false. | |
150 // - DONE. | |
151 // - else (It may happens when redisplaying the dialog box with settings that | |
152 // haven't changed) | |
153 // - if waiting_to_show_print_dialog_ = true && page_count is initialized. | |
154 // - calls print_job_->Init(true). | |
155 // - waiting_to_show_print_dialog_ = false. | |
156 bool waiting_to_show_print_dialog_; | |
157 | |
158 // PrintViewManager is created as an extension of WebContent specialized for | 125 // PrintViewManager is created as an extension of WebContent specialized for |
159 // printing-related behavior. Still, access to the renderer is needed so a | 126 // printing-related behavior. Still, access to the renderer is needed so a |
160 // back reference is kept the the "parent object". | 127 // back reference is kept the the "parent object". |
161 WebContents& owner_; | 128 WebContents& owner_; |
162 | 129 |
163 DISALLOW_COPY_AND_ASSIGN(PrintViewManager); | 130 DISALLOW_COPY_AND_ASSIGN(PrintViewManager); |
164 }; | 131 }; |
165 | 132 |
166 } // namespace printing | 133 } // namespace printing |
167 | 134 |
168 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ | 135 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_ |
OLD | NEW |