| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/mock_render_thread.h" | 5 #include "chrome/renderer/mock_render_thread.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 OnDidGetPrintedPagesCount) | 105 OnDidGetPrintedPagesCount) |
| 106 IPC_MESSAGE_HANDLER(ViewHostMsg_DidPrintPage, OnDidPrintPage) | 106 IPC_MESSAGE_HANDLER(ViewHostMsg_DidPrintPage, OnDidPrintPage) |
| 107 #endif | 107 #endif |
| 108 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
| 109 IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) | 109 IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) |
| 110 #endif | 110 #endif |
| 111 #if defined(OS_POSIX) | 111 #if defined(OS_POSIX) |
| 112 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer, | 112 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer, |
| 113 OnAllocateSharedMemoryBuffer) | 113 OnAllocateSharedMemoryBuffer) |
| 114 #endif | 114 #endif |
| 115 #if defined(OS_LINUX) | 115 #if defined(OS_CHROMEOS) |
| 116 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateTempFileForPrinting, | 116 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateTempFileForPrinting, |
| 117 OnAllocateTempFileForPrinting) | 117 OnAllocateTempFileForPrinting) |
| 118 IPC_MESSAGE_HANDLER(ViewHostMsg_TempFileForPrintingWritten, | 118 IPC_MESSAGE_HANDLER(ViewHostMsg_TempFileForPrintingWritten, |
| 119 OnTempFileForPrintingWritten) | 119 OnTempFileForPrintingWritten) |
| 120 #endif | 120 #endif |
| 121 IPC_MESSAGE_UNHANDLED(handled = false) | 121 IPC_MESSAGE_UNHANDLED(handled = false) |
| 122 IPC_END_MESSAGE_MAP_EX() | 122 IPC_END_MESSAGE_MAP_EX() |
| 123 return handled; | 123 return handled; |
| 124 } | 124 } |
| 125 | 125 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 154 base::SharedMemory shared_buf; | 154 base::SharedMemory shared_buf; |
| 155 if (!shared_buf.CreateAndMapAnonymous(buffer_size)) { | 155 if (!shared_buf.CreateAndMapAnonymous(buffer_size)) { |
| 156 *handle = base::SharedMemory::NULLHandle(); | 156 *handle = base::SharedMemory::NULLHandle(); |
| 157 NOTREACHED() << "Cannot map shared memory buffer"; | 157 NOTREACHED() << "Cannot map shared memory buffer"; |
| 158 return; | 158 return; |
| 159 } | 159 } |
| 160 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), handle); | 160 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), handle); |
| 161 } | 161 } |
| 162 #endif | 162 #endif |
| 163 | 163 |
| 164 #if defined(OS_LINUX) | 164 #if defined(OS_CHROMEOS) |
| 165 void MockRenderThread::OnAllocateTempFileForPrinting( | 165 void MockRenderThread::OnAllocateTempFileForPrinting( |
| 166 base::FileDescriptor* renderer_fd, | 166 base::FileDescriptor* renderer_fd, |
| 167 int* browser_fd) { | 167 int* browser_fd) { |
| 168 renderer_fd->fd = *browser_fd = -1; | 168 renderer_fd->fd = *browser_fd = -1; |
| 169 renderer_fd->auto_close = false; | 169 renderer_fd->auto_close = false; |
| 170 | 170 |
| 171 FilePath path; | 171 FilePath path; |
| 172 if (file_util::CreateTemporaryFile(&path)) { | 172 if (file_util::CreateTemporaryFile(&path)) { |
| 173 int fd = open(path.value().c_str(), O_WRONLY); | 173 int fd = open(path.value().c_str(), O_WRONLY); |
| 174 DCHECK_GE(fd, 0); | 174 DCHECK_GE(fd, 0); |
| 175 renderer_fd->fd = *browser_fd = fd; | 175 renderer_fd->fd = *browser_fd = fd; |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 void MockRenderThread::OnTempFileForPrintingWritten(int browser_fd) { | 179 void MockRenderThread::OnTempFileForPrintingWritten(int browser_fd) { |
| 180 close(browser_fd); | 180 close(browser_fd); |
| 181 } | 181 } |
| 182 #endif | 182 #endif // defined(OS_CHROMEOS) |
| 183 | 183 |
| 184 void MockRenderThread::OnGetDefaultPrintSettings(ViewMsg_Print_Params* params) { | 184 void MockRenderThread::OnGetDefaultPrintSettings(ViewMsg_Print_Params* params) { |
| 185 if (printer_.get()) | 185 if (printer_.get()) |
| 186 printer_->GetDefaultPrintSettings(params); | 186 printer_->GetDefaultPrintSettings(params); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void MockRenderThread::OnScriptedPrint( | 189 void MockRenderThread::OnScriptedPrint( |
| 190 const ViewHostMsg_ScriptedPrint_Params& params, | 190 const ViewHostMsg_ScriptedPrint_Params& params, |
| 191 ViewMsg_PrintPages_Params* settings) { | 191 ViewMsg_PrintPages_Params* settings) { |
| 192 if (printer_.get()) { | 192 if (printer_.get()) { |
| 193 printer_->ScriptedPrint(params.cookie, | 193 printer_->ScriptedPrint(params.cookie, |
| 194 params.expected_pages_count, | 194 params.expected_pages_count, |
| 195 params.has_selection, | 195 params.has_selection, |
| 196 settings); | 196 settings); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { | 200 void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { |
| 201 if (printer_.get()) | 201 if (printer_.get()) |
| 202 printer_->SetPrintedPagesCount(cookie, number_pages); | 202 printer_->SetPrintedPagesCount(cookie, number_pages); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void MockRenderThread::OnDidPrintPage( | 205 void MockRenderThread::OnDidPrintPage( |
| 206 const ViewHostMsg_DidPrintPage_Params& params) { | 206 const ViewHostMsg_DidPrintPage_Params& params) { |
| 207 if (printer_.get()) | 207 if (printer_.get()) |
| 208 printer_->PrintPage(params); | 208 printer_->PrintPage(params); |
| 209 } | 209 } |
| OLD | NEW |