pdf_viewer_ui.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_
  5. #define ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_
  6. #ifndef ENABLE_PDF_VIEWER
  7. #error("This header can only be used when enable_pdf_viewer gyp flag is enabled") // NOLINT
  8. #endif // defined(ENABLE_PDF_VIEWER)
  9. #include <string>
  10. #include "base/macros.h"
  11. #include "content/public/browser/web_contents_observer.h"
  12. #include "content/public/browser/web_ui_controller.h"
  13. #include "ipc/ipc_message.h"
  14. namespace content {
  15. class BrowserContext;
  16. struct StreamInfo;
  17. } // namespace content
  18. namespace atom {
  19. class PdfViewerHandler;
  20. class PdfViewerUI : public content::WebUIController,
  21. public content::WebContentsObserver {
  22. public:
  23. PdfViewerUI(content::BrowserContext* browser_context,
  24. content::WebUI* web_ui,
  25. const std::string& src);
  26. ~PdfViewerUI() override;
  27. // content::WebContentsObserver:
  28. bool OnMessageReceived(const IPC::Message& message,
  29. content::RenderFrameHost* render_frame_host) override;
  30. void RenderFrameCreated(content::RenderFrameHost* rfh) override;
  31. private:
  32. using StreamResponseCallback =
  33. base::OnceCallback<void(std::unique_ptr<content::StreamInfo>)>;
  34. class ResourceRequester;
  35. void OnPdfStreamCreated(std::unique_ptr<content::StreamInfo> stream_info);
  36. void OnSaveURLAs(const GURL& url, const content::Referrer& referrer);
  37. // Source URL from where the PDF originates.
  38. std::string src_;
  39. PdfViewerHandler* pdf_handler_;
  40. scoped_refptr<ResourceRequester> resource_requester_;
  41. // Pdf Resource stream.
  42. std::unique_ptr<content::StreamInfo> stream_;
  43. DISALLOW_COPY_AND_ASSIGN(PdfViewerUI);
  44. };
  45. } // namespace atom
  46. #endif // ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_