diff --git a/chromium_src/chrome/browser/printing/print_preview_message_handler.cc b/chromium_src/chrome/browser/printing/print_preview_message_handler.cc index 78f01c5de016..3971b9552504 100644 --- a/chromium_src/chrome/browser/printing/print_preview_message_handler.cc +++ b/chromium_src/chrome/browser/printing/print_preview_message_handler.cc @@ -48,20 +48,6 @@ void StopWorker(int document_cookie) { } } -base::RefCountedBytes* GetDataFromHandle(base::SharedMemoryHandle handle, - uint32 data_size) { - scoped_ptr shared_buf( - new base::SharedMemory(handle, true)); - if (!shared_buf->Map(data_size)) { - NOTREACHED(); - return NULL; - } - - unsigned char* data_begin = static_cast(shared_buf->memory()); - std::vector data(data_begin, data_begin + data_size); - return base::RefCountedBytes::TakeVector(&data); -} - } // namespace namespace printing { @@ -86,15 +72,22 @@ void PrintPreviewMessageHandler::OnMetafileReadyForPrinting( return; } - base::RefCountedBytes *data = ( - GetDataFromHandle(params.metafile_data_handle, params.data_size)); - RunPrintToPDFCallback(params.preview_request_id, data); + scoped_ptr shared_buf( + new base::SharedMemory(params.metafile_data_handle, true)); + if (!shared_buf->Map(params.data_size)) { + RunPrintToPDFCallback(params.preview_request_id, nullptr, 0); + return; + } + + RunPrintToPDFCallback(params.preview_request_id, + static_cast(shared_buf->memory()), + params.data_size); } void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie, int request_id) { StopWorker(document_cookie); - RunPrintToPDFCallback(request_id, nullptr); + RunPrintToPDFCallback(request_id, nullptr, 0); } bool PrintPreviewMessageHandler::OnMessageReceived( @@ -122,15 +115,13 @@ void PrintPreviewMessageHandler::PrintToPDF( } void PrintPreviewMessageHandler::RunPrintToPDFCallback( - int request_id, base::RefCountedBytes* data) { + int request_id, char* data, uint32 data_size) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); v8::HandleScope handle_scope(isolate); if (data) { - v8::Local buffer = node::Buffer::Use( - isolate, - const_cast(reinterpret_cast(data->front())), - data->size()); + v8::Local buffer = node::Buffer::New(isolate, + data, static_cast(data_size)); print_to_pdf_callback_map_[request_id].Run(v8::Null(isolate), buffer); } else { v8::Local error_message = v8::String::NewFromUtf8(isolate, diff --git a/chromium_src/chrome/browser/printing/print_preview_message_handler.h b/chromium_src/chrome/browser/printing/print_preview_message_handler.h index 391261d08e0f..a16591dd9f66 100644 --- a/chromium_src/chrome/browser/printing/print_preview_message_handler.h +++ b/chromium_src/chrome/browser/printing/print_preview_message_handler.h @@ -48,7 +48,7 @@ class PrintPreviewMessageHandler void OnPrintPreviewFailed(int document_cookie, int request_id); void RunPrintToPDFCallback( - int request_id, base::RefCountedBytes* data); + int request_id, char* data, uint32 data_size); PrintToPDFCallbackMap print_to_pdf_callback_map_;