Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / printing / print_view_manager.h
blob45e840b54c97aa45550ae4ec529b738c96036ff9
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.
5 #ifndef CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
6 #define CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_
8 #include "chrome/browser/printing/print_view_manager_base.h"
9 #include "content/public/browser/web_contents_user_data.h"
11 namespace content {
12 class RenderProcessHost;
15 namespace printing {
17 class PrintViewManagerObserver;
19 // Manages the print commands for a WebContents.
20 class PrintViewManager : public PrintViewManagerBase,
21 public content::WebContentsUserData<PrintViewManager> {
22 public:
23 ~PrintViewManager() override;
25 #if defined(ENABLE_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();
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 // ENABLE_BASIC_PRINTING
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);
42 // Notify PrintViewManager that print preview is starting in the renderer for
43 // a particular WebNode.
44 void PrintPreviewForWebNode();
46 // Notify PrintViewManager that print preview has finished. Unfreeze the
47 // renderer in the case of scripted print preview.
48 void PrintPreviewDone();
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);
55 // content::WebContentsObserver implementation.
56 bool OnMessageReceived(const IPC::Message& message) override;
58 // content::WebContentsObserver implementation.
59 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
61 // content::WebContentsObserver implementation.
62 // Terminates or cancels the print job if one was pending.
63 void RenderProcessGone(base::TerminationStatus status) override;
65 private:
66 explicit PrintViewManager(content::WebContents* web_contents);
67 friend class content::WebContentsUserData<PrintViewManager>;
69 enum PrintPreviewState {
70 NOT_PREVIEWING,
71 USER_INITIATED_PREVIEW,
72 SCRIPTED_PREVIEW,
75 // IPC Message handlers.
76 void OnDidShowPrintDialog();
77 void OnSetupScriptedPrintPreview(IPC::Message* reply_msg);
78 void OnShowScriptedPrintPreview(bool source_is_modifiable);
79 void OnScriptedPrintPreviewReply(IPC::Message* reply_msg);
81 // Weak pointer to an observer that is notified when the print dialog is
82 // shown.
83 PrintViewManagerObserver* observer_;
85 // Current state of print preview for this view.
86 PrintPreviewState print_preview_state_;
88 // Keeps track of the pending callback during scripted print preview.
89 content::RenderProcessHost* scripted_print_preview_rph_;
91 DISALLOW_COPY_AND_ASSIGN(PrintViewManager);
94 } // namespace printing
96 #endif // CHROME_BROWSER_PRINTING_PRINT_VIEW_MANAGER_H_