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/utility/chrome_content_utility_client.h" | 5 #include "chrome/utility/chrome_content_utility_client.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 for (size_t i = 0; i < decoded_string.size(); ++i) { | 164 for (size_t i = 0; i < decoded_string.size(); ++i) { |
165 decoded_vector[i] = static_cast<unsigned char>(decoded_string[i]); | 165 decoded_vector[i] = static_cast<unsigned char>(decoded_string[i]); |
166 } | 166 } |
167 | 167 |
168 OnDecodeImage(decoded_vector); | 168 OnDecodeImage(decoded_vector); |
169 } | 169 } |
170 | 170 |
171 void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile( | 171 void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile( |
172 base::PlatformFile pdf_file, | 172 base::PlatformFile pdf_file, |
173 const FilePath& metafile_path, | 173 const FilePath& metafile_path, |
174 const gfx::Rect& render_area, | 174 const printing::PdfRenderSettings& pdf_render_settings, |
175 int render_dpi, | |
176 const std::vector<printing::PageRange>& page_ranges) { | 175 const std::vector<printing::PageRange>& page_ranges) { |
177 bool succeeded = false; | 176 bool succeeded = false; |
178 #if defined(OS_WIN) | 177 #if defined(OS_WIN) |
179 int highest_rendered_page_number = 0; | 178 int highest_rendered_page_number = 0; |
180 succeeded = RenderPDFToWinMetafile(pdf_file, | 179 succeeded = RenderPDFToWinMetafile(pdf_file, |
181 metafile_path, | 180 metafile_path, |
182 render_area, | 181 pdf_render_settings.area(), |
183 render_dpi, | 182 pdf_render_settings.dpi(), |
| 183 pdf_render_settings.autorotate(), |
184 page_ranges, | 184 page_ranges, |
185 &highest_rendered_page_number); | 185 &highest_rendered_page_number); |
186 if (succeeded) { | 186 if (succeeded) { |
187 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded( | 187 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded( |
188 highest_rendered_page_number)); | 188 highest_rendered_page_number)); |
189 } | 189 } |
190 #endif // defined(OS_WIN) | 190 #endif // defined(OS_WIN) |
191 if (!succeeded) { | 191 if (!succeeded) { |
192 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); | 192 Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed()); |
193 } | 193 } |
194 UtilityThread::current()->ReleaseProcessIfNeeded(); | 194 UtilityThread::current()->ReleaseProcessIfNeeded(); |
195 } | 195 } |
196 | 196 |
197 #if defined(OS_WIN) | 197 #if defined(OS_WIN) |
198 // Exported by pdf.dll | 198 // Exported by pdf.dll |
199 typedef bool (*RenderPDFPageToDCProc)( | 199 typedef bool (*RenderPDFPageToDCProc)( |
200 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, | 200 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, |
201 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, | 201 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, |
202 int bounds_width, int bounds_height, bool fit_to_bounds, | 202 int bounds_width, int bounds_height, bool fit_to_bounds, |
203 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds); | 203 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds, |
| 204 bool autorotate); |
204 | 205 |
205 typedef bool (*GetPDFDocInfoProc)(const unsigned char* pdf_buffer, | 206 typedef bool (*GetPDFDocInfoProc)(const unsigned char* pdf_buffer, |
206 int buffer_size, int* page_count, | 207 int buffer_size, int* page_count, |
207 double* max_page_width); | 208 double* max_page_width); |
208 | 209 |
209 // The 2 below IAT patch functions are almost identical to the code in | 210 // The 2 below IAT patch functions are almost identical to the code in |
210 // render_process_impl.cc. This is needed to work around specific Windows APIs | 211 // render_process_impl.cc. This is needed to work around specific Windows APIs |
211 // used by the Chrome PDF plugin that will fail in the sandbox. | 212 // used by the Chrome PDF plugin that will fail in the sandbox. |
212 static base::win::IATPatchFunction g_iat_patch_createdca; | 213 static base::win::IATPatchFunction g_iat_patch_createdca; |
213 HDC WINAPI UtilityProcess_CreateDCAPatch(LPCSTR driver_name, | 214 HDC WINAPI UtilityProcess_CreateDCAPatch(LPCSTR driver_name, |
(...skipping 28 matching lines...) Expand all Loading... |
242 } | 243 } |
243 } | 244 } |
244 return rv; | 245 return rv; |
245 } | 246 } |
246 | 247 |
247 bool ChromeContentUtilityClient::RenderPDFToWinMetafile( | 248 bool ChromeContentUtilityClient::RenderPDFToWinMetafile( |
248 base::PlatformFile pdf_file, | 249 base::PlatformFile pdf_file, |
249 const FilePath& metafile_path, | 250 const FilePath& metafile_path, |
250 const gfx::Rect& render_area, | 251 const gfx::Rect& render_area, |
251 int render_dpi, | 252 int render_dpi, |
| 253 bool autorotate, |
252 const std::vector<printing::PageRange>& page_ranges, | 254 const std::vector<printing::PageRange>& page_ranges, |
253 int* highest_rendered_page_number) { | 255 int* highest_rendered_page_number) { |
254 *highest_rendered_page_number = -1; | 256 *highest_rendered_page_number = -1; |
255 base::win::ScopedHandle file(pdf_file); | 257 base::win::ScopedHandle file(pdf_file); |
256 FilePath pdf_module_path; | 258 FilePath pdf_module_path; |
257 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_module_path); | 259 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_module_path); |
258 HMODULE pdf_module = GetModuleHandle(pdf_module_path.value().c_str()); | 260 HMODULE pdf_module = GetModuleHandle(pdf_module_path.value().c_str()); |
259 if (!pdf_module) | 261 if (!pdf_module) |
260 return false; | 262 return false; |
261 | 263 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 for (iter = page_ranges.begin(); iter != page_ranges.end(); ++iter) { | 318 for (iter = page_ranges.begin(); iter != page_ranges.end(); ++iter) { |
317 for (int page_number = iter->from; page_number <= iter->to; ++page_number) { | 319 for (int page_number = iter->from; page_number <= iter->to; ++page_number) { |
318 if (page_number >= total_page_count) | 320 if (page_number >= total_page_count) |
319 break; | 321 break; |
320 // The underlying metafile is of type Emf and ignores the arguments passed | 322 // The underlying metafile is of type Emf and ignores the arguments passed |
321 // to StartPage. | 323 // to StartPage. |
322 metafile.StartPage(gfx::Size(), gfx::Rect(), 1); | 324 metafile.StartPage(gfx::Size(), gfx::Rect(), 1); |
323 if (render_proc(&buffer.front(), buffer.size(), page_number, | 325 if (render_proc(&buffer.front(), buffer.size(), page_number, |
324 metafile.context(), render_dpi, render_dpi, | 326 metafile.context(), render_dpi, render_dpi, |
325 render_area.x(), render_area.y(), render_area.width(), | 327 render_area.x(), render_area.y(), render_area.width(), |
326 render_area.height(), true, false, true, true)) | 328 render_area.height(), true, false, true, true, |
| 329 autorotate)) |
327 if (*highest_rendered_page_number < page_number) | 330 if (*highest_rendered_page_number < page_number) |
328 *highest_rendered_page_number = page_number; | 331 *highest_rendered_page_number = page_number; |
329 ret = true; | 332 ret = true; |
330 metafile.FinishPage(); | 333 metafile.FinishPage(); |
331 } | 334 } |
332 } | 335 } |
333 metafile.FinishDocument(); | 336 metafile.FinishDocument(); |
334 return ret; | 337 return ret; |
335 } | 338 } |
336 #endif // defined(OS_WIN) | 339 #endif // defined(OS_WIN) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 414 |
412 void ChromeContentUtilityClient::ImporterCleanup() { | 415 void ChromeContentUtilityClient::ImporterCleanup() { |
413 importer_->Cancel(); | 416 importer_->Cancel(); |
414 importer_ = NULL; | 417 importer_ = NULL; |
415 bridge_ = NULL; | 418 bridge_ = NULL; |
416 import_thread_.reset(); | 419 import_thread_.reset(); |
417 UtilityThread::current()->ReleaseProcessIfNeeded(); | 420 UtilityThread::current()->ReleaseProcessIfNeeded(); |
418 } | 421 } |
419 | 422 |
420 } // namespace chrome | 423 } // namespace chrome |
OLD | NEW |