Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: trunk/src/chrome/browser/printing/print_preview_dialog_controller.h

Issue 21372006: Revert 212329 "Reland "Close web contents modal dialogs on conte..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_DIALOG_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_
6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ 6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/sessions/session_id.h" 11 #include "chrome/browser/sessions/session_id.h"
12 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 13 #include "content/public/browser/notification_registrar.h"
14 14
15 class GURL; 15 class GURL;
16 16
17 namespace content { 17 namespace content {
18 struct LoadCommittedDetails; 18 struct LoadCommittedDetails;
19 class RenderProcessHost; 19 class RenderProcessHost;
20 class WebContents; 20 class WebContents;
21 } 21 }
22 22
23 namespace printing { 23 namespace printing {
24 24
25 // For print preview, the WebContents that initiates the printing operation is 25 // For print preview, the tab that initiates the printing operation is the
26 // the initiator, and the constrained dialog that shows the print preview is the 26 // initiator tab, and the constrained dialog that shows the print preview is
27 // print preview dialog. 27 // the print preview dialog.
28 // This class manages print preview dialog creation and destruction, and keeps 28 // This class manages print preview dialog creation and destruction, and keeps
29 // track of the 1:1 relationship between initiatora tabs and print preview 29 // track of the 1:1 relationship between initiatora tabs and print preview
30 // dialogs. 30 // dialogs.
31 class PrintPreviewDialogController 31 class PrintPreviewDialogController
32 : public base::RefCounted<PrintPreviewDialogController>, 32 : public base::RefCounted<PrintPreviewDialogController>,
33 public content::NotificationObserver { 33 public content::NotificationObserver {
34 public: 34 public:
35 PrintPreviewDialogController(); 35 PrintPreviewDialogController();
36 36
37 static PrintPreviewDialogController* GetInstance(); 37 static PrintPreviewDialogController* GetInstance();
38 38
39 // Initiate print preview for |initiator|. 39 // Initiate print preview for |initiator_tab|.
40 // Call this instead of GetOrCreatePreviewDialog(). 40 // Call this instead of GetOrCreatePreviewDialog().
41 static void PrintPreview(content::WebContents* initiator); 41 static void PrintPreview(content::WebContents* initiator_tab);
42 42
43 // Get/Create the print preview dialog for |initiator|. 43 // Get/Create the print preview dialog for |initiator_tab|.
44 // Exposed for unit tests. 44 // Exposed for unit tests.
45 content::WebContents* GetOrCreatePreviewDialog( 45 content::WebContents* GetOrCreatePreviewDialog(
46 content::WebContents* initiator); 46 content::WebContents* initiator_tab);
47 47
48 // Returns the preview dialog for |contents|. 48 // Returns the preview dialog for |contents|.
49 // Returns |contents| if |contents| is a preview dialog. 49 // Returns |contents| if |contents| is a preview dialog.
50 // Returns NULL if no preview dialog exists for |contents|. 50 // Returns NULL if no preview dialog exists for |contents|.
51 content::WebContents* GetPrintPreviewForContents( 51 content::WebContents* GetPrintPreviewForContents(
52 content::WebContents* contents) const; 52 content::WebContents* contents) const;
53 53
54 // Returns the initiator for |preview_dialog|. 54 // Returns the initiator tab for |preview_dialog|.
55 // Returns NULL if no initiator exists for |preview_dialog|. 55 // Returns NULL if no initiator tab exists for |preview_dialog|.
56 content::WebContents* GetInitiator(content::WebContents* preview_dialog); 56 content::WebContents* GetInitiatorTab(content::WebContents* preview_dialog);
57 57
58 // content::NotificationObserver implementation. 58 // content::NotificationObserver implementation.
59 virtual void Observe(int type, 59 virtual void Observe(int type,
60 const content::NotificationSource& source, 60 const content::NotificationSource& source,
61 const content::NotificationDetails& details) OVERRIDE; 61 const content::NotificationDetails& details) OVERRIDE;
62 62
63 // Returns true if |contents| is a print preview dialog. 63 // Returns true if |contents| is a print preview dialog.
64 static bool IsPrintPreviewDialog(content::WebContents* contents); 64 static bool IsPrintPreviewDialog(content::WebContents* contents);
65 65
66 // Returns true if |url| is a print preview url. 66 // Returns true if |url| is a print preview url.
67 static bool IsPrintPreviewURL(const GURL& url); 67 static bool IsPrintPreviewURL(const GURL& url);
68 68
69 // Erase the initiator info associated with |preview_dialog|. 69 // Erase the initiator tab info associated with |preview_tab|.
70 void EraseInitiatorInfo(content::WebContents* preview_dialog); 70 void EraseInitiatorTabInfo(content::WebContents* preview_tab);
71 71
72 bool is_creating_print_preview_dialog() const { 72 bool is_creating_print_preview_dialog() const {
73 return is_creating_print_preview_dialog_; 73 return is_creating_print_preview_dialog_;
74 } 74 }
75 75
76 private: 76 private:
77 friend class base::RefCounted<PrintPreviewDialogController>; 77 friend class base::RefCounted<PrintPreviewDialogController>;
78 78
79 // Used to distinguish between the two varieties of WebContents dealt with by 79 // 1:1 relationship between a print preview dialog and its initiator tab.
80 // this class.
81 enum ContentsType {
82 INITIATOR,
83 PREVIEW_DIALOG
84 };
85
86 // 1:1 relationship between a print preview dialog and its initiator.
87 // Key: Print preview dialog. 80 // Key: Print preview dialog.
88 // Value: Initiator. 81 // Value: Initiator tab.
89 typedef std::map<content::WebContents*, content::WebContents*> 82 typedef std::map<content::WebContents*, content::WebContents*>
90 PrintPreviewDialogMap; 83 PrintPreviewDialogMap;
91 84
92 virtual ~PrintPreviewDialogController(); 85 virtual ~PrintPreviewDialogController();
93 86
94 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when 87 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when
95 // the initiator renderer crashed. 88 // the initiator renderer crashed.
96 void OnRendererProcessClosed(content::RenderProcessHost* rph); 89 void OnRendererProcessClosed(content::RenderProcessHost* rph);
97 90
98 // Handler for the WEB_CONTENTS_DESTROYED notification. This is observed when 91 // Handler for the WEB_CONTENTS_DESTROYED notification. This is observed when
99 // either WebContents is closed. 92 // either WebContents is closed.
100 void OnWebContentsDestroyed(content::WebContents* contents); 93 void OnWebContentsDestroyed(content::WebContents* contents);
101 94
102 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the 95 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the
103 // renderer is navigated to a different page. 96 // renderer is navigated to a different page.
104 void OnNavEntryCommitted(content::WebContents* contents, 97 void OnNavEntryCommitted(content::WebContents* contents,
105 content::LoadCommittedDetails* details); 98 content::LoadCommittedDetails* details);
106 99
107 // Creates a new print preview dialog. 100 // Creates a new print preview dialog.
108 content::WebContents* CreatePrintPreviewDialog( 101 content::WebContents* CreatePrintPreviewDialog(
109 content::WebContents* initiator); 102 content::WebContents* initiator_tab);
110 103
111 // Helper function to store the title of the initiator associated with 104 // Helper function to store the title of the initiator tab associated with
112 // |preview_dialog| in |preview_dialog|'s PrintPreviewUI. 105 // |preview_dialog| in |preview_dialog|'s PrintPreviewUI.
113 void SaveInitiatorTitle(content::WebContents* preview_dialog); 106 void SaveInitiatorTabTitle(content::WebContents* preview_dialog);
114 107
115 // Adds/Removes observers for notifications from |contents|. 108 // Adds/Removes observers for notifications from |contents|.
116 void AddObservers(content::WebContents* contents, ContentsType contents_type); 109 void AddObservers(content::WebContents* contents);
117 void RemoveObservers(content::WebContents* contents, 110 void RemoveObservers(content::WebContents* contents);
118 ContentsType contents_type);
119 111
120 // Removes WebContents when they close/crash/navigate. 112 // Removes WebContents when they close/crash/navigate.
121 void RemoveInitiator(content::WebContents* initiator); 113 void RemoveInitiatorTab(content::WebContents* initiator_tab);
122 void RemovePreviewDialog(content::WebContents* preview_dialog); 114 void RemovePreviewDialog(content::WebContents* preview_dialog);
123 115
124 // Mapping between print preview dialog and the corresponding initiator. 116 // Mapping between print preview dialog and the corresponding initiator tab.
125 PrintPreviewDialogMap preview_dialog_map_; 117 PrintPreviewDialogMap preview_dialog_map_;
126 118
127 // A registrar for listening notifications. 119 // A registrar for listening notifications.
128 content::NotificationRegistrar registrar_; 120 content::NotificationRegistrar registrar_;
129 121
130 // True if the controller is waiting for a new preview dialog via 122 // True if the controller is waiting for a new preview dialog via
131 // content::NAVIGATION_TYPE_NEW_PAGE. 123 // content::NAVIGATION_TYPE_NEW_PAGE.
132 bool waiting_for_new_preview_page_; 124 bool waiting_for_new_preview_page_;
133 125
134 // Whether the PrintPreviewDialogController is in the middle of creating a 126 // Whether the PrintPreviewDialogController is in the middle of creating a
135 // print preview dialog. 127 // print preview dialog.
136 bool is_creating_print_preview_dialog_; 128 bool is_creating_print_preview_dialog_;
137 129
138 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogController); 130 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogController);
139 }; 131 };
140 132
141 } // namespace printing 133 } // namespace printing
142 134
143 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_ 135 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_DIALOG_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698