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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 delete shared_buf; | 77 delete shared_buf; |
78 return; | 78 return; |
79 } | 79 } |
80 | 80 |
81 TabContentsWrapper* wrapper = | 81 TabContentsWrapper* wrapper = |
82 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab); | 82 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab); |
83 wrapper->print_view_manager()->OverrideTitle(tab_contents()); | 83 wrapper->print_view_manager()->OverrideTitle(tab_contents()); |
84 | 84 |
85 PrintPreviewUI* print_preview_ui = | 85 PrintPreviewUI* print_preview_ui = |
86 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | 86 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
87 PrintPreviewUIHTMLSource* html_source = print_preview_ui->html_source(); | 87 |
88 html_source->SetPrintPreviewData( | 88 char* preview_data = reinterpret_cast<char*>(shared_buf->memory()); |
Lei Zhang
2011/05/27 17:26:53
nit: static_cast
kmadhusu
2011/05/27 23:44:42
Done.
| |
89 std::make_pair(shared_buf, params.data_size)); | 89 uint32 preview_data_size = params.data_size; |
90 | |
91 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | |
92 html_bytes->data.resize(preview_data_size); | |
93 std::vector<unsigned char>::iterator it = html_bytes->data.begin(); | |
94 for (uint32 i = 0; i < preview_data_size; ++i, ++it) | |
95 *it = *(preview_data + i); | |
96 | |
97 print_preview_ui->SetPrintPreviewData(html_bytes.get()); | |
90 print_preview_ui->OnPreviewDataIsAvailable( | 98 print_preview_ui->OnPreviewDataIsAvailable( |
91 params.expected_pages_count, | 99 params.expected_pages_count, |
92 wrapper->print_view_manager()->RenderSourceName(), | 100 wrapper->print_view_manager()->RenderSourceName(), |
93 params.modifiable); | 101 params.modifiable); |
94 } | 102 } |
95 | 103 |
96 void PrintPreviewMessageHandler::OnPrintPreviewNodeUnderContextMenu() { | 104 void PrintPreviewMessageHandler::OnPrintPreviewNodeUnderContextMenu() { |
97 PrintPreviewTabController::PrintPreview(tab_contents()); | 105 PrintPreviewTabController::PrintPreview(tab_contents()); |
98 } | 106 } |
99 | 107 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 } | 139 } |
132 | 140 |
133 void PrintPreviewMessageHandler::DidStartLoading() { | 141 void PrintPreviewMessageHandler::DidStartLoading() { |
134 if (tab_contents()->delegate() && | 142 if (tab_contents()->delegate() && |
135 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { | 143 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { |
136 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); | 144 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); |
137 } | 145 } |
138 } | 146 } |
139 | 147 |
140 } // namespace printing | 148 } // namespace printing |
OLD | NEW |