85718349cc
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: Samuel Attard <sam@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
137 lines
7.9 KiB
Diff
137 lines
7.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jeremy Apthorp <nornagon@nornagon.net>
|
|
Date: Wed, 15 Jan 2020 16:35:18 -0800
|
|
Subject: add DidInstallConditionalFeatures
|
|
|
|
This adds a hook on script context creation _after conditional features
|
|
have been installed_. Electron uses this to run preload scripts and
|
|
various other initialization. This is necessary because at the time
|
|
DidCreateScriptContext is called, not all JS APIs are available in the
|
|
context, which can cause some preload scripts to trip.
|
|
|
|
diff --git a/content/public/renderer/render_frame_observer.h b/content/public/renderer/render_frame_observer.h
|
|
index 3d985164eee3d7d8ef9e7ff2215ec9a17ec157a5..9c1c4fd8528fbb088f1836c8503c5875727f5d62 100644
|
|
--- a/content/public/renderer/render_frame_observer.h
|
|
+++ b/content/public/renderer/render_frame_observer.h
|
|
@@ -127,6 +127,8 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener,
|
|
virtual void DidHandleOnloadEvents() {}
|
|
virtual void DidCreateScriptContext(v8::Local<v8::Context> context,
|
|
int32_t world_id) {}
|
|
+ virtual void DidInstallConditionalFeatures(v8::Local<v8::Context> context,
|
|
+ int32_t world_id) {}
|
|
virtual void WillReleaseScriptContext(v8::Local<v8::Context> context,
|
|
int32_t world_id) {}
|
|
virtual void DidClearWindowObject() {}
|
|
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
|
|
index 105dc2b5db804a699da4173476281b7ff240f0dc..197d97364bb19a1378d57cced8c485e86fda1e18 100644
|
|
--- a/content/renderer/render_frame_impl.cc
|
|
+++ b/content/renderer/render_frame_impl.cc
|
|
@@ -4263,6 +4263,12 @@ void RenderFrameImpl::DidCreateScriptContext(v8::Local<v8::Context> context,
|
|
observer.DidCreateScriptContext(context, world_id);
|
|
}
|
|
|
|
+void RenderFrameImpl::DidInstallConditionalFeatures(
|
|
+ v8::Local<v8::Context> context, int world_id) {
|
|
+ for (auto& observer : observers_)
|
|
+ observer.DidInstallConditionalFeatures(context, world_id);
|
|
+}
|
|
+
|
|
void RenderFrameImpl::WillReleaseScriptContext(v8::Local<v8::Context> context,
|
|
int world_id) {
|
|
for (auto& observer : observers_)
|
|
diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h
|
|
index 53299308d20eaaf5e26b8a5dc34d1c66d7b0fdf8..fa63808238ede5bebc3589901e318acc882b766a 100644
|
|
--- a/content/renderer/render_frame_impl.h
|
|
+++ b/content/renderer/render_frame_impl.h
|
|
@@ -583,6 +583,8 @@ class CONTENT_EXPORT RenderFrameImpl
|
|
blink::WebLocalFrameClient::LazyLoadBehavior lazy_load_behavior) override;
|
|
void DidCreateScriptContext(v8::Local<v8::Context> context,
|
|
int world_id) override;
|
|
+ void DidInstallConditionalFeatures(v8::Local<v8::Context> context,
|
|
+ int world_id) override;
|
|
void WillReleaseScriptContext(v8::Local<v8::Context> context,
|
|
int world_id) override;
|
|
void DidChangeScrollOffset() override;
|
|
diff --git a/third_party/blink/public/web/web_local_frame_client.h b/third_party/blink/public/web/web_local_frame_client.h
|
|
index 493358dade0f6a1359f95bc3f8b3adc4303b8bcc..c0a53b380d5d3d2430e353d581dab6f183fa48b7 100644
|
|
--- a/third_party/blink/public/web/web_local_frame_client.h
|
|
+++ b/third_party/blink/public/web/web_local_frame_client.h
|
|
@@ -583,6 +583,9 @@ class BLINK_EXPORT WebLocalFrameClient {
|
|
virtual void DidCreateScriptContext(v8::Local<v8::Context>,
|
|
int32_t world_id) {}
|
|
|
|
+ virtual void DidInstallConditionalFeatures(v8::Local<v8::Context>,
|
|
+ int32_t world_id) {}
|
|
+
|
|
// WebKit is about to release its reference to a v8 context for a frame.
|
|
virtual void WillReleaseScriptContext(v8::Local<v8::Context>,
|
|
int32_t world_id) {}
|
|
diff --git a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
|
|
index 83b81f4c1fd4232ee5c2b7b1b7b85424164f3acc..bdd4a0031af6f9c2b701979dd469867c018e5753 100644
|
|
--- a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
|
|
+++ b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
|
|
@@ -187,6 +187,7 @@ void LocalWindowProxy::Initialize() {
|
|
}
|
|
|
|
InstallConditionalFeatures();
|
|
+ GetFrame()->Client()->DidInstallConditionalFeatures(context, world_->GetWorldId());
|
|
|
|
if (World().IsMainWorld()) {
|
|
GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
|
|
diff --git a/third_party/blink/renderer/core/frame/local_frame_client.h b/third_party/blink/renderer/core/frame/local_frame_client.h
|
|
index fafb45421f5bc348672d20caa23b5b35293db811..1172958ff116b2f98c994245c3c3a42c6a18627b 100644
|
|
--- a/third_party/blink/renderer/core/frame/local_frame_client.h
|
|
+++ b/third_party/blink/renderer/core/frame/local_frame_client.h
|
|
@@ -298,6 +298,8 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
|
|
|
|
virtual void DidCreateScriptContext(v8::Local<v8::Context>,
|
|
int32_t world_id) = 0;
|
|
+ virtual void DidInstallConditionalFeatures(v8::Local<v8::Context>,
|
|
+ int32_t world_id) = 0;
|
|
virtual void WillReleaseScriptContext(v8::Local<v8::Context>,
|
|
int32_t world_id) = 0;
|
|
virtual bool AllowScriptExtensions() = 0;
|
|
diff --git a/third_party/blink/renderer/core/frame/local_frame_client_impl.cc b/third_party/blink/renderer/core/frame/local_frame_client_impl.cc
|
|
index 69b8211729d5b10bad95abc2ed40e9f7844666c7..a2996e454141b1823b6baa0184ccbdde784808ab 100644
|
|
--- a/third_party/blink/renderer/core/frame/local_frame_client_impl.cc
|
|
+++ b/third_party/blink/renderer/core/frame/local_frame_client_impl.cc
|
|
@@ -273,6 +273,13 @@ void LocalFrameClientImpl::DidCreateScriptContext(
|
|
web_frame_->Client()->DidCreateScriptContext(context, world_id);
|
|
}
|
|
|
|
+void LocalFrameClientImpl::DidInstallConditionalFeatures(
|
|
+ v8::Local<v8::Context> context,
|
|
+ int32_t world_id) {
|
|
+ if (web_frame_->Client())
|
|
+ web_frame_->Client()->DidInstallConditionalFeatures(context, world_id);
|
|
+}
|
|
+
|
|
void LocalFrameClientImpl::WillReleaseScriptContext(
|
|
v8::Local<v8::Context> context,
|
|
int32_t world_id) {
|
|
diff --git a/third_party/blink/renderer/core/frame/local_frame_client_impl.h b/third_party/blink/renderer/core/frame/local_frame_client_impl.h
|
|
index a853d0dd0ecfd676b6ada622f38a6546e526be92..d39a81547c3335d6b2ff3219ddcf5f3b2daa1c9c 100644
|
|
--- a/third_party/blink/renderer/core/frame/local_frame_client_impl.h
|
|
+++ b/third_party/blink/renderer/core/frame/local_frame_client_impl.h
|
|
@@ -77,6 +77,8 @@ class CORE_EXPORT LocalFrameClientImpl final : public LocalFrameClient {
|
|
|
|
void DidCreateScriptContext(v8::Local<v8::Context>,
|
|
int32_t world_id) override;
|
|
+ void DidInstallConditionalFeatures(v8::Local<v8::Context>,
|
|
+ int32_t world_id) override;
|
|
void WillReleaseScriptContext(v8::Local<v8::Context>,
|
|
int32_t world_id) override;
|
|
|
|
diff --git a/third_party/blink/renderer/core/loader/empty_clients.h b/third_party/blink/renderer/core/loader/empty_clients.h
|
|
index 461ecb3cf70026a1f6a43a72ed9e0ad6c27296fd..b7e5a66f9dc0d27df09ddaf9483d56af0e892489 100644
|
|
--- a/third_party/blink/renderer/core/loader/empty_clients.h
|
|
+++ b/third_party/blink/renderer/core/loader/empty_clients.h
|
|
@@ -348,6 +348,8 @@ class CORE_EXPORT EmptyLocalFrameClient : public LocalFrameClient {
|
|
|
|
void DidCreateScriptContext(v8::Local<v8::Context>,
|
|
int32_t world_id) override {}
|
|
+ void DidInstallConditionalFeatures(v8::Local<v8::Context>,
|
|
+ int32_t world_id) override {}
|
|
void WillReleaseScriptContext(v8::Local<v8::Context>,
|
|
int32_t world_id) override {}
|
|
bool AllowScriptExtensions() override { return false; }
|