| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/pdf_to_emf_converter.h" | 5 #include "chrome/browser/printing/pdf_to_emf_converter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 private: | 84 private: |
| 85 mutable scoped_refptr<RefCountedTempDir> temp_dir_; | 85 mutable scoped_refptr<RefCountedTempDir> temp_dir_; |
| 86 mutable ScopedTempFile file_; // Mutable because of consts in base class. | 86 mutable ScopedTempFile file_; // Mutable because of consts in base class. |
| 87 | 87 |
| 88 bool GetDataAsVector(std::vector<char>* buffer) const override; | 88 bool GetDataAsVector(std::vector<char>* buffer) const override; |
| 89 bool SaveTo(base::File* file) const override; | 89 bool SaveTo(base::File* file) const override; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(LazyEmf); | 91 DISALLOW_COPY_AND_ASSIGN(LazyEmf); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // Postscript metafile subclass to override SafePlayback. |
| 95 class PostScriptMetaFile : public LazyEmf { |
| 96 public: |
| 97 PostScriptMetaFile(const scoped_refptr<RefCountedTempDir>& temp_dir, |
| 98 ScopedTempFile file) |
| 99 : LazyEmf(temp_dir, std::move(file)) {} |
| 100 |
| 101 protected: |
| 102 // MetafilePlayer: |
| 103 bool SafePlayback(HDC hdc) const override; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(PostScriptMetaFile); |
| 106 }; |
| 107 |
| 94 // Class for converting PDF to another format for printing (Emf, Postscript). | 108 // Class for converting PDF to another format for printing (Emf, Postscript). |
| 95 // Class uses 3 threads: UI, IO and FILE. | 109 // Class uses 3 threads: UI, IO and FILE. |
| 96 // Internal workflow is following: | 110 // Internal workflow is following: |
| 97 // 1. Create instance on the UI thread. (files_, settings_,) | 111 // 1. Create instance on the UI thread. (files_, settings_,) |
| 98 // 2. Create pdf file on the FILE thread. | 112 // 2. Create pdf file on the FILE thread. |
| 99 // 3. Start utility process and start conversion on the IO thread. | 113 // 3. Start utility process and start conversion on the IO thread. |
| 100 // 4. Utility process returns page count. | 114 // 4. Utility process returns page count. |
| 101 // 5. For each page: | 115 // 5. For each page: |
| 102 // 1. Clients requests page with file handle to a temp file. | 116 // 1. Clients requests page with file handle to a temp file. |
| 103 // 2. Utility converts the page, save it to the file and reply. | 117 // 2. Utility converts the page, save it to the file and reply. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 165 |
| 152 private: | 166 private: |
| 153 int page_number_; | 167 int page_number_; |
| 154 | 168 |
| 155 PdfConverter::GetPageCallback callback_; | 169 PdfConverter::GetPageCallback callback_; |
| 156 ScopedTempFile file_; | 170 ScopedTempFile file_; |
| 157 | 171 |
| 158 DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData); | 172 DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData); |
| 159 }; | 173 }; |
| 160 | 174 |
| 161 ~PdfConverterUtilityProcessHostClient() override; | 175 bool OnMessageReceived(const IPC::Message& message) override; |
| 162 | 176 |
| 163 // Helper functions: must be overridden by subclasses | 177 // Helper functions: must be overridden by subclasses |
| 164 // Set the process name | 178 // Set the process name |
| 165 virtual base::string16 GetName() const = 0; | 179 base::string16 GetName() const; |
| 166 // Create a metafileplayer subclass file from a temporary file. | 180 // Create a metafileplayer subclass file from a temporary file. |
| 167 virtual std::unique_ptr<MetafilePlayer> GetFileFromTemp( | 181 std::unique_ptr<MetafilePlayer> GetFileFromTemp( |
| 168 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> | 182 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> |
| 169 temp_file) = 0; | 183 temp_file); |
| 170 // Send the messages to Start, GetPage, and Stop. | 184 // Send the messages to Start, GetPage, and Stop. |
| 171 virtual void SendStartMessage(IPC::PlatformFileForTransit transit) = 0; | 185 void SendStartMessage(IPC::PlatformFileForTransit transit); |
| 172 virtual void SendGetPageMessage(int page_number, | 186 void SendGetPageMessage(int page_number, IPC::PlatformFileForTransit transit); |
| 173 IPC::PlatformFileForTransit transit) = 0; | 187 void SendStopMessage(); |
| 174 virtual void SendStopMessage() = 0; | |
| 175 | 188 |
| 176 // Message handlers: | 189 // Message handlers: |
| 177 void OnPageCount(int page_count); | 190 void OnPageCount(int page_count); |
| 178 void OnPageDone(bool success, float scale_factor); | 191 void OnPageDone(bool success, float scale_factor); |
| 179 | 192 |
| 180 void OnFailed(); | 193 void OnFailed(); |
| 181 void OnTempPdfReady(ScopedTempFile pdf); | 194 void OnTempPdfReady(ScopedTempFile pdf); |
| 182 void OnTempFileReady(GetPageCallbackData* callback_data, | 195 void OnTempFileReady(GetPageCallbackData* callback_data, |
| 183 ScopedTempFile temp_file); | 196 ScopedTempFile temp_file); |
| 184 | 197 |
| 198 // Additional message handler needed for Pdf to Emf |
| 199 void OnPreCacheFontCharacters(const LOGFONT& log_font, |
| 200 const base::string16& characters); |
| 201 |
| 185 scoped_refptr<RefCountedTempDir> temp_dir_; | 202 scoped_refptr<RefCountedTempDir> temp_dir_; |
| 186 | 203 |
| 187 // Used to suppress callbacks after PdfConverter is deleted. | 204 // Used to suppress callbacks after PdfConverter is deleted. |
| 188 base::WeakPtr<PdfConverterImpl> converter_; | 205 base::WeakPtr<PdfConverterImpl> converter_; |
| 189 PdfRenderSettings settings_; | 206 PdfRenderSettings settings_; |
| 190 | 207 |
| 191 // Document loaded callback. | 208 // Document loaded callback. |
| 192 PdfConverter::StartCallback start_callback_; | 209 PdfConverter::StartCallback start_callback_; |
| 193 | 210 |
| 194 // Process host for IPC. | 211 // Process host for IPC. |
| 195 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 212 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| 196 | 213 |
| 197 // Queue of callbacks for GetPage() requests. Utility process should reply | 214 // Queue of callbacks for GetPage() requests. Utility process should reply |
| 198 // with PageDone in the same order as requests were received. | 215 // with PageDone in the same order as requests were received. |
| 199 // Use containers that keeps element pointers valid after push() and pop(). | 216 // Use containers that keeps element pointers valid after push() and pop(). |
| 200 using GetPageCallbacks = std::queue<GetPageCallbackData>; | 217 using GetPageCallbacks = std::queue<GetPageCallbackData>; |
| 201 GetPageCallbacks get_page_callbacks_; | 218 GetPageCallbacks get_page_callbacks_; |
| 219 |
| 220 DISALLOW_COPY_AND_ASSIGN(PdfConverterUtilityProcessHostClient); |
| 202 }; | 221 }; |
| 203 | 222 |
| 204 // Converts PDF into Emf. | 223 std::unique_ptr<MetafilePlayer> |
| 205 class PdfToEmfUtilityProcessHostClient | 224 PdfConverterUtilityProcessHostClient::GetFileFromTemp( |
| 206 : public PdfConverterUtilityProcessHostClient { | 225 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> |
| 207 public: | 226 temp_file) { |
| 208 PdfToEmfUtilityProcessHostClient(base::WeakPtr<PdfConverterImpl> converter, | 227 if (settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 || |
| 209 const PdfRenderSettings& settings) | 228 settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3) { |
| 210 : PdfConverterUtilityProcessHostClient(converter, settings) {} | 229 return base::MakeUnique<PostScriptMetaFile>(temp_dir_, |
| 211 | 230 std::move(temp_file)); |
| 212 bool OnMessageReceived(const IPC::Message& message) override; | 231 } |
| 213 | 232 return base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_file)); |
| 214 private: | 233 } |
| 215 ~PdfToEmfUtilityProcessHostClient() override; | |
| 216 // Helpers to send messages and set process name | |
| 217 base::string16 GetName() const override; | |
| 218 std::unique_ptr<MetafilePlayer> GetFileFromTemp( | |
| 219 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> | |
| 220 temp_file) override; | |
| 221 void SendStartMessage(IPC::PlatformFileForTransit transit) override; | |
| 222 void SendGetPageMessage(int page_number, | |
| 223 IPC::PlatformFileForTransit transit) override; | |
| 224 void SendStopMessage() override; | |
| 225 | |
| 226 // Additional message handler needed for Pdf to Emf | |
| 227 void OnPreCacheFontCharacters(const LOGFONT& log_font, | |
| 228 const base::string16& characters); | |
| 229 | |
| 230 DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient); | |
| 231 }; | |
| 232 | |
| 233 // Converts PDF into PostScript. | |
| 234 class PdfToPostScriptUtilityProcessHostClient | |
| 235 : public PdfConverterUtilityProcessHostClient { | |
| 236 public: | |
| 237 PdfToPostScriptUtilityProcessHostClient( | |
| 238 base::WeakPtr<PdfConverterImpl> converter, | |
| 239 const PdfRenderSettings& settings) | |
| 240 : PdfConverterUtilityProcessHostClient(converter, settings) {} | |
| 241 | |
| 242 // UtilityProcessHostClient implementation. | |
| 243 bool OnMessageReceived(const IPC::Message& message) override; | |
| 244 | |
| 245 private: | |
| 246 // Helpers to send messages and set process name | |
| 247 base::string16 GetName() const override; | |
| 248 std::unique_ptr<MetafilePlayer> GetFileFromTemp( | |
| 249 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> | |
| 250 temp_file) override; | |
| 251 void SendStartMessage(IPC::PlatformFileForTransit transit) override; | |
| 252 void SendGetPageMessage(int page_number, | |
| 253 IPC::PlatformFileForTransit transit) override; | |
| 254 void SendStopMessage() override; | |
| 255 | |
| 256 // Additional message handler needed for Pdf to PostScript | |
| 257 void OnPageDone(bool success); | |
| 258 | |
| 259 DISALLOW_COPY_AND_ASSIGN(PdfToPostScriptUtilityProcessHostClient); | |
| 260 }; | |
| 261 | 234 |
| 262 class PdfConverterImpl : public PdfConverter { | 235 class PdfConverterImpl : public PdfConverter { |
| 263 public: | 236 public: |
| 264 PdfConverterImpl() : weak_ptr_factory_(this) {} | 237 PdfConverterImpl() : weak_ptr_factory_(this) {} |
| 265 | 238 |
| 266 base::WeakPtr<PdfConverterImpl> GetWeakPtr() { | 239 base::WeakPtr<PdfConverterImpl> GetWeakPtr() { |
| 267 return weak_ptr_factory_.GetWeakPtr(); | 240 return weak_ptr_factory_.GetWeakPtr(); |
| 268 } | 241 } |
| 269 | 242 |
| 270 void GetPage(int page_number, | 243 void GetPage(int page_number, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 file_->Seek(base::File::FROM_BEGIN, 0); | 334 file_->Seek(base::File::FROM_BEGIN, 0); |
| 362 int64_t size = file_->GetLength(); | 335 int64_t size = file_->GetLength(); |
| 363 if (size <= 0) | 336 if (size <= 0) |
| 364 return false; | 337 return false; |
| 365 std::vector<char> data(size); | 338 std::vector<char> data(size); |
| 366 if (file_->ReadAtCurrentPos(data.data(), data.size()) != size) | 339 if (file_->ReadAtCurrentPos(data.data(), data.size()) != size) |
| 367 return false; | 340 return false; |
| 368 return emf->InitFromData(data.data(), data.size()); | 341 return emf->InitFromData(data.data(), data.size()); |
| 369 } | 342 } |
| 370 | 343 |
| 371 // Postscript metafile subclass to override SafePlayback. | |
| 372 class PostScriptMetaFile : public LazyEmf { | |
| 373 public: | |
| 374 PostScriptMetaFile(const scoped_refptr<RefCountedTempDir>& temp_dir, | |
| 375 ScopedTempFile file) | |
| 376 : LazyEmf(temp_dir, std::move(file)) {} | |
| 377 ~PostScriptMetaFile() override; | |
| 378 | |
| 379 protected: | |
| 380 // MetafilePlayer: | |
| 381 bool SafePlayback(HDC hdc) const override; | |
| 382 | |
| 383 DISALLOW_COPY_AND_ASSIGN(PostScriptMetaFile); | |
| 384 }; | |
| 385 | |
| 386 PostScriptMetaFile::~PostScriptMetaFile() {} | |
| 387 | |
| 388 bool PostScriptMetaFile::SafePlayback(HDC hdc) const { | 344 bool PostScriptMetaFile::SafePlayback(HDC hdc) const { |
| 389 // TODO(thestig): Fix destruction of metafiles. For some reasons | 345 // TODO(thestig): Fix destruction of metafiles. For some reasons |
| 390 // instances of Emf are not deleted. https://crbug.com/260806 | 346 // instances of Emf are not deleted. https://crbug.com/260806 |
| 391 // It's known that the Emf going to be played just once to a printer. So just | 347 // It's known that the Emf going to be played just once to a printer. So just |
| 392 // release |file_| before returning. | 348 // release |file_| before returning. |
| 393 Emf emf; | 349 Emf emf; |
| 394 if (!LoadEmf(&emf)) { | 350 if (!LoadEmf(&emf)) { |
| 395 Close(); | 351 Close(); |
| 396 return false; | 352 return false; |
| 397 } | 353 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 414 } | 370 } |
| 415 Close(); | 371 Close(); |
| 416 return true; | 372 return true; |
| 417 } | 373 } |
| 418 | 374 |
| 419 PdfConverterUtilityProcessHostClient::PdfConverterUtilityProcessHostClient( | 375 PdfConverterUtilityProcessHostClient::PdfConverterUtilityProcessHostClient( |
| 420 base::WeakPtr<PdfConverterImpl> converter, | 376 base::WeakPtr<PdfConverterImpl> converter, |
| 421 const PdfRenderSettings& settings) | 377 const PdfRenderSettings& settings) |
| 422 : converter_(converter), settings_(settings) {} | 378 : converter_(converter), settings_(settings) {} |
| 423 | 379 |
| 424 PdfConverterUtilityProcessHostClient::~PdfConverterUtilityProcessHostClient() {} | |
| 425 | |
| 426 void PdfConverterUtilityProcessHostClient::Start( | 380 void PdfConverterUtilityProcessHostClient::Start( |
| 427 const scoped_refptr<base::RefCountedMemory>& data, | 381 const scoped_refptr<base::RefCountedMemory>& data, |
| 428 const PdfConverter::StartCallback& start_callback) { | 382 const PdfConverter::StartCallback& start_callback) { |
| 429 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 383 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 430 BrowserThread::PostTask( | 384 BrowserThread::PostTask( |
| 431 BrowserThread::IO, FROM_HERE, | 385 BrowserThread::IO, FROM_HERE, |
| 432 base::Bind(&PdfConverterUtilityProcessHostClient::Start, this, data, | 386 base::Bind(&PdfConverterUtilityProcessHostClient::Start, this, data, |
| 433 start_callback)); | 387 start_callback)); |
| 434 return; | 388 return; |
| 435 } | 389 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 511 |
| 558 void PdfConverterUtilityProcessHostClient::OnFailed() { | 512 void PdfConverterUtilityProcessHostClient::OnFailed() { |
| 559 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 513 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 560 if (!start_callback_.is_null()) | 514 if (!start_callback_.is_null()) |
| 561 OnPageCount(0); | 515 OnPageCount(0); |
| 562 while (!get_page_callbacks_.empty()) | 516 while (!get_page_callbacks_.empty()) |
| 563 OnPageDone(false, 0.0f); | 517 OnPageDone(false, 0.0f); |
| 564 utility_process_host_.reset(); | 518 utility_process_host_.reset(); |
| 565 } | 519 } |
| 566 | 520 |
| 567 // PDF to Emf | 521 void PdfConverterUtilityProcessHostClient::OnPreCacheFontCharacters( |
| 568 PdfToEmfUtilityProcessHostClient::~PdfToEmfUtilityProcessHostClient() {} | |
| 569 | |
| 570 void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters( | |
| 571 const LOGFONT& font, | 522 const LOGFONT& font, |
| 572 const base::string16& str) { | 523 const base::string16& str) { |
| 573 // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache | 524 // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache |
| 574 // GDI fonts (http://crbug.com/383227), even when using DirectWrite. | 525 // GDI fonts (http://crbug.com/383227), even when using DirectWrite. |
| 575 // Eventually this shouldn't be added and should be moved to | 526 // Eventually this shouldn't be added and should be moved to |
| 576 // FontCacheDispatcher too. http://crbug.com/356346. | 527 // FontCacheDispatcher too. http://crbug.com/356346. |
| 577 | 528 |
| 578 // First, comments from FontCacheDispatcher::OnPreCacheFont do apply here too. | 529 // First, comments from FontCacheDispatcher::OnPreCacheFont do apply here too. |
| 579 // Except that for True Type fonts, | 530 // Except that for True Type fonts, |
| 580 // GetTextMetrics will not load the font in memory. | 531 // GetTextMetrics will not load the font in memory. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 592 | 543 |
| 593 SelectObject(hdc, old_font); | 544 SelectObject(hdc, old_font); |
| 594 DeleteObject(font_handle); | 545 DeleteObject(font_handle); |
| 595 | 546 |
| 596 HENHMETAFILE metafile = CloseEnhMetaFile(hdc); | 547 HENHMETAFILE metafile = CloseEnhMetaFile(hdc); |
| 597 | 548 |
| 598 if (metafile) | 549 if (metafile) |
| 599 DeleteEnhMetaFile(metafile); | 550 DeleteEnhMetaFile(metafile); |
| 600 } | 551 } |
| 601 | 552 |
| 602 bool PdfToEmfUtilityProcessHostClient::OnMessageReceived( | 553 bool PdfConverterUtilityProcessHostClient::OnMessageReceived( |
| 603 const IPC::Message& message) { | 554 const IPC::Message& message) { |
| 604 bool handled = true; | 555 bool handled = true; |
| 605 IPC_BEGIN_MESSAGE_MAP(PdfToEmfUtilityProcessHostClient, message) | 556 IPC_BEGIN_MESSAGE_MAP(PdfConverterUtilityProcessHostClient, message) |
| 606 IPC_MESSAGE_HANDLER( | 557 IPC_MESSAGE_HANDLER( |
| 607 ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, OnPageCount) | 558 ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, OnPageCount) |
| 608 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone, | 559 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone, |
| 609 OnPageDone) | 560 OnPageDone) |
| 610 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PreCacheFontCharacters, | 561 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PreCacheFontCharacters, |
| 611 OnPreCacheFontCharacters) | 562 OnPreCacheFontCharacters) |
| 612 IPC_MESSAGE_UNHANDLED(handled = false) | 563 IPC_MESSAGE_UNHANDLED(handled = false) |
| 613 IPC_END_MESSAGE_MAP() | 564 IPC_END_MESSAGE_MAP() |
| 614 return handled; | 565 return handled; |
| 615 } | 566 } |
| 616 | 567 |
| 617 base::string16 PdfToEmfUtilityProcessHostClient::GetName() const { | 568 base::string16 PdfConverterUtilityProcessHostClient::GetName() const { |
| 618 return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_EMF_CONVERTOR_NAME); | 569 return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PDF_CONVERTOR_NAME); |
| 619 } | 570 } |
| 620 | 571 |
| 621 std::unique_ptr<MetafilePlayer> | 572 void PdfConverterUtilityProcessHostClient::SendGetPageMessage( |
| 622 PdfToEmfUtilityProcessHostClient::GetFileFromTemp( | |
| 623 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> | |
| 624 temp_file) { | |
| 625 return base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_file)); | |
| 626 } | |
| 627 | |
| 628 void PdfToEmfUtilityProcessHostClient::SendGetPageMessage( | |
| 629 int page_number, | 573 int page_number, |
| 630 IPC::PlatformFileForTransit transit) { | 574 IPC::PlatformFileForTransit transit) { |
| 631 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(page_number, | 575 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(page_number, |
| 632 transit)); | 576 transit)); |
| 633 } | 577 } |
| 634 | 578 |
| 635 void PdfToEmfUtilityProcessHostClient::SendStartMessage( | 579 void PdfConverterUtilityProcessHostClient::SendStartMessage( |
| 636 IPC::PlatformFileForTransit transit) { | 580 IPC::PlatformFileForTransit transit) { |
| 637 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(transit, settings_)); | 581 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(transit, settings_)); |
| 638 } | 582 } |
| 639 | 583 |
| 640 void PdfToEmfUtilityProcessHostClient::SendStopMessage() { | 584 void PdfConverterUtilityProcessHostClient::SendStopMessage() { |
| 641 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); | 585 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); |
| 642 } | 586 } |
| 643 | 587 |
| 644 // Pdf to PostScript | |
| 645 bool PdfToPostScriptUtilityProcessHostClient::OnMessageReceived( | |
| 646 const IPC::Message& message) { | |
| 647 bool handled = true; | |
| 648 IPC_BEGIN_MESSAGE_MAP(PdfToPostScriptUtilityProcessHostClient, message) | |
| 649 IPC_MESSAGE_HANDLER( | |
| 650 ChromeUtilityHostMsg_RenderPDFPagesToPostScript_PageCount, OnPageCount) | |
| 651 IPC_MESSAGE_HANDLER( | |
| 652 ChromeUtilityHostMsg_RenderPDFPagesToPostScript_PageDone, OnPageDone) | |
| 653 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 654 IPC_END_MESSAGE_MAP() | |
| 655 return handled; | |
| 656 } | |
| 657 | |
| 658 base::string16 PdfToPostScriptUtilityProcessHostClient::GetName() const { | |
| 659 return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PS_CONVERTOR_NAME); | |
| 660 } | |
| 661 | |
| 662 std::unique_ptr<MetafilePlayer> | |
| 663 PdfToPostScriptUtilityProcessHostClient::GetFileFromTemp( | |
| 664 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> | |
| 665 temp_file) { | |
| 666 return base::MakeUnique<PostScriptMetaFile>(temp_dir_, std::move(temp_file)); | |
| 667 } | |
| 668 | |
| 669 void PdfToPostScriptUtilityProcessHostClient::SendGetPageMessage( | |
| 670 int page_number, | |
| 671 IPC::PlatformFileForTransit transit) { | |
| 672 Send(new ChromeUtilityMsg_RenderPDFPagesToPostScript_GetPage(page_number, | |
| 673 transit)); | |
| 674 } | |
| 675 | |
| 676 void PdfToPostScriptUtilityProcessHostClient::SendStartMessage( | |
| 677 IPC::PlatformFileForTransit transit) { | |
| 678 Send(new ChromeUtilityMsg_RenderPDFPagesToPostScript_Start(transit, | |
| 679 settings_)); | |
| 680 } | |
| 681 | |
| 682 void PdfToPostScriptUtilityProcessHostClient::SendStopMessage() { | |
| 683 Send(new ChromeUtilityMsg_RenderPDFPagesToPostScript_Stop()); | |
| 684 } | |
| 685 | |
| 686 void PdfToPostScriptUtilityProcessHostClient::OnPageDone(bool success) { | |
| 687 PdfConverterUtilityProcessHostClient::OnPageDone(success, 0.0f); | |
| 688 } | |
| 689 | |
| 690 void PdfConverterImpl::GetPage(int page_number, | 588 void PdfConverterImpl::GetPage(int page_number, |
| 691 const GetPageCallback& get_page_callback) { | 589 const GetPageCallback& get_page_callback) { |
| 692 utility_client_->GetPage(page_number, get_page_callback); | 590 utility_client_->GetPage(page_number, get_page_callback); |
| 693 } | 591 } |
| 694 | |
| 695 void PdfConverterImpl::RunCallback(const base::Closure& callback) { | 592 void PdfConverterImpl::RunCallback(const base::Closure& callback) { |
| 696 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 593 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 697 callback.Run(); | 594 callback.Run(); |
| 698 } | 595 } |
| 699 | 596 |
| 700 } // namespace | 597 } // namespace |
| 701 | 598 |
| 702 PdfConverter::~PdfConverter() {} | 599 PdfConverter::~PdfConverter() {} |
| 703 | 600 |
| 704 // static | 601 // static |
| 705 std::unique_ptr<PdfConverter> PdfConverter::StartPdfToEmfConverter( | 602 std::unique_ptr<PdfConverter> PdfConverter::StartConverter( |
| 706 const scoped_refptr<base::RefCountedMemory>& data, | 603 const scoped_refptr<base::RefCountedMemory>& data, |
| 707 const PdfRenderSettings& conversion_settings, | 604 const PdfRenderSettings& conversion_settings, |
| 708 const StartCallback& start_callback) { | 605 const StartCallback& start_callback) { |
| 709 std::unique_ptr<PdfConverterImpl> converter = | 606 std::unique_ptr<PdfConverterImpl> converter = |
| 710 base::MakeUnique<PdfConverterImpl>(); | 607 base::MakeUnique<PdfConverterImpl>(); |
| 711 converter->Start(new PdfToEmfUtilityProcessHostClient(converter->GetWeakPtr(), | 608 converter->Start(new PdfConverterUtilityProcessHostClient( |
| 712 conversion_settings), | |
| 713 data, start_callback); | |
| 714 return std::move(converter); | |
| 715 } | |
| 716 | |
| 717 // static | |
| 718 std::unique_ptr<PdfConverter> PdfConverter::StartPdfToPostScriptConverter( | |
| 719 const scoped_refptr<base::RefCountedMemory>& data, | |
| 720 const PdfRenderSettings& conversion_settings, | |
| 721 const StartCallback& start_callback) { | |
| 722 std::unique_ptr<PdfConverterImpl> converter = | |
| 723 base::MakeUnique<PdfConverterImpl>(); | |
| 724 converter->Start(new PdfToPostScriptUtilityProcessHostClient( | |
| 725 converter->GetWeakPtr(), conversion_settings), | 609 converter->GetWeakPtr(), conversion_settings), |
| 726 data, start_callback); | 610 data, start_callback); |
| 727 return std::move(converter); | 611 return std::move(converter); |
| 728 } | 612 } |
| 729 | 613 |
| 730 } // namespace printing | 614 } // namespace printing |
| OLD | NEW |