Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: headless/lib/browser/headless_print_manager.cc

Issue 2890133002: check whether the printing render frame host has been initialised before accepting a message in the… (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 DLOG(WARNING)
178 << "Unexpected message received before GetPDFContents is called.";
179 render_frame_host->Send(new IPC::Message());
jzfeng 2017/05/18 08:12:47 use DLOG(ERROR), and add the message type into the
180 return true;
181 }
182
176 bool handled = true; 183 bool handled = true;
177 IPC_BEGIN_MESSAGE_MAP(HeadlessPrintManager, message) 184 IPC_BEGIN_MESSAGE_MAP(HeadlessPrintManager, message)
178 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowInvalidPrinterSettingsError, 185 IPC_MESSAGE_HANDLER(PrintHostMsg_ShowInvalidPrinterSettingsError,
179 OnShowInvalidPrinterSettingsError) 186 OnShowInvalidPrinterSettingsError)
180 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) 187 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage)
181 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, 188 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings,
182 OnGetDefaultPrintSettings) 189 OnGetDefaultPrintSettings)
183 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint) 190 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint)
184 IPC_MESSAGE_UNHANDLED(handled = false) 191 IPC_MESSAGE_UNHANDLED(handled = false)
185 IPC_END_MESSAGE_MAP() 192 IPC_END_MESSAGE_MAP()
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (!print_params_->pages.empty()) 237 if (!print_params_->pages.empty())
231 number_pages_ = print_params_->pages.size(); 238 number_pages_ = print_params_->pages.size();
232 } 239 }
233 240
234 void HeadlessPrintManager::OnDidPrintPage( 241 void HeadlessPrintManager::OnDidPrintPage(
235 const PrintHostMsg_DidPrintPage_Params& params) { 242 const PrintHostMsg_DidPrintPage_Params& params) {
236 if (!callback_) { 243 if (!callback_) {
237 DLOG(ERROR) 244 DLOG(ERROR)
238 << "Unexpected PrintHostMsg_DidPrintPage message from the renderer"; 245 << "Unexpected PrintHostMsg_DidPrintPage message from the renderer";
239 return; 246 return;
240 } 247 }
jzfeng 2017/05/18 08:12:47 remove this block since now it is checked in OnMes
241 248
242 const bool metafile_must_be_valid = expecting_first_page_; 249 const bool metafile_must_be_valid = expecting_first_page_;
243 expecting_first_page_ = false; 250 expecting_first_page_ = false;
244 251
245 if (metafile_must_be_valid) { 252 if (metafile_must_be_valid) {
246 if (!base::SharedMemory::IsHandleValid(params.metafile_data_handle)) { 253 if (!base::SharedMemory::IsHandleValid(params.metafile_data_handle)) {
247 ReleaseJob(INVALID_MEMORY_HANDLE); 254 ReleaseJob(INVALID_MEMORY_HANDLE);
248 return; 255 return;
249 } 256 }
250 auto shared_buf = 257 auto shared_buf =
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (result == PRINT_SUCCESS) 303 if (result == PRINT_SUCCESS)
297 callback_.Run(result, std::move(data_)); 304 callback_.Run(result, std::move(data_));
298 else 305 else
299 callback_.Run(result, std::string()); 306 callback_.Run(result, std::string());
300 printing_rfh_->Send(new PrintMsg_PrintingDone(printing_rfh_->GetRoutingID(), 307 printing_rfh_->Send(new PrintMsg_PrintingDone(printing_rfh_->GetRoutingID(),
301 result == PRINT_SUCCESS)); 308 result == PRINT_SUCCESS));
302 Reset(); 309 Reset();
303 } 310 }
304 311
305 } // namespace printing 312 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698