| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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. | |
| 4 | |
| 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 | |
| 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 | |
| 9 // 1:1 relationship between PP tabs and initiating tabs. This class manages PP | |
| 10 // tabs and initiator tabs. | |
| 11 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | |
| 12 | |
| 13 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | |
| 14 #pragma once | |
| 15 | |
| 16 #include <map> | |
| 17 | |
| 18 #include "base/ref_counted.h" | |
| 19 #include "chrome/common/notification_observer.h" | |
| 20 #include "chrome/common/notification_registrar.h" | |
| 21 | |
| 22 class Browser; | |
| 23 class TabContents; | |
| 24 | |
| 25 namespace printing { | |
| 26 | |
| 27 class PrintPreviewTabController | |
| 28 : public base::RefCounted<PrintPreviewTabController>, | |
| 29 public NotificationObserver { | |
| 30 public: | |
| 31 PrintPreviewTabController(); | |
| 32 | |
| 33 virtual ~PrintPreviewTabController(); | |
| 34 | |
| 35 static PrintPreviewTabController* GetInstance(); | |
| 36 | |
| 37 // Get/Create the print preview tab for |initiator_tab|. | |
| 38 // |browser_window_id| is the browser window containing |initiator_tab|. | |
| 39 TabContents* GetOrCreatePreviewTab( | |
| 40 TabContents* initiator_tab, int browser_window_id); | |
| 41 | |
| 42 // Notification observer implementation. | |
| 43 virtual void Observe(NotificationType type, | |
| 44 const NotificationSource& source, | |
| 45 const NotificationDetails& details); | |
| 46 | |
| 47 // Returns true if |tab| is a print preview tab. | |
| 48 static bool IsPrintPreviewTab(TabContents* tab); | |
| 49 | |
| 50 private: | |
| 51 friend class base::RefCounted<PrintPreviewTabController>; | |
| 52 | |
| 53 // 1:1 relationship between initiator tab and print preview tab. | |
| 54 // Key: Preview tab. | |
| 55 // Value: Initiator tab. | |
| 56 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; | |
| 57 | |
| 58 // Returns initiator tab for |preview_tab|. | |
| 59 // Returns NULL if no initiator tab exists for |preview_tab|. | |
| 60 TabContents* GetInitiatorTab(TabContents* preview_tab); | |
| 61 | |
| 62 // Returns preview tab for |tab|. | |
| 63 // Returns |tab| if |tab| is a preview tab. | |
| 64 // Returns NULL if no preview tab exists for |tab|. | |
| 65 TabContents* GetPrintPreviewForTab(TabContents* tab); | |
| 66 | |
| 67 // Creates a new print preview tab. | |
| 68 TabContents* CreatePrintPreviewTab( | |
| 69 TabContents* initiator_tab, int browser_window_id); | |
| 70 | |
| 71 // Adds/Removes observers for notifications from |tab|. | |
| 72 void AddObservers(TabContents* tab); | |
| 73 void RemoveObservers(TabContents* tab); | |
| 74 | |
| 75 PrintPreviewTabMap preview_tab_map_; | |
| 76 | |
| 77 // A registrar for listening notifications. | |
| 78 NotificationRegistrar registrar_; | |
| 79 | |
| 80 // True if the controller is waiting for a new preview tab via | |
| 81 // NavigationType::NEW_PAGE. | |
| 82 bool waiting_for_new_preview_page_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); | |
| 85 }; | |
| 86 | |
| 87 } // namespace printing | |
| 88 | |
| 89 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | |
| OLD | NEW |