OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/process_util.h" |
7 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
8 #include "ipc/ipc_message_utils.h" | 9 #include "ipc/ipc_message_utils.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 MockRenderThread::MockRenderThread() | 12 MockRenderThread::MockRenderThread() |
12 : routing_id_(0), | 13 : routing_id_(0), |
13 opener_id_(0), | 14 opener_id_(0), |
14 widget_(NULL), | 15 widget_(NULL), |
15 reply_deserializer_(NULL), | 16 reply_deserializer_(NULL), |
16 printer_(new MockPrinter) { | 17 printer_(new MockPrinter) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // Save the message in the sink. | 68 // Save the message in the sink. |
68 sink_.OnMessageReceived(msg); | 69 sink_.OnMessageReceived(msg); |
69 | 70 |
70 // Some messages we do special handling. | 71 // Some messages we do special handling. |
71 bool handled = true; | 72 bool handled = true; |
72 bool msg_is_ok = true; | 73 bool msg_is_ok = true; |
73 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) | 74 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) |
74 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget); | 75 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget); |
75 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, | 76 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, |
76 OnMsgOpenChannelToExtension); | 77 OnMsgOpenChannelToExtension); |
77 #if defined(OS_WIN) | 78 #if defined(OS_WIN) || defined(OS_MACOSX) |
78 IPC_MESSAGE_HANDLER(ViewHostMsg_GetDefaultPrintSettings, | 79 IPC_MESSAGE_HANDLER(ViewHostMsg_GetDefaultPrintSettings, |
79 OnGetDefaultPrintSettings); | 80 OnGetDefaultPrintSettings); |
80 IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptedPrint, | 81 IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptedPrint, |
81 OnScriptedPrint); | 82 OnScriptedPrint); |
82 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetPrintedPagesCount, | 83 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetPrintedPagesCount, |
83 OnDidGetPrintedPagesCount) | 84 OnDidGetPrintedPagesCount) |
84 IPC_MESSAGE_HANDLER(ViewHostMsg_DidPrintPage, OnDidPrintPage) | 85 IPC_MESSAGE_HANDLER(ViewHostMsg_DidPrintPage, OnDidPrintPage) |
| 86 #endif |
| 87 #if defined(OS_WIN) |
85 IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) | 88 IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) |
86 #endif | 89 #endif |
| 90 #if defined(OS_MACOSX) |
| 91 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocatePDFTransport, |
| 92 OnAllocatePDFTransport) |
| 93 #endif |
87 IPC_MESSAGE_UNHANDLED(handled = false) | 94 IPC_MESSAGE_UNHANDLED(handled = false) |
88 IPC_END_MESSAGE_MAP_EX() | 95 IPC_END_MESSAGE_MAP_EX() |
89 } | 96 } |
90 | 97 |
91 // The Widget expects to be returned valid route_id. | 98 // The Widget expects to be returned valid route_id. |
92 void MockRenderThread::OnMsgCreateWidget(int opener_id, | 99 void MockRenderThread::OnMsgCreateWidget(int opener_id, |
93 bool activatable, | 100 bool activatable, |
94 int* route_id) { | 101 int* route_id) { |
95 opener_id_ = opener_id; | 102 opener_id_ = opener_id; |
96 *route_id = routing_id_; | 103 *route_id = routing_id_; |
97 } | 104 } |
98 | 105 |
99 void MockRenderThread::OnMsgOpenChannelToExtension( | 106 void MockRenderThread::OnMsgOpenChannelToExtension( |
100 int routing_id, const std::string& source_extension_id, | 107 int routing_id, const std::string& source_extension_id, |
101 const std::string& target_extension_id, | 108 const std::string& target_extension_id, |
102 const std::string& channel_name, int* port_id) { | 109 const std::string& channel_name, int* port_id) { |
103 *port_id = 0; | 110 *port_id = 0; |
104 } | 111 } |
105 | 112 |
| 113 #if defined(OS_WIN) |
106 void MockRenderThread::OnDuplicateSection( | 114 void MockRenderThread::OnDuplicateSection( |
107 base::SharedMemoryHandle renderer_handle, | 115 base::SharedMemoryHandle renderer_handle, |
108 base::SharedMemoryHandle* browser_handle) { | 116 base::SharedMemoryHandle* browser_handle) { |
109 // We don't have to duplicate the input handles since RenderViewTest does not | 117 // We don't have to duplicate the input handles since RenderViewTest does not |
110 // separate a browser process from a renderer process. | 118 // separate a browser process from a renderer process. |
111 *browser_handle = renderer_handle; | 119 *browser_handle = renderer_handle; |
112 } | 120 } |
| 121 #endif |
| 122 |
| 123 #if defined(OS_MACOSX) |
| 124 void MockRenderThread::OnAllocatePDFTransport( |
| 125 size_t buffer_size, base::SharedMemoryHandle* handle) { |
| 126 base::SharedMemory shared_buf; |
| 127 shared_buf.Create(L"", false, false, buffer_size); |
| 128 if (!shared_buf.Map(buffer_size)) { |
| 129 *handle = base::SharedMemory::NULLHandle(); |
| 130 NOTREACHED() << "Cannot map PDF transport buffer"; |
| 131 return; |
| 132 } |
| 133 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), handle); |
| 134 } |
| 135 #endif |
113 | 136 |
114 void MockRenderThread::OnGetDefaultPrintSettings(ViewMsg_Print_Params* params) { | 137 void MockRenderThread::OnGetDefaultPrintSettings(ViewMsg_Print_Params* params) { |
115 if (printer_.get()) | 138 if (printer_.get()) |
116 printer_->GetDefaultPrintSettings(params); | 139 printer_->GetDefaultPrintSettings(params); |
117 } | 140 } |
118 | 141 |
119 void MockRenderThread::OnScriptedPrint( | 142 void MockRenderThread::OnScriptedPrint( |
120 const ViewHostMsg_ScriptedPrint_Params& params, | 143 const ViewHostMsg_ScriptedPrint_Params& params, |
121 ViewMsg_PrintPages_Params* settings) { | 144 ViewMsg_PrintPages_Params* settings) { |
122 if (printer_.get()) { | 145 if (printer_.get()) { |
123 printer_->ScriptedPrint(params.cookie, | 146 printer_->ScriptedPrint(params.cookie, |
124 params.expected_pages_count, | 147 params.expected_pages_count, |
125 params.has_selection, | 148 params.has_selection, |
126 settings); | 149 settings); |
127 } | 150 } |
128 } | 151 } |
129 | 152 |
130 void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { | 153 void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { |
131 if (printer_.get()) | 154 if (printer_.get()) |
132 printer_->SetPrintedPagesCount(cookie, number_pages); | 155 printer_->SetPrintedPagesCount(cookie, number_pages); |
133 } | 156 } |
134 | 157 |
135 void MockRenderThread::OnDidPrintPage( | 158 void MockRenderThread::OnDidPrintPage( |
136 const ViewHostMsg_DidPrintPage_Params& params) { | 159 const ViewHostMsg_DidPrintPage_Params& params) { |
137 if (printer_.get()) | 160 if (printer_.get()) |
138 printer_->PrintPage(params); | 161 printer_->PrintPage(params); |
139 } | 162 } |
OLD | NEW |