electron_web_contents_utility_handler_impl.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. 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. base::WeakPtr<ElectronWebContentsUtilityHandlerImpl> GetWeakPtr() {
  39. return weak_factory_.GetWeakPtr();
  40. }
  41. private:
  42. ~ElectronWebContentsUtilityHandlerImpl() override;
  43. // content::WebContentsObserver:
  44. void WebContentsDestroyed() override;
  45. void OnConnectionError();
  46. content::RenderFrameHost* GetRenderFrameHost();
  47. content::GlobalRenderFrameHostId render_frame_host_id_;
  48. mojo::AssociatedReceiver<mojom::ElectronWebContentsUtility> receiver_{this};
  49. base::WeakPtrFactory<ElectronWebContentsUtilityHandlerImpl> weak_factory_{
  50. this};
  51. };
  52. } // namespace electron
  53. #endif // ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_