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 107c22e38babc4860d53d4fb539f322e6dec1df0..366382caddffc3beb363fe96eab63ea7474f81d1 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 e0c8e8c19450b067757a8e8289f46f32b7d443eb..0f13101c719e6f43cfc5d281d0f6f345d475744d 100644
|
|
--- a/content/renderer/render_frame_impl.cc
|
|
+++ b/content/renderer/render_frame_impl.cc
|
|
@@ -4135,6 +4135,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 77aaa3c08c1268c246f698a02df3e8a1aa4ef294..ffc6a5d1cd16ee2aecee027e9a321f1e435f5410 100644
|
|
--- a/content/renderer/render_frame_impl.h
|
|
+++ b/content/renderer/render_frame_impl.h
|
|
@@ -576,6 +576,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 4b3b9b1c4034656fdf5f9862d3fffa66f51e72fe..55e69bb644e2c47ac15fe8b2e255d660b8a51b4f 100644
|
|
--- a/third_party/blink/public/web/web_local_frame_client.h
|
|
+++ b/third_party/blink/public/web/web_local_frame_client.h
|
|
@@ -577,6 +577,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 d8ac4cd5b0847b03ed30663dea24654c6e29d2f0..8c46855d4a5f888425ea4b6d4f69c74ac649933e 100644
|
|
--- a/third_party/blink/renderer/core/frame/local_frame_client.h
|
|
+++ b/third_party/blink/renderer/core/frame/local_frame_client.h
|
|
@@ -291,6 +291,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 3538350785762dc742f862ff0e9ba8f43c92199a..0c980c66d861af11760faf1f1f78070d9f487367 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
|
|
@@ -272,6 +272,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 aab6643b89899a2b7f5bd74d4501bbf74562a663..8a3dddf797106e3d5da6a75d458ddea97cdf5edc 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 f4e37cb5be1a84b9610d2d33f126e040d5ff4822..8cc53215effecb53ee383c33469a27f1e267daf6 100644
|
|
--- a/third_party/blink/renderer/core/loader/empty_clients.h
|
|
+++ b/third_party/blink/renderer/core/loader/empty_clients.h
|
|
@@ -349,6 +349,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; }
|