Commit 0fe599e9 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Give PrintHostMsg_DidGetPreviewPageCount a better name.

It really should be called PrintHostMsg_DidStartPreview. Getting the
page count is usually one of the first steps in starting a print
preview, but the IPC message does a bit more than that now.

Change-Id: I001a66c169fa5cf42b238605d6067bf12d58962e
Reviewed-on: https://chromium-review.googlesource.com/1184317Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585298}
parent 8abf4223
......@@ -106,8 +106,8 @@ void PrintPreviewMessageHandler::OnRequestPrintPreview(
PrintPreviewUI::SetInitialParams(GetPrintPreviewDialog(), params);
}
void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params,
void PrintPreviewMessageHandler::OnDidStartPreview(
const PrintHostMsg_DidStartPreview_Params& params,
const PrintHostMsg_PreviewIds& ids) {
if (params.page_count <= 0) {
NOTREACHED();
......@@ -119,7 +119,7 @@ void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(
return;
print_preview_ui->ClearAllPreviewData();
print_preview_ui->OnDidGetPreviewPageCount(params, ids.request_id);
print_preview_ui->OnDidStartPreview(params, ids.request_id);
}
void PrintPreviewMessageHandler::OnDidPreviewPage(
......@@ -324,8 +324,7 @@ bool PrintPreviewMessageHandler::OnMessageReceived(
handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount,
OnDidGetPreviewPageCount)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidStartPreview, OnDidStartPreview)
IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed,
OnPrintPreviewFailed)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDefaultPageLayout,
......
......@@ -13,9 +13,9 @@
#include "content/public/browser/web_contents_user_data.h"
class PrintPreviewUI;
struct PrintHostMsg_DidGetPreviewPageCount_Params;
struct PrintHostMsg_DidPreviewDocument_Params;
struct PrintHostMsg_DidPreviewPage_Params;
struct PrintHostMsg_DidStartPreview_Params;
struct PrintHostMsg_PreviewIds;
struct PrintHostMsg_RequestPrintPreview_Params;
struct PrintHostMsg_SetOptionsFromDocument_Params;
......@@ -69,9 +69,8 @@ class PrintPreviewMessageHandler
const gfx::Rect& printable_area_in_points,
bool has_custom_page_size_style,
const PrintHostMsg_PreviewIds& ids);
void OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params,
const PrintHostMsg_PreviewIds& ids);
void OnDidStartPreview(const PrintHostMsg_DidStartPreview_Params& params,
const PrintHostMsg_PreviewIds& ids);
void OnDidPreviewPage(content::RenderFrameHost* render_frame_host,
const PrintHostMsg_DidPreviewPage_Params& params,
const PrintHostMsg_PreviewIds& ids);
......
......@@ -141,8 +141,7 @@ class PrintPreviewObserver : public WebContentsObserver {
bool OnMessageReceived(const IPC::Message& message) override {
IPC_BEGIN_MESSAGE_MAP(PrintPreviewObserver, message)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount,
OnDidGetPreviewPageCount)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidStartPreview, OnDidStartPreview)
IPC_END_MESSAGE_MAP()
return false;
}
......@@ -268,11 +267,10 @@ class PrintPreviewObserver : public WebContentsObserver {
DISALLOW_COPY_AND_ASSIGN(UIDoneLoadingMessageHandler);
};
// Called when the observer gets the IPC message stating that the page count
// is ready.
void OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params,
const PrintHostMsg_PreviewIds& ids) {
// Called when the observer gets the IPC message with the preview document's
// properties.
void OnDidStartPreview(const PrintHostMsg_DidStartPreview_Params& params,
const PrintHostMsg_PreviewIds& ids) {
WebContents* web_contents = GetDialog();
ASSERT_TRUE(web_contents);
Observe(web_contents);
......
......@@ -693,8 +693,8 @@ void PrintPreviewUI::OnPrintPreviewRequest(int request_id) {
g_print_preview_request_id_map.Get().Set(id_, request_id);
}
void PrintPreviewUI::OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params,
void PrintPreviewUI::OnDidStartPreview(
const PrintHostMsg_DidStartPreview_Params& params,
int request_id) {
DCHECK_GT(params.page_count, 0);
if (g_testing_delegate)
......
......@@ -17,7 +17,7 @@
#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
class PrintPreviewHandler;
struct PrintHostMsg_DidGetPreviewPageCount_Params;
struct PrintHostMsg_DidStartPreview_Params;
struct PrintHostMsg_PreviewIds;
struct PrintHostMsg_RequestPrintPreview_Params;
struct PrintHostMsg_SetOptionsFromDocument_Params;
......@@ -85,10 +85,9 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
// Notifies the Web UI of a print preview request with |request_id|.
virtual void OnPrintPreviewRequest(int request_id);
// Notifies the Web UI about the page count of the request preview.
void OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params,
int request_id);
// Notifies the Web UI about the properties of the request preview.
void OnDidStartPreview(const PrintHostMsg_DidStartPreview_Params& params,
int request_id);
// Notifies the Web UI of the default page layout according to the currently
// selected printer and page size.
......
......@@ -284,19 +284,14 @@ IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintContent_Params)
IPC_STRUCT_END()
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
// Parameters to describe a rendered document.
IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params)
// Document's content including metafile data and subframe info.
IPC_STRUCT_MEMBER(PrintHostMsg_DidPrintContent_Params, content)
// Cookie for the document to ensure correctness.
IPC_STRUCT_MEMBER(int, document_cookie)
// Store the expected pages count.
IPC_STRUCT_MEMBER(int, expected_pages_count)
// Parameters to describe the to-be-rendered preview document.
IPC_STRUCT_BEGIN(PrintHostMsg_DidStartPreview_Params)
// Total page count for the rendered preview. (Not the number of pages the
// user selected to print.)
IPC_STRUCT_MEMBER(int, page_count)
// Whether the preview can be modified.
IPC_STRUCT_MEMBER(bool, modifiable)
// Scaling % to fit to page
IPC_STRUCT_MEMBER(int, fit_to_page_scaling)
IPC_STRUCT_END()
// Parameters to describe a rendered preview page.
......@@ -311,13 +306,19 @@ IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewPage_Params)
IPC_STRUCT_MEMBER(int, document_cookie)
IPC_STRUCT_END()
// Parameters sent along with the page count.
IPC_STRUCT_BEGIN(PrintHostMsg_DidGetPreviewPageCount_Params)
// Total page count.
IPC_STRUCT_MEMBER(int, page_count)
// Parameters to describe the final rendered preview document.
IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params)
// Document's content including metafile data and subframe info.
IPC_STRUCT_MEMBER(PrintHostMsg_DidPrintContent_Params, content)
// Scaling % to fit to page
IPC_STRUCT_MEMBER(int, fit_to_page_scaling)
// Cookie for the document to ensure correctness.
IPC_STRUCT_MEMBER(int, document_cookie)
// Store the expected pages count.
IPC_STRUCT_MEMBER(int, expected_pages_count)
// Whether the preview can be modified.
IPC_STRUCT_MEMBER(bool, modifiable)
IPC_STRUCT_END()
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
......@@ -337,7 +338,6 @@ IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintDocument_Params)
// The physical offsets of the printer in DPI. Used for PS printing.
IPC_STRUCT_MEMBER(gfx::Point, physical_offsets)
IPC_STRUCT_END()
// TODO(dgn) Rename *ScriptedPrint messages because they are not called only
......@@ -460,9 +460,9 @@ IPC_MESSAGE_CONTROL3(PrintHostMsg_TempFileForPrintingWritten,
IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview,
PrintHostMsg_RequestPrintPreview_Params /* params */)
// Notify the browser the number of pages in the print preview document.
IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPreviewPageCount,
PrintHostMsg_DidGetPreviewPageCount_Params /* params */,
// Notify the browser the about the to-be-rendered print preview document.
IPC_MESSAGE_ROUTED2(PrintHostMsg_DidStartPreview,
PrintHostMsg_DidStartPreview_Params /* params */,
PrintHostMsg_PreviewIds /* ids */)
// Notify the browser of the default page layout according to the currently
......
......@@ -1261,11 +1261,11 @@ bool PrintRenderFrameHelper::CreatePreviewDocument() {
routing_id(), default_page_layout, printable_area_in_points,
has_page_size_style, ids));
PrintHostMsg_DidGetPreviewPageCount_Params params;
PrintHostMsg_DidStartPreview_Params params;
params.page_count = print_preview_context_.total_page_count();
params.fit_to_page_scaling =
GetFitToPageScaleFactor(printable_area_in_points);
Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params, ids));
Send(new PrintHostMsg_DidStartPreview(routing_id(), params, ids));
if (CheckForCancel())
return false;
......
......@@ -61,8 +61,7 @@ bool PrintMockRenderThread::OnMessageReceived(const IPC::Message& msg) {
OnDidGetPrintedPagesCount)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintDocument, OnDidPrintDocument)
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount,
OnDidGetPreviewPageCount)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidStartPreview, OnDidStartPreview)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage, OnDidPreviewPage)
IPC_MESSAGE_HANDLER(PrintHostMsg_CheckForCancel, OnCheckForCancel)
#endif
......@@ -99,8 +98,8 @@ void PrintMockRenderThread::OnDidPrintDocument(
}
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
void PrintMockRenderThread::OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params,
void PrintMockRenderThread::OnDidStartPreview(
const PrintHostMsg_DidStartPreview_Params& params,
const PrintHostMsg_PreviewIds& ids) {
print_preview_pages_remaining_ = params.page_count;
}
......
......@@ -22,7 +22,7 @@ class DictionaryValue;
}
class MockPrinter;
struct PrintHostMsg_DidGetPreviewPageCount_Params;
struct PrintHostMsg_DidStartPreview_Params;
struct PrintHostMsg_DidPreviewPage_Params;
struct PrintHostMsg_DidPrintDocument_Params;
struct PrintHostMsg_PreviewIds;
......@@ -78,9 +78,8 @@ class PrintMockRenderThread : public content::MockRenderThread {
void OnDidGetPrintedPagesCount(int cookie, int number_pages);
void OnDidPrintDocument(const PrintHostMsg_DidPrintDocument_Params& params);
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
void OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params,
const PrintHostMsg_PreviewIds& ids);
void OnDidStartPreview(const PrintHostMsg_DidStartPreview_Params& params,
const PrintHostMsg_PreviewIds& ids);
void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params,
const PrintHostMsg_PreviewIds& ids);
void OnCheckForCancel(const PrintHostMsg_PreviewIds& ids, bool* cancel);
......
......@@ -202,14 +202,13 @@ class PrintRenderFrameHelperTestBase : public content::RenderViewTest {
// according to the specified settings defined in the mock render thread.
// Verify the page count is correct.
void VerifyPreviewPageCount(int expected_count) {
const IPC::Message* page_cnt_msg =
const IPC::Message* preview_started_message =
render_thread_->sink().GetUniqueMessageMatching(
PrintHostMsg_DidGetPreviewPageCount::ID);
ASSERT_TRUE(page_cnt_msg);
PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param;
PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg,
&post_page_count_param);
EXPECT_EQ(expected_count, std::get<0>(post_page_count_param).page_count);
PrintHostMsg_DidStartPreview::ID);
ASSERT_TRUE(preview_started_message);
PrintHostMsg_DidStartPreview::Param param;
PrintHostMsg_DidStartPreview::Read(preview_started_message, &param);
EXPECT_EQ(expected_count, std::get<0>(param).page_count);
}
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
......
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