diff options
-rw-r--r-- | chrome/browser/printing/print_view_manager.cc | 16 | ||||
-rw-r--r-- | chrome/browser/printing/printing_layout_uitest.cc | 212 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 16 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.cc | 13 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 8 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 29 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 4 |
8 files changed, 119 insertions, 187 deletions
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index 6813a15..436742a 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -254,14 +254,8 @@ void PrintViewManager::OnNotifyPrintJobInitEvent( owner_.render_view_host()->IsRenderViewLive() && (!old_print_params.Equals(print_params_) || !event_details.document()->page_count())) { - // This will generate a DidGetPrintedPagesCount() callback. - if (!owner_.render_view_host()->GetPrintedPagesCount(print_params_)) { - NOTREACHED(); - if (inside_inner_message_loop_) { - MessageLoop::current()->Quit(); - return; - } - } + // TODO(maruel): Will never happen, this code is about to be deleted. + NOTREACHED(); } // Continue even if owner_.render_view_host() is dead because we may already @@ -477,10 +471,8 @@ void PrintViewManager::PrintNowInternal() { if (!print_job_->document() || !print_job_->document()->IsComplete()) { - ViewMsg_PrintPages_Params params; - params.params = print_params_; - params.pages = PageRange::GetPages(print_job_->settings().ranges); - owner_.render_view_host()->PrintPages(params); + // TODO(maruel): Will never happen. This code is about to be deleted. + NOTREACHED(); } } diff --git a/chrome/browser/printing/printing_layout_uitest.cc b/chrome/browser/printing/printing_layout_uitest.cc index 038ee5d..c7a4f92 100644 --- a/chrome/browser/printing/printing_layout_uitest.cc +++ b/chrome/browser/printing/printing_layout_uitest.cc @@ -8,6 +8,7 @@ #include "skia/ext/platform_device.h" #include "base/gfx/png_decoder.h" #include "base/gfx/png_encoder.h" +#include "base/simple_thread.h" #include "base/time.h" #include "base/win_util.h" #include "chrome/common/chrome_paths.h" @@ -397,95 +398,75 @@ class PrintingLayoutTextTest : public PrintingLayoutTest { } }; -// Dismiss the first dialog box child of owner_window by "executing" the +// Finds the first dialog window owned by owner_process. +HWND FindDialogWindow(DWORD owner_process) { + HWND dialog_window(NULL); + for (;;) { + dialog_window = FindWindowEx(NULL, + dialog_window, + MAKEINTATOM(32770), + NULL); + if (!dialog_window) + break; + + // The dialog must be owned by our target process. + DWORD process_id = 0; + GetWindowThreadProcessId(dialog_window, &process_id); + if (process_id == owner_process) + break; + } + return dialog_window; +} + +// Tries to close a dialog window. +bool CloseDialogWindow(HWND dialog_window) { + LRESULT res = SendMessage(dialog_window, DM_GETDEFID, 0, 0); + if (!res) + return false; + EXPECT_EQ(DC_HASDEFID, HIWORD(res)); + WORD print_button_id = LOWORD(res); + res = SendMessage( + dialog_window, + WM_COMMAND, + print_button_id, + reinterpret_cast<LPARAM>(GetDlgItem(dialog_window, print_button_id))); + return res == 0; +} + +// Dismiss the first dialog box owned by owner_process by "executing" the // default button. -class DismissTheWindow : public base::RefCountedThreadSafe<DismissTheWindow> { +class DismissTheWindow : public base::DelegateSimpleThread::Delegate { public: DismissTheWindow(DWORD owner_process) - : owner_process_(owner_process), - dialog_was_found_(false), - dialog_window_(NULL), - other_thread_(MessageLoop::current()), - start_time_(Time::Now()) { + : owner_process_(owner_process) { } - void Start() { - timer_.Start(TimeDelta::FromMilliseconds(250), this, - &DismissTheWindow::DoTimeout); - } + virtual void Run() { + HWND dialog_window; + for (;;) { + // First enumerate the windows. + dialog_window = FindDialogWindow(owner_process_); - private: - void DoTimeout() { - // A bit twisted code that runs in 2 passes or more. First it tries to find - // a dialog box, if it finds it, it will execute the default action. If it - // still works, it will loop again but then it will try to *not* find the - // window. Once this is right, it will stop the timer and unlock the - // other_thread_ message loop. - if (!timer_.IsRunning()) - return; - - if (!dialog_window_) { - HWND dialog_window = NULL; - for (;;) { - dialog_window = FindWindowEx(NULL, - dialog_window, - MAKEINTATOM(32770), - NULL); - if (!dialog_window) - break; - - // In some corner case, the Print... dialog box may not have any owner. - // Trap that case. Too bad if the user has a dialog opened. - if (Time::Now() - start_time_ > TimeDelta::FromSeconds(3)) - break; - - DWORD process_id = 0; - GetWindowThreadProcessId(dialog_window, &process_id); - if (process_id == owner_process_) - break; - } + // Try to close it. if (dialog_window) { - LRESULT res = SendMessage(dialog_window, DM_GETDEFID, 0, 0); - if (!res) - return; - EXPECT_EQ(DC_HASDEFID, HIWORD(res)); - WORD print_button_id = LOWORD(res); - res = SendMessage( - dialog_window, - WM_COMMAND, - print_button_id, - reinterpret_cast<LPARAM>(GetDlgItem(dialog_window, - print_button_id))); - // Try again. - if (res) - return; - - // Ok it succeeded. - dialog_window_ = dialog_window; - dialog_was_found_ = true; - return; + if (CloseDialogWindow(dialog_window)) { + break; + } } - if (!dialog_was_found_) - return; + Sleep(10); } // Now verify that it indeed closed itself. - if (!IsWindow(dialog_window_)) { - timer_.Stop(); - // Unlock the other thread. - other_thread_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - } else { - // Maybe it's time to try to click it again. Restart from the begining. - dialog_window_ = NULL; + while (IsWindow(dialog_window)) { + CloseDialogWindow(dialog_window); + Sleep(10); } } + DWORD owner_process() { return owner_process_; } + + private: DWORD owner_process_; - bool dialog_was_found_; - HWND dialog_window_; - MessageLoop* other_thread_; - base::RepeatingTimer<DismissTheWindow> timer_; - Time start_time_; }; } // namespace @@ -495,13 +476,19 @@ TEST_F(PrintingLayoutTextTest, DISABLED_Complex) { if (IsTestCaseDisabled()) return; + DismissTheWindow dismisser(base::GetProcId(process())); + base::DelegateSimpleThread close_printdlg_thread(&dismisser, + "close_printdlg_thread"); + // Print a document, check its output. scoped_refptr<HTTPTestServer> server = HTTPTestServer::CreateServer(kDocRoot); ASSERT_TRUE(NULL != server.get()); NavigateToURL(server->TestServerPage("files/printing/test1.html")); + close_printdlg_thread.Start(); PrintNowTab(); + close_printdlg_thread.Join(); EXPECT_EQ(0., CompareWithResult(L"test1")); } @@ -525,9 +512,9 @@ TEST_F(PrintingLayoutTestHidden, ManyTimes) { if (IsTestCaseDisabled()) return; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); + scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); ASSERT_TRUE(NULL != server.get()); + DismissTheWindow dismisser(base::GetProcId(process())); ASSERT_GT(arraysize(kTestPool), 0u); for (int i = 0; i < arraysize(kTestPool); ++i) { @@ -535,31 +522,46 @@ TEST_F(PrintingLayoutTestHidden, ManyTimes) { CleanupDumpDirectory(); const TestPool& test = kTestPool[i % arraysize(kTestPool)]; NavigateToURL(server->TestServerPageW(test.source)); + base::DelegateSimpleThread close_printdlg_thread1(&dismisser, + "close_printdlg_thread"); + EXPECT_EQ(NULL, FindDialogWindow(dismisser.owner_process())); + close_printdlg_thread1.Start(); PrintNowTab(); + close_printdlg_thread1.Join(); EXPECT_EQ(0., CompareWithResult(test.result)) << test.result; CleanupDumpDirectory(); + base::DelegateSimpleThread close_printdlg_thread2(&dismisser, + "close_printdlg_thread"); + EXPECT_EQ(NULL, FindDialogWindow(dismisser.owner_process())); + close_printdlg_thread2.Start(); PrintNowTab(); + close_printdlg_thread2.Join(); EXPECT_EQ(0., CompareWithResult(test.result)) << test.result; CleanupDumpDirectory(); + base::DelegateSimpleThread close_printdlg_thread3(&dismisser, + "close_printdlg_thread"); + EXPECT_EQ(NULL, FindDialogWindow(dismisser.owner_process())); + close_printdlg_thread3.Start(); PrintNowTab(); + close_printdlg_thread3.Join(); EXPECT_EQ(0., CompareWithResult(test.result)) << test.result; CleanupDumpDirectory(); + base::DelegateSimpleThread close_printdlg_thread4(&dismisser, + "close_printdlg_thread"); + EXPECT_EQ(NULL, FindDialogWindow(dismisser.owner_process())); + close_printdlg_thread4.Start(); PrintNowTab(); + close_printdlg_thread4.Join(); EXPECT_EQ(0., CompareWithResult(test.result)) << test.result; } } // Prints a popup and immediately closes it. -TEST_F(PrintingLayoutTest, DISABLED_Delayed) { +TEST_F(PrintingLayoutTest, Delayed) { if (IsTestCaseDisabled()) return; - // TODO(maruel): This test is failing on Windows 2000. I haven't investigated - // why. - if (win_util::GetWinVersion() < win_util::WINVERSION_XP) - return; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); + scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); ASSERT_TRUE(NULL != server.get()); { @@ -570,19 +572,11 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) { EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); - - scoped_ptr<base::Thread> worker( - new base::Thread("PrintingLayoutTest_worker")); - scoped_refptr<DismissTheWindow> dismiss_task = - new DismissTheWindow(base::GetProcId(process())); - // We need to start the thread to be able to set the timer. - worker->Start(); - worker->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(dismiss_task.get(), &DismissTheWindow::Start)); - - MessageLoop::current()->Run(); - - worker->Stop(); + DismissTheWindow dismisser(base::GetProcId(process())); + base::DelegateSimpleThread close_printdlg_thread(&dismisser, + "close_printdlg_thread"); + close_printdlg_thread.Start(); + close_printdlg_thread.Join(); // Force a navigation elsewhere to verify that it's fine with it. url = server->TestServerPage("files/printing/test1.html"); @@ -596,12 +590,11 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) { } // Prints a popup and immediately closes it. -TEST_F(PrintingLayoutTest, DISABLED_IFrame) { +TEST_F(PrintingLayoutTest, IFrame) { if (IsTestCaseDisabled()) return; - scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(kDocRoot); + scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); ASSERT_TRUE(NULL != server.get()); { @@ -611,18 +604,11 @@ TEST_F(PrintingLayoutTest, DISABLED_IFrame) { EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->NavigateToURL(url)); - scoped_ptr<base::Thread> worker( - new base::Thread("PrintingLayoutTest_worker")); - scoped_refptr<DismissTheWindow> dismiss_task = - new DismissTheWindow(base::GetProcId(process())); - // We need to start the thread to be able to set the timer. - worker->Start(); - worker->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(dismiss_task.get(), &DismissTheWindow::Start)); - - MessageLoop::current()->Run(); - - worker->Stop(); + DismissTheWindow dismisser(base::GetProcId(process())); + base::DelegateSimpleThread close_printdlg_thread(&dismisser, + "close_printdlg_thread"); + close_printdlg_thread.Start(); + close_printdlg_thread.Join(); // Force a navigation elsewhere to verify that it's fine with it. url = server->TestServerPage("files/printing/test1.html"); @@ -631,7 +617,5 @@ TEST_F(PrintingLayoutTest, DISABLED_IFrame) { } CloseBrowserAndServer(); - EXPECT_EQ(0., CompareWithResult(L"iframe")) - << L"iframe"; + EXPECT_EQ(0., CompareWithResult(L"iframe")) << L"iframe"; } - diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 567e7e2..b6629e9 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -321,12 +321,8 @@ void RenderViewHost::Stop() { Send(new ViewMsg_Stop(routing_id())); } -bool RenderViewHost::GetPrintedPagesCount(const ViewMsg_Print_Params& params) { - return Send(new ViewMsg_GetPrintedPagesCount(routing_id(), params)); -} - -bool RenderViewHost::PrintPages(const ViewMsg_PrintPages_Params& params) { - return Send(new ViewMsg_PrintPages(routing_id(), params)); +bool RenderViewHost::PrintPages() { + return Send(new ViewMsg_PrintPages(routing_id())); } void RenderViewHost::StartFinding(int request_id, diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index b355f48..19bb424 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_RENDER_VIEW_HOST_H__ -#define CHROME_BROWSER_RENDER_VIEW_HOST_H__ +#ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_H__ +#define CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_H__ #include <string> #include <vector> @@ -180,13 +180,9 @@ class RenderViewHost : public RenderWidgetHost { void Stop(); - // Retrieves the number of printed pages that would result for the current web - // page and the specified settings. The response is a - // ViewHostMsg_DidGetPrintedPagesCount. - bool GetPrintedPagesCount(const ViewMsg_Print_Params& params); - - // Asks the renderer to "render" printed pages. - bool PrintPages(const ViewMsg_PrintPages_Params& params); + // Asks the renderer to "render" printed pages and initiate printing on our + // behalf. + bool PrintPages(); // Start looking for a string within the content of the page, with the // specified options. @@ -627,4 +623,4 @@ class RenderViewHostFactory { base::WaitableEvent* modal_dialog_event) = 0; }; -#endif // CHROME_BROWSER_RENDER_VIEW_HOST_H__ +#endif // CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_H__ diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 5c2fdb2..63e6689 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -589,15 +589,8 @@ void WebContents::SavePage(const std::wstring& main_file, } void WebContents::PrintPreview() { - // We can't print interstitial page for now. - if (showing_interstitial_page()) - return; - - // If we have a find bar it needs to hide as well. - view_->HideFindBar(false); - - // We don't show the print preview for the beta, only the print dialog. - printing_.ShowPrintDialog(); + // We don't show the print preview yet, only the print dialog. + PrintNow(); } bool WebContents::PrintNow() { @@ -608,7 +601,7 @@ bool WebContents::PrintNow() { // If we have a find bar it needs to hide as well. view_->HideFindBar(false); - return printing_.PrintNow(); + return render_view_host()->PrintPages(); } bool WebContents::IsActiveEntry(int32 page_id) { diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 30c6469..c03a110 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -97,15 +97,9 @@ IPC_BEGIN_MESSAGES(View, 1) // This signals the render view that it can send another PaintRect message. IPC_MESSAGE_ROUTED0(ViewMsg_PaintRect_ACK) - // Asks the renderer to calculate the number of printed pages according to the - // supplied settings. The renderer will reply with - // ViewHostMsg_DidGetPrintedPagesCount. - IPC_MESSAGE_ROUTED1(ViewMsg_GetPrintedPagesCount, - ViewMsg_Print_Params) - // Tells the render view to switch the CSS to print media type, renders every // requested pages and switch back the CSS to display media type. - IPC_MESSAGE_ROUTED1(ViewMsg_PrintPages, ViewMsg_PrintPages_Params) + IPC_MESSAGE_ROUTED0(ViewMsg_PrintPages) // Tells the render view that a ViewHostMsg_ScrollRect message was processed. // This signals the render view that it can send another ScrollRect message. diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index b8d321a..45a64dc 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -341,7 +341,6 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(RenderView, message) IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail) - IPC_MESSAGE_HANDLER(ViewMsg_GetPrintedPagesCount, OnGetPrintedPagesCount) IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) @@ -515,12 +514,6 @@ void RenderView::SwitchFrameToDisplayMediaType(WebFrame* frame) { printed_document_width_ = 0; } -void RenderView::OnPrintPage(const ViewMsg_PrintPage_Params& params) { - DCHECK(webview()); - if (webview()) - PrintPage(params, webview()->GetMainFrame()); -} - void RenderView::PrintPage(const ViewMsg_PrintPage_Params& params, WebFrame* frame) { #if defined(OS_WIN) @@ -646,26 +639,12 @@ void RenderView::PrintPage(const ViewMsg_PrintPage_Params& params, #endif } -void RenderView::OnGetPrintedPagesCount(const ViewMsg_Print_Params& params) { +void RenderView::OnPrintPages() { DCHECK(webview()); - if (!webview()) { - Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id_, - params.document_cookie, - 0)); - return; + if (webview()) { + // The renderer own the control flow as if it was a window.print() call. + ScriptedPrint(webview()->GetMainFrame()); } - WebFrame* frame = webview()->GetMainFrame(); - int expected_pages = SwitchFrameToPrintMediaType(params, frame); - Send(new ViewHostMsg_DidGetPrintedPagesCount(routing_id_, - params.document_cookie, - expected_pages)); - SwitchFrameToDisplayMediaType(frame); -} - -void RenderView::OnPrintPages(const ViewMsg_PrintPages_Params& params) { - DCHECK(webview()); - if (webview()) - PrintPages(params, webview()->GetMainFrame()); } void RenderView::PrintPages(const ViewMsg_PrintPages_Params& params, diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index c7f5384..ffd551e 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -398,9 +398,7 @@ class RenderView : public RenderWidget, // RenderView IPC message handlers void OnCreatingNewAck(gfx::NativeViewId parent); void SendThumbnail(); - void OnPrintPage(const ViewMsg_PrintPage_Params& params); - void OnGetPrintedPagesCount(const ViewMsg_Print_Params& params); - void OnPrintPages(const ViewMsg_PrintPages_Params& params); + void OnPrintPages(); void OnNavigate(const ViewMsg_Navigate_Params& params); void OnStop(); void OnLoadAlternateHTMLText(const std::string& html_contents, |