2014-10-31 12:17:05 -06:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 03:49:37 -06:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-11 19:46:58 -06:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#ifndef ELECTRON_SHELL_RENDERER_ELECTRON_RENDERER_CLIENT_H_
|
|
|
|
#define ELECTRON_SHELL_RENDERER_ELECTRON_RENDERER_CLIENT_H_
|
2013-04-11 19:46:58 -06:00
|
|
|
|
2018-09-12 18:25:56 -06:00
|
|
|
#include <memory>
|
2018-03-15 00:16:30 -06:00
|
|
|
#include <set>
|
2014-01-09 07:13:06 -07:00
|
|
|
|
2019-06-19 14:46:59 -06:00
|
|
|
#include "shell/renderer/renderer_client_base.h"
|
2013-04-11 19:46:58 -06:00
|
|
|
|
2018-03-15 00:16:30 -06:00
|
|
|
namespace node {
|
|
|
|
class Environment;
|
2021-07-01 18:51:37 -06:00
|
|
|
}
|
2018-03-15 00:16:30 -06:00
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
namespace electron {
|
2013-04-11 19:46:58 -06:00
|
|
|
|
2019-03-18 13:37:06 -06:00
|
|
|
class ElectronBindings;
|
2013-04-19 21:13:06 -06:00
|
|
|
class NodeBindings;
|
|
|
|
|
2020-02-04 13:19:40 -07:00
|
|
|
class ElectronRendererClient : public RendererClientBase {
|
2013-04-12 09:16:16 -06:00
|
|
|
public:
|
2020-02-04 13:19:40 -07:00
|
|
|
ElectronRendererClient();
|
|
|
|
~ElectronRendererClient() override;
|
2013-04-11 19:46:58 -06:00
|
|
|
|
2021-11-03 05:41:45 -06:00
|
|
|
// disable copy
|
|
|
|
ElectronRendererClient(const ElectronRendererClient&) = delete;
|
|
|
|
ElectronRendererClient& operator=(const ElectronRendererClient&) = delete;
|
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
// electron::RendererClientBase:
|
2018-04-17 19:44:10 -06:00
|
|
|
void DidCreateScriptContext(v8::Handle<v8::Context> context,
|
|
|
|
content::RenderFrame* render_frame) override;
|
|
|
|
void WillReleaseScriptContext(v8::Handle<v8::Context> context,
|
|
|
|
content::RenderFrame* render_frame) override;
|
2017-04-08 07:58:13 -06:00
|
|
|
|
2013-04-12 09:16:16 -06:00
|
|
|
private:
|
2023-08-30 18:38:07 -06:00
|
|
|
void UndeferLoad(content::RenderFrame* render_frame);
|
|
|
|
|
2014-06-28 08:33:00 -06:00
|
|
|
// content::ContentRendererClient:
|
2015-04-28 09:45:58 -06:00
|
|
|
void RenderFrameCreated(content::RenderFrame*) override;
|
2016-05-10 00:43:25 -06:00
|
|
|
void RunScriptsAtDocumentStart(content::RenderFrame* render_frame) override;
|
2016-05-26 20:07:06 -06:00
|
|
|
void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame) override;
|
2020-07-27 19:48:37 -06:00
|
|
|
void WorkerScriptReadyForEvaluationOnWorkerThread(
|
2017-03-07 03:35:03 -07:00
|
|
|
v8::Local<v8::Context> context) override;
|
|
|
|
void WillDestroyWorkerContextOnWorkerThread(
|
|
|
|
v8::Local<v8::Context> context) override;
|
2015-12-29 01:41:44 -07:00
|
|
|
|
2018-03-15 00:16:30 -06:00
|
|
|
node::Environment* GetEnvironment(content::RenderFrame* frame) const;
|
|
|
|
|
2017-03-02 01:18:00 -07:00
|
|
|
// Whether the node integration has been initialized.
|
2018-05-21 16:18:38 -06:00
|
|
|
bool node_integration_initialized_ = false;
|
2017-03-02 01:18:00 -07:00
|
|
|
|
2023-09-07 17:25:17 -06:00
|
|
|
const std::unique_ptr<NodeBindings> node_bindings_;
|
|
|
|
const std::unique_ptr<ElectronBindings> electron_bindings_;
|
2013-04-19 21:13:06 -06:00
|
|
|
|
2018-03-15 00:16:30 -06: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.
|
2023-08-23 07:56:16 -06:00
|
|
|
std::set<std::shared_ptr<node::Environment>> environments_;
|
2018-03-15 00:16:30 -06: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.
|
|
|
|
std::set<content::RenderFrame*> injected_frames_;
|
2013-04-11 19:46:58 -06:00
|
|
|
};
|
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
} // namespace electron
|
2013-04-11 19:46:58 -06:00
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#endif // ELECTRON_SHELL_RENDERER_ELECTRON_RENDERER_CLIENT_H_
|