Commit 1ab6de81 authored by thestig@chromium.org's avatar thestig@chromium.org

Cleanup: Remove more uses of deprecated PrintPreviewDialogController methods.

BUG=163671

Review URL: https://chromiumcodereview.appspot.com/12250008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182099 0039d316-1c4b-4281-b951-d872f2087c98
parent 0ca00fca
......@@ -215,52 +215,42 @@ PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() {
}
// static
void PrintPreviewDialogController::PrintPreview(WebContents* tab) {
if (tab->ShowingInterstitialPage())
void PrintPreviewDialogController::PrintPreview(WebContents* initiator_tab) {
if (initiator_tab->ShowingInterstitialPage())
return;
PrintPreviewDialogController* tab_controller = GetInstance();
if (!tab_controller)
PrintPreviewDialogController* dialog_controller = GetInstance();
if (!dialog_controller)
return;
if (!tab_controller->GetOrCreatePreviewTab(tab))
PrintViewManager::FromWebContents(tab)->PrintPreviewDone();
if (!dialog_controller->GetOrCreatePreviewDialog(initiator_tab))
PrintViewManager::FromWebContents(initiator_tab)->PrintPreviewDone();
}
WebContents* PrintPreviewDialogController::GetOrCreatePreviewDialog(
WebContents* initiator_tab) {
return GetOrCreatePreviewTab(initiator_tab);
}
WebContents* PrintPreviewDialogController::GetOrCreatePreviewTab(
WebContents* initiator_tab) {
DCHECK(initiator_tab);
// Get the print preview tab for |initiator_tab|.
WebContents* preview_tab = GetPrintPreviewForTab(initiator_tab);
if (!preview_tab)
// Get the print preview dialog for |initiator_tab|.
WebContents* preview_dialog = GetPrintPreviewForContents(initiator_tab);
if (!preview_dialog)
return CreatePrintPreviewTab(initiator_tab);
// Show the initiator tab holding the existing preview tab.
// Show the initiator tab holding the existing preview dialog.
initiator_tab->GetDelegate()->ActivateContents(initiator_tab);
return preview_tab;
return preview_dialog;
}
WebContents* PrintPreviewDialogController::GetPrintPreviewForContents(
WebContents* contents) const {
return GetPrintPreviewForTab(contents);
}
WebContents* PrintPreviewDialogController::GetPrintPreviewForTab(
WebContents* tab) const {
// |preview_tab_map_| is keyed by the preview tab, so if find() succeeds, then
// |tab| is the preview tab.
PrintPreviewTabMap::const_iterator it = preview_tab_map_.find(tab);
// |preview_tab_map_| is keyed by the preview dialog, so if find() succeeds,
// then |contents| is the preview dialog.
PrintPreviewTabMap::const_iterator it = preview_tab_map_.find(contents);
if (it != preview_tab_map_.end())
return tab;
return contents;
for (it = preview_tab_map_.begin(); it != preview_tab_map_.end(); ++it) {
// If |tab| is an initiator tab.
if (tab == it->second) {
// If |contents| is an initiator tab.
if (contents == it->second) {
// Return the associated preview tab.
return it->first;
}
......@@ -299,11 +289,6 @@ bool PrintPreviewDialogController::IsPrintPreviewDialog(WebContents* contents) {
return IsPrintPreviewURL(contents->GetURL());
}
// static
bool PrintPreviewDialogController::IsPrintPreviewTab(WebContents* tab) {
return IsPrintPreviewURL(tab->GetURL());
}
// static
bool PrintPreviewDialogController::IsPrintPreviewURL(const GURL& url) {
return (url.SchemeIs(chrome::kChromeUIScheme) &&
......@@ -357,7 +342,7 @@ void PrintPreviewDialogController::OnRendererProcessClosed(
}
void PrintPreviewDialogController::OnWebContentsDestroyed(WebContents* tab) {
WebContents* preview_tab = GetPrintPreviewForTab(tab);
WebContents* preview_tab = GetPrintPreviewForContents(tab);
if (!preview_tab) {
NOTREACHED();
return;
......@@ -371,7 +356,7 @@ void PrintPreviewDialogController::OnWebContentsDestroyed(WebContents* tab) {
void PrintPreviewDialogController::OnNavEntryCommitted(
WebContents* tab, content::LoadCommittedDetails* details) {
WebContents* preview_tab = GetPrintPreviewForTab(tab);
WebContents* preview_tab = GetPrintPreviewForContents(tab);
if (!preview_tab) {
NOTREACHED();
return;
......@@ -499,7 +484,7 @@ void PrintPreviewDialogController::RemoveObservers(WebContents* tab) {
void PrintPreviewDialogController::RemoveInitiatorTab(
WebContents* initiator_tab) {
WebContents* preview_tab = GetPrintPreviewForTab(initiator_tab);
WebContents* preview_tab = GetPrintPreviewForContents(initiator_tab);
DCHECK(preview_tab);
// Update the map entry first, so when the print preview tab gets destroyed
// and reaches RemovePreviewTab(), it does not attempt to also remove the
......
......@@ -52,21 +52,12 @@ class PrintPreviewDialogController
content::WebContents* GetOrCreatePreviewDialog(
content::WebContents* initiator_tab);
// DEPRECATED. Use GetOrCreatePreviewDialog() instead.
// TODO(thestig) Remove.
content::WebContents* GetOrCreatePreviewTab(
content::WebContents* initiator_tab);
// Returns the preview dialog for |contents|.
// Returns |contents| if |contents| is a preview dialog.
// Returns NULL if no preview dialog exists for |contents|.
content::WebContents* GetPrintPreviewForContents(
content::WebContents* contents) const;
// DEPRECATED. Use GetPrintPreviewForContents() instead.
// TODO(thestig) Remove.
content::WebContents* GetPrintPreviewForTab(content::WebContents* tab) const;
// Returns initiator tab for |preview_tab|.
// Returns NULL if no initiator tab exists for |preview_tab|.
content::WebContents* GetInitiatorTab(content::WebContents* preview_tab);
......@@ -79,10 +70,6 @@ class PrintPreviewDialogController
// Returns true if |contents| is a print preview dialog.
static bool IsPrintPreviewDialog(content::WebContents* contents);
// DEPRECATED. Use IsPrintPreviewDialog() instead.
// TODO(thestig) Remove.
static bool IsPrintPreviewTab(content::WebContents* tab);
// Returns true if |url| is a print preview url.
static bool IsPrintPreviewURL(const GURL& url);
......
......@@ -31,22 +31,23 @@ class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest {
}
};
class TabDestroyedObserver : public content::WebContentsObserver {
class PrintPreviewDialogDestroyedObserver
: public content::WebContentsObserver {
public:
explicit TabDestroyedObserver(WebContents* contents)
: content::WebContentsObserver(contents),
tab_destroyed_(false) {
explicit PrintPreviewDialogDestroyedObserver(WebContents* dialog)
: content::WebContentsObserver(dialog),
dialog_destroyed_(false) {
}
virtual ~TabDestroyedObserver() {}
virtual ~PrintPreviewDialogDestroyedObserver() {}
bool tab_destroyed() { return tab_destroyed_; }
bool dialog_destroyed() { return dialog_destroyed_; }
private:
virtual void WebContentsDestroyed(WebContents* tab) OVERRIDE {
tab_destroyed_ = true;
virtual void WebContentsDestroyed(WebContents* contents) OVERRIDE {
dialog_destroyed_ = true;
}
bool tab_destroyed_;
bool dialog_destroyed_;
};
// Test to verify that when a initiator tab navigates, we can create a new
......@@ -61,33 +62,33 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(initiator_tab);
printing::PrintPreviewDialogController* tab_controller =
printing::PrintPreviewDialogController* dialog_controller =
printing::PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(tab_controller);
ASSERT_TRUE(dialog_controller);
// Get the preview tab for initiator tab.
printing::PrintViewManager* print_view_manager =
printing::PrintViewManager::FromWebContents(initiator_tab);
print_view_manager->PrintPreviewNow(false);
WebContents* preview_tab =
tab_controller->GetOrCreatePreviewTab(initiator_tab);
dialog_controller->GetOrCreatePreviewDialog(initiator_tab);
// New print preview tab is created.
EXPECT_EQ(1, browser()->tab_strip_model()->count());
ASSERT_TRUE(preview_tab);
ASSERT_NE(initiator_tab, preview_tab);
TabDestroyedObserver observer(preview_tab);
PrintPreviewDialogDestroyedObserver observer(preview_tab);
// Navigate in the initiator tab.
GURL url(chrome::kChromeUINewTabURL);
ui_test_utils::NavigateToURL(browser(), url);
ASSERT_TRUE(observer.tab_destroyed());
ASSERT_TRUE(observer.dialog_destroyed());
// Get the print preview tab for initiator tab.
print_view_manager->PrintPreviewNow(false);
WebContents* new_preview_tab =
tab_controller->GetOrCreatePreviewTab(initiator_tab);
dialog_controller->GetOrCreatePreviewDialog(initiator_tab);
// New preview tab is created.
EXPECT_EQ(1, browser()->tab_strip_model()->count());
......@@ -106,22 +107,22 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(initiator_tab);
printing::PrintPreviewDialogController* tab_controller =
printing::PrintPreviewDialogController* dialog_controller =
printing::PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(tab_controller);
ASSERT_TRUE(dialog_controller);
// Get the preview tab for initiator tab.
printing::PrintViewManager* print_view_manager =
printing::PrintViewManager::FromWebContents(initiator_tab);
print_view_manager->PrintPreviewNow(false);
WebContents* preview_tab =
tab_controller->GetOrCreatePreviewTab(initiator_tab);
dialog_controller->GetOrCreatePreviewDialog(initiator_tab);
// New print preview tab is created.
EXPECT_EQ(1, browser()->tab_strip_model()->count());
ASSERT_TRUE(preview_tab);
ASSERT_NE(initiator_tab, preview_tab);
TabDestroyedObserver tab_destroyed_observer(preview_tab);
PrintPreviewDialogDestroyedObserver dialog_destroyed_observer(preview_tab);
// Reload the initiator tab.
content::WindowedNotificationObserver notification_observer(
......@@ -130,12 +131,12 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
chrome::Reload(browser(), CURRENT_TAB);
notification_observer.Wait();
ASSERT_TRUE(tab_destroyed_observer.tab_destroyed());
ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed());
// Get the print preview tab for initiator tab.
print_view_manager->PrintPreviewNow(false);
WebContents* new_preview_tab =
tab_controller->GetOrCreatePreviewTab(initiator_tab);
dialog_controller->GetOrCreatePreviewDialog(initiator_tab);
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_TRUE(new_preview_tab);
......
......@@ -73,20 +73,19 @@ PrintPreviewMessageHandler::PrintPreviewMessageHandler(
PrintPreviewMessageHandler::~PrintPreviewMessageHandler() {
}
WebContents* PrintPreviewMessageHandler::GetPrintPreviewTab() {
PrintPreviewDialogController* tab_controller =
WebContents* PrintPreviewMessageHandler::GetPrintPreviewDialog() {
PrintPreviewDialogController* dialog_controller =
PrintPreviewDialogController::GetInstance();
if (!tab_controller)
if (!dialog_controller)
return NULL;
return tab_controller->GetPrintPreviewForTab(web_contents());
return dialog_controller->GetPrintPreviewForContents(web_contents());
}
PrintPreviewUI* PrintPreviewMessageHandler::GetPrintPreviewUI() {
WebContents* tab = GetPrintPreviewTab();
if (!tab || !tab->GetWebUI())
WebContents* dialog = GetPrintPreviewDialog();
if (!dialog || !dialog->GetWebUI())
return NULL;
return static_cast<PrintPreviewUI*>(tab->GetWebUI()->GetController());
return static_cast<PrintPreviewUI*>(dialog->GetWebUI()->GetController());
}
void PrintPreviewMessageHandler::OnRequestPrintPreview(
......@@ -96,7 +95,7 @@ void PrintPreviewMessageHandler::OnRequestPrintPreview(
PrintPreviewForWebNode();
}
PrintPreviewDialogController::PrintPreview(web_contents());
PrintPreviewUI::SetInitialParams(GetPrintPreviewTab(), params);
PrintPreviewUI::SetInitialParams(GetPrintPreviewDialog(), params);
}
void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(
......
......@@ -41,8 +41,9 @@ class PrintPreviewMessageHandler
explicit PrintPreviewMessageHandler(content::WebContents* web_contents);
friend class content::WebContentsUserData<PrintPreviewMessageHandler>;
// Gets the print preview tab associated with the WebContents being observed.
content::WebContents* GetPrintPreviewTab();
// Gets the print preview dialog associated with the WebContents being
// observed.
content::WebContents* GetPrintPreviewDialog();
// Gets the PrintPreviewUI associated with the WebContents being observed.
PrintPreviewUI* GetPrintPreviewUI();
......
......@@ -472,7 +472,8 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) {
web_ui()->GetController());
print_preview_ui->OnHidePreviewDialog();
// Do this so the initiator tab can open a new print preview dialog.
// Do this so the initiator tab can open a new print preview dialog, while
// the current print preview dialog is still handling its print job.
ClearInitiatorTabDetails();
// The PDF being printed contains only the pages that the user selected,
......
......@@ -28,21 +28,21 @@ void TestTabStripModelObserver::TabBlockedStateChanged(
// Need to do this later - the print preview dialog has not been created yet.
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&TestTabStripModelObserver::ObservePrintPreviewTabContents,
base::Bind(&TestTabStripModelObserver::ObservePrintPreviewDialog,
base::Unretained(this),
contents));
}
void TestTabStripModelObserver::ObservePrintPreviewTabContents(
void TestTabStripModelObserver::ObservePrintPreviewDialog(
content::WebContents* contents) {
printing::PrintPreviewDialogController* tab_controller =
printing::PrintPreviewDialogController* dialog_controller =
printing::PrintPreviewDialogController::GetInstance();
if (tab_controller) {
content::WebContents* preview_tab =
tab_controller->GetPrintPreviewForTab(contents);
if (preview_tab) {
if (!dialog_controller)
return;
content::WebContents* preview_dialog =
dialog_controller->GetPrintPreviewForContents(contents);
if (!preview_dialog)
return;
RegisterAsObserver(content::Source<content::NavigationController>(
&preview_tab->GetController()));
}
}
&preview_dialog->GetController()));
}
......@@ -30,7 +30,7 @@ class TestTabStripModelObserver : public content::TestNavigationObserver,
private:
// Callback to observer the print preview dialog associated with |contents|.
void ObservePrintPreviewTabContents(content::WebContents* contents);
void ObservePrintPreviewDialog(content::WebContents* contents);
// TabStripModelObserver:
virtual void TabBlockedStateChanged(content::WebContents* contents,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment