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 "base/memory/ref_counted.h" |
7 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/printing/print_job_manager.h" | 9 #include "chrome/browser/printing/print_job_manager.h" |
9 #include "chrome/browser/printing/print_preview_tab_controller.h" | 10 #include "chrome/browser/printing/print_preview_tab_controller.h" |
10 #include "chrome/browser/printing/print_view_manager.h" | 11 #include "chrome/browser/printing/print_view_manager.h" |
11 #include "chrome/browser/printing/printer_query.h" | 12 #include "chrome/browser/printing/printer_query.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
13 #include "chrome/browser/ui/webui/print_preview_handler.h" | 14 #include "chrome/browser/ui/webui/print_preview_handler.h" |
14 #include "chrome/browser/ui/webui/print_preview_ui.h" | 15 #include "chrome/browser/ui/webui/print_preview_ui.h" |
15 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" | |
16 #include "chrome/common/print_messages.h" | 16 #include "chrome/common/print_messages.h" |
17 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
18 #include "content/browser/renderer_host/render_view_host.h" | 18 #include "content/browser/renderer_host/render_view_host.h" |
19 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
20 #include "content/common/content_restriction.h" | 20 #include "content/common/content_restriction.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 void StopWorker(int document_cookie) { | 24 void StopWorker(int document_cookie) { |
25 printing::PrintJobManager* print_job_manager = | 25 printing::PrintJobManager* print_job_manager = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 delete shared_buf; | 81 delete shared_buf; |
82 return; | 82 return; |
83 } | 83 } |
84 | 84 |
85 TabContentsWrapper* wrapper = | 85 TabContentsWrapper* wrapper = |
86 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab); | 86 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab); |
87 wrapper->print_view_manager()->OverrideTitle(tab_contents()); | 87 wrapper->print_view_manager()->OverrideTitle(tab_contents()); |
88 | 88 |
89 PrintPreviewUI* print_preview_ui = | 89 PrintPreviewUI* print_preview_ui = |
90 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | 90 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
91 PrintPreviewUIHTMLSource* html_source = print_preview_ui->html_source(); | 91 |
92 html_source->SetPrintPreviewData( | 92 char* preview_data = static_cast<char*>(shared_buf->memory()); |
93 std::make_pair(shared_buf, params.data_size)); | 93 uint32 preview_data_size = params.data_size; |
| 94 |
| 95 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 96 html_bytes->data.resize(preview_data_size); |
| 97 std::vector<unsigned char>::iterator it = html_bytes->data.begin(); |
| 98 for (uint32 i = 0; i < preview_data_size; ++i, ++it) |
| 99 *it = *(preview_data + i); |
| 100 |
| 101 print_preview_ui->SetPrintPreviewData(html_bytes.get()); |
94 print_preview_ui->OnPreviewDataIsAvailable( | 102 print_preview_ui->OnPreviewDataIsAvailable( |
95 params.expected_pages_count, | 103 params.expected_pages_count, |
96 wrapper->print_view_manager()->RenderSourceName(), | 104 wrapper->print_view_manager()->RenderSourceName(), |
97 params.modifiable); | 105 params.modifiable); |
98 } | 106 } |
99 | 107 |
100 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { | 108 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { |
101 // Always need to stop the worker. | 109 // Always need to stop the worker. |
102 StopWorker(document_cookie); | 110 StopWorker(document_cookie); |
103 | 111 |
(...skipping 21 matching lines...) Expand all Loading... |
125 } | 133 } |
126 | 134 |
127 void PrintPreviewMessageHandler::DidStartLoading() { | 135 void PrintPreviewMessageHandler::DidStartLoading() { |
128 if (tab_contents()->delegate() && | 136 if (tab_contents()->delegate() && |
129 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { | 137 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { |
130 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); | 138 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); |
131 } | 139 } |
132 } | 140 } |
133 | 141 |
134 } // namespace printing | 142 } // namespace printing |
OLD | NEW |