2022-10-20 08:49:49 +03:00
|
|
|
// Copyright (c) 2022 Microsoft, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ELECTRON_SHELL_SERVICES_NODE_NODE_SERVICE_H_
|
|
|
|
#define ELECTRON_SHELL_SERVICES_NODE_NODE_SERVICE_H_
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
2024-01-05 00:20:37 +03:00
|
|
|
#include "mojo/public/cpp/bindings/pending_remote.h"
|
2022-10-20 08:49:49 +03:00
|
|
|
#include "mojo/public/cpp/bindings/receiver.h"
|
2024-01-05 00:20:37 +03:00
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
|
|
|
#include "services/network/public/cpp/shared_url_loader_factory.h"
|
|
|
|
#include "services/network/public/mojom/host_resolver.mojom.h"
|
|
|
|
#include "services/network/public/mojom/url_loader_factory.mojom-forward.h"
|
2022-10-20 08:49:49 +03:00
|
|
|
#include "shell/services/node/public/mojom/node_service.mojom.h"
|
|
|
|
|
2023-08-23 16:56:16 +03:00
|
|
|
namespace node {
|
|
|
|
|
|
|
|
class Environment;
|
|
|
|
|
|
|
|
} // namespace node
|
|
|
|
|
2022-10-20 08:49:49 +03:00
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class ElectronBindings;
|
|
|
|
class JavascriptEnvironment;
|
|
|
|
class NodeBindings;
|
|
|
|
|
2024-01-05 00:20:37 +03:00
|
|
|
class URLLoaderBundle {
|
|
|
|
public:
|
|
|
|
URLLoaderBundle();
|
|
|
|
~URLLoaderBundle();
|
|
|
|
|
|
|
|
URLLoaderBundle(const URLLoaderBundle&) = delete;
|
|
|
|
URLLoaderBundle& operator=(const URLLoaderBundle&) = delete;
|
|
|
|
|
|
|
|
static URLLoaderBundle* GetInstance();
|
|
|
|
void SetURLLoaderFactory(
|
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderFactory> factory,
|
2024-08-14 05:36:47 +03:00
|
|
|
mojo::Remote<network::mojom::HostResolver> host_resolver,
|
|
|
|
bool use_network_observer_from_url_loader_factory);
|
2024-01-05 00:20:37 +03:00
|
|
|
scoped_refptr<network::SharedURLLoaderFactory> GetSharedURLLoaderFactory();
|
|
|
|
network::mojom::HostResolver* GetHostResolver();
|
2024-08-14 05:36:47 +03:00
|
|
|
bool ShouldUseNetworkObserverfromURLLoaderFactory() const;
|
2024-01-05 00:20:37 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
scoped_refptr<network::SharedURLLoaderFactory> factory_;
|
|
|
|
mojo::Remote<network::mojom::HostResolver> host_resolver_;
|
2024-08-14 05:36:47 +03:00
|
|
|
bool should_use_network_observer_from_url_loader_factory_ = false;
|
2024-01-05 00:20:37 +03:00
|
|
|
};
|
|
|
|
|
2022-10-20 08:49:49 +03:00
|
|
|
class NodeService : public node::mojom::NodeService {
|
|
|
|
public:
|
|
|
|
explicit NodeService(
|
|
|
|
mojo::PendingReceiver<node::mojom::NodeService> receiver);
|
|
|
|
~NodeService() override;
|
|
|
|
|
|
|
|
NodeService(const NodeService&) = delete;
|
|
|
|
NodeService& operator=(const NodeService&) = delete;
|
|
|
|
|
|
|
|
// mojom::NodeService implementation:
|
2024-09-27 04:17:06 +03:00
|
|
|
void Initialize(node::mojom::NodeServiceParamsPtr params,
|
|
|
|
mojo::PendingRemote<node::mojom::NodeServiceClient>
|
|
|
|
client_pending_remote) override;
|
2022-10-20 08:49:49 +03:00
|
|
|
|
|
|
|
private:
|
2024-02-10 00:44:35 +03:00
|
|
|
// This needs to be initialized first so that it can be destroyed last
|
|
|
|
// after the node::Environment is destroyed. This ensures that if
|
|
|
|
// there are crashes in the node::Environment destructor, they
|
|
|
|
// will be propagated to the exit handler.
|
|
|
|
mojo::Receiver<node::mojom::NodeService> receiver_{this};
|
|
|
|
|
2022-10-20 08:49:49 +03:00
|
|
|
bool node_env_stopped_ = false;
|
2023-09-12 13:27:14 +03:00
|
|
|
|
|
|
|
const std::unique_ptr<NodeBindings> node_bindings_;
|
|
|
|
|
|
|
|
// depends-on: node_bindings_'s uv_loop
|
|
|
|
const std::unique_ptr<ElectronBindings> electron_bindings_;
|
|
|
|
|
|
|
|
// depends-on: node_bindings_'s uv_loop
|
2022-10-20 08:49:49 +03:00
|
|
|
std::unique_ptr<JavascriptEnvironment> js_env_;
|
2023-09-12 13:27:14 +03:00
|
|
|
|
|
|
|
// depends-on: js_env_'s isolate
|
2023-08-23 16:56:16 +03:00
|
|
|
std::shared_ptr<node::Environment> node_env_;
|
2022-10-20 08:49:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
|
|
|
#endif // ELECTRON_SHELL_SERVICES_NODE_NODE_SERVICE_H_
|