pdf_viewer_handler.h 1.9 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_HANDLER_H_
  5. #define ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_HANDLER_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 "atom/browser/web_contents_zoom_controller.h"
  11. #include "base/macros.h"
  12. #include "content/public/browser/host_zoom_map.h"
  13. #include "content/public/browser/web_ui_message_handler.h"
  14. namespace base {
  15. class ListValue;
  16. }
  17. namespace content {
  18. struct StreamInfo;
  19. }
  20. namespace atom {
  21. class PdfViewerHandler : public content::WebUIMessageHandler,
  22. public WebContentsZoomController::Observer {
  23. public:
  24. explicit PdfViewerHandler(const std::string& original_url);
  25. ~PdfViewerHandler() override;
  26. void SetPdfResourceStream(content::StreamInfo* stream);
  27. protected:
  28. // WebUIMessageHandler implementation.
  29. void RegisterMessages() override;
  30. void OnJavascriptAllowed() override;
  31. void OnJavascriptDisallowed() override;
  32. private:
  33. void Initialize(const base::ListValue* args);
  34. void GetDefaultZoom(const base::ListValue* args);
  35. void GetInitialZoom(const base::ListValue* args);
  36. void SetZoom(const base::ListValue* args);
  37. void GetStrings(const base::ListValue* args);
  38. void Reload(const base::ListValue* args);
  39. void OnZoomLevelChanged(content::WebContents* web_contents,
  40. double level,
  41. bool is_temporary);
  42. void AddObserver();
  43. void RemoveObserver();
  44. std::unique_ptr<base::Value> initialize_callback_id_;
  45. content::StreamInfo* stream_ = nullptr;
  46. std::string original_url_;
  47. DISALLOW_COPY_AND_ASSIGN(PdfViewerHandler);
  48. };
  49. } // namespace atom
  50. #endif // ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_HANDLER_H_