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 IsPreviewTab(TabContents* tab); |
| 51 |
| 52 // Return the initiator tab for |preview_tab| or return NULL. |
| 53 TabContents* GetInitiatorTab(TabContents* preview_tab); |
| 54 |
| 55 // Return preview tab for |current_tab| or return NULL. |
| 56 // If |current_tab| is preview tab return |current_tab|. |
| 57 TabContents* GetPreviewTab(TabContents* current_tab); |
| 58 |
| 59 // Create a new print preview tab. |
| 60 TabContents* CreatePrintPreviewTab( |
| 61 TabContents* initiator_tab, int browser_window_id); |
| 62 |
| 63 // Add/Remove observers for notifications from |tab|. |
| 64 void AddObservers(TabContents* tab); |
| 65 void RemoveObservers(TabContents* tab); |
| 66 |
| 67 // 1:1 relationship between initiator tab and print preview tab. |
| 68 // Key: Preview tab. |
| 69 // Value: Initiator tab. |
| 70 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; |
| 71 PrintPreviewTabMap preview_tab_map_; |
| 72 |
| 73 // A registrar for listening for TAB_CONTENTS_DESTROYED notification. |
| 74 NotificationRegistrar registrar_; |
| 75 |
| 76 // Are we waiting for a new preview tab with NavigationType::NEW_PAGE? If so, |
| 77 // do nothing in observer. |
| 78 bool waiting_for_new_preview_page_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); |
| 81 }; |
| 82 |
| 83 } // namespace printing |
| 84 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |
OLD | NEW |