2019-04-02 22:38:16 +00:00
|
|
|
// Copyright (c) 2019 Slack Technologies, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_RENDERER_ELECTRON_API_SERVICE_IMPL_H_
|
|
|
|
#define ELECTRON_SHELL_RENDERER_ELECTRON_API_SERVICE_IMPL_H_
|
2019-04-02 22:38:16 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2019-08-12 17:38:41 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2019-04-02 22:38:16 +00:00
|
|
|
#include "content/public/renderer/render_frame.h"
|
|
|
|
#include "content/public/renderer/render_frame_observer.h"
|
2019-10-09 17:59:08 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "electron/shell/common/api/api.mojom.h"
|
2021-02-09 20:16:21 +00:00
|
|
|
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
|
|
|
#include "mojo/public/cpp/bindings/receiver.h"
|
2019-04-02 22:38:16 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class RendererClientBase;
|
|
|
|
|
|
|
|
class ElectronApiServiceImpl : public mojom::ElectronRenderer,
|
|
|
|
public content::RenderFrameObserver {
|
|
|
|
public:
|
2019-08-12 17:38:41 +00:00
|
|
|
ElectronApiServiceImpl(content::RenderFrame* render_frame,
|
|
|
|
RendererClientBase* renderer_client);
|
2021-02-09 20:16:21 +00:00
|
|
|
~ElectronApiServiceImpl() override;
|
2019-08-12 17:38:41 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
ElectronApiServiceImpl(const ElectronApiServiceImpl&) = delete;
|
|
|
|
ElectronApiServiceImpl& operator=(const ElectronApiServiceImpl&) = delete;
|
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
void BindTo(mojo::PendingReceiver<mojom::ElectronRenderer> receiver);
|
2019-04-02 22:38:16 +00:00
|
|
|
|
|
|
|
void Message(bool internal,
|
|
|
|
const std::string& channel,
|
2023-08-28 14:29:27 +00:00
|
|
|
blink::CloneableMessage arguments) override;
|
2020-03-12 01:07:54 +00:00
|
|
|
void ReceivePostMessage(const std::string& channel,
|
|
|
|
blink::TransferableMessage message) override;
|
2019-04-02 22:38:16 +00:00
|
|
|
void TakeHeapSnapshot(mojo::ScopedHandle file,
|
|
|
|
TakeHeapSnapshotCallback callback) override;
|
2021-02-09 20:16:21 +00:00
|
|
|
void ProcessPendingMessages();
|
2019-04-02 22:38:16 +00:00
|
|
|
|
2019-08-12 17:38:41 +00:00
|
|
|
base::WeakPtr<ElectronApiServiceImpl> GetWeakPtr() {
|
|
|
|
return weak_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
void OnInterfaceRequestForFrame(
|
|
|
|
const std::string& interface_name,
|
|
|
|
mojo::ScopedMessagePipeHandle* interface_pipe) override;
|
2019-04-02 22:38:16 +00:00
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
private:
|
2019-04-02 22:38:16 +00:00
|
|
|
// RenderFrameObserver implementation.
|
2019-08-12 17:38:41 +00:00
|
|
|
void DidCreateDocumentElement() override;
|
2019-04-02 22:38:16 +00:00
|
|
|
void OnDestruct() override;
|
|
|
|
|
2019-08-12 17:38:41 +00:00
|
|
|
void OnConnectionError();
|
|
|
|
|
|
|
|
// Whether the DOM document element has been created.
|
|
|
|
bool document_created_ = false;
|
2021-02-09 20:16:21 +00:00
|
|
|
service_manager::BinderRegistry registry_;
|
2019-08-12 17:38:41 +00:00
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
mojo::PendingReceiver<mojom::ElectronRenderer> pending_receiver_;
|
|
|
|
mojo::Receiver<mojom::ElectronRenderer> receiver_{this};
|
2019-04-02 22:38:16 +00:00
|
|
|
|
2024-07-03 19:58:15 +00:00
|
|
|
raw_ptr<RendererClientBase> renderer_client_;
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<ElectronApiServiceImpl> weak_factory_{this};
|
2019-04-02 22:38:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_RENDERER_ELECTRON_API_SERVICE_IMPL_H_
|