OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // For print preview, a print preview (PP) tab is linked with the initiator tab | 5 // For print preview, a print preview (PP) tab is linked with the initiator tab |
6 // that initiated the printing operation. If the tab initiates a second | 6 // that initiated the printing operation. If the tab initiates a second |
7 // printing operation while the first print preview tab is still open, that PP | 7 // printing operation while the first print preview tab is still open, that PP |
8 // tab is focused/activated. There may be more than one PP tab open. There is a | 8 // tab is focused/activated. There may be more than one PP tab open. There is a |
9 // 1:1 relationship between PP tabs and initiating tabs. This class manages PP | 9 // 1:1 relationship between PP tabs and initiating tabs. This class manages PP |
10 // tabs and initiator tabs. | 10 // tabs and initiator tabs. |
11 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | 11 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |
12 | 12 |
13 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | 13 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |
14 #pragma once | 14 #pragma once |
15 | 15 |
16 #include <map> | 16 #include <map> |
17 | 17 |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "chrome/browser/sessions/session_id.h" | 19 #include "chrome/browser/sessions/session_id.h" |
20 #include "content/common/notification_observer.h" | 20 #include "content/common/notification_observer.h" |
21 #include "content/common/notification_registrar.h" | 21 #include "content/common/notification_registrar.h" |
22 | 22 |
23 class Browser; | 23 class Browser; |
24 class RenderProcessHost; | 24 class RenderProcessHost; |
25 class TabContents; | 25 class TabContentsWrapper; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 struct LoadCommittedDetails; | 28 struct LoadCommittedDetails; |
29 } | 29 } |
30 | 30 |
31 namespace printing { | 31 namespace printing { |
32 | 32 |
33 class PrintPreviewTabController | 33 class PrintPreviewTabController |
34 : public base::RefCounted<PrintPreviewTabController>, | 34 : public base::RefCounted<PrintPreviewTabController>, |
35 public NotificationObserver { | 35 public NotificationObserver { |
36 public: | 36 public: |
37 PrintPreviewTabController(); | 37 PrintPreviewTabController(); |
38 | 38 |
39 virtual ~PrintPreviewTabController(); | 39 virtual ~PrintPreviewTabController(); |
40 | 40 |
41 static PrintPreviewTabController* GetInstance(); | 41 static PrintPreviewTabController* GetInstance(); |
42 | 42 |
43 // Initiate print preview for |initiator_tab|. | 43 // Initiate print preview for |initiator_tab|. |
44 // Call this instead of GetOrCreatePreviewTab(). | 44 // Call this instead of GetOrCreatePreviewTab(). |
45 static void PrintPreview(TabContents* initiator_tab); | 45 static void PrintPreview(TabContentsWrapper* initiator_tab); |
46 | 46 |
47 // Get/Create the print preview tab for |initiator_tab|. | 47 // Get/Create the print preview tab for |initiator_tab|. |
48 // Exposed for unit tests. | 48 // Exposed for unit tests. |
49 TabContents* GetOrCreatePreviewTab(TabContents* initiator_tab); | 49 TabContentsWrapper* GetOrCreatePreviewTab(TabContentsWrapper* initiator_tab); |
50 | 50 |
51 // Returns preview tab for |tab|. | 51 // Returns preview tab for |tab|. |
52 // Returns |tab| if |tab| is a preview tab. | 52 // Returns |tab| if |tab| is a preview tab. |
53 // Returns NULL if no preview tab exists for |tab|. | 53 // Returns NULL if no preview tab exists for |tab|. |
54 TabContents* GetPrintPreviewForTab(TabContents* tab) const; | 54 TabContentsWrapper* GetPrintPreviewForTab(TabContentsWrapper* tab) const; |
55 | 55 |
56 // Returns initiator tab for |preview_tab|. | 56 // Returns initiator tab for |preview_tab|. |
57 // Returns NULL if no initiator tab exists for |preview_tab|. | 57 // Returns NULL if no initiator tab exists for |preview_tab|. |
58 TabContents* GetInitiatorTab(TabContents* preview_tab); | 58 TabContentsWrapper* GetInitiatorTab(TabContentsWrapper* preview_tab); |
59 | 59 |
60 // NotificationObserver implementation. | 60 // NotificationObserver implementation. |
61 virtual void Observe(int type, | 61 virtual void Observe(int type, |
62 const NotificationSource& source, | 62 const NotificationSource& source, |
63 const NotificationDetails& details); | 63 const NotificationDetails& details); |
64 | 64 |
65 // Returns true if |tab| is a print preview tab. | 65 // Returns true if |tab| is a print preview tab. |
66 static bool IsPrintPreviewTab(TabContents* tab); | 66 static bool IsPrintPreviewTab(TabContentsWrapper* tab); |
67 | 67 |
68 // Erase the initiator tab info associated with |preview_tab|. | 68 // Erase the initiator tab info associated with |preview_tab|. |
69 void EraseInitiatorTabInfo(TabContents* preview_tab); | 69 void EraseInitiatorTabInfo(TabContentsWrapper* preview_tab); |
70 | 70 |
71 private: | 71 private: |
72 friend class base::RefCounted<PrintPreviewTabController>; | 72 friend class base::RefCounted<PrintPreviewTabController>; |
73 | 73 |
| 74 // 1:1 relationship between initiator tab and print preview tab. |
| 75 // Key: Preview tab. |
| 76 // Value: Initiator tab. |
| 77 typedef std::map<TabContentsWrapper*, TabContentsWrapper*> PrintPreviewTabMap; |
| 78 |
74 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when | 79 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when |
75 // the initiator renderer crashed. | 80 // the initiator renderer crashed. |
76 void OnRendererProcessClosed(RenderProcessHost* rph); | 81 void OnRendererProcessClosed(RenderProcessHost* rph); |
77 | 82 |
78 // Handler for the TAB_CONTENTS_DESTROYED notification. This is observed when | 83 // Handler for the TAB_CONTENTS_DESTROYED notification. This is observed when |
79 // either tab is closed. | 84 // either tab is closed. |
80 void OnTabContentsDestroyed(TabContents* tab); | 85 void OnTabContentsDestroyed(TabContentsWrapper* tab); |
81 | 86 |
82 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the | 87 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the |
83 // renderer is navigated to a different page. | 88 // renderer is navigated to a different page. |
84 void OnNavEntryCommitted(TabContents* tab, | 89 void OnNavEntryCommitted(TabContentsWrapper* tab, |
85 content::LoadCommittedDetails* details); | 90 content::LoadCommittedDetails* details); |
86 | 91 |
87 // 1:1 relationship between initiator tab and print preview tab. | |
88 // Key: Preview tab. | |
89 // Value: Initiator tab. | |
90 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; | |
91 | |
92 // Creates a new print preview tab. | 92 // Creates a new print preview tab. |
93 TabContents* CreatePrintPreviewTab(TabContents* initiator_tab); | 93 TabContentsWrapper* CreatePrintPreviewTab(TabContentsWrapper* initiator_tab); |
94 | 94 |
95 // Helper function to store the initiator tab(title and url) information | 95 // Helper function to store the initiator tab(title and url) information |
96 // in |PrintPreviewUI|. | 96 // in PrintPreviewUI. |
97 void SetInitiatorTabURLAndTitle(TabContents* preview_tab); | 97 void SetInitiatorTabURLAndTitle(TabContentsWrapper* preview_tab); |
98 | 98 |
99 // Adds/Removes observers for notifications from |tab|. | 99 // Adds/Removes observers for notifications from |tab|. |
100 void AddObservers(TabContents* tab); | 100 void AddObservers(TabContentsWrapper* tab); |
101 void RemoveObservers(TabContents* tab); | 101 void RemoveObservers(TabContentsWrapper* tab); |
102 | 102 |
103 // Mapping between print preview tab and the corresponding initiator tab. | 103 // Mapping between print preview tab and the corresponding initiator tab. |
104 PrintPreviewTabMap preview_tab_map_; | 104 PrintPreviewTabMap preview_tab_map_; |
105 | 105 |
106 // A registrar for listening notifications. | 106 // A registrar for listening notifications. |
107 NotificationRegistrar registrar_; | 107 NotificationRegistrar registrar_; |
108 | 108 |
109 // True if the controller is waiting for a new preview tab via | 109 // True if the controller is waiting for a new preview tab via |
110 // NavigationType::NEW_PAGE. | 110 // NavigationType::NEW_PAGE. |
111 bool waiting_for_new_preview_page_; | 111 bool waiting_for_new_preview_page_; |
112 | 112 |
113 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); | 113 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); |
114 }; | 114 }; |
115 | 115 |
116 } // namespace printing | 116 } // namespace printing |
117 | 117 |
118 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | 118 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |
OLD | NEW |