| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PREVIEW_MESSAGE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "chrome/browser/tab_contents/web_contents_user_data.h" |
| 9 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
| 10 | 11 |
| 11 class PrintPreviewUI; | 12 class PrintPreviewUI; |
| 12 class TabContents; | 13 class TabContents; |
| 13 struct PrintHostMsg_DidGetPreviewPageCount_Params; | 14 struct PrintHostMsg_DidGetPreviewPageCount_Params; |
| 14 struct PrintHostMsg_DidPreviewDocument_Params; | 15 struct PrintHostMsg_DidPreviewDocument_Params; |
| 15 struct PrintHostMsg_DidPreviewPage_Params; | 16 struct PrintHostMsg_DidPreviewPage_Params; |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| 18 class Rect; | 19 class Rect; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace printing { | 22 namespace printing { |
| 22 | 23 |
| 23 struct PageSizeMargins; | 24 struct PageSizeMargins; |
| 24 | 25 |
| 25 // TabContents offloads print preview message handling to | 26 // Manages the print preview handling for a WebContents. |
| 26 // PrintPreviewMessageHandler. This object has the same life time as the | 27 class PrintPreviewMessageHandler |
| 27 // TabContents that owns it. | 28 : public content::WebContentsObserver, |
| 28 class PrintPreviewMessageHandler : public content::WebContentsObserver { | 29 public WebContentsUserData<PrintPreviewMessageHandler> { |
| 29 public: | 30 public: |
| 30 explicit PrintPreviewMessageHandler(content::WebContents* web_contents); | |
| 31 virtual ~PrintPreviewMessageHandler(); | 31 virtual ~PrintPreviewMessageHandler(); |
| 32 | 32 |
| 33 // content::WebContentsObserver implementation. | 33 // content::WebContentsObserver implementation. |
| 34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 explicit PrintPreviewMessageHandler(content::WebContents* web_contents); |
| 38 static int kUserDataKey; |
| 39 friend class WebContentsUserData<PrintPreviewMessageHandler>; |
| 40 |
| 37 // Gets the print preview tab associated with the WebContents being observed. | 41 // Gets the print preview tab associated with the WebContents being observed. |
| 38 TabContents* GetPrintPreviewTab(); | 42 TabContents* GetPrintPreviewTab(); |
| 39 | 43 |
| 40 // Helper function to return the TabContents for web_contents(). | |
| 41 TabContents* tab_contents(); | |
| 42 | |
| 43 // Gets the PrintPreviewUI associated with the WebContents being observed. | 44 // Gets the PrintPreviewUI associated with the WebContents being observed. |
| 44 PrintPreviewUI* GetPrintPreviewUI(); | 45 PrintPreviewUI* GetPrintPreviewUI(); |
| 45 | 46 |
| 46 // Message handlers. | 47 // Message handlers. |
| 47 void OnRequestPrintPreview(bool source_is_modifiable, bool webnode_only); | 48 void OnRequestPrintPreview(bool source_is_modifiable, bool webnode_only); |
| 48 void OnDidGetDefaultPageLayout( | 49 void OnDidGetDefaultPageLayout( |
| 49 const printing::PageSizeMargins& page_layout_in_points, | 50 const printing::PageSizeMargins& page_layout_in_points, |
| 50 const gfx::Rect& printable_area_in_points, | 51 const gfx::Rect& printable_area_in_points, |
| 51 bool has_custom_page_size_style); | 52 bool has_custom_page_size_style); |
| 52 void OnDidGetPreviewPageCount( | 53 void OnDidGetPreviewPageCount( |
| 53 const PrintHostMsg_DidGetPreviewPageCount_Params& params); | 54 const PrintHostMsg_DidGetPreviewPageCount_Params& params); |
| 54 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); | 55 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); |
| 55 void OnMetafileReadyForPrinting( | 56 void OnMetafileReadyForPrinting( |
| 56 const PrintHostMsg_DidPreviewDocument_Params& params); | 57 const PrintHostMsg_DidPreviewDocument_Params& params); |
| 57 void OnPrintPreviewFailed(int document_cookie); | 58 void OnPrintPreviewFailed(int document_cookie); |
| 58 void OnPrintPreviewCancelled(int document_cookie); | 59 void OnPrintPreviewCancelled(int document_cookie); |
| 59 void OnInvalidPrinterSettings(int document_cookie); | 60 void OnInvalidPrinterSettings(int document_cookie); |
| 60 void OnPrintPreviewScalingDisabled(); | 61 void OnPrintPreviewScalingDisabled(); |
| 61 | 62 |
| 62 DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler); | 63 DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 } // namespace printing | 66 } // namespace printing |
| 66 | 67 |
| 67 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_ | 68 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_ |
| OLD | NEW |