diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 09:12:03 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 09:12:03 +0000 |
commit | c2e71d2e86657cad334fb2d778c3756878d1359b (patch) | |
tree | eb1e22e064c20618780a6afedbe333d52862a724 /chrome/browser/ui/webui | |
parent | 29cd97871e733952ab4e05b5d9d7ea79d3a339d9 (diff) | |
download | chromium_src-c2e71d2e86657cad334fb2d778c3756878d1359b.zip chromium_src-c2e71d2e86657cad334fb2d778c3756878d1359b.tar.gz chromium_src-c2e71d2e86657cad334fb2d778c3756878d1359b.tar.bz2 |
Revert 110056 - Print Preview: Make print preview tab modal.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8136027
TBR=thestig@chromium.org
Review URL: http://codereview.chromium.org/8564044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui')
-rw-r--r-- | chrome/browser/ui/webui/cloud_print_signin_dialog.cc | 8 | ||||
-rw-r--r-- | chrome/browser/ui/webui/constrained_html_ui.h | 3 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_data_source.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_handler.cc | 71 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_handler.h | 15 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_handler_unittest.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_ui.cc | 63 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_ui.h | 23 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_ui_uitest.cc | 72 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_ui_unittest.cc | 15 | ||||
-rw-r--r-- | chrome/browser/ui/webui/web_ui_browsertest.cc | 8 |
11 files changed, 159 insertions, 134 deletions
diff --git a/chrome/browser/ui/webui/cloud_print_signin_dialog.cc b/chrome/browser/ui/webui/cloud_print_signin_dialog.cc index c163447..20f3bfc 100644 --- a/chrome/browser/ui/webui/cloud_print_signin_dialog.cc +++ b/chrome/browser/ui/webui/cloud_print_signin_dialog.cc @@ -4,9 +4,6 @@ #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h" -#include <string> -#include <vector> - #include "base/bind.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/cloud_print/cloud_print_url.h" @@ -14,7 +11,6 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/webui/html_dialog_ui.h" -#include "chrome/browser/ui/webui/print_preview_ui.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" @@ -83,8 +79,7 @@ void CloudPrintSigninFlowHandler::Observe( url.scheme() == dialog_url.scheme()) { StoreDialogSize(); web_ui_->tab_contents()->render_view_host()->ClosePage(); - static_cast<PrintPreviewUI*>( - parent_tab_->web_ui())->OnReloadPrintersList(); + parent_tab_->controller().Reload(false); } } } @@ -192,3 +187,4 @@ void CreateCloudPrintSigninDialog(TabContents* parent_tab) { base::Bind(&CreateCloudPrintSigninDialogImpl, parent_tab)); } } // namespace cloud_print_signin_dialog + diff --git a/chrome/browser/ui/webui/constrained_html_ui.h b/chrome/browser/ui/webui/constrained_html_ui.h index 03d2022..fd8f276 100644 --- a/chrome/browser/ui/webui/constrained_html_ui.h +++ b/chrome/browser/ui/webui/constrained_html_ui.h @@ -65,12 +65,11 @@ class ConstrainedHtmlUI : public ChromeWebUI { static PropertyAccessor<ConstrainedHtmlUIDelegate*>& GetPropertyAccessor(); - protected: + private: // Returns the TabContents' PropertyBag's ConstrainedHtmlUIDelegate. // Returns NULL if that property is not set. ConstrainedHtmlUIDelegate* GetConstrainedDelegate(); - private: // JS Message Handler void OnDialogCloseMessage(const base::ListValue* args); diff --git a/chrome/browser/ui/webui/print_preview_data_source.cc b/chrome/browser/ui/webui/print_preview_data_source.cc index b3a45d6..3621859 100644 --- a/chrome/browser/ui/webui/print_preview_data_source.cc +++ b/chrome/browser/ui/webui/print_preview_data_source.cc @@ -51,6 +51,12 @@ PrintPreviewDataSource::PrintPreviewDataSource() AddLocalizedString("previewFailed", IDS_PRINT_PREVIEW_FAILED); AddLocalizedString("invalidPrinterSettings", IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS); + AddLocalizedString("initiatorTabCrashed", + IDS_PRINT_PREVIEW_INITIATOR_TAB_CRASHED); + AddLocalizedString("initiatorTabClosed", + IDS_PRINT_PREVIEW_INITIATOR_TAB_CLOSED); + AddLocalizedString("reopenPage", IDS_PRINT_PREVIEW_REOPEN_PAGE); + AddLocalizedString("printButton", IDS_PRINT_PREVIEW_PRINT_BUTTON); AddLocalizedString("cancelButton", IDS_PRINT_PREVIEW_CANCEL_BUTTON); AddLocalizedString("printing", IDS_PRINT_PREVIEW_PRINTING); diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc index f3fb0df..5bf6e85 100644 --- a/chrome/browser/ui/webui/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview_handler.cc @@ -25,6 +25,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/printing/background_printing_manager.h" #include "chrome/browser/printing/cloud_print/cloud_print_url.h" #include "chrome/browser/printing/print_dialog_cloud.h" #include "chrome/browser/printing/print_job_manager.h" @@ -33,6 +34,8 @@ #include "chrome/browser/printing/print_view_manager.h" #include "chrome/browser/printing/printer_manager_dialog.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sessions/restore_tab_helper.h" +#include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h" @@ -67,7 +70,7 @@ enum UserActionBuckets { FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, PREVIEW_FAILED, PREVIEW_STARTED, - INITIATOR_TAB_CRASHED, // UNUSED + INITIATOR_TAB_CRASHED, INITIATOR_TAB_CLOSED, PRINT_WITH_CLOUD_PRINT, USERACTION_BUCKET_BOUNDARY @@ -173,6 +176,10 @@ void ReportPrintSettingsStats(const DictionaryValue& settings) { } } +printing::BackgroundPrintingManager* GetBackgroundPrintingManager() { + return g_browser_process->background_printing_manager(); +} + } // namespace // A Task implementation that stores a PDF file on disk. @@ -253,6 +260,9 @@ void PrintPreviewHandler::RegisterMessages() { web_ui_->RegisterMessageCallback("manageLocalPrinters", base::Bind(&PrintPreviewHandler::HandleManagePrinters, base::Unretained(this))); + web_ui_->RegisterMessageCallback("reloadCrashedInitiatorTab", + base::Bind(&PrintPreviewHandler::HandleReloadCrashedInitiatorTab, + base::Unretained(this))); web_ui_->RegisterMessageCallback("closePrintPreviewTab", base::Bind(&PrintPreviewHandler::HandleClosePreviewTab, base::Unretained(this))); @@ -312,7 +322,7 @@ void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { TabContentsWrapper* initiator_tab = GetInitiatorTab(); if (!initiator_tab) { ReportUserActionHistogram(INITIATOR_TAB_CLOSED); - print_preview_ui->OnClosePrintPreviewTab(); + print_preview_ui->OnInitiatorTabClosed(); return; } @@ -422,8 +432,7 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { // This tries to activate the initiator tab as well, so do not clear the // association with the initiator tab yet. - PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); - print_preview_ui->OnHidePreviewTab(); + HidePreviewTab(); // Do this so the initiator tab can open a new print preview tab. ClearInitiatorTabDetails(); @@ -467,8 +476,7 @@ void PrintPreviewHandler::HandlePrintToPdf( } void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { - PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); - print_preview_ui->OnHidePreviewTab(); + HidePreviewTab(); } void PrintPreviewHandler::HandleCancelPendingPrintRequest( @@ -579,6 +587,21 @@ void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { printing::PrinterManagerDialog::ShowPrinterManagerDialog(); } +void PrintPreviewHandler::HandleReloadCrashedInitiatorTab( + const ListValue* /*args*/) { + ReportStats(); + ReportUserActionHistogram(INITIATOR_TAB_CRASHED); + + TabContentsWrapper* initiator_tab = GetInitiatorTab(); + if (!initiator_tab) + return; + + TabContents* contents = initiator_tab->tab_contents(); + contents->OpenURL(contents->GetURL(), GURL(), CURRENT_TAB, + content::PAGE_TRANSITION_RELOAD); + ActivateInitiatorTabAndClosePreviewTab(); +} + void PrintPreviewHandler::HandleClosePreviewTab(const ListValue* /*args*/) { ReportStats(); ReportUserActionHistogram(CANCEL); @@ -587,6 +610,8 @@ void PrintPreviewHandler::HandleClosePreviewTab(const ListValue* /*args*/) { // before cancelling. UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforeCancel", regenerate_preview_request_count_); + + ActivateInitiatorTabAndClosePreviewTab(); } void PrintPreviewHandler::ReportStats() { @@ -663,8 +688,7 @@ void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { static_cast<RenderViewHostDelegate*>( initiator_tab->tab_contents())->Activate(); } - PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); - print_preview_ui->OnClosePrintPreviewTab(); + ClosePrintPreviewTab(); } void PrintPreviewHandler::SendPrinterCapabilities( @@ -703,7 +727,7 @@ void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); std::string printer_id; settings.GetString(printing::kSettingCloudPrintId, &printer_id); - // BASE64 encode the job data. +// BASE64 encode the job data. std::string raw_data(reinterpret_cast<const char*>(data->front()), data->size()); std::string base64_data; @@ -725,8 +749,8 @@ void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, "data:application/pdf;base64,%s\r\n" "--%s\r\n"; - // TODO(abodenha@chromium.org) This implies a large copy operation. - // Profile this and optimize if necessary. +// TODO(abodenha@chromium.org) This implies a large copy operation. +// Profile this and optimize if necessary. std::string final_data; base::SStringPrintf(&final_data, prolog, @@ -755,6 +779,25 @@ TabContentsWrapper* PrintPreviewHandler::GetInitiatorTab() const { return tab_controller->GetInitiatorTab(preview_tab_wrapper()); } +void PrintPreviewHandler::ClosePrintPreviewTab() { + TabContentsWrapper* tab = + TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); + if (!tab) + return; + Browser* preview_tab_browser = BrowserList::FindBrowserWithID( + tab->restore_tab_helper()->window_id().id()); + if (!preview_tab_browser) + return; + TabStripModel* tabstrip = preview_tab_browser->tabstrip_model(); + int index = tabstrip->GetIndexOfTabContents(tab); + if (index == TabStripModel::kNoTab) + return; + + // Keep print preview tab out of the recently closed tab list, because + // re-opening that page will just display a non-functional print preview page. + tabstrip->CloseTabContentsAt(index, TabStripModel::CLOSE_NONE); +} + void PrintPreviewHandler::OnPrintDialogShown() { ActivateInitiatorTabAndClosePreviewTab(); } @@ -843,6 +886,12 @@ void PrintPreviewHandler::FileSelectionCanceled(void* params) { print_preview_ui->OnFileSelectionCancelled(); } +void PrintPreviewHandler::HidePreviewTab() { + if (GetBackgroundPrintingManager()->HasPrintPreviewTab(preview_tab_wrapper())) + return; + GetBackgroundPrintingManager()->OwnPrintPreviewTab(preview_tab_wrapper()); +} + void PrintPreviewHandler::ClearInitiatorTabDetails() { TabContentsWrapper* initiator_tab = GetInitiatorTab(); if (!initiator_tab) diff --git a/chrome/browser/ui/webui/print_preview_handler.h b/chrome/browser/ui/webui/print_preview_handler.h index 8d0315c..20ea1c7 100644 --- a/chrome/browser/ui/webui/print_preview_handler.h +++ b/chrome/browser/ui/webui/print_preview_handler.h @@ -124,9 +124,9 @@ class PrintPreviewHandler : public WebUIMessageHandler, // |args| is unused. void HandleManageCloudPrint(const base::ListValue* args); - // Gathers UMA stats when the print preview tab is about to close. - // |args| is unused. - void HandleClosePreviewTab(const base::ListValue* args); + // Reloads the initiator tab and closes the associated preview tab. |args| is + // unused. + void HandleReloadCrashedInitiatorTab(const base::ListValue* args); // Asks the browser to show the native printer management dialog. // |args| is unused. @@ -135,6 +135,9 @@ class PrintPreviewHandler : public WebUIMessageHandler, // Asks the browser to show the cloud print dialog. void HandlePrintWithCloudPrint(); + // Asks the browser to close the preview tab. |args| is unused. + void HandleClosePreviewTab(const base::ListValue* args); + // Asks the browser for several settings that are needed before the first // preview is displayed. void HandleGetInitialSettings(const base::ListValue* args); @@ -160,12 +163,18 @@ class PrintPreviewHandler : public WebUIMessageHandler, // Gets the initiator tab for the print preview tab. TabContentsWrapper* GetInitiatorTab() const; + // Closes the print preview tab. + void ClosePrintPreviewTab(); + // Activates the initiator tab and close the preview tab. void ActivateInitiatorTabAndClosePreviewTab(); // Adds all the recorded stats taken so far to histogram counts. void ReportStats(); + // Hides the preview tab for printing. + void HidePreviewTab(); + // Clears initiator tab details for this preview tab. void ClearInitiatorTabDetails(); diff --git a/chrome/browser/ui/webui/print_preview_handler_unittest.cc b/chrome/browser/ui/webui/print_preview_handler_unittest.cc index 3d7fdb3..d44ce53 100644 --- a/chrome/browser/ui/webui/print_preview_handler_unittest.cc +++ b/chrome/browser/ui/webui/print_preview_handler_unittest.cc @@ -21,7 +21,7 @@ namespace { DictionaryValue* GetCustomMarginsDictionary( const double margin_top, const double margin_right, - const double margin_bottom, const double margin_left) { + const double margin_bottom,const double margin_left) { base::DictionaryValue* custom_settings = new base::DictionaryValue(); custom_settings->SetDouble(printing::kSettingMarginTop, margin_top); custom_settings->SetDouble(printing::kSettingMarginRight, margin_right); @@ -30,7 +30,7 @@ DictionaryValue* GetCustomMarginsDictionary( return custom_settings; } -} // namespace +} class PrintPreviewHandlerTest : public BrowserWithTestWindowTest { protected: @@ -65,6 +65,7 @@ class PrintPreviewHandlerTest : public BrowserWithTestWindowTest { preview_tab_ = controller->GetOrCreatePreviewTab(initiator_tab); ASSERT_TRUE(preview_tab_); + EXPECT_EQ(2, browser()->tab_count()); preview_ui_ = static_cast<PrintPreviewUI*>(preview_tab_->web_ui()); ASSERT_TRUE(preview_ui_); @@ -113,7 +114,7 @@ class PrintPreviewHandlerTest : public BrowserWithTestWindowTest { void RequestPrintWithCustomMargins( const double margin_top, const double margin_right, - const double margin_bottom, const double margin_left) { + const double margin_bottom,const double margin_left) { // Set the minimal dummy settings to make the HandlePrint() code happy. DictionaryValue settings; settings.SetBoolean(printing::kSettingPreviewModifiable, true); @@ -145,6 +146,7 @@ class PrintPreviewHandlerTest : public BrowserWithTestWindowTest { delete PrintPreviewHandler::last_used_page_size_margins_; PrintPreviewHandler::last_used_page_size_margins_ = NULL; } + }; // Tests that margin settings are saved correctly when printing with custom @@ -196,6 +198,7 @@ TEST_F(PrintPreviewHandlerTest, StickyMarginsCustomThenDefault) { CheckCustomMargins(kMarginTop, kMarginRight, kMarginBottom, kMarginLeft); OpenPrintPreviewTab(); + EXPECT_EQ(2, browser()->tab_count()); RequestPrintWithDefaultMargins(); // Checking that sticky settings were saved correctly. diff --git a/chrome/browser/ui/webui/print_preview_ui.cc b/chrome/browser/ui/webui/print_preview_ui.cc index 0faac66..fc7684e4 100644 --- a/chrome/browser/ui/webui/print_preview_ui.cc +++ b/chrome/browser/ui/webui/print_preview_ui.cc @@ -11,12 +11,8 @@ #include "base/string_util.h" #include "base/synchronization/lock.h" #include "base/values.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/printing/background_printing_manager.h" #include "chrome/browser/printing/print_preview_data_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/browser/ui/webui/html_dialog_ui.h" #include "chrome/browser/ui/webui/print_preview_data_source.h" #include "chrome/browser/ui/webui/print_preview_handler.h" #include "chrome/common/print_messages.h" @@ -71,9 +67,8 @@ base::LazyInstance<PrintPreviewRequestIdMapWithLock> } // namespace PrintPreviewUI::PrintPreviewUI(TabContents* contents) - : ConstrainedHtmlUI(contents), - initial_preview_start_time_(base::TimeTicks::Now()), - tab_closed_(false) { + : ChromeWebUI(contents), + initial_preview_start_time_(base::TimeTicks::Now()) { // WebUI owns |handler_|. handler_ = new PrintPreviewHandler(); AddMessageHandler(handler_->Attach(this)); @@ -146,25 +141,14 @@ std::string PrintPreviewUI::GetPrintPreviewUIAddress() const { return preview_ui_addr; } -void PrintPreviewUI::OnPrintPreviewTabClosed() { - TabContentsWrapper* preview_tab = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); - printing::BackgroundPrintingManager* background_printing_manager = - g_browser_process->background_printing_manager(); - if (background_printing_manager->HasPrintPreviewTab(preview_tab)) - return; - OnClosePrintPreviewTab(); +void PrintPreviewUI::OnInitiatorTabCrashed() { + StringValue initiator_tab_url(initiator_url_); + CallJavascriptFunction("onInitiatorTabCrashed", initiator_tab_url); } void PrintPreviewUI::OnInitiatorTabClosed() { - TabContentsWrapper* preview_tab = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); - printing::BackgroundPrintingManager* background_printing_manager = - g_browser_process->background_printing_manager(); - if (background_printing_manager->HasPrintPreviewTab(preview_tab)) - CallJavascriptFunction("cancelPendingPrintRequest"); - else - OnClosePrintPreviewTab(); + StringValue initiator_tab_url(initiator_url_); + CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); } void PrintPreviewUI::OnPrintPreviewRequest(int request_id) { @@ -180,7 +164,7 @@ void PrintPreviewUI::OnDidGetPreviewPageCount( DCHECK_GT(params.page_count, 0); base::FundamentalValue count(params.page_count); base::FundamentalValue request_id(params.preview_request_id); - CallJavascriptFunction("onDidGetPreviewPageCount", count, request_id); + CallJavascriptFunction("onDidGetPreviewPageCount", count,request_id); } void PrintPreviewUI::OnDidGetDefaultPageLayout( @@ -261,34 +245,3 @@ void PrintPreviewUI::OnInvalidPrinterSettings() { PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() { return PrintPreviewDataService::GetInstance(); } - -void PrintPreviewUI::OnHidePreviewTab() { - TabContentsWrapper* preview_tab = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); - printing::BackgroundPrintingManager* background_printing_manager = - g_browser_process->background_printing_manager(); - if (background_printing_manager->HasPrintPreviewTab(preview_tab)) - return; - - ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); - if (!delegate) - return; - delegate->ReleaseTabContentsOnDialogClose(); - background_printing_manager->OwnPrintPreviewTab(preview_tab); - OnClosePrintPreviewTab(); -} - -void PrintPreviewUI::OnClosePrintPreviewTab() { - if (tab_closed_) - return; - tab_closed_ = true; - ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); - if (!delegate) - return; - delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); - delegate->OnDialogCloseFromWebUI(); -} - -void PrintPreviewUI::OnReloadPrintersList() { - CallJavascriptFunction("reloadPrintersList"); -} diff --git a/chrome/browser/ui/webui/print_preview_ui.h b/chrome/browser/ui/webui/print_preview_ui.h index de59b47..0625ef0 100644 --- a/chrome/browser/ui/webui/print_preview_ui.h +++ b/chrome/browser/ui/webui/print_preview_ui.h @@ -12,7 +12,7 @@ #include "base/memory/ref_counted_memory.h" #include "base/time.h" #include "chrome/browser/printing/print_preview_data_service.h" -#include "chrome/browser/ui/webui/constrained_html_ui.h" +#include "chrome/browser/ui/webui/chrome_web_ui.h" class PrintPreviewDataService; class PrintPreviewHandler; @@ -22,7 +22,7 @@ namespace printing { struct PageSizeMargins; } -class PrintPreviewUI : public ConstrainedHtmlUI { +class PrintPreviewUI : public ChromeWebUI { public: explicit PrintPreviewUI(TabContents* contents); virtual ~PrintPreviewUI(); @@ -100,14 +100,13 @@ class PrintPreviewUI : public ConstrainedHtmlUI { // Notifies the Web UI that the print preview failed to render. void OnPrintPreviewFailed(); - // Notified the Web UI that this print preview tab's RenderProcess has been - // closed, which may occur for several reasons, e.g. tab closure or crash. - void OnPrintPreviewTabClosed(); - // Notifies the Web UI that initiator tab is closed, so we can disable all the // controls that need the initiator tab for generating the preview data. void OnInitiatorTabClosed(); + // Notifies the Web UI that the initiator tab has crashed. + void OnInitiatorTabCrashed(); + // Notifies the Web UI renderer that file selection has been cancelled. void OnFileSelectionCancelled(); @@ -118,15 +117,6 @@ class PrintPreviewUI : public ConstrainedHtmlUI { // Notifies the Web UI to cancel the pending preview request. void OnCancelPendingPreviewRequest(); - // Hides the print preview tab. - void OnHidePreviewTab(); - - // Closes the print preview tab. - void OnClosePrintPreviewTab(); - - // Reload the printers list. - void OnReloadPrintersList(); - private: friend class PrintPreviewHandlerTest; FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsCustom); @@ -162,9 +152,6 @@ class PrintPreviewUI : public ConstrainedHtmlUI { // title. string16 initiator_tab_title_; - // Keeps track of whether OnClosePrintPreviewTab() has been called or not. - bool tab_closed_; - DISALLOW_COPY_AND_ASSIGN(PrintPreviewUI); }; diff --git a/chrome/browser/ui/webui/print_preview_ui_uitest.cc b/chrome/browser/ui/webui/print_preview_ui_uitest.cc index 55e33d8..a8bba38 100644 --- a/chrome/browser/ui/webui/print_preview_ui_uitest.cc +++ b/chrome/browser/ui/webui/print_preview_ui_uitest.cc @@ -22,48 +22,88 @@ class PrintPreviewUITest : public UITest { dom_automation_enabled_ = true; launch_arguments_.AppendSwitch(switches::kEnablePrintPreview); } + + void AssertIsPrintPage(TabProxy* tab) { + std::wstring title; + ASSERT_TRUE(tab->GetTabTitle(&title)); + string16 expected_title = + l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_TITLE); + ASSERT_EQ(expected_title, WideToUTF16Hack(title)); + } }; -TEST_F(PrintPreviewUITest, PrintCommands) { +// TODO(thestig) Remove this test in the future if loading +// chrome::kChromeUIPrintURL directly does not make sense. +TEST_F(PrintPreviewUITest, LoadPrintPreviewByURL) { + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + + scoped_refptr<TabProxy> tab = browser->GetActiveTab(); + ASSERT_TRUE(tab.get()); + + // Go to the print preview tab via URL. + NavigateToURL(GURL(chrome::kChromeUIPrintURL)); + AssertIsPrintPage(tab); +} + +TEST_F(PrintPreviewUITest, PrintCommandDisabled) { scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); // Go to the about:blank page. NavigateToURL(GURL(chrome::kAboutBlankURL)); - // Make sure there is 1 tab and print is enabled. + // Make sure there is 1 tab and print is enabled. Create print preview tab. int tab_count; ASSERT_TRUE(browser->GetTabCount(&tab_count)); ASSERT_EQ(1, tab_count); - - bool enabled = false; + bool enabled; ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); ASSERT_TRUE(enabled); - - // Make sure advanced print command (Ctrl+Shift+p) is enabled. - enabled = false; - ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); - ASSERT_TRUE(enabled); - - // Create print preview tab. ASSERT_TRUE(browser->RunCommand(IDC_PRINT)); - // Make sure print is disabled. + // Make sure there are 2 tabs and print is disabled. + ASSERT_TRUE(browser->GetTabCount(&tab_count)); + ASSERT_EQ(2, tab_count); + scoped_refptr<TabProxy> tab = browser->GetActiveTab(); + ASSERT_TRUE(tab.get()); + AssertIsPrintPage(tab); ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); ASSERT_FALSE(enabled); +} + +TEST_F(PrintPreviewUITest, AdvancedPrintCommandEnabled) { + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + + // Go to the about:blank page. + NavigateToURL(GURL(chrome::kAboutBlankURL)); + + // Make sure there is 1 tab and print is enabled. Create print preview tab. + int tab_count; + ASSERT_TRUE(browser->GetTabCount(&tab_count)); + ASSERT_EQ(1, tab_count); + bool enabled; + ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); + ASSERT_TRUE(enabled); // Make sure advanced print command (Ctrl+Shift+p) is enabled. enabled = false; ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); ASSERT_TRUE(enabled); - ASSERT_TRUE(browser->RunCommand(IDC_RELOAD)); + ASSERT_TRUE(browser->RunCommand(IDC_PRINT)); - enabled = false; + // Make sure there are 2 tabs and print is disabled. + ASSERT_TRUE(browser->GetTabCount(&tab_count)); + ASSERT_EQ(2, tab_count); + scoped_refptr<TabProxy> tab = browser->GetActiveTab(); + ASSERT_TRUE(tab.get()); + AssertIsPrintPage(tab); ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); - ASSERT_TRUE(enabled); + ASSERT_FALSE(enabled); - // Make sure advanced print command (Ctrl+Shift+p) is enabled. + // Make sure advanced print command (Ctrl+Shift+p) is enabled on preview tab. enabled = false; ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); ASSERT_TRUE(enabled); diff --git a/chrome/browser/ui/webui/print_preview_ui_unittest.cc b/chrome/browser/ui/webui/print_preview_ui_unittest.cc index f2612a7..a7060cc 100644 --- a/chrome/browser/ui/webui/print_preview_ui_unittest.cc +++ b/chrome/browser/ui/webui/print_preview_ui_unittest.cc @@ -8,7 +8,6 @@ #include "base/memory/ref_counted_memory.h" #include "chrome/browser/printing/print_preview_tab_controller.h" #include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/constrained_window_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/webui/print_preview_ui.h" #include "chrome/common/chrome_switches.h" @@ -22,10 +21,6 @@ namespace { const unsigned char blob1[] = "12346102356120394751634516591348710478123649165419234519234512349134"; -size_t GetConstrainedWindowCount(TabContentsWrapper* tab) { - return tab->constrained_window_tab_helper()->constrained_window_count(); -} - } // namespace typedef BrowserWithTestWindowTest PrintPreviewUITest; @@ -41,7 +36,6 @@ TEST_F(PrintPreviewUITest, PrintPreviewData) { TabContentsWrapper* initiator_tab = browser()->GetSelectedTabContentsWrapper(); ASSERT_TRUE(initiator_tab); - EXPECT_EQ(0U, GetConstrainedWindowCount(initiator_tab)); scoped_refptr<printing::PrintPreviewTabController> controller(new printing::PrintPreviewTabController()); @@ -51,8 +45,7 @@ TEST_F(PrintPreviewUITest, PrintPreviewData) { controller->GetOrCreatePreviewTab(initiator_tab); EXPECT_NE(initiator_tab, preview_tab); - EXPECT_EQ(1, browser()->tab_count()); - EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); + EXPECT_EQ(2, browser()->tab_count()); PrintPreviewUI* preview_ui = reinterpret_cast<PrintPreviewUI*>(preview_tab->web_ui()); @@ -112,8 +105,7 @@ TEST_F(PrintPreviewUITest, PrintPreviewDraftPages) { controller->GetOrCreatePreviewTab(initiator_tab); EXPECT_NE(initiator_tab, preview_tab); - EXPECT_EQ(1, browser()->tab_count()); - EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); + EXPECT_EQ(2, browser()->tab_count()); PrintPreviewUI* preview_ui = reinterpret_cast<PrintPreviewUI*>(preview_tab->web_ui()); @@ -180,8 +172,7 @@ TEST_F(PrintPreviewUITest, GetCurrentPrintPreviewStatus) { controller->GetOrCreatePreviewTab(initiator_tab); EXPECT_NE(initiator_tab, preview_tab); - EXPECT_EQ(1, browser()->tab_count()); - EXPECT_EQ(1U, GetConstrainedWindowCount(initiator_tab)); + EXPECT_EQ(2, browser()->tab_count()); PrintPreviewUI* preview_ui = reinterpret_cast<PrintPreviewUI*>(preview_tab->web_ui()); diff --git a/chrome/browser/ui/webui/web_ui_browsertest.cc b/chrome/browser/ui/webui/web_ui_browsertest.cc index 2ceed0c..2c84f2df 100644 --- a/chrome/browser/ui/webui/web_ui_browsertest.cc +++ b/chrome/browser/ui/webui/web_ui_browsertest.cc @@ -12,7 +12,6 @@ #include "base/path_service.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/browser/printing/print_preview_tab_controller.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/webui/chrome_web_ui.h" @@ -207,13 +206,6 @@ void WebUIBrowserTest::BrowsePrintPreload( browser()->tabstrip_model(), this); browser()->Print(); tabstrip_observer.WaitForObservation(); - printing::PrintPreviewTabController* tab_controller = - printing::PrintPreviewTabController::GetInstance(); - ASSERT_TRUE(tab_controller); - TabContentsWrapper* preview_tab = tab_controller->GetPrintPreviewForTab( - browser()->GetSelectedTabContentsWrapper()); - ASSERT_TRUE(preview_tab); - SetWebUIInstance(preview_tab->web_ui()); } const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; |