Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <map> | |
| 10 | |
| 11 #include "base/ref_counted.h" | |
| 12 #include "chrome/common/notification_observer.h" | |
| 13 #include "chrome/common/notification_registrar.h" | |
| 14 | |
| 15 class Browser; | |
| 16 class TabContents; | |
| 17 | |
| 18 namespace printing { | |
| 19 | |
| 20 // For print preview, a print preview (PP) tab should be linked with the | |
| 21 // initiator tab that initiated the printing operation. If the tab initiates | |
| 22 // a second printing operation while the first print preview tab is still open, | |
| 23 // that PP tab should be focused/activated. There may be more than one PP tab | |
| 24 // open. There is 1:1 relationship between PP tabs and initiating tabs. This | |
| 25 // class manages PP tabs and initiator tabs. | |
| 26 class PrintPreviewTabController | |
| 27 : public base::RefCounted<PrintPreviewTabController>, | |
| 28 public NotificationObserver { | |
| 29 public: | |
| 30 static PrintPreviewTabController* GetInstance(); | |
| 31 | |
| 32 PrintPreviewTabController(); | |
| 33 | |
| 34 virtual ~PrintPreviewTabController(); | |
| 35 | |
| 36 // Get/Create the print preview tab for initiator_tab. | |
| 37 // |browser_window_id| is used to identify |initiator_tab| browser window. | |
| 38 TabContents* GetOrCreatePreviewTab( | |
| 39 TabContents* initiator_tab, int browser_window_id); | |
| 40 | |
| 41 // Notification observer implementation. | |
| 42 virtual void Observe(NotificationType type, | |
| 43 const NotificationSource& source, | |
| 44 const NotificationDetails& details); | |
| 45 | |
| 46 private: | |
| 47 friend class base::RefCounted<PrintPreviewTabController>; | |
| 48 | |
| 49 // Returns true if |tab| is a print preview tab. | |
| 50 bool IsPrintPreviewTab(TabContents* tab); | |
|
Lei Zhang
2010/11/13 05:04:56
nit: Be consistent. Either name this IsPreviewTab(
kmadhusu
2010/11/15 21:22:27
Renamed IsPrintPreviewTab() to IsPreviewTab().
| |
| 51 | |
| 52 // Return the initiator tab for |preview_tab| or return NULL. | |
| 53 TabContents* GetInitiatorTab(TabContents* preview_tab); | |
| 54 | |
| 55 // Return preview tab for |initiator_tab| or return NULL. | |
| 56 TabContents* GetPreviewTab(TabContents* initiator_tab); | |
|
Lei Zhang
2010/11/13 05:04:56
nit: |initiator_tab| is called "current_tab" in th
kmadhusu
2010/11/15 21:22:27
Done.
| |
| 57 | |
| 58 // Create a new print preview tab. | |
| 59 TabContents* CreatePrintPreviewTab( | |
| 60 TabContents* initiator_tab, int browser_window_id); | |
| 61 | |
| 62 // Add/Remove observers for notifications from |tab|. | |
| 63 void AddObservers(TabContents* tab); | |
| 64 void RemoveObservers(TabContents* tab); | |
| 65 | |
| 66 // 1:1 relationship between initiator tab and print preview tab. | |
| 67 // Key: Preview tab. | |
| 68 // Value: Initiator tab. | |
| 69 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; | |
| 70 PrintPreviewTabMap preview_tab_map_; | |
| 71 | |
| 72 // A registrar for listening for TAB_CONTENTS_DESTROYED notification. | |
| 73 NotificationRegistrar registrar_; | |
| 74 | |
| 75 // Are we waiting for a new preview tab with NavigationType::NEW_PAGE? If so, | |
| 76 // do nothing in observer. | |
| 77 bool waiting_for_new_preview_page_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); | |
| 80 }; | |
| 81 | |
| 82 } // namespace printing | |
| 83 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | |
| OLD | NEW |