| 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 |
| 147 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 148 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 148 html_bytes->data.resize(preview_data_size); | 149 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 | 150 |
| 153 print_preview_ui->SetPrintPreviewData(html_bytes.get()); | 151 print_preview_ui->SetPrintPreviewData(html_bytes.get()); |
| 154 print_preview_ui->OnPreviewDataIsAvailable( | 152 print_preview_ui->OnPreviewDataIsAvailable( |
| 155 params.expected_pages_count, | 153 params.expected_pages_count, |
| 156 wrapper->print_view_manager()->RenderSourceName(), | 154 wrapper->print_view_manager()->RenderSourceName(), |
| 157 params.modifiable, | 155 params.modifiable, |
| 158 params.preview_request_id); | 156 params.preview_request_id); |
| 159 } | 157 } |
| 160 | 158 |
| 161 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { | 159 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 200 } |
| 203 | 201 |
| 204 void PrintPreviewMessageHandler::DidStartLoading() { | 202 void PrintPreviewMessageHandler::DidStartLoading() { |
| 205 if (tab_contents()->delegate() && | 203 if (tab_contents()->delegate() && |
| 206 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { | 204 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { |
| 207 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); | 205 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); |
| 208 } | 206 } |
| 209 } | 207 } |
| 210 | 208 |
| 211 } // namespace printing | 209 } // namespace printing |
| OLD | NEW |