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.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_RENDERER_ELECTRON_API_SERVICE_IMPL_H_
|
|
|
|
#define SHELL_RENDERER_ELECTRON_API_SERVICE_IMPL_H_
|
2019-04-02 22:38:16 +00:00
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
#include <queue>
|
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
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2019-04-02 22:38:16 +00:00
|
|
|
|
|
|
|
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-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,
|
2019-10-09 17:59:08 +00:00
|
|
|
blink::CloneableMessage arguments,
|
2019-04-02 22:38:16 +00:00
|
|
|
int32_t sender_id) 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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ElectronApiServiceImpl);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2019-04-02 22:38:16 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_RENDERER_ELECTRON_API_SERVICE_IMPL_H_
|