Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / printing / print_preview_dialog_controller.h
blob90b7ca69982066704d96d19d59055168914e03bf
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_PREVIEW_DIALOG_CONTROLLER_H_
6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_
8 #include <vector>
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/sessions/session_id.h"
13 class GURL;
15 namespace content {
16 struct LoadCommittedDetails;
17 class RenderProcessHost;
18 class WebContents;
21 namespace printing {
23 // For print preview, the WebContents that initiates the printing operation is
24 // the initiator, and the constrained dialog that shows the print preview is the
25 // print preview dialog.
26 // This class manages print preview dialog creation and destruction, and keeps
27 // track of the 1:1 relationship between initiator tabs and print preview
28 // dialogs.
29 class PrintPreviewDialogController
30 : public base::RefCounted<PrintPreviewDialogController> {
31 public:
32 PrintPreviewDialogController();
34 static PrintPreviewDialogController* GetInstance();
36 // Initiate print preview for |initiator|.
37 // Call this instead of GetOrCreatePreviewDialog().
38 static void PrintPreview(content::WebContents* initiator);
40 // Get/Create the print preview dialog for |initiator|.
41 // Exposed for unit tests.
42 content::WebContents* GetOrCreatePreviewDialog(
43 content::WebContents* initiator);
45 // Returns the preview dialog for |contents|.
46 // Returns |contents| if |contents| is a preview dialog.
47 // Returns NULL if no preview dialog exists for |contents|.
48 content::WebContents* GetPrintPreviewForContents(
49 content::WebContents* contents) const;
51 // Returns the initiator for |preview_dialog|.
52 // Returns NULL if no initiator exists for |preview_dialog|.
53 content::WebContents* GetInitiator(content::WebContents* preview_dialog);
55 // Returns true if |contents| is a print preview dialog.
56 static bool IsPrintPreviewDialog(content::WebContents* contents);
58 // Returns true if |url| is a print preview url.
59 static bool IsPrintPreviewURL(const GURL& url);
61 // Erase the initiator info associated with |preview_dialog|.
62 void EraseInitiatorInfo(content::WebContents* preview_dialog);
64 bool is_creating_print_preview_dialog() const {
65 return is_creating_print_preview_dialog_;
68 private:
69 friend class base::RefCounted<PrintPreviewDialogController>;
70 struct Operation;
72 virtual ~PrintPreviewDialogController();
74 // Handlers for observed events.
75 void OnRenderProcessExited(content::RenderProcessHost* rph);
76 void OnWebContentsDestroyed(content::WebContents* contents);
77 void OnNavigationEntryCommitted(content::WebContents* contents,
78 const content::LoadCommittedDetails* details);
80 // Creates a new print preview dialog.
81 content::WebContents* CreatePrintPreviewDialog(
82 content::WebContents* initiator);
84 // Helper function to store the title of the initiator associated with
85 // |preview_dialog| in |preview_dialog|'s PrintPreviewUI.
86 void SaveInitiatorTitle(content::WebContents* preview_dialog);
88 // Removes WebContents when they close/crash/navigate.
89 void RemoveInitiator(content::WebContents* initiator);
90 void RemovePreviewDialog(content::WebContents* preview_dialog);
92 // The list of the currently active preview operations.
93 std::vector<Operation*> preview_operations_;
95 // True if the controller is waiting for a new preview dialog via
96 // content::NAVIGATION_TYPE_NEW_PAGE.
97 bool waiting_for_new_preview_page_;
99 // Whether the PrintPreviewDialogController is in the middle of creating a
100 // print preview dialog.
101 bool is_creating_print_preview_dialog_;
103 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogController);
106 } // namespace printing
108 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_