OLD | NEW |
1 // Copyright (c) 2011 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/browser/printing/print_preview_message_handler.h" | 5 #include "chrome/browser/printing/print_preview_message_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 base::SharedMemory* shared_buf = | 134 base::SharedMemory* shared_buf = |
135 new base::SharedMemory(params.metafile_data_handle, true); | 135 new base::SharedMemory(params.metafile_data_handle, true); |
136 if (!shared_buf->Map(params.data_size)) { | 136 if (!shared_buf->Map(params.data_size)) { |
137 NOTREACHED(); | 137 NOTREACHED(); |
138 delete shared_buf; | 138 delete shared_buf; |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 wrapper->print_view_manager()->OverrideTitle(tab_contents()); | 142 wrapper->print_view_manager()->OverrideTitle(tab_contents()); |
143 | 143 |
144 char* preview_data = static_cast<char*>(shared_buf->memory()); | 144 const unsigned char* preview_data = |
| 145 static_cast<unsigned char*>(shared_buf->memory()); |
145 uint32 preview_data_size = params.data_size; | 146 uint32 preview_data_size = params.data_size; |
146 | 147 |
| 148 // TODO(joth): This seems like a good match for using RefCountedStaticMemory |
| 149 // to avoid the memory copy, but the SetPrintPreviewData call chain below |
| 150 // needs updating to accept the RefCountedMemory* base class. |
147 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 151 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
148 html_bytes->data.resize(preview_data_size); | 152 html_bytes->data().assign(preview_data, preview_data + preview_data_size); |
149 std::vector<unsigned char>::iterator it = html_bytes->data.begin(); | |
150 for (uint32 i = 0; i < preview_data_size; ++i, ++it) | |
151 *it = *(preview_data + i); | |
152 | 153 |
153 print_preview_ui->SetPrintPreviewData(html_bytes.get()); | 154 print_preview_ui->SetPrintPreviewData(html_bytes.get()); |
154 print_preview_ui->OnPreviewDataIsAvailable( | 155 print_preview_ui->OnPreviewDataIsAvailable( |
155 params.expected_pages_count, | 156 params.expected_pages_count, |
156 wrapper->print_view_manager()->RenderSourceName(), | 157 wrapper->print_view_manager()->RenderSourceName(), |
157 params.modifiable, | 158 params.modifiable, |
158 params.preview_request_id); | 159 params.preview_request_id); |
159 } | 160 } |
160 | 161 |
161 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { | 162 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 203 } |
203 | 204 |
204 void PrintPreviewMessageHandler::DidStartLoading() { | 205 void PrintPreviewMessageHandler::DidStartLoading() { |
205 if (tab_contents()->delegate() && | 206 if (tab_contents()->delegate() && |
206 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { | 207 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { |
207 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); | 208 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); |
208 } | 209 } |
209 } | 210 } |
210 | 211 |
211 } // namespace printing | 212 } // namespace printing |
OLD | NEW |