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/ui/webui/print_preview_ui_html_source.h" | 5 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 char* preview_data = reinterpret_cast<char*>(data_.first->memory()); | 153 char* preview_data = reinterpret_cast<char*>(data_.first->memory()); |
154 uint32 preview_data_size = data_.second; | 154 uint32 preview_data_size = data_.second; |
155 | 155 |
156 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 156 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
157 html_bytes->data.resize(preview_data_size); | 157 html_bytes->data.resize(preview_data_size); |
158 std::vector<unsigned char>::iterator it = html_bytes->data.begin(); | 158 std::vector<unsigned char>::iterator it = html_bytes->data.begin(); |
159 for (uint32 i = 0; i < preview_data_size; ++i, ++it) | 159 for (uint32 i = 0; i < preview_data_size; ++i, ++it) |
160 *it = *(preview_data + i); | 160 *it = *(preview_data + i); |
161 SendResponse(request_id, html_bytes); | 161 SendResponse(request_id, html_bytes); |
162 return; | 162 return; |
163 } else if (path == "dummy.pdf") { | |
164 scoped_refptr<RefCountedBytes> dummy_bytes(new RefCountedBytes); | |
165 std::string dummy_string("%PDF-1.4\n4 0 obj\n<</Type /Catalog /Pages 1 0 R" | |
vandebo (ex-Chrome)
2011/05/11 18:00:05
I squished this down a bit more (to 316 bytes):
dpapad
2011/05/11 18:35:38
Done.
| |
166 " >> endobj 2 0 obj\n<</Type /Page /Parent 1 0 R /MediaBox [0 0 612 792" | |
167 "] /Contents 3 0 R >> endobj 3 0 obj\n<</Length 0 >> stream\nendstream\n" | |
168 "endobj\n1 0 obj\n<</Type /Pages /Kids [2 0 R] /Count 1 >> endobj\n" | |
169 "xref\n0 5\n0000000000 65535 f \n0000000200 00000 n \n0000000067 00000" | |
170 " n \n0000000153 00000 n \n0000000019 00000 n \ntrailer\n<</Size 8\n" | |
171 "/Root 4 0 R\n>>\nstartxref\n256\n%%EOF"); | |
172 const char* dummy_data = dummy_string.c_str(); | |
173 dummy_bytes->data.resize(dummy_string.length()); | |
174 std::vector<unsigned char>::iterator it = dummy_bytes->data.begin(); | |
175 for (uint32 i = 0; i < dummy_string.length(); ++i, ++it) | |
176 *it = *(dummy_data + i); | |
177 SendResponse(request_id, dummy_bytes); | |
178 return; | |
163 } else { | 179 } else { |
164 // Invalid request. | 180 // Invalid request. |
165 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); | 181 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); |
166 SendResponse(request_id, empty_bytes); | 182 SendResponse(request_id, empty_bytes); |
167 return; | 183 return; |
168 } | 184 } |
169 } | 185 } |
170 | 186 |
171 std::string PrintPreviewUIHTMLSource::GetMimeType( | 187 std::string PrintPreviewUIHTMLSource::GetMimeType( |
172 const std::string& path) const { | 188 const std::string& path) const { |
173 // Print Preview Index page. | 189 // Print Preview Index page. |
174 if (path.empty()) | 190 if (path.empty()) |
175 return "text/html"; | 191 return "text/html"; |
176 // Print Preview data. | 192 // Print Preview data. |
177 return "application/pdf"; | 193 return "application/pdf"; |
178 } | 194 } |
OLD | NEW |