2022-03-19 02:50:05 +00:00
|
|
|
// Copyright (c) 2022 Slack Technologies, Inc.
|
2020-12-14 18:57:36 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2022-03-19 02:50:05 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_
|
2020-12-14 18:57:36 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
|
|
#include "electron/shell/common/api/api.mojom.h"
|
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class RenderFrameHost;
|
2021-07-02 00:51:37 +00:00
|
|
|
}
|
2020-12-14 18:57:36 +00:00
|
|
|
|
|
|
|
namespace electron {
|
2022-03-19 02:50:05 +00:00
|
|
|
class ElectronApiIPCHandlerImpl : public mojom::ElectronApiIPC,
|
|
|
|
public content::WebContentsObserver {
|
2020-12-14 18:57:36 +00:00
|
|
|
public:
|
2022-03-19 02:50:05 +00:00
|
|
|
explicit ElectronApiIPCHandlerImpl(
|
2020-12-14 18:57:36 +00:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2022-03-19 02:50:05 +00:00
|
|
|
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver);
|
2020-12-14 18:57:36 +00:00
|
|
|
|
2022-02-08 16:33:21 +00:00
|
|
|
static void Create(
|
|
|
|
content::RenderFrameHost* frame_host,
|
2022-03-19 02:50:05 +00:00
|
|
|
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver);
|
2020-12-14 18:57:36 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
2022-03-19 02:50:05 +00:00
|
|
|
ElectronApiIPCHandlerImpl(const ElectronApiIPCHandlerImpl&) = delete;
|
|
|
|
ElectronApiIPCHandlerImpl& operator=(const ElectronApiIPCHandlerImpl&) =
|
2021-11-03 11:41:45 +00:00
|
|
|
delete;
|
|
|
|
|
2022-03-19 02:50:05 +00:00
|
|
|
// mojom::ElectronApiIPC:
|
2020-12-14 18:57:36 +00:00
|
|
|
void Message(bool internal,
|
|
|
|
const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments) override;
|
|
|
|
void Invoke(bool internal,
|
|
|
|
const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments,
|
|
|
|
InvokeCallback callback) override;
|
|
|
|
void ReceivePostMessage(const std::string& channel,
|
|
|
|
blink::TransferableMessage message) override;
|
|
|
|
void MessageSync(bool internal,
|
|
|
|
const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments,
|
|
|
|
MessageSyncCallback callback) override;
|
2021-06-18 04:26:18 +00:00
|
|
|
void MessageTo(int32_t web_contents_id,
|
2020-12-14 18:57:36 +00:00
|
|
|
const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments) override;
|
|
|
|
void MessageHost(const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments) override;
|
|
|
|
|
2022-03-19 02:50:05 +00:00
|
|
|
base::WeakPtr<ElectronApiIPCHandlerImpl> GetWeakPtr() {
|
2020-12-14 18:57:36 +00:00
|
|
|
return weak_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-03-19 02:50:05 +00:00
|
|
|
~ElectronApiIPCHandlerImpl() override;
|
2020-12-14 18:57:36 +00:00
|
|
|
|
|
|
|
// content::WebContentsObserver:
|
|
|
|
void WebContentsDestroyed() override;
|
|
|
|
|
|
|
|
void OnConnectionError();
|
|
|
|
|
|
|
|
content::RenderFrameHost* GetRenderFrameHost();
|
|
|
|
|
|
|
|
const int render_process_id_;
|
|
|
|
const int render_frame_id_;
|
|
|
|
|
2022-03-19 02:50:05 +00:00
|
|
|
mojo::AssociatedReceiver<mojom::ElectronApiIPC> receiver_{this};
|
2020-12-14 18:57:36 +00:00
|
|
|
|
2022-03-19 02:50:05 +00:00
|
|
|
base::WeakPtrFactory<ElectronApiIPCHandlerImpl> weak_factory_{this};
|
2020-12-14 18:57:36 +00:00
|
|
|
};
|
|
|
|
} // namespace electron
|
2022-03-19 02:50:05 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_
|