summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing/print_preview_message_handler.h
blob: f9eab859e3b980470fd5d3ffd4645901a5d93b39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_
#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_
#pragma once

#include "base/compiler_specific.h"
#include "content/public/browser/web_contents_observer.h"

class PrintPreviewUI;
class TabContentsWrapper;
struct PrintHostMsg_DidGetPreviewPageCount_Params;
struct PrintHostMsg_DidPreviewDocument_Params;
struct PrintHostMsg_DidPreviewPage_Params;

namespace printing {

struct PageSizeMargins;

// TabContents offloads print preview message handling to
// PrintPreviewMessageHandler. This object has the same life time as the
// TabContents that owns it.
class PrintPreviewMessageHandler : public content::WebContentsObserver {
 public:
  explicit PrintPreviewMessageHandler(content::WebContents* web_contents);
  virtual ~PrintPreviewMessageHandler();

  // content::WebContentsObserver implementation.
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
  virtual void NavigateToPendingEntry(const GURL& url,
      content::NavigationController::ReloadType reload_type) OVERRIDE;

 private:
  // Gets the print preview tab associated with the WebContents being observed.
  TabContentsWrapper* GetPrintPreviewTab();

  // Helper function to return the TabContentsWrapper for web_contents().
  TabContentsWrapper* tab_contents_wrapper();

  // Common code between failure handlers. Returns a PrintPreviewUI* if there
  // exists a PrintPreviewUI to send messages to.
  PrintPreviewUI* OnFailure(int document_cookie);

  // Message handlers.
  void OnRequestPrintPreview(bool source_is_modifiable);
  void OnDidGetDefaultPageLayout(
      const printing::PageSizeMargins& page_layout_in_points);
  void OnDidGetPreviewPageCount(
      const PrintHostMsg_DidGetPreviewPageCount_Params& params);
  void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params);
  void OnMetafileReadyForPrinting(
      const PrintHostMsg_DidPreviewDocument_Params& params);
  void OnPrintPreviewFailed(int document_cookie);
  void OnPrintPreviewCancelled(int document_cookie);
  void OnInvalidPrinterSettings(int document_cookie);

  DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler);
};

}  // namespace printing

#endif  // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_