| Index: chrome/browser/printing/print_preview_manager.h
|
| ===================================================================
|
| --- chrome/browser/printing/print_preview_manager.h (revision 71344)
|
| +++ chrome/browser/printing/print_preview_manager.h (working copy)
|
| @@ -1,16 +1,26 @@
|
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2011 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.
|
|
|
| -// For print preview, a print preview (PP) tab is 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 is focused/activated. There may be more than one PP tab open. There is a
|
| -// 1:1 relationship between PP tabs and initiating tabs. This class manages PP
|
| -// tabs and initiator tabs.
|
| -#ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_
|
| +// The print preview manager manages print preview (PP) tabs, data used by PP
|
| +// tabs, and PP tabs' relationship to the tabs that initiated print preview.
|
| +// (initiator tabs)
|
| +//
|
| +// For print preview, there is a 1:1 relationship between an initiator tab and
|
| +// a PP tab. Any tab that is not a print preview tab can be an initiator tab.
|
| +// Thus it is possible to have multiple PP tabs, since there can be multiple
|
| +// initiator tab. Print preview tabs cannot be initiator tabs. Any attempts for
|
| +// PP tabs to initiate print preview will result in a no-op. If an initiator
|
| +// tab already created a PP tab, a second attempt to create a PP tab will
|
| +// instead focus/active the PP tab already associated with the initiator tab.
|
| +//
|
| +// The print preview manager also keeps track of the print preview data used by
|
| +// print preview tabs. When renderers generate print preview data, it notifies
|
| +// the browser, which stores the data here. When the print preview tab is ready
|
| +// to display the data, it retrieves the data from the print preview manager.
|
| +#ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MANAGER_H_
|
|
|
| -#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_
|
| +#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MANAGER_H_
|
| #pragma once
|
|
|
| #include <map>
|
| @@ -22,36 +32,58 @@
|
| class Browser;
|
| class TabContents;
|
|
|
| +namespace base {
|
| +class SharedMemory;
|
| +}
|
| +
|
| namespace printing {
|
|
|
| -class PrintPreviewTabController
|
| - : public base::RefCounted<PrintPreviewTabController>,
|
| +class PrintPreviewManager
|
| + : public base::RefCounted<PrintPreviewManager>,
|
| public NotificationObserver {
|
| public:
|
| - PrintPreviewTabController();
|
| + typedef std::pair<base::SharedMemory*, uint32> PrintPreviewData;
|
|
|
| - virtual ~PrintPreviewTabController();
|
| + PrintPreviewManager();
|
|
|
| - static PrintPreviewTabController* GetInstance();
|
| + virtual ~PrintPreviewManager();
|
|
|
| + static PrintPreviewManager* GetInstance();
|
| +
|
| + // Returns true if |tab| is a print preview tab.
|
| + static bool IsPrintPreviewTab(TabContents* tab);
|
| +
|
| // Get/Create the print preview tab for |initiator_tab|.
|
| // |browser_window_id| is the browser window containing |initiator_tab|.
|
| TabContents* GetOrCreatePreviewTab(
|
| TabContents* initiator_tab, int browser_window_id);
|
|
|
| + // Get the print preview |data| for |preview_tab|. The data is valid as long
|
| + // as |preview_tab| is valid and SetPrintPreviewData() does not get called.
|
| + bool GetPrintPreviewData(TabContents* preview_tab, PrintPreviewData* data);
|
| +
|
| + // Save the print preview |data| for |preview_tab|. PrintPreviewManager
|
| + // owns the data and is responsible for freeing it when either:
|
| + // a) there is new data.
|
| + // b) when |preview_tab| goes away.
|
| + bool SetPrintPreviewData(TabContents* preview_tab,
|
| + const PrintPreviewData& data);
|
| +
|
| // Notification observer implementation.
|
| virtual void Observe(NotificationType type,
|
| const NotificationSource& source,
|
| const NotificationDetails& details);
|
|
|
| - // Returns true if |tab| is a print preview tab.
|
| - static bool IsPrintPreviewTab(TabContents* tab);
|
| -
|
| private:
|
| - friend class base::RefCounted<PrintPreviewTabController>;
|
| + friend class base::RefCounted<PrintPreviewManager>;
|
|
|
| + // 1:1 relationship between print preview tab and its print preview data.
|
| + // Key: Print preview tab.
|
| + // Value: Print preview data.
|
| + typedef std::map<TabContents*, PrintPreviewData> PrintPreviewDataMap;
|
| +
|
| // 1:1 relationship between initiator tab and print preview tab.
|
| - // Key: Preview tab.
|
| + // Key: Print preview tab.
|
| // Value: Initiator tab.
|
| typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap;
|
|
|
| @@ -72,6 +104,7 @@
|
| void AddObservers(TabContents* tab);
|
| void RemoveObservers(TabContents* tab);
|
|
|
| + PrintPreviewDataMap preview_data_map_;
|
| PrintPreviewTabMap preview_tab_map_;
|
|
|
| // A registrar for listening notifications.
|
| @@ -81,9 +114,9 @@
|
| // NavigationType::NEW_PAGE.
|
| bool waiting_for_new_preview_page_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController);
|
| + DISALLOW_COPY_AND_ASSIGN(PrintPreviewManager);
|
| };
|
|
|
| } // namespace printing
|
|
|
| -#endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_
|
| +#endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MANAGER_H_
|
|
|