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