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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
6#define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
7
8#include "chrome/browser/printing/print_view_manager_base.h"
9#include "content/public/browser/web_contents_user_data.h"
10
11namespace content {
12class RenderProcessHost;
13}
14
15namespace printing {
16
17class PrintViewManagerObserver;
18
19// Manages the print commands for a WebContents.
20class PrintViewManager : public PrintViewManagerBase,
21                         public content::WebContentsUserData<PrintViewManager> {
22 public:
23  virtual ~PrintViewManager();
24
25#if !defined(DISABLE_BASIC_PRINTING)
26  // Same as PrintNow(), but for the case where a user prints with the system
27  // dialog from print preview.
28  bool PrintForSystemDialogNow();
29
30  // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
31  // show the native system dialog. This can happen from both initiator and
32  // preview dialog.
33  bool BasicPrint();
34#endif  // !DISABLE_BASIC_PRINTING
35
36  // Initiate print preview of the current document by first notifying the
37  // renderer. Since this happens asynchronous, the print preview dialog
38  // creation will not be completed on the return of this function. Returns
39  // false if print preview is impossible at the moment.
40  bool PrintPreviewNow(bool selection_only);
41
42  // Notify PrintViewManager that print preview is starting in the renderer for
43  // a particular WebNode.
44  void PrintPreviewForWebNode();
45
46  // Notify PrintViewManager that print preview has finished. Unfreeze the
47  // renderer in the case of scripted print preview.
48  void PrintPreviewDone();
49
50  // Sets |observer| as the current PrintViewManagerObserver. Pass in NULL to
51  // remove the current observer. |observer| may always be NULL, but |observer_|
52  // must be NULL if |observer| is non-NULL.
53  void set_observer(PrintViewManagerObserver* observer);
54
55  // content::WebContentsObserver implementation.
56  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
57
58  // content::WebContentsObserver implementation.
59  // Terminates or cancels the print job if one was pending.
60  virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
61
62 private:
63  explicit PrintViewManager(content::WebContents* web_contents);
64  friend class content::WebContentsUserData<PrintViewManager>;
65
66  enum PrintPreviewState {
67    NOT_PREVIEWING,
68    USER_INITIATED_PREVIEW,
69    SCRIPTED_PREVIEW,
70  };
71
72  // IPC Message handlers.
73  void OnDidShowPrintDialog();
74  void OnSetupScriptedPrintPreview(IPC::Message* reply_msg);
75  void OnShowScriptedPrintPreview(bool source_is_modifiable);
76  void OnScriptedPrintPreviewReply(IPC::Message* reply_msg);
77
78  // Weak pointer to an observer that is notified when the print dialog is
79  // shown.
80  PrintViewManagerObserver* observer_;
81
82  // Current state of print preview for this view.
83  PrintPreviewState print_preview_state_;
84
85  // Keeps track of the pending callback during scripted print preview.
86  content::RenderProcessHost* scripted_print_preview_rph_;
87
88  DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
89};
90
91}  // namespace printing
92
93#endif  // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
94