electron_browser_handler_impl.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) 2019 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 SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_
  5. #define SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/macros.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "content/public/browser/web_contents_observer.h"
  11. #include "electron/shell/common/api/api.mojom.h"
  12. #include "shell/browser/api/electron_api_web_contents.h"
  13. namespace content {
  14. class RenderFrameHost;
  15. } // namespace content
  16. namespace electron {
  17. class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
  18. public content::WebContentsObserver {
  19. public:
  20. explicit ElectronBrowserHandlerImpl(
  21. content::RenderFrameHost* render_frame_host,
  22. mojo::PendingReceiver<mojom::ElectronBrowser> receiver);
  23. static void Create(content::RenderFrameHost* frame_host,
  24. mojo::PendingReceiver<mojom::ElectronBrowser> receiver);
  25. // mojom::ElectronBrowser:
  26. void Message(bool internal,
  27. const std::string& channel,
  28. blink::CloneableMessage arguments) override;
  29. void Invoke(bool internal,
  30. const std::string& channel,
  31. blink::CloneableMessage arguments,
  32. InvokeCallback callback) override;
  33. void OnFirstNonEmptyLayout() override;
  34. void ReceivePostMessage(const std::string& channel,
  35. blink::TransferableMessage message) override;
  36. void MessageSync(bool internal,
  37. const std::string& channel,
  38. blink::CloneableMessage arguments,
  39. MessageSyncCallback callback) override;
  40. void MessageTo(bool internal,
  41. int32_t web_contents_id,
  42. const std::string& channel,
  43. blink::CloneableMessage arguments) override;
  44. void MessageHost(const std::string& channel,
  45. blink::CloneableMessage arguments) override;
  46. void UpdateDraggableRegions(
  47. std::vector<mojom::DraggableRegionPtr> regions) override;
  48. void SetTemporaryZoomLevel(double level) override;
  49. void DoGetZoomLevel(DoGetZoomLevelCallback callback) override;
  50. base::WeakPtr<ElectronBrowserHandlerImpl> GetWeakPtr() {
  51. return weak_factory_.GetWeakPtr();
  52. }
  53. private:
  54. ~ElectronBrowserHandlerImpl() override;
  55. // content::WebContentsObserver:
  56. void WebContentsDestroyed() override;
  57. void OnConnectionError();
  58. content::RenderFrameHost* GetRenderFrameHost();
  59. const int render_process_id_;
  60. const int render_frame_id_;
  61. mojo::Receiver<mojom::ElectronBrowser> receiver_{this};
  62. base::WeakPtrFactory<ElectronBrowserHandlerImpl> weak_factory_;
  63. DISALLOW_COPY_AND_ASSIGN(ElectronBrowserHandlerImpl);
  64. };
  65. } // namespace electron
  66. #endif // SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_