2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-12 01:46:58 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_RENDERER_ELECTRON_RENDERER_CLIENT_H_
|
|
|
|
#define ELECTRON_SHELL_RENDERER_ELECTRON_RENDERER_CLIENT_H_
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2014-01-09 14:13:06 +00:00
|
|
|
|
2024-01-05 11:18:31 +00:00
|
|
|
#include "base/containers/flat_set.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/renderer/renderer_client_base.h"
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2018-03-15 06:16:30 +00:00
|
|
|
namespace node {
|
|
|
|
class Environment;
|
2021-07-02 00:51:37 +00:00
|
|
|
}
|
2018-03-15 06:16:30 +00:00
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2019-03-18 19:37:06 +00:00
|
|
|
class ElectronBindings;
|
2013-04-20 03:13:06 +00:00
|
|
|
class NodeBindings;
|
|
|
|
|
2017-03-27 21:19:34 +00:00
|
|
|
class ElectronRendererClient : public RendererClientBase {
|
2013-04-12 15:16:16 +00:00
|
|
|
public:
|
2013-04-12 01:46:58 +00:00
|
|
|
ElectronRendererClient();
|
2018-04-17 23:03:51 +00:00
|
|
|
~ElectronRendererClient() override;
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
ElectronRendererClient(const ElectronRendererClient&) = delete;
|
|
|
|
ElectronRendererClient& operator=(const ElectronRendererClient&) = delete;
|
|
|
|
|
2017-04-08 13:58:13 +00:00
|
|
|
// electron::RendererClientBase:
|
2024-07-25 10:45:06 +00:00
|
|
|
void DidCreateScriptContext(v8::Local<v8::Context> context,
|
2018-04-18 01:44:10 +00:00
|
|
|
content::RenderFrame* render_frame) override;
|
2024-07-25 10:45:06 +00:00
|
|
|
void WillReleaseScriptContext(v8::Local<v8::Context> context,
|
2018-04-18 01:44:10 +00:00
|
|
|
content::RenderFrame* render_frame) override;
|
2017-04-08 13:58:13 +00:00
|
|
|
|
2013-04-12 15:16:16 +00:00
|
|
|
private:
|
2023-08-31 00:38:07 +00:00
|
|
|
void UndeferLoad(content::RenderFrame* render_frame);
|
|
|
|
|
2014-06-28 14:33:00 +00:00
|
|
|
// content::ContentRendererClient:
|
2015-04-28 15:45:58 +00:00
|
|
|
void RenderFrameCreated(content::RenderFrame*) override;
|
2016-05-10 06:43:25 +00:00
|
|
|
void RunScriptsAtDocumentStart(content::RenderFrame* render_frame) override;
|
2016-05-27 02:07:06 +00:00
|
|
|
void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame) override;
|
2020-07-28 01:48:37 +00:00
|
|
|
void WorkerScriptReadyForEvaluationOnWorkerThread(
|
2017-03-07 10:35:03 +00:00
|
|
|
v8::Local<v8::Context> context) override;
|
|
|
|
void WillDestroyWorkerContextOnWorkerThread(
|
|
|
|
v8::Local<v8::Context> context) override;
|
2015-12-29 08:41:44 +00:00
|
|
|
|
2018-03-15 06:16:30 +00:00
|
|
|
node::Environment* GetEnvironment(content::RenderFrame* frame) const;
|
|
|
|
|
2017-03-02 08:18:00 +00:00
|
|
|
// Whether the node integration has been initialized.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool node_integration_initialized_ = false;
|
2017-03-02 08:18:00 +00:00
|
|
|
|
2023-09-07 23:25:17 +00:00
|
|
|
const std::unique_ptr<NodeBindings> node_bindings_;
|
|
|
|
const std::unique_ptr<ElectronBindings> electron_bindings_;
|
2013-04-20 03:13:06 +00:00
|
|
|
|
2018-03-15 06:16:30 +00:00
|
|
|
// The node::Environment::GetCurrent API does not return nullptr when it
|
|
|
|
// is called for a context without node::Environment, so we have to keep
|
|
|
|
// a book of the environments created.
|
2024-01-05 11:18:31 +00:00
|
|
|
base::flat_set<std::shared_ptr<node::Environment>> environments_;
|
2018-03-15 06:16:30 +00:00
|
|
|
|
|
|
|
// Getting main script context from web frame would lazily initializes
|
|
|
|
// its script context. Doing so in a web page without scripts would trigger
|
|
|
|
// assertion, so we have to keep a book of injected web frames.
|
2024-01-05 11:18:31 +00:00
|
|
|
base::flat_set<content::RenderFrame*> injected_frames_;
|
2013-04-12 01:46:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_RENDERER_ELECTRON_RENDERER_CLIENT_H_
|