electron_web_contents_utility_handler_impl.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 CanAccessClipboardDeprecated(
  38. mojom::PermissionName name,
  39. const blink::LocalFrameToken& frame_token,
  40. CanAccessClipboardDeprecatedCallback callback) override;
  41. base::WeakPtr<ElectronWebContentsUtilityHandlerImpl> GetWeakPtr() {
  42. return weak_factory_.GetWeakPtr();
  43. }
  44. private:
  45. ~ElectronWebContentsUtilityHandlerImpl() override;
  46. // content::WebContentsObserver:
  47. void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
  48. void OnConnectionError();
  49. content::RenderFrameHost* GetRenderFrameHost();
  50. content::GlobalRenderFrameHostToken render_frame_host_token_;
  51. mojo::AssociatedReceiver<mojom::ElectronWebContentsUtility> receiver_{this};
  52. base::WeakPtrFactory<ElectronWebContentsUtilityHandlerImpl> weak_factory_{
  53. this};
  54. };
  55. } // namespace electron
  56. #endif // ELECTRON_SHELL_BROWSER_ELECTRON_WEB_CONTENTS_UTILITY_HANDLER_IMPL_H_