| 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 // The print preview manager manages print preview (PP) tabs, data used by PP |
| 6 // that initiated the printing operation. If the tab initiates a second | 6 // tabs, and PP tabs' relationship to the tabs that initiated print preview. |
| 7 // printing operation while the first print preview tab is still open, that PP | 7 // (initiator tabs) |
| 8 // tab is focused/activated. There may be more than one PP tab open. There is a | 8 // |
| 9 // 1:1 relationship between PP tabs and initiating tabs. This class manages PP | 9 // For print preview, there is a 1:1 relationship between an initiator tab and |
| 10 // tabs and initiator tabs. | 10 // a PP tab. Any tab that is not a print preview tab can be an initiator tab. |
| 11 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | 11 // Thus it is possible to have multiple PP tabs, since there can be multiple |
| 12 // initiator tab. Print preview tabs cannot be initiator tabs. Any attempts for |
| 13 // PP tabs to initiate print preview will result in a no-op. If an initiator |
| 14 // tab already created a PP tab, a second attempt to create a PP tab will |
| 15 // instead focus/active the PP tab already associated with the initiator tab. |
| 16 // |
| 17 // The print preview manager also keeps track of the print preview data used by |
| 18 // print preview tabs. When renderers generate print preview data, it notifies |
| 19 // the browser, which stores the data here. When the print preview tab is ready |
| 20 // to display the data, it retrieves the data from the print preview manager. |
| 21 #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MANAGER_H_ |
| 12 | 22 |
| 13 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | 23 #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MANAGER_H_ |
| 14 #pragma once | 24 #pragma once |
| 15 | 25 |
| 16 #include <map> | 26 #include <map> |
| 17 | 27 |
| 18 #include "base/ref_counted.h" | 28 #include "base/ref_counted.h" |
| 19 #include "chrome/common/notification_observer.h" | 29 #include "chrome/common/notification_observer.h" |
| 20 #include "chrome/common/notification_registrar.h" | 30 #include "chrome/common/notification_registrar.h" |
| 21 | 31 |
| 22 class Browser; | 32 class Browser; |
| 23 class TabContents; | 33 class TabContents; |
| 24 | 34 |
| 35 namespace base { |
| 36 class SharedMemory; |
| 37 } |
| 38 |
| 25 namespace printing { | 39 namespace printing { |
| 26 | 40 |
| 27 class PrintPreviewTabController | 41 class PrintPreviewManager |
| 28 : public base::RefCounted<PrintPreviewTabController>, | 42 : public base::RefCounted<PrintPreviewManager>, |
| 29 public NotificationObserver { | 43 public NotificationObserver { |
| 30 public: | 44 public: |
| 31 PrintPreviewTabController(); | 45 typedef std::pair<base::SharedMemory*, uint32> PrintPreviewData; |
| 32 | 46 |
| 33 virtual ~PrintPreviewTabController(); | 47 PrintPreviewManager(); |
| 34 | 48 |
| 35 static PrintPreviewTabController* GetInstance(); | 49 virtual ~PrintPreviewManager(); |
| 50 |
| 51 static PrintPreviewManager* GetInstance(); |
| 52 |
| 53 // Returns true if |tab| is a print preview tab. |
| 54 static bool IsPrintPreviewTab(TabContents* tab); |
| 36 | 55 |
| 37 // Get/Create the print preview tab for |initiator_tab|. | 56 // Get/Create the print preview tab for |initiator_tab|. |
| 38 // |browser_window_id| is the browser window containing |initiator_tab|. | 57 // |browser_window_id| is the browser window containing |initiator_tab|. |
| 39 TabContents* GetOrCreatePreviewTab( | 58 TabContents* GetOrCreatePreviewTab( |
| 40 TabContents* initiator_tab, int browser_window_id); | 59 TabContents* initiator_tab, int browser_window_id); |
| 41 | 60 |
| 61 // Get the print preview |data| for |preview_tab|. The data is valid as long |
| 62 // as |preview_tab| is valid and SetPrintPreviewData() does not get called. |
| 63 bool GetPrintPreviewData(TabContents* preview_tab, PrintPreviewData* data); |
| 64 |
| 65 // Save the print preview |data| for |preview_tab|. PrintPreviewManager |
| 66 // owns the data and is responsible for freeing it when either: |
| 67 // a) there is new data. |
| 68 // b) when |preview_tab| goes away. |
| 69 bool SetPrintPreviewData(TabContents* preview_tab, |
| 70 const PrintPreviewData& data); |
| 71 |
| 42 // Notification observer implementation. | 72 // Notification observer implementation. |
| 43 virtual void Observe(NotificationType type, | 73 virtual void Observe(NotificationType type, |
| 44 const NotificationSource& source, | 74 const NotificationSource& source, |
| 45 const NotificationDetails& details); | 75 const NotificationDetails& details); |
| 46 | 76 |
| 47 // Returns true if |tab| is a print preview tab. | 77 private: |
| 48 static bool IsPrintPreviewTab(TabContents* tab); | 78 friend class base::RefCounted<PrintPreviewManager>; |
| 49 | 79 |
| 50 private: | 80 // 1:1 relationship between print preview tab and its print preview data. |
| 51 friend class base::RefCounted<PrintPreviewTabController>; | 81 // Key: Print preview tab. |
| 82 // Value: Print preview data. |
| 83 typedef std::map<TabContents*, PrintPreviewData> PrintPreviewDataMap; |
| 52 | 84 |
| 53 // 1:1 relationship between initiator tab and print preview tab. | 85 // 1:1 relationship between initiator tab and print preview tab. |
| 54 // Key: Preview tab. | 86 // Key: Print preview tab. |
| 55 // Value: Initiator tab. | 87 // Value: Initiator tab. |
| 56 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; | 88 typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; |
| 57 | 89 |
| 58 // Returns initiator tab for |preview_tab|. | 90 // Returns initiator tab for |preview_tab|. |
| 59 // Returns NULL if no initiator tab exists for |preview_tab|. | 91 // Returns NULL if no initiator tab exists for |preview_tab|. |
| 60 TabContents* GetInitiatorTab(TabContents* preview_tab); | 92 TabContents* GetInitiatorTab(TabContents* preview_tab); |
| 61 | 93 |
| 62 // Returns preview tab for |tab|. | 94 // Returns preview tab for |tab|. |
| 63 // Returns |tab| if |tab| is a preview tab. | 95 // Returns |tab| if |tab| is a preview tab. |
| 64 // Returns NULL if no preview tab exists for |tab|. | 96 // Returns NULL if no preview tab exists for |tab|. |
| 65 TabContents* GetPrintPreviewForTab(TabContents* tab); | 97 TabContents* GetPrintPreviewForTab(TabContents* tab); |
| 66 | 98 |
| 67 // Creates a new print preview tab. | 99 // Creates a new print preview tab. |
| 68 TabContents* CreatePrintPreviewTab( | 100 TabContents* CreatePrintPreviewTab( |
| 69 TabContents* initiator_tab, int browser_window_id); | 101 TabContents* initiator_tab, int browser_window_id); |
| 70 | 102 |
| 71 // Adds/Removes observers for notifications from |tab|. | 103 // Adds/Removes observers for notifications from |tab|. |
| 72 void AddObservers(TabContents* tab); | 104 void AddObservers(TabContents* tab); |
| 73 void RemoveObservers(TabContents* tab); | 105 void RemoveObservers(TabContents* tab); |
| 74 | 106 |
| 107 PrintPreviewDataMap preview_data_map_; |
| 75 PrintPreviewTabMap preview_tab_map_; | 108 PrintPreviewTabMap preview_tab_map_; |
| 76 | 109 |
| 77 // A registrar for listening notifications. | 110 // A registrar for listening notifications. |
| 78 NotificationRegistrar registrar_; | 111 NotificationRegistrar registrar_; |
| 79 | 112 |
| 80 // True if the controller is waiting for a new preview tab via | 113 // True if the controller is waiting for a new preview tab via |
| 81 // NavigationType::NEW_PAGE. | 114 // NavigationType::NEW_PAGE. |
| 82 bool waiting_for_new_preview_page_; | 115 bool waiting_for_new_preview_page_; |
| 83 | 116 |
| 84 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); | 117 DISALLOW_COPY_AND_ASSIGN(PrintPreviewManager); |
| 85 }; | 118 }; |
| 86 | 119 |
| 87 } // namespace printing | 120 } // namespace printing |
| 88 | 121 |
| 89 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ | 122 #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MANAGER_H_ |
| OLD | NEW |