Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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 the associated initiator tabs and print preview data. |
|
James Hawkins
2011/01/13 06:43:27
This really feels shoe-horned in here. The name o
| |
| 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/ref_counted.h" | 18 #include "base/ref_counted.h" |
| 19 #include "chrome/common/notification_observer.h" | 19 #include "chrome/common/notification_observer.h" |
| 20 #include "chrome/common/notification_registrar.h" | 20 #include "chrome/common/notification_registrar.h" |
| 21 | 21 |
| 22 class Browser; | 22 class Browser; |
| 23 class TabContents; | 23 class TabContents; |
| 24 | 24 |
| 25 namespace base { | |
| 26 class SharedMemory; | |
| 27 } | |
| 28 | |
| 25 namespace printing { | 29 namespace printing { |
| 26 | 30 |
| 27 class PrintPreviewTabController | 31 class PrintPreviewTabController |
| 28 : public base::RefCounted<PrintPreviewTabController>, | 32 : public base::RefCounted<PrintPreviewTabController>, |
| 29 public NotificationObserver { | 33 public NotificationObserver { |
| 30 public: | 34 public: |
| 35 typedef std::pair<base::SharedMemory*, uint32> PrintPreviewData; | |
| 36 | |
| 31 PrintPreviewTabController(); | 37 PrintPreviewTabController(); |
| 32 | 38 |
| 33 virtual ~PrintPreviewTabController(); | 39 virtual ~PrintPreviewTabController(); |
| 34 | 40 |
| 35 static PrintPreviewTabController* GetInstance(); | 41 static PrintPreviewTabController* GetInstance(); |
| 36 | 42 |
| 43 // Returns true if |tab| is a print preview tab. | |
| 44 static bool IsPrintPreviewTab(TabContents* tab); | |
| 45 | |
| 37 // Get/Create the print preview tab for |initiator_tab|. | 46 // Get/Create the print preview tab for |initiator_tab|. |
| 38 // |browser_window_id| is the browser window containing |initiator_tab|. | 47 // |browser_window_id| is the browser window containing |initiator_tab|. |
| 39 TabContents* GetOrCreatePreviewTab( | 48 TabContents* GetOrCreatePreviewTab( |
| 40 TabContents* initiator_tab, int browser_window_id); | 49 TabContents* initiator_tab, int browser_window_id); |
| 41 | 50 |
| 51 // Get the print preview |data| for |preview_tab|. The data is valid as long | |
| 52 // as |preview_tab| is valid and SetPrintPreviewData() does not get called. | |
| 53 bool GetPrintPreviewData(TabContents* preview_tab, PrintPreviewData* data); | |
| 54 | |
| 55 // Save the print preview |data| for |preview_tab|. PrintPreviewTabController | |
| 56 // owns the data and is responsible for freeing it when either: | |
| 57 // a) there is new data. | |
| 58 // b) when |preview_tab| goes away. | |
| 59 bool SetPrintPreviewData(TabContents* preview_tab, | |
| 60 const PrintPreviewData& data); | |
| 61 | |
| 42 // Notification observer implementation. | 62 // Notification observer implementation. |
| 43 virtual void Observe(NotificationType type, | 63 virtual void Observe(NotificationType type, |
| 44 const NotificationSource& source, | 64 const NotificationSource& source, |
| 45 const NotificationDetails& details); | 65 const NotificationDetails& details); |
| 46 | 66 |
| 47 // Returns true if |tab| is a print preview tab. | |
| 48 static bool IsPrintPreviewTab(TabContents* tab); | |
| 49 | |
| 50 private: | 67 private: |
| 51 friend class base::RefCounted<PrintPreviewTabController>; | 68 friend class base::RefCounted<PrintPreviewTabController>; |
| 52 | 69 |
| 70 // 1:1 relationship between print preview tab and its print preview data. | |
| 71 // Key: Print preview tab. | |
| 72 // Value: Print preview data. | |
| 73 typedef std::map<TabContents*, PrintPreviewData> PrintPreviewDataMap; | |
| 74 | |
| 53 // 1:1 relationship between initiator tab and print preview tab. | 75 // 1:1 relationship between initiator tab and print preview tab. |
| 54 // Key: Preview tab. | 76 // Key: Print preview tab. |
| 55 // Value: Initiator tab. | 77 // Value: Initiator tab. |
| 56 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; | 78 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; |
| 57 | 79 |
| 58 // Returns initiator tab for |preview_tab|. | 80 // Returns initiator tab for |preview_tab|. |
| 59 // Returns NULL if no initiator tab exists for |preview_tab|. | 81 // Returns NULL if no initiator tab exists for |preview_tab|. |
| 60 TabContents* GetInitiatorTab(TabContents* preview_tab); | 82 TabContents* GetInitiatorTab(TabContents* preview_tab); |
| 61 | 83 |
| 62 // Returns preview tab for |tab|. | 84 // Returns preview tab for |tab|. |
| 63 // Returns |tab| if |tab| is a preview tab. | 85 // Returns |tab| if |tab| is a preview tab. |
| 64 // Returns NULL if no preview tab exists for |tab|. | 86 // Returns NULL if no preview tab exists for |tab|. |
| 65 TabContents* GetPrintPreviewForTab(TabContents* tab); | 87 TabContents* GetPrintPreviewForTab(TabContents* tab); |
| 66 | 88 |
| 67 // Creates a new print preview tab. | 89 // Creates a new print preview tab. |
| 68 TabContents* CreatePrintPreviewTab( | 90 TabContents* CreatePrintPreviewTab( |
| 69 TabContents* initiator_tab, int browser_window_id); | 91 TabContents* initiator_tab, int browser_window_id); |
| 70 | 92 |
| 71 // Adds/Removes observers for notifications from |tab|. | 93 // Adds/Removes observers for notifications from |tab|. |
| 72 void AddObservers(TabContents* tab); | 94 void AddObservers(TabContents* tab); |
| 73 void RemoveObservers(TabContents* tab); | 95 void RemoveObservers(TabContents* tab); |
| 74 | 96 |
| 97 PrintPreviewDataMap preview_data_map_; | |
| 75 PrintPreviewTabMap preview_tab_map_; | 98 PrintPreviewTabMap preview_tab_map_; |
| 76 | 99 |
| 77 // A registrar for listening notifications. | 100 // A registrar for listening notifications. |
| 78 NotificationRegistrar registrar_; | 101 NotificationRegistrar registrar_; |
| 79 | 102 |
| 80 // True if the controller is waiting for a new preview tab via | 103 // True if the controller is waiting for a new preview tab via |
| 81 // NavigationType::NEW_PAGE. | 104 // NavigationType::NEW_PAGE. |
| 82 bool waiting_for_new_preview_page_; | 105 bool waiting_for_new_preview_page_; |
| 83 | 106 |
| 84 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); | 107 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); |
| 85 }; | 108 }; |
| 86 | 109 |
| 87 } // namespace printing | 110 } // namespace printing |
| 88 | 111 |
| 89 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | 112 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |
| OLD | NEW |