Index: chrome/browser/printing/print_preview_tab_controller.h |
diff --git a/chrome/browser/printing/print_preview_tab_controller.h b/chrome/browser/printing/print_preview_tab_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ea8ad77f30377af5cc1bd318e9ce1619f00937d7 |
--- /dev/null |
+++ b/chrome/browser/printing/print_preview_tab_controller.h |
@@ -0,0 +1,91 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |
+#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |
+#pragma once |
+ |
+#include <map> |
+ |
+#include "base/ref_counted.h" |
+#include "chrome/common/notification_observer.h" |
+#include "chrome/common/notification_registrar.h" |
+ |
+class Browser; |
+class TabContents; |
+ |
+namespace printing { |
+ |
+// For print preview, a print preview (PP) tab should be linked with the |
+// initiator tab that initiated the printing operation. If the tab initiates |
+// a second printing operation while the first print preview tab is still open, |
+// that PP tab should be focused/activated. There may be more than one PP tab |
+// open. There is 1:1 relationship between PP tabs and initiating tabs. This |
+// class manages PP tabs and initiator tabs. |
+class PrintPreviewTabController |
+ : public base::RefCounted<PrintPreviewTabController>, |
+ public NotificationObserver { |
+ public: |
+ static PrintPreviewTabController* GetInstance(); |
+ |
+ PrintPreviewTabController(); |
+ |
+ virtual ~PrintPreviewTabController(); |
+ |
+ // Get/Create the print preview tab for initiator_tab. |
+ // |browser_window_id| is used to identify |initiator_tab| browser window. |
+ TabContents* GetOrCreatePreviewTab( |
+ TabContents* initiator_tab, int browser_window_id); |
+ |
+ private: |
+ friend class base::RefCounted<PrintPreviewTabController>; |
+ |
+ // Returns true if |tab| is a print preview tab. |
+ bool IsPrintPreviewTab(TabContents* tab); |
+ |
+ // Return the browser window with |browser_window_id|. |
+ Browser* GetBrowserWindow(int browser_window_id); |
Lei Zhang
2010/11/12 23:17:18
This is a one line private method that's only call
kmadhusu
2010/11/13 00:05:59
Removed.
|
+ |
+ // Return the initiator tab for |preview_tab| or return NULL. |
+ TabContents* GetInitiatorTab(TabContents* preview_tab); |
+ |
+ // Return preview tab for |initiator_tab| or return NULL. |
+ TabContents* GetPreviewTab(TabContents* initiator_tab); |
+ |
+ // Create a new print preview tab. |
+ TabContents* CreatePrintPreviewTab( |
+ TabContents* initiator_tab, int browser_window_id); |
+ |
+ // Add |tab| notification(TAB_CONTENTS_DESTROYED & NAV_ENTRY_COMMITTED) |
Lei Zhang
2010/11/12 23:48:40
nit: Just combine the comments for Add and RemoveO
kmadhusu
2010/11/13 00:05:59
Done.
|
+ // observers. |
+ void AddObservers(TabContents* tab); |
+ |
+ // Remove |tab| notification(TAB_CONTENTS_DESTROYED & NAV_ENTRY_COMMITTED) |
+ // observers. |
+ void RemoveObservers(TabContents* tab); |
+ |
+ // Notification observer implementation. |
+ virtual void Observe(NotificationType type, |
Lei Zhang
2010/11/12 23:48:40
this needs to be public.
kmadhusu
2010/11/13 00:05:59
Done.
|
+ const NotificationSource& source, |
+ const NotificationDetails& details); |
+ |
+ // Erase the map entry for |initiator_tab|. |
+ void EraseMapEntry(TabContents* initiator_tab); |
Lei Zhang
2010/11/12 23:48:40
again, why have a private, one line method that's
kmadhusu
2010/11/13 00:05:59
Removed.
|
+ |
+ // 1:1 relationship between initiator tab and print preview tab. |
Lei Zhang
2010/11/12 23:17:18
You should state which type of tabs is the key and
kmadhusu
2010/11/13 00:05:59
Done.
|
+ typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap; |
+ PrintPreviewTabMap preview_tab_map_; |
+ |
+ // A registrar for listening for TAB_CONTENTS_DESTROYED notification. |
+ NotificationRegistrar registrar_; |
+ |
+ // Are we waiting for a new preview tab with NavigationType::NEW_PAGE? If so, |
+ // do nothing in observer. |
+ bool waiting_for_new_preview_page_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController); |
+}; |
+ |
+} // namespace printing |
+#endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_ |