electron_web_contents_utility_handler_impl.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "base/memory/weak_ptr.h"
  7. #include "content/public/browser/global_routing_id.h"
  8. #include "content/public/browser/web_contents_observer.h"
  9. #include "electron/shell/common/web_contents_utility.mojom.h"
  10. #include "mojo/public/cpp/bindings/associated_receiver.h"
  11. #include "shell/browser/api/electron_api_web_contents.h"
  12. namespace content {
  13. class RenderFrameHost;
  14. }
  15. namespace electron {
  16. class ElectronWebContentsUtilityHandlerImpl
  17. : public mojom::ElectronWebContentsUtility,
  18. private content::WebContentsObserver {
  19. public:
  20. explicit ElectronWebContentsUtilityHandlerImpl(
  21. content::RenderFrameHost* render_frame_host,
  22. mojo::PendingAssociatedReceiver<mojom::ElectronWebContentsUtility>
  23. receiver);
  24. static void Create(
  25. content::RenderFrameHost* frame_host,
  26. mojo::PendingAssociatedReceiver<mojom::ElectronWebContentsUtility>
  27. receiver);
  28. // disable copy
  29. ElectronWebContentsUtilityHandlerImpl(
  30. const ElectronWebContentsUtilityHandlerImpl&) = delete;
  31. ElectronWebContentsUtilityHandlerImpl& operator=(
  32. const ElectronWebContentsUtilityHandlerImpl&) = delete;
  33. // mojom::ElectronWebContentsUtility:
  34. void OnFirstNonEmptyLayout() override;
  35. void SetTemporaryZoomLevel(double level) override;
  36. void CanAccessClipboardDeprecated(
  37. mojom::PermissionName name,
  38. const blink::LocalFrameToken& frame_token,
  39. CanAccessClipboardDeprecatedCallback callback) override;
  40. base::WeakPtr<ElectronWebContentsUtilityHandlerImpl> GetWeakPtr() {
  41. return weak_factory_.GetWeakPtr();
  42. }
  43. private:
  44. ~ElectronWebContentsUtilityHandlerImpl() override;
  45. // content::WebContentsObserver:
  46. void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
  47. void OnConnectionError();
  48. content::RenderFrameHost* GetRenderFrameHost();
  49. content::GlobalRenderFrameHostToken render_frame_host_token_;
  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_