electron_web_contents_utility_handler_impl.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2022 Slack Technologies, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_
  5. #define ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_
  6. #include <vector>
  7. #include "base/memory/weak_ptr.h"
  8. #include "content/public/browser/global_routing_id.h"
  9. #include "content/public/browser/web_contents_observer.h"
  10. #include "electron/shell/common/web_contents_utility.mojom.h"
  11. #include "mojo/public/cpp/bindings/associated_receiver.h"
  12. #include "shell/browser/api/electron_api_web_contents.h"
  13. namespace content {
  14. class RenderFrameHost;
  15. }
  16. namespace electron {
  17. class ElectronWebContentsUtilityHandlerImpl
  18. : public mojom::ElectronWebContentsUtility,
  19. private content::WebContentsObserver {
  20. public:
  21. explicit ElectronWebContentsUtilityHandlerImpl(
  22. content::RenderFrameHost* render_frame_host,
  23. mojo::PendingAssociatedReceiver<mojom::ElectronWebContentsUtility>
  24. receiver);
  25. static void Create(
  26. content::RenderFrameHost* frame_host,
  27. mojo::PendingAssociatedReceiver<mojom::ElectronWebContentsUtility>
  28. receiver);
  29. // disable copy
  30. ElectronWebContentsUtilityHandlerImpl(
  31. const ElectronWebContentsUtilityHandlerImpl&) = delete;
  32. ElectronWebContentsUtilityHandlerImpl& operator=(
  33. const ElectronWebContentsUtilityHandlerImpl&) = delete;
  34. // mojom::ElectronWebContentsUtility:
  35. void OnFirstNonEmptyLayout() override;
  36. void SetTemporaryZoomLevel(double level) override;
  37. void DoGetZoomLevel(DoGetZoomLevelCallback callback) override;
  38. void CanAccessClipboardDeprecated(
  39. mojom::PermissionName name,
  40. const blink::LocalFrameToken& frame_token,
  41. CanAccessClipboardDeprecatedCallback callback) override;
  42. base::WeakPtr<ElectronWebContentsUtilityHandlerImpl> GetWeakPtr() {
  43. return weak_factory_.GetWeakPtr();
  44. }
  45. private:
  46. ~ElectronWebContentsUtilityHandlerImpl() override;
  47. // content::WebContentsObserver:
  48. void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
  49. void OnConnectionError();
  50. content::RenderFrameHost* GetRenderFrameHost();
  51. content::GlobalRenderFrameHostToken render_frame_host_token_;
  52. mojo::AssociatedReceiver<mojom::ElectronWebContentsUtility> receiver_{this};
  53. base::WeakPtrFactory<ElectronWebContentsUtilityHandlerImpl> weak_factory_{
  54. this};
  55. };
  56. } // namespace electron
  57. #endif // ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_