-
Notifications
You must be signed in to change notification settings - Fork 17k
Expand file tree
/
Copy pathelectron_api_ipc_handler_impl.h
More file actions
89 lines (71 loc) · 2.96 KB
/
electron_api_ipc_handler_impl.h
File metadata and controls
89 lines (71 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) 2022 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_
#define ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_
#include <string>
#include "base/memory/weak_ptr.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/common/api/api.mojom.h"
namespace content {
class RenderFrameHost;
}
namespace gin {
template <typename T>
class WeakCell;
} // namespace gin
namespace electron {
class ElectronApiIPCHandlerImpl : public mojom::ElectronApiIPC,
private content::WebContentsObserver {
public:
explicit ElectronApiIPCHandlerImpl(
content::RenderFrameHost* render_frame_host,
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver);
static void Create(
content::RenderFrameHost* frame_host,
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver);
// disable copy
ElectronApiIPCHandlerImpl(const ElectronApiIPCHandlerImpl&) = delete;
ElectronApiIPCHandlerImpl& operator=(const ElectronApiIPCHandlerImpl&) =
delete;
// mojom::ElectronApiIPC:
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;
void MessageHost(const std::string& channel,
blink::CloneableMessage arguments) override;
base::WeakPtr<ElectronApiIPCHandlerImpl> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
private:
~ElectronApiIPCHandlerImpl() override;
// content::WebContentsObserver:
void WebContentsDestroyed() override;
void OnConnectionError();
content::RenderFrameHost* GetRenderFrameHost();
gin::WeakCell<api::Session>* GetSession();
gin_helper::internal::Event* MakeIPCEvent(
v8::Isolate* isolate,
api::Session* session,
bool internal,
electron::mojom::ElectronApiIPC::InvokeCallback callback =
electron::mojom::ElectronApiIPC::InvokeCallback());
content::GlobalRenderFrameHostId render_frame_host_id_;
mojo::AssociatedReceiver<mojom::ElectronApiIPC> receiver_{this};
base::WeakPtrFactory<ElectronApiIPCHandlerImpl> weak_factory_{this};
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_API_IPC_HANDLER_IMPL_H_