| 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 TabContents; | 25 class TabContents; |
| 25 | 26 |
| 27 namespace content { |
| 28 struct LoadCommittedDetails; |
| 29 } |
| 30 |
| 26 namespace printing { | 31 namespace printing { |
| 27 | 32 |
| 28 class PrintPreviewTabController | 33 class PrintPreviewTabController |
| 29 : public base::RefCounted<PrintPreviewTabController>, | 34 : public base::RefCounted<PrintPreviewTabController>, |
| 30 public NotificationObserver { | 35 public NotificationObserver { |
| 31 public: | 36 public: |
| 32 PrintPreviewTabController(); | 37 PrintPreviewTabController(); |
| 33 | 38 |
| 34 virtual ~PrintPreviewTabController(); | 39 virtual ~PrintPreviewTabController(); |
| 35 | 40 |
| 36 static PrintPreviewTabController* GetInstance(); | 41 static PrintPreviewTabController* GetInstance(); |
| 37 | 42 |
| 38 // Initiate print preview for |initiator_tab|. | 43 // Initiate print preview for |initiator_tab|. |
| 39 // Call this instead of GetOrCreatePreviewTab(). | 44 // Call this instead of GetOrCreatePreviewTab(). |
| 40 static void PrintPreview(TabContents* initiator_tab); | 45 static void PrintPreview(TabContents* initiator_tab); |
| 41 | 46 |
| 42 // Get/Create the print preview tab for |initiator_tab|. | 47 // Get/Create the print preview tab for |initiator_tab|. |
| 43 // Exposed for unit tests. | 48 // Exposed for unit tests. |
| 44 TabContents* GetOrCreatePreviewTab(TabContents* initiator_tab); | 49 TabContents* GetOrCreatePreviewTab(TabContents* initiator_tab); |
| 45 | 50 |
| 46 // Returns preview tab for |tab|. | 51 // Returns preview tab for |tab|. |
| 47 // Returns |tab| if |tab| is a preview tab. | 52 // Returns |tab| if |tab| is a preview tab. |
| 48 // Returns NULL if no preview tab exists for |tab|. | 53 // Returns NULL if no preview tab exists for |tab|. |
| 49 TabContents* GetPrintPreviewForTab(TabContents* tab) const; | 54 TabContents* GetPrintPreviewForTab(TabContents* tab) const; |
| 50 | 55 |
| 51 // Returns initiator tab for |preview_tab|. | 56 // Returns initiator tab for |preview_tab|. |
| 52 // Returns NULL if no initiator tab exists for |preview_tab|. | 57 // Returns NULL if no initiator tab exists for |preview_tab|. |
| 53 TabContents* GetInitiatorTab(TabContents* preview_tab); | 58 TabContents* GetInitiatorTab(TabContents* preview_tab); |
| 54 | 59 |
| 55 // Notification observer implementation. | 60 // NotificationObserver implementation. |
| 56 virtual void Observe(int type, | 61 virtual void Observe(int type, |
| 57 const NotificationSource& source, | 62 const NotificationSource& source, |
| 58 const NotificationDetails& details); | 63 const NotificationDetails& details); |
| 59 | 64 |
| 60 // Returns true if |tab| is a print preview tab. | 65 // Returns true if |tab| is a print preview tab. |
| 61 static bool IsPrintPreviewTab(TabContents* tab); | 66 static bool IsPrintPreviewTab(TabContents* tab); |
| 62 | 67 |
| 63 // Erase the initiator tab info associated with |preview_tab|. | 68 // Erase the initiator tab info associated with |preview_tab|. |
| 64 void EraseInitiatorTabInfo(TabContents* preview_tab); | 69 void EraseInitiatorTabInfo(TabContents* preview_tab); |
| 65 | 70 |
| 66 private: | 71 private: |
| 67 friend class base::RefCounted<PrintPreviewTabController>; | 72 friend class base::RefCounted<PrintPreviewTabController>; |
| 68 | 73 |
| 74 // Handler for the RENDERER_PROCESS_CLOSED notification. This is observed when |
| 75 // the initiator renderer crashed. |
| 76 void OnRendererProcessClosed(RenderProcessHost* rph); |
| 77 |
| 78 // Handler for the TAB_CONTENTS_DESTROYED notification. This is observed when |
| 79 // either tab is closed. |
| 80 void OnTabContentsDestroyed(TabContents* tab); |
| 81 |
| 82 // Handler for the NAV_ENTRY_COMMITTED notification. This is observed when the |
| 83 // renderer is navigated to a different page. |
| 84 void OnNavEntryCommitted(TabContents* tab, |
| 85 content::LoadCommittedDetails* details); |
| 86 |
| 69 // 1:1 relationship between initiator tab and print preview tab. | 87 // 1:1 relationship between initiator tab and print preview tab. |
| 70 // Key: Preview tab. | 88 // Key: Preview tab. |
| 71 // Value: Initiator tab. | 89 // Value: Initiator tab. |
| 72 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; | 90 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; |
| 73 | 91 |
| 74 // Creates a new print preview tab. | 92 // Creates a new print preview tab. |
| 75 TabContents* CreatePrintPreviewTab(TabContents* initiator_tab); | 93 TabContents* CreatePrintPreviewTab(TabContents* initiator_tab); |
| 76 | 94 |
| 77 // Adds/Removes observers for notifications from |tab|. | 95 // Adds/Removes observers for notifications from |tab|. |
| 78 void AddObservers(TabContents* tab); | 96 void AddObservers(TabContents* tab); |
| 79 void RemoveObservers(TabContents* tab); | 97 void RemoveObservers(TabContents* tab); |
| 80 | 98 |
| 99 // Mapping between print preview tab and the corresponding initiator tab. |
| 81 PrintPreviewTabMap preview_tab_map_; | 100 PrintPreviewTabMap preview_tab_map_; |
| 82 | 101 |
| 83 // A registrar for listening notifications. | 102 // A registrar for listening notifications. |
| 84 NotificationRegistrar registrar_; | 103 NotificationRegistrar registrar_; |
| 85 | 104 |
| 86 // True if the controller is waiting for a new preview tab via | 105 // True if the controller is waiting for a new preview tab via |
| 87 // NavigationType::NEW_PAGE. | 106 // NavigationType::NEW_PAGE. |
| 88 bool waiting_for_new_preview_page_; | 107 bool waiting_for_new_preview_page_; |
| 89 | 108 |
| 90 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); | 109 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); |
| 91 }; | 110 }; |
| 92 | 111 |
| 93 } // namespace printing | 112 } // namespace printing |
| 94 | 113 |
| 95 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | 114 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |
| OLD | NEW |