electron_web_contents_utility_handler_impl.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/api/api.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. public 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 UpdateDraggableRegions(
  37. std::vector<mojom::DraggableRegionPtr> regions) override;
  38. void SetTemporaryZoomLevel(double level) override;
  39. void DoGetZoomLevel(DoGetZoomLevelCallback callback) override;
  40. base::WeakPtr<ElectronWebContentsUtilityHandlerImpl> GetWeakPtr() {
  41. return weak_factory_.GetWeakPtr();
  42. }
  43. private:
  44. ~ElectronWebContentsUtilityHandlerImpl() override;
  45. // content::WebContentsObserver:
  46. void WebContentsDestroyed() override;
  47. void OnConnectionError();
  48. content::RenderFrameHost* GetRenderFrameHost();
  49. content::GlobalRenderFrameHostId render_frame_host_id_;
  50. mojo::AssociatedReceiver<mojom::ElectronWebContentsUtility> receiver_{this};
  51. base::WeakPtrFactory<ElectronWebContentsUtilityHandlerImpl> weak_factory_{
  52. this};
  53. };
  54. } // namespace electron
  55. #endif // ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_