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.
|
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#ifndef SHELL_RENDERER_RENDERER_CLIENT_BASE_H_
|
|
|
|
#define 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 <vector>
|
|
|
|
|
|
|
|
#include "content/public/renderer/content_renderer_client.h"
|
2019-07-24 19:01:08 -04:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2018-07-20 18:08:18 +02:00
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
2018-09-11 01:05:05 +05:30
|
|
|
// In SHARED_INTERMEDIATE_DIR.
|
|
|
|
#include "widevine_cdm_version.h" // NOLINT(build/include)
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2018-09-10 01:44:16 +05:30
|
|
|
#if defined(WIDEVINE_CDM_AVAILABLE)
|
2019-03-05 10:38:55 +05:30
|
|
|
#include "chrome/renderer/media/chrome_key_systems_provider.h" // nogncheck
|
2018-09-10 01:44:16 +05:30
|
|
|
#endif
|
|
|
|
|
2019-08-26 19:47:32 +03:00
|
|
|
namespace network_hints {
|
|
|
|
class PrescientNetworkingDispatcher;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
class AtomExtensionsRendererClient;
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 18:19:34 -03:00
|
|
|
class RendererClientBase : public content::ContentRendererClient {
|
|
|
|
public:
|
|
|
|
RendererClientBase();
|
2018-04-17 16:03:51 -07:00
|
|
|
~RendererClientBase() override;
|
2017-03-27 18:19:34 -03:00
|
|
|
|
2018-04-17 21:44:10 -04:00
|
|
|
virtual void DidCreateScriptContext(v8::Handle<v8::Context> context,
|
2018-07-19 13:29:47 +09:00
|
|
|
content::RenderFrame* render_frame);
|
2018-04-17 21:44:10 -04:00
|
|
|
virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context,
|
|
|
|
content::RenderFrame* render_frame) = 0;
|
2017-04-08 10:43:19 -03:00
|
|
|
virtual void DidClearWindowObject(content::RenderFrame* render_frame);
|
2018-12-14 06:25:12 +09:00
|
|
|
virtual void SetupMainWorldOverrides(v8::Handle<v8::Context> context,
|
|
|
|
content::RenderFrame* render_frame) = 0;
|
2019-03-11 19:27:57 -04:00
|
|
|
virtual void SetupExtensionWorldOverrides(v8::Handle<v8::Context> context,
|
|
|
|
content::RenderFrame* render_frame,
|
|
|
|
int world_id) = 0;
|
2017-07-27 17:08:24 -07:00
|
|
|
|
2019-08-26 19:47:32 +03:00
|
|
|
blink::WebPrescientNetworking* GetPrescientNetworking() override;
|
2018-05-04 23:39:54 -07:00
|
|
|
bool isolated_world() const { return isolated_world_; }
|
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;
|
2018-10-25 20:59:13 +05:30
|
|
|
// Executes a given v8 Script
|
2018-11-29 07:25:03 +05:30
|
|
|
static v8::Local<v8::Value> RunScript(v8::Local<v8::Context> context,
|
2018-10-25 20:59:13 +05:30
|
|
|
v8::Local<v8::String> source);
|
2017-04-08 10:43:19 -03:00
|
|
|
|
2019-07-17 02:13:05 +02:00
|
|
|
// v8Util.getHiddenValue(window.frameElement, 'internal')
|
|
|
|
bool IsWebViewFrame(v8::Handle<v8::Context> context,
|
|
|
|
content::RenderFrame* render_frame) const;
|
|
|
|
|
2017-03-27 18:19:34 -03:00
|
|
|
protected:
|
|
|
|
void AddRenderBindings(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> binding_object);
|
|
|
|
|
|
|
|
// content::ContentRendererClient:
|
|
|
|
void RenderThreadStarted() override;
|
|
|
|
void RenderFrameCreated(content::RenderFrame*) override;
|
|
|
|
bool OverrideCreatePlugin(content::RenderFrame* render_frame,
|
|
|
|
const blink::WebPluginParams& params,
|
|
|
|
blink::WebPlugin** plugin) override;
|
|
|
|
void AddSupportedKeySystems(
|
|
|
|
std::vector<std::unique_ptr<::media::KeySystemProperties>>* key_systems)
|
|
|
|
override;
|
2018-09-06 02:30:37 +05:30
|
|
|
bool IsKeySystemsUpdateNeeded() override;
|
2019-01-22 12:54:36 +05:30
|
|
|
void DidSetUserAgent(const std::string& user_agent) 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;
|
|
|
|
|
|
|
|
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-08-26 19:47:32 +03:00
|
|
|
std::unique_ptr<network_hints::PrescientNetworkingDispatcher>
|
|
|
|
prescient_networking_dispatcher_;
|
|
|
|
|
2019-07-24 19:01:08 -04:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
std::unique_ptr<extensions::ExtensionsClient> extensions_client_;
|
|
|
|
std::unique_ptr<AtomExtensionsRendererClient> extensions_renderer_client_;
|
|
|
|
#endif
|
2019-08-26 19:47:32 +03:00
|
|
|
|
2018-09-10 01:44:16 +05:30
|
|
|
#if defined(WIDEVINE_CDM_AVAILABLE)
|
2018-09-06 02:30:37 +05:30
|
|
|
ChromeKeySystemsProvider key_systems_provider_;
|
2018-09-10 01:44:16 +05:30
|
|
|
#endif
|
2017-07-27 17:08:24 -07:00
|
|
|
bool isolated_world_;
|
2018-09-11 23:48:10 +05:30
|
|
|
std::string renderer_client_id_;
|
2018-07-24 16:21:38 +09:00
|
|
|
// An increasing ID used for indentifying an V8 context in this process.
|
2018-09-11 23:48:10 +05:30
|
|
|
int64_t next_context_id_ = 0;
|
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
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#endif // SHELL_RENDERER_RENDERER_CLIENT_BASE_H_
|