Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "headless/lib/browser/headless_print_manager.h" | 5 #include "headless/lib/browser/headless_print_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 | 166 |
| 167 auto print_params = base::MakeUnique<PrintMsg_PrintPages_Params>(); | 167 auto print_params = base::MakeUnique<PrintMsg_PrintPages_Params>(); |
| 168 RenderParamsFromPrintSettings(print_settings, &print_params->params); | 168 RenderParamsFromPrintSettings(print_settings, &print_params->params); |
| 169 print_params->params.document_cookie = PrintSettings::NewCookie(); | 169 print_params->params.document_cookie = PrintSettings::NewCookie(); |
| 170 return print_params; | 170 return print_params; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool HeadlessPrintManager::OnMessageReceived( | 173 bool HeadlessPrintManager::OnMessageReceived( |
| 174 const IPC::Message& message, | 174 const IPC::Message& message, |
| 175 content::RenderFrameHost* render_frame_host) { | 175 content::RenderFrameHost* render_frame_host) { |
| 176 if (!printing_rfh_ && | |
| 177 (message.type() == PrintHostMsg_GetDefaultPrintSettings::ID || | |
| 178 message.type() == PrintHostMsg_ScriptedPrint::ID)) { | |
|
jzfeng
2017/05/19 01:01:08
nit: check for PrintHostMsg_DidPrintPage here?
Or
| |
| 179 std::string type; | |
| 180 switch (message.type()) { | |
| 181 case PrintHostMsg_GetDefaultPrintSettings::ID: | |
| 182 type = "GetDefaultPrintSettings"; | |
| 183 break; | |
| 184 case PrintHostMsg_ScriptedPrint::ID: | |
| 185 type = "ScriptedPrint"; | |
| 186 break; | |
|
Sami
2017/05/19 13:10:01
Please add a default case too.
| |
| 187 } | |
| 188 DLOG(ERROR) | |
| 189 << "Unexpected message received before GetPDFContents is called: " | |
| 190 << type; | |
| 191 render_frame_host->Send(new IPC::Message()); | |
|
Sami
2017/05/19 13:10:01
Does this end up dropping the print request on the
| |
| 192 return true; | |
| 193 } | |
| 194 | |
| 176 bool handled = true; | 195 bool handled = true; |
| 177 IPC_BEGIN_MESSAGE_MAP(HeadlessPrintManager, message) | 196 IPC_BEGIN_MESSAGE_MAP(HeadlessPrintManager, message) |
| 178 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowInvalidPrinterSettingsError, | 197 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowInvalidPrinterSettingsError, |
| 179 OnShowInvalidPrinterSettingsError) | 198 OnShowInvalidPrinterSettingsError) |
| 180 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) | 199 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) |
| 181 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, | 200 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, |
| 182 OnGetDefaultPrintSettings) | 201 OnGetDefaultPrintSettings) |
| 183 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint) | 202 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint) |
| 184 IPC_MESSAGE_UNHANDLED(handled = false) | 203 IPC_MESSAGE_UNHANDLED(handled = false) |
| 185 IPC_END_MESSAGE_MAP() | 204 IPC_END_MESSAGE_MAP() |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 245 |
| 227 void HeadlessPrintManager::OnDidGetPrintedPagesCount(int cookie, | 246 void HeadlessPrintManager::OnDidGetPrintedPagesCount(int cookie, |
| 228 int number_pages) { | 247 int number_pages) { |
| 229 PrintManager::OnDidGetPrintedPagesCount(cookie, number_pages); | 248 PrintManager::OnDidGetPrintedPagesCount(cookie, number_pages); |
| 230 if (!print_params_->pages.empty()) | 249 if (!print_params_->pages.empty()) |
| 231 number_pages_ = print_params_->pages.size(); | 250 number_pages_ = print_params_->pages.size(); |
| 232 } | 251 } |
| 233 | 252 |
| 234 void HeadlessPrintManager::OnDidPrintPage( | 253 void HeadlessPrintManager::OnDidPrintPage( |
| 235 const PrintHostMsg_DidPrintPage_Params& params) { | 254 const PrintHostMsg_DidPrintPage_Params& params) { |
| 236 if (!callback_) { | |
| 237 DLOG(ERROR) | |
| 238 << "Unexpected PrintHostMsg_DidPrintPage message from the renderer"; | |
| 239 return; | |
| 240 } | |
| 241 | |
| 242 const bool metafile_must_be_valid = expecting_first_page_; | 255 const bool metafile_must_be_valid = expecting_first_page_; |
| 243 expecting_first_page_ = false; | 256 expecting_first_page_ = false; |
| 244 | 257 |
| 245 if (metafile_must_be_valid) { | 258 if (metafile_must_be_valid) { |
| 246 if (!base::SharedMemory::IsHandleValid(params.metafile_data_handle)) { | 259 if (!base::SharedMemory::IsHandleValid(params.metafile_data_handle)) { |
| 247 ReleaseJob(INVALID_MEMORY_HANDLE); | 260 ReleaseJob(INVALID_MEMORY_HANDLE); |
| 248 return; | 261 return; |
| 249 } | 262 } |
| 250 auto shared_buf = | 263 auto shared_buf = |
| 251 base::MakeUnique<base::SharedMemory>(params.metafile_data_handle, true); | 264 base::MakeUnique<base::SharedMemory>(params.metafile_data_handle, true); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 if (result == PRINT_SUCCESS) | 309 if (result == PRINT_SUCCESS) |
| 297 callback_.Run(result, std::move(data_)); | 310 callback_.Run(result, std::move(data_)); |
| 298 else | 311 else |
| 299 callback_.Run(result, std::string()); | 312 callback_.Run(result, std::string()); |
| 300 printing_rfh_->Send(new PrintMsg_PrintingDone(printing_rfh_->GetRoutingID(), | 313 printing_rfh_->Send(new PrintMsg_PrintingDone(printing_rfh_->GetRoutingID(), |
| 301 result == PRINT_SUCCESS)); | 314 result == PRINT_SUCCESS)); |
| 302 Reset(); | 315 Reset(); |
| 303 } | 316 } |
| 304 | 317 |
| 305 } // namespace printing | 318 } // namespace printing |
| OLD | NEW |