2017-03-27 18:19:34 -03: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 08:34:31 +01:00
|
|
|
#ifndef ELECTRON_SHELL_RENDERER_RENDERER_CLIENT_BASE_H_
|
|
|
|
#define ELECTRON_SHELL_RENDERER_RENDERER_CLIENT_BASE_H_
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2018-09-12 19:25:56 -05:00
|
|
|
#include <memory>
|
2017-03-27 18:19:34 -03:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "content/public/renderer/content_renderer_client.h"
|
2019-07-24 19:01:08 -04:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2024-04-15 18:10:32 -04:00
|
|
|
#include "media/base/key_systems_support_registration.h"
|
2020-10-16 18:30:46 -07:00
|
|
|
#include "printing/buildflags/buildflags.h"
|
2021-03-17 19:23:29 +01:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2018-09-11 01:05:05 +05:30
|
|
|
// In SHARED_INTERMEDIATE_DIR.
|
2020-04-25 04:57:41 +09:00
|
|
|
#include "widevine_cdm_version.h" // NOLINT(build/include_directory)
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2020-10-16 18:30:46 -07:00
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
2022-03-24 21:39:03 -04:00
|
|
|
#include "components/pdf/renderer/internal_plugin_renderer_helpers.h"
|
2020-10-16 18:30:46 -07:00
|
|
|
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
|
|
|
2019-10-31 13:11:51 -07:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
#include "services/service_manager/public/cpp/binder_registry.h"
|
|
|
|
#include "services/service_manager/public/cpp/local_interface_provider.h"
|
|
|
|
|
|
|
|
class SpellCheck;
|
|
|
|
#endif
|
|
|
|
|
2021-07-01 17:51:37 -07:00
|
|
|
namespace blink {
|
|
|
|
class WebLocalFrame;
|
|
|
|
}
|
|
|
|
|
2019-07-24 19:01:08 -04:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
namespace extensions {
|
|
|
|
class ExtensionsClient;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2019-07-24 19:01:08 -04:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-02-03 14:01:10 -08:00
|
|
|
class ElectronExtensionsRendererClient;
|
2019-07-24 19:01:08 -04:00
|
|
|
#endif
|
|
|
|
|
2019-10-31 13:11:51 -07:00
|
|
|
class RendererClientBase : public content::ContentRendererClient
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
,
|
|
|
|
public service_manager::LocalInterfaceProvider
|
|
|
|
#endif
|
|
|
|
{
|
2017-03-27 18:19:34 -03:00
|
|
|
public:
|
|
|
|
RendererClientBase();
|
2018-04-17 16:03:51 -07:00
|
|
|
~RendererClientBase() override;
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2021-05-10 14:19:23 +02:00
|
|
|
static RendererClientBase* Get();
|
|
|
|
|
2019-10-31 13:11:51 -07:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
// service_manager::LocalInterfaceProvider implementation.
|
|
|
|
void GetInterface(const std::string& name,
|
2021-05-31 18:46:25 -07:00
|
|
|
mojo::ScopedMessagePipeHandle interface_pipe) override;
|
2019-10-31 13:11:51 -07:00
|
|
|
#endif
|
|
|
|
|
2024-07-25 12:45:06 +02:00
|
|
|
virtual void DidCreateScriptContext(v8::Local<v8::Context> context,
|
2021-05-24 09:51:54 +02:00
|
|
|
content::RenderFrame* render_frame) = 0;
|
2024-07-25 12:45:06 +02:00
|
|
|
virtual void WillReleaseScriptContext(v8::Local<v8::Context> context,
|
2018-04-17 21:44:10 -04:00
|
|
|
content::RenderFrame* render_frame) = 0;
|
2017-04-08 10:43:19 -03:00
|
|
|
virtual void DidClearWindowObject(content::RenderFrame* render_frame);
|
2024-07-25 12:45:06 +02:00
|
|
|
virtual void SetupMainWorldOverrides(v8::Local<v8::Context> context,
|
2021-05-15 09:42:07 +02:00
|
|
|
content::RenderFrame* render_frame);
|
2017-07-27 17:08:24 -07:00
|
|
|
|
2019-12-10 16:22:35 -08:00
|
|
|
std::unique_ptr<blink::WebPrescientNetworking> CreatePrescientNetworking(
|
|
|
|
content::RenderFrame* render_frame) override;
|
2017-07-27 17:08:24 -07:00
|
|
|
|
|
|
|
// Get the context that the Electron API is running in.
|
2018-04-17 21:44:10 -04:00
|
|
|
v8::Local<v8::Context> GetContext(blink::WebLocalFrame* frame,
|
2018-05-04 23:39:54 -07:00
|
|
|
v8::Isolate* isolate) const;
|
2017-04-08 10:43:19 -03:00
|
|
|
|
2021-05-15 09:42:07 +02:00
|
|
|
static void AllowGuestViewElementDefinition(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> context,
|
|
|
|
v8::Local<v8::Function> register_cb);
|
|
|
|
|
2024-07-25 12:45:06 +02:00
|
|
|
bool IsWebViewFrame(v8::Local<v8::Context> context,
|
2019-07-17 02:13:05 +02:00
|
|
|
content::RenderFrame* render_frame) const;
|
|
|
|
|
2020-02-03 09:49:37 -08:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
SpellCheck* GetSpellCheck() { return spellcheck_.get(); }
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 18:19:34 -03:00
|
|
|
protected:
|
2021-03-17 19:23:29 +01:00
|
|
|
void BindProcess(v8::Isolate* isolate,
|
|
|
|
gin_helper::Dictionary* process,
|
|
|
|
content::RenderFrame* render_frame);
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2024-07-25 12:45:06 +02:00
|
|
|
bool ShouldLoadPreload(v8::Local<v8::Context> context,
|
2022-06-13 08:58:27 +02:00
|
|
|
content::RenderFrame* render_frame) const;
|
|
|
|
|
2017-03-27 18:19:34 -03:00
|
|
|
// content::ContentRendererClient:
|
|
|
|
void RenderThreadStarted() override;
|
2020-02-03 09:49:37 -08:00
|
|
|
void ExposeInterfacesToBrowser(mojo::BinderMap* binders) override;
|
2017-03-27 18:19:34 -03:00
|
|
|
void RenderFrameCreated(content::RenderFrame*) override;
|
|
|
|
bool OverrideCreatePlugin(content::RenderFrame* render_frame,
|
|
|
|
const blink::WebPluginParams& params,
|
|
|
|
blink::WebPlugin** plugin) override;
|
2019-01-22 12:54:36 +05:30
|
|
|
void DidSetUserAgent(const std::string& user_agent) override;
|
2020-02-12 16:39:12 -08:00
|
|
|
bool IsPluginHandledExternally(content::RenderFrame* render_frame,
|
|
|
|
const blink::WebElement& plugin_element,
|
|
|
|
const GURL& original_url,
|
|
|
|
const std::string& mime_type) override;
|
2022-03-24 21:39:03 -04:00
|
|
|
v8::Local<v8::Object> GetScriptableObject(
|
|
|
|
const blink::WebElement& plugin_element,
|
|
|
|
v8::Isolate* isolate) override;
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2019-07-24 19:01:08 -04:00
|
|
|
void RunScriptsAtDocumentStart(content::RenderFrame* render_frame) override;
|
|
|
|
void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame) override;
|
|
|
|
void RunScriptsAtDocumentIdle(content::RenderFrame* render_frame) override;
|
|
|
|
|
2021-02-11 10:58:03 -05:00
|
|
|
bool AllowScriptExtensionForServiceWorker(
|
|
|
|
const url::Origin& script_origin) override;
|
|
|
|
void DidInitializeServiceWorkerContextOnWorkerThread(
|
|
|
|
blink::WebServiceWorkerContextProxy* context_proxy,
|
|
|
|
const GURL& service_worker_scope,
|
|
|
|
const GURL& script_url) override;
|
|
|
|
void WillEvaluateServiceWorkerOnWorkerThread(
|
|
|
|
blink::WebServiceWorkerContextProxy* context_proxy,
|
|
|
|
v8::Local<v8::Context> v8_context,
|
|
|
|
int64_t service_worker_version_id,
|
|
|
|
const GURL& service_worker_scope,
|
|
|
|
const GURL& script_url) override;
|
|
|
|
void DidStartServiceWorkerContextOnWorkerThread(
|
|
|
|
int64_t service_worker_version_id,
|
|
|
|
const GURL& service_worker_scope,
|
|
|
|
const GURL& script_url) override;
|
|
|
|
void WillDestroyServiceWorkerContextOnWorkerThread(
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
int64_t service_worker_version_id,
|
|
|
|
const GURL& service_worker_scope,
|
|
|
|
const GURL& script_url) override;
|
2022-10-03 13:21:00 -07:00
|
|
|
void WebViewCreated(blink::WebView* web_view,
|
|
|
|
bool was_created_by_renderer,
|
|
|
|
const url::Origin* outermost_origin) override;
|
2021-02-11 10:58:03 -05:00
|
|
|
|
2019-07-24 19:01:08 -04:00
|
|
|
protected:
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
// app_shell embedders may need custom extensions client interfaces.
|
|
|
|
// This class takes ownership of the returned object.
|
|
|
|
virtual extensions::ExtensionsClient* CreateExtensionsClient();
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 18:19:34 -03:00
|
|
|
private:
|
2019-07-24 19:01:08 -04:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
std::unique_ptr<extensions::ExtensionsClient> extensions_client_;
|
2020-02-03 14:01:10 -08:00
|
|
|
std::unique_ptr<ElectronExtensionsRendererClient> extensions_renderer_client_;
|
2019-07-24 19:01:08 -04:00
|
|
|
#endif
|
2019-08-26 19:47:32 +03:00
|
|
|
|
2018-09-11 23:48:10 +05:30
|
|
|
std::string renderer_client_id_;
|
2020-10-13 10:25:21 -07:00
|
|
|
// An increasing ID used for identifying an V8 context in this process.
|
2018-09-11 23:48:10 +05:30
|
|
|
int64_t next_context_id_ = 0;
|
2019-10-31 13:11:51 -07:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
std::unique_ptr<SpellCheck> spellcheck_;
|
|
|
|
#endif
|
2017-03-27 18:19:34 -03:00
|
|
|
};
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#endif // ELECTRON_SHELL_RENDERER_RENDERER_CLIENT_BASE_H_
|