print_preview_message_handler.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_
  5. #define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_
  6. #include <map>
  7. #include "atom/browser/api/atom_api_web_contents.h"
  8. #include "base/compiler_specific.h"
  9. #include "content/public/browser/web_contents_observer.h"
  10. #include "content/public/browser/web_contents_user_data.h"
  11. struct PrintHostMsg_DidPreviewDocument_Params;
  12. namespace content {
  13. class WebContents;
  14. }
  15. namespace printing {
  16. struct PageSizeMargins;
  17. // Manages the print preview handling for a WebContents.
  18. class PrintPreviewMessageHandler
  19. : public content::WebContentsObserver,
  20. public content::WebContentsUserData<PrintPreviewMessageHandler> {
  21. public:
  22. ~PrintPreviewMessageHandler() override;
  23. // content::WebContentsObserver implementation.
  24. bool OnMessageReceived(const IPC::Message& message,
  25. content::RenderFrameHost* render_frame_host) override;
  26. void PrintToPDF(const base::DictionaryValue& options,
  27. const atom::api::WebContents::PrintToPDFCallback& callback);
  28. private:
  29. typedef std::map<int, atom::api::WebContents::PrintToPDFCallback>
  30. PrintToPDFCallbackMap;
  31. explicit PrintPreviewMessageHandler(content::WebContents* web_contents);
  32. friend class content::WebContentsUserData<PrintPreviewMessageHandler>;
  33. // Message handlers.
  34. void OnMetafileReadyForPrinting(
  35. const PrintHostMsg_DidPreviewDocument_Params& params);
  36. void OnPrintPreviewFailed(int document_cookie, int request_id);
  37. void RunPrintToPDFCallback(int request_id, uint32_t data_size, char* data);
  38. PrintToPDFCallbackMap print_to_pdf_callback_map_;
  39. DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler);
  40. };
  41. } // namespace printing
  42. #endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_