2017-03-07 10:35:03 +00:00
|
|
|
// Copyright (c) 2017 GitHub, 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_WEB_WORKER_OBSERVER_H_
|
|
|
|
#define ELECTRON_SHELL_RENDERER_WEB_WORKER_OBSERVER_H_
|
2017-03-07 10:35:03 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2024-01-05 11:18:31 +00:00
|
|
|
#include "base/containers/flat_set.h"
|
2024-07-29 17:42:57 +00:00
|
|
|
#include "v8/include/v8-forward.h"
|
2017-03-07 10:35:03 +00:00
|
|
|
|
2023-08-23 13:56:16 +00:00
|
|
|
namespace node {
|
|
|
|
|
|
|
|
class Environment;
|
|
|
|
|
|
|
|
} // namespace node
|
|
|
|
|
2017-03-07 10:35:03 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2019-03-18 19:37:06 +00:00
|
|
|
class ElectronBindings;
|
2017-03-07 10:35:03 +00:00
|
|
|
class NodeBindings;
|
|
|
|
|
|
|
|
// Watches for WebWorker and insert node integration to it.
|
|
|
|
class WebWorkerObserver {
|
|
|
|
public:
|
2023-01-31 11:29:29 +00:00
|
|
|
WebWorkerObserver();
|
|
|
|
~WebWorkerObserver();
|
|
|
|
|
2017-03-07 10:35:03 +00:00
|
|
|
// Returns the WebWorkerObserver for current worker thread.
|
|
|
|
static WebWorkerObserver* GetCurrent();
|
2023-01-31 11:29:29 +00:00
|
|
|
// Creates a new WebWorkerObserver for a given context.
|
|
|
|
static WebWorkerObserver* Create();
|
2017-03-07 10:35:03 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
WebWorkerObserver(const WebWorkerObserver&) = delete;
|
|
|
|
WebWorkerObserver& operator=(const WebWorkerObserver&) = delete;
|
|
|
|
|
2020-07-28 01:48:37 +00:00
|
|
|
void WorkerScriptReadyForEvaluation(v8::Local<v8::Context> context);
|
2017-03-07 10:35:03 +00:00
|
|
|
void ContextWillDestroy(v8::Local<v8::Context> context);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<NodeBindings> node_bindings_;
|
2019-03-18 19:37:06 +00:00
|
|
|
std::unique_ptr<ElectronBindings> electron_bindings_;
|
2024-01-05 11:18:31 +00:00
|
|
|
base::flat_set<std::shared_ptr<node::Environment>> environments_;
|
2017-03-07 10:35:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_RENDERER_WEB_WORKER_OBSERVER_H_
|